decompiled_code:
void __fastcall graph_free(void *ptr)
{
int v1; // ebx

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0;
do
graph_remove_vertex((__int64)ptr, v1++);
while ( *(_DWORD *)ptr > v1 );
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
int v1; // ebx

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0;
do
func13((__int64)ptr, v1++);
while ( *(_DWORD *)ptr > v1 );
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void graph_free(graph *g)
{
  int i;
  if(g == ((void *)0)) {
    return;
  }
  for(i = 0; i < g->max_verticies; i++) {
    graph_remove_vertex(g, i);
  }
  free(g->edges);
  free(g->verticies);
  free(g);
}

canonical_original_code:
void graph_free(struct graph_s *g)
{
  int i;
  if(g == ((void *)0)) {
    return;
  }
  for(i = 0; i < g->max_verticies; i++) {
    graph_remove_vertex(g, i);
  }
  free(g->edges);
  free(g->verticies);
  free(g);
}


ithprime

repo: ajrisi/algorithms

decompiled_code:
__int64 __fastcall ithprime(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // edx

result = 0LL;
if ( a1 <= 0x14 )
{
v2 = primetbl[a1];
if ( v2 )
result = (1 << (a1 + 8)) - v2;
}
return result;
}

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

result = 0LL;
if ( a1 <= 0x14 )
{
v2 = primetbl[a1];
if ( v2 )
result = (1 << (a1 + 8)) - v2;
}
return result;
}

original_code:
static unsigned long ithprime(size_t i)
{
  if ((i < sizeof primetbl / sizeof (int)) && (primetbl[i])) {
    return ((1 << (8 + i)) - primetbl[i]);
  } else {
    return 0;
  }
}

canonical_original_code:
static unsigned long ithprime(unsigned long i)
{
  if ((i < sizeof primetbl / sizeof (int)) && (primetbl[i])) {
    return ((1 << (8 + i)) - primetbl[i]);
  } else {
    return 0;
  }
}

variable_types:
i
unsigned long

return_type: unsigned long


inserted

original_code:
static void *inserted(hashtable *master,
        unsigned long h,
        void *item,
        int copying)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if (hh == ((void *)0)) {
    if(copying) {
      master->htbl[h] = item;
    } else if ((master->htbl[h] = (master->dupe == ((void *)0)) ? item : master->dupe(item))) {
      master->hstatus.hentries++;
    } else {
      master->hstatus.herror |= hshNOMEM;
    }
  } else if (copying) {
    return ((void *)0);
  } else if (hh == (void*)master) {
    return ((void *)0);
  } else if (0 != master->cmp(master->htbl[h], item)) {
    return ((void *)0);
  }
  return master->htbl[h];
}

canonical_original_code:
static void *inserted(struct hashtable_s *master, unsigned long h, void *item, int copying)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if (hh == ((void *)0)) {
    if(copying) {
      master->htbl[h] = item;
    } else if ((master->htbl[h] = (master->dupe == ((void *)0)) ? item : master->dupe(item))) {
      master->hstatus.hentries++;
    } else {
      master->hstatus.herror |= hshNOMEM;
    }
  } else if (copying) {
    return ((void *)0);
  } else if (hh == (void *)master) {
    return ((void *)0);
  } else if (0 != master->cmp(master->htbl[h], item)) {
    return ((void *)0);
  }
  return master->htbl[h];
}

variable_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } hstatus; } *

variable_types:
h
unsigned long

variable_types:
item
void *

variable_types: copying int

variable_types:
hh
void *

return_type: void *

user_defined_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s hstatus; }

user_defined_types: struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e herror; }


putintbl

original_code:
static void *putintbl(hashtable *master, void *item, int copying)
{
  unsigned long h;
  unsigned long h2;
  void *stored;
  h = master->hash(item) % master->size;
  stored = inserted(master, h, item, copying);
  if ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK)) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
      stored = inserted(master, h, item, copying);
    } while ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK));
  }
  return stored;
}

canonical_original_code:
static void *putintbl(struct hashtable_s *master, void *item, int copying)
{
  unsigned long h;
  unsigned long h2;
  void *stored;
  h = master->hash(item) % master->size;
  stored = inserted(master, h, item, copying);
  if ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK)) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
      stored = inserted(master, h, item, copying);
    } while ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK));
  }
  return stored;
}

variable_types:
stored
void *

user_defined_types: enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 }


found

decompiled_code:
_BOOL8 __fastcall found(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdi
_BOOL8 result; // rax

++*(_QWORD *)(a1 + 56);
v4 = *(_QWORD *)(*(_QWORD *)a1 + 8 * a2);
if ( !v4 || a1 == v4 )
result = 0LL;
else
result = (*(unsigned int (__fastcall **)(__int64, __int64))(a1 + 32))(v4, a3) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rdi
_BOOL8 result; // rax

++*(_QWORD *)(a1 + 56);
v4 = *(_QWORD *)(*(_QWORD *)a1 + 8 * a2);
if ( !v4 || a1 == v4 )
result = 0LL;
else
result = (*(unsigned int (__fastcall **)(__int64, __int64))(a1 + 32))(v4, a3) == 0;
return result;
}

original_code:
static int found(hashtable *master, unsigned long h, void *item)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if((hh == ((void *)0)) ||
     (hh == (void*)master)) {
    return 0;
  }
  return !(master->cmp(hh, item));
}

canonical_original_code:
static int found(struct hashtable_s *master, unsigned long h, void *item)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if((hh == ((void *)0)) ||
     (hh == (void *)master)) {
    return 0;
  }
  return !(master->cmp(hh, item));
}

return_type: int


huntup

original_code:
static unsigned long huntup(hashtable *master, void *item)
{
  unsigned long h;
  unsigned long h2;
  h = master->hash(item) % master->size;
  if (!(found(master, h, item)) && master->htbl[h]) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
    } while (!(found(master, h, item)) && (master->htbl[h]));
  }
  return h;
}

canonical_original_code:
static unsigned long huntup(struct hashtable_s *master, void *item)
{
  unsigned long h;
  unsigned long h2;
  h = master->hash(item) % master->size;
  if (!(found(master, h, item)) && master->htbl[h]) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
    } while (!(found(master, h, item)) && (master->htbl[h]));
  }
  return h;
}


reorganize

original_code:
static int reorganize(hashtable *master)
{
  void **newtbl;
  void **oldtbl;
  unsigned long newsize, oldsize;
  unsigned long oldentries, j;
  unsigned int i;
  oldsize = master->size;
  oldtbl = master->htbl;
  oldentries = 0;
  if (master->hstatus.hdeleted > (master->hstatus.hentries / 4))
    newsize = oldsize;
  else {
    newsize = ithprime(0);
    for (i = 1; newsize && (newsize <= oldsize); i++) {
      newsize = ithprime(i);
    }
  }
  if (newsize != 0) {
    newtbl = calloc(newsize, sizeof(*newtbl));
  } else {
    return 0;
  }
  master->size = newsize;
  master->htbl = newtbl;
  for (j = 0; j < oldsize; j++) {
    if ((oldtbl[j] != ((void *)0)) &&
 (oldtbl[j] != (void*)master)) {
      (void) putintbl(master, oldtbl[j], 1);
      oldentries++;
    }
  }
  if (oldentries !=
      (master->hstatus.hentries - master->hstatus.hdeleted)) {
    master->hstatus.herror |= hshINTERR;
    free(master->htbl);
    master->htbl = oldtbl;
    master->size = oldsize;
    return 0;
  } else {
    master->hstatus.hentries = oldentries;
    master->hstatus.hdeleted = 0;
    free(oldtbl);
  }
  return 1;
}

canonical_original_code:
static int reorganize(struct hashtable_s *master)
{
  void **newtbl;
  void **oldtbl;
  unsigned long newsize; unsigned long oldsize;
  unsigned long oldentries; unsigned long j;
  unsigned int i;
  oldsize = master->size;
  oldtbl = master->htbl;
  oldentries = 0;
  if (master->hstatus.hdeleted > (master->hstatus.hentries / 4))
    newsize = oldsize;
  else {
    newsize = ithprime(0);
    for (i = 1; newsize && (newsize <= oldsize); i++) {
      newsize = ithprime(i);
    }
  }
  if (newsize != 0) {
    newtbl = calloc(newsize, sizeof(*newtbl));
  } else {
    return 0;
  }
  master->size = newsize;
  master->htbl = newtbl;
  for (j = 0; j < oldsize; j++) {
    if ((oldtbl[j] != ((void *)0)) &&
 (oldtbl[j] != (void *)master)) {
      (void) putintbl(master, oldtbl[j], 1);
      oldentries++;
    }
  }
  if (oldentries !=
      (master->hstatus.hentries - master->hstatus.hdeleted)) {
    master->hstatus.herror |= hshINTERR;
    free(master->htbl);
    master->htbl = oldtbl;
    master->size = oldsize;
    return 0;
  } else {
    master->hstatus.hentries = oldentries;
    master->hstatus.hdeleted = 0;
    free(oldtbl);
  }
  return 1;
}

variable_types:
newtbl
void **

variable_types:
oldtbl
void **

variable_types:
newsize
unsigned long

variable_types:
oldsize
unsigned long

variable_types:
oldentries
unsigned long

variable_types:
j
unsigned long

variable_types:
i
unsigned int


decompiled_code:
void __fastcall hashtable_free(void *ptr)
{
unsigned __int64 v2; // rbp
void *v3; // rdi
void (*v4)(void); // rax

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( ptr != v3 && v3 )
{
v4 = (void (*)(void))*((_QWORD *)ptr + 6);
if ( v4 )
v4();
}
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
unsigned __int64 v2; // rbp
void *v3; // rdi
void (*v4)(void); // rax

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 8 * v2);
if ( ptr != v3 && v3 )
{
v4 = (void (*)(void))*((_QWORD *)ptr + 6);
if ( v4 )
v4();
}
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void hashtable_free(hashtable *m)
{
  unsigned long i;
  void *h;
  if(m == ((void *)0)) {
    return;
  }
  for (i = 0; i < m->size; i++) {
    if ((h = m->htbl[i]) && ((void*)m != h)) {
      if(m->undupe != ((void *)0)) {
 m->undupe(m->htbl[i]);
      }
    }
  }
  free(m->htbl);
  free(m);
}

canonical_original_code:
void hashtable_free(struct hashtable_s *m)
{
  unsigned long i;
  void *h;
  if(m == ((void *)0)) {
    return;
  }
  for (i = 0; i < m->size; i++) {
    if ((h = m->htbl[i]) && ((void *)m != h)) {
      if(m->undupe != ((void *)0)) {
 m->undupe(m->htbl[i]);
      }
    }
  }
  free(m->htbl);
  free(m);
}

variable_types:
h
void *

return_type: void


decompiled_code:
__int64 __fastcall hashtable_insert(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0LL;
if ( (__int64)(*(_QWORD *)(a1 + 8) - (*(_QWORD *)(a1 + 8) >> 3) - *(_QWORD *)(a1 + 72)) > 0
|| (unsigned int)reorganize(a1) )
{
return putintbl(a1, a2, 0);
}
*(_DWORD *)(a1 + 88) |= 2u;
return 0LL;
}

original_code:
void *hashtable_insert(hashtable *m, void *item)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  if ((((long)(m->size - (m->size >> 3)) - (long)m->hstatus.hentries) <= 0) && !reorganize(m)) {
    m->hstatus.herror |= hshTBLFULL;
    return ((void *)0);
  }
  return putintbl(m, item, 0);
}

canonical_original_code:
void *hashtable_insert(struct hashtable_s *m, void *item)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  if ((((long)(m->size - (m->size >> 3)) - (long)m->hstatus.hentries) <= 0) && !reorganize(m)) {
    m->hstatus.herror |= hshTBLFULL;
    return ((void *)0);
  }
  return putintbl(m, item, 0);
}


decompiled_code:
__int64 __fastcall hashtable_find(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = *(_QWORD *)(*a1 + 8 * huntup((__int64)a1, a2));
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( a1 )
result = *(_QWORD *)(*a1 + 8 * func4((__int64)a1, a2));
else
result = 0LL;
return result;
}

original_code:
void *hashtable_find(hashtable *m, void *item)
{
  unsigned long h;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  return m->htbl[h];
}

canonical_original_code:
void *hashtable_find(struct hashtable_s *m, void *item)
{
  unsigned long h;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  return m->htbl[h];
}


decompiled_code:
__int64 __fastcall hashtable_remove(_QWORD *a1, __int64 a2)
{
__int64 *v2; // rdx
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = (__int64 *)(*a1 + 8 * huntup((__int64)a1, a2));
result = *v2;
if ( *v2 )
{
*v2 = (__int64)a1;
++a1[10];
}
return result;
}

original_code:
void *hashtable_remove(hashtable *m, void *item)
{
  unsigned long h;
  void *olditem;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  olditem = m->htbl[h];
  if(olditem != ((void *)0)) {
    m->htbl[h] = (void*)m;
    m->hstatus.hdeleted++;
  }
  return olditem;
}

canonical_original_code:
void *hashtable_remove(struct hashtable_s *m, void *item)
{
  unsigned long h;
  void *olditem;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  olditem = m->htbl[h];
  if(olditem != ((void *)0)) {
    m->htbl[h] = (void *)m;
    m->hstatus.hdeleted++;
  }
  return olditem;
}

