#!/usr/bin/env python3
import sys,lzma,os

def parse_units(path):
 op=lzma.open if path.endswith('.xz') else open
 n=m=0; units=[]
 with op(path,'rt') as f:
  for line in f:
   if not line or line[0]=='c': continue
   if line[0]=='p':
    sp=line.split(); n=int(sp[2]); m=int(sp[3]); continue
   xs=list(map(int,line.split()))
   if xs and xs[-1]==0: xs=xs[:-1]
   if len(xs)==1: units.append(xs[0])
 return n,units

def bits_to_int(vals,base):
 x=0
 for i in range(32):
  v=vals.get(base+i+1)
  if v is None: return None
  if v: x|=1<<i
 return x
for p in sys.argv[1:]:
 n,units=parse_units(p); vals={abs(u):u>0 for u in units}
 r=(n-128)//160
 print(os.path.basename(p),'r',r,'units',len(units),'Kdup?', all((33+i in vals and 1+i not in vals) for i in range(32)))
 print(' init L,R',hex(bits_to_int(vals,65) or 0),hex(bits_to_int(vals,97) or 0),' final',hex(bits_to_int(vals,n-63) or 0),hex(bits_to_int(vals,n-31) or 0))
 # print unit ranges compact
 print(' first unit vars', sorted(abs(u) for u in units)[:5], sorted(abs(u) for u in units)[-5:])
