decompiled_code:
__int64 __fastcall read_next(void *buf, __int64 a2)
{
__off64_t v4; // rsi
__int64 result; // rax
int v6; // eax
unsigned int v7; // edi
int v8; // eax
unsigned int v9; // edi
int v10; // eax
unsigned __int64 v11; // rdi
unsigned __int64 v12; // rax
unsigned __int64 v13; // rdi
unsigned __int64 v14; // rax
int v15; // eax
int v16; // eax
int v17; // eax
int v18; // eax
int v19; // eax
FILE *v20; // rcx
size_t v21; // rdx

while ( 1 )
{
result = read(*((_DWORD *)buf + 12), buf, 0x30uLL);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result != 48 )
{
perror("Reading trace\n");
exit(1);
}
v6 = native_trace;
v7 = *(_DWORD *)buf;
if ( native_trace < 0 )
{
v6 = check_data_endianness(v7);
native_trace = v6;
if ( v6 < 0 )
_assert_fail("native_trace>=0", "trace_reader/trace.c", 0x4Eu, "read_next");
}
if ( !v6 )
{
v8 = _bswap_32(v7);
v9 = *((_DWORD *)buf + 1);
*(_DWORD *)buf = v8;
v10 = _bswap_32(v9);
v11 = *((_QWORD *)buf + 1);
*((_DWORD *)buf + 1) = v10;
v12 = _bswap_64(v11);
v13 = *((_QWORD *)buf + 2);
*((_QWORD *)buf + 1) = v12;
v14 = _bswap_64(v13);
LODWORD(v13) = *((_DWORD *)buf + 6);
*((_QWORD *)buf + 2) = v14;
v15 = _bswap_32(v13);
LODWORD(v13) = *((_DWORD *)buf + 7);
*((_DWORD *)buf + 6) = v15;
v16 = _bswap_32(v13);
LODWORD(v13) = *((_DWORD *)buf + 8);
*((_DWORD *)buf + 7) = v16;
v17 = _bswap_32(v13);
LODWORD(v13) = *((_DWORD *)buf + 9);
*((_DWORD *)buf + 8) = v17;
v18 = _bswap_32(v13);
LODWORD(v13) = *((_DWORD *)buf + 10);
*((_DWORD *)buf + 9) = v18;
v19 = _bswap_32(v13);
v20 = stderr;
*((_DWORD *)buf + 10) = v19;
fwrite("Wrong endian conversion", 1uLL, v21, v20);
exit(1);
}
if ( (unsigned int)verify_trace_isra_0(v7) )
{
fwrite("Bad trace!\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
v4 = *((unsigned __int16 *)buf + 23);
*((_QWORD *)buf + 1) -= a2;
if ( (_WORD)v4 )
{
if ( (unsigned int)lseek64(*((_DWORD *)buf + 12), v4, 1) == -1 )
{
perror("Skipping pdu");
exit(1);
}
}
result = not_real_event((__int64)buf);
if ( !(_DWORD)result )
return result;
}
*((_DWORD *)buf + 13) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *buf, __int64 a2)
{
__off64_t v4; // rsi
__int64 result; // rax
int v6; // eax
unsigned int v7; // edi
int v8; // eax
unsigned int v9; // edi
int v10; // eax
unsigned __int64 v11; // rdi
unsigned __int64 v12; // rax
unsigned __int64 v13; // rdi
unsigned __int64 v14; // rax
int v15; // eax
int v16; // eax
int v17; // eax
int v18; // eax
int v19; // eax
FILE *v20; // rcx
size_t v21; // rdx

while ( 1 )
{
result = read(*((_DWORD *)buf + 12), buf, 0x30uLL);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result != 48 )
{
perror("Reading trace\n");
exit(1);
}
v6 = native_trace;
v7 = *(_DWORD *)buf;
if ( native_trace < 0 )
{
v6 = func4(v7);
native_trace = v6;
if ( v6 < 0 )
_assert_fail("native_trace>=0", "trace_reader/trace.c", 0x4Eu, "read_next");
}
if ( !v6 )
{
v8 = func3(v7);
v9 = *((_DWORD *)buf + 1);
*(_DWORD *)buf = v8;
v10 = func3(v9);
v11 = *((_QWORD *)buf + 1);
*((_DWORD *)buf + 1) = v10;
v12 = func2(v11);
v13 = *((_QWORD *)buf + 2);
*((_QWORD *)buf + 1) = v12;
v14 = func2(v13);
LODWORD(v13) = *((_DWORD *)buf + 6);
*((_QWORD *)buf + 2) = v14;
v15 = func3(v13);
LODWORD(v13) = *((_DWORD *)buf + 7);
*((_DWORD *)buf + 6) = v15;
v16 = func3(v13);
LODWORD(v13) = *((_DWORD *)buf + 8);
*((_DWORD *)buf + 7) = v16;
v17 = func3(v13);
LODWORD(v13) = *((_DWORD *)buf + 9);
*((_DWORD *)buf + 8) = v17;
v18 = func3(v13);
LODWORD(v13) = *((_DWORD *)buf + 10);
*((_DWORD *)buf + 9) = v18;
v19 = func3(v13);
v20 = stderr;
*((_DWORD *)buf + 10) = v19;
fwrite("Wrong endian conversion", 1uLL, v21, v20);
exit(1);
}
if ( (unsigned int)func6(v7) )
{
fwrite("Bad trace!\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
v4 = *((unsigned __int16 *)buf + 23);
*((_QWORD *)buf + 1) -= a2;
if ( (_WORD)v4 )
{
if ( (unsigned int)lseek64(*((_DWORD *)buf + 12), v4, 1) == -1 )
{
perror("Skipping pdu");
exit(1);
}
}
result = func7((__int64)buf);
if ( !(_DWORD)result )
return result;
}
*((_DWORD *)buf + 13) = 1;
return result;
}

original_code:
void read_next(struct trace_file *tf, __u64 genesis)
{
 int e;
 do {
  e = read(tf->fd,&tf->t,sizeof(struct blk_io_trace));
  if(e==0) {
   tf->eof = (!(0));
   break;
  } else if(e==-1 || e!=sizeof(struct blk_io_trace)) {
   do { perror("Reading trace\n"); exit(1); } while(0);
  } else {
   if(native_trace<0)
    native_trace = check_data_endianness(tf->t.magic);
   ((void) sizeof ((native_trace>=0) ? 1 : 0), __extension__ ({ if (native_trace>=0) ; else __assert_fail ("native_trace>=0", "trace_reader/trace.c", 78, __extension__ __PRETTY_FUNCTION__); }));
   if(!native_trace) {
    do { if(sizeof(tf->t.magic) == sizeof(__u32)) tf->t.magic = __bswap_32(tf->t.magic); else if(sizeof(tf->t.magic) == sizeof(__u64)) tf->t.magic = __bswap_64(tf->t.magic); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.sequence) == sizeof(__u32)) tf->t.sequence = __bswap_32(tf->t.sequence); else if(sizeof(tf->t.sequence) == sizeof(__u64)) tf->t.sequence = __bswap_64(tf->t.sequence); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.time) == sizeof(__u32)) tf->t.time = __bswap_32(tf->t.time); else if(sizeof(tf->t.time) == sizeof(__u64)) tf->t.time = __bswap_64(tf->t.time); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.sector) == sizeof(__u32)) tf->t.sector = __bswap_32(tf->t.sector); else if(sizeof(tf->t.sector) == sizeof(__u64)) tf->t.sector = __bswap_64(tf->t.sector); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.bytes) == sizeof(__u32)) tf->t.bytes = __bswap_32(tf->t.bytes); else if(sizeof(tf->t.bytes) == sizeof(__u64)) tf->t.bytes = __bswap_64(tf->t.bytes); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.action) == sizeof(__u32)) tf->t.action = __bswap_32(tf->t.action); else if(sizeof(tf->t.action) == sizeof(__u64)) tf->t.action = __bswap_64(tf->t.action); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.pid) == sizeof(__u32)) tf->t.pid = __bswap_32(tf->t.pid); else if(sizeof(tf->t.pid) == sizeof(__u64)) tf->t.pid = __bswap_64(tf->t.pid); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.device) == sizeof(__u32)) tf->t.device = __bswap_32(tf->t.device); else if(sizeof(tf->t.device) == sizeof(__u64)) tf->t.device = __bswap_64(tf->t.device); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.cpu) == sizeof(__u32)) tf->t.cpu = __bswap_32(tf->t.cpu); else if(sizeof(tf->t.cpu) == sizeof(__u64)) tf->t.cpu = __bswap_64(tf->t.cpu); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.error) == sizeof(__u32)) tf->t.error = __bswap_32(tf->t.error); else if(sizeof(tf->t.error) == sizeof(__u64)) tf->t.error = __bswap_64(tf->t.error); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.pdu_len) == sizeof(__u32)) tf->t.pdu_len = __bswap_32(tf->t.pdu_len); else if(sizeof(tf->t.pdu_len) == sizeof(__u64)) tf->t.pdu_len = __bswap_64(tf->t.pdu_len); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
   }
   if(verify_trace(&tf->t))
    do { fprintf(stderr,"Bad trace!\n"); exit(1); } while(0);
   tf->t.time -= genesis;
   if(tf->t.pdu_len) {
    e = lseek(tf->fd,tf->t.pdu_len,1);
    if(e==-1) do { perror("Skipping pdu"); exit(1); } while(0);
   }
  }
 } while(not_real_event(&tf->t));
}

canonical_original_code:
void read_next(struct trace_file *tf, unsigned long long genesis)
{
 int e;
 do {
  e = read(tf->fd,&tf->t,sizeof(struct blk_io_trace));
  if(e==0) {
   tf->eof = (!(0));
   break;
  } else if(e==-1 || e!=sizeof(struct blk_io_trace)) {
   do { perror("Reading trace\n"); exit(1); } while(0);
  } else {
   if(native_trace<0)
    native_trace = check_data_endianness(tf->t.magic);
   ((void) sizeof ((native_trace>=0) ? 1 : 0), __extension__ ({ if (native_trace>=0) ; else __assert_fail ("native_trace>=0", "trace_reader/trace.c", 78, __extension__ __PRETTY_FUNCTION__); }));
   if(!native_trace) {
    do { if(sizeof(tf->t.magic) == sizeof(__u32)) tf->t.magic = __bswap_32(tf->t.magic); else if(sizeof(tf->t.magic) == sizeof(__u64)) tf->t.magic = __bswap_64(tf->t.magic); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.sequence) == sizeof(__u32)) tf->t.sequence = __bswap_32(tf->t.sequence); else if(sizeof(tf->t.sequence) == sizeof(__u64)) tf->t.sequence = __bswap_64(tf->t.sequence); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.time) == sizeof(__u32)) tf->t.time = __bswap_32(tf->t.time); else if(sizeof(tf->t.time) == sizeof(__u64)) tf->t.time = __bswap_64(tf->t.time); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.sector) == sizeof(__u32)) tf->t.sector = __bswap_32(tf->t.sector); else if(sizeof(tf->t.sector) == sizeof(__u64)) tf->t.sector = __bswap_64(tf->t.sector); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.bytes) == sizeof(__u32)) tf->t.bytes = __bswap_32(tf->t.bytes); else if(sizeof(tf->t.bytes) == sizeof(__u64)) tf->t.bytes = __bswap_64(tf->t.bytes); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.action) == sizeof(__u32)) tf->t.action = __bswap_32(tf->t.action); else if(sizeof(tf->t.action) == sizeof(__u64)) tf->t.action = __bswap_64(tf->t.action); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.pid) == sizeof(__u32)) tf->t.pid = __bswap_32(tf->t.pid); else if(sizeof(tf->t.pid) == sizeof(__u64)) tf->t.pid = __bswap_64(tf->t.pid); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.device) == sizeof(__u32)) tf->t.device = __bswap_32(tf->t.device); else if(sizeof(tf->t.device) == sizeof(__u64)) tf->t.device = __bswap_64(tf->t.device); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.cpu) == sizeof(__u32)) tf->t.cpu = __bswap_32(tf->t.cpu); else if(sizeof(tf->t.cpu) == sizeof(__u64)) tf->t.cpu = __bswap_64(tf->t.cpu); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.error) == sizeof(__u32)) tf->t.error = __bswap_32(tf->t.error); else if(sizeof(tf->t.error) == sizeof(__u64)) tf->t.error = __bswap_64(tf->t.error); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
    do { if(sizeof(tf->t.pdu_len) == sizeof(__u32)) tf->t.pdu_len = __bswap_32(tf->t.pdu_len); else if(sizeof(tf->t.pdu_len) == sizeof(__u64)) tf->t.pdu_len = __bswap_64(tf->t.pdu_len); else do { fprintf(stderr,"Wrong endian conversion"); exit(1); } while(0); } while(0);
   }
   if(verify_trace(&tf->t))
    do { fprintf(stderr,"Bad trace!\n"); exit(1); } while(0);
   tf->t.time -= genesis;
   if(tf->t.pdu_len) {
    e = lseek(tf->fd,tf->t.pdu_len,1);
    if(e==-1) do { perror("Skipping pdu"); exit(1); } while(0);
   }
  }
 } while(not_real_event(&tf->t));
}

variable_types:
genesis
unsigned long long

variable_types: e int


repo: useche/btstats

decompiled_code:
__int64 __fastcall trace_destroy(_QWORD *a1)
{
g_slist_foreach(*a1, free_data, 0LL);
g_slist_free(*a1);
return g_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
g_slist_foreach(*a1, free_data, 0LL);
g_slist_free(*a1);
return g_free(a1);
}

original_code:
void trace_destroy(struct trace *dt)
{
 g_slist_foreach(dt->files,free_data,((void *)0));
 g_slist_free(dt->files);
 g_free(dt);
}

variable_types: struct trace { struct _GSList { void *data; struct _GSList *next; } *files; unsigned long long genesis; } *

return_type: void

user_defined_types: struct trace { struct _GSList *files; unsigned long long genesis; }