variable_types:
olditem
void *


decompiled_code:
__int64 __fastcall hashtable_foreach(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
__int64 v5; // rbx
_QWORD *v6; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
if ( !a1[1] )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_QWORD **)(*a1 + 8 * v5);
if ( v6 )
{
if ( a1 != v6 )
{
result = a2(v6, a3);
if ( (_DWORD)result )
break;
}
}
if ( a1[1] <= (unsigned __int64)++v5 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
__int64 v5; // rbx
_QWORD *v6; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
if ( !a1[1] )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_QWORD **)(*a1 + 8 * v5);
if ( v6 )
{
if ( a1 != v6 )
{
result = a2(v6, a3);
if ( (_DWORD)result )
break;
}
}
if ( a1[1] <= (unsigned __int64)++v5 )
return 0LL;
}
return result;
}

original_code:
int hashtable_foreach(hashtable *m, hshexecfn exec, void *datum)
{
  int err;
  unsigned long i;
  void *hh;
  if ((m == ((void *)0)) ||
      (exec == ((void *)0))) {
    return -1;
  }
  for (i = 0; i < m->size; i++) {
    hh = m->htbl[i];
    if((hh != ((void *)0)) &&
       (hh != (void*)m)) {
      err = exec(hh, datum);
      if(err != 0) {
 return err;
      }
    }
  }
  return 0;
}

canonical_original_code:
int hashtable_foreach(struct hashtable_s *m, int (*exec)(void *item, void *datum), void *datum)
{
  int err;
  unsigned long i;
  void *hh;
  if ((m == ((void *)0)) ||
      (exec == ((void *)0))) {
    return -1;
  }
  for (i = 0; i < m->size; i++) {
    hh = m->htbl[i];
    if((hh != ((void *)0)) &&
       (hh != (void *)m)) {
      err = exec(hh, datum);
      if(err != 0) {
 return err;
      }
    }
  }
  return 0;
}

variable_types:
exec
int (*)(void *item, void *datum)

variable_types:
datum
void *

variable_types: err int


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

result = a1 + 56;
if ( !a1 )
result = 0LL;
return result;
}

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

result = a1 + 56;
if ( !a1 )
result = 0LL;
return result;
}

original_code:
hshstats *hashtable_stats(hashtable *m)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  return &(m->hstatus);
}

canonical_original_code:
struct hshstats_s *hashtable_stats(struct hashtable_s *m)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  return &(m->hstatus);
}

variable_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s hstatus; } *

return_type: struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } *


hshstrhash

decompiled_code:
__int64 __fastcall hshstrhash(char *a1)
{
char v1; // dl
__int64 v2; // rcx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
do
{
++a1;
v2 = v1 + 65600 * v2 - v2;
v1 = *a1;
}
while ( *a1 );
return v2;
}

original_code:
unsigned long hshstrhash(const char * string)
{
  unsigned long hash = 0;
  while(*string) {
    hash = *string++ + ( hash << 6 ) + ( hash << 16 ) - hash;
  }
  return hash;
}

canonical_original_code:
unsigned long hshstrhash(char *string)
{
  unsigned long hash = 0;
  while(*string) {
    hash = *string++ + ( hash << 6 ) + ( hash << 16 ) - hash;
  }
  return hash;
}

variable_types:
string
char *

variable_types:
hash
unsigned long


hshstrehash

decompiled_code:
__int64 __fastcall hshstrehash(char *a1)
{
char v1; // al
__int64 v2; // rcx
__int64 v3; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 63689LL;
v3 = 0LL;
do
{
++a1;
v3 = v1 + v2 * v3;
v2 *= 378551LL;
v1 = *a1;
}
while ( *a1 );
return v3;
}

original_code:
unsigned long hshstrehash(const char * string)
{
  unsigned long hash = 0;
  unsigned long a = 63689;
  unsigned long b = 378551;
  while(*string) {
    hash = hash*a + *string++;
    a *= b;
  }
  return hash;
}

canonical_original_code:
unsigned long hshstrehash(char *string)
{
  unsigned long hash = 0;
  unsigned long a = 63689;
  unsigned long b = 378551;
  while(*string) {
    hash = hash*a + *string++;
    a *= b;
  }
  return hash;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


original_code:
static trie_node **lookup_node(trie *t, char *key, unsigned int len)
{
  int i;
  trie_node **n;
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  n = &(t->root_node);
  for(i = 0; (i < len-1) && (*n != ((void *)0)); (n = &((*n)->next[ (int)*(key + i) ]), i++))
    ;
  if(i != (len - 1)) {
    return ((void *)0);
  } else {
    return &((*n)->next[ (int)*(key + i) ]);
  }
}

canonical_original_code:
static struct trie_node_s **lookup_node(struct trie_s *t, char *key, unsigned int len)
{
  int i;
  struct trie_node_s **n;
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  n = &(t->root_node);
  for(i = 0; (i < len-1) && (*n != ((void *)0)); (n = &((*n)->next[ (int)*(key + i) ]), i++))
    ;
  if(i != (len - 1)) {
    return ((void *)0);
  } else {
    return &((*n)->next[ (int)*(key + i) ]);
  }
}

variable_types: struct trie_s { struct trie_node_s *root_node; unsigned int size; } *

variable_types:
key
char *

variable_types:
len
unsigned int

variable_types: i int

variable_types: struct trie_node_s { void *value; struct trie_node_s *next[256]; } **


decompiled_code:
void *trie_node_new()
{
return calloc(1uLL, 0x808uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(1uLL, 0x808uLL);
}

original_code:
static trie_node *trie_node_new()
{
  trie_node *tn;
  tn = (trie_node*)calloc(1, sizeof(trie_node));
  return tn;
}

canonical_original_code:
static struct trie_node_s *trie_node_new()
{
  struct trie_node_s *tn;
  tn = (struct trie_node_s *)calloc(1, sizeof(trie_node));
  return tn;
}

variable_types: struct trie_node_s { void *value; struct trie_node_s *next[256]; } *


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

if ( ptr )
{
v1 = (void **)((char *)ptr + 8);
do
trie_node_free(*v1++);
while ( v1 != (void **)((char *)ptr + 2056) );
free(ptr);
}
}

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

if ( ptr )
{
v1 = (void **)((char *)ptr + 8);
do
func2(*v1++);
while ( v1 != (void **)((char *)ptr + 2056) );
free(ptr);
}
}

original_code:
static void trie_node_free(trie_node *tn)
{
  int i;
  if(tn == ((void *)0)) {
    return;
  }
  for(i = 0; i < 256; i++) {
    trie_node_free(tn->next[i]);
  }
  free(tn);
}

canonical_original_code:
static void trie_node_free(struct trie_node_s *tn)
{
  int i;
  if(tn == ((void *)0)) {
    return;
  }
  for(i = 0; i < 256; i++) {
    trie_node_free(tn->next[i]);
  }
  free(tn);
}

user_defined_types: struct trie_node_s { void *value; struct trie_node_s *next[256]; }


