pbwtSubSample

original_code:
PBWT *pbwtSubSample (PBWT *pOld, Array select)
{
  if (!pOld || !pOld->yz) die ("subSample called without valid pbwt") ;
  PBWT *pNew = pbwtCreate (((select)->max), pOld->N) ;
  int i, j, nOld = 0 ;
  uchar *x = (uchar*)_myalloc((pNew->M)*sizeof(uchar)) ;
  int *ainv = (int*)_myalloc((pOld->M)*sizeof(int)) ;
  PbwtCursor *uOld = pbwtCursorCreate (pOld, 1, 1) ;
  PbwtCursor *uNew = pbwtCursorCreate (pNew, 1, 1) ;
  for (i = 0 ; i < pOld->N ; ++i)
    { for (j = 0 ; j < pOld->M ; ++j) ainv[uOld->a[j]] = j ;
      for (j = 0 ; j < pNew->M ; ++j) x[j] = uOld->y[ainv[((*(int*)((select)->base + (j)*(select)->size)))]] ;
      for (j = 0 ; j < pNew->M ; ++j) uNew->y[j] = x[uNew->a[j]] ;
      pbwtCursorWriteForwards (uNew) ;
      pbwtCursorForwardsRead (uOld) ;
    }
  pbwtCursorToAFend (uNew, pNew) ;
  if (pOld->samples)
    { pNew->samples = uArrayCreate(pNew->M,sizeof(int)) ;
      for (j = 0 ; j < pNew->M ; ++j)
 (*(int*)uArray(pNew->samples,j)) = ((*(int*)((pOld->samples)->base + (((*(int*)((select)->base + (j)*(select)->size))))*(pOld->samples)->size))) ;
    }
  pNew->chrom = pOld->chrom ; pOld->chrom = 0 ;
  pNew->sites = pOld->sites ; pOld->sites = 0 ;
  pbwtDestroy (pOld) ;
  free(x) ; free(ainv) ; pbwtCursorDestroy (uOld) ; pbwtCursorDestroy (uNew) ;
  return pNew ;
}

canonical_original_code:
struct PBWTstruct *pbwtSubSample(struct PBWTstruct *pOld, struct ArrayStruct *select)
{
  if (!pOld || !pOld->yz) die ("subSample called without valid pbwt") ;
  struct PBWTstruct *pNew = pbwtCreate (((select)->max), pOld->N);
  int i; int j; int nOld = 0;
  unsigned char *x = (uchar*)_myalloc((pNew->M)*sizeof(uchar));
  int *ainv = (int*)_myalloc((pOld->M)*sizeof(int));
  struct PbwtCursor *uOld = pbwtCursorCreate (pOld, 1, 1);
  struct PbwtCursor *uNew = pbwtCursorCreate (pNew, 1, 1);
  for (i = 0 ; i < pOld->N ; ++i)
    { for (j = 0 ; j < pOld->M ; ++j) ainv[uOld->a[j]] = j ;
      for (j = 0 ; j < pNew->M ; ++j) x[j] = uOld->y[ainv[((*(int *)((select)->base + (j)*(select)->size)))]] ;
      for (j = 0 ; j < pNew->M ; ++j) uNew->y[j] = x[uNew->a[j]] ;
      pbwtCursorWriteForwards (uNew) ;
      pbwtCursorForwardsRead (uOld) ;
    }
  pbwtCursorToAFend (uNew, pNew) ;
  if (pOld->samples)
    { pNew->samples = uArrayCreate(pNew->M,sizeof(int)) ;
      for (j = 0 ; j < pNew->M ; ++j)
 (*(int *)uArray(pNew->samples,j)) = ((*(int *)((pOld->samples)->base + (((*(int *)((select)->base + (j)*(select)->size))))*(pOld->samples)->size))) ;
    }
  pNew->chrom = pOld->chrom ; pOld->chrom = 0 ;
  pNew->sites = pOld->sites ; pOld->sites = 0 ;
  pbwtDestroy (pOld) ;
  free(x) ; free(ainv) ; pbwtCursorDestroy (uOld) ; pbwtCursorDestroy (uNew) ;
  return pNew ;
}

variable_types:
pOld
struct PBWTstruct *

variable_types:
select
struct ArrayStruct *

variable_types: nOld int

variable_types:
x
unsigned char *

variable_types:
ainv
int *

variable_types: struct PbwtCursor { int M; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *z; long n; char isBlockEnd; unsigned char *y; int c; int *a; int *d; int *u; int *b; int *e; long nBlockStart; } *

return_type: struct PBWTstruct { int N; int M; char *chrom; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *sites; struct ArrayStruct *samples; struct ArrayStruct *yz; int *aFstart; struct ArrayStruct *zz; int *aRstart; struct ArrayStruct *zMissing; struct ArrayStruct *missingOffset; struct ArrayStruct *zDosage; struct ArrayStruct *dosageOffset; char isRefFreq; char isUnphased; } *

user_defined_types: struct PbwtCursor { int M; struct ArrayStruct *z; long n; char isBlockEnd; unsigned char *y; int c; int *a; int *d; int *u; int *b; int *e; long nBlockStart; }


pbwtSubSampleInterval

repo: richarddurbin/pbwt