decompiled_code:
__int64 __fastcall trace_read_next(__int64 *a1, __m128i *a2)
{
__int64 v4; // rdi
__m128i *v5; // rdi
__int64 result; // rax
__int64 v7; // rsi
void *buf; // [rsp+8h] [rbp-20h] BYREF

v4 = *a1;
buf = 0LL;
g_slist_foreach(v4, min_time, &buf);
v5 = (__m128i *)buf;
result = 0LL;
if ( buf )
{
v7 = a1[1];
*a2 = _mm_loadu_si128((const __m128i *)buf);
a2[1] = _mm_loadu_si128(v5 + 1);
a2[2] = _mm_loadu_si128(v5 + 2);
read_next(v5, v7);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1, __m128i *a2)
{
__int64 v4; // rdi
__m128i *v5; // rdi
__int64 result; // rax
__int64 v7; // rsi
void *buf; // [rsp+8h] [rbp-20h] BYREF

v4 = *a1;
buf = 0LL;
g_slist_foreach(v4, min_time, &buf);
v5 = (__m128i *)buf;
result = 0LL;
if ( buf )
{
v7 = a1[1];
*a2 = _mm_loadu_si128((const __m128i *)buf);
a2[1] = _mm_loadu_si128(v5 + 1);
a2[2] = _mm_loadu_si128(v5 + 2);
func8(v5, v7);
result = 1LL;
}
return result;
}

original_code:
gboolean trace_read_next(const struct trace *dt, struct blk_io_trace *t)
{
 struct trace_file *min = ((void *)0);
 g_slist_foreach(dt->files,min_time,&min);
 if(!min)
  return (0);
 else {
  *t = min->t;
  read_next(min, dt->genesis);
  return (!(0));
 }
}

canonical_original_code:
int trace_read_next(struct trace *dt, struct blk_io_trace *t)
{
 struct trace_file *min = ((void *)0);
 g_slist_foreach(dt->files,min_time,&min);
 if(!min)
  return (0);
 else {
  *t = min->t;
  read_next(min, dt->genesis);
  return (!(0));
 }
}

variable_types: struct blk_io_trace { unsigned int magic; unsigned int sequence; unsigned long long time; unsigned long long sector; unsigned int bytes; unsigned int action; unsigned int pid; unsigned int device; unsigned int cpu; unsigned short error; unsigned short pdu_len; } *

variable_types: struct trace_file { struct blk_io_trace { unsigned int magic; unsigned int sequence; unsigned long long time; unsigned long long sector; unsigned int bytes; unsigned int action; unsigned int pid; unsigned int device; unsigned int cpu; unsigned short error; unsigned short pdu_len; } t; int fd; int eof; } *

return_type: int

user_defined_types: struct trace_file { struct blk_io_trace t; int fd; int eof; }

user_defined_types: struct _GSList { void *data; struct _GSList *next; }


P

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

result = *(unsigned int *)(a2 + 40);
if ( !(_DWORD)result )
{
result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a2 + 40) = 1;
*(_QWORD *)(a2 + 32) = result;
}
return result;
}

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

result = *(unsigned int *)(a2 + 40);
if ( !(_DWORD)result )
{
result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a2 + 40) = 1;
*(_QWORD *)(a2 + 32) = result;
}
return result;
}

original_code:
static void P(struct blk_io_trace *t, void *data)
{
 struct pluging_data *plug = (struct pluging_data *)data;
 if(!plug->plugged) {
  plug->plug_time = t->time;
  plug->plugged = (!(0));
 }
}

variable_types:
data
void *

variable_types: struct pluging_data { unsigned long long min; unsigned long long max; unsigned long long total; unsigned long long nplugs; unsigned long long plug_time; int plugged; } *

user_defined_types: struct blk_io_trace { unsigned int magic; unsigned int sequence; unsigned long long time; unsigned long long sector; unsigned int bytes; unsigned int action; unsigned int pid; unsigned int device; unsigned int cpu; unsigned short error; unsigned short pdu_len; }


U

decompiled_code:
unsigned __int64 __fastcall U(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdx
bool v4; // cf

result = *((unsigned int *)a2 + 10);
if ( (_DWORD)result )
{
result = *(_QWORD *)(a1 + 8) - a2[4];
*((_DWORD *)a2 + 10) = 0;
a2[2] += result;
v3 = result;
++a2[3];
if ( *a2 <= result )
v3 = *a2;
v4 = a2[1] < result;
a2[4] = 0LL;
if ( !v4 )
result = a2[1];
*a2 = v3;
a2[1] = result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 result; // rax
unsigned __int64 v3; // rdx
bool v4; // cf

result = *((unsigned int *)a2 + 10);
if ( (_DWORD)result )
{
result = *(_QWORD *)(a1 + 8) - a2[4];
*((_DWORD *)a2 + 10) = 0;
a2[2] += result;
v3 = result;
++a2[3];
if ( *a2 <= result )
v3 = *a2;
v4 = a2[1] < result;
a2[4] = 0LL;
if ( !v4 )
result = a2[1];
*a2 = v3;
a2[1] = result;
}
return result;
}

original_code:
static void U(struct blk_io_trace *t, void *data)
{
 struct pluging_data *plug = (struct pluging_data *)data;
 if(plug->plugged) {
  __u64 time = t->time - plug->plug_time;
  plug->nplugs++;
  plug->total += time;
  plug->min = (((plug->min) < (time)) ? (plug->min) : (time));
  plug->max = (((plug->max) > (time)) ? (plug->max) : (time));
  plug->plugged = (0);
  plug->plug_time = 0;
 }
}

canonical_original_code:
static void U(struct blk_io_trace *t, void *data)
{
 struct pluging_data *plug = (struct pluging_data *)data;
 if(plug->plugged) {
  unsigned long long time = t->time - plug->plug_time;
  plug->nplugs++;
  plug->total += time;
  plug->min = (((plug->min) < (time)) ? (plug->min) : (time));
  plug->max = (((plug->max) > (time)) ? (plug->max) : (time));
  plug->plugged = (0);
  plug->plug_time = 0;
 }
}

variable_types:
time
unsigned long long

user_defined_types: struct pluging_data { unsigned long long min; unsigned long long max; unsigned long long total; unsigned long long nplugs; unsigned long long plug_time; int plugged; }


original_code:
void pluging_print_results(const void *data)
{
 struct pluging_data *plug = (struct pluging_data *)data;
 if(plug->nplugs)
  printf("Plug Time Min: %f Avg: %f Max: %f (sec)\n",
         (((double)(plug->min))/1000000000),
         (((double)(plug->total))/1000000000)/plug->nplugs,
         (((double)(plug->max))/1000000000));
 else
  printf("No plugging in this range\n");
}

canonical_original_code:
void pluging_print_results(void *data)
{
 struct pluging_data *plug = (struct pluging_data *)data;
 if(plug->nplugs)
  printf("Plug Time Min: %f Avg: %f Max: %f (sec)\n",
         (((double)(plug->min))/1000000000),
         (((double)(plug->total))/1000000000)/plug->nplugs,
         (((double)(plug->max))/1000000000));
 else
  printf("No plugging in this range\n");
}


C

decompiled_code:
__int64 __fastcall C(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
bool v4; // cf
__int64 v5; // rdx

result = *(_DWORD *)(a1 + 24) >> 9;
if ( (_DWORD)result )
{
result = (unsigned int)result;
v3 = (unsigned int)result;
if ( *a2 <= (unsigned __int64)(unsigned int)result )
v3 = *a2;
v4 = a2[1] < (unsigned __int64)(unsigned int)result;
*a2 = v3;
v5 = (unsigned int)result;
if ( !v4 )
v5 = a2[1];
a2[2] += (unsigned int)result;
++a2[3];
a2[1] = v5;
if ( (*(_BYTE *)(a1 + 30) & 2) == 0 )
++a2[4];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
bool v4; // cf
__int64 v5; // rdx

result = *(_DWORD *)(a1 + 24) >> 9;
if ( (_DWORD)result )
{
result = (unsigned int)result;
v3 = (unsigned int)result;
if ( *a2 <= (unsigned __int64)(unsigned int)result )
v3 = *a2;
v4 = a2[1] < (unsigned __int64)(unsigned int)result;
*a2 = v3;
v5 = (unsigned int)result;
if ( !v4 )
v5 = a2[1];
a2[2] += (unsigned int)result;
++a2[3];
a2[1] = v5;
if ( (*(_BYTE *)(a1 + 30) & 2) == 0 )
++a2[4];
}
return result;
}

original_code:
static void C(struct blk_io_trace *t, void *data)
{
 struct reqsize_data *rsd = (struct reqsize_data *)data;
 __u64 blks = ((t)->bytes >> 9);
 if(blks) {
  rsd->min = (((rsd->min) < (blks)) ? (rsd->min) : (blks));
  rsd->max = (((rsd->max) > (blks)) ? (rsd->max) : (blks));
  rsd->total_size += blks;
  rsd->reqs++;
  if(!((t->action & ((BLK_TC_WRITE) << (16))) != 0)) {
   rsd->reads++;
  }
 }
}

canonical_original_code:
static void C(struct blk_io_trace *t, void *data)
{
 struct reqsize_data *rsd = (struct reqsize_data *)data;
 unsigned long long blks = ((t)->bytes >> 9);
 if(blks) {
  rsd->min = (((rsd->min) < (blks)) ? (rsd->min) : (blks));
  rsd->max = (((rsd->max) > (blks)) ? (rsd->max) : (blks));
  rsd->total_size += blks;
  rsd->reqs++;
  if(!((t->action & ((BLK_TC_WRITE) << (16))) != 0)) {
   rsd->reads++;
  }
 }
}

variable_types: struct reqsize_data { unsigned long long min; unsigned long long max; unsigned long long total_size; unsigned long long reqs; unsigned long long reads; } *

variable_types:
blks
unsigned long long


decompiled_code:
void __fastcall reqsize_print_results(_QWORD *a1)
{
__int64 v1; // rdx
double v2; // xmm2_8
__int64 v3; // rax
__int64 v4; // rcx
double v5; // xmm1_8
double v6; // xmm1_8
double v7; // xmm0_8
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rsi

v1 = a1[3];
if ( v1 )
{
if ( v1 < 0 )
{
v8 = a1[3] & 1LL | ((unsigned __int64)v1 >> 1);
v2 = (double)(int)v8 + (double)(int)v8;
}
else
{
v2 = (double)(int)v1;
}
v3 = a1[2];
v4 = a1[4];
if ( v3 < 0 )
{
v10 = a1[2] & 1LL | (a1[2] >> 1);
v5 = (double)(int)v10 + (double)(int)v10;
}
else
{
v5 = (double)(int)v3;
}
v6 = v5 / v2;
if ( v4 < 0 )
{
v9 = a1[4] & 1LL | ((unsigned __int64)v4 >> 1);
v7 = (double)(int)v9 + (double)(int)v9;
}
else
{
v7 = (double)(int)v4;
}
_printf_chk(
1LL,
"Reqs. #: %lld Reads: %lld (%.1f%%) Size:(min: %lld avg: %f max: %lld (blks))\n",
v1,
v4,
v7 * 100.0 / v2,
*a1,
v6,
a1[1]);
}
}

original_code:
void reqsize_print_results(const void *data)
{
 struct reqsize_data *rsd = (struct reqsize_data *)data;
 if(rsd->reqs)
  printf("Reqs. #: %lld Reads: %lld (%.1f%%) Size:(min: %lld avg: %f max: %lld (blks))\n",
         rsd->reqs,
         rsd->reads,
         100*((double)rsd->reads)/rsd->reqs,
         rsd->min,
         ((double)rsd->total_size)/rsd->reqs,
         rsd->max);
}

canonical_original_code:
void reqsize_print_results(void *data)
{
 struct reqsize_data *rsd = (struct reqsize_data *)data;
 if(rsd->reqs)
  printf("Reqs. #: %lld Reads: %lld (%.1f%%) Size:(min: %lld avg: %f max: %lld (blks))\n",
         rsd->reqs,
         rsd->reads,
         100*((double)rsd->reads)/rsd->reqs,
         rsd->min,
         ((double)rsd->total_size)/rsd->reqs,
         rsd->max);
}

user_defined_types: struct reqsize_data { unsigned long long min; unsigned long long max; unsigned long long total_size; unsigned long long reqs; unsigned long long reads; }


F

original_code:
static void F(struct blk_io_trace *t, void *data)
{
 struct merge_data *m = (struct merge_data *)data;
 if(m->ins)
  m->fs++;
}

variable_types: struct merge_data { unsigned long long ms; unsigned long long fs; unsigned long long ins; } *


I

original_code:
static void I(struct blk_io_trace *t, void *data)
{
 struct merge_data *m = (struct merge_data *)data;
 m->ins++;
}

user_defined_types: struct merge_data { unsigned long long ms; unsigned long long fs; unsigned long long ins; }


decompiled_code:
int __fastcall merge_print_results(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // rax
double v4; // xmm1_8
double v5; // xmm0_8
double v6; // xmm2_8
__int64 v8; // rsi

v1 = a1[2];
if ( v1 )
{
v2 = a1[1];
v3 = *a1;
if ( v1 < 0 )
{
v8 = a1[2] & 1 | ((unsigned __int64)v1 >> 1);
v4 = (double)(int)v8 + (double)(int)v8;
if ( v2 >= 0 )
{
LABEL_4:
v5 = (double)(int)v2;
if ( v3 >= 0 )
{
LABEL_5:
v6 = (double)(int)v3;
return _printf_chk(1LL, "#I: %llu #F+#M: %llu ratio: %f\n", v1, v3 + v2, (v5 + v6 + v4) / v4);
}
LABEL_10:
v6 = (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1)) + (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1));
return _printf_chk(1LL, "#I: %llu #F+#M: %llu ratio: %f\n", v1, v3 + v2, (v5 + v6 + v4) / v4);
}
}
else
{
v4 = (double)(int)v1;
if ( v2 >= 0 )
goto LABEL_4;
}
v5 = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
if ( v3 >= 0 )
goto LABEL_5;
goto LABEL_10;
}
return puts("#I: 0");
}

canonical_decompiled_code:
int __fastcall func4(__int64 *a1)
{
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // rax
double v4; // xmm1_8
double v5; // xmm0_8
double v6; // xmm2_8
__int64 v8; // rsi

v1 = a1[2];
if ( v1 )
{
v2 = a1[1];
v3 = *a1;
if ( v1 < 0 )
{
v8 = a1[2] & 1 | ((unsigned __int64)v1 >> 1);
v4 = (double)(int)v8 + (double)(int)v8;
if ( v2 >= 0 )
{
LABEL_4:
v5 = (double)(int)v2;
if ( v3 >= 0 )
{
LABEL_5:
v6 = (double)(int)v3;
return _printf_chk(1LL, "#I: %llu #F+#M: %llu ratio: %f\n", v1, v3 + v2, (v5 + v6 + v4) / v4);
}
LABEL_10:
v6 = (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1)) + (double)(int)(v3 & 1 | ((unsigned __int64)v3 >> 1));
return _printf_chk(1LL, "#I: %llu #F+#M: %llu ratio: %f\n", v1, v3 + v2, (v5 + v6 + v4) / v4);
}
}
else
{
v4 = (double)(int)v1;
if ( v2 >= 0 )
goto LABEL_4;
}
v5 = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
if ( v3 >= 0 )
goto LABEL_5;
goto LABEL_10;
}
return puts("#I: 0");
}