decompiled_code:
__int64 __fastcall foreach_in(_QWORD *a1, unsigned int a2, const void *a3, __int64 (__fastcall *a4)(const void *))
{
unsigned int v6; // ebx
_BYTE *v7; // rax
_BYTE *v8; // r12
__int64 i; // rbp

if ( !a1 )
return 0;
if ( !*a1 || (v6 = a4(a3)) == 0 )
{
v7 = calloc(a2 + 2, 1uLL);
v8 = v7;
if ( v7 )
{
memcpy(v7, a3, a2);
for ( i = 0LL; i != 256; ++i )
{
v8[a2] = i;
v6 = foreach_in(a1[i + 1], a2 + 1, v8, a4);
if ( v6 )
break;
}
free(v8);
}
else
{
v6 = 1;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned int a2, const void *a3, __int64 (__fastcall *a4)(const void *))
{
unsigned int v6; // ebx
_BYTE *v7; // rax
_BYTE *v8; // r12
__int64 i; // rbp

if ( !a1 )
return 0;
if ( !*a1 || (v6 = a4(a3)) == 0 )
{
v7 = calloc(a2 + 2, 1uLL);
v8 = v7;
if ( v7 )
{
memcpy(v7, a3, a2);
for ( i = 0LL; i != 256; ++i )
{
v8[a2] = i;
v6 = func3(a1[i + 1], a2 + 1, v8, a4);
if ( v6 )
break;
}
free(v8);
}
else
{
v6 = 1;
}
}
return v6;
}

original_code:
static int foreach_in(trie_node *n, unsigned int depth, char *s, int(*fn)(char *, unsigned int, void*))
{
  int i;
  int ret;
  char *sc;
  if(n == ((void *)0)) {
    return 0;
  }
  ret = 0;
  if(n->value != ((void *)0)) {
    ret = fn(s, depth, n->value);
    if(ret != 0) {
      return ret;
    }
  }
  sc = (char*)calloc(depth+2, sizeof(char));
  if(sc == ((void *)0)) {
    return 1;
  }
  memcpy(sc, s, depth);
  for(i = 0; i < 256; i++) {
    sc[depth] = i;
    ret = foreach_in(n->next[i], depth+1, sc, fn);
    if(ret != 0) {
      break;
    }
  }
  free(sc);
  return ret;
}

canonical_original_code:
static int foreach_in(struct trie_node_s *n, unsigned int depth, char *s, int (*fn)(char *, unsigned int, void *))
{
  int i;
  int ret;
  char *sc;
  if(n == ((void *)0)) {
    return 0;
  }
  ret = 0;
  if(n->value != ((void *)0)) {
    ret = fn(s, depth, n->value);
    if(ret != 0) {
      return ret;
    }
  }
  sc = (char *)calloc(depth+2, sizeof(char));
  if(sc == ((void *)0)) {
    return 1;
  }
  memcpy(sc, s, depth);
  for(i = 0; i < 256; i++) {
    sc[depth] = i;
    ret = foreach_in(n->next[i], depth+1, sc, fn);
    if(ret != 0) {
      break;
    }
  }
  free(sc);
  return ret;
}

variable_types:
depth
unsigned int

variable_types:
s
char *

variable_types:
fn
int (*)(char *, unsigned int, void *)

variable_types: ret int

variable_types:
sc
char *


decompiled_code:
_QWORD *trie_new()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = calloc(1uLL, 0x10uLL);
if ( v0 )
{
v1 = trie_node_new();
*v0 = v1;
if ( !v1 )
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = calloc(1uLL, 0x10uLL);
if ( v0 )
{
v1 = func1();
*v0 = v1;
if ( !v1 )
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

original_code:
trie *trie_new(void)
{
  trie *t;
  t = (trie*)calloc(1, sizeof(trie));
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  t->root_node = trie_node_new();
  if(t->root_node == ((void *)0)) {
    free(t);
    return ((void *)0);
  }
  return t;
}

canonical_original_code:
struct trie_s *trie_new()
{
  struct trie_s *t;
  t = (struct trie_s *)calloc(1, sizeof(trie));
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  t->root_node = trie_node_new();
  if(t->root_node == ((void *)0)) {
    free(t);
    return ((void *)0);
  }
  return t;
}

variable_types: struct trie_s { struct trie_node_s { void *value; struct trie_node_s *next[256]; } *root_node; unsigned int size; } *

user_defined_types: struct trie_s { struct trie_node_s *root_node; unsigned int size; }


decompiled_code:
void __fastcall trie_free(void *ptr)
{
if ( ptr )
{
trie_node_free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
func2(*(void **)ptr);
free(ptr);
}
}

original_code:
void trie_free(trie *t)
{
  if(t == ((void *)0)) {
    return;
  }
  trie_node_free(t->root_node);
  free(t);
}

canonical_original_code:
void trie_free(struct trie_s *t)
{
  if(t == ((void *)0)) {
    return;
  }
  trie_node_free(t->root_node);
  free(t);
}


decompiled_code:
__int64 __fastcall trie_insert_n(__int64 a1, char *a2, int a3, __int64 a4)
{
_QWORD **v4; // r12
char *v5; // rbx
__int64 v6; // r14
_QWORD *v7; // rbp
int v8; // er13
void *v9; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v4 = (_QWORD **)a1;
if ( a3 <= 0 )
{
LABEL_8:
if ( **v4 )
--*(_DWORD *)(a1 + 8);
**v4 = a4;
++*(_DWORD *)(a1 + 8);
result = 0LL;
}
else
{
v5 = a2;
v6 = (__int64)&a2[a3 - 1 + 1];
while ( 1 )
{
v7 = *v4;
v8 = *v5;
v4 = (_QWORD **)&(*v4)[*v5 + 1];
if ( !*v4 )
{
v9 = trie_node_new();
v7[v8 + 1] = v9;
if ( !v9 )
break;
}
if ( ++v5 == (char *)v6 )
goto LABEL_8;
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int trie_insert_n(trie *t, char *key, int len, void *value)
{
  trie_node **n;
  int i;
  if(t == ((void *)0)) {
    return -1;
  }
  n = &(t->root_node);
  for(i = 0; i < len; i++) {
    n = &((*n)->next[ (int)*(key + i) ]);
    if(*n == ((void *)0)) {
      *n = trie_node_new();
      if(*n == ((void *)0)) {
 return -1;
      }
    }
  }
  if((*n)->value != ((void *)0)) {
    t->size--;
  }
  (*n)->value = value;
  t->size++;
  return 0;
}

canonical_original_code:
int trie_insert_n(struct trie_s *t, char *key, int len, void *value)
{
  struct trie_node_s **n;
  int i;
  if(t == ((void *)0)) {
    return -1;
  }
  n = &(t->root_node);
  for(i = 0; i < len; i++) {
    n = &((*n)->next[ (int)*(key + i) ]);
    if(*n == ((void *)0)) {
      *n = trie_node_new();
      if(*n == ((void *)0)) {
 return -1;
      }
    }
  }
  if((*n)->value != ((void *)0)) {
    t->size--;
  }
  (*n)->value = value;
  t->size++;
  return 0;
}

variable_types: len int

variable_types:
value
void *


decompiled_code:
__int64 __fastcall trie_insert(__int64 a1, char *a2, __int64 a3)
{
int v4; // eax

v4 = strlen(a2);
return trie_insert_n(a1, a2, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2, __int64 a3)
{
int v4; // eax

v4 = strlen(a2);
return func6(a1, a2, v4, a3);
}

original_code:
int trie_insert(trie *t, char *key, void *value)
{
  return trie_insert_n(t, key, strlen(key), value);
}

canonical_original_code:
int trie_insert(struct trie_s *t, char *key, void *value)
{
  return trie_insert_n(t, key, strlen(key), value);
}


decompiled_code:
void __fastcall trie_remove_n(__int64 a1, char *a2, int a3)
{
int v4; // ebp
void **v5; // rax
void **v6; // rbx
_QWORD *v7; // rax
_QWORD *v8; // rdi
_QWORD *v9; // rax

if ( a1 )
{
v4 = a3;
v5 = (void **)lookup_node((_QWORD *)a1, a2, a3);
v6 = v5;
if ( v5 )
{
v7 = *v5;
if ( v7 )
{
if ( *v7 )
{
*v7 = 0LL;
--*(_DWORD *)(a1 + 8);
}
do
{
v8 = *v6;
if ( !*v6 )
break;
v9 = v8 + 1;
while ( !*v9 )
{
if ( ++v9 == v8 + 257 )
{
trie_node_free(v8);
*v6 = 0LL;
break;
}
}
v6 = (void **)lookup_node((_QWORD *)a1, a2, --v4);
}
while ( v6 );
}
}
}
}

original_code:
void trie_remove_n(trie *t, char *key, unsigned int len)
{
  int i;
  int allnull;
  trie_node **n;
  allnull = 1;
  if(t == ((void *)0)) {
    return;
  }
  n = lookup_node(t, key, len);
  if((n != ((void *)0)) &&
     (*n != ((void *)0)) &&
     ((*n)->value != ((void *)0))) {
    (*n)->value = ((void *)0);
    t->size--;
  }
  for( ;
 ((n != ((void *)0)) &&
  (*n != ((void *)0))) ;
 n = lookup_node(t, key, --len)) {
    allnull = 1;
    for(i = 0; i < 256; i++) {
      if( (*n)->next[i] != ((void *)0)) {
 allnull = 0;
 break;
      }
    }
    if(allnull) {
      trie_node_free(*n);
      *n = ((void *)0);
    }
  }
}

canonical_original_code:
void trie_remove_n(struct trie_s *t, char *key, unsigned int len)
{
  int i;
  int allnull;
  struct trie_node_s **n;
  allnull = 1;
  if(t == ((void *)0)) {
    return;
  }
  n = lookup_node(t, key, len);
  if((n != ((void *)0)) &&
     (*n != ((void *)0)) &&
     ((*n)->value != ((void *)0))) {
    (*n)->value = ((void *)0);
    t->size--;
  }
  for( ;
 ((n != ((void *)0)) &&
  (*n != ((void *)0))) ;
 n = lookup_node(t, key, --len)) {
    allnull = 1;
    for(i = 0; i < 256; i++) {
      if( (*n)->next[i] != ((void *)0)) {
 allnull = 0;
 break;
      }
    }
    if(allnull) {
      trie_node_free(*n);
      *n = ((void *)0);
    }
  }
}

variable_types: allnull int


decompiled_code:
void __fastcall trie_remove(__int64 a1, char *a2)
{
int v2; // eax

v2 = strlen(a2);
trie_remove_n(a1, a2, v2);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, char *a2)
{
int v2; // eax

v2 = strlen(a2);
func8(a1, a2, v2);
}

original_code:
void trie_remove(trie *t, char *key)
{
  trie_remove_n(t, key, strlen(key));
}

canonical_original_code:
void trie_remove(struct trie_s *t, char *key)
{
  trie_remove_n(t, key, strlen(key));
}


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

result = 0LL;
if ( !a1 )
result = *(unsigned int *)((char *)&loc_6 + 2);
return result;
}

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

result = 0LL;
if ( !a1 )
result = *(unsigned int *)((char *)&loc_6 + 2);
return result;
}

original_code:
unsigned int trie_size(trie *t)
{
  if(t != ((void *)0)) {
    return 0;
  }
  return t->size;
}

canonical_original_code:
unsigned int trie_size(struct trie_s *t)
{
  if(t != ((void *)0)) {
    return 0;
  }
  return t->size;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall trie_foreach(_QWORD **a1, __int64 (__fastcall *a2)(const void *))
{
return foreach_in(*a1, 0, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD **a1, __int64 (__fastcall *a2)(const void *))
{
return func3(*a1, 0, 0LL, a2);
}

original_code:
int trie_foreach(trie *t, int(*foreach_fn)(char *, unsigned int, void*))
{
  return foreach_in(t->root_node, 0, ((void *)0), foreach_fn);
}

canonical_original_code:
int trie_foreach(struct trie_s *t, int (*foreach_fn)(char *, unsigned int, void *))
{
  return foreach_in(t->root_node, 0, ((void *)0), foreach_fn);
}


original_code:
static void sift_up(heap *h, int insert_index)
{
  int parent_index;
  int swap_tmp;
  void *parent_item;
  void *insert_item;
  if(h == ((void *)0)) {
    return;
  }
  if(insert_index == 1) {
    return;
  }
  parent_index = insert_index >> 1;
  parent_item = h->heap_items[parent_index];
  insert_item = h->heap_items[insert_index];
  if(h->orderitem_fn(insert_item, parent_item)) {
    swap_tmp = insert_index;
    h->heap_items[parent_index] = insert_item;
    h->heap_items[insert_index] = parent_item;
    insert_index = parent_index;
    parent_index = swap_tmp;
    sift_up(h, insert_index);
  }
}

canonical_original_code:
static void sift_up(struct heap_s *h, int insert_index)
{
  int parent_index;
  int swap_tmp;
  void *parent_item;
  void *insert_item;
  if(h == ((void *)0)) {
    return;
  }
  if(insert_index == 1) {
    return;
  }
  parent_index = insert_index >> 1;
  parent_item = h->heap_items[parent_index];
  insert_item = h->heap_items[insert_index];
  if(h->orderitem_fn(insert_item, parent_item)) {
    swap_tmp = insert_index;
    h->heap_items[parent_index] = insert_item;
    h->heap_items[insert_index] = parent_item;
    insert_index = parent_index;
    parent_index = swap_tmp;
    sift_up(h, insert_index);
  }
}

variable_types: struct heap_s { int max_heap_size; void **heap_items; void *(*dupitem_fn)(void *); int (*orderitem_fn)(void *, void *); void (*freeitem_fn)(void *); int next_free_idx; } *


decompiled_code:
_BOOL8 __fastcall heap_isempty(__int64 a1)
{
return *(_DWORD *)(a1 + 40) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 40) == 1;
}

original_code:
int heap_isempty(heap *h)
{
  return (h->next_free_idx == 1);
}

canonical_original_code:
int heap_isempty(struct heap_s *h)
{
  return (h->next_free_idx == 1);
}

user_defined_types: struct heap_s { int max_heap_size; void **heap_items; void *(*dupitem_fn)(void *); int (*orderitem_fn)(void *, void *); void (*freeitem_fn)(void *); int next_free_idx; }


original_code:
void *heap_extract(heap *h)
{
  void *minitem;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isempty(h)) {
    return ((void *)0);
  }
  minitem = h->heap_items[1];
  h->next_free_idx--;
  h->heap_items[1] = h->heap_items[h->next_free_idx];
  h->heap_items[h->next_free_idx] = ((void *)0);
  sift_down(h, 1);
  return minitem;
}

canonical_original_code:
void *heap_extract(struct heap_s *h)
{
  void *minitem;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isempty(h)) {
    return ((void *)0);
  }
  minitem = h->heap_items[1];
  h->next_free_idx--;
  h->heap_items[1] = h->heap_items[h->next_free_idx];
  h->heap_items[h->next_free_idx] = ((void *)0);
  sift_down(h, 1);
  return minitem;
}

variable_types:
minitem
void *


decompiled_code:
_BOOL8 __fastcall heap_isfull(_DWORD *a1)
{
return a1[10] >= *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1)
{
return a1[10] >= *a1;
}

original_code:
int heap_isfull(heap *h)
{
  return (h->next_free_idx >= h->max_heap_size);
}

canonical_original_code:
int heap_isfull(struct heap_s *h)
{
  return (h->next_free_idx >= h->max_heap_size);
}


original_code:
void *heap_insert(heap *h, void *data)
{
  int insert_index;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isfull(h)) {
    return ((void *)0);
  }
  if(h->dupitem_fn != ((void *)0)) {
    data = h->dupitem_fn(data);
    if(data == ((void *)0)) {
      return ((void *)0);
    }
  }
  insert_index = h->next_free_idx;
  h->heap_items[insert_index] = data;
  h->next_free_idx++;
  sift_up(h, insert_index);
  return data;
}

canonical_original_code:
void *heap_insert(struct heap_s *h, void *data)
{
  int insert_index;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isfull(h)) {
    return ((void *)0);
  }
  if(h->dupitem_fn != ((void *)0)) {
    data = h->dupitem_fn(data);
    if(data == ((void *)0)) {
      return ((void *)0);
    }
  }
  insert_index = h->next_free_idx;
  h->heap_items[insert_index] = data;
  h->next_free_idx++;
  sift_up(h, insert_index);
  return data;
}

variable_types:
data
void *


original_code:
void heap_free(heap *h)
{
  int i;
  if(h->dupitem_fn != ((void *)0)) {
    for(i = 1; i < h->next_free_idx; i++) {
      h->freeitem_fn(h->heap_items[i]);
    }
  }
  free(h->heap_items);
  free(h);
}

canonical_original_code:
void heap_free(struct heap_s *h)
{
  int i;
  if(h->dupitem_fn != ((void *)0)) {
    for(i = 1; i < h->next_free_idx; i++) {
      h->freeitem_fn(h->heap_items[i]);
    }
  }
  free(h->heap_items);
  free(h);
}


decompiled_code:
void __fastcall di_free(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

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

original_code:
static void di_free(void *di)
{
  if(di == ((void *)0)) {
    return;
  }
  free( ((dictionary_item*)di)->key );
  free( ((dictionary_item*)di)->value );
  free(di);
}

canonical_original_code:
static void di_free(void *di)
{
  if(di == ((void *)0)) {
    return;
  }
  free( ((struct dictionary_item_s *)di)->key );
  free( ((struct dictionary_item_s *)di)->value );
  free(di);
}

variable_types:
di
void *

user_defined_types: struct dictionary_item_s { char *key; char *value; }


decompiled_code:
int __fastcall di_cmp(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
static int di_cmp(void *a, void *b)
{
  return strcmp( ((dictionary_item*)a)->key, ((dictionary_item*)b)->key );
}

canonical_original_code:
static int di_cmp(void *a, void *b)
{
  return strcmp( ((struct dictionary_item_s *)a)->key, ((struct dictionary_item_s *)b)->key );
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall di_rehash(_QWORD *a1)
{
return rehash_string(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
return rehash_string(*a1);
}

original_code:
static unsigned long di_rehash(void *di)
{
  return rehash_string( ((dictionary_item*)di)->key );
}

canonical_original_code:
static unsigned long di_rehash(void *di)
{
  return rehash_string( ((struct dictionary_item_s *)di)->key );
}


decompiled_code:
__int64 __fastcall di_hash(_QWORD *a1)
{
return hash_string(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
return hash_string(*a1);
}

original_code:
static unsigned long di_hash(void *di)
{
  return hash_string( ((dictionary_item*)di)->key );
}

canonical_original_code:
static unsigned long di_hash(void *di)
{
  return hash_string( ((struct dictionary_item_s *)di)->key );
}


decompiled_code:
__int64 dictionary_new()
{
return hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

canonical_decompiled_code:
__int64 func4()
{
return hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

original_code:
dictionary *dictionary_new()
{
  return (dictionary*)hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

canonical_original_code:
struct hashtable_s *dictionary_new()
{
  return (struct hashtable_s *)hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

return_type: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } hstatus; } *


decompiled_code:
__int64 __fastcall dictionary_set(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a2;
v4[1] = a3;
return hashtable_insert(a1, v4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a2;
v4[1] = a3;
return hashtable_insert(a1, v4);
}

original_code:
char *dictionary_set(dictionary *d, char *key, char *value)
{
  dictionary_item di;
  di.key = key;
  di.value = value;
  return (char*)hashtable_insert( (hashtable*)d, (void*)&di);
}

canonical_original_code:
char *dictionary_set(struct hashtable_s *d, char *key, char *value)
{
  struct dictionary_item_s di;
  di.key = key;
  di.value = value;
  return (char *)hashtable_insert( (struct hashtable_s *)d, (void *)&di);
}

variable_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } hstatus; } *

variable_types:
key
char *

variable_types:
value
char *

variable_types: struct dictionary_item_s { char *key; char *value; }

return_type: char *


decompiled_code:
__int64 __fastcall dictionary_get(__int64 a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
return hashtable_find(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
return hashtable_find(a1, v3);
}

original_code:
char *dictionary_get(dictionary *d, char *key)
{
  dictionary_item di;
  di.key = key;
  di.value = ((void *)0);
  return (char*)hashtable_find( (hashtable*)d, (void*)&di );
}

canonical_original_code:
char *dictionary_get(struct hashtable_s *d, char *key)
{
  struct dictionary_item_s di;
  di.key = key;
  di.value = ((void *)0);
  return (char *)hashtable_find( (struct hashtable_s *)d, (void *)&di );
}


decompiled_code:
void __fastcall dictionary_remove(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
v2 = (void *)hashtable_remove(a1, v3);
di_free(v2);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
v2 = (void *)hashtable_remove(a1, v3);
func0(v2);
}

original_code:
void dictionary_remove(dictionary *d, char *key)
{
  dictionary_item di;
  di.key = key;
  di.value = ((void *)0);
  di_free( hashtable_remove( (hashtable*)d, (void*)&di) );
}

canonical_original_code:
void dictionary_remove(struct hashtable_s *d, char *key)
{
  struct dictionary_item_s di;
  di.key = key;
  di.value = ((void *)0);
  di_free( hashtable_remove( (struct hashtable_s *)d, (void *)&di) );
}


decompiled_code:
__int64 dictionary_free()
{
return hashtable_free();
}

canonical_decompiled_code:
__int64 func8()
{
return hashtable_free();
}

original_code:
void dictionary_free(dictionary *d)
{
  hashtable_free( (hashtable*)d );
}

canonical_original_code:
void dictionary_free(struct hashtable_s *d)
{
  hashtable_free( (struct hashtable_s *)d );
}


cmpchr

decompiled_code:
__int64 __fastcall cmpchr(char *a1, char *a2)
{
return (unsigned int)(*a2 - *a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char *a2)
{
return (unsigned int)(*a2 - *a1);
}

original_code:
int cmpchr(char *x, char *y)
{
  return *y - *x;
}

variable_types:
x
char *

variable_types:
y
char *


main

canonical_name: main

repo: ajross/project-euler

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edx
__int64 v4; // rsi

v3 = 0;
v4 = 0LL;
do
{
if ( v3 == 3 * (v3 / 3) || v3 == 5 * (v3 / 5) )
v4 = (unsigned int)(v3 + v4);
++v3;
}
while ( v3 != 1000 );
printf("The total is: %d\n", v4);
return 0;
}

original_code:
int main(int argc, char** argv) {
   int sum = 0;
   int i;
   for (i = 0; i < 1000; i++) {
       if ((i % 3 == 0) || (i % 5 == 0)) {
           sum += i;
       }
   }
   printf("The total is: %d\n", sum);
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   int sum = 0;
   int i;
   for (i = 0; i < 1000; i++) {
       if ((i % 3 == 0) || (i % 5 == 0)) {
           sum += i;
       }
   }
   printf("The total is: %d\n", sum);
   return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: sum int

variable_types: i int


repo: ajtowns/altos

decompiled_code:
void ao_aes_set_mode()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void
ao_aes_set_mode(enum ao_aes_mode mode)
{
 (void) mode;
}

variable_types: enum ao_aes_mode { ao_aes_mode_cbc_mac=0 }


decompiled_code:
__int64 __fastcall ao_aes_set_key(const __m128i *a1)
{
key = (__int128)_mm_loadu_si128(a1);
return xrijndaelKeySched(&key, 128, 128, rkk);
}

canonical_decompiled_code:
__int64 __fastcall func13(const __m128i *a1)
{
key = (__int128)_mm_loadu_si128(a1);
return func10(&key, 128, 128, rkk);
}

original_code:
void
ao_aes_set_key( uint8_t *in)
{
 memcpy(key, in, 16);
 xrijndaelKeySched((word32 *) key, 128, 128, &rkk);
}

canonical_original_code:
void ao_aes_set_key(unsigned char *in)
{
 memcpy(key, in, 16);
 xrijndaelKeySched((unsigned int *) key, 128, 128, &rkk);
}

variable_types:
in
unsigned char *


decompiled_code:
void ao_aes_zero_iv()
{
iv = 0uLL;
}

canonical_decompiled_code:
void func14()
{
iv = 0uLL;
}

original_code:
void
ao_aes_zero_iv(void)
{
 memset(iv, '\0', sizeof (iv));
}

canonical_original_code:
void ao_aes_zero_iv()
{
 memset(iv, '\0', sizeof (iv));
}


decompiled_code:
void __fastcall ao_aes_run(__int64 a1, __m128i *a2)
{
__int64 i; // rax

for ( i = 0LL; i != 16; ++i )
*((_BYTE *)&iv + i) ^= *(_BYTE *)(a1 + i);
xrijndaelEncrypt((__int64)&iv, rkk);
if ( a2 )
*a2 = _mm_load_si128((const __m128i *)&iv);
}

original_code:
void
ao_aes_run( uint8_t *in,
    uint8_t *out)
{
 uint8_t i;
 for (i = 0; i < 16; i++)
  iv[i] ^= in[i];
 xrijndaelEncrypt((word32 *) iv, &rkk);
 if (out)
  memcpy(out, iv, 16);
}

canonical_original_code:
void ao_aes_run(unsigned char *in, unsigned char *out)
{
 unsigned char i;
 for (i = 0; i < 16; i++)
  iv[i] ^= in[i];
 xrijndaelEncrypt((unsigned int *) iv, &rkk);
 if (out)
  memcpy(out, iv, 16);
}

variable_types:
out
unsigned char *

variable_types:
i
unsigned char


decompiled_code:
void ao_aes_init()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void
ao_aes_init(void)
{
}

canonical_original_code:
void ao_aes_init()
{
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 *v3; // rbx

ao_aes_set_key((const __m128i *)&key);
ao_aes_zero_iv();
ao_aes_run((__int64)&text, &cbc);
printf("CBC");
v3 = (unsigned __int8 *)&cbc;
do
printf(" %02x", *v3++);
while ( v3 != (unsigned __int8 *)&text );
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 *v3; // rbx

func13((const __m128i *)&key);
func14();
func15((__int64)&text, &cbc);
printf("CBC");
v3 = (unsigned __int8 *)&cbc;
do
printf(" %02x", *v3++);
while ( v3 != (unsigned __int8 *)&text );
putchar(10);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
 int i;
 ao_aes_init();
 ao_aes_set_mode(ao_aes_mode_cbc_mac);
 ao_aes_set_key(key);
 ao_aes_zero_iv();
 ao_aes_run(text, cbc);
 printf ("CBC");
 for (i = 0; i < sizeof (cbc); i++)
  printf (" %02x", cbc[i]);
 printf ("\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 ao_aes_init();
 ao_aes_set_mode(ao_aes_mode_cbc_mac);
 ao_aes_set_key(key);
 ao_aes_zero_iv();
 ao_aes_run(text, cbc);
 printf ("CBC");
 for (i = 0; i < sizeof (cbc); i++)
  printf (" %02x", cbc[i]);
 printf ("\n");
 return 0;
}


decompiled_code:
__int64 rand24()
{
return random() & 0xFFFFFF;
}

canonical_decompiled_code:
__int64 func7()
{
return random() & 0xFFFFFF;
}

original_code: static int32_t rand24(void) { return random() & 0xffffff; }

canonical_original_code: static int rand24() { return random() & 0xffffff; }


decompiled_code:
__int64 __fastcall ao_rshift64(_DWORD *a1, int *a2, unsigned __int8 a3)
{
unsigned int v3; // eax
__int64 result; // rax

if ( a3 > 0x1Fu )
{
result = (unsigned int)(*a2 >> a3);
a1[1] = result;
*a1 = 0;
}
else
{
v3 = (unsigned int)a2[1] >> a3;
a1[1] = v3;
if ( a3 )
a1[1] = (*a2 << (32 - a3)) | v3;
result = (unsigned int)(*a2 >> a3);
*a1 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, int *a2, unsigned __int8 a3)
{
unsigned int v3; // eax
__int64 result; // rax

if ( a3 > 0x1Fu )
{
result = (unsigned int)(*a2 >> a3);
a1[1] = result;
*a1 = 0;
}
else
{
v3 = (unsigned int)a2[1] >> a3;
a1[1] = v3;
if ( a3 )
a1[1] = (*a2 << (32 - a3)) | v3;
result = (unsigned int)(*a2 >> a3);
*a1 = result;
}
return result;
}

original_code:
void ao_rshift64( ao_int64_t *r, ao_int64_t *a, uint8_t d) {
 if (d < 32) {
  r->low = a->low >> d;
  if (d)
   r->low |= a->high << (32 - d);
  r->high = (int32_t) a->high >> d;
 } else {
  d &= 0x1f;
  r->low = (int32_t) a->high >> d;
  r->high = 0;
 }
}

canonical_original_code:
void ao_rshift64(struct ao_int64_t *r, struct ao_int64_t *a, unsigned char d) {
 if (d < 32) {
  r->low = a->low >> d;
  if (d)
   r->low |= a->high << (32 - d);
  r->high = (int) a->high >> d;
 } else {
  d &= 0x1f;
  r->low = (int) a->high >> d;
  r->high = 0;
 }
}

variable_types: struct ao_int64_t { unsigned int high; unsigned int low; } *

variable_types:
a
struct ao_int64_t *

variable_types:
d
unsigned char


decompiled_code:
__int64 __fastcall ao_neg64(unsigned int *a1, int *a2)
{
int v2; // eax
unsigned int v3; // ecx
int v4; // edx
__int64 result; // rax

v2 = *a2;
v3 = ~*a2;
*a1 = v3;
v4 = -a2[1];
a1[1] = v4;
result = (unsigned int)-v2;
if ( v4 )
result = v3;
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int *a1, int *a2)
{
int v2; // eax
unsigned int v3; // ecx
int v4; // edx
__int64 result; // rax

v2 = *a2;
v3 = ~*a2;
*a1 = v3;
v4 = -a2[1];
a1[1] = v4;
result = (unsigned int)-v2;
if ( v4 )
result = v3;
*a1 = result;
return result;
}

original_code:
void ao_neg64( ao_int64_t *r, ao_int64_t *a) {
 r->high = ~a->high;
 if (!(r->low = ~a->low + 1))
  r->high++;
}

canonical_original_code:
void ao_neg64(struct ao_int64_t *r, struct ao_int64_t *a) {
 r->high = ~a->high;
 if (!(r->low = ~a->low + 1))
  r->high++;
}

user_defined_types: struct ao_int64_t { unsigned int high; unsigned int low; }


test

decompiled_code:
int __fastcall test(unsigned int a1, unsigned int *a2)
{
int result; // eax
unsigned int v3; // [rsp+0h] [rbp-28h] BYREF
unsigned int v4; // [rsp+4h] [rbp-24h]
unsigned int v5; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-1Ch]

ao_ms5607_convert_8051((int *)a2, &v5);
ao_ms5607_convert_8051((int *)a2, &v3);
result = v6;
if ( v6 != v4 || v5 != v3 )
{
++errors;
result = printf("trial %d: %d, %d -> %d, %d (should be %d, %d)\n", a1, *a2, a2[1], v3, v4, v5, v6);
}
return result;
}

canonical_decompiled_code:
int __fastcall func21(unsigned int a1, unsigned int *a2)
{
int result; // eax
unsigned int v3; // [rsp+0h] [rbp-28h] BYREF
unsigned int v4; // [rsp+4h] [rbp-24h]
unsigned int v5; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-1Ch]

func20((int *)a2, &v5);
func20((int *)a2, &v3);
result = v6;
if ( v6 != v4 || v5 != v3 )
{
++errors;
result = printf("trial %d: %d, %d -> %d, %d (should be %d, %d)\n", a1, *a2, a2[1], v3, v4, v5, v6);
}
return result;
}

original_code:
void test(int trial, struct ao_ms5607_sample *sample)
{
 struct ao_ms5607_value value, value_8051;
 ao_ms5607_convert_8051(sample, &value);
 ao_ms5607_convert_8051(sample, &value_8051);
 if (value.temp != value_8051.temp || value.pres != value_8051.pres) {
  ++errors;
  printf ("trial %d: %d, %d -> %d, %d (should be %d, %d)\n",
   trial,
   sample->pres, sample->temp,
   value_8051.pres, value_8051.temp,
   value.pres, value.temp);
 }
}

canonical_original_code:
void test(int trial, struct ao_ms5607_sample *sample)
{
 struct ao_ms5607_value value; struct ao_ms5607_value value_8051;
 ao_ms5607_convert_8051(sample, &value);
 ao_ms5607_convert_8051(sample, &value_8051);
 if (value.temp != value_8051.temp || value.pres != value_8051.pres) {
  ++errors;
  printf ("trial %d: %d, %d -> %d, %d (should be %d, %d)\n",
   trial,
   sample->pres, sample->temp,
   value_8051.pres, value_8051.temp,
   value.pres, value.temp);
 }
}

variable_types: trial int

variable_types: struct ao_ms5607_sample { unsigned int pres; unsigned int temp; } *

variable_types: struct ao_ms5607_value { int pres; int temp; }


decompiled_code:
__int64 __fastcall i_abs(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return abs32(a1);
}

original_code: static inline int i_abs(int i) { return i < 0 ? -i : i; }


decompiled_code:
__int64 __fastcall ao_pres_to_altitude(__int16 a1)
{
__int16 v1; // ax

v1 = 0;
if ( a1 >= 0 )
v1 = a1;
return (unsigned int)(((256 - (unsigned __int8)v1) * altitude_table[HIBYTE(v1)]
+ (unsigned __int8)v1 * altitude_table[(unsigned __int8)(HIBYTE(v1) + 1)]
+ 128) >> 8);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int16 a1)
{
__int16 v1; // ax

v1 = 0;
if ( a1 >= 0 )
v1 = a1;
return (unsigned int)(((256 - (unsigned __int8)v1) * altitude_table[HIBYTE(v1)]
+ (unsigned __int8)v1 * altitude_table[(unsigned __int8)(HIBYTE(v1) + 1)]
+ 128) >> 8);
}

original_code:
int16_t
ao_pres_to_altitude(int16_t pres)
{
 uint8_t o;
 int16_t part;
 if (pres < 0)
  pres = 0;
 o = pres >> 8;
 part = pres & ((1 << 8) - 1);
 return ((int32_t) altitude_table[o] * ((1 << 8) - part) +
  (int32_t) altitude_table[o+1] * part + ((1 << 8) >> 1)) >> 8;
}

canonical_original_code:
short ao_pres_to_altitude(short pres)
{
 unsigned char o;
 short part;
 if (pres < 0)
  pres = 0;
 o = pres >> 8;
 part = pres & ((1 << 8) - 1);
 return ((int) altitude_table[o] * ((1 << 8) - part) +
  (int) altitude_table[o+1] * part + ((1 << 8) >> 1)) >> 8;
}

variable_types: pres short

variable_types:
o
unsigned char

variable_types: part short

return_type: short


decompiled_code:
__int64 __fastcall ao_altitude_to_pres(__int16 a1)
{
__int16 v1; // r9
unsigned __int8 v3; // si
unsigned __int8 v4; // di
int v5; // edx
int v6; // eax
int v7; // eax
__int16 v8; // r10
int v9; // esi
__int64 result; // rax

v1 = a1;
v3 = 0x80;
v4 = 0;
LABEL_2:
v5 = v4;
while ( 1 )
{
v6 = v3;
if ( v3 - v5 == 1 )
break;
v7 = (v5 + v3) >> 1;
v4 = v7;
if ( altitude_table[v7] >= a1 )
goto LABEL_2;
v3 = v7;
}
v8 = altitude_table[v5] - altitude_table[v3];
v9 = (__int16)(altitude_table[v5] - v1);
result = (unsigned int)(((v8 >> 1) + (((v8 - v9) * v5 + v9 * v6) << 8)) / v8);
if ( (int)result < 0 )
result = 0LL;
if ( (int)result > 0x7FFF )
result = 0x7FFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int16 a1)
{
__int16 v1; // r9
unsigned __int8 v3; // si
unsigned __int8 v4; // di
int v5; // edx
int v6; // eax
int v7; // eax
__int16 v8; // r10
int v9; // esi
__int64 result; // rax

v1 = a1;
v3 = 0x80;
v4 = 0;
LABEL_2:
v5 = v4;
while ( 1 )
{
v6 = v3;
if ( v3 - v5 == 1 )
break;
v7 = (v5 + v3) >> 1;
v4 = v7;
if ( altitude_table[v7] >= a1 )
goto LABEL_2;
v3 = v7;
}
v8 = altitude_table[v5] - altitude_table[v3];
v9 = (__int16)(altitude_table[v5] - v1);
result = (unsigned int)(((v8 >> 1) + (((v8 - v9) * v5 + v9 * v6) << 8)) / v8);
if ( (int)result < 0 )
result = 0LL;
if ( (int)result > 0x7FFF )
result = 0x7FFFLL;
return result;
}

original_code:
int16_t
ao_altitude_to_pres(int16_t alt)
{
 int16_t span, sub_span;
 uint8_t l, h, m;
 int32_t pres;
 l = 0;
 h = 129 - 1;
 while ((h - l) != 1) {
  m = (l + h) >> 1;
  if (altitude_table[m] < alt)
   h = m;
  else
   l = m;
 }
 span = altitude_table[l] - altitude_table[h];
 sub_span = altitude_table[l] - alt;
 pres = ((((int32_t) l * (span - sub_span) + (int32_t) h * sub_span) << 8) + (span >> 1)) / span;
 if (pres > 32767)
  pres = 32767;
 if (pres < 0)
  pres = 0;
 return (int16_t) pres;
}

canonical_original_code:
short ao_altitude_to_pres(short alt)
{
 short span; short sub_span;
 unsigned char l; unsigned char h; unsigned char m;
 int pres;
 l = 0;
 h = 129 - 1;
 while ((h - l) != 1) {
  m = (l + h) >> 1;
  if (altitude_table[m] < alt)
   h = m;
  else
   l = m;
 }
 span = altitude_table[l] - altitude_table[h];
 sub_span = altitude_table[l] - alt;
 pres = ((((int) l * (span - sub_span) + (int) h * sub_span) << 8) + (span >> 1)) / span;
 if (pres > 32767)
  pres = 32767;
 if (pres < 0)
  pres = 0;
 return (short) pres;
}

variable_types: alt short

variable_types: span short

variable_types:
l
unsigned char

variable_types:
h
unsigned char

variable_types:
m
unsigned char

variable_types: pres int


repo: akaehy/Project

decompiled_code:
void __fastcall __noreturn consumer_main(void *a1)
{
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
sem_wait(&global_value_sem);
++global_value;
sem_getvalue(&global_value_sem, sval);
fprintf(stdout, "[Thread #%02d] Acquire resource, sem_value = %d \n", (unsigned int)a1, (unsigned int)sval[0]);
sleep(1u);
sem_post(&global_value_sem);
sleep((_DWORD)a1 + 1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int sval[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
sem_wait(&global_value_sem);
++global_value;
sem_getvalue(&global_value_sem, sval);
fprintf(stdout, "[Thread #%02d] Acquire resource, sem_value = %d \n", (unsigned int)a1, (unsigned int)sval[0]);
sleep(1u);
sem_post(&global_value_sem);
sleep((_DWORD)a1 + 1);
}
}

original_code:
void *consumer_main(void *arg)
{
  int id = (int) arg;
  for (;;)
  {
    sem_wait(&global_value_sem);
    global_value++;
    int sem_value;
    sem_getvalue(&global_value_sem, &sem_value);
    fprintf(stdout, "[Thread #%02d] Acquire resource, sem_value = %d \n", id, sem_value);
    sleep(1);
    sem_post(&global_value_sem);
    sleep(id+1);
  }
  pthread_exit((void *) 0);
}

variable_types:
arg
void *

variable_types: id int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbx
pthread_t *v4; // r12
char *v5; // rbp
_BYTE v6[80]; // [rsp+0h] [rbp-68h] BYREF
__int64 v7; // [rsp+50h] [rbp-18h] BYREF

sem_init(&global_value_sem, 0, 3u);
v3 = (pthread_t *)v6;
v4 = (pthread_t *)v6;
v5 = 0LL;
do
pthread_create(v4++, 0LL, (void *(*)(void *))consumer_main, v5++);
while ( v5 != (char *)10 );
do
pthread_join(*v3++, 0LL);
while ( v3 != (pthread_t *)&v7 );
sem_destroy(&global_value_sem);
pthread_exit(0LL);
}

original_code:
int main(int argc, char **argv)
{
  pthread_t threads[10];
  int code;
  sem_init(&global_value_sem, 0, 3);
  int i;
  for (i = 0; i < 10; i++)
  {
    code = pthread_create(&threads[i], ((void *)0), consumer_main, (void *) i);
  }
  for (i = 0; i < 10; i++)
  {
    pthread_join(threads[i], ((void *)0));
  }
  sem_destroy(&global_value_sem);
  pthread_exit((void *) 0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  unsigned long threads[10];
  int code;
  sem_init(&global_value_sem, 0, 3);
  int i;
  for (i = 0; i < 10; i++)
  {
    code = pthread_create(&threads[i], ((void *)0), consumer_main, (void *) i);
  }
  for (i = 0; i < 10; i++)
  {
    pthread_join(threads[i], ((void *)0));
  }
  sem_destroy(&global_value_sem);
  pthread_exit((void *) 0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
threads
unsigned long [10]

variable_types: code int

variable_types: i int


partition

decompiled_code:
int __fastcall partition(unsigned int a1)
{
return printf("%hx, %hx\n", (unsigned __int16)a1, HIWORD(a1));
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("%hx, %hx\n", (unsigned __int16)a1, HIWORD(a1));
}

original_code:
void partition(unsigned n)
{
 un_t u;
 u.n = n;
 printf("%hx, %hx\n", u.s_n[0], u.s_n[1]);
}

canonical_original_code:
void partition(unsigned int n)
{
 union un_t u;
 u.n = n;
 printf("%hx, %hx\n", u.s_n[0], u.s_n[1]);
}

variable_types:
n
unsigned int

variable_types: union un_t { unsigned int n; unsigned short s_n[2]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+Ch] [rbp-Ch]

printf("enter a num:");
__isoc99_scanf();
partition(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+Ch] [rbp-Ch]

printf("enter a num:");
__isoc99_scanf();
func7(v4);
return 0;
}

original_code:
int main(void)
{
 unsigned n;
 printf("enter a num:");
 scanf("%x", &n);
 partition(n);
 return 0;
}

canonical_original_code:
int main()
{
 unsigned int n;
 printf("enter a num:");
 scanf("%x", &n);
 partition(n);
 return 0;
}


decompiled_code:
__int64 __fastcall cmp_int(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int cmp_int(void *a, void *b)
{
 return *(int *)a - *(int *)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall cmp_std(__int64 a1, __int64 a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 20) - *(_DWORD *)(a2 + 20));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
return (unsigned int)(*(_DWORD *)(a1 + 20) - *(_DWORD *)(a2 + 20));
}

original_code:
int cmp_std(void *a, void *b)
{
 return ((std_t *)a)->score - ((std_t *)b)->score;
}

canonical_original_code:
int cmp_std(void *a, void *b)
{
 return ((struct student *)a)->score - ((struct student *)b)->score;
}

user_defined_types: struct student { char name[20]; unsigned int score; }


decompiled_code:
int __fastcall cmp_str(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func9(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
int cmp_str(void *a, void *b)
{
 return strcmp(*(char **)a, *(char **)b);
}


max

original_code:
void *max(void *base, int len, int size, cmp_t cmp)
{
 char *baseaddr = base, *maxp = base;
 int i;
 for(i = 1; i < len; i++)
  if(cmp(maxp, baseaddr + i * size) < 0)
   maxp = baseaddr + i * size;
 return (void *)maxp;
}

canonical_original_code:
void *max(void *base, int len, int size, int (*cmp)(void *, void *))
{
 char *baseaddr = base; char *maxp = base;
 int i;
 for(i = 1; i < len; i++)
  if(cmp(maxp, baseaddr + i * size) < 0)
   maxp = baseaddr + i * size;
 return (void *)maxp;
}

variable_types:
base
void *

variable_types: len int

variable_types: size int

variable_types:
cmp
int (*)(void *, void *)

variable_types:
baseaddr
char *

variable_types:
maxp
char *


main

original_code:
int main(void)
{
 int num[5], i;
 char *strp[5] = {"hello", "aka", "world", "program", "week"};
 char **maxstrp;
 std_t stdinfo[4] = {{"name1", 78}, {"name2", 69}, {"name3", 88}, {"name4", 67}};
 std_t *maxstdp;
 srand(time(((void *)0)));
 for(i = 0; i < 5; i++)
  printf("%d ", num[i] = rand() % 50);
 printf("\n");
 printf("max_n:%d\n", *((int *)(max(num, 5, 4, cmp_int))));
 maxstdp = max(stdinfo, 4, sizeof(std_t), cmp_std);
 printf("max_std:%s %u\n", maxstdp->name, maxstdp->score);
 maxstrp = max(strp, 5, 4, cmp_str);
 printf("max_str:%s\n", *maxstrp);
 return 0;
}

canonical_original_code:
int main()
{
 int num[5]; int i;
 char *strp[5] = {"hello", "aka", "world", "program", "week"};
 char **maxstrp;
 struct student stdinfo[4] = {{"name1", 78}, {"name2", 69}, {"name3", 88}, {"name4", 67}};
 struct student *maxstdp;
 srand(time(((void *)0)));
 for(i = 0; i < 5; i++)
  printf("%d ", num[i] = rand() % 50);
 printf("\n");
 printf("max_n:%d\n", *((int *)(max(num, 5, 4, cmp_int))));
 maxstdp = max(stdinfo, 4, sizeof(std_t), cmp_std);
 printf("max_std:%s %u\n", maxstdp->name, maxstdp->score);
 maxstrp = max(strp, 5, 4, cmp_str);
 printf("max_str:%s\n", *maxstrp);
 return 0;
}

variable_types:
num
int [5]

variable_types:
strp
char *[5]

variable_types:
maxstrp
char **

variable_types: struct student { char name[20]; unsigned int score; } [4]

variable_types: struct student { char name[20]; unsigned int score; } *


mydiv

decompiled_code:
__int64 __fastcall mydiv(int a1, int a2)
{
return (unsigned int)(a1 / a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
return (unsigned int)(a1 / a2);
}

original_code: int mydiv(int a, int b){ return a / b;}

canonical_original_code: int mydiv(int a, int b){ return a / b;}

variable_types: a int

variable_types: b int


add

decompiled_code:
__int64 __fastcall add(int a1, int a2)
{
return (unsigned int)(a1 + a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)(a1 + a2);
}

original_code: int add(int a, int b){ return a + b;}

canonical_original_code: int add(int a, int b){ return a + b;}


sub

decompiled_code:
__int64 __fastcall sub(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
return (unsigned int)(a1 - a2);
}

original_code: int sub(int a, int b){ return a - b;}

canonical_original_code: int sub(int a, int b){ return a - b;}


mul

decompiled_code:
__int64 __fastcall mul(int a1, int a2)
{
return (unsigned int)(a2 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
return (unsigned int)(a2 * a1);
}

original_code: int mul(int a, int b){ return a * b;}

canonical_original_code: int mul(int a, int b){ return a * b;}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char *v4; // rdx
int v5; // eax
int v7; // [rsp+4h] [rbp-54h]
int v8; // [rsp+8h] [rbp-50h]
char v9; // [rsp+Fh] [rbp-49h]
char v10; // [rsp+10h] [rbp-48h] BYREF
__int64 (__fastcall *v11)(int, int); // [rsp+18h] [rbp-40h]
char v12; // [rsp+20h] [rbp-38h]
__int64 (__fastcall *v13)(int, int); // [rsp+28h] [rbp-30h]
char v14; // [rsp+30h] [rbp-28h]
__int64 (__fastcall *v15)(int, int); // [rsp+38h] [rbp-20h]
char v16; // [rsp+40h] [rbp-18h]
__int64 (__fastcall *v17)(int, int); // [rsp+48h] [rbp-10h]

v10 = 43;
v11 = add;
v12 = 45;
v13 = sub;
v14 = 42;
v15 = mul;
v16 = 47;
v17 = mydiv;
LABEL_3:
while ( 1 )
{
printf("input the operator:");
__isoc99_scanf();
if ( v9 == 35 )
return 0;
printf("input a b:");
__isoc99_scanf();
getchar();
v4 = &v10;
v5 = 0;
while ( *v4 != v9 )
{
++v5;
v4 += 16;
if ( v5 == 4 )
goto LABEL_3;
}
v3 = (*(&v11 + 2 * v5))(v8, v7);
printf("result:%d\n", v3);
}
}

original_code:
int main(void)
{
 cmd_t cmd[4] = {{'+', add}, {'-', sub}, {'*', mul}, {'/', mydiv}};
 char c;
 int a, b, i;
 while(1){
  printf("input the operator:");
  scanf("%c", &c);
  if(c == '#')
   break;
  printf("input a b:");
  scanf("%d %d", &a, &b);
  getchar();
  for(i = 0; i < 4; i++){
   if(c == cmd[i].op){
    printf("result:%d\n", cmd[i].fp(a, b));
    break;
   }
  }
 }
 return 0;
}

canonical_original_code:
int main()
{
 struct command cmd[4] = {{'+', add}, {'-', sub}, {'*', mul}, {'/', mydiv}};
 char c;
 int a; int b; int i;
 while(1){
  printf("input the operator:");
  scanf("%c", &c);
  if(c == '#')
   break;
  printf("input a b:");
  scanf("%d %d", &a, &b);
  getchar();
  for(i = 0; i < 4; i++){
   if(c == cmd[i].op){
    printf("result:%d\n", cmd[i].fp(a, b));
    break;
   }
  }
 }
 return 0;
}

variable_types: struct command { char op; int (*fp)(int, int); } [4]

variable_types: c char

variable_types: i int


insertrecord

decompiled_code:
__int64 __fastcall insertrecord(__int64 a1, __int64 a2)
{
float *v2; // rbp
int v3; // er14
__int64 v4; // rbx
int *v5; // rdx
int v6; // ecx

v2 = (float *)malloc(0x30uLL);
puts("Please input the new info(name chgrade mathgrade):");
v3 = 0;
while ( 1 )
{
v4 = *(_QWORD *)(a2 + 40);
if ( v4 )
{
v5 = (int *)a2;
while ( 1 )
{
v6 = *v5;
v5 = (int *)v4;
if ( !*(_QWORD *)(v4 + 40) )
break;
v4 = *(_QWORD *)(v4 + 40);
}
v3 = v6;
}
else
{
v4 = a2;
}
if ( (unsigned int)_isoc99_scanf("%s %4f %4f", v2 + 1, v2 + 6, v2 + 7) == 3 )
break;
puts("Please input again!");
}
*(_DWORD *)v2 = v3 + 2;
v2[8] = (float)(v2[6] + v2[7]) * 0.5;
*((_QWORD *)v2 + 5) = 0LL;
*(_QWORD *)(v4 + 40) = v2;
writetofile(a1, (const char *)a2);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
float *v2; // rbp
int v3; // er14
__int64 v4; // rbx
int *v5; // rdx
int v6; // ecx

v2 = (float *)malloc(0x30uLL);
puts("Please input the new info(name chgrade mathgrade):");
v3 = 0;
while ( 1 )
{
v4 = *(_QWORD *)(a2 + 40);
if ( v4 )
{
v5 = (int *)a2;
while ( 1 )
{
v6 = *v5;
v5 = (int *)v4;
if ( !*(_QWORD *)(v4 + 40) )
break;
v4 = *(_QWORD *)(v4 + 40);
}
v3 = v6;
}
else
{
v4 = a2;
}
if ( (unsigned int)_isoc99_scanf("%s %4f %4f", v2 + 1, v2 + 6, v2 + 7) == 3 )
break;
puts("Please input again!");
}
*(_DWORD *)v2 = v3 + 2;
v2[8] = (float)(v2[6] + v2[7]) * 0.5;
*((_QWORD *)v2 + 5) = 0LL;
*(_QWORD *)(v4 + 40) = v2;
func0(a1, (const char *)a2);
return a2;
}

original_code:
link_t insertrecord(char *filename, link_t head)
{
 link_t newrecord = (link_t)malloc(sizeof(node_t));
 link_t pre;
 int ID = 0;
 printf("Please input the new info(name chgrade mathgrade):\n");
 while(1)
 {
        for(pre = head; pre->next != ((void *)0); pre = pre->next)
  {
   ID = pre->ID;
  }
  if(3 != scanf("%s %4f %4f", newrecord->name, &newrecord->chgrade, &newrecord->mathgrade))
  {
   printf("Please input again!\n");
   continue;
  }
        newrecord->ID = ID + 2;
        newrecord->average = (newrecord->chgrade + newrecord->mathgrade) / 2.0;
  newrecord->next = ((void *)0);
  break;
 }
 if(head == ((void *)0))
  head = newrecord;
 else
  pre->next = newrecord;
 writetofile(filename, head);
 return head;
}

canonical_original_code:
struct node *insertrecord(char *filename, struct node *head)
{
 struct node *newrecord = (link_t)malloc(sizeof(node_t));
 struct node *pre;
 int ID = 0;
 printf("Please input the new info(name chgrade mathgrade):\n");
 while(1)
 {
        for(pre = head; pre->next != ((void *)0); pre = pre->next)
  {
   ID = pre->ID;
  }
  if(3 != scanf("%s %4f %4f", newrecord->name, &newrecord->chgrade, &newrecord->mathgrade))
  {
   printf("Please input again!\n");
   continue;
  }
        newrecord->ID = ID + 2;
        newrecord->average = (newrecord->chgrade + newrecord->mathgrade) / 2.0;
  newrecord->next = ((void *)0);
  break;
 }
 if(head == ((void *)0))
  head = newrecord;
 else
  pre->next = newrecord;
 writetofile(filename, head);
 return head;
}

variable_types:
filename
char *

variable_types:
head
struct node *

variable_types: struct node { unsigned int ID; char name[20]; float chgrade; float mathgrade; float average; struct node *next; } *

variable_types: ID int


myitoa

original_code:
void myitoa(int n, char *str, int radix)
{
 int i = 0, j, remain;
 char tmp;
 do{
  remain = n % radix;
  if(remain > 10){
   str[i++] = remain - 10 + 'A';
  }else{
   str[i++] = remain + '0';
  }
 }while(n /= radix);
 str[i] = '\0';
 for(i--, j = 0; j <= i; i--, j++){
  tmp = str[j];
  str[j] = str[i];
  str[i] = tmp;
 }
}

canonical_original_code:
void myitoa(int n, char *str, int radix)
{
 int i = 0; int j; int remain;
 char tmp;
 do{
  remain = n % radix;
  if(remain > 10){
   str[i++] = remain - 10 + 'A';
  }else{
   str[i++] = remain + '0';
  }
 }while(n /= radix);
 str[i] = '\0';
 for(i--, j = 0; j <= i; i--, j++){
  tmp = str[j];
  str[j] = str[i];
  str[i] = tmp;
 }
}

variable_types: n int

variable_types:
str
char *

variable_types: radix int

variable_types: j int

variable_types: remain int

variable_types: tmp char


deleterecord

decompiled_code:
const char *__fastcall deleterecord(__int64 a1, char *a2)
{
const char *v2; // rbx
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = a2;
v4 = 0;
showinfo();
_isoc99_scanf("%d", v5);
if ( v5[0] == 1 )
{
v4 = 0;
v2 = (const char *)deletebyID(a2, &v4);
}
else if ( v5[0] == 2 )
{
v4 = 0;
v2 = (const char *)deletebyname(a2, &v4);
}
if ( v4 )
writetofile(a1, v2);
return v2;
}

canonical_decompiled_code:
const char *__fastcall func2(__int64 a1, char *a2)
{
const char *v2; // rbx
int v4; // [rsp+8h] [rbp-20h] BYREF
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = a2;
v4 = 0;
func0();
_isoc99_scanf("%d", v5);
if ( v5[0] == 1 )
{
v4 = 0;
v2 = (const char *)deletebyID(a2, &v4);
}
else if ( v5[0] == 2 )
{
v4 = 0;
v2 = (const char *)deletebyname(a2, &v4);
}
if ( v4 )
func1(a1, v2);
return v2;
}

original_code:
link_t deleterecord(char *filename, link_t head)
{
 int selnum;
 int flag = 0;
 showinfo();
 scanf("%d", &selnum);
 switch(selnum)
 {
  case 1: flag = 0;
    head = deletebyID(head, &flag);
    break;
  case 2: flag = 0;
    head = deletebyname(head, &flag);
    break;
  case 3:
  default:
    break;
 }
 if(flag)
  writetofile(filename, head);
 return head;
}

canonical_original_code:
struct node *deleterecord(char *filename, struct node *head)
{
 int selnum;
 int flag = 0;
 showinfo();
 scanf("%d", &selnum);
 switch(selnum)
 {
  case 1: flag = 0;
    head = deletebyID(head, &flag);
    break;
  case 2: flag = 0;
    head = deletebyname(head, &flag);
    break;
  case 3:
  default:
    break;
 }
 if(flag)
  writetofile(filename, head);
 return head;
}

variable_types: selnum int

variable_types: flag int

return_type: struct node { unsigned int ID; char name[20]; float chgrade; float mathgrade; float average; struct node *next; } *


showinfo

decompiled_code:
int showinfo()
{
puts("Please choose the way:\n1.Delete by ID\n2.Delete by name\n3.Exit");
return printf("Your choice:");
}

canonical_decompiled_code:
int func0()
{
puts("Please choose the way:\n1.Delete by ID\n2.Delete by name\n3.Exit");
return printf("Your choice:");
}

original_code:
static void showinfo(void)
{
 printf("Please choose the way:\n1.Delete by ID\n2.Delete by name\n3.Exit\n");
 printf("Your choice:");
}

canonical_original_code:
static void showinfo()
{
 printf("Please choose the way:\n1.Delete by ID\n2.Delete by name\n3.Exit\n");
 printf("Your choice:");
}


decompiled_code:
size_t __fastcall free_memory(void *a1)
{
if ( a1 )
free(a1);
return fwrite("Cancellation cleanup handler: memory freed.\n", 1uLL, 0x2CuLL, stdout);
}

canonical_decompiled_code:
size_t __fastcall func7(void *a1)
{
if ( a1 )
free(a1);
return fwrite("Cancellation cleanup handler: memory freed.\n", 1uLL, 0x2CuLL, stdout);
}

original_code:
void free_memory(void *p)
{
  if (p)
  {
    free(p);
    p = ((void *)0);
  }
  fprintf(stdout, "Cancellation cleanup handler: memory freed.\n");
}

variable_types:
p
void *


decompiled_code:
size_t __fastcall close_file(int a1)
{
if ( a1 >= 0 )
close(a1);
return fwrite("Cancellation cleanup handler: file closed.\n", 1uLL, 0x2BuLL, stdout);
}

canonical_decompiled_code:
size_t __fastcall func9(int a1)
{
if ( a1 >= 0 )
close(a1);
return fwrite("Cancellation cleanup handler: file closed.\n", 1uLL, 0x2BuLL, stdout);
}

original_code:
void close_file(void *arg)
{
  int fd = (int) arg;
  if (fd >= 0)
  {
    close(fd);
  }
  fprintf(stdout, "Cancellation cleanup handler: file closed.\n");
}

variable_types:
arg
void *

variable_types: fd int


decompiled_code:
void *__fastcall start_routine(void *a1)
{
int v1; // ebx
int *v3; // rax
char *v4; // rax
int fd; // [rsp+Ch] [rbp-FCh]
void *ptr; // [rsp+10h] [rbp-F8h]
struct __jmp_buf_tag env; // [rsp+20h] [rbp-E8h] BYREF
int oldtype; // [rsp+F8h] [rbp-10h] BYREF
int oldstate[3]; // [rsp+FCh] [rbp-Ch] BYREF

pthread_setcanceltype(0, &oldtype);
pthread_setcancelstate(1, oldstate);
ptr = malloc(0x400uLL);
if ( !ptr )
fwrite("Allocate memory failed.\n", 1uLL, 0x18uLL, stderr);
pthread_setcancelstate(0, oldstate);
pthread_setcancelstate(1, oldstate);
fd = open("test8", 0);
if ( fd < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Open file %s failed: %s\n", "test8", v4);
}
else
{
fprintf(stdout, "Open file %s successfully, fd = %d\n", "test8", (unsigned int)fd);
}
pthread_setcancelstate(0, oldstate);
if ( __sigsetjmp(&env, 0) )
{
free_memory(ptr);
__pthread_unwind_next((__pthread_unwind_buf_t *)&env);
}
__pthread_register_cancel((__pthread_unwind_buf_t *)&env);
if ( __sigsetjmp((struct __jmp_buf_tag *)&env.__saved_mask.__val[5], 0) )
{
close_file(fd);
__pthread_unwind_next((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
}
__pthread_register_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
fprintf(stdout, "%s:%d:%s() running ...\n", "test8.c", 129LL, "start_routine");
v1 = 50;
do
{
pthread_setcancelstate(1, oldstate);
write(1, ".", 1uLL);
sleep(1u);
pthread_setcancelstate(0, oldstate);
pthread_testcancel();
--v1;
}
while ( v1 );
__pthread_unregister_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
__pthread_unregister_cancel((__pthread_unwind_buf_t *)&env);
pthread_setcancelstate(1, oldstate);
fwrite("Manually free memory and close file.\n", 1uLL, 0x25uLL, stdout);
if ( ptr )
free(ptr);
if ( fd >= 0 )
close(fd);
pthread_setcancelstate(0, oldstate);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebx
int *v3; // rax
char *v4; // rax
int fd; // [rsp+Ch] [rbp-FCh]
void *ptr; // [rsp+10h] [rbp-F8h]
struct __jmp_buf_tag env; // [rsp+20h] [rbp-E8h] BYREF
int oldtype; // [rsp+F8h] [rbp-10h] BYREF
int oldstate[3]; // [rsp+FCh] [rbp-Ch] BYREF

pthread_setcanceltype(0, &oldtype);
pthread_setcancelstate(1, oldstate);
ptr = malloc(0x400uLL);
if ( !ptr )
fwrite("Allocate memory failed.\n", 1uLL, 0x18uLL, stderr);
pthread_setcancelstate(0, oldstate);
pthread_setcancelstate(1, oldstate);
fd = open("test8", 0);
if ( fd < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Open file %s failed: %s\n", "test8", v4);
}
else
{
fprintf(stdout, "Open file %s successfully, fd = %d\n", "test8", (unsigned int)fd);
}
pthread_setcancelstate(0, oldstate);
if ( __sigsetjmp(&env, 0) )
{
func7(ptr);
__pthread_unwind_next((__pthread_unwind_buf_t *)&env);
}
__pthread_register_cancel((__pthread_unwind_buf_t *)&env);
if ( __sigsetjmp((struct __jmp_buf_tag *)&env.__saved_mask.__val[5], 0) )
{
func9(fd);
__pthread_unwind_next((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
}
__pthread_register_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
fprintf(stdout, "%s:%d:%s() running ...\n", "test8.c", 129LL, "start_routine");
v1 = 50;
do
{
pthread_setcancelstate(1, oldstate);
write(1, ".", 1uLL);
sleep(1u);
pthread_setcancelstate(0, oldstate);
pthread_testcancel();
--v1;
}
while ( v1 );
__pthread_unregister_cancel((__pthread_unwind_buf_t *)&env.__saved_mask.__val[5]);
__pthread_unregister_cancel((__pthread_unwind_buf_t *)&env);
pthread_setcancelstate(1, oldstate);
fwrite("Manually free memory and close file.\n", 1uLL, 0x25uLL, stdout);
if ( ptr )
free(ptr);
if ( fd >= 0 )
close(fd);
pthread_setcancelstate(0, oldstate);
return 0LL;
}

original_code:
void *start_routine(void *arg)
{
  int oldstate;
  int oldtype;
  char *p = ((void *)0);
  int fd;
  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
  p = malloc(1024);
  if (p == ((void *)0))
  {
    fprintf(stderr, "Allocate memory failed.\n");
  }
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
  fd = open("test8", 00);
  if (fd < 0)
  {
    fprintf(stderr, "Open file %s failed: %s\n", "test8", strerror((*__errno_location ())));
  }
  else
  {
    fprintf(stdout, "Open file %s successfully, fd = %d\n", "test8", fd);
  }
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
  do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (free_memory); void *__cancel_arg = ((void *) p); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
  do { __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine) (void *) = (close_file); void *__cancel_arg = ((void *) fd); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
  fprintf(stdout, "%s:%d:%s() running ...\n", "test8.c", 129, __func__);
  int i;
  for (i = 0; i < 50; i++)
  {
    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
    write(1, ".", 1);
    sleep(1);
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
    pthread_testcancel();
  }
  do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
  do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
  fprintf(stdout, "Manually free memory and close file.\n");
  if (p != ((void *)0))
  {
    free(p);
  }
  if (fd >= 0)
  {
    close(fd);
  }
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
  return ((void *) 0);
}

canonical_original_code:
void *start_routine(void *arg)
{
  int oldstate;
  int oldtype;
  char *p = ((void *)0);
  int fd;
  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
  p = malloc(1024);
  if (p == ((void *)0))
  {
    fprintf(stderr, "Allocate memory failed.\n");
  }
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
  fd = open("test8", 00);
  if (fd < 0)
  {
    fprintf(stderr, "Open file %s failed: %s\n", "test8", strerror((*__errno_location ())));
  }
  else
  {
    fprintf(stdout, "Open file %s successfully, fd = %d\n", "test8", fd);
  }
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
  do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (free_memory); void *__cancel_arg = ((void *) p); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
  do { struct __pthread_unwind_buf_t __cancel_buf; void (*__cancel_routine)(void *) = (close_file); void *__cancel_arg = ((void *) fd); int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) __cancel_buf.__cancel_jmp_buf, 0); if (__builtin_expect ((__not_first_call), 0)) { __cancel_routine (__cancel_arg); __pthread_unwind_next (&__cancel_buf); } __pthread_register_cancel (&__cancel_buf); do {;
  fprintf(stdout, "%s:%d:%s() running ...\n", "test8.c", 129, __func__);
  int i;
  for (i = 0; i < 50; i++)
  {
    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
    write(1, ".", 1);
    sleep(1);
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
    pthread_testcancel();
  }
  do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
  do { } while (0); } while (0); __pthread_unregister_cancel (&__cancel_buf); if (0) __cancel_routine (__cancel_arg); } while (0);
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
  fprintf(stdout, "Manually free memory and close file.\n");
  if (p != ((void *)0))
  {
    free(p);
  }
  if (fd >= 0)
  {
    close(fd);
  }
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
  return ((void *) 0);
}

variable_types: oldstate int

variable_types: oldtype int

variable_types:
p
char *

variable_types: struct __pthread_unwind_buf_t { struct { long __cancel_jmp_buf[8]; int __mask_was_saved; } __cancel_jmp_buf[1]; void *__pad[4]; }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *v4; // rax
int v5; // eax
char *v6; // rax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = pthread_create(newthread, 0LL, start_routine, 0LL);
if ( v3 )
{
v4 = strerror(v3);
fprintf(stderr, "Create new thread failed: %s\n", v4);
exit(1);
}
fwrite("New thread created.\n", 1uLL, 0x14uLL, stdout);
sleep(5u);
v5 = pthread_cancel(newthread[0]);
if ( v5 )
{
v6 = strerror(v5);
fprintf(stderr, "Send cancel request to target thread failed: %s\n", v6);
}
else
{
fwrite("Send cancel request to target thread successfully.\n", 1uLL, 0x33uLL, stdout);
}
pthread_join(newthread[0], 0LL);
sleep(0x64u);
pthread_exit(0LL);
}

original_code:
int main(int argc, char **argv)
{
  pthread_t tid;
  int code;
  code = pthread_create(&tid, ((void *)0), start_routine, ((void *)0));
  if (code != 0)
  {
    fprintf(stderr, "Create new thread failed: %s\n", strerror(code));
    exit(1);
  }
  fprintf(stdout, "New thread created.\n");
  sleep(5);
  code = pthread_cancel(tid);
  if (code != 0)
  {
    fprintf(stderr, "Send cancel request to target thread failed: %s\n", strerror(code));
  }
  else
  {
    fprintf(stdout, "Send cancel request to target thread successfully.\n");
  }
  pthread_join(tid, ((void *)0));
  sleep(100);
  pthread_exit((void *) 0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  unsigned long tid;
  int code;
  code = pthread_create(&tid, ((void *)0), start_routine, ((void *)0));
  if (code != 0)
  {
    fprintf(stderr, "Create new thread failed: %s\n", strerror(code));
    exit(1);
  }
  fprintf(stdout, "New thread created.\n");
  sleep(5);
  code = pthread_cancel(tid);
  if (code != 0)
  {
    fprintf(stderr, "Send cancel request to target thread failed: %s\n", strerror(code));
  }
  else
  {
    fprintf(stdout, "Send cancel request to target thread successfully.\n");
  }
  pthread_join(tid, ((void *)0));
  sleep(100);
  pthread_exit((void *) 0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
tid
unsigned long

variable_types: code int


decompiled_code:
ssize_t cleanup_function1()
{
size_t v0; // rax
__int64 v2; // [rsp+0h] [rbp-418h]
char s[1032]; // [rsp+10h] [rbp-408h] BYREF

snprintf(s, 0x3FFuLL, "Calling %s:%d:%s() with arg %d\n", "test8.c", 198LL, "cleanup_function1", v2);
v0 = strlen(s);
return write(1, s, v0);
}

canonical_decompiled_code:
ssize_t func10()
{
size_t v0; // rax
__int64 v2; // [rsp+0h] [rbp-418h]
char s[1032]; // [rsp+10h] [rbp-408h] BYREF

snprintf(s, 0x3FFuLL, "Calling %s:%d:%s() with arg %d\n", "test8.c", 198LL, "cleanup_function1", v2);
v0 = strlen(s);
return write(1, s, v0);
}

original_code:
void cleanup_function1(void *arg)
{
  int value = (int) arg;
  char buffer[1024];
  snprintf(buffer, sizeof(buffer) - 1, "Calling %s:%d:%s() with arg %d\n", "test8.c", 198, __func__, value);
  write(1, buffer, strlen(buffer));
}

variable_types: value int

variable_types:
buffer
char [1024]


decompiled_code:
ssize_t cleanup_function2()
{
size_t v0; // rax
const void *v2; // [rsp+0h] [rbp-418h]
char s[1032]; // [rsp+10h] [rbp-408h] BYREF

snprintf(s, 0x3FFuLL, "Calling %s:%d:%s() with arg %p\n", "test8.c", 212LL, "cleanup_function2", v2);
v0 = strlen(s);
return write(1, s, v0);
}

canonical_decompiled_code:
ssize_t func11()
{
size_t v0; // rax
const void *v2; // [rsp+0h] [rbp-418h]
char s[1032]; // [rsp+10h] [rbp-408h] BYREF

snprintf(s, 0x3FFuLL, "Calling %s:%d:%s() with arg %p\n", "test8.c", 212LL, "cleanup_function2", v2);
v0 = strlen(s);
return write(1, s, v0);
}

original_code:
void cleanup_function2(void *arg)
{
  char buffer[1024];
  char *p = (char *) arg;
  snprintf(buffer, sizeof(buffer) - 1, "Calling %s:%d:%s() with arg %p\n", "test8.c", 212, __func__, p);
  write(1, buffer, strlen(buffer));
}


printstr

decompiled_code:
int __fastcall printstr(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return puts(a1);
}

original_code:
void printstr(void *str)
{
 printf("%s\n", (char *)str);
}

variable_types:
str
void *


printnum

decompiled_code:
int __fastcall printnum(__int64 a1)
{
return printf("%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
return printf("%d\n", a1);
}

original_code:
void printnum(void *n)
{
 printf("%d\n", (int)n);
}

variable_types:
n
void *


printmsg

decompiled_code:
__int64 __fastcall printmsg(__int64 (__fastcall *a1)(__int64), __int64 a2)
{
return a1(a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 (__fastcall *a1)(__int64), __int64 a2)
{
return a1(a2);
}

original_code:
void printmsg(funcp_t fp, void *arg)
{
 fp(arg);
}

canonical_original_code:
void printmsg(void (*fp)(void *), void *arg)
{
 fp(arg);
}

variable_types:
fp
void (*)(void *)


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
printmsg((__int64 (__fastcall *)(__int64))printstr, (__int64)"hello");
printmsg((__int64 (__fastcall *)(__int64))printnum, 123LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9((__int64 (__fastcall *)(__int64))printstr, (__int64)"hello");
func9((__int64 (__fastcall *)(__int64))printnum, 123LL);
return 0;
}

original_code:
int main(void)
{
 printmsg(printstr, (void *)"hello");
 printmsg(printnum, (void *)123);
 return 0;
}

canonical_original_code:
int main()
{
 printmsg(printstr, (void *)"hello");
 printmsg(printnum, (void *)123);
 return 0;
}


showstu

variable_types: struct node { unsigned int ID; char name[20]; float chgrade; float mathgrade; float average; struct node *next; } *

variable_types: i int


showinfo

decompiled_code:
int showinfo()
{
puts("Please select the option:");
puts("1.Display all student's info");
puts("2.Sort by average");
puts("3.Insert a new info");
puts("4.Delete a record");
puts("5.Quit");
return printf("Please input your choice:");
}

canonical_decompiled_code:
int func0()
{
puts("Please select the option:");
puts("1.Display all student's info");
puts("2.Sort by average");
puts("3.Insert a new info");
puts("4.Delete a record");
puts("5.Quit");
return printf("Please input your choice:");
}

original_code:
void showinfo(void)
{
 printf("Please select the option:\n");
 printf("1.Display all student's info\n");
 printf("2.Sort by average\n");
 printf("3.Insert a new info\n");
 printf("4.Delete a record\n");
 printf("5.Quit\n");
 printf("Please input your choice:");
}

canonical_original_code:
void showinfo()
{
 printf("Please select the option:\n");
 printf("1.Display all student's info\n");
 printf("2.Sort by average\n");
 printf("3.Insert a new info\n");
 printf("4.Delete a record\n");
 printf("5.Quit\n");
 printf("Please input your choice:");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rbx
int v5; // er14
int v6; // ebp
const char *v7; // r13
const char *v8; // rax
int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( argc != 2 )
{
fwrite("Usage argument:./app \"filename\"\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
LODWORD(v3) = creat(argv[1], 0);
v4 = v3;
v5 = 1;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
showinfo();
_isoc99_scanf("%d", v10);
switch ( v10[0] )
{
case 1:
showstu(v4);
continue;
case 2:
if ( v6 == 1 )
{
link_destroy(v7);
}
else if ( v5 != 1 )
{
goto LABEL_8;
}
LODWORD(v8) = creat(argv[1], 1u);
v7 = v8;
v5 = 0;
LABEL_8:
showstu(v7);
v6 = 0;
break;
case 3:
v4 = (const char *)insertrecord(argv[1], v4);
v6 = 1;
continue;
case 4:
v4 = (const char *)deleterecord(argv[1], v4);
showstu(v4);
v6 = 1;
continue;
case 5:
if ( v4 )
link_destroy(v4);
if ( v7 )
link_destroy(v7);
return 0;
default:
continue;
}
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rbx
int v5; // er14
int v6; // ebp
const char *v7; // r13
const char *v8; // rax
int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( argc != 2 )
{
fwrite("Usage argument:./app \"filename\"\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
LODWORD(v3) = creat(argv[1], 0);
v4 = v3;
v5 = 1;
v6 = 0;
v7 = 0LL;
while ( 1 )
{
func0();
_isoc99_scanf("%d", v10);
switch ( v10[0] )
{
case 1:
func1(v4);
continue;
case 2:
if ( v6 == 1 )
{
link_destroy(v7);
}
else if ( v5 != 1 )
{
goto LABEL_8;
}
LODWORD(v8) = creat(argv[1], 1u);
v7 = v8;
v5 = 0;
LABEL_8:
func1(v7);
v6 = 0;
break;
case 3:
v4 = (const char *)insertrecord(argv[1], v4);
v6 = 1;
continue;
case 4:
v4 = (const char *)deleterecord(argv[1], v4);
func1(v4);
v6 = 1;
continue;
case 5:
if ( v4 )
link_destroy(v4);
if ( v7 )
link_destroy(v7);
return 0;
default:
continue;
}
}
}

original_code:
int main(int argc, char *argv[])
{
 int selnum;
 link_t head_show = ((void *)0), head_sort = ((void *)0);
 int flagbyaverage = 1, ins_del_flag = 0, firstsort = 1;
 if(argc != 2)
 {
  fprintf(stderr, "Usage argument:./app \"filename\"\n");
  exit(1);
 }
 head_show = creat(argv[1], !flagbyaverage, head_show);
 while(1)
 {
  showinfo();
  scanf("%d", &selnum);
  switch(selnum)
  {
   case 1: showstu(head_show);
     break;
   case 2:
                    if(ins_del_flag == 1){
                        link_destroy(head_sort);
                        head_sort = ((void *)0);
                    }
                    if(firstsort == 1 || ins_del_flag == 1){
                        head_sort = creat(argv[1], flagbyaverage, head_sort);
                        ins_del_flag = 0;
                        firstsort = 0;
                    }
     showstu(head_sort);
     break;
   case 3: head_show = insertrecord(argv[1], head_show);
                    ins_del_flag = 1;
     break;
   case 4: head_show = deleterecord(argv[1],head_show);
                    ins_del_flag = 1;
     showstu(head_show);
     break;
   case 5: if(head_show)
                        link_destroy(head_show);
                    if(head_sort)
                        link_destroy(head_sort);
     return 0;
   default: break;
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int selnum;
 struct node *head_show = ((void *)0); struct node *head_sort = ((void *)0);
 int flagbyaverage = 1; int ins_del_flag = 0; int firstsort = 1;
 if(argc != 2)
 {
  fprintf(stderr, "Usage argument:./app \"filename\"\n");
  exit(1);
 }
 head_show = creat(argv[1], !flagbyaverage, head_show);
 while(1)
 {
  showinfo();
  scanf("%d", &selnum);
  switch(selnum)
  {
   case 1: showstu(head_show);
     break;
   case 2:
                    if(ins_del_flag == 1){
                        link_destroy(head_sort);
                        head_sort = ((void *)0);
                    }
                    if(firstsort == 1 || ins_del_flag == 1){
                        head_sort = creat(argv[1], flagbyaverage, head_sort);
                        ins_del_flag = 0;
                        firstsort = 0;
                    }
     showstu(head_sort);
     break;
   case 3: head_show = insertrecord(argv[1], head_show);
                    ins_del_flag = 1;
     break;
   case 4: head_show = deleterecord(argv[1],head_show);
                    ins_del_flag = 1;
     showstu(head_show);
     break;
   case 5: if(head_show)
                        link_destroy(head_show);
                    if(head_sort)
                        link_destroy(head_sort);
     return 0;
   default: break;
  }
 }
 return 0;
}

variable_types:
argv
char *[]

variable_types: selnum int

variable_types: flagbyaverage int

variable_types: firstsort int

user_defined_types: struct node { unsigned int ID; char name[20]; float chgrade; float mathgrade; float average; struct node *next; }


decompiled_code:
int __fastcall get_record(__int64 a1, int a2)
{
int result; // eax
__int64 v3; // rbx
int v4; // ebp

result = puts("Please input student record like zhang 88 78, then Enter");
if ( a2 > 0 )
{
v3 = a1 + 4;
v4 = 0;
do
{
*(_DWORD *)(v3 - 4) = ++v4;
result = __isoc99_scanf();
v3 += 32LL;
}
while ( v4 != a2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, int a2)
{
int result; // eax
__int64 v3; // rbx
int v4; // ebp

result = puts("Please input student record like zhang 88 78, then Enter");
if ( a2 > 0 )
{
v3 = a1 + 4;
v4 = 0;
do
{
*(_DWORD *)(v3 - 4) = ++v4;
result = __isoc99_scanf();
v3 += 32LL;
}
while ( v4 != a2 );
}
return result;
}

original_code:
void get_record(std_t std[], int len)
{
    int i;
 printf("Please input student record like zhang 88 78, then Enter\n");
    for(i = 0; i < len; i++)
 {
  std[i].id = i+1;
        scanf("%s %d %d", std[i].name, &std[i].math, &std[i].eng);
 }
}

canonical_original_code:
void get_record(struct std_t std[], int len)
{
    int i;
 printf("Please input student record like zhang 88 78, then Enter\n");
    for(i = 0; i < len; i++)
 {
  std[i].id = i+1;
        scanf("%s %d %d", std[i].name, &std[i].math, &std[i].eng);
 }
}

variable_types: struct std_t { unsigned int id; char name[20]; unsigned int math; } []

variable_types: len int


decompiled_code:
void __fastcall __noreturn sys_err(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void sys_err(const char *msg)
{
    perror(msg);
    exit(1);
}

canonical_original_code:
void sys_err(char *msg)
{
    perror(msg);
    exit(1);
}

variable_types:
msg
char *


decompiled_code:
int __fastcall show_msg(int a1)
{
int result; // eax

if ( a1 == 1 )
return printf("1.Display std msg\n2.Sort by average\n3.Insert a new rec\n4.Exit\nPlease choose:");
if ( a1 == 2 )
{
puts("ID\tNAME\tMATH\tENG\tAVE");
result = puts("-------------------------------------------");
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
int result; // eax

if ( a1 == 1 )
return printf("1.Display std msg\n2.Sort by average\n3.Insert a new rec\n4.Exit\nPlease choose:");
if ( a1 == 2 )
{
puts("ID\tNAME\tMATH\tENG\tAVE");
result = puts("-------------------------------------------");
}
return result;
}

original_code:
void show_msg(int sign)
{
    switch(sign){
    case 1:printf("1.Display std msg\n2.Sort by average\n3.Insert a new rec\n4.Exit\nPlease choose:");
           break;
    case 2:printf("ID\tNAME\tMATH\tENG\tAVE\n");
           printf("-------------------------------------------\n");
           break;
    }
}

variable_types: sign int


display

decompiled_code:
int __fastcall display(__int64 a1, int a2)
{
int result; // eax
__int64 v3; // rbx

result = show_msg(2);
if ( a2 > 0 )
{
v3 = a1 + 4;
do
{
result = printf(
"%u\t%s\t%d\t%d\t%.2f\n",
*(unsigned int *)(v3 - 4),
(const char *)v3,
*(unsigned int *)(v3 + 20),
*(unsigned int *)(v3 + 24),
(double)(*(_DWORD *)(v3 + 20) + *(_DWORD *)(v3 + 24)) * 0.5);
v3 += 40LL;
}
while ( v3 != a1 + 40LL * (unsigned int)(a2 - 1) + 44 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, int a2)
{
int result; // eax
__int64 v3; // rbx

result = func7(2);
if ( a2 > 0 )
{
v3 = a1 + 4;
do
{
result = printf(
"%u\t%s\t%d\t%d\t%.2f\n",
*(unsigned int *)(v3 - 4),
(const char *)v3,
*(unsigned int *)(v3 + 20),
*(unsigned int *)(v3 + 24),
(double)(*(_DWORD *)(v3 + 20) + *(_DWORD *)(v3 + 24)) * 0.5);
v3 += 40LL;
}
while ( v3 != a1 + 40LL * (unsigned int)(a2 - 1) + 44 );
}
return result;
}

original_code:
void display(std_t *stdp, int len)
{
    int i;
    show_msg(2);
    for(i = 0; i < len; i++){
        printf("%u\t%s\t%d\t%d\t%.2f\n", stdp[i].id, stdp[i].name, stdp[i].math, stdp[i].eng, (stdp[i].math + stdp[i].eng) / 2.0);
    }
}

canonical_original_code:
void display(struct std_t *stdp, int len)
{
    int i;
    show_msg(2);
    for(i = 0; i < len; i++){
        printf("%u\t%s\t%d\t%d\t%.2f\n", stdp[i].id, stdp[i].name, stdp[i].math, stdp[i].eng, (stdp[i].math + stdp[i].eng) / 2.0);
    }
}

variable_types: struct std_t { unsigned int id; char name[20]; unsigned int math; double average; } *