dictFind

decompiled_code:
__int64 __fastcall dictFind(__int64 *a1, char *a2, _DWORD *a3)
{
unsigned int v3; // er15
int v4; // ebx
__int64 v5; // r14
unsigned int v6; // ebp
__int64 v7; // r13
int v9; // er15
int v10; // [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 = *(_DWORD *)(v5 + 4LL * v4);
if ( v6 )
{
v7 = *a1;
if ( !strcmp(a2, *(const char **)(*a1 + 8LL * (int)v6)) )
{
if ( a3 )
*a3 = v6 - 1;
v6 = 1;
}
else
{
v10 = hashString(a2, v3, 1);
v9 = (1 << v3) - 1;
do
{
v4 = v9 & (v10 + v4);
v6 = *(_DWORD *)(v5 + 4LL * v4);
if ( !v6 )
{
newPos = v4;
return v6;
}
}
while ( strcmp(a2, *(const char **)(v7 + 8LL * (int)v6)) );
if ( a3 )
*a3 = v6 - 1;
v6 = 1;
}
}
else
{
newPos = v4;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, char *a2, _DWORD *a3)
{
unsigned int v3; // er15
int v4; // ebx
__int64 v5; // r14
unsigned int v6; // ebp
__int64 v7; // r13
int v9; // er15
int v10; // [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 = *(_DWORD *)(v5 + 4LL * v4);
if ( v6 )
{
v7 = *a1;
if ( !strcmp(a2, *(const char **)(*a1 + 8LL * (int)v6)) )
{
if ( a3 )
*a3 = v6 - 1;
v6 = 1;
}
else
{
v10 = func0(a2, v3, 1);
v9 = (1 << v3) - 1;
do
{
v4 = v9 & (v10 + v4);
v6 = *(_DWORD *)(v5 + 4LL * v4);
if ( !v6 )
{
newPos = v4;
return v6;
}
}
while ( strcmp(a2, *(const char **)(v7 + 8LL * (int)v6)) );
if ( a3 )
*a3 = v6 - 1;
v6 = 1;
}
}
else
{
newPos = v4;
}
return v6;
}

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

repo: richarddurbin/pbwt

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: struct DICT { char **names; int *table; int max; int dim; int size; } *

variable_types:
ip
int *

variable_types: i int

variable_types:
newTable
int *

return_type: 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 *

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


decompiled_code:
void __fastcall pbwt_reader_destroy(void *ptr)
{
__int64 v1; // rbx

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

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
{
pbwtDestroy(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v1));
pbwtCursorDestroy(*(_QWORD *)(*((_QWORD *)ptr + 5) + 8 * v1++));
}
while ( *(_DWORD *)ptr > (int)v1 );
}
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; } *

return_type: void

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

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; }


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

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; }


uArrayCreate