original_code:
void merge_print_results(const void *data)
{
 struct merge_data *m = (struct merge_data *)data;
 if(m->ins) {
  printf("#I: %llu #F+#M: %llu ratio: %f\n",
         m->ins,
         m->fs + m->ms,
         ((double) m->fs + m->ms + m->ins)/m->ins);
 } else
  printf("#I: 0\n");
}

canonical_original_code:
void merge_print_results(void *data)
{
 struct merge_data *m = (struct merge_data *)data;
 if(m->ins) {
  printf("#I: %llu #F+#M: %llu ratio: %f\n",
         m->ins,
         m->fs + m->ms,
         ((double) m->fs + m->ms + m->ins)/m->ins);
 } else
  printf("#I: 0\n");
}


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

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

original_code:
inline static int comp_int(gconstpointer a,gconstpointer b)
{
 long x = (long)a;
 long y = (long)b;
 return x-y;
}

canonical_original_code:
inline static int comp_int(void *a, void *b)
{
 long x = (long)a;
 long y = (long)b;
 return x-y;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: x long

variable_types: y long


decompiled_code:
__int64 destroy_plugs_ops()
{
void (__fastcall **v0)(char *); // rbp
char *v1; // rbx
__int64 v2; // rdi
__int64 result; // rax
void (__fastcall *v4)(char *); // rax

v0 = (void (__fastcall **)(char *))&unk_3B8;
v1 = (char *)&ps_ops;
while ( 1 )
{
v2 = *(_QWORD *)v1;
v1 += 24;
result = g_tree_destroy(v2);
if ( v1 == (char *)&ps_ops + 192 )
break;
v4 = *v0;
v0 += 4;
if ( v4 )
v4(v1);
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
void (__fastcall **v0)(char *); // rbp
char *v1; // rbx
__int64 v2; // rdi
__int64 result; // rax
void (__fastcall *v4)(char *); // rax

v0 = (void (__fastcall **)(char *))&unk_3B8;
v1 = (char *)&ps_ops;
while ( 1 )
{
v2 = *(_QWORD *)v1;
v1 += 24;
result = g_tree_destroy(v2);
if ( v1 == (char *)&ps_ops + 192 )
break;
v4 = *v0;
v0 += 4;
if ( v4 )
v4(v1);
}
return result;
}

original_code:
void destroy_plugs_ops()
{
 int i;
 for(i = 0; i < N_PLUGINS; ++i) {
  if(plug_init_dest[i].ops_destroy)
   plug_init_dest[i].ops_destroy(&ps_ops[i]);
  g_tree_destroy(ps_ops[i].event_tree);
 }
}

variable_types: i int


decompiled_code:
void __noreturn usage_exit()
{
fwrite(
"Usage: btstats [-h] [-f <file>] [-r <reader>] [-t] [-d <file>] [-i <file>] [<trace> .. <trace>]\n"
"\n"
"Options:\n"
"\t-h: Show this help message and exit\n"
"\t-f: File which list the traces and phases to analyze.\n"
"\t-t: Print the total stats for all traces.\n"
"\t-d: File sufix where all the details of D2C will be stored.\n"
"\t\t<timestamp> <Sector #> <Req. Size (blks)> <D2C time (sec)>\n"
"\t-i: File sufix where all the changes in OIO for I2C are logged.\n"
"\t-s: File sufix where the histogram of OIO for I2C is printed.\n"
"\t-r: Trace reader to be used\n"
"\t\t0: default\n"
"\t\t1: reader for driver ata_piix\n"
"\t<trace>: String of device/range to analyze. Exclusive with -f.\n",
1uLL,
0x275uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite(
"Usage: btstats [-h] [-f <file>] [-r <reader>] [-t] [-d <file>] [-i <file>] [<trace> .. <trace>]\n"
"\n"
"Options:\n"
"\t-h: Show this help message and exit\n"
"\t-f: File which list the traces and phases to analyze.\n"
"\t-t: Print the total stats for all traces.\n"
"\t-d: File sufix where all the details of D2C will be stored.\n"
"\t\t<timestamp> <Sector #> <Req. Size (blks)> <D2C time (sec)>\n"
"\t-i: File sufix where all the changes in OIO for I2C are logged.\n"
"\t-s: File sufix where the histogram of OIO for I2C is printed.\n"
"\t-r: Trace reader to be used\n"
"\t\t0: default\n"
"\t\t1: reader for driver ata_piix\n"
"\t<trace>: String of device/range to analyze. Exclusive with -f.\n",
1uLL,
0x275uLL,
stderr);
exit(1);
}

original_code:
void usage_exit()
{
 do { fprintf(stderr,"Usage: btstats [-h] [-f <file>] [-r <reader>] [-t] [-d <file>] [-i <file>] [<trace> .. <trace>]\n\n" "Options:\n" "\t-h: Show this help message and exit\n" "\t-f: File which list the traces and phases to analyze.\n" "\t-t: Print the total stats for all traces.\n" "\t-d: File sufix where all the details of D2C will be stored.\n" "\t\t<timestamp> <Sector #> <Req. Size (blks)> <D2C time (sec)>\n" "\t-i: File sufix where all the changes in OIO for I2C are logged.\n" "\t-s: File sufix where the histogram of OIO for I2C is printed.\n" "\t-r: Trace reader to be used\n" "\t\t0: default\n" "\t\t1: reader for driver ata_piix\n" "\t<trace>: String of device/range to analyze. Exclusive with -f.\n"); exit(1); } while(0);
}


decompiled_code:
__int64 __fastcall trace_ata_piix_read_next(__int64 a1, __m128i *a2)
{
__int64 result; // rax
int v3; // eax
__m128i v4; // xmm1
__m128i v5; // xmm2
int v6; // eax
bool v7; // zf
__m128i v8; // xmm4
__m128i v9; // xmm5

if ( !send_p_d )
{
while ( 1 )
{
result = trace_read_next(a1, a2);
if ( !(_DWORD)result )
return result;
v3 = a2[1].m128i_u16[6];
if ( v3 != 7 )
break;
if ( !((unsigned __int32)a2[1].m128i_i32[2] >> 9) )
return 1LL;
v7 = out_reqs == 1;
if ( out_reqs > 1 )
_assert_fail("out_reqs<2", "trace_reader/trace_ata_piix.c", 0x36u, "trace_ata_piix_read_next");
++out_reqs;
if ( !v7 )
return 1LL;
v8 = _mm_loadu_si128(a2 + 1);
v9 = _mm_loadu_si128(a2 + 2);
at = (__int128)_mm_loadu_si128(a2);
xmmword_190 = (__int128)v8;
xmmword_1A0 = (__int128)v9;
}
if ( v3 == 8 )
{
v6 = out_reqs;
if ( out_reqs == 2 )
{
send_p_d = 1;
*((_QWORD *)&at + 1) = a2->m128i_i64[1] + 1;
}
}
else
{
if ( v3 != 6 )
return 1LL;
v6 = out_reqs;
}
out_reqs = v6 - (v6 > 0);
return 1LL;
}
result = 1LL;
v4 = _mm_load_si128((const __m128i *)&xmmword_190);
send_p_d = 0;
v5 = _mm_load_si128((const __m128i *)&xmmword_1A0);
*a2 = _mm_load_si128((const __m128i *)&at);
a2[1] = v4;
a2[2] = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __m128i *a2)
{
__int64 result; // rax
int v3; // eax
__m128i v4; // xmm1
__m128i v5; // xmm2
int v6; // eax
bool v7; // zf
__m128i v8; // xmm4
__m128i v9; // xmm5

if ( !send_p_d )
{
while ( 1 )
{
result = trace_read_next(a1, a2);
if ( !(_DWORD)result )
return result;
v3 = a2[1].m128i_u16[6];
if ( v3 != 7 )
break;
if ( !((unsigned __int32)a2[1].m128i_i32[2] >> 9) )
return 1LL;
v7 = out_reqs == 1;
if ( out_reqs > 1 )
_assert_fail("out_reqs<2", "trace_reader/trace_ata_piix.c", 0x36u, "trace_ata_piix_read_next");
++out_reqs;
if ( !v7 )
return 1LL;
v8 = _mm_loadu_si128(a2 + 1);
v9 = _mm_loadu_si128(a2 + 2);
at = (__int128)_mm_loadu_si128(a2);
xmmword_190 = (__int128)v8;
xmmword_1A0 = (__int128)v9;
}
if ( v3 == 8 )
{
v6 = out_reqs;
if ( out_reqs == 2 )
{
send_p_d = 1;
*((_QWORD *)&at + 1) = a2->m128i_i64[1] + 1;
}
}
else
{
if ( v3 != 6 )
return 1LL;
v6 = out_reqs;
}
out_reqs = v6 - (v6 > 0);
return 1LL;
}
result = 1LL;
v4 = _mm_load_si128((const __m128i *)&xmmword_190);
send_p_d = 0;
v5 = _mm_load_si128((const __m128i *)&xmmword_1A0);
*a2 = _mm_load_si128((const __m128i *)&at);
a2[1] = v4;
a2[2] = v5;
return result;
}

original_code:
gboolean trace_ata_piix_read_next(const struct trace *dt, struct blk_io_trace *t) {
 gboolean r;
 if(send_p_d) {
  *t = at;
  send_p_d = (0);
  return (!(0));
 } else {
reread:
  r = trace_read_next(dt,t);
  blks = ((t)->bytes >> 9);
  if(!r) return (0);
  switch(t->action & 0xffff) {
   case __BLK_TA_COMPLETE:
    if(out_reqs==2) {
     send_p_d = (!(0));
     at.time = t->time+1;
    }
    out_reqs -= out_reqs>0?1:0;
    break;
   case __BLK_TA_ISSUE:
    if(blks==0)
     break;
    ((void) sizeof ((out_reqs<2) ? 1 : 0), __extension__ ({ if (out_reqs<2) ; else __assert_fail ("out_reqs<2", "trace_reader/trace_ata_piix.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    if(out_reqs++==1) {
     at = *t;
     goto reread;
    }
    break;
   case __BLK_TA_REQUEUE:
    out_reqs -= out_reqs>0?1:0;
    break;
  }
  return (!(0));
 }
}

canonical_original_code:
int trace_ata_piix_read_next(struct trace *dt, struct blk_io_trace *t) {
 int r;
 if(send_p_d) {
  *t = at;
  send_p_d = (0);
  return (!(0));
 } else {
reread:
  r = trace_read_next(dt,t);
  blks = ((t)->bytes >> 9);
  if(!r) return (0);
  switch(t->action & 0xffff) {
   case __BLK_TA_COMPLETE:
    if(out_reqs==2) {
     send_p_d = (!(0));
     at.time = t->time+1;
    }
    out_reqs -= out_reqs>0?1:0;
    break;
   case __BLK_TA_ISSUE:
    if(blks==0)
     break;
    ((void) sizeof ((out_reqs<2) ? 1 : 0), __extension__ ({ if (out_reqs<2) ; else __assert_fail ("out_reqs<2", "trace_reader/trace_ata_piix.c", 54, __extension__ __PRETTY_FUNCTION__); }));
    if(out_reqs++==1) {
     at = *t;
     goto reread;
    }
    break;
   case __BLK_TA_REQUEUE:
    out_reqs -= out_reqs>0?1:0;
    break;
  }
  return (!(0));
 }
}

variable_types: r int


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

result = 0LL;
if ( *a1 != *a2 )
result = *a2 < *a1 ? 1 : -1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = *a2 < *a1 ? 1 : -1;
return result;
}

original_code:
inline static int comp_int64(gconstpointer a,gconstpointer b)
{
 __u64 x = *((__u64 *)a);
 __u64 y = *((__u64 *)b);
 if(x==y)
  return 0;
 else
  return x>y?1:-1;
}

canonical_original_code:
inline static int comp_int64(void *a, void *b)
{
 unsigned long long x = *((__u64 *)a);
 unsigned long long y = *((__u64 *)b);
 if(x==y)
  return 0;
 else
  return x>y?1:-1;
}

variable_types:
x
unsigned long long

variable_types:
y
unsigned long long


repo: usmanm/cachingfractalbtree

decompiled_code:
int init_benchmark()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
remove("btree.db");
return remove("table.db");
}

canonical_decompiled_code:
int func6()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
remove("btree.db");
return remove("table.db");
}

original_code:
void init_benchmark() {
  unsigned int s = (unsigned int) time(((void *)0));
  srand(s);
  remove("btree.db");
  remove("table.db");
}

variable_types:
s
unsigned int


decompiled_code:
int __fastcall load_tables(unsigned int a1)
{
int i; // ebp
int *v2; // r15
time_t v3; // rax
time_t v5; // [rsp+8h] [rbp-70h]
int v6; // [rsp+10h] [rbp-68h] BYREF
char v7[100]; // [rsp+14h] [rbp-64h] BYREF

v5 = time(0LL);
printf("Loading table [%u]...\n", a1);
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v2 = &v6;
qmemcpy(v7, "Benchmarking Ninjas", 19);
v6 = i;
v7[19] = i;
do
{
++v2;
v2[5] = rand() % a1;
}
while ( v2 != (int *)&v7[16] );
insert();
}
}
v3 = time(0LL);
return printf("Table loaded in %lu s.\n", v3 - v5);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
int i; // ebp
int *v2; // r15
time_t v3; // rax
time_t v5; // [rsp+8h] [rbp-70h]
int v6; // [rsp+10h] [rbp-68h] BYREF
char v7[100]; // [rsp+14h] [rbp-64h] BYREF

v5 = time(0LL);
printf("Loading table [%u]...\n", a1);
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v2 = &v6;
qmemcpy(v7, "Benchmarking Ninjas", 19);
v6 = i;
v7[19] = i;
do
{
++v2;
v2[5] = rand() % a1;
}
while ( v2 != (int *)&v7[16] );
insert();
}
}
v3 = time(0LL);
return printf("Table loaded in %lu s.\n", v3 - v5);
}