decompiled_code:
__int64 __fastcall pbwtSubSampleInterval(unsigned int *a1, __int64 a2, int a3)
{
__int64 v3; // r14
__int64 v5; // r14
__int64 v6; // rbx
_DWORD *v7; // rax
int v8; // edx
__int64 v9; // r12

v3 = a3;
if ( (int)a2 < 0 || a3 <= 0 )
{
die("bad start %d, Mnew %d in subsample", (unsigned int)a2, (unsigned int)a3);
v5 = uArrayCreate(v3, 4LL);
if ( a3 <= 0 )
goto LABEL_8;
}
else
{
if ( (int)a2 + a3 > (int)a1[1] )
die("bad start %d, Mnew %d in subsample", a2, (unsigned int)a3);
v5 = uArrayCreate(v3, 4LL);
}
v6 = 0LL;
do
{
v7 = (_DWORD *)uArray(v5, v6);
v8 = a2 + v6++;
*v7 = v8;
}
while ( a3 > (int)v6 );
LABEL_8:
v9 = pbwtSubSample(a1, v5);
arrayDestroy(v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, __int64 a2, int a3)
{
__int64 v3; // r14
__int64 v5; // r14
__int64 v6; // rbx
_DWORD *v7; // rax
int v8; // edx
__int64 v9; // r12

v3 = a3;
if ( (int)a2 < 0 || a3 <= 0 )
{
die("bad start %d, Mnew %d in subsample", (unsigned int)a2, (unsigned int)a3);
v5 = uArrayCreate(v3, 4LL);
if ( a3 <= 0 )
goto LABEL_8;
}
else
{
if ( (int)a2 + a3 > (int)a1[1] )
die("bad start %d, Mnew %d in subsample", a2, (unsigned int)a3);
v5 = uArrayCreate(v3, 4LL);
}
v6 = 0LL;
do
{
v7 = (_DWORD *)uArray(v5, v6);
v8 = a2 + v6++;
*v7 = v8;
}
while ( a3 > (int)v6 );
LABEL_8:
v9 = func6(a1, v5);
arrayDestroy(v5);
return v9;
}

original_code:
PBWT *pbwtSubSampleInterval (PBWT *pOld, int start, int Mnew)
{
  if (start < 0 || Mnew <= 0 || start + Mnew > pOld->M)
    die ("bad start %d, Mnew %d in subsample", start, Mnew) ;
  int i ;
  Array select = uArrayCreate(Mnew,sizeof(int)) ;
  for (i = 0 ; i < Mnew ; ++i)
    (*(int*)uArray(select,i)) = start + i ;
  PBWT *pNew = pbwtSubSample (pOld, select) ;
  arrayDestroy (select) ;
  return pNew ;
}

canonical_original_code:
struct PBWTstruct *pbwtSubSampleInterval(struct PBWTstruct *pOld, int start, int Mnew)
{
  if (start < 0 || Mnew <= 0 || start + Mnew > pOld->M)
    die ("bad start %d, Mnew %d in subsample", start, Mnew) ;
  int i;
  struct ArrayStruct *select = uArrayCreate(Mnew,sizeof(int));
  for (i = 0 ; i < Mnew ; ++i)
    (*(int *)uArray(select,i)) = start + i ;
  struct PBWTstruct *pNew = pbwtSubSample (pOld, select);
  arrayDestroy (select) ;
  return pNew ;
}

variable_types: start int

variable_types: Mnew int

variable_types: i int

variable_types: struct PBWTstruct { int N; int M; char *chrom; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *sites; struct ArrayStruct *samples; struct ArrayStruct *yz; int *aFstart; struct ArrayStruct *zz; int *aRstart; struct ArrayStruct *zMissing; struct ArrayStruct *missingOffset; struct ArrayStruct *zDosage; struct ArrayStruct *dosageOffset; char isRefFreq; char isUnphased; } *

user_defined_types: struct PBWTstruct { int N; int M; char *chrom; struct ArrayStruct *sites; struct ArrayStruct *samples; struct ArrayStruct *yz; int *aFstart; struct ArrayStruct *zz; int *aRstart; struct ArrayStruct *zMissing; struct ArrayStruct *missingOffset; struct ArrayStruct *zDosage; struct ArrayStruct *dosageOffset; char isRefFreq; char isUnphased; }


hashDouble

original_code:
static void hashDouble (TRUE_HASH *h)
{
  int oldsize, newsize ;
  long int hash, delta = 0 ;
  int *oldKeys, *kp ;
  int *oldValues, i ;
  HASHKEY hk ;
  oldsize = 1 << h->nbits ;
  ++h->nbits ;
  newsize = 1 << h->nbits ;
  h->mask = (1 << h->nbits) - 1 ;
  h->guard = (1 << (h->nbits - 1)) ;
  oldKeys = h->keys ;
  h->keys = (int*)_mycalloc(newsize,sizeof(int)) ;
  oldValues = h->values ;
  h->values = (int*)_myalloc((newsize)*sizeof(int)) ;
  for (i = 0, kp = oldKeys ; i < oldsize ; i++)
    if (*kp && *kp != REMOVED)
      { hk.i = *kp ; { register int z = IS5, x = hk.i ; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
        while (1)
          if (!h->keys[hash])
     { h->keys[hash] = *kp ;
       h->values[hash] = oldValues[i] ;
       --h->guard ;
       ++nAdded ;
       break ;
     }
   else
            { nBounced++ ;
       if (!delta) { register int z = IS7, x = hk.i ; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
       hash = (hash + delta) & h->mask ;
     }
      }
  free (oldKeys) ;
  free (oldValues) ;
}

canonical_original_code:
static void hashDouble(struct TRUE_HASH *h)
{
  int oldsize; int newsize;
  long hash; long delta = 0;
  int *oldKeys; int *kp;
  int *oldValues; int i;
  union HASHKEY hk;
  oldsize = 1 << h->nbits ;
  ++h->nbits ;
  newsize = 1 << h->nbits ;
  h->mask = (1 << h->nbits) - 1 ;
  h->guard = (1 << (h->nbits - 1)) ;
  oldKeys = h->keys ;
  h->keys = (int *)_mycalloc(newsize,sizeof(int)) ;
  oldValues = h->values ;
  h->values = (int *)_myalloc((newsize)*sizeof(int)) ;
  for (i = 0, kp = oldKeys ; i < oldsize ; i++)
    if (*kp && *kp != REMOVED)
      { hk.i = *kp ; { register int z = IS5; register int x = hk.i; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
        while (1)
          if (!h->keys[hash])
     { h->keys[hash] = *kp ;
       h->values[hash] = oldValues[i] ;
       --h->guard ;
       ++nAdded ;
       break ;
     }
   else
            { nBounced++ ;
       if (!delta) { register int z = IS7; register int x = hk.i; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
       hash = (hash + delta) & h->mask ;
     }
      }
  free (oldKeys) ;
  free (oldValues) ;
}

variable_types: struct TRUE_HASH { int nbits; unsigned int mask; int n; int guard; int *keys; int *values; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *freeList; int nFree; int iter; } *

variable_types: oldsize int

variable_types: newsize int

variable_types: hash long

variable_types: delta long

variable_types:
oldKeys
int *

variable_types:
kp
int *

variable_types:
oldValues
int *

variable_types: union HASHKEY { long i; float f; void *p; }

variable_types: z int

variable_types: x int

return_type: void

user_defined_types: struct TRUE_HASH { int nbits; unsigned int mask; int n; int guard; int *keys; int *values; struct ArrayStruct *freeList; int nFree; int iter; }


hashCreate

original_code:
HASH hashCreate (int n)
{
  TRUE_HASH *h = (TRUE_HASH*)_myalloc((1)*sizeof(TRUE_HASH)) ;
  if (n < 64) n = 64 ;
  --n ;
  h->nbits = 1 ;
  while (n >>= 1) ++h->nbits ;
  h->mask = (1 << h->nbits) - 1 ;
  h->guard = (1 << (h->nbits - 1)) ;
  h->keys = (int*)_mycalloc(1 << h->nbits,sizeof(int)) ;
  h->values = (int*)_myalloc((1 << h->nbits)*sizeof(int)) ;
  h->n = 0 ;
  h->freeList = uArrayCreate(32,sizeof(int)) ;
  h->nFree = 0 ;
  ++nCreated ;
  return (HASH) h ;
}

canonical_original_code:
void *hashCreate(int n)
{
  struct TRUE_HASH *h = (TRUE_HASH*)_myalloc((1)*sizeof(TRUE_HASH));
  if (n < 64) n = 64 ;
  --n ;
  h->nbits = 1 ;
  while (n >>= 1) ++h->nbits ;
  h->mask = (1 << h->nbits) - 1 ;
  h->guard = (1 << (h->nbits - 1)) ;
  h->keys = (int *)_mycalloc(1 << h->nbits,sizeof(int)) ;
  h->values = (int *)_myalloc((1 << h->nbits)*sizeof(int)) ;
  h->n = 0 ;
  h->freeList = uArrayCreate(32,sizeof(int)) ;
  h->nFree = 0 ;
  ++nCreated ;
  return (void *) h ;
}

variable_types: n int

return_type: void *

user_defined_types: struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; }


hashDestroy

decompiled_code:
void __fastcall hashDestroy(void *ptr)
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
arrayDestroy(*((_QWORD *)ptr + 4));
free(ptr);
++nDestroyed;
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
arrayDestroy(*((_QWORD *)ptr + 4));
free(ptr);
++nDestroyed;
}

original_code:
void hashDestroy (HASH hx)
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  free (h->keys) ;
  free (h->values) ;
  arrayDestroy (h->freeList) ;
  free (h) ;
  ++nDestroyed ;
}

canonical_original_code:
void hashDestroy(void *hx)
{
  struct TRUE_HASH *h = (TRUE_HASH*) hx;
  free (h->keys) ;
  free (h->values) ;
  arrayDestroy (h->freeList) ;
  free (h) ;
  ++nDestroyed ;
}

variable_types:
hx
void *


hashClear

decompiled_code:
__int64 __fastcall hashClear(void **a1)
{
int v1; // ecx
__int64 result; // rax

v1 = *(_DWORD *)a1;
*((_DWORD *)a1 + 2) = 0;
memset(a1[2], 0, 4LL * (1 << v1));
result = uArrayReCreate(a1[4], 32LL, 4LL);
a1[4] = (void *)result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void **a1)
{
int v1; // ecx
__int64 result; // rax

v1 = *(_DWORD *)a1;
*((_DWORD *)a1 + 2) = 0;
memset(a1[2], 0, 4LL * (1 << v1));
result = uArrayReCreate(a1[4], 32LL, 4LL);
a1[4] = (void *)result;
return result;
}

original_code:
void hashClear (HASH hx)
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  h->n = 0 ;
  memset (h->keys, 0, sizeof(int)*(1 << h->nbits)) ;
  h->freeList = uArrayReCreate(h->freeList,32,sizeof(int)) ;
}

canonical_original_code:
void hashClear(void *hx)
{
  struct TRUE_HASH *h = (TRUE_HASH*) hx;
  h->n = 0 ;
  memset (h->keys, 0, sizeof(int)*(1 << h->nbits)) ;
  h->freeList = uArrayReCreate(h->freeList,32,sizeof(int)) ;
}


hashFind

original_code:
int hashFind (HASH hx, HASHKEY k)
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  long int hash, delta = 0 ;
  { register int z = IS5, x = k.i ; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
  while (1)
    if (h->keys[hash] == k.i)
      { nFound++ ;
 return h->values[hash] ;
      }
    else if (!h->keys[hash])
      { nNotFound++ ;
 return 0 ;
      }
    else
      { nBounced++ ;
 if (!delta) { register int z = IS7, x = k.i ; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
 hash = (hash + delta) & h->mask ;
      }
}

canonical_original_code:
int hashFind(void *hx, union HASHKEY k)
{
  struct TRUE_HASH *h = (TRUE_HASH*) hx;
  long hash; long delta = 0;
  { register int z = IS5; register int x = k.i; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
  while (1)
    if (h->keys[hash] == k.i)
      { nFound++ ;
 return h->values[hash] ;
      }
    else if (!h->keys[hash])
      { nNotFound++ ;
 return 0 ;
      }
    else
      { nBounced++ ;
 if (!delta) { register int z = IS7; register int x = k.i; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
 hash = (hash + delta) & h->mask ;
      }
}

return_type: int

user_defined_types: union HASHKEY { long i; float f; void *p; }


hashAdd

original_code:
int hashAdd (HASH hx, HASHKEY k)
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  long int hash, delta = 0 ;
  int test ;
  if (!h->guard)
    hashDouble (h) ;
  { register int z = IS5, x = k.i ; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
  while (1)
    if (!h->keys[hash] || h->keys[hash] == REMOVED)
      { if (!h->keys[hash]) --h->guard ;
 h->keys[hash] = k.i ;
 if (h->nFree)
   h->values[hash] = ((*(int*)((h->freeList)->base + (h->nFree--)*(h->freeList)->size))) ;
 else
   h->values[hash] = ++h->n ;
 nAdded++ ;
 return h->values[hash] ;
      }
    else if (h->keys[hash] == k.i)
      return h->values[hash] ;
    else
      { nBounced++ ;
 if (!delta) { register int z = IS7, x = k.i ; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
 hash = (hash + delta) & h->mask ;
      }
}

canonical_original_code:
int hashAdd(void *hx, union HASHKEY k)
{
  struct TRUE_HASH *h = (TRUE_HASH*) hx;
  long hash; long delta = 0;
  int test;
  if (!h->guard)
    hashDouble (h) ;
  { register int z = IS5; register int x = k.i; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
  while (1)
    if (!h->keys[hash] || h->keys[hash] == REMOVED)
      { if (!h->keys[hash]) --h->guard ;
 h->keys[hash] = k.i ;
 if (h->nFree)
   h->values[hash] = ((*(int *)((h->freeList)->base + (h->nFree--)*(h->freeList)->size))) ;
 else
   h->values[hash] = ++h->n ;
 nAdded++ ;
 return h->values[hash] ;
      }
    else if (h->keys[hash] == k.i)
      return h->values[hash] ;
    else
      { nBounced++ ;
 if (!delta) { register int z = IS7; register int x = k.i; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
 hash = (hash + delta) & h->mask ;
      }
}

variable_types: test int


hashRemove

original_code:
BOOL hashRemove (HASH hx, HASHKEY k)
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  long int hash, delta = 0 ;
  { register int z = IS5, x = k.i ; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
  while (1)
    if (h->keys[hash] == k.i)
      { h->keys[hash] = REMOVED ;
 (*(int*)uArray(h->freeList,++h->nFree)) = h->values[hash] ;
 ++nFound ;
 return 1 ;
      }
    else if (!h->keys[hash])
      { nNotFound++ ;
 return 0 ;
      }
    else
      { nBounced++ ;
 if (!delta) { register int z = IS7, x = k.i ; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
 hash = (hash + delta) & h->mask ;
      }
}

canonical_original_code:
char hashRemove(void *hx, union HASHKEY k)
{
  struct TRUE_HASH *h = (TRUE_HASH*) hx;
  long hash; long delta = 0;
  { register int z = IS5; register int x = k.i; for (hash = x, x >>= 5 ; z-- ; x >>= 5) hash ^= x ; hash &= h->mask ; } ;
  while (1)
    if (h->keys[hash] == k.i)
      { h->keys[hash] = REMOVED ;
 (*(int *)uArray(h->freeList,++h->nFree)) = h->values[hash] ;
 ++nFound ;
 return 1 ;
      }
    else if (!h->keys[hash])
      { nNotFound++ ;
 return 0 ;
      }
    else
      { nBounced++ ;
 if (!delta) { register int z = IS7; register int x = k.i; for (delta = x, x >>= 7 ; z-- ; x >>= 7) delta ^= x ; delta = (delta & h->mask) | 0x01 ; } ;
 hash = (hash + delta) & h->mask ;
      }
}

return_type: char


hashInitIterator

decompiled_code:
void __fastcall hashInitIterator(__int64 a1)
{
*(_DWORD *)(a1 + 44) = -1;
}

original_code:
void hashInitIterator (HASH hx)
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  h->iter = -1 ;
}

canonical_original_code:
void hashInitIterator(void *hx)
{
  struct TRUE_HASH *h = (TRUE_HASH*) hx;
  h->iter = -1 ;
}


hashNextKeyValue

decompiled_code:
__int64 __fastcall hashNextKeyValue(__int64 a1, _QWORD *a2, _DWORD *a3)
{
__int64 v4; // rdx
int v5; // eax
int v6; // er8
__int64 i; // rdx
__int64 v8; // rcx
__int64 result; // rax
__int64 v10; // rax

v4 = *(int *)(a1 + 44);
v5 = v4 + 1;
v6 = 1 << *(_DWORD *)a1;
for ( i = 4 * v4 + 4; ; i += 4LL )
{
*(_DWORD *)(a1 + 44) = v5;
if ( v5 >= v6 )
return 0LL;
++v5;
v8 = *(int *)(*(_QWORD *)(a1 + 16) + i);
if ( (unsigned int)v8 > 1 )
break;
}
v10 = *(_QWORD *)(a1 + 24);
*a2 = v8;
result = *(unsigned int *)(v10 + i);
*a3 = result;
return result;
}

original_code:
int hashNextKeyValue (HASH hx, HASHKEY *kp, int *ip)
{
  TRUE_HASH *h = (TRUE_HASH*) hx ;
  int size = 1 << h->nbits ;
  while (++h->iter < size)
    if (h->keys[h->iter] && h->keys[h->iter] != REMOVED)
      { kp->i = h->keys[h->iter] ;
 *ip = h->values[h->iter] ;
 return *ip ;
      }
  return 0 ;
}

canonical_original_code:
int hashNextKeyValue(void *hx, union HASHKEY *kp, int *ip)
{
  struct TRUE_HASH *h = (TRUE_HASH*) hx;
  int size = 1 << h->nbits;
  while (++h->iter < size)
    if (h->keys[h->iter] && h->keys[h->iter] != REMOVED)
      { kp->i = h->keys[h->iter] ;
 *ip = h->values[h->iter] ;
 return *ip ;
      }
  return 0 ;
}

variable_types: union HASHKEY { long i; float f; void *p; } *

variable_types:
ip
int *

variable_types: size int


hashStats

decompiled_code:
int hashStats()
{
printf(
"%d hashes (%d created, %d destroyed)\n",
(unsigned int)(nCreated - nDestroyed),
(unsigned int)nCreated,
(unsigned int)nDestroyed);
return printf(
"%d added, %d found, %d bounced, %d not found\n",
(unsigned int)nAdded,
(unsigned int)nFound,
(unsigned int)nBounced,
(unsigned int)nNotFound);
}

canonical_decompiled_code:
int func9()
{
printf(
"%d hashes (%d created, %d destroyed)\n",
(unsigned int)(nCreated - nDestroyed),
(unsigned int)nCreated,
(unsigned int)nDestroyed);
return printf(
"%d added, %d found, %d bounced, %d not found\n",
(unsigned int)nAdded,
(unsigned int)nFound,
(unsigned int)nBounced,
(unsigned int)nNotFound);
}

original_code:
void hashStats (void)
{
  printf ("%d hashes (%d created, %d destroyed)\n",
   nCreated - nDestroyed, nCreated, nDestroyed) ;
  printf ("%d added, %d found, %d bounced, %d not found\n",
   nAdded, nFound, nBounced, nNotFound) ;
}

canonical_original_code:
void hashStats()
{
  printf ("%d hashes (%d created, %d destroyed)\n",
   nCreated - nDestroyed, nCreated, nDestroyed) ;
  printf ("%d added, %d found, %d bounced, %d not found\n",
   nAdded, nFound, nBounced, nNotFound) ;
}


hashString

decompiled_code:
__int64 __fastcall hashString(_BYTE *a1, unsigned int a2, int a3)
{
int v3; // eax
unsigned int v5; // er8
int v6; // ecx
unsigned int v7; // edx
char i; // cl
unsigned int v9; // eax
int v10; // ecx
unsigned int v11; // esi
__int64 result; // rax

v3 = (char)*a1;
v5 = a2;
v6 = -(a3 == 0);
v7 = 0;
for ( i = (v6 & 0xF8) + 21; *a1; v3 = (char)*a1 )
{
++a1;
v7 = v3 ^ __ROL4__(v7, i);
}
v9 = v7;
if ( a2 <= 3 )
{
v10 = a2;
do
{
v11 = v7 >> v10;
v10 += v5;
v9 ^= v11;
}
while ( v10 <= 3 );
}
result = ((1 << v5) - 1) & v9;
if ( a3 )
result = (unsigned int)result | 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned int a2, int a3)
{
int v3; // eax
unsigned int v5; // er8
int v6; // ecx
unsigned int v7; // edx
char i; // cl
unsigned int v9; // eax
int v10; // ecx
unsigned int v11; // esi
__int64 result; // rax

v3 = (char)*a1;
v5 = a2;
v6 = -(a3 == 0);
v7 = 0;
for ( i = (v6 & 0xF8) + 21; *a1; v3 = (char)*a1 )
{
++a1;
v7 = v3 ^ __ROL4__(v7, i);
}
v9 = v7;
if ( a2 <= 3 )
{
v10 = a2;
do
{
v11 = v7 >> v10;
v10 += v5;
v9 ^= v11;
}
while ( v10 <= 3 );
}
result = ((1 << v5) - 1) & v9;
if ( a3 )
result = (unsigned int)result | 1;
return result;
}

original_code:
static int hashString (char *cp, int n, int isDiff)
{
  int i ;
  unsigned int j, x = 0 ;
  int rotate = isDiff ? 21 : 13 ;
  int leftover = 8 * sizeof(int) - rotate ;
  while (*cp)
    x = (*cp++) ^ ((x >> leftover) | (x << rotate)) ;
  for (j = x, i = n ; i < sizeof(int) ; i += n)
    j ^= (x >> i) ;
  j &= (1 << n) - 1 ;
  if (isDiff)
    j |= 1 ;
  return j ;
}

canonical_original_code:
static int hashString(char *cp, int n, int isDiff)
{
  int i;
  unsigned int j; unsigned int x = 0;
  int rotate = isDiff ? 21 : 13;
  int leftover = 8 * sizeof(int) - rotate;
  while (*cp)
    x = (*cp++) ^ ((x >> leftover) | (x << rotate)) ;
  for (j = x, i = n ; i < sizeof(int) ; i += n)
    j ^= (x >> i) ;
  j &= (1 << n) - 1 ;
  if (isDiff)
    j |= 1 ;
  return j ;
}

variable_types:
cp
char *

variable_types: isDiff int

variable_types: i int

variable_types:
j
unsigned int

variable_types:
x
unsigned int

variable_types: rotate int

variable_types: leftover int


remap

decompiled_code:
void *__fastcall remap(void *ptr, int a2, int a3)
{
void *v3; // r12

v3 = (void *)mycalloc(a3, 1LL);
memcpy(v3, ptr, a2);
free(ptr);
return v3;
}

canonical_decompiled_code:
void *__fastcall func1(void *ptr, int a2, int a3)
{
void *v3; // r12

v3 = (void *)mycalloc(a3, 1LL);
memcpy(v3, ptr, a2);
free(ptr);
return v3;
}

original_code:
static void* remap (void *old, int oldSize, int newSize)
{
  void* new = _mycalloc (newSize, 1) ;
  memcpy (new, old, oldSize) ;
  free (old) ;
  return new ;
}

canonical_original_code:
static void *remap(void *old, int oldSize, int newSize)
{
  void *new = _mycalloc (newSize, 1);
  memcpy (new, old, oldSize) ;
  free (old) ;
  return new ;
}

variable_types:
old
void *

variable_types: oldSize int

variable_types: newSize int

variable_types:
new
void *


dictCreate

original_code:
DICT *dictCreate (int size)
{
  DICT *dict = (DICT*)_mycalloc(1,sizeof(DICT)) ;
  for (dict->dim = 10, dict->size = 1024 ; dict->size < size ; ++dict->dim, dict->size *= 2) ;
  dict->table = (int*)_mycalloc(dict->size,sizeof(int)) ;
  dict->names = (char**)_mycalloc(dict->size/2,sizeof(char*)) ;
  return dict ;
}

canonical_original_code:
struct DICT *dictCreate(int size)
{
  struct DICT *dict = (DICT*)_mycalloc(1,sizeof(DICT));
  for (dict->dim = 10, dict->size = 1024 ; dict->size < size ; ++dict->dim, dict->size *= 2) ;
  dict->table = (int *)_mycalloc(dict->size,sizeof(int)) ;
  dict->names = (char **)_mycalloc(dict->size/2,sizeof(char *)) ;
  return dict ;
}

variable_types: struct DICT { char **names; int *table; int max; int dim; int size; } *


dictDestroy

decompiled_code:
void __fastcall dictDestroy(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rbx

if ( *((int *)ptr + 4) > 0 )
{
v1 = 0LL;
do
{
v2 = v1 + 1;
free(*(void **)(*(_QWORD *)ptr + 8 * (v1 + 1)));
v1 = v2;
}
while ( *((_DWORD *)ptr + 4) >= (int)v2 + 1 );
}
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void dictDestroy (DICT *dict)
{
  int i ;
  for (i = 1 ; i <= dict->max ; ++i) free (dict->names[i]) ;
  free (dict->names) ;
  free (dict->table) ;
  free (dict) ;
}

canonical_original_code:
void dictDestroy(struct DICT *dict)
{
  int i;
  for (i = 1 ; i <= dict->max ; ++i) free (dict->names[i]) ;
  free (dict->names) ;
  free (dict->table) ;
  free (dict) ;
}

user_defined_types: struct DICT { char **names; int *table; int max; int dim; int size; }


dictFind

decompiled_code:
__int64 __fastcall dictFind(__int64 *a1, char *a2, unsigned int *a3)
{
unsigned int v3; // er12
int v4; // eax
__int64 v5; // rbp
int v6; // er14
unsigned int v7; // er15
__int64 v8; // r13
unsigned int v9; // er9
int v10; // er12
int v12; // [rsp+4h] [rbp-44h]

if ( !a1 )
die("dictAdd received null dict\n");
if ( !a2 )
die("dictAdd received null string\n");
v3 = *((_DWORD *)a1 + 5);
v4 = hashString(a2, v3, 0);
v5 = a1[1];
v6 = v4;
v7 = *(_DWORD *)(v5 + 4LL * v4);
if ( !v7 )
{
LABEL_12:
newPos = v6;
return v7;
}
v8 = *a1;
if ( strcmp(a2, *(const char **)(*a1 + 8LL * (int)v7)) )
{
v12 = hashString(a2, v3, 1);
v10 = (1 << v3) - 1;
do
{
v7 = *(_DWORD *)(v5 + 4LL * (v10 & (v6 + v12)));
v6 = v10 & (v6 + v12);
if ( !v7 )
goto LABEL_12;
}
while ( strcmp(a2, *(const char **)(v8 + 8LL * (int)v7)) );
}
if ( !a3 )
return 1;
v9 = v7 - 1;
v7 = 1;
*a3 = v9;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, char *a2, unsigned int *a3)
{
unsigned int v3; // er12
int v4; // eax
__int64 v5; // rbp
int v6; // er14
unsigned int v7; // er15
__int64 v8; // r13
unsigned int v9; // er9
int v10; // er12
int v12; // [rsp+4h] [rbp-44h]

if ( !a1 )
die("dictAdd received null dict\n");
if ( !a2 )
die("dictAdd received null string\n");
v3 = *((_DWORD *)a1 + 5);
v4 = func0(a2, v3, 0);
v5 = a1[1];
v6 = v4;
v7 = *(_DWORD *)(v5 + 4LL * v4);
if ( !v7 )
{
LABEL_12:
newPos = v6;
return v7;
}
v8 = *a1;
if ( strcmp(a2, *(const char **)(*a1 + 8LL * (int)v7)) )
{
v12 = func0(a2, v3, 1);
v10 = (1 << v3) - 1;
do
{
v7 = *(_DWORD *)(v5 + 4LL * (v10 & (v6 + v12)));
v6 = v10 & (v6 + v12);
if ( !v7 )
goto LABEL_12;
}
while ( strcmp(a2, *(const char **)(v8 + 8LL * (int)v7)) );
}
if ( !a3 )
return 1;
v9 = v7 - 1;
v7 = 1;
*a3 = v9;
return v7;
}

original_code:
int dictFind (DICT *dict, char *s, int *ip)
{
  int i, x, d ;
  if (!dict) die ("dictAdd received null dict\n") ;
  if (!s) die ("dictAdd received null string\n") ;
  x = hashString (s, dict->dim, 0) ;
  if (!(i = dict->table[x]))
    { newPos = x ;
      return 0 ;
    }
  else if (!strcmp (s, dict->names[i]))
    { if (ip) *ip = i-1 ;
      return 1 ;
    }
  else
    { d = hashString (s, dict->dim, 1) ;
      while (1)
 { x = (x + d) & ((1 << dict->dim) - 1) ;
   if (!(i = dict->table[x]))
     { newPos = x ;
       return 0 ;
     }
   else if (!strcmp (s, dict->names[i]))
     { if (ip) *ip = i-1 ;
       return 1 ;
     }
 }
    }
}

canonical_original_code:
int dictFind(struct DICT *dict, char *s, int *ip)
{
  int i; int x; int d;
  if (!dict) die ("dictAdd received null dict\n") ;
  if (!s) die ("dictAdd received null string\n") ;
  x = hashString (s, dict->dim, 0) ;
  if (!(i = dict->table[x]))
    { newPos = x ;
      return 0 ;
    }
  else if (!strcmp (s, dict->names[i]))
    { if (ip) *ip = i-1 ;
      return 1 ;
    }
  else
    { d = hashString (s, dict->dim, 1) ;
      while (1)
 { x = (x + d) & ((1 << dict->dim) - 1) ;
   if (!(i = dict->table[x]))
     { newPos = x ;
       return 0 ;
     }
   else if (!strcmp (s, dict->names[i]))
     { if (ip) *ip = i-1 ;
       return 1 ;
     }
 }
    }
}

variable_types:
s
char *

variable_types: x int

variable_types: d int


dictAdd

original_code:
int dictAdd (DICT *dict, char *s, int *ip)
{
  int i, x ;
  if (dictFind (dict, s, ip)) return 0 ;
  i = ++dict->max ;
  dict->table[newPos] = i ;
  dict->names[i] = (char*)_myalloc((strlen(s) + 1)*sizeof(char)) ;
  strcpy (dict->names[i], s) ;
  if (ip) *ip = i-1 ;
  if (dict->max > 0.3 * dict->size)
    { int *newTable ;
      ++dict->dim ; dict->size *= 2 ;
      dict->names = (char**) remap (dict->names, (dict->max+1)*sizeof(char*), (dict->size/2)*sizeof(char*)) ;
      newTable = (int*)_mycalloc(dict->size,sizeof(int)) ;
      for (i = 1 ; i <= dict->max ; ++i)
 { s = dict->names[i] ;
   x = hashString (s, dict->dim, 0) ;
   if (!newTable[x])
     newTable[x] = i ;
   else
     { int d = hashString (s, dict->dim, 1) ;
       while (1)
  { x = (x + d) & ((1 << dict->dim) - 1) ;
    if (!newTable[x])
      { newTable[x] = i ; break ; }
  }
     }
 }
      free (dict->table) ; dict->table = newTable ;
    }
  return 1 ;
}

canonical_original_code:
int dictAdd(struct DICT *dict, char *s, int *ip)
{
  int i; int x;
  if (dictFind (dict, s, ip)) return 0 ;
  i = ++dict->max ;
  dict->table[newPos] = i ;
  dict->names[i] = (char *)_myalloc((strlen(s) + 1)*sizeof(char)) ;
  strcpy (dict->names[i], s) ;
  if (ip) *ip = i-1 ;
  if (dict->max > 0.3 * dict->size)
    { int *newTable;
      ++dict->dim ; dict->size *= 2 ;
      dict->names = (char **) remap (dict->names, (dict->max+1)*sizeof(char *), (dict->size/2)*sizeof(char *)) ;
      newTable = (int *)_mycalloc(dict->size,sizeof(int)) ;
      for (i = 1 ; i <= dict->max ; ++i)
 { s = dict->names[i] ;
   x = hashString (s, dict->dim, 0) ;
   if (!newTable[x])
     newTable[x] = i ;
   else
     { int d = hashString (s, dict->dim, 1);
       while (1)
  { x = (x + d) & ((1 << dict->dim) - 1) ;
    if (!newTable[x])
      { newTable[x] = i ; break ; }
  }
     }
 }
      free (dict->table) ; dict->table = newTable ;
    }
  return 1 ;
}

variable_types:
ip
int *

variable_types:
newTable
int *


dictName

decompiled_code:
__int64 __fastcall dictName(_QWORD *a1, int a2)
{
return *(_QWORD *)(*a1 + 8LL * a2 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, int a2)
{
return *(_QWORD *)(*a1 + 8LL * a2 + 8);
}

original_code:
char* dictName (DICT *dict, int i)
{ return dict->names[i+1] ; }

canonical_original_code:
char *dictName(struct DICT *dict, int i)
{ return dict->names[i+1] ; }

return_type: char *


decompiled_code:
void __fastcall pbwt_reader_destroy(void *ptr)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
pbwtDestroy(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v2));
v3 = *(_QWORD *)(*((_QWORD *)ptr + 5) + 8 * v2++);
pbwtCursorDestroy(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
pbwtDestroy(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v2));
v3 = *(_QWORD *)(*((_QWORD *)ptr + 5) + 8 * v2++);
pbwtCursorDestroy(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
static void pbwt_reader_destroy(pbwt_reader_t *reader)
{
 int i;
 for (i=0; i<reader->n; i++)
 {
  pbwtDestroy(reader->pbwt[i]);
  pbwtCursorDestroy(reader->cursor[i]);
 }
 free(reader->pbwt);
 free(reader->cursor);
 free(reader->unpacked);
 free(reader->cpos);
 free(reader);
}

canonical_original_code:
static void pbwt_reader_destroy(struct pbwt_reader_t *reader)
{
 int i;
 for (i=0; i<reader->n; i++)
 {
  pbwtDestroy(reader->pbwt[i]);
  pbwtCursorDestroy(reader->cursor[i]);
 }
 free(reader->pbwt);
 free(reader->cursor);
 free(reader->unpacked);
 free(reader->cpos);
 free(reader);
}

variable_types: struct pbwt_reader_t { int n; struct PBWTstruct { int N; int M; char *chrom; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *sites; struct ArrayStruct *samples; struct ArrayStruct *yz; int *aFstart; struct ArrayStruct *zz; int *aRstart; struct ArrayStruct *zMissing; struct ArrayStruct *missingOffset; struct ArrayStruct *zDosage; struct ArrayStruct *dosageOffset; char isRefFreq; char isUnphased; } **pbwt; int *cpos; int mpos; char *mals; struct PbwtCursor { int M; struct ArrayStruct *z; long n; char isBlockEnd; unsigned char *y; int c; int *a; int *d; int *u; int *b; int *e; long nBlockStart; } **cursor; int *unpacked; } *

user_defined_types: struct pbwt_reader_t { int n; struct PBWTstruct **pbwt; int *cpos; int mpos; char *mals; struct PbwtCursor **cursor; int *unpacked; }


pbwtMerge

original_code:
PBWT *pbwtMerge(const char **fnames, int nfiles)
{
 pbwt_reader_t *reader = pbwt_reader_init(fnames, nfiles);
 int nhaps = 0, i;
 for (i=0; i<nfiles; i++) nhaps += reader->pbwt[i]->M;
 PBWT *out_pbwt = pbwtCreate(nhaps, 0);
 PbwtCursor *cursor = pbwtNakedCursorCreate(nhaps, 0);
 uchar *yseq = (uchar*)_myalloc((nhaps)*sizeof(uchar));
 out_pbwt->yz = uArrayCreate(1<<20,sizeof(uchar)) ;
 out_pbwt->sites = uArrayReCreate(out_pbwt->sites,reader->pbwt[0]->N,sizeof(Site));
 out_pbwt->chrom = strdup(reader->pbwt[0]->chrom);
 int pos, j;
 while ( (pos=pbwt_reader_next(reader, nfiles)) )
 {
  for (i=0; i<nfiles; i++)
  {
   PBWT *p = reader->pbwt[i];
   Site *site = (((Site*)((p->sites)->base + (reader->cpos[i])*(p->sites)->size)));
   if ( site->x!=pos ) break;
   char *als = dictName(variationDict, site->varD);
   if ( strcmp(als,reader->mals) ) break;
  }
  if ( i!=nfiles )
  {
   for (i=0; i<nfiles; i++)
   {
    PBWT *p = reader->pbwt[i];
    Site *site = (((Site*)((p->sites)->base + (reader->cpos[i])*(p->sites)->size)));
    if ( site->x!=pos ) continue;
    char *als = dictName(variationDict, site->varD);
    if ( strcmp(als,reader->mals) ) continue;
    PbwtCursor *c = reader->cursor[i];
    reader->unpacked[i] += unpack3((((uchar*)((p->yz)->base + (reader->unpacked[i])*(p->yz)->size))), p->M, c->y, 0);
    pbwtCursorForwardsA(c);
   }
   continue;
  }
  int ihap = 0;
  for (i=0; i<nfiles; i++)
  {
   PbwtCursor *c = reader->cursor[i];
   PBWT *p = reader->pbwt[i];
   Site *site = (((Site*)((p->sites)->base + (reader->cpos[i])*(p->sites)->size)));
   reader->unpacked[i] += unpack3((((uchar*)((p->yz)->base + (reader->unpacked[i])*(p->yz)->size))), p->M, c->y, 0);
   for (j=0; j<p->M; j++) yseq[ihap + c->a[j]] = c->y[j];
   pbwtCursorForwardsA(c);
   ihap += p->M;
  }
  for (j=0; j<nhaps; j++)
   cursor->y[j] = yseq[cursor->a[j]];
  pack3arrayAdd(cursor->y, out_pbwt->M, out_pbwt->yz);
  pbwtCursorForwardsA(cursor);
  arrayExtend(out_pbwt->sites, out_pbwt->N+1);
  Site *site = ((Site*)uArray(out_pbwt->sites,out_pbwt->N));
  site->x = pos;
  dictAdd(variationDict, reader->mals, &site->varD);
  out_pbwt->N++;
 }
 pbwtCursorToAFend (cursor, out_pbwt) ;
 free(yseq);
 pbwtCursorDestroy(cursor);
 pbwt_reader_destroy(reader);
 return out_pbwt;
}

canonical_original_code:
struct PBWTstruct *pbwtMerge(char **fnames, int nfiles)
{
 struct pbwt_reader_t *reader = pbwt_reader_init(fnames, nfiles);
 int nhaps = 0; int i;
 for (i=0; i<nfiles; i++) nhaps += reader->pbwt[i]->M;
 struct PBWTstruct *out_pbwt = pbwtCreate(nhaps, 0);
 struct PbwtCursor *cursor = pbwtNakedCursorCreate(nhaps, 0);
 unsigned char *yseq = (uchar*)_myalloc((nhaps)*sizeof(uchar));
 out_pbwt->yz = uArrayCreate(1<<20,sizeof(uchar)) ;
 out_pbwt->sites = uArrayReCreate(out_pbwt->sites,reader->pbwt[0]->N,sizeof(Site));
 out_pbwt->chrom = strdup(reader->pbwt[0]->chrom);
 int pos; int j;
 while ( (pos=pbwt_reader_next(reader, nfiles)) )
 {
  for (i=0; i<nfiles; i++)
  {
   struct PBWTstruct *p = reader->pbwt[i];
   struct SiteStruct *site = (((Site*)((p->sites)->base + (reader->cpos[i])*(p->sites)->size)));
   if ( site->x!=pos ) break;
   char *als = dictName(variationDict, site->varD);
   if ( strcmp(als,reader->mals) ) break;
  }
  if ( i!=nfiles )
  {
   for (i=0; i<nfiles; i++)
   {
    struct PBWTstruct *p = reader->pbwt[i];
    struct SiteStruct *site = (((Site*)((p->sites)->base + (reader->cpos[i])*(p->sites)->size)));
    if ( site->x!=pos ) continue;
    char *als = dictName(variationDict, site->varD);
    if ( strcmp(als,reader->mals) ) continue;
    struct PbwtCursor *c = reader->cursor[i];
    reader->unpacked[i] += unpack3((((unsigned char *)((p->yz)->base + (reader->unpacked[i])*(p->yz)->size))), p->M, c->y, 0);
    pbwtCursorForwardsA(c);
   }
   continue;
  }
  int ihap = 0;
  for (i=0; i<nfiles; i++)
  {
   struct PbwtCursor *c = reader->cursor[i];
   struct PBWTstruct *p = reader->pbwt[i];
   struct SiteStruct *site = (((Site*)((p->sites)->base + (reader->cpos[i])*(p->sites)->size)));
   reader->unpacked[i] += unpack3((((unsigned char *)((p->yz)->base + (reader->unpacked[i])*(p->yz)->size))), p->M, c->y, 0);
   for (j=0; j<p->M; j++) yseq[ihap + c->a[j]] = c->y[j];
   pbwtCursorForwardsA(c);
   ihap += p->M;
  }
  for (j=0; j<nhaps; j++)
   cursor->y[j] = yseq[cursor->a[j]];
  pack3arrayAdd(cursor->y, out_pbwt->M, out_pbwt->yz);
  pbwtCursorForwardsA(cursor);
  arrayExtend(out_pbwt->sites, out_pbwt->N+1);
  struct SiteStruct *site = ((Site*)uArray(out_pbwt->sites,out_pbwt->N));
  site->x = pos;
  dictAdd(variationDict, reader->mals, &site->varD);
  out_pbwt->N++;
 }
 pbwtCursorToAFend (cursor, out_pbwt) ;
 free(yseq);
 pbwtCursorDestroy(cursor);
 pbwt_reader_destroy(reader);
 return out_pbwt;
}

variable_types:
fnames
char **

variable_types: nfiles int

variable_types: nhaps int

variable_types: struct PBWTstruct { int N; int M; char *chrom; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *sites; struct ArrayStruct *samples; struct ArrayStruct *yz; int *aFstart; struct ArrayStruct *zz; int *aRstart; struct ArrayStruct *zMissing; struct ArrayStruct *missingOffset; struct ArrayStruct *zDosage; struct ArrayStruct *dosageOffset; char isRefFreq; char isUnphased; } *

variable_types: struct PbwtCursor { int M; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *z; long n; char isBlockEnd; unsigned char *y; int c; int *a; int *d; int *u; int *b; int *e; long nBlockStart; } *

variable_types:
yseq
unsigned char *

variable_types: pos int

variable_types: j int

variable_types: struct SiteStruct { int x; int varD; double freq; double refFreq; double imputeInfo; } *

variable_types:
als
char *

variable_types: ihap int


uArrayCreate

decompiled_code:
__int64 __fastcall uArrayCreate(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rdx
void *v9; // rdi
int v10; // esi

v4 = a1;
v6 = mycalloc(1LL, 48LL, a3);
if ( isFirst_0 )
isFirst_0 = 0;
if ( a2 <= 0 )
die("negative size %d in uArrayCreate", (unsigned int)a2);
if ( a1 <= 0 )
v4 = 1LL;
*(_DWORD *)v6 = 8918274;
totalAllocatedMemory += v4 * a2;
v7 = mycalloc(v4, (unsigned int)a2, v5);
v9 = reportArray;
*(_QWORD *)(v6 + 16) = v4;
*(_QWORD *)(v6 + 8) = v7;
++totalNumberActive;
v10 = totalNumberCreated + 1;
*(_DWORD *)(v6 + 24) = a2;
*(_QWORD *)(v6 + 32) = 0LL;
totalNumberCreated = v10;
*(_DWORD *)(v6 + 40) = v10;
if ( !v9 )
return v6;
if ( v10 >= 0 )
{
arrayDestroy(v9);
reportArray = 0LL;
return v6;
}
*(_QWORD *)uArray((__int64)v9, v10, v8) = v6;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rdx
void *v9; // rdi
int v10; // esi

v4 = a1;
v6 = mycalloc(1LL, 48LL, a3);
if ( isFirst_0 )
isFirst_0 = 0;
if ( a2 <= 0 )
die("negative size %d in uArrayCreate", (unsigned int)a2);
if ( a1 <= 0 )
v4 = 1LL;
*(_DWORD *)v6 = 8918274;
totalAllocatedMemory += v4 * a2;
v7 = mycalloc(v4, (unsigned int)a2, v5);
v9 = reportArray;
*(_QWORD *)(v6 + 16) = v4;
*(_QWORD *)(v6 + 8) = v7;
++totalNumberActive;
v10 = totalNumberCreated + 1;
*(_DWORD *)(v6 + 24) = a2;
*(_QWORD *)(v6 + 32) = 0LL;
totalNumberCreated = v10;
*(_DWORD *)(v6 + 40) = v10;
if ( !v9 )
return v6;
if ( v10 >= 0 )
{
func0(v9);
reportArray = 0LL;
return v6;
}
*(_QWORD *)func2((__int64)v9, v10, v8) = v6;
return v6;
}

original_code:
Array uArrayCreate (long n, int size)
{
  Array a = (struct ArrayStruct*)_mycalloc(1,sizeof(struct ArrayStruct)) ;
  static int isFirst ;
  if (isFirst)
    { isFirst = 0 ;
      if (0) reportArray = uArrayCreate(512,sizeof(Array)) ;
    }
  if (size <= 0) die ("negative size %d in uArrayCreate", size) ;
  if (n < 1)
    n = 1 ;
  totalAllocatedMemory += n * size ;
  a->magic = 8918274 ;
  a->base = _mycalloc (n, size) ;
  a->dim = n ;
  a->max = 0 ;
  a->size = size ;
  a->id = ++totalNumberCreated ;
  ++totalNumberActive ;
  if (reportArray)
    { if (a->id < 0)
 (*(Array*)uArray(reportArray,a->id)) = a ;
      else
 { arrayDestroy (reportArray) ;
   reportArray = 0 ;
 }
    }
  return a ;
}

canonical_original_code:
struct ArrayStruct *uArrayCreate(long n, int size)
{
  struct ArrayStruct *a = (struct ArrayStruct*)_mycalloc(1,sizeof(struct ArrayStruct));
  static int isFirst;
  if (isFirst)
    { isFirst = 0 ;
      if (0) reportArray = uArrayCreate(512,sizeof(Array)) ;
    }
  if (size <= 0) die ("negative size %d in uArrayCreate", size) ;
  if (n < 1)
    n = 1 ;
  totalAllocatedMemory += n * size ;
  a->magic = 8918274 ;
  a->base = _mycalloc (n, size) ;
  a->dim = n ;
  a->max = 0 ;
  a->size = size ;
  a->id = ++totalNumberCreated ;
  ++totalNumberActive ;
  if (reportArray)
    { if (a->id < 0)
 (*(struct ArrayStruct **)uArray(reportArray,a->id)) = a ;
      else
 { arrayDestroy (reportArray) ;
   reportArray = 0 ;
 }
    }
  return a ;
}

variable_types: n long

variable_types: size int

variable_types: struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *

variable_types: isFirst int


arrayReportMark

decompiled_code:
__int64 arrayReportMark()
{
__int64 result; // rax

result = 0LL;
if ( reportArray )
result = *((unsigned int *)reportArray + 8);
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax

result = 0LL;
if ( reportArray )
result = *((unsigned int *)reportArray + 8);
return result;
}

original_code:
int arrayReportMark (void)
{
  if (reportArray)
    return ((reportArray)->max) ;
  else
    return 0 ;
}

canonical_original_code:
int arrayReportMark()
{
  if (reportArray)
    return ((reportArray)->max) ;
  else
    return 0 ;
}


arrayStatus

decompiled_code:
__int64 __fastcall arrayStatus(_DWORD *a1, _DWORD *a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax
int *v7; // rsi
__int64 v8; // r8
__int64 *v9; // rcx
__int64 v10; // rdx

*a1 = totalNumberCreated;
*a2 = totalNumberActive;
result = totalAllocatedMemory;
v7 = (int *)reportArray;
*a3 = totalAllocatedMemory;
*a4 = 0LL;
if ( v7 && *((__int64 *)v7 + 4) > 0 )
{
v8 = v7[6];
v9 = (__int64 *)*((_QWORD *)v7 + 1);
v10 = 0LL;
do
{
result = *v9;
if ( *v9 )
{
if ( *(_DWORD *)result == 8918274 )
*a4 += *(_QWORD *)(result + 32) * *(int *)(result + 24);
}
++v10;
v9 = (__int64 *)((char *)v9 + v8);
}
while ( *((_QWORD *)v7 + 4) > v10 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, _DWORD *a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax
int *v7; // rsi
__int64 v8; // r8
__int64 *v9; // rcx
__int64 v10; // rdx

*a1 = totalNumberCreated;
*a2 = totalNumberActive;
result = totalAllocatedMemory;
v7 = (int *)reportArray;
*a3 = totalAllocatedMemory;
*a4 = 0LL;
if ( v7 && *((__int64 *)v7 + 4) > 0 )
{
v8 = v7[6];
v9 = (__int64 *)*((_QWORD *)v7 + 1);
v10 = 0LL;
do
{
result = *v9;
if ( *v9 )
{
if ( *(_DWORD *)result == 8918274 )
*a4 += *(_QWORD *)(result + 32) * *(int *)(result + 24);
}
++v10;
v9 = (__int64 *)((char *)v9 + v8);
}
while ( *((_QWORD *)v7 + 4) > v10 );
}
return result;
}

original_code:
void arrayStatus (int *nmadep, int *nusedp,
    long *memAllocp, long *memUsedp)
{
  int i ;
  Array a ;
  *nmadep = totalNumberCreated ;
  *nusedp = totalNumberActive ;
  *memAllocp = totalAllocatedMemory ;
  *memUsedp = 0 ;
  if (reportArray)
    for (i = 0 ; i < ((reportArray)->max) ; ++i)
      if (((a = ((*(Array*)((reportArray)->base + (i)*(reportArray)->size)))) && (a = ((*(Array*)((reportArray)->base + (i)*(reportArray)->size))))->magic == 8918274))
 *memUsedp += a->max * a->size ;
}

canonical_original_code:
void arrayStatus(int *nmadep, int *nusedp, long *memAllocp, long *memUsedp)
{
  int i;
  struct ArrayStruct *a;
  *nmadep = totalNumberCreated ;
  *nusedp = totalNumberActive ;
  *memAllocp = totalAllocatedMemory ;
  *memUsedp = 0 ;
  if (reportArray)
    for (i = 0 ; i < ((reportArray)->max) ; ++i)
      if (((a = ((*(struct ArrayStruct **)((reportArray)->base + (i)*(reportArray)->size)))) && (a = ((*(struct ArrayStruct **)((reportArray)->base + (i)*(reportArray)->size))))->magic == 8918274))
 *memUsedp += a->max * a->size ;
}

variable_types:
nmadep
int *

variable_types:
nusedp
int *

variable_types:
memAllocp
long *

variable_types:
memUsedp
long *

variable_types: i int


reportMinus

decompiled_code:
double *__fastcall reportMinus(int a1, int a2, int a3, double a4, double a5)
{
int v5; // esi
__int64 v6; // rax
double v7; // xmm2_8
double v8; // xmm1_8
__int64 v9; // xmm0_8
double *result; // rax
double v11; // xmm2_8
__int64 v12; // rdx

v5 = a2 - a3;
v6 = 1LL;
v7 = a4 - a5;
v8 = 1000000.0 * (a4 - a5) / (double)v5;
v9 = LC0;
if ( v8 > 0.1 )
{
while ( 1 )
{
v12 = (int)v6++;
if ( v8 <= *(double *)&v9 )
break;
v9 = rateBoundary[v6];
}
}
else
{
v12 = 0LL;
}
result = (double *)((char *)stats + 960 * a1 + 8 * v12);
v11 = v7 + result[40];
++*((_QWORD *)result + 60);
*((_QWORD *)result + 100) += v5;
result[40] = v11;
return result;
}

canonical_decompiled_code:
double *__fastcall func0(int a1, int a2, int a3, double a4, double a5)
{
int v5; // esi
__int64 v6; // rax
double v7; // xmm2_8
double v8; // xmm1_8
__int64 v9; // xmm0_8
double *result; // rax
double v11; // xmm2_8
__int64 v12; // rdx

v5 = a2 - a3;
v6 = 1LL;
v7 = a4 - a5;
v8 = 1000000.0 * (a4 - a5) / (double)v5;
v9 = LC0;
if ( v8 > 0.1 )
{
while ( 1 )
{
v12 = (int)v6++;
if ( v8 <= *(double *)&v9 )
break;
v9 = rateBoundary[v6];
}
}
else
{
v12 = 0LL;
}
result = (double *)((char *)stats + 960 * a1 + 8 * v12);
v11 = v7 + result[40];
++*((_QWORD *)result + 60);
*((_QWORD *)result + 100) += v5;
result[40] = v11;
return result;
}

original_code:
static void reportMinus (int varD, int x1, double g1, int x0, double g0)
{
  double rate = 1000000.0 * (g1 - g0) / (x1 - x0) ;
  int i = 0 ; while (rateBoundary[i] < rate) ++i ;
  ++stats[varD].nMinus[i] ;
  stats[varD].glen[i] += g1 - g0 ;
  stats[varD].len[i] += x1 - x0 ;
}

canonical_original_code:
static void reportMinus(int varD, int x1, double g1, int x0, double g0)
{
  double rate = 1000000.0 * (g1 - g0) / (x1 - x0);
  int i = 0; while (rateBoundary[i] < rate) ++i ;
  ++stats[varD].nMinus[i] ;
  stats[varD].glen[i] += g1 - g0 ;
  stats[varD].len[i] += x1 - x0 ;
}

variable_types: varD int

variable_types: rate double


reportPlus

decompiled_code:
double *__fastcall reportPlus(int a1, int a2, int a3, double a4, double a5)
{
int v5; // esi
__int64 v6; // rax
double v7; // xmm2_8
double v8; // xmm1_8
__int64 v9; // xmm0_8
double *result; // rax
double v11; // xmm2_8
__int64 v12; // rdx

v5 = a2 - a3;
v6 = 1LL;
v7 = a4 - a5;
v8 = 1000000.0 * (a4 - a5) / (double)v5;
v9 = LC0;
if ( v8 > 0.1 )
{
while ( 1 )
{
v12 = (int)v6++;
if ( v8 <= *(double *)&v9 )
break;
v9 = *(__int64 *)&rateBoundary[v6];
}
}
else
{
v12 = 0LL;
}
result = (double *)((char *)stats + 960 * a1 + 8 * v12);
v11 = v7 + result[40];
++*((_QWORD *)result + 80);
*((_QWORD *)result + 100) += v5;
result[40] = v11;
return result;
}

canonical_decompiled_code:
double *__fastcall func1(int a1, int a2, int a3, double a4, double a5)
{
int v5; // esi
__int64 v6; // rax
double v7; // xmm2_8
double v8; // xmm1_8
__int64 v9; // xmm0_8
double *result; // rax
double v11; // xmm2_8
__int64 v12; // rdx

v5 = a2 - a3;
v6 = 1LL;
v7 = a4 - a5;
v8 = 1000000.0 * (a4 - a5) / (double)v5;
v9 = LC0;
if ( v8 > 0.1 )
{
while ( 1 )
{
v12 = (int)v6++;
if ( v8 <= *(double *)&v9 )
break;
v9 = *(__int64 *)&rateBoundary[v6];
}
}
else
{
v12 = 0LL;
}
result = (double *)((char *)stats + 960 * a1 + 8 * v12);
v11 = v7 + result[40];
++*((_QWORD *)result + 80);
*((_QWORD *)result + 100) += v5;
result[40] = v11;
return result;
}

original_code:
static void reportPlus (int varD, int x1, double g1, int x0, double g0)
{
  double rate = 1000000.0 * (g1 - g0) / (x1 - x0) ;
  int i = 0 ; while (rateBoundary[i] < rate) ++i ;
  ++stats[varD].nPlus[i] ;
  stats[varD].glen[i] += g1 - g0 ;
  stats[varD].len[i] += x1 - x0 ;
}

canonical_original_code:
static void reportPlus(int varD, int x1, double g1, int x0, double g0)
{
  double rate = 1000000.0 * (g1 - g0) / (x1 - x0);
  int i = 0; while (rateBoundary[i] < rate) ++i ;
  ++stats[varD].nPlus[i] ;
  stats[varD].glen[i] += g1 - g0 ;
  stats[varD].len[i] += x1 - x0 ;
}


buildMap

decompiled_code:
__int64 buildMap()
{
int *v0; // rsi
__int64 v1; // rax
int v2; // er13
int v3; // er12
_DWORD *v4; // rbx
double *v5; // rbp
__int64 result; // rax
__int64 v7; // r13
int v8; // eax
int i; // edx
__int64 v10; // rsi
double v11; // xmm0_8

v0 = *(int **)(qword_AA8 + 8);
v1 = *(int *)(qword_AA8 + 24) * (*(_QWORD *)(qword_AA8 + 32) - 1LL);
dword_AB8 = *v0;
v2 = *(int *)((char *)v0 + v1) - dword_AB8;
v3 = v2 / 100;
qword_AC0 = uArrayReCreate(qword_AC0, v2 / 100, 8LL);
v4 = *(_DWORD **)(qword_AA8 + 8);
v5 = *(double **)(qword_AB0 + 8);
result = uArray(qword_AC0, 0LL);
*(_QWORD *)result = 0LL;
if ( v2 > 99 )
{
v7 = 1LL;
do
{
v8 = v4[1];
for ( i = dword_AB8 + 100 * v7; v8 < i; ++v5 )
{
v8 = v4[2];
++v4;
}
v10 = v7++;
v11 = *v5 + (double)(i - *v4) * (v5[1] - *v5) / (double)(v8 - *v4);
*(double *)uArray(qword_AC0, v10) = v11;
result = (unsigned int)(v7 - 1);
}
while ( v3 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int *v0; // rsi
__int64 v1; // rax
int v2; // er13
int v3; // er12
_DWORD *v4; // rbx
double *v5; // rbp
__int64 result; // rax
__int64 v7; // r13
int v8; // eax
int i; // edx
__int64 v10; // rsi
double v11; // xmm0_8

v0 = *(int **)(qword_AA8 + 8);
v1 = *(int *)(qword_AA8 + 24) * (*(_QWORD *)(qword_AA8 + 32) - 1LL);
dword_AB8 = *v0;
v2 = *(int *)((char *)v0 + v1) - dword_AB8;
v3 = v2 / 100;
qword_AC0 = uArrayReCreate(qword_AC0, v2 / 100, 8LL);
v4 = *(_DWORD **)(qword_AA8 + 8);
v5 = *(double **)(qword_AB0 + 8);
result = uArray(qword_AC0, 0LL);
*(_QWORD *)result = 0LL;
if ( v2 > 99 )
{
v7 = 1LL;
do
{
v8 = v4[1];
for ( i = dword_AB8 + 100 * v7; v8 < i; ++v5 )
{
v8 = v4[2];
++v4;
}
v10 = v7++;
v11 = *v5 + (double)(i - *v4) * (v5[1] - *v5) / (double)(v8 - *v4);
*(double *)uArray(qword_AC0, v10) = v11;
result = (unsigned int)(v7 - 1);
}
while ( v3 > (int)result );
}
return result;
}

original_code:
static void buildMap (void)
{
  map.x0 = ((*(int*)((map.x)->base + (0)*(map.x)->size))) ;
  int n = (((*(int*)((map.x)->base + (((map.x)->max)-1)*(map.x)->size))) - map.x0) / 100 ;
  map.z = uArrayReCreate(map.z,n,sizeof(double)) ;
  int i = 0, *mapx = (((int*)((map.x)->base + (0)*(map.x)->size))) ;
  double *mapg = (((double*)((map.g)->base + (0)*(map.g)->size))) ;
  (*(double*)uArray(map.z,i)) = 0.0 ;
  while (i++ < n)
    { int xi = map.x0 + 100*i ;
      while (mapx[1] < xi) { ++mapx ; ++mapg ; }
      (*(double*)uArray(map.z,i)) =
 *mapg + (xi - mapx[0]) * (mapg[1] - mapg[0]) / (mapx[1] - mapx[0]) ;
    }
}

canonical_original_code:
static void buildMap()
{
  map.x0 = ((*(int *)((map.x)->base + (0)*(map.x)->size))) ;
  int n = (((*(int*)((map.x)->base + (((map.x)->max)-1)*(map.x)->size))) - map.x0) / 100;
  map.z = uArrayReCreate(map.z,n,sizeof(double)) ;
  int i = 0; int *mapx = (((int*)((map.x)->base + (0)*(map.x)->size)));
  double *mapg = (((double*)((map.g)->base + (0)*(map.g)->size)));
  (*(double *)uArray(map.z,i)) = 0.0 ;
  while (i++ < n)
    { int xi = map.x0 + 100*i;
      while (mapx[1] < xi) { ++mapx ; ++mapg ; }
      (*(double *)uArray(map.z,i)) =
 *mapg + (xi - mapx[0]) * (mapg[1] - mapg[0]) / (mapx[1] - mapx[0]) ;
    }
}

variable_types: n int

variable_types:
mapx
int *

variable_types:
mapg
double *

variable_types: xi int


finalReport

decompiled_code:
int finalReport()
{
__int64 v0; // rdi
double *v1; // rax
__int64 v2; // r13
unsigned int v3; // er14
__int64 i; // rbx
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // r15
const char *v8; // rax
double v9; // xmm0_8
double v11; // [rsp+8h] [rbp-40h]

puts(" rate\tvar\t\tlen\tglen\tminus\t\tplus");
v0 = variationDict;
LODWORD(v1) = *(_DWORD *)(variationDict + 16LL);
if ( (int)v1 > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
for ( i = 0LL; i != 20; ++i )
{
while ( 1 )
{
v1 = (double *)((char *)stats + 8 * i + v2);
v5 = *((_QWORD *)v1 + 60);
v6 = *((_QWORD *)v1 + 80);
if ( v6 + v5 )
break;
if ( ++i == 20 )
goto LABEL_7;
}
v7 = *((_QWORD *)v1 + 100);
v11 = v1[40];
v8 = (const char *)dictName(v0, v3);
v9 = rateBoundary[i];
LODWORD(v1) = printf("%.2f\t%s\t%12ld\t%.4g\t%12ld\t%12ld\n", v9, v8, v7, v11, v5, v6);
v0 = variationDict;
}
LABEL_7:
++v3;
v2 += 960LL;
}
while ( *(_DWORD *)(v0 + 16) > (signed int)v3 );
}
return (int)v1;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rdi
double *v1; // rax
__int64 v2; // r13
unsigned int v3; // er14
__int64 i; // rbx
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // r15
const char *v8; // rax
double v9; // xmm0_8
double v11; // [rsp+8h] [rbp-40h]

puts(" rate\tvar\t\tlen\tglen\tminus\t\tplus");
v0 = variationDict;
LODWORD(v1) = *(_DWORD *)(variationDict + 16LL);
if ( (int)v1 > 0 )
{
v2 = 0LL;
v3 = 0;
do
{
for ( i = 0LL; i != 20; ++i )
{
while ( 1 )
{
v1 = (double *)((char *)stats + 8 * i + v2);
v5 = *((_QWORD *)v1 + 60);
v6 = *((_QWORD *)v1 + 80);
if ( v6 + v5 )
break;
if ( ++i == 20 )
goto LABEL_7;
}
v7 = *((_QWORD *)v1 + 100);
v11 = v1[40];
v8 = (const char *)dictName(v0, v3);
v9 = rateBoundary[i];
LODWORD(v1) = printf("%.2f\t%s\t%12ld\t%.4g\t%12ld\t%12ld\n", v9, v8, v7, v11, v5, v6);
v0 = variationDict;
}
LABEL_7:
++v3;
v2 += 960LL;
}
while ( *(_DWORD *)(v0 + 16) > (signed int)v3 );
}
return (int)v1;
}

original_code:
static void finalReport (void)
{
  int v, i ;
  printf (" rate\tvar\t\tlen\tglen\tminus\t\tplus\n") ;
  for (v = 0 ; v < ((variationDict)->max) ; ++v)
    for (i = 0 ; i < 20 ; ++i)
      if (stats[v].nMinus[i] + stats[v].nPlus[i])
 printf ("%.2f\t%s\t%12ld\t%.4g\t%12ld\t%12ld\n", rateBoundary[i],
  dictName (variationDict, v), stats[v].len[i], stats[v].glen[i],
  stats[v].nMinus[i], stats[v].nPlus[i]) ;
}

canonical_original_code:
static void finalReport()
{
  int v; int i;
  printf (" rate\tvar\t\tlen\tglen\tminus\t\tplus\n") ;
  for (v = 0 ; v < ((variationDict)->max) ; ++v)
    for (i = 0 ; i < 20 ; ++i)
      if (stats[v].nMinus[i] + stats[v].nPlus[i])
 printf ("%.2f\t%s\t%12ld\t%.4g\t%12ld\t%12ld\n", rateBoundary[i],
  dictName (variationDict, v), stats[v].len[i], stats[v].glen[i],
  stats[v].nMinus[i], stats[v].nPlus[i]) ;
}

variable_types: v int


geneticMap

decompiled_code:
double __fastcall geneticMap(int a1)
{
int v1; // edi
double result; // xmm0_8
__int64 v3; // rdx
__int64 v4; // rsi
__int64 v5; // rcx

v1 = a1 - dword_AB8;
result = 0.0;
if ( v1 > 0 )
{
v3 = *(_QWORD *)(qword_AC0 + 32) - 1LL;
v4 = *(_QWORD *)(qword_AC0 + 8);
v5 = *(int *)(qword_AC0 + 24);
if ( v1 / 100 >= v3 )
result = *(double *)(v4 + v5 * v3);
else
result = (1.0 - (double)(v1 % 100) * 0.01) * *(double *)(v4 + (int)v5 * (v1 / 100))
+ (double)(v1 % 100) * 0.01 * *(double *)(v4 + (int)v5 + (int)v5 * (v1 / 100));
}
return result;
}

original_code:
double geneticMap (int x)
{
  x -= map.x0 ;
  if (x <= 0) return 0.0 ;
  int xi = x / 100 ;
  if (xi >= ((map.z)->max)-1) return ((*(double*)((map.z)->base + (((map.z)->max)-1)*(map.z)->size))) ;
  double xx = 0.01 * (x % 100) ;
  return (1-xx) * ((*(double*)((map.z)->base + (xi)*(map.z)->size))) + xx * ((*(double*)((map.z)->base + (xi+1)*(map.z)->size))) ;
}

canonical_original_code:
double geneticMap(int x)
{
  x -= map.x0 ;
  if (x <= 0) return 0.0 ;
  int xi = x / 100;
  if (xi >= ((map.z)->max)-1) return ((*(double *)((map.z)->base + (((map.z)->max)-1)*(map.z)->size))) ;
  double xx = 0.01 * (x % 100);
  return (1-xx) * ((*(double *)((map.z)->base + (xi)*(map.z)->size))) + xx * ((*(double *)((map.z)->base + (xi+1)*(map.z)->size))) ;
}

variable_types: x int

variable_types: xx double

return_type: double


decompiled_code:
void __fastcall pbwt4hapsStats(__int64 a1, __m128 a2)
{
const char *v3; // r12
const char *v4; // rbp
__int64 v5; // rsi
char *v6; // rax
char *v7; // rcx
int v8; // ebp
__int64 v9; // rdx
int v10; // ebx
__int64 v11; // rdi
int v12; // ebp
__int64 v13; // rbx
__int64 v14; // r12
int v15; // er9
__int64 v16; // r10
int v17; // er10
__m128 v18; // xmm3
__int64 v19; // rax
char v20; // cl
__int64 v21; // rdx
int v22; // edx
__int64 v23; // rcx
__int64 v24; // r8
int v25; // edi
int v26; // er11
__int64 v27; // r14
int v28; // esi
int v29; // edx
char *v30; // r15
int v31; // ebp
int *v32; // r11
int v33; // edx
double v34; // xmm1_8
_DWORD *v35; // rbx
_DWORD *v36; // rax
__int64 v37; // rdi
_DWORD *v38; // rbx
_QWORD *v39; // rax
__int64 v40; // rdi
double v41; // rbx
_DWORD *v42; // rax
const char *v43; // rdi
int v44; // [rsp+Ch] [rbp-3Ch]

if ( a1 && *(_QWORD *)(a1 + 16) )
{
if ( qword_AA8 )
goto LABEL_4;
LABEL_31:
fwrite("hap4stats called without a map - using a linear 1cM/Mb map\n", 1uLL, 0x3BuLL, logFile);
qword_AA8 = uArrayCreate(2LL, 4LL);
v35 = *(_DWORD **)(*(_QWORD *)(a1 + 16) + 8LL);
v36 = (_DWORD *)uArray(qword_AA8, 0LL);
v37 = qword_AA8;
*v36 = *v35;
v38 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL)
+ *(int *)(*(_QWORD *)(a1 + 16) + 24LL) * (*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL) - 1LL));
*(_DWORD *)uArray(v37, 1LL) = *v38;
qword_AB0 = uArrayCreate(2LL, 8LL);
v39 = (_QWORD *)uArray(qword_AB0, 0LL);
a2 = 0LL;
v40 = qword_AB0;
*v39 = 0LL;
v41 = (double)(*(_DWORD *)(*(_QWORD *)(qword_AA8 + 8) + *(int *)(qword_AA8 + 24)) - **(_DWORD **)(qword_AA8 + 8))
* 0.000001;
v42 = (_DWORD *)uArray(v40, 1LL);
v43 = *(const char **)(a1 + 8);
*v42 = (int)v41;
map = strdup(v43);
buildMap();
goto LABEL_6;
}
die("hap4stats called without a PBWT with sites");
if ( !qword_AA8 )
goto LABEL_31;
LABEL_4:
v3 = map;
v4 = *(const char **)(a1 + 8);
if ( strcmp(v4, map) )
warn("chrom mismatch in hap4stats: %s != %s", v4, v3);
LABEL_6:
v5 = 960LL;
v6 = (char *)mycalloc(*(int *)(variationDict + 16LL), 960LL);
v8 = *(_DWORD *)(a1 + 4);
stats = v6;
v9 = *(unsigned int *)(variationDict + 16LL);
v10 = v9 - 1;
if ( (_DWORD)v9 )
{
v9 = v10;
v7 = &v6[960 * v10];
do
{
if ( v8 > 0 )
{
v5 = 255LL;
v7 = (char *)memset(v7, 255, 4LL * (unsigned int)(v8 - 1) + 4);
}
--v10;
v7 -= 960;
}
while ( v10 != -1 );
}
v11 = v8;
v12 = 0;
v13 = myalloc(v11, v5, v9, v7);
v14 = pbwtCursorCreate(a1, 1LL, 1LL);
while ( *(_DWORD *)a1 > v12 )
{
if ( *(_DWORD *)v14 - *(_DWORD *)(v14 + 40) > 1 )
{
*(double *)a2.m128_u64 = geneticMap(*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL)
+ v12 * *(_DWORD *)(*(_QWORD *)(a1 + 16) + 24LL)));
v17 = *(_DWORD *)(v16 + 4);
v18 = a2;
if ( *(int *)(a1 + 4) > 0 )
{
v19 = 0LL;
do
{
v20 = *(_BYTE *)(*(_QWORD *)(v14 + 32) + v19);
v21 = *(int *)(*(_QWORD *)(v14 + 48) + 4 * v19++);
*(_BYTE *)(v13 + v21) = v20;
v22 = *(_DWORD *)(a1 + 4);
}
while ( v22 > (int)v19 );
if ( v22 > 3 )
{
v44 = v12;
v23 = 0LL;
v24 = 960LL * v17;
do
{
while ( 1 )
{
v25 = *(unsigned __int8 *)(v13 + v23);
v26 = *(unsigned __int8 *)(v13 + v23 + 1);
v27 = (int)v23;
v28 = *(unsigned __int8 *)(v13 + v23 + 2);
v29 = *(unsigned __int8 *)(v13 + v23 + 3);
if ( v29 + v28 + v25 + v26 == 2 )
break;
v23 += 4LL;
if ( *(_DWORD *)(a1 + 4) <= (int)v23 + 3 )
goto LABEL_27;
}
v30 = (char *)stats + v24;
v31 = v25 + 2 * v26 + 4 * v28 + 8 * v29;
v32 = (int *)((char *)stats + 4 * v23 + v24);
v33 = *v32;
if ( *v32 >= 0 )
{
v34 = *(double *)&v30[8 * (int)v23 + 160];
if ( v33 == v31 || v31 + v33 == 15 )
{
a2.m128_u64[1] = v18.m128_u64[1];
reportMinus(v17, v15, v32[20], *(double *)v18.m128_u64, v34);
}
else
{
a2.m128_u64[1] = v18.m128_u64[1];
reportPlus(v17, v15, v32[20], *(double *)v18.m128_u64, v34);
}
}
v23 += 4LL;
*v32 = v31;
v32[20] = v15;
*(_QWORD *)&v30[8 * v27 + 160] = v18.m128_u64[0];
}
while ( *(_DWORD *)(a1 + 4) > (int)v23 + 3 );
LABEL_27:
v12 = v44;
}
}
}
++v12;
pbwtCursorForwardsRead(v14);
}
finalReport();
free(stats);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __m128 a2)
{
const char *v3; // r12
const char *v4; // rbp
__int64 v5; // rsi
char *v6; // rax
char *v7; // rcx
int v8; // ebp
__int64 v9; // rdx
int v10; // ebx
__int64 v11; // rdi
int v12; // ebp
__int64 v13; // rbx
__int64 v14; // r12
int v15; // er9
__int64 v16; // r10
int v17; // er10
__m128 v18; // xmm3
__int64 v19; // rax
char v20; // cl
__int64 v21; // rdx
int v22; // edx
__int64 v23; // rcx
__int64 v24; // r8
int v25; // edi
int v26; // er11
__int64 v27; // r14
int v28; // esi
int v29; // edx
char *v30; // r15
int v31; // ebp
int *v32; // r11
int v33; // edx
double v34; // xmm1_8
_DWORD *v35; // rbx
_DWORD *v36; // rax
__int64 v37; // rdi
_DWORD *v38; // rbx
_QWORD *v39; // rax
__int64 v40; // rdi
double v41; // rbx
_DWORD *v42; // rax
const char *v43; // rdi
int v44; // [rsp+Ch] [rbp-3Ch]

if ( a1 && *(_QWORD *)(a1 + 16) )
{
if ( qword_AA8 )
goto LABEL_4;
LABEL_31:
fwrite("hap4stats called without a map - using a linear 1cM/Mb map\n", 1uLL, 0x3BuLL, logFile);
qword_AA8 = uArrayCreate(2LL, 4LL);
v35 = *(_DWORD **)(*(_QWORD *)(a1 + 16) + 8LL);
v36 = (_DWORD *)uArray(qword_AA8, 0LL);
v37 = qword_AA8;
*v36 = *v35;
v38 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL)
+ *(int *)(*(_QWORD *)(a1 + 16) + 24LL) * (*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL) - 1LL));
*(_DWORD *)uArray(v37, 1LL) = *v38;
qword_AB0 = uArrayCreate(2LL, 8LL);
v39 = (_QWORD *)uArray(qword_AB0, 0LL);
a2 = 0LL;
v40 = qword_AB0;
*v39 = 0LL;
v41 = (double)(*(_DWORD *)(*(_QWORD *)(qword_AA8 + 8) + *(int *)(qword_AA8 + 24)) - **(_DWORD **)(qword_AA8 + 8))
* 0.000001;
v42 = (_DWORD *)uArray(v40, 1LL);
v43 = *(const char **)(a1 + 8);
*v42 = (int)v41;
map = strdup(v43);
func2();
goto LABEL_6;
}
die("hap4stats called without a PBWT with sites");
if ( !qword_AA8 )
goto LABEL_31;
LABEL_4:
v3 = map;
v4 = *(const char **)(a1 + 8);
if ( strcmp(v4, map) )
warn("chrom mismatch in hap4stats: %s != %s", v4, v3);
LABEL_6:
v5 = 960LL;
v6 = (char *)mycalloc(*(int *)(variationDict + 16LL), 960LL);
v8 = *(_DWORD *)(a1 + 4);
stats = v6;
v9 = *(unsigned int *)(variationDict + 16LL);
v10 = v9 - 1;
if ( (_DWORD)v9 )
{
v9 = v10;
v7 = &v6[960 * v10];
do
{
if ( v8 > 0 )
{
v5 = 255LL;
v7 = (char *)memset(v7, 255, 4LL * (unsigned int)(v8 - 1) + 4);
}
--v10;
v7 -= 960;
}
while ( v10 != -1 );
}
v11 = v8;
v12 = 0;
v13 = myalloc(v11, v5, v9, v7);
v14 = pbwtCursorCreate(a1, 1LL, 1LL);
while ( *(_DWORD *)a1 > v12 )
{
if ( *(_DWORD *)v14 - *(_DWORD *)(v14 + 40) > 1 )
{
*(double *)a2.m128_u64 = func5(*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL)
+ v12 * *(_DWORD *)(*(_QWORD *)(a1 + 16) + 24LL)));
v17 = *(_DWORD *)(v16 + 4);
v18 = a2;
if ( *(int *)(a1 + 4) > 0 )
{
v19 = 0LL;
do
{
v20 = *(_BYTE *)(*(_QWORD *)(v14 + 32) + v19);
v21 = *(int *)(*(_QWORD *)(v14 + 48) + 4 * v19++);
*(_BYTE *)(v13 + v21) = v20;
v22 = *(_DWORD *)(a1 + 4);
}
while ( v22 > (int)v19 );
if ( v22 > 3 )
{
v44 = v12;
v23 = 0LL;
v24 = 960LL * v17;
do
{
while ( 1 )
{
v25 = *(unsigned __int8 *)(v13 + v23);
v26 = *(unsigned __int8 *)(v13 + v23 + 1);
v27 = (int)v23;
v28 = *(unsigned __int8 *)(v13 + v23 + 2);
v29 = *(unsigned __int8 *)(v13 + v23 + 3);
if ( v29 + v28 + v25 + v26 == 2 )
break;
v23 += 4LL;
if ( *(_DWORD *)(a1 + 4) <= (int)v23 + 3 )
goto LABEL_27;
}
v30 = (char *)stats + v24;
v31 = v25 + 2 * v26 + 4 * v28 + 8 * v29;
v32 = (int *)((char *)stats + 4 * v23 + v24);
v33 = *v32;
if ( *v32 >= 0 )
{
v34 = *(double *)&v30[8 * (int)v23 + 160];
if ( v33 == v31 || v31 + v33 == 15 )
{
a2.m128_u64[1] = v18.m128_u64[1];
func0(v17, v15, v32[20], *(double *)v18.m128_u64, v34);
}
else
{
a2.m128_u64[1] = v18.m128_u64[1];
func1(v17, v15, v32[20], *(double *)v18.m128_u64, v34);
}
}
v23 += 4LL;
*v32 = v31;
v32[20] = v15;
*(_QWORD *)&v30[8 * v27 + 160] = v18.m128_u64[0];
}
while ( *(_DWORD *)(a1 + 4) > (int)v23 + 3 );
LABEL_27:
v12 = v44;
}
}
}
++v12;
pbwtCursorForwardsRead(v14);
}
func3();
free(stats);
}

original_code:
void pbwt4hapsStats (PBWT *p)
{
  if (!p || !p->sites) die ("hap4stats called without a PBWT with sites") ;
  if (!map.x)
    { fprintf (logFile, "hap4stats called without a map - using a linear 1cM/Mb map\n") ;
      map.x = uArrayCreate(2,sizeof(int)) ;
      (*(int*)uArray(map.x,0)) = (((Site*)((p->sites)->base + (0)*(p->sites)->size)))->x ;
      (*(int*)uArray(map.x,1)) = (((Site*)((p->sites)->base + (((p->sites)->max)-1)*(p->sites)->size)))->x ;
      map.g = uArrayCreate(2,sizeof(double)) ;
      (*(double*)uArray(map.g,0)) = 0.0 ;
      (*(int*)uArray(map.g,1)) = 0.000001 * (((*(int*)((map.x)->base + (1)*(map.x)->size))) - ((*(int*)((map.x)->base + (0)*(map.x)->size)))) ;
      map.chrom = strdup (p->chrom) ;
      buildMap () ;
    }
  else if (strcmp (p->chrom, map.chrom))
    warn ("chrom mismatch in hap4stats: %s != %s", p->chrom, map.chrom) ;
  stats = (Hap4Stats*)_mycalloc(((variationDict)->max),sizeof(Hap4Stats)) ;
  int i, k ;
  int v ;
  for (v = ((variationDict)->max) ; v-- ; )
    for (i = 0 ; i < p->M ; ++i) stats[v].lastPat[i] = -1 ;
  uchar *x = (uchar*)_myalloc((p->M)*sizeof(uchar)) ;
  PbwtCursor *u = pbwtCursorCreate (p, 1, 1) ;
  for (k = 0 ; k < p->N ; ++k)
    { int pos = (((Site*)((p->sites)->base + (k)*(p->sites)->size)))->x ;
      double g = geneticMap (pos) ;
      v = (((Site*)((p->sites)->base + (k)*(p->sites)->size)))->varD ;
      if (u->M - u->c >= 2)
 { for (i = 0 ; i < p->M ; ++i) x[u->a[i]] = u->y[i] ;
   for (i = 0 ; i+4 <= p->M ; i += 4)
     if (x[i] + x[i+1] + x[i+2] + x[i+3] == 2)
       { int pat = x[i] + (x[i+1]<<1) + (x[i+2]<<2) + (x[i+3]<<3) ;
  if (stats[v].lastPat[i] >= 0)
    { if (pat == stats[v].lastPat[i] || pat + stats[v].lastPat[i] == 15)
        reportMinus (v, pos, g,
       stats[v].lastPos[i], stats[v].lastMap[i]) ;
      else
        reportPlus (v, pos, g,
      stats[v].lastPos[i], stats[v].lastMap[i]) ;
    }
  stats[v].lastPat[i] = pat ;
  stats[v].lastPos[i] = pos ;
  stats[v].lastMap[i] = g ;
       }
 }
      pbwtCursorForwardsRead (u) ;
    }
  finalReport () ;
  free (stats) ;
}

canonical_original_code:
void pbwt4hapsStats(struct PBWTstruct *p)
{
  if (!p || !p->sites) die ("hap4stats called without a PBWT with sites") ;
  if (!map.x)
    { fprintf (logFile, "hap4stats called without a map - using a linear 1cM/Mb map\n") ;
      map.x = uArrayCreate(2,sizeof(int)) ;
      (*(int *)uArray(map.x,0)) = (((struct SiteStruct *)((p->sites)->base + (0)*(p->sites)->size)))->x ;
      (*(int *)uArray(map.x,1)) = (((struct SiteStruct *)((p->sites)->base + (((p->sites)->max)-1)*(p->sites)->size)))->x ;
      map.g = uArrayCreate(2,sizeof(double)) ;
      (*(double *)uArray(map.g,0)) = 0.0 ;
      (*(int *)uArray(map.g,1)) = 0.000001 * (((*(int *)((map.x)->base + (1)*(map.x)->size))) - ((*(int *)((map.x)->base + (0)*(map.x)->size)))) ;
      map.chrom = strdup (p->chrom) ;
      buildMap () ;
    }
  else if (strcmp (p->chrom, map.chrom))
    warn ("chrom mismatch in hap4stats: %s != %s", p->chrom, map.chrom) ;
  stats = (struct Hap4Stats *)_mycalloc(((variationDict)->max),sizeof(Hap4Stats)) ;
  int i; int k;
  int v;
  for (v = ((variationDict)->max) ; v-- ; )
    for (i = 0 ; i < p->M ; ++i) stats[v].lastPat[i] = -1 ;
  unsigned char *x = (uchar*)_myalloc((p->M)*sizeof(uchar));
  struct PbwtCursor *u = pbwtCursorCreate (p, 1, 1);
  for (k = 0 ; k < p->N ; ++k)
    { int pos = (((Site*)((p->sites)->base + (k)*(p->sites)->size)))->x;
      double g = geneticMap (pos);
      v = (((struct SiteStruct *)((p->sites)->base + (k)*(p->sites)->size)))->varD ;
      if (u->M - u->c >= 2)
 { for (i = 0 ; i < p->M ; ++i) x[u->a[i]] = u->y[i] ;
   for (i = 0 ; i+4 <= p->M ; i += 4)
     if (x[i] + x[i+1] + x[i+2] + x[i+3] == 2)
       { int pat = x[i] + (x[i+1]<<1) + (x[i+2]<<2) + (x[i+3]<<3);
  if (stats[v].lastPat[i] >= 0)
    { if (pat == stats[v].lastPat[i] || pat + stats[v].lastPat[i] == 15)
        reportMinus (v, pos, g,
       stats[v].lastPos[i], stats[v].lastMap[i]) ;
      else
        reportPlus (v, pos, g,
      stats[v].lastPos[i], stats[v].lastMap[i]) ;
    }
  stats[v].lastPat[i] = pat ;
  stats[v].lastPos[i] = pos ;
  stats[v].lastMap[i] = g ;
       }
 }
      pbwtCursorForwardsRead (u) ;
    }
  finalReport () ;
  free (stats) ;
}

variable_types: struct PBWTstruct { int N; int M; char *chrom; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *sites; struct ArrayStruct *samples; struct ArrayStruct *yz; int *aFstart; struct ArrayStruct *zz; int *aRstart; struct ArrayStruct *zMissing; struct ArrayStruct *missingOffset; struct ArrayStruct *zDosage; struct ArrayStruct *dosageOffset; char isRefFreq; char isUnphased; } *

variable_types: k int

variable_types:
x
unsigned char *

variable_types: struct PbwtCursor { int M; struct ArrayStruct { int magic; char *base; long dim; int size; long max; int id; } *z; long n; char isBlockEnd; unsigned char *y; int c; int *a; int *d; int *u; int *b; int *e; long nBlockStart; } *

variable_types: pos int

variable_types: g double

variable_types: pat int

user_defined_types: struct SiteStruct { int x; int varD; double freq; double refFreq; double imputeInfo; }

user_defined_types: struct Hap4Stats { int lastPat[20]; double lastMap[20]; long nMinus[20]; }


die

decompiled_code:
void __noreturn die(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("FATAL ERROR: ", 1uLL, 0xDuLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
timeUpdate(stderr);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("FATAL ERROR: ", 1uLL, 0xDuLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
func0(stderr);
exit(-1);
}

original_code:
void die (char *format, ...)
{
  va_list args ;
  __builtin_va_start(args,format) ;
  fprintf (stderr, "FATAL ERROR: ") ;
  vfprintf (stderr, format, args) ;
  fprintf (stderr, "\n") ;
  __builtin_va_end(args) ;
  timeUpdate (stderr) ;
  exit (-1) ;
}

canonical_original_code:
void die(char *format, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,format) ;
  fprintf (stderr, "FATAL ERROR: ") ;
  vfprintf (stderr, format, args) ;
  fprintf (stderr, "\n") ;
  __builtin_va_end(args) ;
  timeUpdate (stderr) ;
  exit (-1) ;
}

variable_types:
format
char *


warn

decompiled_code:
__int64 warn(char *format, ...)
{
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
result = (unsigned int)(count_3 + 1);
count_3 = result;
if ( (int)result > 9 )
die("too many errors");
return result;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
__int64 result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fputc(10, stderr);
result = (unsigned int)(count_3 + 1);
count_3 = result;
if ( (int)result > 9 )
func1("too many errors");
return result;
}

original_code:
void warn (char *format, ...)
{
  static int count = 0 ;
  va_list args ;
  __builtin_va_start(args,format) ;
  fprintf (stderr, "ERROR: ") ;
  vfprintf (stderr, format, args) ;
  fprintf (stderr, "\n") ;
  __builtin_va_end(args) ;
  if (++count > 9) die ("too many errors") ;
}

canonical_original_code:
void warn(char *format, ...)
{
  static int count = 0;
  __builtin_va_list args;
  __builtin_va_start(args,format) ;
  fprintf (stderr, "ERROR: ") ;
  vfprintf (stderr, format, args) ;
  fprintf (stderr, "\n") ;
  __builtin_va_end(args) ;
  if (++count > 9) die ("too many errors") ;
}

variable_types: count int


gzopenTag

decompiled_code:
__int64 __fastcall gzopenTag(char *src, const char *a2, __int64 a3)
{
size_t v4; // rax
char *v5; // rbp
char *v6; // rax
__int64 v7; // r12

if ( strlen(a2) > 0x28 )
die("tag %s in gzopenTag too long - should be < 30 chars", a2);
v4 = strlen(src);
v5 = (char *)myalloc(v4 + 42);
v6 = stpcpy(v5, src);
*v6 = 46;
strcpy(v6 + 1, a2);
v7 = gzopen(v5, a3);
free(v5);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, const char *a2, __int64 a3)
{
size_t v4; // rax
char *v5; // rbp
char *v6; // rax
__int64 v7; // r12

if ( strlen(a2) > 0x28 )
func1("tag %s in gzopenTag too long - should be < 30 chars", a2);
v4 = strlen(src);
v5 = (char *)func3(v4 + 42);
v6 = stpcpy(v5, src);
*v6 = 46;
strcpy(v6 + 1, a2);
v7 = gzopen(v5, a3);
free(v5);
return v7;
}

original_code:
gzFile gzopenTag (char* root, char* tag, char* mode)
{
  if (strlen (tag) > 40) die ("tag %s in gzopenTag too long - should be < 30 chars", tag) ;
  char *fileName = (char*)_myalloc((strlen (root) + 42)*sizeof(char)) ;
  strcpy (fileName, root) ;
  strcat (fileName, ".") ;
  strcat (fileName, tag) ;
  gzFile f = gzopen (fileName, mode) ;
  free (fileName) ;
  return f ;
}

canonical_original_code:
struct gzFile_s *gzopenTag(char *root, char *tag, char *mode)
{
  if (strlen (tag) > 40) die ("tag %s in gzopenTag too long - should be < 30 chars", tag) ;
  char *fileName = (char*)_myalloc((strlen (root) + 42)*sizeof(char));
  strcpy (fileName, root) ;
  strcat (fileName, ".") ;
  strcat (fileName, tag) ;
  struct gzFile_s *f = gzopen (fileName, mode);
  free (fileName) ;
  return f ;
}

variable_types:
root
char *

variable_types:
tag
char *

variable_types:
mode
char *

variable_types:
fileName
char *

variable_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; } *


repo: richardgv/skippy-xd

decompiled_code:
__int64 __fastcall dlist_last(__int64 a1)
{
__int64 result; // rax

for ( result = a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax

for ( result = a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

original_code:
dlist *
dlist_last(dlist *l)
{
 while(l && l->next)
  l = l->next;
 return l;
}

canonical_original_code:
struct dlist_element *dlist_last(struct dlist_element *l)
{
 while(l && l->next)
  l = l->next;
 return l;
}

variable_types:
l
struct dlist_element *

return_type: struct dlist_element { void *data; struct dlist_element *next; struct dlist_element *prev; } *


decompiled_code:
__int64 __fastcall dlist_first(__int64 a1)
{
__int64 result; // rax

for ( result = a1; result && *(_QWORD *)(result + 16); result = *(_QWORD *)(result + 16) )
;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax

for ( result = a1; result && *(_QWORD *)(result + 16); result = *(_QWORD *)(result + 16) )
;
return result;
}

original_code:
dlist *
dlist_first(dlist *l)
{
 while(l && l->prev)
  l = l->prev;
 return l;
}

canonical_original_code:
struct dlist_element *dlist_first(struct dlist_element *l)
{
 while(l && l->prev)
  l = l->prev;
 return l;
}

user_defined_types: struct dlist_element { void *data; struct dlist_element *next; struct dlist_element *prev; }


original_code:
dlist *
dlist_remove(dlist *l)
{
 dlist *n = 0;
 if(! l)
  return 0;
 if(l->prev) {
  n = l->prev;
  l->prev->next = l->next;
 }
 if(l->next) {
  n = l->next;
  l->next->prev = l->prev;
 }
 free(l);
 return n;
}

canonical_original_code:
struct dlist_element *dlist_remove(struct dlist_element *l)
{
 struct dlist_element *n = 0;
 if(! l)
  return 0;
 if(l->prev) {
  n = l->prev;
  l->prev->next = l->next;
 }
 if(l->next) {
  n = l->next;
  l->next->prev = l->prev;
 }
 free(l);
 return n;
}

variable_types: struct dlist_element { void *data; struct dlist_element *next; struct dlist_element *prev; } *


decompiled_code:
__int64 __fastcall dlist_remove_free_data(void **a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *a1;
if ( v2 )
free(v2);
}
return dlist_remove(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(void **a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *a1;
if ( v2 )
free(v2);
}
return func2(a1);
}

original_code:
dlist *
dlist_remove_free_data(dlist *l)
{
 if(l && l->data)
  free(l->data);
 return dlist_remove(l);
}

canonical_original_code:
struct dlist_element *dlist_remove_free_data(struct dlist_element *l)
{
 if(l && l->data)
  free(l->data);
 return dlist_remove(l);
}


decompiled_code:
__int64 __fastcall dlist_same(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = dlist_first(a1);
if ( !result )
return 0LL;
if ( result == a2 )
return 1LL;
while ( 1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
break;
if ( a2 == result )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = func1(a1);
if ( !result )
return 0LL;
if ( result == a2 )
return 1LL;
while ( 1 )
{
result = *(_QWORD *)(result + 8);
if ( !result )
break;
if ( a2 == result )
return 1LL;
}
return result;
}

original_code:
int
dlist_same(dlist *l1, dlist *l2)
{
 l1 = dlist_first(l1);
 while(l1) {
  if(l1 == l2)
   return 1;
  l1 = l1->next;
 }
 return 0;
}

canonical_original_code:
int dlist_same(struct dlist_element *l1, struct dlist_element *l2)
{
 l1 = dlist_first(l1);
 while(l1) {
  if(l1 == l2)
   return 1;
  l1 = l1->next;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall dlist_free(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

v1 = dlist_first(a1);
if ( v1 )
{
v2 = (_QWORD *)v1;
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax
_QWORD *v2; // rbx
void *v3; // rdi

v1 = func1(a1);
if ( v1 )
{
v2 = (_QWORD *)v1;
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
return 0LL;
}

original_code:
dlist *
dlist_free(dlist *l)
{
 l = dlist_first(l);
 while(l) {
  dlist *c = l;
  l = l->next;
  free(c);
 }
 return 0;
}

canonical_original_code:
struct dlist_element *dlist_free(struct dlist_element *l)
{
 l = dlist_first(l);
 while(l) {
  struct dlist_element *c = l;
  l = l->next;
  free(c);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall dlist_join(__int64 a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // rcx

if ( !a1 )
return a2;
if ( a2 )
{
dlist_last(a1);
v3 = dlist_first(a2);
*(_QWORD *)(v4 + 8) = v3;
*(_QWORD *)(v3 + 16) = v4;
}
return a1;
}

original_code:
dlist *
dlist_join(dlist *l, dlist *l2) {
 if (!l) return l2;
 if (!l2) return l;
 dlist *last = dlist_last(l);
 dlist *first2 = dlist_first(l2);
 last->next = first2;
 first2->prev = last;
 return l;
}

canonical_original_code:
struct dlist_element *dlist_join(struct dlist_element *l, struct dlist_element *l2) {
 if (!l) return l2;
 if (!l2) return l;
 struct dlist_element *last = dlist_last(l);
 struct dlist_element *first2 = dlist_first(l2);
 last->next = first2;
 first2->prev = last;
 return l;
}


decompiled_code:
__int64 __fastcall dlist_find(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
int i; // eax

v4 = dlist_first(a1);
if ( !v4 )
return 0LL;
v5 = v4;
for ( i = a2(v4, a3); !i; i = a2(v5, a3) )
{
v5 = *(_QWORD *)(v5 + 8);
if ( !v5 )
return 0LL;
}
return v5;
}

original_code:
dlist *
dlist_find(dlist *l, dlist_match_func func, void *data)
{
 for(l = dlist_first(l); l; l = l->next)
  if(func(l, data))
   break;
 return l;
}

canonical_original_code:
struct dlist_element *dlist_find(struct dlist_element *l, int (*func)(struct dlist_element *, void *), void *data)
{
 for(l = dlist_first(l); l; l = l->next)
  if(func(l, data))
   break;
 return l;
}

variable_types:
func
int (*)(struct dlist_element *, void *)

variable_types:
data
void *


decompiled_code:
void __fastcall dlist_free_data(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

v1 = dlist_first(a1);
if ( v1 )
{
v2 = v1;
do
{
if ( *(_QWORD *)v2 )
free(*(void **)v2);
*(_QWORD *)v2 = 0LL;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
}

original_code:
void
dlist_free_data(dlist *l)
{
 l = dlist_first(l);
 while(l) {
  if(l->data)
   free(l->data);
  l->data = 0;
  l = l->next;
 }
}

canonical_original_code:
void dlist_free_data(struct dlist_element *l)
{
 l = dlist_first(l);
 while(l) {
  if(l->data)
   free(l->data);
  l->data = 0;
  l = l->next;
 }
}


decompiled_code:
__int64 __fastcall dlist_free_with_data(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx

v1 = dlist_first(a1);
if ( v1 )
{
while ( 1 )
{
if ( *(_QWORD *)v1 )
free(*(void **)v1);
v2 = *(_QWORD *)(v1 + 8);
free((void *)v1);
if ( !v2 )
break;
v1 = v2;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rbx

v1 = func1(a1);
if ( v1 )
{
while ( 1 )
{
if ( *(_QWORD *)v1 )
free(*(void **)v1);
v2 = *(_QWORD *)(v1 + 8);
free((void *)v1);
if ( !v2 )
break;
v1 = v2;
}
}
return 0LL;
}

original_code:
dlist *
dlist_free_with_data(dlist *l)
{
 l = dlist_first(l);
 while(l) {
  dlist *c = l;
  if(l->data)
   free(l->data);
  l = l->next;
  free(c);
 }
 return 0;
}

canonical_original_code:
struct dlist_element *dlist_free_with_data(struct dlist_element *l)
{
 l = dlist_first(l);
 while(l) {
  struct dlist_element *c = l;
  if(l->data)
   free(l->data);
  l = l->next;
  free(c);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall dlist_free_with_func(__int64 a1, void (*a2)(void))
{
_QWORD *v2; // rbp
_QWORD *v3; // rbx

v2 = (_QWORD *)dlist_first(a1);
if ( v2 )
{
while ( 1 )
{
if ( *v2 )
a2();
v3 = (_QWORD *)v2[1];
free(v2);
if ( !v3 )
break;
v2 = v3;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, void (*a2)(void))
{
_QWORD *v2; // rbp
_QWORD *v3; // rbx

v2 = (_QWORD *)func1(a1);
if ( v2 )
{
while ( 1 )
{
if ( *v2 )
a2();
v3 = (_QWORD *)v2[1];
free(v2);
if ( !v3 )
break;
v2 = v3;
}
}
return 0LL;
}

original_code:
dlist *
dlist_free_with_func(dlist *l, dlist_free_func func)
{
 l = dlist_first(l);
 while(l) {
  dlist *c = l;
  if(l->data)
   func(l->data);
  l = l->next;
  free(c);
 }
 return 0;
}

canonical_original_code:
struct dlist_element *dlist_free_with_func(struct dlist_element *l, void (*func)(void *))
{
 l = dlist_first(l);
 while(l) {
  struct dlist_element *c = l;
  if(l->data)
   func(l->data);
  l = l->next;
  free(c);
 }
 return 0;
}

variable_types:
func
void (*)(void *)


decompiled_code:
__int64 __fastcall dlist_len(__int64 a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = dlist_first(a1);
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = func1(a1);
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 8);
return i;
}

original_code:
unsigned int
dlist_len(dlist *l)
{
 unsigned int n = 0;
 l = dlist_first(l);
 while(l) {
  n++;
  l = l->next;
 }
 return n;
}

canonical_original_code:
unsigned int dlist_len(struct dlist_element *l)
{
 unsigned int n = 0;
 l = dlist_first(l);
 while(l) {
  n++;
  l = l->next;
 }
 return n;
}

variable_types:
n
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall dlist_nth(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = dlist_first(a1);
if ( result && a2 )
{
v3 = 0;
do
{
result = *(_QWORD *)(result + 8);
++v3;
}
while ( result && a2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // edx

result = func1(a1);
if ( result && a2 )
{
v3 = 0;
do
{
result = *(_QWORD *)(result + 8);
++v3;
}
while ( result && a2 != v3 );
}
return result;
}

original_code:
dlist *
dlist_nth(dlist *l, unsigned int n)
{
 unsigned int i = 0;
 l = dlist_first(l);
 while(l && i != n) {
  i++;
  l = l->next;
 }
 return l;
}

canonical_original_code:
struct dlist_element *dlist_nth(struct dlist_element *l, unsigned int n)
{
 unsigned int i = 0;
 l = dlist_first(l);
 while(l && i != n) {
  i++;
  l = l->next;
 }
 return l;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall dlist_remove_nth(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)dlist_nth(a1, a2);
return dlist_remove(v2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)func13(a1, a2);
return func2(v2);
}

original_code:
dlist *
dlist_remove_nth(dlist *l, unsigned int n)
{
 return dlist_remove(dlist_nth(l, n));
}

canonical_original_code:
struct dlist_element *dlist_remove_nth(struct dlist_element *l, unsigned int n)
{
 return dlist_remove(dlist_nth(l, n));
}


decompiled_code:
__int64 __fastcall dlist_remove_nth_free_data(__int64 a1, int a2)
{
void **v2; // rax

v2 = (void **)dlist_nth(a1, a2);
return dlist_remove_free_data(v2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, int a2)
{
void **v2; // rax

v2 = (void **)func13(a1, a2);
return func3(v2);
}

original_code:
dlist *
dlist_remove_nth_free_data(dlist *l, unsigned int n)
{
 return dlist_remove_free_data(dlist_nth(l, n));
}

canonical_original_code:
struct dlist_element *dlist_remove_nth_free_data(struct dlist_element *l, unsigned int n)
{
 return dlist_remove_free_data(dlist_nth(l, n));
}


decompiled_code:
__int64 __fastcall dlist_reverse(__int64 a1)
{
__int64 result; // rax
__int64 *v2; // rcx
__int64 *i; // rsi
__int64 v4; // rcx

dlist_first(a1);
result = dlist_last(a1);
for ( i = (__int64 *)result; v2 != i; i = (__int64 *)i[2] )
{
result = dlist_swap(v2, i);
v2 = *(__int64 **)(v4 + 8);
if ( v2 == i )
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 result; // rax
__int64 *v2; // rcx
__int64 *i; // rsi
__int64 v4; // rcx

func1(a1);
result = func0(a1);
for ( i = (__int64 *)result; v2 != i; i = (__int64 *)i[2] )
{
result = func16(v2, i);
v2 = *(__int64 **)(v4 + 8);
if ( v2 == i )
break;
}
return result;
}

original_code:
void
dlist_reverse(dlist *l)
{
 dlist *iter1 = dlist_first(l),
  *iter2 = dlist_last(l);
 while(iter1 != iter2) {
  dlist_swap(iter1, iter2);
  if(iter1->next == iter2)
   break;
  iter1 = iter1->next;
  iter2 = iter2->prev;
 }
}

canonical_original_code:
void dlist_reverse(struct dlist_element *l)
{
 struct dlist_element *iter1 = dlist_first(l); struct dlist_element *iter2 = dlist_last(l);
 while(iter1 != iter2) {
  dlist_swap(iter1, iter2);
  if(iter1->next == iter2)
   break;
  iter1 = iter1->next;
  iter2 = iter2->prev;
 }
}


decompiled_code:
__int64 __fastcall dlist_sort(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64, __int64), __int64 a3)
{
__int64 result; // rax
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // rsi

result = dlist_first(a1);
if ( result )
{
v6 = result;
do
{
v7 = v6;
v6 = 0LL;
do
{
v8 = *(_QWORD *)(v7 + 8);
if ( !v8 )
break;
result = a2(v7, v8, a3);
if ( (_DWORD)result == 1 )
{
result = dlist_swap((__int64 *)v7, *(__int64 **)(v7 + 8));
if ( !v6 )
v6 = *(_QWORD *)(v7 + 16);
}
v7 = *(_QWORD *)(v7 + 8);
}
while ( v7 );
}
while ( v6 );
}
return result;
}

original_code:
void
dlist_sort(dlist *l, dlist_cmp_func cmp, void *data)
{
 dlist *start = dlist_first(l);
 while(start) {
  dlist *iter = start;
  start = 0;
  while(iter) {
   if(iter->next && cmp(iter, iter->next, data) == 1) {
    dlist_swap(iter, iter->next);
    if(! start)
     start = iter->prev;
   }
   iter = iter->next;
  }
 }
}

canonical_original_code:
void dlist_sort(struct dlist_element *l, int (*cmp)(struct dlist_element *, struct dlist_element *, void *), void *data)
{
 struct dlist_element *start = dlist_first(l);
 while(start) {
  struct dlist_element *iter = start;
  start = 0;
  while(iter) {
   if(iter->next && cmp(iter, iter->next, data) == 1) {
    dlist_swap(iter, iter->next);
    if(! start)
     start = iter->prev;
   }
   iter = iter->next;
  }
 }
}

variable_types: int (*)(struct dlist_element *, struct dlist_element *, void *)


original_code: static int win_above(dlist *l, SkippyWindow *b) { SkippyWindow *a = &((ClientWin*)l->data)->mini; return a->y + a->height < b->y; }

canonical_original_code: static int win_above(struct dlist_element *l, struct SkippyWindow *b) { struct SkippyWindow *a = &((ClientWin*)l->data)->mini; return a->y + a->height < b->y; }

variable_types: struct SkippyWindow { unsigned long window; int x; int width; struct XRenderPictFormat { unsigned long id; int type; int depth; struct XRenderDirectFormat { short red; short redMask; short green; short greenMask; short blue; short blueMask; short alpha; short alphaMask; } direct; unsigned long colormap; } *format; } *

user_defined_types: struct SkippyWindow { unsigned long window; int x; int width; struct XRenderPictFormat *format; }

user_defined_types: struct XRenderPictFormat { unsigned long id; int type; int depth; struct XRenderDirectFormat direct; unsigned long colormap; }


original_code: static int win_below(dlist *l, SkippyWindow *b) { SkippyWindow *a = &((ClientWin*)l->data)->mini; return b->y + b->height < a->y; }

canonical_original_code: static int win_below(struct dlist_element *l, struct SkippyWindow *b) { struct SkippyWindow *a = &((ClientWin*)l->data)->mini; return b->y + b->height < a->y; }

user_defined_types: struct XRenderDirectFormat { short red; short redMask; short green; short greenMask; short blue; short blueMask; short alpha; short alphaMask; }


original_code: static int win_left(dlist *l, SkippyWindow *b) { SkippyWindow *a = &((ClientWin*)l->data)->mini; return a->x + a->width < b->x; }

canonical_original_code: static int win_left(struct dlist_element *l, struct SkippyWindow *b) { struct SkippyWindow *a = &((ClientWin*)l->data)->mini; return a->x + a->width < b->x; }


original_code: static int win_right(dlist *l, SkippyWindow *b) { SkippyWindow *a = &((ClientWin*)l->data)->mini; return b->x + b->width < a->x; }

canonical_original_code: static int win_right(struct dlist_element *l, struct SkippyWindow *b) { struct SkippyWindow *a = &((ClientWin*)l->data)->mini; return b->x + b->width < a->x; }


decompiled_code:
float __fastcall dist_top_bottom(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[2] + a1[4] / 2 - (a2[2] + a2[4] / 2));
v3 = a1[3] - a2[3] - a2[5];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

canonical_decompiled_code:
float __fastcall func4(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[2] + a1[4] / 2 - (a2[2] + a2[4] / 2));
v3 = a1[3] - a2[3] - a2[5];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

original_code: static float dist_top_bottom (SkippyWindow *a, SkippyWindow *b) { return sqrt(pow((a->x + (int)a->width / 2) - (b->x + (int)b->width / 2), 2) + pow(a->y - b->y - (int)b->height, 2)); }

canonical_original_code: static float dist_top_bottom(struct SkippyWindow *a, struct SkippyWindow *b) { return sqrt(pow((a->x + (int)a->width / 2) - (b->x + (int)b->width / 2), 2) + pow(a->y - b->y - (int)b->height, 2)); }

variable_types:
b
struct SkippyWindow *

return_type: float


decompiled_code:
float __fastcall dist_bottom_top(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[2] + a1[4] / 2 - (a2[2] + a2[4] / 2));
v3 = a2[3] - a1[3] - a1[5];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

canonical_decompiled_code:
float __fastcall func5(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[2] + a1[4] / 2 - (a2[2] + a2[4] / 2));
v3 = a2[3] - a1[3] - a1[5];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

original_code: static float dist_bottom_top (SkippyWindow *a, SkippyWindow *b) { return sqrt(pow((a->x + (int)a->width / 2) - (b->x + (int)b->width / 2), 2) + pow(b->y - a->y - (int)a->height, 2)); }

canonical_original_code: static float dist_bottom_top(struct SkippyWindow *a, struct SkippyWindow *b) { return sqrt(pow((a->x + (int)a->width / 2) - (b->x + (int)b->width / 2), 2) + pow(b->y - a->y - (int)a->height, 2)); }


decompiled_code:
float __fastcall dist_left_right(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[3] + a1[5] / 2 - (a2[3] + a2[5] / 2));
v3 = a1[2] - a2[2] - a2[4];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

canonical_decompiled_code:
float __fastcall func6(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[3] + a1[5] / 2 - (a2[3] + a2[5] / 2));
v3 = a1[2] - a2[2] - a2[4];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

original_code: static float dist_left_right (SkippyWindow *a, SkippyWindow *b) { return sqrt(pow((a->y + (int)a->height / 2) - (b->y + (int)b->height / 2), 2) + pow(a->x - b->x - (int)b->width, 2)); }

canonical_original_code: static float dist_left_right(struct SkippyWindow *a, struct SkippyWindow *b) { return sqrt(pow((a->y + (int)a->height / 2) - (b->y + (int)b->height / 2), 2) + pow(a->x - b->x - (int)b->width, 2)); }


decompiled_code:
float __fastcall dist_right_left(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[3] + a1[5] / 2 - (a2[3] + a2[5] / 2));
v3 = a2[2] - a1[2] - a1[4];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

canonical_decompiled_code:
float __fastcall func7(_DWORD *a1, _DWORD *a2)
{
double v2; // xmm0_8
int v3; // eax
double v4; // xmm0_8
float result; // xmm0_4

v2 = (double)(a1[3] + a1[5] / 2 - (a2[3] + a2[5] / 2));
v3 = a2[2] - a1[2] - a1[4];
v4 = v2 * v2 + (double)v3 * (double)v3;
if ( v4 < 0.0 )
result = sqrt(v4);
else
result = sqrt(v4);
return result;
}

original_code: static float dist_right_left (SkippyWindow *a, SkippyWindow *b) { return sqrt(pow((a->y + (int)a->height / 2) - (b->y + (int)b->height / 2), 2) + pow(b->x - a->x - (int)a->width, 2)); }

canonical_original_code: static float dist_right_left(struct SkippyWindow *a, struct SkippyWindow *b) { return sqrt(pow((a->y + (int)a->height / 2) - (b->y + (int)b->height / 2), 2) + pow(b->x - a->x - (int)a->width, 2)); }


decompiled_code:
void __fastcall entry_free(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
static void
entry_free(ConfigEntry *entry)
{
 free(entry->section);
 free(entry->key);
 free(entry->value);
 free(entry);
}

canonical_original_code:
static void entry_free(struct ConfigEntry *entry)
{
 free(entry->section);
 free(entry->key);
 free(entry->value);
 free(entry);
}

variable_types:
entry
struct ConfigEntry { char *section; } *


decompiled_code:
_BOOL8 __fastcall entry_find_func(const char ***a1, const char **a2)
{
const char **v2; // rbp
int v3; // er8
_BOOL8 result; // rax

v2 = *a1;
v3 = strcasecmp(**a1, *a2);
result = 0LL;
if ( !v3 )
result = strcasecmp(v2[1], a2[1]) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char ***a1, const char **a2)
{
const char **v2; // rbp
int v3; // er8
_BOOL8 result; // rax

v2 = *a1;
v3 = strcasecmp(**a1, *a2);
result = 0LL;
if ( !v3 )
result = strcasecmp(v2[1], a2[1]) == 0;
return result;
}

original_code:
static int
entry_find_func(dlist *l, ConfigEntry *key)
{
 ConfigEntry *entry = (ConfigEntry*)l->data;
 return ! (strcasecmp(entry->section, key->section) || strcasecmp(entry->key, key->key));
}

canonical_original_code:
static int entry_find_func(struct dlist_element *l, struct ConfigEntry *key)
{
 struct ConfigEntry *entry = (ConfigEntry*)l->data;
 return ! (strcasecmp(entry->section, key->section) || strcasecmp(entry->key, key->key));
}

variable_types:
key
struct ConfigEntry { char *section; } *


decompiled_code:
__int64 __fastcall entry_set(__int64 a1, char *a2, char *a3, __int64 a4)
{
__int64 v6; // rax
__int64 v7; // rbx
const char **v8; // r15
_QWORD *v9; // rax
__int64 result; // rax

v6 = dlist_first();
if ( v6 )
{
v7 = v6;
while ( 1 )
{
v8 = *(const char ***)v7;
if ( !strcasecmp(**(const char ***)v7, a2) && !strcasecmp(v8[1], a3) )
break;
v7 = *(_QWORD *)(v7 + 8);
if ( !v7 )
goto LABEL_6;
}
free(a3);
free((void *)v8[2]);
v8[2] = (const char *)a4;
result = a1;
}
else
{
LABEL_6:
v9 = entry_new(a2, (__int64)a3, a4);
result = dlist_add(a1, v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, char *a3, __int64 a4)
{
__int64 v6; // rax
__int64 v7; // rbx
const char **v8; // r15
_QWORD *v9; // rax
__int64 result; // rax

v6 = dlist_first();
if ( v6 )
{
v7 = v6;
while ( 1 )
{
v8 = *(const char ***)v7;
if ( !strcasecmp(**(const char ***)v7, a2) && !strcasecmp(v8[1], a3) )
break;
v7 = *(_QWORD *)(v7 + 8);
if ( !v7 )
goto LABEL_6;
}
free(a3);
free((void *)v8[2]);
v8[2] = (const char *)a4;
result = a1;
}
else
{
LABEL_6:
v9 = entry_new(a2, (__int64)a3, a4);
result = dlist_add(a1, v9);
}
return result;
}

original_code:
static dlist *
entry_set(dlist *config, const char *section, char *key, char *value)
{
 dlist *iter = dlist_first(config);
 ConfigEntry *entry;
 for(; iter; iter = iter->next)
 {
  entry = (ConfigEntry *)iter->data;
  if(! strcasecmp(entry->section, section) && ! strcasecmp(entry->key, key)) {
   free(key);
   free(entry->value);
   entry->value = value;
   return config;
  }
 }
 entry = entry_new(section, key, value);
 return dlist_add(config, entry);
}

canonical_original_code:
static struct dlist_element *entry_set(struct dlist_element *config, char *section, char *key, char *value)
{
 struct dlist_element *iter = dlist_first(config);
 struct ConfigEntry *entry;
 for(; iter; iter = iter->next)
 {
  entry = (struct ConfigEntry *)iter->data;
  if(! strcasecmp(entry->section, section) && ! strcasecmp(entry->key, key)) {
   free(key);
   free(entry->value);
   entry->value = value;
   return config;
  }
 }
 entry = entry_new(section, key, value);
 return dlist_add(config, entry);
}

variable_types:
config
struct dlist_element *

variable_types:
section
char *

variable_types:
key
char *

variable_types:
value
char *


decompiled_code:
__int64 __fastcall config_free(__int64 a1)
{
return dlist_free_with_func(a1, entry_free);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return dlist_free_with_func(a1, entry_free);
}

original_code:
void
config_free(dlist *config)
{
 dlist_free_with_func(config, (dlist_free_func)entry_free);
}

canonical_original_code:
void config_free(struct dlist_element *config)
{
 dlist_free_with_func(config, (void (*)(void *))entry_free);
}