decompiled_code:
__int64 __fastcall uArrayCreate(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // esi

v2 = a1;
v3 = mycalloc(1LL, 48LL);
if ( isFirst_0 )
isFirst_0 = 0;
if ( a2 <= 0 )
die("negative size %d in uArrayCreate", (unsigned int)a2);
if ( a1 <= 0 )
v2 = 1LL;
totalAllocatedMemory += v2 * a2;
*(_DWORD *)v3 = 8918274;
*(_QWORD *)(v3 + 8) = mycalloc(v2, (unsigned int)a2);
*(_QWORD *)(v3 + 16) = v2;
*(_QWORD *)(v3 + 32) = 0LL;
*(_DWORD *)(v3 + 24) = a2;
v4 = totalNumberCreated + 1;
totalNumberCreated = v4;
*(_DWORD *)(v3 + 40) = v4;
++totalNumberActive;
if ( reportArray )
{
if ( v4 < 0 )
{
*(_QWORD *)uArray((__int64)reportArray, v4) = v3;
}
else
{
arrayDestroy(reportArray);
reportArray = 0LL;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 v3; // rbx
int v4; // esi

v2 = a1;
v3 = mycalloc(1LL, 48LL);
if ( isFirst_0 )
isFirst_0 = 0;
if ( a2 <= 0 )
die("negative size %d in uArrayCreate", (unsigned int)a2);
if ( a1 <= 0 )
v2 = 1LL;
totalAllocatedMemory += v2 * a2;
*(_DWORD *)v3 = 8918274;
*(_QWORD *)(v3 + 8) = mycalloc(v2, (unsigned int)a2);
*(_QWORD *)(v3 + 16) = v2;
*(_QWORD *)(v3 + 32) = 0LL;
*(_DWORD *)(v3 + 24) = a2;
v4 = totalNumberCreated + 1;
totalNumberCreated = v4;
*(_DWORD *)(v3 + 40) = v4;
++totalNumberActive;
if ( reportArray )
{
if ( v4 < 0 )
{
*(_QWORD *)func2((__int64)reportArray, v4) = v3;
}
else
{
func0(reportArray);
reportArray = 0LL;
}
}
return v3;
}

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
_QWORD *v7; // rcx
__int64 v8; // rdx

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

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

*a1 = totalNumberCreated;
*a2 = totalNumberActive;
result = totalAllocatedMemory;
*a3 = totalAllocatedMemory;
*a4 = 0LL;
v7 = reportArray;
if ( reportArray && *((__int64 *)reportArray + 4) > 0 )
{
result = 0LL;
do
{
v8 = *(_QWORD *)(v7[1] + *((_DWORD *)v7 + 6) * (int)result);
if ( v8 )
{
if ( *(_DWORD *)v8 == 8918274 )
*a4 += *(_QWORD *)(v8 + 32) * *(int *)(v8 + 24);
}
++result;
}
while ( v7[4] > result );
}
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

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


reportMinus

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

v5 = a4 - a5;
v6 = a2 - a3;
v7 = (a4 - a5) * 1000000.0 / (double)v6;
v8 = 1LL;
if ( v7 <= 0.1 )
{
v9 = 0;
}
else
{
do
v9 = v8++;
while ( v7 > *(double *)(8 * v8 + 0xC78) );
}
result = (char *)stats + 960 * a1 + 8 * v9;
++*((_QWORD *)result + 60);
*((double *)result + 40) = v5 + *((double *)result + 40);
*((_QWORD *)result + 100) += v6;
return result;
}

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

v5 = a4 - a5;
v6 = a2 - a3;
v7 = (a4 - a5) * 1000000.0 / (double)v6;
v8 = 1LL;
if ( v7 <= 0.1 )
{
v9 = 0;
}
else
{
do
v9 = v8++;
while ( v7 > *(double *)(8 * v8 + 0xC78) );
}
result = (char *)stats + 960 * a1 + 8 * v9;
++*((_QWORD *)result + 60);
*((double *)result + 40) = v5 + *((double *)result + 40);
*((_QWORD *)result + 100) += v6;
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:
char *__fastcall reportPlus(int a1, int a2, int a3, double a4, double a5)
{
double v5; // xmm2_8
int v6; // esi
double v7; // xmm0_8
__int64 v8; // rax
int v9; // edx
char *result; // rax

v5 = a4 - a5;
v6 = a2 - a3;
v7 = (a4 - a5) * 1000000.0 / (double)v6;
v8 = 1LL;
if ( v7 <= 0.1 )
{
v9 = 0;
}
else
{
do
v9 = v8++;
while ( v7 > *(double *)(8 * v8 + 0xC78) );
}
result = (char *)stats + 960 * a1 + 8 * v9;
++*((_QWORD *)result + 80);
*((double *)result + 40) = v5 + *((double *)result + 40);
*((_QWORD *)result + 100) += v6;
return result;
}

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

v5 = a4 - a5;
v6 = a2 - a3;
v7 = (a4 - a5) * 1000000.0 / (double)v6;
v8 = 1LL;
if ( v7 <= 0.1 )
{
v9 = 0;
}
else
{
do
v9 = v8++;
while ( v7 > *(double *)(8 * v8 + 0xC78) );
}
result = (char *)stats + 960 * a1 + 8 * v9;
++*((_QWORD *)result + 80);
*((double *)result + 40) = v5 + *((double *)result + 40);
*((_QWORD *)result + 100) += v6;
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
int v1; // er12
int v2; // er14
_DWORD *v3; // rbx
double *v4; // rbp
__int64 result; // rax
__int64 v6; // r12
int v7; // edx
int i; // eax
double v9; // xmm3_8

v0 = *(int **)(qword_A68 + 8);
dword_A78 = *v0;
v1 = *(int *)((char *)v0 + *(int *)(qword_A68 + 24) * (*(_QWORD *)(qword_A68 + 32) - 1LL)) - dword_A78;
v2 = v1 / 100;
qword_A80 = uArrayReCreate(qword_A80, v1 / 100, 8LL);
v3 = *(_DWORD **)(qword_A68 + 8);
v4 = *(double **)(qword_A70 + 8);
result = uArray(qword_A80, 0LL);
*(_QWORD *)result = 0LL;
if ( v1 > 99 )
{
v6 = 1LL;
do
{
v7 = dword_A78 + 100 * v6;
for ( i = v3[1]; i < v7; i = v3[1] )
{
++v3;
++v4;
}
v9 = *v4 + (double)(v7 - *v3) * (v4[1] - *v4) / (double)(i - *v3);
*(double *)uArray(qword_A80, v6++) = v9;
result = (unsigned int)(v6 - 1);
}
while ( v2 > (int)result );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int *v0; // rsi
int v1; // er12
int v2; // er14
_DWORD *v3; // rbx
double *v4; // rbp
__int64 result; // rax
__int64 v6; // r12
int v7; // edx
int i; // eax
double v9; // xmm3_8

v0 = *(int **)(qword_A68 + 8);
dword_A78 = *v0;
v1 = *(int *)((char *)v0 + *(int *)(qword_A68 + 24) * (*(_QWORD *)(qword_A68 + 32) - 1LL)) - dword_A78;
v2 = v1 / 100;
qword_A80 = uArrayReCreate(qword_A80, v1 / 100, 8LL);
v3 = *(_DWORD **)(qword_A68 + 8);
v4 = *(double **)(qword_A70 + 8);
result = uArray(qword_A80, 0LL);
*(_QWORD *)result = 0LL;
if ( v1 > 99 )
{
v6 = 1LL;
do
{
v7 = dword_A78 + 100 * v6;
for ( i = v3[1]; i < v7; i = v3[1] )
{
++v3;
++v4;
}
v9 = *v4 + (double)(v7 - *v3) * (v4[1] - *v4) / (double)(i - *v3);
*(double *)uArray(qword_A80, v6++) = v9;
result = (unsigned int)(v6 - 1);
}
while ( v2 > (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:
__int64 finalReport()
{
__int64 v0; // r13
unsigned int v1; // er15
__int64 result; // rax
__int64 i; // rbx
double *v4; // rax
__int64 v5; // rbp
__int64 v6; // r12
__int64 v7; // r14
const char *v8; // rax
double v9; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // r13
unsigned int v1; // er15
__int64 result; // rax
__int64 i; // rbx
double *v4; // rax
__int64 v5; // rbp
__int64 v6; // r12
__int64 v7; // r14
const char *v8; // rax
double v9; // [rsp+8h] [rbp-40h]

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

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

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)
{
const char *v1; // r12
const char *v2; // rbp
char *v3; // rax
char *v4; // rcx
char *v5; // rdx
__int64 v6; // rsi
_DWORD *v7; // rbp
_DWORD *v8; // rbp
__int64 i; // rax
__int64 v10; // r12
__int64 v11; // r13
int v12; // er15
__int64 v14; // rbx
int v15; // esi
int v16; // edi
int v17; // ecx
int v18; // edx
int v19; // er15
char *v20; // r13
int *v21; // rbp
int v22; // eax
int *v23; // rbx
__int64 v24; // rax
double v25; // [rsp+0h] [rbp-68h]
int v26; // [rsp+Ch] [rbp-5Ch]
double v27; // [rsp+10h] [rbp-58h]
__int64 v28; // [rsp+18h] [rbp-50h]
__int64 v29; // [rsp+20h] [rbp-48h]
int v30; // [rsp+28h] [rbp-40h]
int v31; // [rsp+2Ch] [rbp-3Ch]

if ( !a1 || !*(_QWORD *)(a1 + 16) )
die("hap4stats called without a PBWT with sites");
if ( qword_A68 )
{
v1 = map;
v2 = *(const char **)(a1 + 8);
if ( strcmp(v2, map) )
warn("chrom mismatch in hap4stats: %s != %s", v2, v1);
}
else
{
fwrite("hap4stats called without a map - using a linear 1cM/Mb map\n", 1uLL, 0x3BuLL, logFile);
qword_A68 = uArrayCreate(2LL, 4LL);
v7 = *(_DWORD **)(*(_QWORD *)(a1 + 16) + 8LL);
*(_DWORD *)uArray(qword_A68, 0LL) = *v7;
v8 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL)
+ *(int *)(*(_QWORD *)(a1 + 16) + 24LL) * (*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL) - 1LL));
*(_DWORD *)uArray(qword_A68, 1LL) = *v8;
qword_A70 = uArrayCreate(2LL, 8LL);
*(_QWORD *)uArray(qword_A70, 0LL) = 0LL;
v25 = (double)(*(_DWORD *)(*(_QWORD *)(qword_A68 + 8) + *(int *)(qword_A68 + 24)) - **(_DWORD **)(qword_A68 + 8))
* 0.000001;
*(_DWORD *)uArray(qword_A70, 1LL) = (int)v25;
map = strdup(*(const char **)(a1 + 8));
buildMap();
}
v3 = (char *)mycalloc(*(int *)(variationDict + 16LL), 960LL);
stats = v3;
v5 = (char *)*(unsigned int *)(variationDict + 16LL);
v6 = (unsigned int)((_DWORD)v5 - 1);
if ( (_DWORD)v5 )
{
v4 = &v3[960 * (int)v6];
do
{
v5 = v4;
for ( i = 0LL; *(_DWORD *)(a1 + 4) > (int)i; ++i )
*(_DWORD *)&v4[4 * i] = -1;
v6 = (unsigned int)(v6 - 1);
v4 -= 960;
}
while ( (_DWORD)v6 != -1 );
}
v10 = myalloc(*(int *)(a1 + 4), v6, v5, v4);
v11 = pbwtCursorCreate(a1, 1LL, 1LL);
if ( *(int *)a1 > 0 )
{
v12 = 0;
do
{
if ( *(_DWORD *)v11 - *(_DWORD *)(v11 + 40) > 1 )
{
v23 = (int *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) + *(_DWORD *)(*(_QWORD *)(a1 + 16) + 24LL) * v12);
v26 = *v23;
v27 = geneticMap(*v23);
v30 = v23[1];
if ( *(int *)(a1 + 4) > 0 )
{
v24 = 0LL;
do
{
*(_BYTE *)(v10 + *(int *)(*(_QWORD *)(v11 + 48) + 4 * v24)) = *(_BYTE *)(*(_QWORD *)(v11 + 32) + v24);
++v24;
}
while ( *(_DWORD *)(a1 + 4) > (int)v24 );
}
if ( *(int *)(a1 + 4) > 3 )
{
v28 = 960LL * v30;
v14 = 0LL;
v29 = v11;
v31 = v12;
do
{
v15 = *(unsigned __int8 *)(v10 + v14);
v16 = *(unsigned __int8 *)(v10 + v14 + 1);
v17 = *(unsigned __int8 *)(v10 + v14 + 2);
v18 = *(unsigned __int8 *)(v10 + v14 + 3);
if ( v18 + v17 + v15 + v16 == 2 )
{
v19 = v15 + 2 * v16 + 4 * v17 + 8 * v18;
v20 = (char *)stats + v28;
v21 = (int *)((char *)stats + 4 * (int)v14 + v28);
v22 = *v21;
if ( *v21 >= 0 )
{
if ( v22 == v19 || v19 + v22 == 15 )
reportMinus(v30, v26, v21[20], v27, *(double *)&v20[8 * (int)v14 + 160]);
else
reportPlus(v30, v26, v21[20], v27, *(double *)&v20[8 * (int)v14 + 160]);
}
*v21 = v19;
v21[20] = v26;
*(double *)&v20[8 * (int)v14 + 160] = v27;
}
v14 += 4LL;
}
while ( *(_DWORD *)(a1 + 4) > (int)v14 + 3 );
v11 = v29;
v12 = v31;
}
}
pbwtCursorForwardsRead(v11);
++v12;
}
while ( *(_DWORD *)a1 > v12 );
}
finalReport();
free(stats);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
const char *v1; // r12
const char *v2; // rbp
char *v3; // rax
char *v4; // rcx
char *v5; // rdx
__int64 v6; // rsi
_DWORD *v7; // rbp
_DWORD *v8; // rbp
__int64 i; // rax
__int64 v10; // r12
__int64 v11; // r13
int v12; // er15
__int64 v14; // rbx
int v15; // esi
int v16; // edi
int v17; // ecx
int v18; // edx
int v19; // er15
char *v20; // r13
int *v21; // rbp
int v22; // eax
int *v23; // rbx
__int64 v24; // rax
double v25; // [rsp+0h] [rbp-68h]
int v26; // [rsp+Ch] [rbp-5Ch]
double v27; // [rsp+10h] [rbp-58h]
__int64 v28; // [rsp+18h] [rbp-50h]
__int64 v29; // [rsp+20h] [rbp-48h]
int v30; // [rsp+28h] [rbp-40h]
int v31; // [rsp+2Ch] [rbp-3Ch]

if ( !a1 || !*(_QWORD *)(a1 + 16) )
die("hap4stats called without a PBWT with sites");
if ( qword_A68 )
{
v1 = map;
v2 = *(const char **)(a1 + 8);
if ( strcmp(v2, map) )
warn("chrom mismatch in hap4stats: %s != %s", v2, v1);
}
else
{
fwrite("hap4stats called without a map - using a linear 1cM/Mb map\n", 1uLL, 0x3BuLL, logFile);
qword_A68 = uArrayCreate(2LL, 4LL);
v7 = *(_DWORD **)(*(_QWORD *)(a1 + 16) + 8LL);
*(_DWORD *)uArray(qword_A68, 0LL) = *v7;
v8 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL)
+ *(int *)(*(_QWORD *)(a1 + 16) + 24LL) * (*(_QWORD *)(*(_QWORD *)(a1 + 16) + 32LL) - 1LL));
*(_DWORD *)uArray(qword_A68, 1LL) = *v8;
qword_A70 = uArrayCreate(2LL, 8LL);
*(_QWORD *)uArray(qword_A70, 0LL) = 0LL;
v25 = (double)(*(_DWORD *)(*(_QWORD *)(qword_A68 + 8) + *(int *)(qword_A68 + 24)) - **(_DWORD **)(qword_A68 + 8))
* 0.000001;
*(_DWORD *)uArray(qword_A70, 1LL) = (int)v25;
map = strdup(*(const char **)(a1 + 8));
func2();
}
v3 = (char *)mycalloc(*(int *)(variationDict + 16LL), 960LL);
stats = v3;
v5 = (char *)*(unsigned int *)(variationDict + 16LL);
v6 = (unsigned int)((_DWORD)v5 - 1);
if ( (_DWORD)v5 )
{
v4 = &v3[960 * (int)v6];
do
{
v5 = v4;
for ( i = 0LL; *(_DWORD *)(a1 + 4) > (int)i; ++i )
*(_DWORD *)&v4[4 * i] = -1;
v6 = (unsigned int)(v6 - 1);
v4 -= 960;
}
while ( (_DWORD)v6 != -1 );
}
v10 = myalloc(*(int *)(a1 + 4), v6, v5, v4);
v11 = pbwtCursorCreate(a1, 1LL, 1LL);
if ( *(int *)a1 > 0 )
{
v12 = 0;
do
{
if ( *(_DWORD *)v11 - *(_DWORD *)(v11 + 40) > 1 )
{
v23 = (int *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL) + *(_DWORD *)(*(_QWORD *)(a1 + 16) + 24LL) * v12);
v26 = *v23;
v27 = func5(*v23);
v30 = v23[1];
if ( *(int *)(a1 + 4) > 0 )
{
v24 = 0LL;
do
{
*(_BYTE *)(v10 + *(int *)(*(_QWORD *)(v11 + 48) + 4 * v24)) = *(_BYTE *)(*(_QWORD *)(v11 + 32) + v24);
++v24;
}
while ( *(_DWORD *)(a1 + 4) > (int)v24 );
}
if ( *(int *)(a1 + 4) > 3 )
{
v28 = 960LL * v30;
v14 = 0LL;
v29 = v11;
v31 = v12;
do
{
v15 = *(unsigned __int8 *)(v10 + v14);
v16 = *(unsigned __int8 *)(v10 + v14 + 1);
v17 = *(unsigned __int8 *)(v10 + v14 + 2);
v18 = *(unsigned __int8 *)(v10 + v14 + 3);
if ( v18 + v17 + v15 + v16 == 2 )
{
v19 = v15 + 2 * v16 + 4 * v17 + 8 * v18;
v20 = (char *)stats + v28;
v21 = (int *)((char *)stats + 4 * (int)v14 + v28);
v22 = *v21;
if ( *v21 >= 0 )
{
if ( v22 == v19 || v19 + v22 == 15 )
func0(v30, v26, v21[20], v27, *(double *)&v20[8 * (int)v14 + 160]);
else
func1(v30, v26, v21[20], v27, *(double *)&v20[8 * (int)v14 + 160]);
}
*v21 = v19;
v21[20] = v26;
*(double *)&v20[8 * (int)v14 + 160] = v27;
}
v14 += 4LL;
}
while ( *(_DWORD *)(a1 + 4) > (int)v14 + 3 );
v11 = v29;
v12 = v31;
}
}
pbwtCursorForwardsRead(v11);
++v12;
}
while ( *(_DWORD *)a1 > v12 );
}
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(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

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

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

va_start(arg, a1);
fwrite("FATAL ERROR: ", 1uLL, 0xDuLL, stderr);
vfprintf(stderr, a1, 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, char *a2, __int64 a3)
{
size_t v4; // rax
char *v5; // rbx
__int64 v6; // rbp

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

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

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

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; // rbx
void *v2; // rdi

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

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

v1 = func1(a1);
while ( v1 )
{
v2 = (void *)v1;
v1 = *(_QWORD *)(v1 + 8);
free(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 v2; // rbx
__int64 v3; // r12
__int64 v4; // rax

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

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, unsigned int (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 i; // rbx

for ( i = dlist_first(a1); i; i = *(_QWORD *)(i + 8) )
{
if ( a2(i, a3) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 i; // rbx

for ( i = func1(a1); i; i = *(_QWORD *)(i + 8) )
{
if ( a2(i, a3) )
break;
}
return i;
}

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 i; // rbx

for ( i = dlist_first(a1); i; i = *(_QWORD *)(i + 8) )
{
if ( *(_QWORD *)i )
free(*(void **)i);
*(_QWORD *)i = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
__int64 i; // rbx

for ( i = func1(a1); i; i = *(_QWORD *)(i + 8) )
{
if ( *(_QWORD *)i )
free(*(void **)i);
*(_QWORD *)i = 0LL;
}
}

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; // rbx
__int64 v3; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 v1; // rbx
__int64 v3; // rbp

v1 = func1(a1);
if ( v1 )
{
while ( 1 )
{
if ( *(_QWORD *)v1 )
free(*(void **)v1);
v3 = *(_QWORD *)(v1 + 8);
free((void *)v1);
if ( !v3 )
break;
v1 = v3;
}
}
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; // rbx
_QWORD *v4; // rbp

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

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

v2 = (_QWORD *)func1(a1);
if ( v2 )
{
while ( 1 )
{
if ( *v2 )
a2();
v4 = (_QWORD *)v2[1];
free(v2);
if ( !v4 )
break;
v2 = v4;
}
}
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 v2; // edx

v1 = dlist_first(a1);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = func1(a1);
if ( !v1 )
return 0;
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
return v2;
}

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
{
++v3;
result = *(_QWORD *)(result + 8);
}
while ( result && a2 != v3 );
}
return result;
}

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

result = func1(a1);
if ( result && a2 )
{
v3 = 0;
do
{
++v3;
result = *(_QWORD *)(result + 8);
}
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 func13(__int64 a1, int a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)func12(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 func14(__int64 a1, int a2)
{
void **v2; // rax

v2 = (void **)func12(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 *v1; // rbx
__int64 result; // rax
__int64 *i; // rbp

v1 = (__int64 *)dlist_first(a1);
result = dlist_last(a1);
for ( i = (__int64 *)result; v1 != i; i = (__int64 *)i[2] )
{
result = dlist_swap(v1, i);
v1 = (__int64 *)v1[1];
if ( v1 == i )
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 *v1; // rbx
__int64 result; // rax
__int64 *i; // rbp

v1 = (__int64 *)func1(a1);
result = func0(a1);
for ( i = (__int64 *)result; v1 != i; i = (__int64 *)i[2] )
{
result = func15(v1, i);
v1 = (__int64 *)v1[1];
if ( v1 == 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; // rbx
__int64 v7; // r13
__int64 v8; // rsi

result = dlist_first(a1);
v6 = result;
v7 = 0LL;
if ( result )
{
while ( 1 )
{
do
{
v8 = *(_QWORD *)(v6 + 8);
if ( !v8 )
break;
result = a2(v6, v8, a3);
if ( (_DWORD)result == 1 )
{
result = dlist_swap((__int64 *)v6, *(__int64 **)(v6 + 8));
if ( !v7 )
v7 = *(_QWORD *)(v6 + 16);
}
v6 = *(_QWORD *)(v6 + 8);
}
while ( v6 );
if ( !v7 )
break;
v6 = v7;
v7 = 0LL;
}
}
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // xmm1_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 = (double)v3 * (double)v3 + v2 * v2;
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; // edx
_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 func3(const char ***a1, const char **a2)
{
const char **v2; // rbp
int v3; // edx
_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; // rbx
_QWORD *v7; // rax
__int64 result; // rax
const char **v9; // rbp

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

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

v6 = dlist_first();
if ( v6 )
{
while ( 1 )
{
v9 = *(const char ***)v6;
if ( !strcasecmp(**(const char ***)v6, a2) && !strcasecmp(v9[1], a3) )
break;
v6 = *(_QWORD *)(v6 + 8);
if ( !v6 )
goto LABEL_2;
}
free(a3);
free((void *)v9[2]);
v9[2] = (const char *)a4;
result = a1;
}
else
{
LABEL_2:
v7 = entry_new(a2, (__int64)a3, a4);
result = dlist_add(a1, v7);
}
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);
}


decompiled_code:
__int64 __fastcall config_get(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8[5]; // [rsp+0h] [rbp-28h] BYREF

v8[0] = a2;
v8[1] = a3;
v5 = dlist_first(a1, a2);
v6 = dlist_find(v5, entry_find_func, v8);
if ( v6 )
result = *(_QWORD *)(*(_QWORD *)v6 + 16LL);
else
result = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8[5]; // [rsp+0h] [rbp-28h] BYREF

v8[0] = a2;
v8[1] = a3;
v5 = dlist_first(a1, a2);
v6 = dlist_find(v5, entry_find_func, v8);
if ( v6 )
result = *(_QWORD *)(*(_QWORD *)v6 + 16LL);
else
result = a4;
return result;
}

original_code:
const char *
config_get(dlist *config, const char *section, const char *key, const char *def)
{
 ConfigEntry needle;
 dlist *iter;
 needle.section = (char *)section;
 needle.key = (char *)key;
 iter = dlist_find(dlist_first(config), (dlist_match_func)entry_find_func, &needle);
 if(! iter)
  return def;
 return ((ConfigEntry*)iter->data)->value;
}

canonical_original_code:
char *config_get(struct dlist_element *config, char *section, char *key, char *def)
{
 struct ConfigEntry needle;
 struct dlist_element *iter;
 needle.section = (char *)section;
 needle.key = (char *)key;
 iter = dlist_find(dlist_first(config), (int (*)(struct dlist_element *, void *))entry_find_func, &needle);
 if(! iter)
  return def;
 return ((struct ConfigEntry *)iter->data)->value;
}

variable_types:
def
char *

variable_types:
needle
struct ConfigEntry { char *section; }


decompiled_code:
__int64 __fastcall allocchk_(__int64 a1, const char *a2)
{
__int64 result; // rax

result = a1;
if ( !a1 )
{
_fprintf_chk(stderr, 1LL, "%s(): Failed to allocate memory.\n", a2);
fflush(stderr);
exit(4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
__int64 result; // rax

result = a1;
if ( !a1 )
{
_fprintf_chk(stderr, 1LL, "%s(): Failed to allocate memory.\n", a2);
fflush(stderr);
exit(4);
}
return result;
}

original_code:
static inline void *
allocchk_(void *ptr, const char *func_name) {
  if (__builtin_expect(!!(!ptr), 0)) {
    (fprintf(stderr, "%s(): Failed to allocate memory." "\n", func_name), fflush(stderr));
 exit(RET_BADALLOC);
  }
  return ptr;
}

canonical_original_code:
static inline void *allocchk_(void *ptr, char *func_name) {
  if (__builtin_expect(!!(!ptr), 0)) {
    (fprintf(stderr, "%s(): Failed to allocate memory." "\n", func_name), fflush(stderr));
 exit(RET_BADALLOC);
  }
  return ptr;
}

variable_types:
ptr
void *

return_type: void *


mmemcpy

decompiled_code:
void *__fastcall mmemcpy(void *src, int a2)
{
void *v2; // rax
void *v3; // rax

v2 = malloc(a2);
v3 = (void *)allocchk_((__int64)v2, "mmemcpy");
return memcpy(v3, src, a2);
}

canonical_decompiled_code:
void *__fastcall func7(void *src, int a2)
{
void *v2; // rax
void *v3; // rax

v2 = malloc(a2);
v3 = (void *)func6((__int64)v2, "mmemcpy");
return memcpy(v3, src, a2);
}

original_code:
static inline unsigned char *
mmemcpy(const unsigned char *data, int len) {
 unsigned char *d = ((unsigned char *) allocchk_(malloc((len) * sizeof(unsigned char)), __func__));
 memcpy(d, data, len);
 return d;
}

canonical_original_code:
static inline unsigned char *mmemcpy(unsigned char *data, int len) {
 unsigned char *d = ((unsigned char *) allocchk_(malloc((len) * sizeof(unsigned char)), __func__));
 memcpy(d, data, len);
 return d;
}

variable_types:
data
unsigned char *

variable_types: len int

variable_types:
d
unsigned char *

return_type: unsigned char *


canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
__int64 result; // rax

result = a1;
if ( !a1 )
{
_fprintf_chk(stderr, 1LL, "%s(): Failed to allocate memory.\n", a2);
fflush(stderr);
exit(4);
}
return result;
}


canonical_decompiled_code:
void *__fastcall func1(void *src, int a2)
{
void *v2; // rax
void *v3; // rax

v2 = malloc(a2);
v3 = (void *)func0((__int64)v2, "mmemcpy");
return memcpy(v3, src, a2);
}


alphaconv

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

result = (unsigned int)(a1 << 8);
if ( (int)result > 0xFFFF )
result = 0xFFFFLL;
return result;
}

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

result = (unsigned int)(a1 << 8);
if ( (int)result > 0xFFFF )
result = 0xFFFFLL;
return result;
}

original_code:
static inline unsigned short
alphaconv(int alpha) {
 return (((alpha * 256) > (65535)) ? (65535) : (alpha * 256));
}

variable_types: alpha int

return_type: unsigned short


usage

repo: richardtrip/XVAchecker

decompiled_code:
int usage()
{
puts("XVA file checker");
puts("Usage:\n chkxva [options] <XVA filename> verify integrity of XVA file\n");
puts("Options:");
puts(" -v\tVerbose output");
puts(" -o\tExtracts ova.xml alongside with application");
return puts(" -m\tCreates metafile");
}

canonical_decompiled_code:
int func0()
{
puts("XVA file checker");
puts("Usage:\n chkxva [options] <XVA filename> verify integrity of XVA file\n");
puts("Options:");
puts(" -v\tVerbose output");
puts(" -o\tExtracts ova.xml alongside with application");
return puts(" -m\tCreates metafile");
}

original_code:
void usage(void)
{
 printf("XVA file checker\n");
 printf("Usage:\n chkxva [options] <XVA filename>    verify integrity of XVA file\n\n");
 printf("Options:\n");
 printf(" -v\tVerbose output\n");
 printf(" -o\tExtracts ova.xml alongside with application\n");
 printf(" -m\tCreates metafile\n");
}

canonical_original_code:
void usage()
{
 printf("XVA file checker\n");
 printf("Usage:\n chkxva [options] <XVA filename>    verify integrity of XVA file\n\n");
 printf("Options:\n");
 printf(" -v\tVerbose output\n");
 printf(" -o\tExtracts ova.xml alongside with application\n");
 printf(" -m\tCreates metafile\n");
}


decompiled_code:
char *__fastcall sha2char(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
char *result; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
*(_QWORD *)(a2 + 48) = 0LL;
*(_QWORD *)(a2 + 56) = 0LL;
v2 = a1;
do
{
snprintf(temp, 3uLL, "%02x", *v2);
result = strcat((char *)a2, temp);
++v2;
}
while ( v2 != a1 + 20 );
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
char *result; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 24) = 0LL;
*(_QWORD *)(a2 + 32) = 0LL;
*(_QWORD *)(a2 + 40) = 0LL;
*(_QWORD *)(a2 + 48) = 0LL;
*(_QWORD *)(a2 + 56) = 0LL;
v2 = a1;
do
{
snprintf(temp, 3uLL, "%02x", *v2);
result = strcat((char *)a2, temp);
++v2;
}
while ( v2 != a1 + 20 );
return result;
}

original_code:
void sha2char(unsigned char *chunk_hash, char *string)
{
 memset(string,0,64);
 for(int i=0; i<20; i++)
 {
  snprintf(temp, sizeof(temp), "%02x", chunk_hash[i]);
  strcat(string,temp);
 }
}

canonical_original_code:
void sha2char(unsigned char *chunk_hash, char *string)
{
 memset(string,0,64);
 for(int i = 0; i<20; i++)
 {
  snprintf(temp, sizeof(temp), "%02x", chunk_hash[i]);
  strcat(string,temp);
 }
}

variable_types:
string
char *

variable_types: i int


decompiled_code:
__int64 xva_asm()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0LL;
}

original_code:
int xva_asm(char *filename)
{
 return (0);
}

variable_types:
filename
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( argc <= 1 )
{
usage();
result = 1;
}
else
{
xva_validate(argv[1]);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( argc <= 1 )
{
func0();
result = 1;
}
else
{
xva_validate(argv[1]);
result = 0;
}
return result;
}

original_code:
int main (int argc, char *argv[])
{
 if(argc<2)
 {
  usage();
  return (1);
 }
 xva_validate(argv[1]);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc<2)
 {
  usage();
  return (1);
 }
 xva_validate(argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


ConvertDay

repo: richwolski/euca-cutils

decompiled_code:
__int64 __fastcall ConvertDay(__int64 a1)
{
const unsigned __int16 *v1; // rsi
__int64 i; // rax
char v3; // dl
bool v4; // zf
__int64 result; // rax
__int64 v6; // [rsp+1h] [rbp-17h] BYREF
int v7; // [rsp+9h] [rbp-Fh]
__int16 v8; // [rsp+Dh] [rbp-Bh]
char v9; // [rsp+Fh] [rbp-9h]

v6 = 0LL;
v7 = 0;
v8 = 0;
v9 = 0;
v1 = *__ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
if ( (v1[v3] & 0x400) == 0 )
break;
*((_BYTE *)&v6 + i) = v3;
}
v4 = strcmp((const char *)&v6, "Sun") == 0;
result = !v4;
if ( !v4 )
{
result = 1LL;
if ( strcmp((const char *)&v6, "Mon") )
{
result = 2LL;
if ( strcmp((const char *)&v6, "Tue") )
{
result = 3LL;
if ( strcmp((const char *)&v6, "Wed") )
{
result = 4LL;
if ( strcmp((const char *)&v6, "Thu") )
{
result = 5LL;
if ( strcmp((const char *)&v6, "Fri") )
result = strcmp((const char *)&v6, "Sat") == 0 ? 6 : -1;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
const unsigned __int16 *v1; // rsi
__int64 i; // rax
char v3; // dl
bool v4; // zf
__int64 result; // rax
__int64 v6; // [rsp+1h] [rbp-17h] BYREF
int v7; // [rsp+9h] [rbp-Fh]
__int16 v8; // [rsp+Dh] [rbp-Bh]
char v9; // [rsp+Fh] [rbp-9h]

v6 = 0LL;
v7 = 0;
v8 = 0;
v9 = 0;
v1 = *__ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
if ( (v1[v3] & 0x400) == 0 )
break;
*((_BYTE *)&v6 + i) = v3;
}
v4 = strcmp((const char *)&v6, "Sun") == 0;
result = !v4;
if ( !v4 )
{
result = 1LL;
if ( strcmp((const char *)&v6, "Mon") )
{
result = 2LL;
if ( strcmp((const char *)&v6, "Tue") )
{
result = 3LL;
if ( strcmp((const char *)&v6, "Wed") )
{
result = 4LL;
if ( strcmp((const char *)&v6, "Thu") )
{
result = 5LL;
if ( strcmp((const char *)&v6, "Fri") )
result = strcmp((const char *)&v6, "Sat") == 0 ? 6 : -1;
}
}
}
}
}
return result;
}

original_code:
int ConvertDay(char *ds)
{
 char day_buff[15];
 char *curr;
 int i;
 memset(day_buff,0,sizeof(day_buff));
 curr = ds;
 i = 0;
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISalpha))
 {
  day_buff[i] = *curr;
  curr++;
  i++;
 }
 if(strncmp(day_buff,"Sun",sizeof(day_buff)) == 0)
 {
  return(0);
 }
 else if(strncmp(day_buff,"Mon",sizeof(day_buff)) == 0)
 {
  return(1);
 }
 else if (strncmp(day_buff,"Tue",sizeof(day_buff)) == 0)
 {
  return(2);
 }
 else if (strncmp(day_buff,"Wed",sizeof(day_buff)) == 0)
 {
  return(3);
 }
 else if (strncmp(day_buff,"Thu",sizeof(day_buff)) == 0)
 {
  return(4);
 }
 else if (strncmp(day_buff,"Fri",sizeof(day_buff)) == 0)
 {
  return(5);
 }
 else if (strncmp(day_buff,"Sat",sizeof(day_buff)) == 0)
 {
  return(6);
 }
 else
 {
  return(-1);
 }
}

canonical_original_code:
int ConvertDay(char *ds)
{
 char day_buff[15];
 char *curr;
 int i;
 memset(day_buff,0,sizeof(day_buff));
 curr = ds;
 i = 0;
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISalpha))
 {
  day_buff[i] = *curr;
  curr++;
  i++;
 }
 if(strncmp(day_buff,"Sun",sizeof(day_buff)) == 0)
 {
  return(0);
 }
 else if(strncmp(day_buff,"Mon",sizeof(day_buff)) == 0)
 {
  return(1);
 }
 else if (strncmp(day_buff,"Tue",sizeof(day_buff)) == 0)
 {
  return(2);
 }
 else if (strncmp(day_buff,"Wed",sizeof(day_buff)) == 0)
 {
  return(3);
 }
 else if (strncmp(day_buff,"Thu",sizeof(day_buff)) == 0)
 {
  return(4);
 }
 else if (strncmp(day_buff,"Fri",sizeof(day_buff)) == 0)
 {
  return(5);
 }
 else if (strncmp(day_buff,"Sat",sizeof(day_buff)) == 0)
 {
  return(6);
 }
 else
 {
  return(-1);
 }
}

variable_types:
ds
char *

variable_types:
curr
char *


ConvertMonth

decompiled_code:
__int64 __fastcall ConvertMonth(__int64 a1)
{
const unsigned __int16 *v1; // rsi
__int64 i; // rax
char v3; // dl
bool v4; // zf
__int64 result; // rax
__int64 v6; // [rsp+1h] [rbp-17h] BYREF
int v7; // [rsp+9h] [rbp-Fh]
__int16 v8; // [rsp+Dh] [rbp-Bh]
char v9; // [rsp+Fh] [rbp-9h]

v6 = 0LL;
v7 = 0;
v8 = 0;
v9 = 0;
v1 = *__ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
if ( (v1[v3] & 0x400) == 0 )
break;
*((_BYTE *)&v6 + i) = v3;
}
v4 = strcmp((const char *)&v6, "Jan") == 0;
result = !v4;
if ( !v4 )
{
result = 1LL;
if ( strcmp((const char *)&v6, "Feb") )
{
result = 2LL;
if ( strcmp((const char *)&v6, "Mar") )
{
result = 3LL;
if ( strcmp((const char *)&v6, "Apr") )
{
result = 4LL;
if ( strcmp((const char *)&v6, "May") )
{
result = 5LL;
if ( strcmp((const char *)&v6, "Jun") )
{
result = 6LL;
if ( strcmp((const char *)&v6, "Jul") )
{
result = 7LL;
if ( strcmp((const char *)&v6, "Aug") )
{
result = 8LL;
if ( strcmp((const char *)&v6, "Sep") )
{
result = 9LL;
if ( strcmp((const char *)&v6, "Oct") )
{
result = 10LL;
if ( strcmp((const char *)&v6, "Nov") )
result = strcmp((const char *)&v6, "Dec") == 0 ? 11 : -1;
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
const unsigned __int16 *v1; // rsi
__int64 i; // rax
char v3; // dl
bool v4; // zf
__int64 result; // rax
__int64 v6; // [rsp+1h] [rbp-17h] BYREF
int v7; // [rsp+9h] [rbp-Fh]
__int16 v8; // [rsp+Dh] [rbp-Bh]
char v9; // [rsp+Fh] [rbp-9h]

v6 = 0LL;
v7 = 0;
v8 = 0;
v9 = 0;
v1 = *__ctype_b_loc();
for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
if ( (v1[v3] & 0x400) == 0 )
break;
*((_BYTE *)&v6 + i) = v3;
}
v4 = strcmp((const char *)&v6, "Jan") == 0;
result = !v4;
if ( !v4 )
{
result = 1LL;
if ( strcmp((const char *)&v6, "Feb") )
{
result = 2LL;
if ( strcmp((const char *)&v6, "Mar") )
{
result = 3LL;
if ( strcmp((const char *)&v6, "Apr") )
{
result = 4LL;
if ( strcmp((const char *)&v6, "May") )
{
result = 5LL;
if ( strcmp((const char *)&v6, "Jun") )
{
result = 6LL;
if ( strcmp((const char *)&v6, "Jul") )
{
result = 7LL;
if ( strcmp((const char *)&v6, "Aug") )
{
result = 8LL;
if ( strcmp((const char *)&v6, "Sep") )
{
result = 9LL;
if ( strcmp((const char *)&v6, "Oct") )
{
result = 10LL;
if ( strcmp((const char *)&v6, "Nov") )
result = strcmp((const char *)&v6, "Dec") == 0 ? 11 : -1;
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
int ConvertMonth(char *ms)
{
 char mon_buff[15];
 char *curr;
 int i;
 memset(mon_buff,0,sizeof(mon_buff));
 curr = ms;
 i = 0;
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISalpha))
 {
  mon_buff[i] = *curr;
  curr++;
  i++;
 }
 if(strncmp(mon_buff,"Jan",sizeof(mon_buff)) == 0)
 {
  return(0);
 }
 else if(strncmp(mon_buff,"Feb",sizeof(mon_buff)) == 0)
 {
  return(1);
 }
 else if (strncmp(mon_buff,"Mar",sizeof(mon_buff)) == 0)
 {
  return(2);
 }
 else if (strncmp(mon_buff,"Apr",sizeof(mon_buff)) == 0)
 {
  return(3);
 }
 else if (strncmp(mon_buff,"May",sizeof(mon_buff)) == 0)
 {
  return(4);
 }
 else if (strncmp(mon_buff,"Jun",sizeof(mon_buff)) == 0)
 {
  return(5);
 }
 else if (strncmp(mon_buff,"Jul",sizeof(mon_buff)) == 0)
 {
  return(6);
 }
 else if (strncmp(mon_buff,"Aug",sizeof(mon_buff)) == 0)
 {
  return(7);
 }
 else if (strncmp(mon_buff,"Sep",sizeof(mon_buff)) == 0)
 {
  return(8);
 }
 else if (strncmp(mon_buff,"Oct",sizeof(mon_buff)) == 0)
 {
  return(9);
 }
 else if (strncmp(mon_buff,"Nov",sizeof(mon_buff)) == 0)
 {
  return(10);
 }
 else if (strncmp(mon_buff,"Dec",sizeof(mon_buff)) == 0)
 {
  return(11);
 }
 else
 {
  return(-1);
 }
}

canonical_original_code:
int ConvertMonth(char *ms)
{
 char mon_buff[15];
 char *curr;
 int i;
 memset(mon_buff,0,sizeof(mon_buff));
 curr = ms;
 i = 0;
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISalpha))
 {
  mon_buff[i] = *curr;
  curr++;
  i++;
 }
 if(strncmp(mon_buff,"Jan",sizeof(mon_buff)) == 0)
 {
  return(0);
 }
 else if(strncmp(mon_buff,"Feb",sizeof(mon_buff)) == 0)
 {
  return(1);
 }
 else if (strncmp(mon_buff,"Mar",sizeof(mon_buff)) == 0)
 {
  return(2);
 }
 else if (strncmp(mon_buff,"Apr",sizeof(mon_buff)) == 0)
 {
  return(3);
 }
 else if (strncmp(mon_buff,"May",sizeof(mon_buff)) == 0)
 {
  return(4);
 }
 else if (strncmp(mon_buff,"Jun",sizeof(mon_buff)) == 0)
 {
  return(5);
 }
 else if (strncmp(mon_buff,"Jul",sizeof(mon_buff)) == 0)
 {
  return(6);
 }
 else if (strncmp(mon_buff,"Aug",sizeof(mon_buff)) == 0)
 {
  return(7);
 }
 else if (strncmp(mon_buff,"Sep",sizeof(mon_buff)) == 0)
 {
  return(8);
 }
 else if (strncmp(mon_buff,"Oct",sizeof(mon_buff)) == 0)
 {
  return(9);
 }
 else if (strncmp(mon_buff,"Nov",sizeof(mon_buff)) == 0)
 {
  return(10);
 }
 else if (strncmp(mon_buff,"Dec",sizeof(mon_buff)) == 0)
 {
  return(11);
 }
 else
 {
  return(-1);
 }
}

variable_types:
ms
char *


ConvertTime

original_code:
int ConvertTime(char *ts, int *hour, int *min, int *sec)
{
 char t_buff[15];
 char *curr;
 int i;
 int j;
 memset(t_buff,0,sizeof(t_buff));
 curr = ts;
 i = 0;
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISspace) && (i < sizeof(t_buff)))
 {
  t_buff[i] = *curr;
  i++;
  curr++;
  if(*curr == 0)
  {
   return(-1);
  }
  if((*curr == ':') && (i < sizeof(t_buff)))
  {
   t_buff[i] = ' ';
   i++;
   curr++;
   if(*curr == 0)
   {
    return(-1);
   }
  }
 }
 if(i == sizeof(t_buff))
 {
  return(-1);
 }
 curr = t_buff;
 *hour = atoi(curr);
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISspace))
 {
  curr++;
 }
 curr++;
 *min = atoi(curr);
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISspace))
 {
  curr++;
 }
 curr++;
 *sec = atoi(curr);
 return(1);
}

canonical_original_code:
int ConvertTime(char *ts, int *hour, int *min, int *sec)
{
 char t_buff[15];
 char *curr;
 int i;
 int j;
 memset(t_buff,0,sizeof(t_buff));
 curr = ts;
 i = 0;
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISspace) && (i < sizeof(t_buff)))
 {
  t_buff[i] = *curr;
  i++;
  curr++;
  if(*curr == 0)
  {
   return(-1);
  }
  if((*curr == ':') && (i < sizeof(t_buff)))
  {
   t_buff[i] = ' ';
   i++;
   curr++;
   if(*curr == 0)
   {
    return(-1);
   }
  }
 }
 if(i == sizeof(t_buff))
 {
  return(-1);
 }
 curr = t_buff;
 *hour = atoi(curr);
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISspace))
 {
  curr++;
 }
 curr++;
 *min = atoi(curr);
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISspace))
 {
  curr++;
 }
 curr++;
 *sec = atoi(curr);
 return(1);
}

variable_types:
ts
char *

variable_types:
hour
int *

variable_types:
min
int *

variable_types:
sec
int *

variable_types: j int


ConvertTimeStringOld

original_code:
double ConvertTimeStringOld(char *ts)
{
 int day;
 int mon;
 int date;
 int hour;
 int min;
 int sec;
 int year;
 int err;
 struct tm t;
 time_t utc;
 double ret;
 char *curr;
 curr = ts;
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISalpha))
 {
  curr++;
  if(*curr == 0)
  {
   break;
  }
 }
 if(*curr == 0)
 {
  return(-1.0);
 }
 day = ConvertDay(curr);
 if(day < 0)
 {
  day = 0;
 }
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISalpha))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 mon = ConvertMonth(curr);
 if(mon < 0)
 {
  return(-1.0);
 }
 while(*curr != ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 date = atoi(curr);
 while(*curr != ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 err = ConvertTime(curr,&hour,&min,&sec);
 if(err < 0)
 {
  return(-1.0);
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr != ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 year = atoi(curr);
 memset(&t,0,sizeof(t));
 t.tm_sec = sec;
 t.tm_min = min;
 t.tm_hour = hour;
 t.tm_mday = date;
 t.tm_mon = mon;
 t.tm_year = year - 1900;
 t.tm_wday = day;
 utc = mktime(&t);
 ret = (double)utc;
 return(ret);
}

canonical_original_code:
double ConvertTimeStringOld(char *ts)
{
 int day;
 int mon;
 int date;
 int hour;
 int min;
 int sec;
 int year;
 int err;
 struct tm t;
 long utc;
 double ret;
 char *curr;
 curr = ts;
 while(!((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISalpha))
 {
  curr++;
  if(*curr == 0)
  {
   break;
  }
 }
 if(*curr == 0)
 {
  return(-1.0);
 }
 day = ConvertDay(curr);
 if(day < 0)
 {
  day = 0;
 }
 while(((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISalpha))
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 mon = ConvertMonth(curr);
 if(mon < 0)
 {
  return(-1.0);
 }
 while(*curr != ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 date = atoi(curr);
 while(*curr != ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 err = ConvertTime(curr,&hour,&min,&sec);
 if(err < 0)
 {
  return(-1.0);
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr != ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 while(*curr == ' ')
 {
  curr++;
  if(*curr == 0)
  {
   return(-1.0);
  }
 }
 year = atoi(curr);
 memset(&t,0,sizeof(t));
 t.tm_sec = sec;
 t.tm_min = min;
 t.tm_hour = hour;
 t.tm_mday = date;
 t.tm_mon = mon;
 t.tm_year = year - 1900;
 t.tm_wday = day;
 utc = mktime(&t);
 ret = (double)utc;
 return(ret);
}

variable_types: day int

variable_types: mon int

variable_types: date int

variable_types: hour int

variable_types: min int

variable_types: sec int

variable_types: year int

variable_types: err int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: utc long

variable_types: ret double