original_code:
void load_tables(uint32_t numofitems) {
  uint32_t i, j;
  time_t stime = time(((void *)0));
  printf("Loading table [%u]...\n", numofitems);
  for (i = 0; i < numofitems; i++) {
    tuple_t t;
    t.id = i;
    strncpy((char *) &t.name, "Benchmarking Ninjas", 19);
    t.name[19] = (char) i;
    for (j = 0; j < 5; j++) {
      t.items[j] = (uint32_t) (rand() % numofitems);
    }
    insert(i, &t);
  }
  printf("Table loaded in %lu s.\n", (unsigned long) (time(((void *)0)) - stime));
}

canonical_original_code:
void load_tables(unsigned int numofitems) {
  unsigned int i; unsigned int j;
  long stime = time(((void *)0));
  printf("Loading table [%u]...\n", numofitems);
  for (i = 0; i < numofitems; i++) {
    struct _tuple_t t;
    t.id = i;
    strncpy((char *) &t.name, "Benchmarking Ninjas", 19);
    t.name[19] = (char) i;
    for (j = 0; j < 5; j++) {
      t.items[j] = (unsigned int) (rand() % numofitems);
    }
    insert(i, &t);
  }
  printf("Table loaded in %lu s.\n", (unsigned long) (time(((void *)0)) - stime));
}

variable_types:
numofitems
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types: stime long

variable_types: struct _tuple_t { unsigned int id; char name[20]; unsigned int items[5]; }


decompiled_code:
int __fastcall test_lookups(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
unsigned int v3; // er15
time_t v4; // rax
time_t v6; // [rsp+8h] [rbp-90h]
_OWORD v7[2]; // [rsp+10h] [rbp-88h] BYREF
int v8; // [rsp+30h] [rbp-68h]
__int128 v9; // [rsp+34h] [rbp-64h]
__int16 v10; // [rsp+44h] [rbp-54h]
char v11; // [rsp+46h] [rbp-52h]
char v12; // [rsp+47h] [rbp-51h]

v2 = a1;
v6 = time(0LL);
printf("Testing lookups [%u]...\n", a1);
if ( a1 )
{
do
{
strcpy((char *)v7, "Benchmarking Ninjas");
v3 = rand() % a2;
search();
if ( v8 != v3 )
__assert_fail("t.id == (uint32_t) i", "benchmark.c", 0x30u, "test_lookups");
if ( v7[0] != v9 || v10 != LOWORD(v7[1]) || v11 != BYTE2(v7[1]) )
__assert_fail("memcmp(&t.name, &str, 19) == 0", "benchmark.c", 0x31u, "test_lookups");
if ( v12 != (_BYTE)v3 )
__assert_fail("t.name[19] == (char) i", "benchmark.c", 0x32u, "test_lookups");
--v2;
}
while ( v2 );
}
v4 = time(0LL);
return printf("Lookups tested in %lu s.\n", v4 - v6);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2)
{
unsigned int v2; // ebx
unsigned int v3; // er15
time_t v4; // rax
time_t v6; // [rsp+8h] [rbp-90h]
_OWORD v7[2]; // [rsp+10h] [rbp-88h] BYREF
int v8; // [rsp+30h] [rbp-68h]
__int128 v9; // [rsp+34h] [rbp-64h]
__int16 v10; // [rsp+44h] [rbp-54h]
char v11; // [rsp+46h] [rbp-52h]
char v12; // [rsp+47h] [rbp-51h]

v2 = a1;
v6 = time(0LL);
printf("Testing lookups [%u]...\n", a1);
if ( a1 )
{
do
{
strcpy((char *)v7, "Benchmarking Ninjas");
v3 = rand() % a2;
search();
if ( v8 != v3 )
__assert_fail("t.id == (uint32_t) i", "benchmark.c", 0x30u, "test_lookups");
if ( v7[0] != v9 || v10 != LOWORD(v7[1]) || v11 != BYTE2(v7[1]) )
__assert_fail("memcmp(&t.name, &str, 19) == 0", "benchmark.c", 0x31u, "test_lookups");
if ( v12 != (_BYTE)v3 )
__assert_fail("t.name[19] == (char) i", "benchmark.c", 0x32u, "test_lookups");
--v2;
}
while ( v2 );
}
v4 = time(0LL);
return printf("Lookups tested in %lu s.\n", v4 - v6);
}

original_code:
void test_lookups(uint32_t numoflookups, uint32_t numofitems) {
  time_t stime = time(((void *)0));
  printf("Testing lookups [%u]...\n", numoflookups);
  while (numoflookups != 0) {
    uint32_t i;
    tuple_t t;
    char str[] = "Benchmarking Ninjas";
    i = rand() % numofitems;
    search(i, &t);
    ((t.id == (uint32_t) i) ? (void) (0) : __assert_fail ("t.id == (uint32_t) i", "benchmark.c", 48, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(&t.name, &str, 19) == 0) ? (void) (0) : __assert_fail ("memcmp(&t.name, &str, 19) == 0", "benchmark.c", 49, __extension__ __PRETTY_FUNCTION__));
    ((t.name[19] == (char) i) ? (void) (0) : __assert_fail ("t.name[19] == (char) i", "benchmark.c", 50, __extension__ __PRETTY_FUNCTION__));
    numoflookups--;
  }
  printf("Lookups tested in %lu s.\n", (unsigned long) (time(((void *)0)) - stime));
}

canonical_original_code:
void test_lookups(unsigned int numoflookups, unsigned int numofitems) {
  long stime = time(((void *)0));
  printf("Testing lookups [%u]...\n", numoflookups);
  while (numoflookups != 0) {
    unsigned int i;
    struct _tuple_t t;
    char str[] = "Benchmarking Ninjas";
    i = rand() % numofitems;
    search(i, &t);
    ((t.id == (unsigned int) i) ? (void) (0) : __assert_fail ("t.id == (uint32_t) i", "benchmark.c", 48, __extension__ __PRETTY_FUNCTION__));
    ((memcmp(&t.name, &str, 19) == 0) ? (void) (0) : __assert_fail ("memcmp(&t.name, &str, 19) == 0", "benchmark.c", 49, __extension__ __PRETTY_FUNCTION__));
    ((t.name[19] == (char) i) ? (void) (0) : __assert_fail ("t.name[19] == (char) i", "benchmark.c", 50, __extension__ __PRETTY_FUNCTION__));
    numoflookups--;
  }
  printf("Lookups tested in %lu s.\n", (unsigned long) (time(((void *)0)) - stime));
}

variable_types:
numoflookups
unsigned int

variable_types:
str
char []

user_defined_types: struct _tuple_t { unsigned int id; char name[20]; unsigned int items[5]; }


computeCommonInitialStr

original_code:
static void computeCommonInitialStr (const char *pcString, int iStringLen,
                                     int iDeltaTwo[iStringLen])
{
    int iIteratorOne;
    int iIteratorTwo;
    iIteratorTwo = 0;
    for (iIteratorOne = 0; iIteratorOne < iStringLen; iIteratorOne++)
    {
        while (iIteratorTwo > 0 &&
               pcString[iIteratorTwo] != pcString[iIteratorOne])
        {
            iIteratorTwo = iDeltaTwo[iIteratorTwo - 1];
        }
        if (pcString[iIteratorOne] == pcString[iIteratorTwo])
        {
            iIteratorTwo++;
        }
        iDeltaTwo[iIteratorOne] = iIteratorTwo;
    }
}

canonical_original_code:
static void computeCommonInitialStr(char *pcString, int iStringLen, int iDeltaTwo[-1])
{
    int iIteratorOne;
    int iIteratorTwo;
    iIteratorTwo = 0;
    for (iIteratorOne = 0; iIteratorOne < iStringLen; iIteratorOne++)
    {
        while (iIteratorTwo > 0 &&
               pcString[iIteratorTwo] != pcString[iIteratorOne])
        {
            iIteratorTwo = iDeltaTwo[iIteratorTwo - 1];
        }
        if (pcString[iIteratorOne] == pcString[iIteratorTwo])
        {
            iIteratorTwo++;
        }
        iDeltaTwo[iIteratorOne] = iIteratorTwo;
    }
}

variable_types:
pcString
char *

variable_types: iStringLen int

variable_types:
iDeltaTwo
int [-1]

variable_types: iIteratorOne int

variable_types: iIteratorTwo int


scanBuffer

original_code:
static int scanBuffer (unsigned long long ullVirusTableIndex,
                       char *pcBufferToBeScanned, long lBufferLength)
{
    unsigned long ulLengthDifference;
    unsigned long ulIterator;
    long ulIndexJ;
    long ulIndexM;
    long ulIndexK;
    int iASCIIValue;
    if (pVirusSignatureTable[ullVirusTableIndex]->iVirusLength >
        lBufferLength)
    {
        return 1;
    }
    ulLengthDifference =
        lBufferLength -
        pVirusSignatureTable[ullVirusTableIndex]->iVirusLength;
    ulIterator = 0;
    while (ulIterator < ulLengthDifference)
    {
        ulIndexJ = pVirusSignatureTable[ullVirusTableIndex]->iVirusLength;
        while (ulIndexJ > 0 &&
               pVirusSignatureTable[ullVirusTableIndex]->cVirus[ulIndexJ -
                                                                1] ==
               pcBufferToBeScanned[ulIterator + ulIndexJ - 1])
        {
            ulIndexJ--;
        }
        if (ulIndexJ > 0)
        {
            iASCIIValue = 0;
            memcpy (&iASCIIValue,
                    &pcBufferToBeScanned[ulIterator + ulIndexJ - 1], 1);
            ulIndexK =
                pVirusSignatureTable[ullVirusTableIndex]->
                iDeltaOne[iASCIIValue];
            if (ulIndexK < ulIndexJ &&
                (ulIndexM =
                 ulIndexJ - ulIndexK - 1) >
                pVirusSignatureTable[ullVirusTableIndex]->iDeltaTwo[ulIndexJ])
            {
                ulIterator = ulIterator + ulIndexM;
            }
            else
            {
                ulIterator = ulIterator + ulIndexK;
            }
        }
        else
        {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
static int scanBuffer(unsigned long long ullVirusTableIndex, char *pcBufferToBeScanned, long lBufferLength)
{
    unsigned long ulLengthDifference;
    unsigned long ulIterator;
    long ulIndexJ;
    long ulIndexM;
    long ulIndexK;
    int iASCIIValue;
    if (pVirusSignatureTable[ullVirusTableIndex]->iVirusLength >
        lBufferLength)
    {
        return 1;
    }
    ulLengthDifference =
        lBufferLength -
        pVirusSignatureTable[ullVirusTableIndex]->iVirusLength;
    ulIterator = 0;
    while (ulIterator < ulLengthDifference)
    {
        ulIndexJ = pVirusSignatureTable[ullVirusTableIndex]->iVirusLength;
        while (ulIndexJ > 0 &&
               pVirusSignatureTable[ullVirusTableIndex]->cVirus[ulIndexJ -
                                                                1] ==
               pcBufferToBeScanned[ulIterator + ulIndexJ - 1])
        {
            ulIndexJ--;
        }
        if (ulIndexJ > 0)
        {
            iASCIIValue = 0;
            memcpy (&iASCIIValue,
                    &pcBufferToBeScanned[ulIterator + ulIndexJ - 1], 1);
            ulIndexK =
                pVirusSignatureTable[ullVirusTableIndex]->
                iDeltaOne[iASCIIValue];
            if (ulIndexK < ulIndexJ &&
                (ulIndexM =
                 ulIndexJ - ulIndexK - 1) >
                pVirusSignatureTable[ullVirusTableIndex]->iDeltaTwo[ulIndexJ])
            {
                ulIterator = ulIterator + ulIndexM;
            }
            else
            {
                ulIterator = ulIterator + ulIndexK;
            }
        }
        else
        {
            return 0;
        }
    }
    return 1;
}

variable_types:
ullVirusTableIndex
unsigned long long

variable_types:
pcBufferToBeScanned
char *

variable_types: lBufferLength long

variable_types:
ulLengthDifference
unsigned long

variable_types:
ulIterator
unsigned long

variable_types: ulIndexJ long

variable_types: ulIndexM long

variable_types: ulIndexK long

variable_types: iASCIIValue int


constructDeltaTwoTable

original_code:
void constructDeltaTwoTable (VirusSignatureTable_t * pVirusSigTable)
{
    char cReverseVirus[pVirusSigTable->iVirusLength + 1];
    char *pcLeftChar;
    char *pcRightChar;
    char *pcTempStr;
    int iIterator;
    int iIndexOne;
    int iIndextwo;
    int iStrDeltaTwo[pVirusSigTable->iVirusLength];
    int iRevStrDeltaTwo[pVirusSigTable->iVirusLength];
    pcLeftChar = pVirusSigTable->cVirus;
    pcRightChar = pVirusSigTable->cVirus + pVirusSigTable->iVirusLength;
    pcTempStr = cReverseVirus + pVirusSigTable->iVirusLength;
    *pcTempStr = 0;
    while (pcLeftChar < pcRightChar)
    {
        *(--pcTempStr) = *(pcLeftChar++);
    }
    computeCommonInitialStr (pVirusSigTable->cVirus,
                             pVirusSigTable->iVirusLength, iStrDeltaTwo);
    computeCommonInitialStr (cReverseVirus, pVirusSigTable->iVirusLength,
                             iRevStrDeltaTwo);
    for (iIterator = 0; iIterator <= pVirusSigTable->iVirusLength;
         iIterator++)
    {
        pVirusSigTable->iDeltaTwo[iIterator] =
            pVirusSigTable->iVirusLength -
            iStrDeltaTwo[pVirusSigTable->iVirusLength - 1];
    }
    for (iIterator = 0; iIterator < pVirusSigTable->iVirusLength; iIterator++)
    {
        iIndexOne = pVirusSigTable->iVirusLength - iRevStrDeltaTwo[iIterator];
        iIndextwo = iIterator - iRevStrDeltaTwo[iIterator] + 1;
        if (pVirusSigTable->iDeltaTwo[iIndexOne] > iIndextwo)
        {
            pVirusSigTable->iDeltaTwo[iIndexOne] = iIndextwo;
        }
    }
}

canonical_original_code:
void constructDeltaTwoTable(struct VirusSignatureTable *pVirusSigTable)
{
    char cReverseVirus[-1];
    char *pcLeftChar;
    char *pcRightChar;
    char *pcTempStr;
    int iIterator;
    int iIndexOne;
    int iIndextwo;
    int iStrDeltaTwo[-1];
    int iRevStrDeltaTwo[-1];
    pcLeftChar = pVirusSigTable->cVirus;
    pcRightChar = pVirusSigTable->cVirus + pVirusSigTable->iVirusLength;
    pcTempStr = cReverseVirus + pVirusSigTable->iVirusLength;
    *pcTempStr = 0;
    while (pcLeftChar < pcRightChar)
    {
        *(--pcTempStr) = *(pcLeftChar++);
    }
    computeCommonInitialStr (pVirusSigTable->cVirus,
                             pVirusSigTable->iVirusLength, iStrDeltaTwo);
    computeCommonInitialStr (cReverseVirus, pVirusSigTable->iVirusLength,
                             iRevStrDeltaTwo);
    for (iIterator = 0; iIterator <= pVirusSigTable->iVirusLength;
         iIterator++)
    {
        pVirusSigTable->iDeltaTwo[iIterator] =
            pVirusSigTable->iVirusLength -
            iStrDeltaTwo[pVirusSigTable->iVirusLength - 1];
    }
    for (iIterator = 0; iIterator < pVirusSigTable->iVirusLength; iIterator++)
    {
        iIndexOne = pVirusSigTable->iVirusLength - iRevStrDeltaTwo[iIterator];
        iIndextwo = iIterator - iRevStrDeltaTwo[iIterator] + 1;
        if (pVirusSigTable->iDeltaTwo[iIndexOne] > iIndextwo)
        {
            pVirusSigTable->iDeltaTwo[iIndexOne] = iIndextwo;
        }
    }
}

variable_types: struct VirusSignatureTable { char cVirus[200]; int iVirusLength; int iDeltaOne[256]; int iDeltaTwo[200]; } *

variable_types:
cReverseVirus
char [-1]

variable_types:
pcLeftChar
char *

variable_types:
pcRightChar
char *

variable_types:
pcTempStr
char *

variable_types: iIterator int

variable_types: iIndexOne int

variable_types: iIndextwo int

variable_types:
iStrDeltaTwo
int [-1]

variable_types:
iRevStrDeltaTwo
int [-1]


buildVirusSigTable

decompiled_code:
__int64 __fastcall buildVirusSigTable(char *src, char *dest)
{
int v2; // eax
__int64 v3; // r13
int v4; // ebx

if ( !src )
return 0xFFFFFFFFLL;
if ( !dest )
return 0xFFFFFFFFLL;
v2 = strlen(src);
v3 = v2;
v4 = v2;
strncpy(dest, src, v2);
dest[v3] = 0;
*((_DWORD *)dest + 50) = v4;
constructDeltaOneTable((int *)dest);
constructDeltaTwoTable((unsigned __int64)dest);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, char *dest)
{
int v2; // eax
__int64 v3; // r13
int v4; // ebx

if ( !src )
return 0xFFFFFFFFLL;
if ( !dest )
return 0xFFFFFFFFLL;
v2 = strlen(src);
v3 = v2;
v4 = v2;
strncpy(dest, src, v2);
dest[v3] = 0;
*((_DWORD *)dest + 50) = v4;
func1((int *)dest);
func4((unsigned __int64)dest);
return 0LL;
}

original_code:
int buildVirusSigTable (char *pcVirusSignature,
                        VirusSignatureTable_t * pVirusSigTable)
{
    int iVirusLength;
    if (((void *)0) == pcVirusSignature || ((void *)0) == pVirusSigTable)
    {
        return -1;
    }
    iVirusLength = strlen (pcVirusSignature);
    strncpy (pVirusSigTable->cVirus, pcVirusSignature, iVirusLength);
    pVirusSigTable->cVirus[iVirusLength] = '\0';
    pVirusSigTable->iVirusLength = iVirusLength;
    constructDeltaOneTable (pVirusSigTable);
    constructDeltaTwoTable (pVirusSigTable);
    return 0;
}

canonical_original_code:
int buildVirusSigTable(char *pcVirusSignature, struct VirusSignatureTable *pVirusSigTable)
{
    int iVirusLength;
    if (((void *)0) == pcVirusSignature || ((void *)0) == pVirusSigTable)
    {
        return -1;
    }
    iVirusLength = strlen (pcVirusSignature);
    strncpy (pVirusSigTable->cVirus, pcVirusSignature, iVirusLength);
    pVirusSigTable->cVirus[iVirusLength] = '\0';
    pVirusSigTable->iVirusLength = iVirusLength;
    constructDeltaOneTable (pVirusSigTable);
    constructDeltaTwoTable (pVirusSigTable);
    return 0;
}

variable_types:
pcVirusSignature
char *

variable_types: iVirusLength int

user_defined_types: struct VirusSignatureTable { char cVirus[200]; int iVirusLength; int iDeltaOne[256]; int iDeltaTwo[200]; }


repo: ut-osa/anon-pass

decompiled_code:
int set_epoch_start()
{
epoch_start = time(0LL) / SHIDWORD(options) * SHIDWORD(options);
return printf("Epoch 0 begins at t=%lu\n", epoch_start);
}

canonical_decompiled_code:
int func1()
{
epoch_start = time(0LL) / SHIDWORD(options) * SHIDWORD(options);
return printf("Epoch 0 begins at t=%lu\n", epoch_start);
}

original_code:
static void set_epoch_start(void)
{
   epoch_start = time(((void *)0)) / options.epoch_len * options.epoch_len;
   printf("Epoch 0 begins at t=%lu\n", epoch_start);
}

canonical_original_code:
static void set_epoch_start()
{
   epoch_start = time(((void *)0)) / options.epoch_len * options.epoch_len;
   printf("Epoch 0 begins at t=%lu\n", epoch_start);
}


decompiled_code:
unsigned int sleep_until_next_epoch()
{
__int128 v0; // rtt

v0 = time(0LL) - epoch_start;
return sleep(HIDWORD(options) - v0 % SHIDWORD(options));
}

canonical_decompiled_code:
unsigned int func2()
{
__int128 v0; // rtt

v0 = time(0LL) - epoch_start;
return sleep(HIDWORD(options) - v0 % SHIDWORD(options));
}

original_code:
static void sleep_until_next_epoch(void)
{
   time_t current_time = time(((void *)0));
   int time_left;
   time_left = options.epoch_len - ((current_time - epoch_start) % options.epoch_len);
   sleep(time_left);
}

canonical_original_code:
static void sleep_until_next_epoch()
{
   long current_time = time(((void *)0));
   int time_left;
   time_left = options.epoch_len - ((current_time - epoch_start) % options.epoch_len);
   sleep(time_left);
}


decompiled_code:
__int64 __fastcall process_args(int a1, __int64 a2)
{
int v2; // ebx
const char *v3; // rdx
__int64 v4; // rcx
int v5; // eax
__int64 v6; // rsi
int v7; // eax
__int64 result; // rax

options = 0x12C00001A0ALL;
*((_DWORD *)&options + 3) = 0;
if ( a1 > 1 )
{
v2 = 1;
while ( 1 )
{
while ( 1 )
{
v3 = *(const char **)(a2 + 8LL * v2);
v4 = 8LL * v2;
v5 = *(unsigned __int8 *)v3;
if ( v5 == 45 )
{
if ( v3[1] == 101 && !v3[2] )
{
if ( a1 > ++v2 )
HIDWORD(options) = (int)strtod(*(const char **)(a2 + v4 + 8), 0LL);
goto LABEL_5;
}
if ( v3[1] == 112 && !v3[2] )
break;
}
if ( !strcmp(*(const char **)(a2 + 8LL * v2), "--noop") )
{
*((_DWORD *)&options + 3) |= 1u;
}
else
{
if ( strcmp(*(const char **)(a2 + 8LL * v2), "--no-hash") )
{
if ( v5 != 45 || v3[1] != 104 || (result = 4294967294LL, v3[2]) )
{
fprintf(stderr, "Unknown option: %s\n", v3);
result = 0xFFFFFFFFLL;
}
return result;
}
*((_DWORD *)&options + 3) |= 2u;
}
LABEL_5:
if ( a1 <= ++v2 )
goto LABEL_12;
}
if ( a1 <= ++v2 )
goto LABEL_5;
++v2;
LODWORD(options) = (int)strtod(*(const char **)(a2 + v4 + 8), 0LL);
if ( a1 <= v2 )
{
LABEL_12:
v6 = HIDWORD(options);
v7 = 1000000 * v6;
goto LABEL_13;
}
}
}
v7 = 300000000;
v6 = 300LL;
LABEL_13:
*((_DWORD *)&options + 2) = v7;
printf("Epoch length: %d s\n", v6);
printf("Listening on port %d...\n", (unsigned int)options);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, __int64 a2)
{
int v2; // ebx
const char *v3; // rdx
__int64 v4; // rcx
int v5; // eax
__int64 v6; // rsi
int v7; // eax
__int64 result; // rax

options = 0x12C00001A0ALL;
*((_DWORD *)&options + 3) = 0;
if ( a1 > 1 )
{
v2 = 1;
while ( 1 )
{
while ( 1 )
{
v3 = *(const char **)(a2 + 8LL * v2);
v4 = 8LL * v2;
v5 = *(unsigned __int8 *)v3;
if ( v5 == 45 )
{
if ( v3[1] == 101 && !v3[2] )
{
if ( a1 > ++v2 )
HIDWORD(options) = (int)strtod(*(const char **)(a2 + v4 + 8), 0LL);
goto LABEL_5;
}
if ( v3[1] == 112 && !v3[2] )
break;
}
if ( !strcmp(*(const char **)(a2 + 8LL * v2), "--noop") )
{
*((_DWORD *)&options + 3) |= 1u;
}
else
{
if ( strcmp(*(const char **)(a2 + 8LL * v2), "--no-hash") )
{
if ( v5 != 45 || v3[1] != 104 || (result = 4294967294LL, v3[2]) )
{
fprintf(stderr, "Unknown option: %s\n", v3);
result = 0xFFFFFFFFLL;
}
return result;
}
*((_DWORD *)&options + 3) |= 2u;
}
LABEL_5:
if ( a1 <= ++v2 )
goto LABEL_12;
}
if ( a1 <= ++v2 )
goto LABEL_5;
++v2;
LODWORD(options) = (int)strtod(*(const char **)(a2 + v4 + 8), 0LL);
if ( a1 <= v2 )
{
LABEL_12:
v6 = HIDWORD(options);
v7 = 1000000 * v6;
goto LABEL_13;
}
}
}
v7 = 300000000;
v6 = 300LL;
LABEL_13:
*((_DWORD *)&options + 2) = v7;
printf("Epoch length: %d s\n", v6);
printf("Listening on port %d...\n", (unsigned int)options);
return 0LL;
}

original_code:
int process_args(int argc, char *argv[])
{
   int on_arg = 1;
   options.epoch_len = 300;
   options.port = 6666;
   options.flag = 0;
   for (on_arg = 1; on_arg < argc; on_arg++) {
      if (strcmp(argv[on_arg], "-e") == 0) {
         if (++on_arg < argc)
            options.epoch_len = strtod(argv[on_arg], ((void *)0));
      } else if (strcmp(argv[on_arg], "-p") == 0) {
         if (++on_arg < argc)
            options.port = strtod(argv[on_arg], ((void *)0));
      } else if (strcmp(argv[on_arg], "--noop") == 0) {
         options.flag |= (1<<0);
      } else if (strcmp(argv[on_arg], "--no-hash") == 0) {
         options.flag |= (1<<1);
      } else if (strcmp(argv[on_arg], "-h") == 0) {
         return -2;
      } else {
         fprintf(stderr, "Unknown option: %s\n", argv[on_arg]);
         return -1;
      }
   }
   options.timeout_len = 1000000 * options.epoch_len;
   printf("Epoch length: %d s\n", options.epoch_len);
   printf("Listening on port %d...\n", options.port);
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return printf("Usage: %s [OPTION]...\n -e <epoch len (in s) | 300>\n -p <port | 6666>\n", a1);
}

canonical_decompiled_code:
int __fastcall func13(const char *a1)
{
return printf("Usage: %s [OPTION]...\n -e <epoch len (in s) | 300>\n -p <port | 6666>\n", a1);
}

original_code:
void usage(char *prog_name)
{
   printf("Usage: %s [OPTION]...\n"
          "   -e <epoch len (in s) | 300>\n"
          "   -p <port | 6666>\n", prog_name);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v5; // eax
int v6; // ebx
__int64 v7; // rax
unsigned int *v8; // rbp
int v9; // ebx
int optval; // [rsp+Ch] [rbp-6Ch] BYREF
int fd[26]; // [rsp+10h] [rbp-68h] BYREF

optval = 1;
v3 = process_args(argc, (__int64)argv);
if ( v3 >= 0 )
{
v4 = 1;
init_server(fd);
while ( 1 )
{
v5 = accept(fd[0], 0LL, 0LL);
v6 = v5;
if ( v5 < 0 )
break;
if ( setsockopt(v5, 6, 1, &optval, 4u) < 0 )
{
fwrite("setsockopt failed\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
v7 = Malloc(24LL);
*(_DWORD *)v7 = v4++;
*(_DWORD *)(v7 + 4) = v6;
v8 = (unsigned int *)v7;
*(_QWORD *)(v7 + 16) = fd;
if ( pthread_create((pthread_t *)(v7 + 8), 0LL, handle_requests, (void *)v7) < 0 )
{
fprintf(stderr, "couldn't create thread (id %d)\n", *v8);
free(v8);
}
}
fwrite("accept", 1uLL, 6uLL, stderr);
exit(1);
}
v9 = v3;
usage(*argv);
exit(v9 != -2);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
int v5; // eax
int v6; // ebx
__int64 v7; // rax
unsigned int *v8; // rbp
int v9; // ebx
int optval; // [rsp+Ch] [rbp-6Ch] BYREF
int fd[26]; // [rsp+10h] [rbp-68h] BYREF

optval = 1;
v3 = func12(argc, (__int64)argv);
if ( v3 >= 0 )
{
v4 = 1;
func5(fd);
while ( 1 )
{
v5 = accept(fd[0], 0LL, 0LL);
v6 = v5;
if ( v5 < 0 )
break;
if ( setsockopt(v5, 6, 1, &optval, 4u) < 0 )
{
fwrite("setsockopt failed\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
v7 = Malloc(24LL);
*(_DWORD *)v7 = v4++;
*(_DWORD *)(v7 + 4) = v6;
v8 = (unsigned int *)v7;
*(_QWORD *)(v7 + 16) = fd;
if ( pthread_create((pthread_t *)(v7 + 8), 0LL, handle_requests, (void *)v7) < 0 )
{
fprintf(stderr, "couldn't create thread (id %d)\n", *v8);
free(v8);
}
}
fwrite("accept", 1uLL, 6uLL, stderr);
exit(1);
}
v9 = v3;
func13(*argv);
exit(v9 != -2);
}

original_code:
int main(int argc, char *argv[])
{
   static unsigned int start_time = 0;
   struct timeval tv = {0};
   pid_t children[1024] = {0};
   pid_t pid;
   int i, num_children = argc > 1 ? strtod(argv[1], ((void *)0)) : 0;
   if (argc < 3) {
      return -1;
   }
   gettimeofday(&tv, ((void *)0));
   start_time = tv.tv_sec + 10;
   for (i = 0; i < num_children; i++) {
      children[i] = fork();
      if (children[i] < 0) {
         perror("Fork");
         exit(-1);
      } else if (children[i] == 0) {
         break;
      }
   }
   if (i == num_children) {
      for (i = 0; i < num_children; i++) {
         waitpid(children[i], ((void *)0), 0);
      }
   } else {
      struct timeval t = {0};
      gettimeofday(&t, ((void *)0));
      if (t.tv_sec < start_time)
         usleep(1000000 * (start_time - t.tv_sec) - t.tv_usec);
      execv(argv[2], argv + 2);
   }
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   static unsigned int start_time = 0;
   struct timeval tv = {0};
   int children[1024] = {0};
   int pid;
   int i; int num_children = argc > 1 ? strtod(argv[1], ((void *)0)) : 0;
   if (argc < 3) {
      return -1;
   }
   gettimeofday(&tv, ((void *)0));
   start_time = tv.tv_sec + 10;
   for (i = 0; i < num_children; i++) {
      children[i] = fork();
      if (children[i] < 0) {
         perror("Fork");
         exit(-1);
      } else if (children[i] == 0) {
         break;
      }
   }
   if (i == num_children) {
      for (i = 0; i < num_children; i++) {
         waitpid(children[i], ((void *)0), 0);
      }
   } else {
      struct timeval t = {0};
      gettimeofday(&t, ((void *)0));
      if (t.tv_sec < start_time)
         usleep(1000000 * (start_time - t.tv_sec) - t.tv_usec);
      execv(argv[2], argv + 2);
   }
   return 0;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
children
int [1024]

variable_types: pid int

variable_types: i int


decompiled_code:
__int64 __fastcall read_all(int fd, void *buf, size_t nbytes)
{
size_t v4; // rbx
ssize_t v5; // rax

if ( !nbytes )
return 0LL;
v4 = nbytes;
do
{
v5 = read(fd, buf, v4);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
buf = (char *)buf + v5;
v4 -= v5;
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, size_t nbytes)
{
size_t v4; // rbx
ssize_t v5; // rax

if ( !nbytes )
return 0LL;
v4 = nbytes;
do
{
v5 = read(fd, buf, v4);
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
buf = (char *)buf + v5;
v4 -= v5;
}
while ( v4 );
return 0LL;
}

original_code:
int read_all(int fd, void *buf, size_t count)
{
   uint8_t *the_buf = buf;
   while (count > 0) {
      ssize_t rc;
      rc = read(fd, the_buf, count);
      if (rc <= 0) {
         return -1;
      }
      the_buf += rc;
      count -= rc;
   }
   return 0;
}

canonical_original_code:
int read_all(int fd, void *buf, unsigned long count)
{
   unsigned char *the_buf = buf;
   while (count > 0) {
      long rc;
      rc = read(fd, the_buf, count);
      if (rc <= 0) {
         return -1;
      }
      the_buf += rc;
      count -= rc;
   }
   return 0;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: rc long


decompiled_code:
void debug_hex()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void debug_hex(uint8_t *buf, size_t sz)
{
   size_t i;
   for (i = 0; i < sz; i++) {
      do {} while(0);
   }
}

canonical_original_code:
void debug_hex(unsigned char *buf, unsigned long sz)
{
   unsigned long i;
   for (i = 0; i < sz; i++) {
      do {} while(0);
   }
}

variable_types:
buf
unsigned char *

variable_types:
sz
unsigned long

variable_types:
i
unsigned long


decompiled_code:
int __fastcall error_hex(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rdx
int result; // eax

if ( a2 )
{
v2 = a1;
do
{
v3 = *v2++;
result = fprintf(stderr, "%02x", v3);
}
while ( &a1[a2] != v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 *a1, __int64 a2)
{
unsigned __int8 *v2; // rbx
__int64 v3; // rdx
int result; // eax

if ( a2 )
{
v2 = a1;
do
{
v3 = *v2++;
result = fprintf(stderr, "%02x", v3);
}
while ( &a1[a2] != v2 );
}
return result;
}

original_code:
void error_hex(uint8_t *buf, size_t sz)
{
   size_t i;
   for (i = 0; i < sz; i++) {
      fprintf(stderr, "%02x", buf[i]);
   }
}

canonical_original_code:
void error_hex(unsigned char *buf, unsigned long sz)
{
   unsigned long i;
   for (i = 0; i < sz; i++) {
      fprintf(stderr, "%02x", buf[i]);
   }
}


Malloc

decompiled_code:
void *__fastcall Malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

original_code:
void *Malloc(size_t sz)
{
   void *result = malloc(sz);
   if (result == ((void *)0))
      do { fprintf(stderr, "Out of memory!\n"); exit(1); } while(0);
   return result;
}

canonical_original_code:
void *Malloc(unsigned long sz)
{
   void *result = malloc(sz);
   if (result == ((void *)0))
      do { fprintf(stderr, "Out of memory!\n"); exit(1); } while(0);
   return result;
}

variable_types:
result
void *

return_type: void *


decompiled_code:
__int64 __fastcall token_hash(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return *a1;
}

original_code:
guint token_hash(gconstpointer key)
{
   return *(guint *)key;
}

canonical_original_code:
unsigned int token_hash(void *key)
{
   return *(unsigned int *)key;
}

variable_types:
key
void *

return_type: unsigned int


original_code:
gboolean token_cmp(gconstpointer a,
                   gconstpointer b)
{
   return (memcmp(a, b, 20) == 0);
}

canonical_original_code:
int token_cmp(void *a, void *b)
{
   return (memcmp(a, b, 20) == 0);
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
// attributes: thunk
void token_free(void *ptr)
{
free(ptr);
}

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

original_code:
void token_free(gpointer k)
{
   free(k);
}

canonical_original_code:
void token_free(void *k)
{
   free(k);
}

variable_types:
k
void *


decompiled_code:
void __fastcall value_free(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void value_free(gpointer v)
{
   if (v)
      free(v);
}

canonical_original_code:
void value_free(void *v)
{
   if (v)
      free(v);
}

variable_types:
v
void *


unow

decompiled_code:
__suseconds_t unow()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func4()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
uint64_t unow()
{
   struct timeval now;
   gettimeofday(&now, ((void *)0));
   return now.tv_sec * 1000000 + now.tv_usec;
}

canonical_original_code:
unsigned long unow()
{
   struct timeval now;
   gettimeofday(&now, ((void *)0));
   return now.tv_sec * 1000000 + now.tv_usec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: unsigned long


decompiled_code:
__int64 __fastcall hs_connect(const __m128i *a1)
{
__int64 result; // rax

result = Malloc(20LL);
*(_DWORD *)result = -1;
*(__m128i *)(result + 4) = _mm_loadu_si128(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const __m128i *a1)
{
__int64 result; // rax

result = func8(20LL);
*(_DWORD *)result = -1;
*(__m128i *)(result + 4) = _mm_loadu_si128(a1);
return result;
}

original_code:
struct hs_conn *hs_connect(struct sockaddr_in *addr)
{
   struct hs_conn *result = ((void *)0);
   result = Malloc(sizeof(*result));
   result->fd = -1;
   memcpy(&result->addr, addr, sizeof(*addr));
   return result;
}

variable_types:
addr
struct sockaddr_in *

variable_types: struct hs_conn { int fd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; } *

user_defined_types: struct hs_conn { int fd; struct sockaddr_in addr; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
__int64 __fastcall hs_connect_str(const char *a1, __int16 a2)
{
const char *v4; // rsi
void *v5; // rdx
int v6; // er8
__int64 result; // rax
__int128 v8; // [rsp+0h] [rbp-18h] BYREF

v4 = a1;
v8 = 0LL;
LOWORD(v8) = 2;
WORD1(v8) = _bswap_16(a2);
v6 = inet_pton(2, v4, v5);
result = 0LL;
if ( v6 > 0 )
result = hs_connect(&v8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, __int16 a2)
{
const char *v4; // rsi
void *v5; // rdx
int v6; // er8
__int64 result; // rax
__int128 v8; // [rsp+0h] [rbp-18h] BYREF

v4 = a1;
v8 = 0LL;
LOWORD(v8) = 2;
WORD1(v8) = func6(a2);
v6 = inet_pton(2, v4, v5);
result = 0LL;
if ( v6 > 0 )
result = func9(&v8);
return result;
}

original_code:
struct hs_conn *hs_connect_str(const char *host, int port)
{
   struct hs_conn *result = ((void *)0);
   struct sockaddr_in addr;
   memset(&addr, 0, sizeof(addr));
   addr.sin_family = 2;
   addr.sin_port = htons(port);
   if (inet_pton(2, host, &addr.sin_addr) <= 0)
      goto out;
   result = hs_connect(&addr);
 out:
   return result;
}

canonical_original_code:
struct hs_conn *hs_connect_str(char *host, int port)
{
   struct hs_conn *result = ((void *)0);
   struct sockaddr_in addr;
   memset(&addr, 0, sizeof(addr));
   addr.sin_family = 2;
   addr.sin_port = htons(port);
   if (inet_pton(2, host, &addr.sin_addr) <= 0)
      goto out;
   result = hs_connect(&addr);
 out:
   return result;
}

variable_types:
host
char *

variable_types: port int

return_type: struct hs_conn { int fd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; } *


decompiled_code:
__int64 __fastcall hs_login(int *a1, const __m128i *a2)
{
int v3; // eax
int v4; // edi
__int64 result; // rax
unsigned __int8 v6; // [rsp+Fh] [rbp-29h] BYREF
char buf; // [rsp+10h] [rbp-28h] BYREF
__m128i v8; // [rsp+11h] [rbp-27h]
int v9; // [rsp+21h] [rbp-17h]

v3 = a2[1].m128i_i32[0];
v4 = *a1;
buf = 0;
v9 = v3;
v8 = _mm_loadu_si128(a2);
if ( v4 < 0 )
{
if ( (int)_hs_connect((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
v4 = *a1;
}
if ( (unsigned int)write(v4, &buf, 0x15uLL) != 21 )
return 0xFFFFFFFFLL;
if ( (unsigned int)read(*a1, &v6, 1uLL) != 1 )
return 0xFFFFFFFFLL;
result = v6;
if ( v6 > 1u )
return 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, const __m128i *a2)
{
int v3; // eax
int v4; // edi
__int64 result; // rax
unsigned __int8 v6; // [rsp+Fh] [rbp-29h] BYREF
char buf; // [rsp+10h] [rbp-28h] BYREF
__m128i v8; // [rsp+11h] [rbp-27h]
int v9; // [rsp+21h] [rbp-17h]

v3 = a2[1].m128i_i32[0];
v4 = *a1;
buf = 0;
v9 = v3;
v8 = _mm_loadu_si128(a2);
if ( v4 < 0 )
{
if ( (int)func7((__int64)a1) < 0 )
return 0xFFFFFFFFLL;
v4 = *a1;
}
if ( (unsigned int)write(v4, &buf, 0x15uLL) != 21 )
return 0xFFFFFFFFLL;
if ( (unsigned int)read(*a1, &v6, 1uLL) != 1 )
return 0xFFFFFFFFLL;
result = v6;
if ( v6 > 1u )
return 0xFFFFFFFFLL;
return result;
}

original_code:
int hs_login(struct hs_conn *hs, void *token)
{
   uint8_t buf[20 +sizeof(uint8_t)];
   uint8_t result;
   buf[0] = 0;
   memcpy(buf+1, token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf))
      return -1;
   if (read(hs->fd, &result, sizeof(result)) != sizeof(result))
      return -1;
   if (result != 0 && result != 1)
      return -1;
   return result;
}

canonical_original_code:
int hs_login(struct hs_conn *hs, void *token)
{
   unsigned char buf[-1];
   unsigned char result;
   buf[0] = 0;
   memcpy(buf+1, token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf))
      return -1;
   if (read(hs->fd, &result, sizeof(result)) != sizeof(result))
      return -1;
   if (result != 0 && result != 1)
      return -1;
   return result;
}

variable_types:
token
void *

variable_types:
buf
unsigned char [-1]

variable_types:
result
unsigned char


decompiled_code:
__int64 __fastcall hs_link(int *a1, const __m128i *a2, const __m128i *a3)
{
int v4; // eax
int v5; // edi
int v6; // eax
unsigned int v7; // er8
unsigned __int8 v9; // [rsp+Fh] [rbp-39h] BYREF
char buf; // [rsp+10h] [rbp-38h] BYREF
__m128i v11; // [rsp+11h] [rbp-37h]
int v12; // [rsp+21h] [rbp-27h]
__m128i v13; // [rsp+25h] [rbp-23h]
int v14; // [rsp+35h] [rbp-13h]

v4 = a2[1].m128i_i32[0];
v5 = *a1;
buf = 1;
v12 = v4;
v6 = a3[1].m128i_i32[0];
v11 = _mm_loadu_si128(a2);
v14 = v6;
v13 = _mm_loadu_si128(a3);
if ( v5 < 0 )
{
if ( (int)_hs_connect((__int64)a1) < 0 )
{
fwrite("Failed to connect hs\n", 1uLL, 0x15uLL, stderr);
return (unsigned int)-1;
}
v5 = *a1;
}
if ( (unsigned int)write(v5, &buf, 0x29uLL) == 41 )
{
if ( (unsigned int)read(*a1, &v9, 1uLL) == 1 )
{
v7 = v9;
if ( v9 > 1u )
{
fprintf(stderr, "Improper result %d\n", v9);
v7 = -1;
}
}
else
{
fwrite("Failed to read result\n", 1uLL, 0x16uLL, stderr);
v7 = -1;
}
}
else
{
fwrite("Failed to write request\n", 1uLL, 0x18uLL, stderr);
v7 = -1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, const __m128i *a2, const __m128i *a3)
{
int v4; // eax
int v5; // edi
int v6; // eax
unsigned int v7; // er8
unsigned __int8 v9; // [rsp+Fh] [rbp-39h] BYREF
char buf; // [rsp+10h] [rbp-38h] BYREF
__m128i v11; // [rsp+11h] [rbp-37h]
int v12; // [rsp+21h] [rbp-27h]
__m128i v13; // [rsp+25h] [rbp-23h]
int v14; // [rsp+35h] [rbp-13h]

v4 = a2[1].m128i_i32[0];
v5 = *a1;
buf = 1;
v12 = v4;
v6 = a3[1].m128i_i32[0];
v11 = _mm_loadu_si128(a2);
v14 = v6;
v13 = _mm_loadu_si128(a3);
if ( v5 < 0 )
{
if ( (int)func7((__int64)a1) < 0 )
{
fwrite("Failed to connect hs\n", 1uLL, 0x15uLL, stderr);
return (unsigned int)-1;
}
v5 = *a1;
}
if ( (unsigned int)write(v5, &buf, 0x29uLL) == 41 )
{
if ( (unsigned int)read(*a1, &v9, 1uLL) == 1 )
{
v7 = v9;
if ( v9 > 1u )
{
fprintf(stderr, "Improper result %d\n", v9);
v7 = -1;
}
}
else
{
fwrite("Failed to read result\n", 1uLL, 0x16uLL, stderr);
v7 = -1;
}
}
else
{
fwrite("Failed to write request\n", 1uLL, 0x18uLL, stderr);
v7 = -1;
}
return v7;
}

original_code:
int hs_link(struct hs_conn *hs, void *prev_token, void *next_token)
{
   uint8_t buf[sizeof(uint8_t)+2*20];
   uint8_t result;
   buf[0] = 1;
   memcpy(buf+1, prev_token, 20);
   memcpy(buf+1+20, next_token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      fprintf(stderr, "Failed to connect hs\n");
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf)) {
      fprintf(stderr, "Failed to write request\n");
      return -1;
   }
   if (read(hs->fd, &result, sizeof(result)) != sizeof(result)) {
      fprintf(stderr, "Failed to read result\n");
      return -1;
   }
   if (result != 0 && result != 1) {
      fprintf(stderr, "Improper result %d\n", result);
      return -1;
   }
   return result;
}

canonical_original_code:
int hs_link(struct hs_conn *hs, void *prev_token, void *next_token)
{
   unsigned char buf[-1];
   unsigned char result;
   buf[0] = 1;
   memcpy(buf+1, prev_token, 20);
   memcpy(buf+1+20, next_token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      fprintf(stderr, "Failed to connect hs\n");
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf)) {
      fprintf(stderr, "Failed to write request\n");
      return -1;
   }
   if (read(hs->fd, &result, sizeof(result)) != sizeof(result)) {
      fprintf(stderr, "Failed to read result\n");
      return -1;
   }
   if (result != 0 && result != 1) {
      fprintf(stderr, "Improper result %d\n", result);
      return -1;
   }
   return result;
}


decompiled_code:
__int64 __fastcall hs_get(int *a1, const __m128i *a2, _DWORD *a3, void **a4)
{
__int32 v7; // eax
int v8; // edi
__int64 result; // rax
void *v10; // rax
size_t v11; // rdx
int v12; // edi
int v13; // edx
unsigned __int8 v14; // [rsp+Bh] [rbp-3Dh] BYREF
_DWORD nbytes[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v7 = a2[1].m128i_i32[0];
v8 = *a1;
LOBYTE(nbytes[1]) = 3;
*(_DWORD *)((char *)&nbytes[5] + 1) = v7;
*(__m128i *)((char *)&nbytes[1] + 1) = _mm_loadu_si128(a2);
if ( v8 < 0 )
{
if ( (int)_hs_connect((__int64)a1) < 0 )
{
fwrite("Failed to connect hs\n", 1uLL, 0x15uLL, stderr);
return 0xFFFFFFFFLL;
}
v8 = *a1;
}
if ( (unsigned int)write(v8, &nbytes[1], 0x15uLL) != 21 || (unsigned int)read(*a1, &v14, 1uLL) != 1 )
goto LABEL_14;
result = v14;
if ( v14 == 1 && a4 )
{
if ( (unsigned int)read(*a1, nbytes, 4uLL) == 4 )
{
v10 = (void *)Malloc(nbytes[0]);
v11 = nbytes[0];
v12 = *a1;
*a4 = v10;
v13 = read(v12, v10, v11);
if ( v13 == nbytes[0] )
{
result = v14;
if ( a3 )
*a3 = v13;
return result;
}
free(*a4);
}
LABEL_14:
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int *a1, const __m128i *a2, _DWORD *a3, void **a4)
{
__int32 v7; // eax
int v8; // edi
__int64 result; // rax
void *v10; // rax
size_t v11; // rdx
int v12; // edi
int v13; // edx
unsigned __int8 v14; // [rsp+Bh] [rbp-3Dh] BYREF
_DWORD nbytes[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v7 = a2[1].m128i_i32[0];
v8 = *a1;
LOBYTE(nbytes[1]) = 3;
*(_DWORD *)((char *)&nbytes[5] + 1) = v7;
*(__m128i *)((char *)&nbytes[1] + 1) = _mm_loadu_si128(a2);
if ( v8 < 0 )
{
if ( (int)func7((__int64)a1) < 0 )
{
fwrite("Failed to connect hs\n", 1uLL, 0x15uLL, stderr);
return 0xFFFFFFFFLL;
}
v8 = *a1;
}
if ( (unsigned int)write(v8, &nbytes[1], 0x15uLL) != 21 || (unsigned int)read(*a1, &v14, 1uLL) != 1 )
goto LABEL_14;
result = v14;
if ( v14 == 1 && a4 )
{
if ( (unsigned int)read(*a1, nbytes, 4uLL) == 4 )
{
v10 = (void *)func8(nbytes[0]);
v11 = nbytes[0];
v12 = *a1;
*a4 = v10;
v13 = read(v12, v10, v11);
if ( v13 == nbytes[0] )
{
result = v14;
if ( a3 )
*a3 = v13;
return result;
}
free(*a4);
}
LABEL_14:
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int hs_get(struct hs_conn *hs, void *token, uint32_t *value_sz, void **value)
{
   uint8_t buf[sizeof(uint8_t)+20];
   uint8_t result;
   uint32_t the_sz;
   buf[0] = 3;
   memcpy(buf+1, token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      fprintf(stderr, "Failed to connect hs\n");
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf))
      return -1;
   if (read(hs->fd, &result, sizeof(result)) != sizeof(result))
      return -1;
   if (result == 1 && value != ((void *)0)) {
      if (read(hs->fd, &the_sz, sizeof(the_sz)) != sizeof(the_sz))
         return -1;
      *value = Malloc(the_sz);
      if (read(hs->fd, *value, the_sz) != the_sz) {
         free(*value);
         return -1;
      }
      if (value_sz)
         *value_sz = the_sz;
   }
   return result;
}

canonical_original_code:
int hs_get(struct hs_conn *hs, void *token, unsigned int *value_sz, void **value)
{
   unsigned char buf[-1];
   unsigned char result;
   unsigned int the_sz;
   buf[0] = 3;
   memcpy(buf+1, token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      fprintf(stderr, "Failed to connect hs\n");
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf))
      return -1;
   if (read(hs->fd, &result, sizeof(result)) != sizeof(result))
      return -1;
   if (result == 1 && value != ((void *)0)) {
      if (read(hs->fd, &the_sz, sizeof(the_sz)) != sizeof(the_sz))
         return -1;
      *value = Malloc(the_sz);
      if (read(hs->fd, *value, the_sz) != the_sz) {
         free(*value);
         return -1;
      }
      if (value_sz)
         *value_sz = the_sz;
   }
   return result;
}

variable_types:
value
void **


decompiled_code:
__int64 __fastcall hs_put(int *a1, const __m128i *a2, int a3, const void *a4)
{
__int32 v6; // eax
int v7; // edi
__int64 result; // rax
int v9; // eax
_DWORD n[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v6 = a2[1].m128i_i32[0];
v7 = *a1;
n[0] = a3;
LOBYTE(n[1]) = 2;
*(_DWORD *)((char *)&n[5] + 1) = v6;
*(__m128i *)((char *)&n[1] + 1) = _mm_loadu_si128(a2);
if ( v7 < 0 )
{
if ( (int)_hs_connect((__int64)a1) < 0 )
{
fwrite("Failed to connect hs\n", 1uLL, 0x15uLL, stderr);
return 0xFFFFFFFFLL;
}
v7 = *a1;
}
if ( (unsigned int)write(v7, &n[1], 0x15uLL) == 21
&& (unsigned int)write(*a1, n, 4uLL) == 4
&& (v9 = write(*a1, a4, n[0]), v9 == n[0]) )
{
result = 1LL;
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int *a1, const __m128i *a2, int a3, const void *a4)
{
__int32 v6; // eax
int v7; // edi
__int64 result; // rax
int v9; // eax
_DWORD n[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v6 = a2[1].m128i_i32[0];
v7 = *a1;
n[0] = a3;
LOBYTE(n[1]) = 2;
*(_DWORD *)((char *)&n[5] + 1) = v6;
*(__m128i *)((char *)&n[1] + 1) = _mm_loadu_si128(a2);
if ( v7 < 0 )
{
if ( (int)func7((__int64)a1) < 0 )
{
fwrite("Failed to connect hs\n", 1uLL, 0x15uLL, stderr);
return 0xFFFFFFFFLL;
}
v7 = *a1;
}
if ( (unsigned int)write(v7, &n[1], 0x15uLL) == 21
&& (unsigned int)write(*a1, n, 4uLL) == 4
&& (v9 = write(*a1, a4, n[0]), v9 == n[0]) )
{
result = 1LL;
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int hs_put(struct hs_conn *hs, void *token, uint32_t value_sz, void *value)
{
   uint8_t buf[sizeof(uint8_t)+20];
   buf[0] = 2;
   memcpy(buf+1, token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      fprintf(stderr, "Failed to connect hs\n");
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf))
      return -1;
   if (write(hs->fd, &value_sz, sizeof(value_sz)) != sizeof(value_sz))
      return -1;
   if (write(hs->fd, value, value_sz) != value_sz)
      return -1;
   return 1;
}

canonical_original_code:
int hs_put(struct hs_conn *hs, void *token, unsigned int value_sz, void *value)
{
   unsigned char buf[-1];
   buf[0] = 2;
   memcpy(buf+1, token, 20);
   if (hs->fd < 0 && __hs_connect(hs) < 0) {
      fprintf(stderr, "Failed to connect hs\n");
      return -1;
   }
   if (write(hs->fd, buf, sizeof(buf)) != sizeof(buf))
      return -1;
   if (write(hs->fd, &value_sz, sizeof(value_sz)) != sizeof(value_sz))
      return -1;
   if (write(hs->fd, value, value_sz) != value_sz)
      return -1;
   return 1;
}

variable_types:
value
void *


decompiled_code:
void __fastcall hs_disconnect(void *ptr)
{
close(*(_DWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
close(*(_DWORD *)ptr);
free(ptr);
}

original_code:
void hs_disconnect(struct hs_conn *hs)
{
   close(hs->fd);
   free(hs);
}


Malloc

decompiled_code:
void *__fastcall Malloc(size_t a1, int a2)
{
void *result; // rax
const char *v3; // rdx

result = malloc(a1);
if ( !result )
{
error((int)"Out of memory!\n", a2, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(size_t a1, int a2)
{
void *result; // rax
const char *v3; // rdx

result = malloc(a1);
if ( !result )
{
error((int)"Out of memory!\n", a2, v3);
exit(1);
}
return result;
}

original_code:
void *Malloc(size_t sz)
{
   void *result = malloc(sz);
   if (result == ((void *)0))
      do { error("Out of memory!\n"); exit(1); } while(0);
   return result;
}

canonical_original_code:
void *Malloc(unsigned long sz)
{
   void *result = malloc(sz);
   if (result == ((void *)0))
      do { error("Out of memory!\n"); exit(1); } while(0);
   return result;
}

variable_types:
sz
unsigned long


main

repo: utkd/nninc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
unsigned int v4; // ebp
int v5; // edx
const char *v6; // r13
const char *v7; // r9
__int64 v8; // r8
const char *v9; // rax
unsigned int v10; // eax
unsigned int v11; // er12
int v12; // er12
unsigned int v14; // eax
const char *v15; // [rsp+0h] [rbp-98h]
const char *v16; // [rsp+8h] [rbp-90h]
const char *v17; // [rsp+10h] [rbp-88h]
int v18; // [rsp+1Ch] [rbp-7Ch]
__int64 v19; // [rsp+20h] [rbp-78h] BYREF
__int64 v20; // [rsp+28h] [rbp-70h] BYREF
unsigned int v21; // [rsp+30h] [rbp-68h] BYREF
unsigned int v22; // [rsp+38h] [rbp-60h]

if ( argc <= 2 )
{
v12 = 1;
printf(
"Insufficient arguments.\n%s",
"Usage: nninc -[train|test] <train/test file> <options>\nCheck README.txt for more details on options\n");
return v12;
}
v3 = argv[1];
if ( !strcmp("-train", v3) )
{
v18 = 1;
}
else
{
v18 = strcmp("-test", v3);
if ( v18 )
{
v12 = 1;
printf(
"Incorrect usage.\n%s",
"Usage: nninc -[train|test] <train/test file> <options>\nCheck README.txt for more details on options\n");
return v12;
}
}
v4 = 0;
v5 = 2;
v6 = 0LL;
v15 = 0LL;
v7 = "config.conf";
v17 = argv[2];
v16 = "model.mdl";
do
{
v8 = v5;
v9 = argv[v8];
if ( !strcmp(v9, "-config") )
{
v7 = argv[v8 + 1];
++v5;
v9 = v7;
}
if ( !strcmp(v9, "-model") )
{
v9 = argv[++v5];
v16 = v9;
}
if ( !strcmp(v9, "-validation") )
{
v9 = argv[++v5];
v15 = v9;
}
if ( !strcmp(v9, "-output") )
{
v6 = argv[++v5];
v9 = v6;
}
if ( !strcmp(v9, "-saveacts") )
v4 = 1;
++v5;
}
while ( argc > v5 );
if ( !(unsigned int)read_config(v7, &v21) )
{
v12 = 1;
puts("Error parsing config file.");
return v12;
}
puts("Configuration loaded successfully.");
v19 = 0LL;
v10 = read_data(v17, &v19, v21, v22);
v11 = v10;
if ( v10 == -1 )
{
v12 = 1;
puts("Something went wrong in reading data set. Exiting.");
return v12;
}
printf("Read %d training instances successfully.\n", v10);
v20 = 0LL;
if ( v15 )
{
v14 = read_data(v15, &v20, v21, v22);
if ( v14 == -1 )
{
v12 = 1;
puts("Something went wrong in reading validation set. Exiting.");
return v12;
}
printf("Read %d validation instances successfully.\n", v14);
}
if ( !v18 )
{
v12 = test(v19, v16, v6, v11, v4);
if ( !v12 )
{
puts("Testing failed.");
return v12;
}
return 0;
}
v12 = train(v19, v20, v11, &v21);
if ( v12 )
return 0;
puts("Training failed.");
return v12;
}

original_code:
int main(int argc, char* argv[]) {
 struct network_config configuration;
 const char* USAGE_STRING = "Usage: nninc -[train|test] <train/test file> <options>\nCheck README.txt for more details on options\n";
 const char* config_option = "-config";
 const char* model_option = "-model";
 const char* validation_option = "-validation";
 const char* output_option = "-output";
 const char* save_activations_option = "-saveacts";
 char *config_file = "config.conf";
 char *model_file = "model.mdl";
 char *validation_file = ((void *)0);
 char *data_file;
 char *output_file = ((void *)0);
 int option;
 int do_training = 1;
 int do_validation = 0;
 int save_activations = 0;
 int i;
 if(argc < 3){
  printf("Insufficient arguments.\n%s", USAGE_STRING);
  return 1;
 }
 if(strcmp("-train", argv[1]) == 0){
  do_training = 1;
 }
 else if(strcmp("-test", argv[1]) == 0) {
  do_training = 0;
 }
 else{
  printf("Incorrect usage.\n%s", USAGE_STRING);
  return 1;
 }
 data_file = argv[2];
 if(argc > 2) {
  for(option = 2; option < argc; option++){
   if(strcmp(argv[option], config_option) == 0)
    config_file = argv[++option];
   if(strcmp(argv[option], model_option) == 0)
    model_file = argv[++option];
   if(strcmp(argv[option], validation_option) == 0)
    validation_file = argv[++option];
   if(strcmp(argv[option], output_option) == 0)
    output_file = argv[++option];
   if(strcmp(argv[option], save_activations_option) == 0)
    save_activations = 1;
  }
 }
 if(validation_file)
  do_validation = 1;
 int result = read_config(config_file, &configuration);
 if(result == 0) {
  printf("Error parsing config file.\n");
  return 1;
 }
 else {
  printf("Configuration loaded successfully.\n");
 }
 struct data_instance* dataset = ((void *)0);
 int num_instances = read_data(data_file, &dataset, configuration.num_input_nodes, configuration.num_output_nodes);
 if(num_instances == -1){
  printf("Something went wrong in reading data set. Exiting.\n");
  return 1;
 }
 else {
  printf("Read %d training instances successfully.\n", num_instances);
 }
 struct data_instance* validationset = ((void *)0);
 if(do_validation) {
  int num_validation_instances = read_data(validation_file, &validationset, configuration.num_input_nodes, configuration.num_output_nodes);
  if(num_validation_instances == -1){
   printf("Something went wrong in reading validation set. Exiting.\n");
   return 1;
  }
  else {
   printf("Read %d validation instances successfully.\n", num_validation_instances);
  }
 }
 if(do_training) {
  result = train(dataset, validationset, num_instances, &configuration);
  if(result == 0){
   printf("Training failed.\n");
  }
 }
 else {
  result = test(dataset, model_file, output_file, num_instances, save_activations);
  if(result == 0){
   printf("Testing failed.\n");
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct network_config configuration;
 char *USAGE_STRING = "Usage: nninc -[train|test] <train/test file> <options>\nCheck README.txt for more details on options\n";
 char *config_option = "-config";
 char *model_option = "-model";
 char *validation_option = "-validation";
 char *output_option = "-output";
 char *save_activations_option = "-saveacts";
 char *config_file = "config.conf";
 char *model_file = "model.mdl";
 char *validation_file = ((void *)0);
 char *data_file;
 char *output_file = ((void *)0);
 int option;
 int do_training = 1;
 int do_validation = 0;
 int save_activations = 0;
 int i;
 if(argc < 3){
  printf("Insufficient arguments.\n%s", USAGE_STRING);
  return 1;
 }
 if(strcmp("-train", argv[1]) == 0){
  do_training = 1;
 }
 else if(strcmp("-test", argv[1]) == 0) {
  do_training = 0;
 }
 else{
  printf("Incorrect usage.\n%s", USAGE_STRING);
  return 1;
 }
 data_file = argv[2];
 if(argc > 2) {
  for(option = 2; option < argc; option++){
   if(strcmp(argv[option], config_option) == 0)
    config_file = argv[++option];
   if(strcmp(argv[option], model_option) == 0)
    model_file = argv[++option];
   if(strcmp(argv[option], validation_option) == 0)
    validation_file = argv[++option];
   if(strcmp(argv[option], output_option) == 0)
    output_file = argv[++option];
   if(strcmp(argv[option], save_activations_option) == 0)
    save_activations = 1;
  }
 }
 if(validation_file)
  do_validation = 1;
 int result = read_config(config_file, &configuration);
 if(result == 0) {
  printf("Error parsing config file.\n");
  return 1;
 }
 else {
  printf("Configuration loaded successfully.\n");
 }
 struct data_instance *dataset = ((void *)0);
 int num_instances = read_data(data_file, &dataset, configuration.num_input_nodes, configuration.num_output_nodes);
 if(num_instances == -1){
  printf("Something went wrong in reading data set. Exiting.\n");
  return 1;
 }
 else {
  printf("Read %d training instances successfully.\n", num_instances);
 }
 struct data_instance *validationset = ((void *)0);
 if(do_validation) {
  int num_validation_instances = read_data(validation_file, &validationset, configuration.num_input_nodes, configuration.num_output_nodes);
  if(num_validation_instances == -1){
   printf("Something went wrong in reading validation set. Exiting.\n");
   return 1;
  }
  else {
   printf("Read %d validation instances successfully.\n", num_validation_instances);
  }
 }
 if(do_training) {
  result = train(dataset, validationset, num_instances, &configuration);
  if(result == 0){
   printf("Training failed.\n");
  }
 }
 else {
  result = test(dataset, model_file, output_file, num_instances, save_activations);
  if(result == 0){
   printf("Testing failed.\n");
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct network_config { int num_input_nodes; int num_hidden_nodes; int num_output_nodes; int num_iterations; double learning_rate; int seed_value; double momentum; int batch_size; }

variable_types: option int

variable_types: i int

variable_types: result int

variable_types: struct data_instance { double *input; double *output; struct data_instance *next; } *


decompiled_code:
_BOOL8 __fastcall validate_key(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int validate_key(char* required_key, char* input_key) {
 return (strcmp(required_key, input_key) == 0);
}

canonical_original_code:
int validate_key(char *required_key, char *input_key) {
 return (strcmp(required_key, input_key) == 0);
}


printall

repo: uttaresh/GPUHashRecoverer

decompiled_code:
int __fastcall printall(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned __int64 v3; // rbp
__int64 v4; // rdi

if ( a2 )
{
v2 = a1;
v3 = a1 + ((unsigned __int64)(a2 - 1) << 6) + 64;
do
{
printf("Pwd as Stored: ");
v4 = v2;
v2 += 64LL;
printpwd(v4);
putchar(10);
}
while ( v2 != v3 );
}
return printf("Num of lines : %d\n", a2);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned __int64 v3; // rbp
__int64 v4; // rdi

if ( a2 )
{
v2 = a1;
v3 = a1 + ((unsigned __int64)(a2 - 1) << 6) + 64;
do
{
printf("Pwd as Stored: ");
v4 = v2;
v2 += 64LL;
printpwd(v4);
putchar(10);
}
while ( v2 != v3 );
}
return printf("Num of lines : %d\n", a2);
}

original_code:
void printall(password *pwd, unsigned int num){
 unsigned int i=0;
 while(i<num) {
  printf("Pwd as Stored: ");
        printpwd(&(pwd[i]));
  printf("\n");
  ++i;
 }
 printf("Num of lines : %d\n",num);
}

canonical_original_code:
void printall(struct password_t *pwd, unsigned int num){
 unsigned int i = 0;
 while(i<num) {
  printf("Pwd as Stored: ");
        printpwd(&(pwd[i]));
  printf("\n");
  ++i;
 }
 printf("Num of lines : %d\n",num);
}

variable_types: struct password_t { char word[56]; unsigned long length; } *

variable_types:
num
unsigned int

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall getMD5(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
unsigned __int64 v4; // r12
__int64 v5; // rax

if ( !a3 )
return 0LL;
v3 = a1;
v4 = a1 + ((unsigned __int64)(unsigned int)(a3 - 1) << 6) + 64;
do
{
md5(v3, a2);
v5 = 0LL;
while ( intTest[v5] == *(_BYTE *)(a2 + v5) )
{
if ( ++v5 == 16 )
{
printf("\n!!!!PASSWORD FOUND!!!!\nPassword is: ");
printpwd(v3);
puts("\n");
return 1LL;
}
}
v3 += 64LL;
}
while ( v3 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp
unsigned __int64 v4; // r12
__int64 v5; // rax

if ( !a3 )
return 0LL;
v3 = a1;
v4 = a1 + ((unsigned __int64)(unsigned int)(a3 - 1) << 6) + 64;
do
{
md5(v3, a2);
v5 = 0LL;
while ( intTest[v5] == *(_BYTE *)(a2 + v5) )
{
if ( ++v5 == 16 )
{
printf("\n!!!!PASSWORD FOUND!!!!\nPassword is: ");
printpwd(v3);
puts("\n");
return 1LL;
}
}
v3 += 64LL;
}
while ( v3 != v4 );
return 0LL;
}

original_code:
int getMD5(password *pwd, word16 *md5Hash, unsigned int num){
 unsigned int i=0;
 while(i<num) {
  md5(&(pwd[i]), (uint8_t*)md5Hash->word);
        int flag = 1;
        unsigned int j=0;
  while(j<16){
   if(intTest[j] != (uint8_t)md5Hash->word[j]){
                flag = 0;
                break;
   }
   ++j;
  }
        if(flag == 1){
            printf("\n!!!!PASSWORD FOUND!!!!\nPassword is: ");
            printpwd(&(pwd[i]));
            printf("\n\n");
            return 1;
        }
  ++i;
 }
 return 0;
}

canonical_original_code:
int getMD5(struct password_t *pwd, struct word16_t *md5Hash, unsigned int num){
 unsigned int i = 0;
 while(i<num) {
  md5(&(pwd[i]), (unsigned char *)md5Hash->word);
        int flag = 1;
        unsigned int j = 0;
  while(j<16){
   if(intTest[j] != (unsigned char)md5Hash->word[j]){
                flag = 0;
                break;
   }
   ++j;
  }
        if(flag == 1){
            printf("\n!!!!PASSWORD FOUND!!!!\nPassword is: ");
            printpwd(&(pwd[i]));
            printf("\n\n");
            return 1;
        }
  ++i;
 }
 return 0;
}

variable_types: flag int

variable_types:
j
unsigned int

user_defined_types: struct password_t { char word[56]; unsigned long length; }


decompiled_code:
int __fastcall hashToUint8(char *a1, __int64 a2)
{
const char *v3; // rbx
char *v4; // rax
char v5; // dl
int result; // eax
_BYTE v7[48]; // [rsp+0h] [rbp-48h] BYREF
char v8[24]; // [rsp+30h] [rbp-18h] BYREF

v3 = v7;
v4 = v7;
do
{
v5 = *a1;
v4[2] = 0;
v4 += 3;
a1 += 2;
*(v4 - 3) = v5;
*(v4 - 2) = *(a1 - 1);
}
while ( v4 != v8 );
do
{
result = sscanf(v3, "%x", a2);
v3 += 3;
++a2;
}
while ( v3 != v8 );
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *a1, __int64 a2)
{
const char *v3; // rbx
char *v4; // rax
char v5; // dl
int result; // eax
_BYTE v7[48]; // [rsp+0h] [rbp-48h] BYREF
char v8[24]; // [rsp+30h] [rbp-18h] BYREF

v3 = v7;
v4 = v7;
do
{
v5 = *a1;
v4[2] = 0;
v4 += 3;
a1 += 2;
*(v4 - 3) = v5;
*(v4 - 2) = *(a1 - 1);
}
while ( v4 != v8 );
do
{
result = sscanf(v3, "%x", a2);
v3 += 3;
++a2;
}
while ( v3 != v8 );
return result;
}

original_code:
void hashToUint8(char *charHash, uint8_t intHash[]){
    char tempChar[16][3];
    int j=0;
    while(j<16){
        tempChar[j][0] = charHash[j*2];
        tempChar[j][1] = charHash[j*2+1];
        tempChar[j][2] = '\0';
        ++j;
    }
    j = 0;
    while(j<16){
        sscanf(tempChar[j], "%x", (unsigned int*)(&(intHash[j])));
        ++j;
    }
}

canonical_original_code:
void hashToUint8(char *charHash, unsigned char intHash[]){
    char tempChar[16][3];
    int j = 0;
    while(j<16){
        tempChar[j][0] = charHash[j*2];
        tempChar[j][1] = charHash[j*2+1];
        tempChar[j][2] = '\0';
        ++j;
    }
    j = 0;
    while(j<16){
        sscanf(tempChar[j], "%x", (unsigned int *)(&(intHash[j])));
        ++j;
    }
}

variable_types:
charHash
char *

variable_types:
intHash
unsigned char []

variable_types:
tempChar
char [16][3]

variable_types: j int