decompiled_code:
int timer_malloc()
{
char *v0; // rbx
char *v1; // rbp
void *v2; // rdi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v7[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v8[24]; // [rsp+138A0h] [rbp-18h] BYREF

v0 = v7;
gettimeofday(&v5, 0LL);
v1 = v7;
do
{
v1 += 8;
*((_QWORD *)v1 - 1) = malloc(0x40uLL);
}
while ( v1 != v8 );
do
{
v2 = *(void **)v0;
v0 += 8;
free(v2);
}
while ( v0 != v8 );
gettimeofday(&tv, 0LL);
v3 = comp_time(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(_bss_start, "Time taken for mallocs = %f msec\n", v3 / 1000.0);
}

canonical_decompiled_code:
int func7()
{
char *v0; // rbx
char *v1; // rbp
void *v2; // rdi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v7[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v8[24]; // [rsp+138A0h] [rbp-18h] BYREF

v0 = v7;
gettimeofday(&v5, 0LL);
v1 = v7;
do
{
v1 += 8;
*((_QWORD *)v1 - 1) = malloc(0x40uLL);
}
while ( v1 != v8 );
do
{
v2 = *(void **)v0;
v0 += 8;
free(v2);
}
while ( v0 != v8 );
gettimeofday(&tv, 0LL);
v3 = func9(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(_bss_start, "Time taken for mallocs = %f msec\n", v3 / 1000.0);
}

original_code:
void timer_malloc() {
 char* mem_list[10000];
    struct timeval time_start, time_end;
    int j,i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void timer_malloc() {
 char *mem_list[10000];
    struct timeval time_start; struct timeval time_end;
    int j; int i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}

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

variable_types: i int


repo: harlanji/university-coursework

decompiled_code:
int timer_mm()
{
int v0; // ebx
int i; // ebx
int v2; // esi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+20h] [rbp-28h] BYREF
int v8; // [rsp+2Ch] [rbp-1Ch]

gettimeofday(&v5, 0LL);
if ( (unsigned int)mm_init(&v7, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
mm_get(&v7);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
{
v2 = i * v8;
mm_put(&v7, v7 + v2);
}
mm_release(&v7);
gettimeofday(&tv, 0LL);
v3 = comp_time(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(_bss_start, "Time taken for MM = %f msec\n", v3 / 1000.0);
}

canonical_decompiled_code:
int func8()
{
int v0; // ebx
int i; // ebx
int v2; // esi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+20h] [rbp-28h] BYREF
int v8; // [rsp+2Ch] [rbp-1Ch]

gettimeofday(&v5, 0LL);
if ( (unsigned int)func10(&v7, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
func11(&v7);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
{
v2 = i * v8;
func12(&v7, v7 + v2);
}
func13(&v7);
gettimeofday(&tv, 0LL);
v3 = func9(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(_bss_start, "Time taken for MM = %f msec\n", v3 / 1000.0);
}

original_code:
void timer_mm() {
 struct timeval time_start, time_end;
 int j,i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void*) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n",
   comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void timer_mm() {
 struct timeval time_start; struct timeval time_end;
 int j; int i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 struct mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void *) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n",
   comp_time (time_start, time_end)/1000.0);
}

variable_types: j int

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; }

return_type: void

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


original_code:
double comp_time (struct timeval times, struct timeval timee)
{
  double elap = 0.0;
  if (timee.tv_sec > times.tv_sec) {
    elap += (((double)(timee.tv_sec - times.tv_sec -1))*1000000.0);
    elap += timee.tv_usec + (1000000-times.tv_usec);
  }
  else {
    elap = timee.tv_usec - times.tv_usec;
  }
  return ((unsigned long)(elap));
}

canonical_original_code:
double comp_time(struct timeval times, struct timeval timee)
{
  double elap = 0.0;
  if (timee.tv_sec > times.tv_sec) {
    elap += (((double)(timee.tv_sec - times.tv_sec -1))*1000000.0);
    elap += timee.tv_usec + (1000000-times.tv_usec);
  }
  else {
    elap = timee.tv_usec - times.tv_usec;
  }
  return ((unsigned long)(elap));
}

variable_types:
timee
struct timeval

variable_types: elap double

return_type: double


decompiled_code:
__int64 __fastcall mm_init(__int64 a1, unsigned int a2, unsigned int a3)
{
void *v4; // rax

v4 = malloc((int)(a3 * a2));
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
*(_QWORD *)a1 = v4;
*(_QWORD *)(a1 + 16) = calloc((int)a2, 1uLL);
*(_DWORD *)(a1 + 24) = -1;
printf("%i chunks of %i bytes have been allocated.\n", a2, a3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2, unsigned int a3)
{
void *v4; // rax

v4 = malloc((int)(a3 * a2));
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
*(_QWORD *)a1 = v4;
*(_QWORD *)(a1 + 16) = calloc((int)a2, 1uLL);
*(_DWORD *)(a1 + 24) = -1;
printf("%i chunks of %i bytes have been allocated.\n", a2, a3);
return 1LL;
}

original_code:
int mm_init (mm_t *MM, int hm, int sz) {
 if ((MM->blocks = malloc(hm * sz)) == -1) {
  fprintf(stderr, "Failed to allocate memory.");
  return -1;
 }
 MM->total_chunks = hm;
 MM->size = sz;
 if((MM->allocated = (char*)malloc(hm)) == -1 ) {
  fprintf(stderr, "Failed to allocate array to keep track of allocated memory.");
  free(MM->blocks);
  return -1;
 }
 memset(MM->allocated, 0, hm);
 MM->last_allocated = -1;
 printf("%i chunks of %i bytes have been allocated.\n", hm, sz);
 return 1;
}

canonical_original_code:
int mm_init(struct mm_t *MM, int hm, int sz) {
 if ((MM->blocks = malloc(hm * sz)) == -1) {
  fprintf(stderr, "Failed to allocate memory.");
  return -1;
 }
 MM->total_chunks = hm;
 MM->size = sz;
 if((MM->allocated = (char *)malloc(hm)) == -1 ) {
  fprintf(stderr, "Failed to allocate array to keep track of allocated memory.");
  free(MM->blocks);
  return -1;
 }
 memset(MM->allocated, 0, hm);
 MM->last_allocated = -1;
 printf("%i chunks of %i bytes have been allocated.\n", hm, sz);
 return 1;
}

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; } *

variable_types: hm int

variable_types: sz int

return_type: int


decompiled_code:
__int64 __fastcall mm_get(__int64 a1)
{
int v1; // esi
int v3; // edi
int v4; // ecx
int v5; // edi
int v6; // edx
_BYTE *v7; // rax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 24);
if ( v1 <= 0 )
{
LABEL_7:
fwrite("No more memory chunks are available!", 1uLL, 0x24uLL, _bss_start);
result = -1LL;
}
else
{
v4 = v3 + 1;
v5 = v1 + v3;
while ( 1 )
{
v6 = v4 % v1;
v7 = (_BYTE *)(*(_QWORD *)(a1 + 16) + v4 % v1);
if ( !*v7 )
break;
if ( v4 == v5 )
goto LABEL_7;
++v4;
}
*v7 = 1;
*(_DWORD *)(a1 + 24) = v6;
result = *(_QWORD *)a1 + *(_DWORD *)(a1 + 12) * v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // esi
int v3; // edi
int v4; // ecx
int v5; // edi
int v6; // edx
_BYTE *v7; // rax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 24);
if ( v1 <= 0 )
{
LABEL_7:
fwrite("No more memory chunks are available!", 1uLL, 0x24uLL, _bss_start);
result = -1LL;
}
else
{
v4 = v3 + 1;
v5 = v1 + v3;
while ( 1 )
{
v6 = v4 % v1;
v7 = (_BYTE *)(*(_QWORD *)(a1 + 16) + v4 % v1);
if ( !*v7 )
break;
if ( v4 == v5 )
goto LABEL_7;
++v4;
}
*v7 = 1;
*(_DWORD *)(a1 + 24) = v6;
result = *(_QWORD *)a1 + *(_DWORD *)(a1 + 12) * v6;
}
return result;
}

original_code:
void* mm_get (mm_t *MM) {
 void* chunk;
 int length = MM->total_chunks;
 int base = MM->last_allocated + 1;
 int i;
 for (i = 0; i < length; i++) {
  int slot = (base + i) % length;
  if (MM->allocated[ slot ] == 0) {
   MM->allocated[ slot ] = 1;
   MM->last_allocated = slot;
   chunk = MM->blocks + slot * MM->size;
   return chunk;
  }
 }
 fprintf(stderr, "No more memory chunks are available!");
 return -1;
}

canonical_original_code:
void *mm_get(struct mm_t *MM) {
 void *chunk;
 int length = MM->total_chunks;
 int base = MM->last_allocated + 1;
 int i;
 for (i = 0; i < length; i++) {
  int slot = (base + i) % length;
  if (MM->allocated[ slot ] == 0) {
   MM->allocated[ slot ] = 1;
   MM->last_allocated = slot;
   chunk = MM->blocks + slot * MM->size;
   return chunk;
  }
 }
 fprintf(stderr, "No more memory chunks are available!");
 return -1;
}

variable_types:
chunk
void *

variable_types: length int

variable_types: base int

variable_types: slot int

return_type: void *

user_defined_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; }


original_code:
void mm_put (mm_t *MM, void *chunk) {
 int i;
 int index = ((unsigned int)chunk - (unsigned int)MM->blocks) / MM->size;
 MM->allocated[index] = 0;
 memset(chunk, 0, MM->size);
}

canonical_original_code:
void mm_put(struct mm_t *MM, void *chunk) {
 int i;
 int index = ((unsigned int)chunk - (unsigned int)MM->blocks) / MM->size;
 MM->allocated[index] = 0;
 memset(chunk, 0, MM->size);
}

variable_types: index int


decompiled_code:
void __fastcall mm_release(void **a1)
{
free(*a1);
free(a1[2]);
*(_OWORD *)a1 = 0LL;
*((_OWORD *)a1 + 1) = 0LL;
}

canonical_decompiled_code:
void __fastcall func13(void **a1)
{
free(*a1);
free(a1[2]);
*(_OWORD *)a1 = 0LL;
*((_OWORD *)a1 + 1) = 0LL;
}

original_code:
void mm_release (mm_t *MM) {
 free(MM->blocks);
 free(MM->allocated);
 memset(MM, 0, sizeof(mm_t));
}

canonical_original_code:
void mm_release(struct mm_t *MM) {
 free(MM->blocks);
 free(MM->allocated);
 memset(MM, 0, sizeof(mm_t));
}


decompiled_code:
int timer_example()
{
unsigned int v0; // ebx
__int64 v1; // rsi
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v0 = 0;
gettimeofday(&v4, 0LL);
do
{
v1 = v0++;
printf("%i ", v1);
}
while ( v0 != 10 );
gettimeofday(&tv, 0LL);
v2 = comp_time(v4.tv_sec, v4.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(_bss_start, "Time taken = %f msec\n", v2 / 1000.0);
}

canonical_decompiled_code:
int func14()
{
unsigned int v0; // ebx
__int64 v1; // rsi
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v0 = 0;
gettimeofday(&v4, 0LL);
do
{
v1 = v0++;
printf("%i ", v1);
}
while ( v0 != 10 );
gettimeofday(&tv, 0LL);
v2 = func9(v4.tv_sec, v4.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(_bss_start, "Time taken = %f msec\n", v2 / 1000.0);
}

original_code:
void timer_example ()
{
    struct timeval time_start, time_end;
    int j;
    j = gettimeofday (&time_start, (void *)((void *)0));
    int i;
 for (i = 0; i < 10; i++){
  printf("%i ", i);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void timer_example()
{
    struct timeval time_start; struct timeval time_end;
    int j;
    j = gettimeofday (&time_start, (void *)((void *)0));
    int i;
 for (i = 0; i < 10; i++){
  printf("%i ", i);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}


main

canonical_name: main

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

if ( argc == 2 )
{
result = atoi(argv[1]);
v4 = result;
if ( result > 0 )
{
do
{
((void (*)(void))timer_malloc)();
timer_mm();
result = puts("\n");
--v4;
}
while ( v4 );
}
}
else
{
timer_malloc(argc, argv, envp);
timer_mm();
result = puts("\n");
}
return result;
}

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

if ( argc == 2 )
{
result = atoi(argv[1]);
v4 = result;
if ( result > 0 )
{
do
{
((void (*)(void))timer_malloc)();
func8();
result = puts("\n");
--v4;
}
while ( v4 );
}
}
else
{
func7(argc, argv, envp);
func8();
result = puts("\n");
}
return result;
}

original_code:
void main(int argc, char* argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--) {
  timer_malloc();
  timer_mm();
  printf("\n\n");
 }
}

canonical_original_code:
void main(int argc, char *argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--) {
  timer_malloc();
  timer_mm();
  printf("\n\n");
 }
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall calc_blocks(int a1, __int64 a2, int a3, int a4)
{
int v6; // ebx
double v7; // xmm0_8
__m128d v8; // xmm3
__m128d v9; // xmm1
unsigned int v10; // er12
unsigned int v11; // er14
unsigned int v12; // er13
unsigned int v13; // er15
int result; // eax
unsigned int v15; // ebx
int v16; // ebp
unsigned int v17; // eax
__int64 v18; // rdx
__int64 v19; // r8
__int64 v20; // rdx
__int64 v21; // rcx
int v22; // [rsp+0h] [rbp-40h]

v6 = a3 + a4;
v7 = (double)a3 / (double)(int)a2;
if ( fabs((double)a3 / (double)(int)a2) < 4.503599627370496e15 )
{
v8.m128d_f64[0] = (double)a3 / (double)(int)a2;
v9.m128d_f64[0] = (double)(int)v7;
*(_QWORD *)&v7 = COERCE_UNSIGNED_INT64(v9.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v8, v9) & 0x3FF0000000000000LL)) | *(_QWORD *)&v7 & 0x8000000000000000LL;
}
v10 = (int)v7;
v22 = v6 / 10;
if ( a3 / (int)v7 > a1 )
{
puts("error: impossible configuration of max blocks/threads and the input.");
a2 = (unsigned int)a2;
}
v11 = a3 - 1;
v12 = -a4;
v13 = 0;
result = printf("nt=%i, bw=%i, bh=%i, nd=%i\n", a2, v10, 10LL, (unsigned int)v22);
if ( v6 > 9 )
{
do
{
v15 = max(v12, 0);
v16 = min(v13, v11);
v17 = max(1u, v16 - v15);
for ( result = printf("sx=%i, sf=%i, nb=%i, nb=%i\n", v15, v18, v17, v19);
v16 >= (int)v15;
result = printf("%i: [%i, %i]\n", v13, v20, v21) )
{
v20 = 10 * (v13 + v15);
v21 = v10 * v15;
v15 = v21 + 1;
}
++v13;
++v12;
}
while ( v22 > (int)v13 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, __int64 a2, int a3, int a4)
{
int v6; // ebx
double v7; // xmm0_8
__m128d v8; // xmm3
__m128d v9; // xmm1
unsigned int v10; // er12
unsigned int v11; // er14
unsigned int v12; // er13
unsigned int v13; // er15
int result; // eax
unsigned int v15; // ebx
int v16; // ebp
unsigned int v17; // eax
__int64 v18; // rdx
__int64 v19; // r8
__int64 v20; // rdx
__int64 v21; // rcx
int v22; // [rsp+0h] [rbp-40h]

v6 = a3 + a4;
v7 = (double)a3 / (double)(int)a2;
if ( fabs((double)a3 / (double)(int)a2) < 4.503599627370496e15 )
{
v8.m128d_f64[0] = (double)a3 / (double)(int)a2;
v9.m128d_f64[0] = (double)(int)v7;
*(_QWORD *)&v7 = COERCE_UNSIGNED_INT64(v9.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v8, v9) & 0x3FF0000000000000LL)) | *(_QWORD *)&v7 & 0x8000000000000000LL;
}
v10 = (int)v7;
v22 = v6 / 10;
if ( a3 / (int)v7 > a1 )
{
puts("error: impossible configuration of max blocks/threads and the input.");
a2 = (unsigned int)a2;
}
v11 = a3 - 1;
v12 = -a4;
v13 = 0;
result = printf("nt=%i, bw=%i, bh=%i, nd=%i\n", a2, v10, 10LL, (unsigned int)v22);
if ( v6 > 9 )
{
do
{
v15 = func7(v12, 0);
v16 = func8(v13, v11);
v17 = func7(1u, v16 - v15);
for ( result = printf("sx=%i, sf=%i, nb=%i, nb=%i\n", v15, v18, v17, v19);
v16 >= (int)v15;
result = printf("%i: [%i, %i]\n", v13, v20, v21) )
{
v20 = 10 * (v13 + v15);
v21 = v10 * v15;
v15 = v21 + 1;
}
++v13;
++v12;
}
while ( v22 > (int)v13 );
}
return result;
}

original_code:
void calc_blocks(int maxb, int maxt, int w, int h) {
 int d = w + h;
 int nt, bh, bw, nd;
 nt = maxt;
 bw = ceil((double)w / (double)nt);
 bh = 10;
 nd = d / bh;
 if(w/bw > maxb) {
  printf("error: impossible configuration of max blocks/threads and the input.\n");
 }
 printf("nt=%i, bw=%i, bh=%i, nd=%i\n", nt, bw, bh, nd);
 int r;
 for(r = 0; r < nd; r++) {
  int sx = max(r - h, 0);
  int fx = min(r, w - 1);
  int nb = max(1, fx - sx);
  printf("sx=%i, sf=%i, nb=%i, nb=%i\n", sx, fx, nb);
  int x;
  for(x = sx; x <= fx; x++) {
   int y = x + r;
   x *= bw;
   y *= bh;
   printf("%i: [%i, %i]\n", r, y, x);
  }
 }
}

canonical_original_code:
void calc_blocks(int maxb, int maxt, int w, int h) {
 int d = w + h;
 int nt; int bh; int bw; int nd;
 nt = maxt;
 bw = ceil((double)w / (double)nt);
 bh = 10;
 nd = d / bh;
 if(w/bw > maxb) {
  printf("error: impossible configuration of max blocks/threads and the input.\n");
 }
 printf("nt=%i, bw=%i, bh=%i, nd=%i\n", nt, bw, bh, nd);
 int r;
 for(r = 0; r < nd; r++) {
  int sx = max(r - h, 0);
  int fx = min(r, w - 1);
  int nb = max(1, fx - sx);
  printf("sx=%i, sf=%i, nb=%i, nb=%i\n", sx, fx, nb);
  int x;
  for(x = sx; x <= fx; x++) {
   int y = x + r;
   x *= bw;
   y *= bh;
   printf("%i: [%i, %i]\n", r, y, x);
  }
 }
}

variable_types: maxb int

variable_types: maxt int

variable_types: w int

variable_types: h int

variable_types: d int

variable_types: nt int

variable_types: bh int

variable_types: bw int

variable_types: nd int

variable_types: r int

variable_types: sx int

variable_types: fx int

variable_types: nb int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall test_calc(int a1, int a2, int a3)
{
__int64 result; // rax

if ( a1 * a2 > a3 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2, int a3)
{
__int64 result; // rax

if ( a1 * a2 > a3 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int test_calc(int maxb, int maxt, int w, int h) {
 if(maxt*maxb > w) {
  return -1;
 }
 int bw = maxt;
 int bh = 10;
 int nby = ceil( (double)h / (double)bh );
 int nbx = ceil( (double)w / (double)bw );
 int nd = nbx + nby - 1;
 int d;
 for(d = 0; d < nd; d++) {
 }
}

variable_types: nby int

variable_types: nbx int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
calc_blocks(5LL, 2LL, 60LL, 80LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9(5LL, 2LL, 60LL, 80LL);
return 0;
}

original_code:
int main() {
 calc_blocks(5, 2, 60, 80);
}


max

decompiled_code:
__int64 __fastcall max(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int a, int b) {
    if(a > b) return a;
    else return b;
}

variable_types: a int

variable_types: b int


min

decompiled_code:
__int64 __fastcall min(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
int min(int a, int b) {
    if(a < b) return a;
    else return b;
}


merge

original_code:
void merge(const int* a, const int* b, const unsigned long n, int* out) {
 unsigned long cura=0, curb=0, curout=0;
 while( cura < n && curb < n ) {
  if( a[ cura ] < b[ curb ] ) {
   out[ curout ] = a[ cura ];
   cura++;
  } else {
   out[ curout ] = b[ curb ];
   curb++;
  }
  curout++;
 }
 while( curb < n ) {
  out[ curout ] = b[ curb ];
  curb++; curout++;
 }
 while( cura < n ) {
  out[ curout ] = a[ cura ];
  cura++; curout++;
 }
}

canonical_original_code:
void merge(int *a, int *b, unsigned long n, int *out) {
 unsigned long cura = 0; unsigned long curb = 0; unsigned long curout = 0;
 while( cura < n && curb < n ) {
  if( a[ cura ] < b[ curb ] ) {
   out[ curout ] = a[ cura ];
   cura++;
  } else {
   out[ curout ] = b[ curb ];
   curb++;
  }
  curout++;
 }
 while( curb < n ) {
  out[ curout ] = b[ curb ];
  curb++; curout++;
 }
 while( cura < n ) {
  out[ curout ] = a[ cura ];
  cura++; curout++;
 }
}

variable_types:
a
int *

variable_types:
b
int *

variable_types:
n
unsigned long

variable_types:
out
int *

variable_types:
cura
unsigned long

variable_types:
curb
unsigned long

variable_types:
curout
unsigned long


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

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

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

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double get_timeofday() {
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_sec+(tv.tv_usec/1000000.0);
}

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


original_code:
void merge_helper(int *input, unsigned long left, unsigned long right, int *scratch)
{
    if(right == left + 1)
    {
        return;
    }
    else
    {
        unsigned long i = 0;
        unsigned long length = right - left;
        unsigned long midpoint_distance = length/2;
        unsigned long l = left, r = left + midpoint_distance;
        merge_helper(input, left, left + midpoint_distance, scratch);
        merge_helper(input, left + midpoint_distance, right, scratch);
        for(i = 0; i < length; i++)
        {
            if(l < left + midpoint_distance &&
                    (r == right || min(input[l], input[r]) == input[l]))
            {
                scratch[i] = input[l];
                l++;
            }
            else
            {
                scratch[i] = input[r];
                r++;
            }
        }
        for(i = left; i < right; i++)
        {
            input[i] = scratch[i - left];
        }
    }
}

canonical_original_code:
void merge_helper(int *input, unsigned long left, unsigned long right, int *scratch)
{
    if(right == left + 1)
    {
        return;
    }
    else
    {
        unsigned long i = 0;
        unsigned long length = right - left;
        unsigned long midpoint_distance = length/2;
        unsigned long l = left; unsigned long r = left + midpoint_distance;
        merge_helper(input, left, left + midpoint_distance, scratch);
        merge_helper(input, left + midpoint_distance, right, scratch);
        for(i = 0; i < length; i++)
        {
            if(l < left + midpoint_distance &&
                    (r == right || min(input[l], input[r]) == input[l]))
            {
                scratch[i] = input[l];
                l++;
            }
            else
            {
                scratch[i] = input[r];
                r++;
            }
        }
        for(i = left; i < right; i++)
        {
            input[i] = scratch[i - left];
        }
    }
}

variable_types:
input
int *

variable_types:
left
unsigned long

variable_types:
right
unsigned long

variable_types:
scratch
int *

variable_types:
i
unsigned long

variable_types:
length
unsigned long

variable_types:
l
unsigned long

variable_types:
r
unsigned long


mergesort

decompiled_code:
__int64 __fastcall mergesort(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax
void *v3; // rbp

v2 = malloc(4 * a2);
if ( !v2 )
return 0LL;
v3 = v2;
merge_helper(a1, 0LL, a2, (__int64)v2);
free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax
void *v3; // rbp

v2 = malloc(4 * a2);
if ( !v2 )
return 0LL;
v3 = v2;
func11(a1, 0LL, a2, (__int64)v2);
free(v3);
return 1LL;
}

original_code:
int mergesort(int *input, unsigned long size)
{
    int *scratch = (int *)malloc(size * sizeof(int));
    if(scratch != ((void *)0))
    {
        merge_helper(input, 0, size, scratch);
        free(scratch);
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types:
size
unsigned long


min

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

result = a2;
if ( a1 <= a2 )
result = a1;
return result;
}

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

result = a2;
if ( a1 <= a2 )
result = a1;
return result;
}

original_code:
unsigned long min(unsigned long x, unsigned long y)
{
    if(x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

variable_types:
x
unsigned long

variable_types:
y
unsigned long

return_type: unsigned long


decompiled_code:
__sighandler_t handle_complete_messages()
{
__int64 *v0; // rbx
void (*v1)(int); // r12
int *v2; // rdi
char *v3; // rbp

v0 = g_messages;
v1 = signal(14, (__sighandler_t)((char *)get_packet + 1));
do
{
while ( *((_DWORD *)v0 + 2) == -1 || *((_DWORD *)v0 + 1) != *(_DWORD *)v0 )
{
v0 += 12;
if ( v0 == &g_messages[180] )
return signal(14, v1);
}
v2 = (int *)v0;
v0 += 12;
v3 = assemble_message(v2);
printf("GOT IT: msg_id=%d, message=%s\n", *((unsigned int *)v0 - 22), v3);
free(v3);
*((_DWORD *)v0 - 22) = -1;
}
while ( v0 != &g_messages[180] );
return signal(14, v1);
}

canonical_decompiled_code:
__sighandler_t func1()
{
__int64 *v0; // rbx
void (*v1)(int); // r12
int *v2; // rdi
char *v3; // rbp

v0 = g_messages;
v1 = signal(14, (__sighandler_t)((char *)get_packet + 1));
do
{
while ( *((_DWORD *)v0 + 2) == -1 || *((_DWORD *)v0 + 1) != *(_DWORD *)v0 )
{
v0 += 12;
if ( v0 == &g_messages[180] )
return signal(14, v1);
}
v2 = (int *)v0;
v0 += 12;
v3 = assemble_message(v2);
printf("GOT IT: msg_id=%d, message=%s\n", *((unsigned int *)v0 - 22), v3);
free(v3);
*((_DWORD *)v0 - 22) = -1;
}
while ( v0 != &g_messages[180] );
return signal(14, v1);
}

original_code:
void handle_complete_messages() {
 void* old_handler = signal(14, ((__sighandler_t) 1));
 int i;
 for( i = 0; i < 15; i++ ) {
  if( g_messages[ i ].id == -1 ) {
   continue;
  }
  if( g_messages[ i ].how_many_arrived == g_messages[ i ].num_packets ) {
   char* msg = assemble_message( &g_messages[ i ] );
   printf( "GOT IT: msg_id=%d, message=%s\n", g_messages[ i ].id, msg );
   free( msg );
   g_messages[ i ].id = -1;
  }
 }
 signal(14, old_handler);
}

canonical_original_code:
void handle_complete_messages() {
 void *old_handler = signal(14, ((__sighandler_t) 1));
 int i;
 for( i = 0; i < 15; i++ ) {
  if( g_messages[ i ].id == -1 ) {
   continue;
  }
  if( g_messages[ i ].how_many_arrived == g_messages[ i ].num_packets ) {
   char *msg = assemble_message( &g_messages[ i ] );
   printf( "GOT IT: msg_id=%d, message=%s\n", g_messages[ i ].id, msg );
   free( msg );
   g_messages[ i ].id = -1;
  }
 }
 signal(14, old_handler);
}

variable_types: i int

variable_types:
msg
char *


original_code:
void packet_handler(int sig)
{
 void* old_handler = signal(sig, ((__sighandler_t) 1));
  packet_t pkt = get_packet();
  if(pkt.msg_id == -1) {
   g_has_more = 0;
  }
  g_messages[ pkt.msg_id ].id = pkt.msg_id;
  g_messages[ pkt.msg_id ].num_packets = pkt.how_many;
  g_messages[ pkt.msg_id ].how_many_arrived++;
 void* memory = mm_get(&g_MM);
 memcpy(memory, pkt.data, 56);
 g_messages[ pkt.msg_id ].data[ pkt.which ] = memory;
 signal(sig, old_handler);
}

canonical_original_code:
void packet_handler(int sig)
{
 void *old_handler = signal(sig, ((__sighandler_t) 1));
  struct packet_t pkt = get_packet();
  if(pkt.msg_id == -1) {
   g_has_more = 0;
  }
  g_messages[ pkt.msg_id ].id = pkt.msg_id;
  g_messages[ pkt.msg_id ].num_packets = pkt.how_many;
  g_messages[ pkt.msg_id ].how_many_arrived++;
 void *memory = mm_get(&g_MM);
 memcpy(memory, pkt.data, 56);
 g_messages[ pkt.msg_id ].data[ pkt.which ] = memory;
 signal(sig, old_handler);
}

variable_types: sig int

variable_types: struct packet_t { int how_many; int which; int msg_id; char data[56]; }

variable_types:
memory
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rax
void (*v4)(int); // rbp
struct itimerval v6; // [rsp+0h] [rbp-28h] BYREF

v3 = (unsigned int)((_DWORD)g_messages + 8);
do
{
*(_DWORD *)v3 = -1;
v3 += 96LL;
}
while ( (__int64 *)v3 != &g_messages[181] );
if ( (unsigned int)mm_init(&g_MM, 100LL, 64LL) == -1 )
fwrite("failed to initialize mm for packets", 1uLL, 0x23uLL, stderr);
v6.it_interval.tv_sec = 0LL;
v4 = signal(14, packet_handler);
v6.it_interval.tv_usec = 50000LL;
v6.it_value.tv_sec = 0LL;
v6.it_value.tv_usec = 100LL;
setitimer(ITIMER_REAL, &v6, 0LL);
while ( g_has_more )
{
handle_complete_messages();
pause();
}
v6.it_interval.tv_sec = 0LL;
v6.it_interval.tv_usec = 0LL;
setitimer(ITIMER_REAL, &v6, 0LL);
signal(14, v4);
mm_release(&g_MM);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rax
void (*v4)(int); // rbp
struct itimerval v6; // [rsp+0h] [rbp-28h] BYREF

v3 = (unsigned int)((_DWORD)g_messages + 8);
do
{
*(_DWORD *)v3 = -1;
v3 += 96LL;
}
while ( (__int64 *)v3 != &g_messages[181] );
if ( (unsigned int)mm_init(&g_MM, 100LL, 64LL) == -1 )
fwrite("failed to initialize mm for packets", 1uLL, 0x23uLL, stderr);
v6.it_interval.tv_sec = 0LL;
v4 = signal(14, packet_handler);
v6.it_interval.tv_usec = 50000LL;
v6.it_value.tv_sec = 0LL;
v6.it_value.tv_usec = 100LL;
setitimer(ITIMER_REAL, &v6, 0LL);
while ( g_has_more )
{
func1();
pause();
}
v6.it_interval.tv_sec = 0LL;
v6.it_interval.tv_usec = 0LL;
setitimer(ITIMER_REAL, &v6, 0LL);
signal(14, v4);
mm_release(&g_MM);
return 0;
}

original_code:
int main (int argc, char **argv)
{
 int i;
 for( i = 0; i < 15; i++ ) {
  g_messages[ i ].id = -1;
 }
 if(mm_init (&g_MM, 100, 64) == -1){
  fprintf(stderr, "failed to initialize mm for packets");
 }
 void* old_handler = signal(14, packet_handler);
 struct itimerval itv;
 itv.it_interval.tv_sec = 0;
 itv.it_interval.tv_usec = 50000;
 itv.it_value.tv_sec = 0;
 itv.it_value.tv_usec = 100;
 setitimer( ITIMER_REAL, &itv, ((void *)0) );
 while( g_has_more ) {
  handle_complete_messages();
  pause();
 }
    itv.it_interval.tv_sec = itv.it_interval.tv_usec = 0;
    setitimer( ITIMER_REAL, &itv, ((void *)0) );
 signal(14, old_handler);
 mm_release(&g_MM);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 for( i = 0; i < 15; i++ ) {
  g_messages[ i ].id = -1;
 }
 if(mm_init (&g_MM, 100, 64) == -1){
  fprintf(stderr, "failed to initialize mm for packets");
 }
 void *old_handler = signal(14, packet_handler);
 struct itimerval itv;
 itv.it_interval.tv_sec = 0;
 itv.it_interval.tv_usec = 50000;
 itv.it_value.tv_sec = 0;
 itv.it_value.tv_usec = 100;
 setitimer( ITIMER_REAL, &itv, ((void *)0) );
 while( g_has_more ) {
  handle_complete_messages();
  pause();
 }
    itv.it_interval.tv_sec = itv.it_interval.tv_usec = 0;
    setitimer( ITIMER_REAL, &itv, ((void *)0) );
 signal(14, old_handler);
 mm_release(&g_MM);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
int main_mm()
{
int v0; // ebx
int i; // ebx
int v2; // esi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+20h] [rbp-28h] BYREF
int v8; // [rsp+2Ch] [rbp-1Ch]

gettimeofday(&v5, 0LL);
if ( (unsigned int)mm_init(&v7, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
mm_get(&v7);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
{
v2 = i * v8;
mm_put(&v7, v7 + v2);
}
mm_release(&v7);
gettimeofday(&tv, 0LL);
v3 = comp_time(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(stderr, "Time taken for MM = %f msec\n\n", v3 / 1000.0);
}

canonical_decompiled_code:
int func7()
{
int v0; // ebx
int i; // ebx
int v2; // esi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-48h] BYREF
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+20h] [rbp-28h] BYREF
int v8; // [rsp+2Ch] [rbp-1Ch]

gettimeofday(&v5, 0LL);
if ( (unsigned int)func9(&v7, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
func10(&v7);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
{
v2 = i * v8;
func11(&v7, v7 + v2);
}
func12(&v7);
gettimeofday(&tv, 0LL);
v3 = func8(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(stderr, "Time taken for MM = %f msec\n\n", v3 / 1000.0);
}

original_code:
void main_mm() {
 struct timeval time_start, time_end;
 int j,i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void*) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n\n",
   comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void main_mm() {
 struct timeval time_start; struct timeval time_end;
 int j; int i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 struct mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void *) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n\n",
   comp_time (time_start, time_end)/1000.0);
}

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

variable_types: j int

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; }


original_code:
double comp_time (struct timeval times, struct timeval timee)
{
  double elap = 0.0;
  if (timee.tv_sec > times.tv_sec) {
    elap += (((double)(timee.tv_sec - times.tv_sec -1))*1000000.0);
    elap += timee.tv_usec + (1000000-times.tv_usec);
  }
  else {
    elap = timee.tv_usec - times.tv_usec;
  }
  return ((unsigned long)(elap));
}

variable_types:
timee
struct timeval

variable_types: elap double


canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, unsigned int a3)
{
void *v4; // rax

v4 = malloc((int)(a3 * a2));
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
*(_QWORD *)a1 = v4;
*(_QWORD *)(a1 + 16) = calloc((int)a2, 1uLL);
*(_DWORD *)(a1 + 24) = -1;
printf("%i chunks of %i bytes have been allocated.\n", a2, a3);
return 1LL;
}

original_code:
int mm_init (mm_t *MM, int hm, int sz) {
 if ((MM->blocks = malloc(hm * sz)) == -1) {
  fprintf(stderr, "Failed to allocate memory.");
  return -1;
 }
 MM->total_chunks = hm;
 MM->size = sz;
 if((MM->allocated = (char*)malloc(hm)) == -1 ) {
  fprintf(stderr, "Failed to allocate array to keep track of allocated memory.");
  free(MM->blocks);
  return -1;
 }
 memset(MM->allocated, 0, hm);
 MM->last_allocated = -1;
 printf("%i chunks of %i bytes have been allocated.\n", hm, sz);
 return 1;
}

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; } *

variable_types: hm int

variable_types: sz int


decompiled_code:
__int64 __fastcall mm_get(__int64 a1)
{
int v1; // esi
int v3; // edi
int v4; // ecx
int v5; // edi
int v6; // edx
_BYTE *v7; // rax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 24);
if ( v1 <= 0 )
{
LABEL_7:
fwrite("No more memory chunks are available!", 1uLL, 0x24uLL, stderr);
result = -1LL;
}
else
{
v4 = v3 + 1;
v5 = v1 + v3;
while ( 1 )
{
v6 = v4 % v1;
v7 = (_BYTE *)(*(_QWORD *)(a1 + 16) + v4 % v1);
if ( !*v7 )
break;
if ( v4 == v5 )
goto LABEL_7;
++v4;
}
*v7 = 1;
*(_DWORD *)(a1 + 24) = v6;
result = *(_QWORD *)a1 + *(_DWORD *)(a1 + 12) * v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // esi
int v3; // edi
int v4; // ecx
int v5; // edi
int v6; // edx
_BYTE *v7; // rax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 24);
if ( v1 <= 0 )
{
LABEL_7:
fwrite("No more memory chunks are available!", 1uLL, 0x24uLL, stderr);
result = -1LL;
}
else
{
v4 = v3 + 1;
v5 = v1 + v3;
while ( 1 )
{
v6 = v4 % v1;
v7 = (_BYTE *)(*(_QWORD *)(a1 + 16) + v4 % v1);
if ( !*v7 )
break;
if ( v4 == v5 )
goto LABEL_7;
++v4;
}
*v7 = 1;
*(_DWORD *)(a1 + 24) = v6;
result = *(_QWORD *)a1 + *(_DWORD *)(a1 + 12) * v6;
}
return result;
}

original_code:
void* mm_get (mm_t *MM) {
 void* chunk;
 int length = MM->total_chunks;
 int base = MM->last_allocated + 1;
 int i;
 for (i = 0; i < length; i++) {
  int slot = (base + i) % length;
  if (MM->allocated[ slot ] == 0) {
   MM->allocated[ slot ] = 1;
   MM->last_allocated = slot;
   chunk = MM->blocks + slot * MM->size;
   return chunk;
  }
 }
 fprintf(stderr, "No more memory chunks are available!");
 return -1;
}

variable_types:
chunk
void *

variable_types: length int

variable_types: base int

variable_types: slot int


original_code:
void mm_put (mm_t *MM, void *chunk) {
 int i;
 int index = ((unsigned int)chunk - (unsigned int)MM->blocks) / MM->size;
 MM->allocated[index] = 0;
 memset(chunk, 0, MM->size);
}

variable_types: i int

variable_types: index int


canonical_decompiled_code:
void __fastcall func12(void **a1)
{
free(*a1);
free(a1[2]);
*(_OWORD *)a1 = 0LL;
*((_OWORD *)a1 + 1) = 0LL;
}

original_code:
void mm_release (mm_t *MM) {
 free(MM->blocks);
 free(MM->allocated);
 memset(MM, 0, sizeof(mm_t));
}


decompiled_code:
int timer_example()
{
unsigned int v0; // ebx
__int64 v1; // rsi
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v0 = 0;
gettimeofday(&v4, 0LL);
do
{
v1 = v0++;
printf("%i ", v1);
}
while ( v0 != 10 );
gettimeofday(&tv, 0LL);
v2 = comp_time(v4.tv_sec, v4.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(stderr, "Time taken = %f msec\n", v2 / 1000.0);
}

canonical_decompiled_code:
int func13()
{
unsigned int v0; // ebx
__int64 v1; // rsi
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

v0 = 0;
gettimeofday(&v4, 0LL);
do
{
v1 = v0++;
printf("%i ", v1);
}
while ( v0 != 10 );
gettimeofday(&tv, 0LL);
v2 = func8(v4.tv_sec, v4.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(stderr, "Time taken = %f msec\n", v2 / 1000.0);
}

original_code:
void timer_example ()
{
    struct timeval time_start, time_end;
    int j;
    j = gettimeofday (&time_start, (void *)((void *)0));
    int i;
 for (i = 0; i < 10; i++){
  printf("%i ", i);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}


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

if ( argc != 2 )
return main_mm(argc, argv, envp);
result = atoi(argv[1]);
v4 = result;
if ( result > 0 )
{
do
{
result = ((__int64 (*)(void))main_mm)();
--v4;
}
while ( v4 );
}
return result;
}

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

if ( argc != 2 )
return func7(argc, argv, envp);
result = atoi(argv[1]);
v4 = result;
if ( result > 0 )
{
do
{
result = ((__int64 (*)(void))main_mm)();
--v4;
}
while ( v4 );
}
return result;
}

original_code:
void main(int argc, char* argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_mm();
}

canonical_original_code:
void main(int argc, char *argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_mm();
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int main_malloc()
{
char *v0; // rbx
char *v1; // rbp
void *v2; // rdi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v7[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v8[24]; // [rsp+138A0h] [rbp-18h] BYREF

v0 = v7;
gettimeofday(&v5, 0LL);
v1 = v7;
do
{
v1 += 8;
*((_QWORD *)v1 - 1) = malloc(0x40uLL);
}
while ( v1 != v8 );
do
{
v2 = *(void **)v0;
v0 += 8;
free(v2);
}
while ( v0 != v8 );
gettimeofday(&tv, 0LL);
v3 = comp_time(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(stderr, "Time taken for mallocs = %f msec\n\n", v3 / 1000.0);
}

canonical_decompiled_code:
int func7()
{
char *v0; // rbx
char *v1; // rbp
void *v2; // rdi
double v3; // xmm0_8
struct timeval v5; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v7[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v8[24]; // [rsp+138A0h] [rbp-18h] BYREF

v0 = v7;
gettimeofday(&v5, 0LL);
v1 = v7;
do
{
v1 += 8;
*((_QWORD *)v1 - 1) = malloc(0x40uLL);
}
while ( v1 != v8 );
do
{
v2 = *(void **)v0;
v0 += 8;
free(v2);
}
while ( v0 != v8 );
gettimeofday(&tv, 0LL);
v3 = func8(v5.tv_sec, v5.tv_usec, tv.tv_sec, tv.tv_usec);
return fprintf(stderr, "Time taken for mallocs = %f msec\n\n", v3 / 1000.0);
}

original_code:
void main_malloc() {
 char* mem_list[10000];
    struct timeval time_start, time_end;
    int j,i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n\n",
      comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void main_malloc() {
 char *mem_list[10000];
    struct timeval time_start; struct timeval time_end;
    int j; int i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n\n",
      comp_time (time_start, time_end)/1000.0);
}


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

if ( argc != 2 )
return main_malloc(argc, argv, envp);
result = atoi(argv[1]);
v4 = result;
if ( result > 0 )
{
do
{
result = ((__int64 (*)(void))main_malloc)();
--v4;
}
while ( v4 );
}
return result;
}

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

if ( argc != 2 )
return func7(argc, argv, envp);
result = atoi(argv[1]);
v4 = result;
if ( result > 0 )
{
do
{
result = ((__int64 (*)(void))main_malloc)();
--v4;
}
while ( v4 );
}
return result;
}

original_code:
void main(int argc, char* argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_malloc();
}

canonical_original_code:
void main(int argc, char *argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_malloc();
}


repo: harmanpa/crecon

decompiled_code:
const char *msgpack_version()
{
return "5.6.0";
}

canonical_decompiled_code:
const char *func0()
{
return "5.6.0";
}

original_code:
const char* msgpack_version(void)
{
 return "5.6.0";
}

return_type: char *


decompiled_code:
__int64 msgpack_version_major()
{
return 5LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 5LL;
}

original_code:
int msgpack_version_major(void)
{
 return 5;
}

canonical_original_code:
int msgpack_version_major()
{
 return 5;
}


decompiled_code:
__int64 msgpack_version_minor()
{
return 6LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 6LL;
}

original_code:
int msgpack_version_minor(void)
{
 return 6;
}

canonical_original_code:
int msgpack_version_minor()
{
 return 6;
}


decompiled_code:
__int64 __fastcall recon_wall_table_n_signals(__int64 a1, _DWORD *a2, _DWORD *a3)
{
*a2 = *(_QWORD *)(a1 + 16);
*a3 = *(_QWORD *)(a1 + 32);
return 0LL;
}

original_code:
recon_status recon_wall_table_n_signals(recon_wall_table tab, int* nsignals, int* naliases) {
    wall_table* table = (wall_table*) tab;
    *nsignals = table->nsignals;
    *naliases = table->naliases;
    return 0;
}

canonical_original_code:
int recon_wall_table_n_signals(void *tab, int *nsignals, int *naliases) {
    struct wall_table *table = (wall_table*) tab;
    *nsignals = table->nsignals;
    *naliases = table->naliases;
    return 0;
}

variable_types:
tab
void *

variable_types:
nsignals
int *

variable_types:
naliases
int *

variable_types: struct wall_table { void *wall; char *name; unsigned long nsignals; unsigned long ndefinedsignals; unsigned long naliases; unsigned long ndefinedaliases; char **signals; char **aliases; char **aliased; char **transforms; unsigned long nrows; } *


original_code:
recon_status recon_wall_free_table(wall_table* table) {
    int i;
    for (i = 0; i < table->ndefinedsignals; i++) {
        free(table->signals[i]);
        table->signals[i] = ((void *)0);
    }
    for (i = 0; i < table->ndefinedaliases; i++) {
        free(table->aliases[i]);
        free(table->aliased[i]);
        if (0 != strcmp(table->transforms[i], "")) {
            free(table->transforms[i]);
            table->transforms[i] = ((void *)0);
        }
    }
    if (table->nsignals > 0) {
        free(table->signals);
        table->signals = ((void *)0);
    }
    if (table->naliases > 0) {
        free(table->aliases);
        free(table->aliased);
        free(table->transforms);
        table->aliases = ((void *)0);
        table->aliased = ((void *)0);
        table->transforms = ((void *)0);
    }
    free(table->name);
    return 0;
}

canonical_original_code:
int recon_wall_free_table(struct wall_table *table) {
    int i;
    for (i = 0; i < table->ndefinedsignals; i++) {
        free(table->signals[i]);
        table->signals[i] = ((void *)0);
    }
    for (i = 0; i < table->ndefinedaliases; i++) {
        free(table->aliases[i]);
        free(table->aliased[i]);
        if (0 != strcmp(table->transforms[i], "")) {
            free(table->transforms[i]);
            table->transforms[i] = ((void *)0);
        }
    }
    if (table->nsignals > 0) {
        free(table->signals);
        table->signals = ((void *)0);
    }
    if (table->naliases > 0) {
        free(table->aliases);
        free(table->aliased);
        free(table->transforms);
        table->aliases = ((void *)0);
        table->aliased = ((void *)0);
        table->transforms = ((void *)0);
    }
    free(table->name);
    return 0;
}

user_defined_types: struct wall_table { void *wall; char *name; unsigned long nsignals; unsigned long ndefinedsignals; unsigned long naliases; unsigned long ndefinedaliases; char **signals; char **aliases; char **aliased; char **transforms; unsigned long nrows; }


decompiled_code:
int __fastcall recon_wall_table_find_signal(__int64 a1, const char *a2, _DWORD *a3)
{
__int64 v3; // r12
__int64 v4; // r14
__int64 v6; // rbx
int result; // eax

v3 = *(_QWORD *)(a1 + 24);
if ( !v3 )
return -4;
v4 = *(_QWORD *)(a1 + 48);
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v4 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v3 )
return -4;
}
*a3 = v6;
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, _DWORD *a3)
{
__int64 v3; // r12
__int64 v4; // r14
__int64 v6; // rbx
int result; // eax

v3 = *(_QWORD *)(a1 + 24);
if ( !v3 )
return -4;
v4 = *(_QWORD *)(a1 + 48);
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v4 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v3 )
return -4;
}
*a3 = v6;
return result;
}

original_code:
recon_status recon_wall_table_find_signal(recon_wall_table tab, const char* name, int* index) {
    int i;
    wall_table* table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedsignals; i++) {
        if (strcmp(name, table->signals[i]) == 0) {
            *index = i;
            return 0;
        }
    }
    return -4;
}

canonical_original_code:
int recon_wall_table_find_signal(void *tab, char *name, int *index) {
    int i;
    struct wall_table *table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedsignals; i++) {
        if (strcmp(name, table->signals[i]) == 0) {
            *index = i;
            return 0;
        }
    }
    return -4;
}

variable_types:
name
char *

variable_types:
index
int *


decompiled_code:
__int64 __fastcall recon_wall_table_add_signal(_QWORD *a1, const char *a2)
{
size_t v2; // rax
__int64 v3; // r12
_QWORD *v4; // r14
void *v5; // rax
void *v6; // r13
size_t v7; // rax
int v9[11]; // [rsp+0h] [rbp-2Ch] BYREF

if ( a1[3] >= a1[2] )
return 0xFFFFFFFFLL;
if ( !recon_wall_table_find_signal((__int64)a1, a2, v9) )
return 4294967294LL;
v2 = strlen(a2);
v3 = a1[3];
v4 = (_QWORD *)(a1[6] + 8 * v3);
v5 = malloc(v2 + 1);
*v4 = v5;
v6 = v5;
v7 = strlen(a2);
memcpy(v6, a2, v7 + 1);
a1[3] = v3 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, const char *a2)
{
size_t v2; // rax
__int64 v3; // r12
_QWORD *v4; // r14
void *v5; // rax
void *v6; // r13
size_t v7; // rax
int v9[11]; // [rsp+0h] [rbp-2Ch] BYREF

if ( a1[3] >= a1[2] )
return 0xFFFFFFFFLL;
if ( !func3((__int64)a1, a2, v9) )
return 4294967294LL;
v2 = strlen(a2);
v3 = a1[3];
v4 = (_QWORD *)(a1[6] + 8 * v3);
v5 = malloc(v2 + 1);
*v4 = v5;
v6 = v5;
v7 = strlen(a2);
memcpy(v6, a2, v7 + 1);
a1[3] = v3 + 1;
return 0LL;
}

original_code:
recon_status recon_wall_table_add_signal(recon_wall_table tab, const char* name) {
    int other;
    wall_table* table = (wall_table*) tab;
    if (table->ndefinedsignals >= table->nsignals) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, name, &other) == 0) {
        return -2;
    }
    table->signals[table->ndefinedsignals] = (char*) malloc(strlen(name) + 1);
    memcpy(table->signals[table->ndefinedsignals], name, strlen(name) + 1);
    table->ndefinedsignals++;
    return 0;
}

canonical_original_code:
int recon_wall_table_add_signal(void *tab, char *name) {
    int other;
    struct wall_table *table = (wall_table*) tab;
    if (table->ndefinedsignals >= table->nsignals) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, name, &other) == 0) {
        return -2;
    }
    table->signals[table->ndefinedsignals] = (char *) malloc(strlen(name) + 1);
    memcpy(table->signals[table->ndefinedsignals], name, strlen(name) + 1);
    table->ndefinedsignals++;
    return 0;
}

variable_types: other int


decompiled_code:
int __fastcall recon_wall_table_find_alias(_QWORD *a1, const char *a2, _QWORD *a3, _QWORD *a4)
{
__int64 v4; // rbp
__int64 v5; // r15
__int64 v6; // r14
int result; // eax

v4 = a1[5];
if ( !v4 )
return -4;
v5 = a1[7];
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v5 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v4 )
return -4;
}
*a3 = *(_QWORD *)(a1[8] + 8 * v6);
*a4 = *(_QWORD *)(a1[9] + 8 * v6);
return result;
}

canonical_decompiled_code:
int __fastcall func5(_QWORD *a1, const char *a2, _QWORD *a3, _QWORD *a4)
{
__int64 v4; // rbp
__int64 v5; // r15
__int64 v6; // r14
int result; // eax

v4 = a1[5];
if ( !v4 )
return -4;
v5 = a1[7];
v6 = 0LL;
while ( 1 )
{
result = strcmp(a2, *(const char **)(v5 + 8 * v6));
if ( !result )
break;
if ( ++v6 == v4 )
return -4;
}
*a3 = *(_QWORD *)(a1[8] + 8 * v6);
*a4 = *(_QWORD *)(a1[9] + 8 * v6);
return result;
}

original_code:
recon_status recon_wall_table_find_alias(recon_wall_table tab, const char* name, char** of, char** transform) {
    int i;
    wall_table* table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedaliases; i++) {
        if (strcmp(name, table->aliases[i]) == 0) {
            *of = table->aliased[i];
            *transform = table->transforms[i];
            return 0;
        }
    }
    return -4;
}

canonical_original_code:
int recon_wall_table_find_alias(void *tab, char *name, char **of, char **transform) {
    int i;
    struct wall_table *table = (wall_table*) tab;
    for (i = 0; i < table->ndefinedaliases; i++) {
        if (strcmp(name, table->aliases[i]) == 0) {
            *of = table->aliased[i];
            *transform = table->transforms[i];
            return 0;
        }
    }
    return -4;
}

variable_types:
of
char **

variable_types:
transform
char **


decompiled_code:
__int64 __fastcall recon_wall_table_get_signal(__int64 a1, int a2, _QWORD *a3)
{
if ( a2 < 0 || (unsigned __int64)a2 >= *(_QWORD *)(a1 + 24) )
return 4294967285LL;
*a3 = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * a2);
return 0LL;
}

original_code:
recon_status recon_wall_table_get_signal(recon_wall_table tab, int index, char** name) {
    wall_table* table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedsignals) {
        return -11;
    }
    *name = table->signals[index];
    return 0;
}

canonical_original_code:
int recon_wall_table_get_signal(void *tab, int index, char **name) {
    struct wall_table *table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedsignals) {
        return -11;
    }
    *name = table->signals[index];
    return 0;
}

variable_types:
name
char **


decompiled_code:
__int64 __fastcall recon_wall_table_get_alias(__int64 a1, int a2, _QWORD *a3)
{
if ( a2 < 0 || (unsigned __int64)a2 >= *(_QWORD *)(a1 + 40) )
return 4294967285LL;
*a3 = *(_QWORD *)(*(_QWORD *)(a1 + 56) + 8LL * a2);
return 0LL;
}

original_code:
recon_status recon_wall_table_get_alias(recon_wall_table tab, int index, char** name) {
    wall_table* table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedaliases) {
        return -11;
    }
    *name = table->aliases[index];
    return 0;
}

canonical_original_code:
int recon_wall_table_get_alias(void *tab, int index, char **name) {
    struct wall_table *table = (wall_table*) tab;
    if (index < 0 || index >= table->ndefinedaliases) {
        return -11;
    }
    *name = table->aliases[index];
    return 0;
}


decompiled_code:
__int64 __fastcall recon_wall_table_add_alias(_QWORD *a1, const char *a2, const char *a3, const char *a4)
{
size_t v6; // rax
__int64 v7; // r14
void *v8; // rax
_QWORD *v9; // rdx
size_t v10; // rax
size_t v11; // rax
void *v12; // r12
size_t v13; // rax
unsigned int v14; // er8
size_t v15; // rax
_QWORD *v16; // r15
void *v17; // rax
void *v18; // rbp
size_t v19; // rax
_QWORD *dest; // [rsp+4h] [rbp-50h]
void *desta; // [rsp+4h] [rbp-50h]
_QWORD *destb; // [rsp+4h] [rbp-50h]
int v24[15]; // [rsp+18h] [rbp-3Ch] BYREF

if ( a1[5] >= a1[4] )
return 0xFFFFFFFFLL;
if ( recon_wall_table_find_signal((__int64)a1, a3, v24) )
return (unsigned int)-4;
v6 = strlen(a2);
v7 = a1[5];
dest = (_QWORD *)(8 * v7 + a1[7]);
v8 = malloc(v6 + 1);
v9 = dest;
desta = v8;
*v9 = v8;
v10 = strlen(a2);
memcpy(desta, a2, v10 + 1);
v11 = strlen(a3);
destb = (_QWORD *)(8 * v7 + a1[8]);
v12 = malloc(v11 + 1);
*destb = v12;
v13 = strlen(a3);
memcpy(v12, a3, v13 + 1);
v14 = 0;
if ( a4 )
{
v15 = strlen(a4);
v16 = (_QWORD *)(a1[9] + 8 * v7);
v17 = malloc(v15 + 1);
*v16 = v17;
v18 = v17;
v19 = strlen(a4);
memcpy(v18, a4, v19 + 1);
v14 = 0;
}
else
{
*(_QWORD *)(a1[9] + 8 * v7) = &unk_70A;
}
a1[5] = v7 + 1;
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, const char *a2, const char *a3, const char *a4)
{
size_t v6; // rax
__int64 v7; // r14
void *v8; // rax
_QWORD *v9; // rdx
size_t v10; // rax
size_t v11; // rax
void *v12; // r12
size_t v13; // rax
unsigned int v14; // er8
size_t v15; // rax
_QWORD *v16; // r15
void *v17; // rax
void *v18; // rbp
size_t v19; // rax
_QWORD *dest; // [rsp+4h] [rbp-50h]
void *desta; // [rsp+4h] [rbp-50h]
_QWORD *destb; // [rsp+4h] [rbp-50h]
int v24[15]; // [rsp+18h] [rbp-3Ch] BYREF

if ( a1[5] >= a1[4] )
return 0xFFFFFFFFLL;
if ( func3((__int64)a1, a3, v24) )
return (unsigned int)-4;
v6 = strlen(a2);
v7 = a1[5];
dest = (_QWORD *)(8 * v7 + a1[7]);
v8 = malloc(v6 + 1);
v9 = dest;
desta = v8;
*v9 = v8;
v10 = strlen(a2);
memcpy(desta, a2, v10 + 1);
v11 = strlen(a3);
destb = (_QWORD *)(8 * v7 + a1[8]);
v12 = malloc(v11 + 1);
*destb = v12;
v13 = strlen(a3);
memcpy(v12, a3, v13 + 1);
v14 = 0;
if ( a4 )
{
v15 = strlen(a4);
v16 = (_QWORD *)(a1[9] + 8 * v7);
v17 = malloc(v15 + 1);
*v16 = v17;
v18 = v17;
v19 = strlen(a4);
memcpy(v18, a4, v19 + 1);
v14 = 0;
}
else
{
*(_QWORD *)(a1[9] + 8 * v7) = &unk_70A;
}
a1[5] = v7 + 1;
return v14;
}

original_code:
recon_status recon_wall_table_add_alias(recon_wall_table tab, const char* alias, const char* signal, char* transform) {
    int other;
    wall_table* table = (wall_table*) tab;
    if (table->ndefinedaliases >= table->naliases) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, signal, &other) != 0) {
        return -4;
    }
    table->aliases[table->ndefinedaliases] = (char*) malloc(strlen(alias) + 1);
    memcpy(table->aliases[table->ndefinedaliases], alias, strlen(alias) + 1);
    table->aliased[table->ndefinedaliases] = (char*) malloc(strlen(signal) + 1);
    memcpy(table->aliased[table->ndefinedaliases], signal, strlen(signal) + 1);
    if (transform) {
        table->transforms[table->ndefinedaliases] = (char*) malloc(strlen(transform) + 1);
        memcpy(table->transforms[table->ndefinedaliases], transform, strlen(transform) + 1);
    } else {
        table->transforms[table->ndefinedaliases] = "";
    }
    table->ndefinedaliases++;
    return 0;
}

canonical_original_code:
int recon_wall_table_add_alias(void *tab, char *alias, char *signal, char *transform) {
    int other;
    struct wall_table *table = (wall_table*) tab;
    if (table->ndefinedaliases >= table->naliases) {
        return -1;
    }
    if (recon_wall_table_find_signal(table, signal, &other) != 0) {
        return -4;
    }
    table->aliases[table->ndefinedaliases] = (char *) malloc(strlen(alias) + 1);
    memcpy(table->aliases[table->ndefinedaliases], alias, strlen(alias) + 1);
    table->aliased[table->ndefinedaliases] = (char *) malloc(strlen(signal) + 1);
    memcpy(table->aliased[table->ndefinedaliases], signal, strlen(signal) + 1);
    if (transform) {
        table->transforms[table->ndefinedaliases] = (char *) malloc(strlen(transform) + 1);
        memcpy(table->transforms[table->ndefinedaliases], transform, strlen(transform) + 1);
    } else {
        table->transforms[table->ndefinedaliases] = "";
    }
    table->ndefinedaliases++;
    return 0;
}

variable_types:
alias
char *

variable_types:
signal
char *

variable_types:
transform
char *


decompiled_code:
__int64 __fastcall call_finalizer_array(__int64 *a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; a1[2] != i; i -= 16LL )
result = (*(__int64 (__fastcall **)(_QWORD))(i - 16))(*(_QWORD *)(i - 8));
return result;
}

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

for ( i = *a1; a1[2] != i; i -= 16LL )
result = (*(__int64 (__fastcall **)(_QWORD))(i - 16))(*(_QWORD *)(i - 8));
return result;
}

original_code:
static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa)
{
 msgpack_zone_finalizer* fin = fa->tail;
 for(; fin != fa->array; --fin) {
  (*(fin-1)->func)((fin-1)->data);
 }
}

canonical_original_code:
static inline void call_finalizer_array(struct msgpack_zone_finalizer_array *fa)
{
 struct msgpack_zone_finalizer *fin = fa->tail;
 for(; fin != fa->array; --fin) {
  (*(fin-1)->func)((fin-1)->data);
 }
}

variable_types: struct msgpack_zone_finalizer_array { struct msgpack_zone_finalizer { void (*func)(void *data); void *data; } *tail; struct msgpack_zone_finalizer *end; struct msgpack_zone_finalizer *array; } *

user_defined_types: struct msgpack_zone_finalizer_array { struct msgpack_zone_finalizer *tail; struct msgpack_zone_finalizer *end; struct msgpack_zone_finalizer *array; }


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

v2 = malloc(a2 + 8);
if ( !v2 )
return 0LL;
*a1 = a2;
a1[1] = v2 + 1;
a1[2] = v2;
*v2 = 0LL;
return 1LL;
}

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

v2 = malloc(a2 + 8);
if ( !v2 )
return 0LL;
*a1 = a2;
a1[1] = v2 + 1;
a1[2] = v2;
*v2 = 0LL;
return 1LL;
}

original_code:
static inline _Bool init_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size)
{
 msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc(
   sizeof(msgpack_zone_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  return 0;
 }
 cl->head = chunk;
 cl->free = chunk_size;
 cl->ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
 chunk->next = ((void *)0);
 return 1;
}

canonical_original_code:
static inline _Bool init_chunk_list(struct msgpack_zone_chunk_list *cl, unsigned long chunk_size)
{
 struct msgpack_zone_chunk *chunk = (msgpack_zone_chunk*)malloc(
   sizeof(msgpack_zone_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  return 0;
 }
 cl->head = chunk;
 cl->free = chunk_size;
 cl->ptr = ((char *)chunk) + sizeof(msgpack_zone_chunk);
 chunk->next = ((void *)0);
 return 1;
}

variable_types: struct msgpack_zone_chunk_list { unsigned long free; char *ptr; struct msgpack_zone_chunk { struct msgpack_zone_chunk *next; } *head; } *

user_defined_types: struct msgpack_zone_chunk_list { unsigned long free; char *ptr; struct msgpack_zone_chunk *head; }


decompiled_code:
void __fastcall destroy_finalizer_array(__int64 a1)
{
call_finalizer_array((__int64 *)a1);
free(*(void **)(a1 + 16));
}

original_code:
static inline void destroy_finalizer_array(msgpack_zone_finalizer_array* fa)
{
 call_finalizer_array(fa);
 free(fa->array);
}

canonical_original_code:
static inline void destroy_finalizer_array(struct msgpack_zone_finalizer_array *fa)
{
 call_finalizer_array(fa);
 free(fa->array);
}

user_defined_types: struct msgpack_zone_finalizer { void (*func)(void *data); void *data; }


original_code:
_Bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
  void (*func)(void* data), void* data)
{
 msgpack_zone_finalizer* tmp;
 msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
 const size_t nused = fa->end - fa->array;
 size_t nnext;
 if(nused == 0) {
  nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ?
    72 / sizeof(msgpack_zone_finalizer) : 8;
 } else {
  nnext = nused * 2;
 }
 tmp =
  (msgpack_zone_finalizer*)realloc(fa->array,
    sizeof(msgpack_zone_finalizer) * nnext);
 if(tmp == ((void *)0)) {
  return 0;
 }
 fa->array = tmp;
 fa->end = tmp + nnext;
 fa->tail = tmp + nused;
 fa->tail->func = func;
 fa->tail->data = data;
 ++fa->tail;
 return 1;
}

canonical_original_code:
_Bool msgpack_zone_push_finalizer_expand(struct msgpack_zone *zone, void (*func)(void *data), void *data)
{
 struct msgpack_zone_finalizer *tmp;
 struct msgpack_zone_finalizer_array *fa = &zone->finalizer_array;
 unsigned long nused = fa->end - fa->array;
 unsigned long nnext;
 if(nused == 0) {
  nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ?
    72 / sizeof(msgpack_zone_finalizer) : 8;
 } else {
  nnext = nused * 2;
 }
 tmp =
  (struct msgpack_zone_finalizer *)realloc(fa->array,
    sizeof(msgpack_zone_finalizer) * nnext);
 if(tmp == ((void *)0)) {
  return 0;
 }
 fa->array = tmp;
 fa->end = tmp + nnext;
 fa->tail = tmp + nused;
 fa->tail->func = func;
 fa->tail->data = data;
 ++fa->tail;
 return 1;
}

variable_types: struct msgpack_zone { struct msgpack_zone_chunk_list { unsigned long free; char *ptr; struct msgpack_zone_chunk { struct msgpack_zone_chunk *next; } *head; } chunk_list; struct msgpack_zone_finalizer_array { struct msgpack_zone_finalizer { void (*func)(void *data); void *data; } *tail; struct msgpack_zone_finalizer *end; struct msgpack_zone_finalizer *array; } finalizer_array; unsigned long chunk_size; } *

variable_types:
func
void (*)(void *data)

variable_types:
data
void *

variable_types:
nused
unsigned long

variable_types:
nnext
unsigned long

user_defined_types: struct msgpack_zone { struct msgpack_zone_chunk_list chunk_list; struct msgpack_zone_finalizer_array finalizer_array; unsigned long chunk_size; }


decompiled_code:
bool __fastcall msgpack_zone_is_empty(__int64 a1)
{
bool result; // al

result = 0;
if ( *(_QWORD *)a1 == *(_QWORD *)(a1 + 48) && !**(_QWORD **)(a1 + 16) )
result = *(_QWORD *)(a1 + 24) == *(_QWORD *)(a1 + 40);
return result;
}

canonical_decompiled_code:
bool __fastcall func8(__int64 a1)
{
bool result; // al

result = 0;
if ( *(_QWORD *)a1 == *(_QWORD *)(a1 + 48) && !**(_QWORD **)(a1 + 16) )
result = *(_QWORD *)(a1 + 24) == *(_QWORD *)(a1 + 40);
return result;
}

original_code:
_Bool msgpack_zone_is_empty(msgpack_zone* zone)
{
 msgpack_zone_chunk_list* const cl = &zone->chunk_list;
 msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
 return cl->free == zone->chunk_size && cl->head->next == ((void *)0) &&
  fa->tail == fa->array;
}

canonical_original_code:
_Bool msgpack_zone_is_empty(struct msgpack_zone *zone)
{
 struct msgpack_zone_chunk_list *cl = &zone->chunk_list;
 struct msgpack_zone_finalizer_array *fa = &zone->finalizer_array;
 return cl->free == zone->chunk_size && cl->head->next == ((void *)0) &&
  fa->tail == fa->array;
}

user_defined_types: struct msgpack_zone_chunk { struct msgpack_zone_chunk *next; }


decompiled_code:
void __fastcall msgpack_zone_destroy(__int64 a1)
{
destroy_finalizer_array(a1 + 24);
destroy_chunk_list_isra_0(*(void **)(a1 + 16));
}

original_code:
void msgpack_zone_destroy(msgpack_zone* zone)
{
 destroy_finalizer_array(&zone->finalizer_array);
 destroy_chunk_list(&zone->chunk_list);
}

canonical_original_code:
void msgpack_zone_destroy(struct msgpack_zone *zone)
{
 destroy_finalizer_array(&zone->finalizer_array);
 destroy_chunk_list(&zone->chunk_list);
}


decompiled_code:
void __fastcall msgpack_zone_init(_QWORD *a1, __int64 a2)
{
a1[6] = a2;
if ( (unsigned __int8)init_chunk_list(a1, a2) )
init_finalizer_array(a1 + 3);
}

canonical_decompiled_code:
void __fastcall func11(_QWORD *a1, __int64 a2)
{
a1[6] = a2;
if ( (unsigned __int8)func3(a1, a2) )
func0(a1 + 3);
}

original_code:
_Bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size)
{
 zone->chunk_size = chunk_size;
 if(!init_chunk_list(&zone->chunk_list, chunk_size)) {
  return 0;
 }
 init_finalizer_array(&zone->finalizer_array);
 return 1;
}

canonical_original_code:
_Bool msgpack_zone_init(struct msgpack_zone *zone, unsigned long chunk_size)
{
 zone->chunk_size = chunk_size;
 if(!init_chunk_list(&zone->chunk_list, chunk_size)) {
  return 0;
 }
 init_finalizer_array(&zone->finalizer_array);
 return 1;
}


decompiled_code:
void __fastcall msgpack_zone_free(void *ptr)
{
if ( ptr )
{
msgpack_zone_destroy((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
if ( ptr )
{
func9((__int64)ptr);
free(ptr);
}
}

original_code:
void msgpack_zone_free(msgpack_zone* zone)
{
 if(zone == ((void *)0)) { return; }
 msgpack_zone_destroy(zone);
 free(zone);
}

canonical_original_code:
void msgpack_zone_free(struct msgpack_zone *zone)
{
 if(zone == ((void *)0)) { return; }
 msgpack_zone_destroy(zone);
 free(zone);
}


decompiled_code:
__int64 __fastcall msgpack_vrefbuffer_init(_QWORD *a1, __int64 a2, __int64 a3)
{
char *v4; // rax
void *v5; // rbp
_QWORD *v6; // rax
__int64 result; // rax

a1[3] = a3;
a1[4] = a2;
v4 = (char *)malloc(0x40uLL);
if ( !v4 )
return 0LL;
v5 = v4;
*a1 = v4;
a1[1] = v4 + 64;
a1[2] = v4;
v6 = malloc(a3 + 8);
if ( v6 )
{
a1[5] = a3;
a1[6] = v6 + 1;
a1[7] = v6;
*v6 = 0LL;
result = 1LL;
}
else
{
free(v5);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, __int64 a3)
{
char *v4; // rax
void *v5; // rbp
_QWORD *v6; // rax
__int64 result; // rax

a1[3] = a3;
a1[4] = a2;
v4 = (char *)malloc(0x40uLL);
if ( !v4 )
return 0LL;
v5 = v4;
*a1 = v4;
a1[1] = v4 + 64;
a1[2] = v4;
v6 = malloc(a3 + 8);
if ( v6 )
{
a1[5] = a3;
a1[6] = v6 + 1;
a1[7] = v6;
*v6 = 0LL;
result = 1LL;
}
else
{
free(v5);
result = 0LL;
}
return result;
}

original_code:
_Bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
  size_t ref_size, size_t chunk_size)
{
 size_t nfirst;
 struct iovec* array;
 msgpack_vrefbuffer_chunk* chunk;
 msgpack_vrefbuffer_inner_buffer* ib;
 vbuf->chunk_size = chunk_size;
 vbuf->ref_size = ref_size;
  nfirst = (sizeof(struct iovec) < 72/2) ?
   72 / sizeof(struct iovec) : 8;
 array = (struct iovec*)malloc(
   sizeof(struct iovec) * nfirst);
 if(array == ((void *)0)) {
  return 0;
 }
 vbuf->tail = array;
 vbuf->end = array + nfirst;
 vbuf->array = array;
 chunk = (msgpack_vrefbuffer_chunk*)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  free(array);
  return 0;
 }
 ib = &vbuf->inner_buffer;
 ib->free = chunk_size;
 ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 ib->head = chunk;
 chunk->next = ((void *)0);
 return 1;
}

canonical_original_code:
_Bool msgpack_vrefbuffer_init(struct msgpack_vrefbuffer *vbuf, unsigned long ref_size, unsigned long chunk_size)
{
 unsigned long nfirst;
 struct iovec *array;
 struct msgpack_vrefbuffer_chunk *chunk;
 struct msgpack_vrefbuffer_inner_buffer *ib;
 vbuf->chunk_size = chunk_size;
 vbuf->ref_size = ref_size;
  nfirst = (sizeof(struct iovec) < 72/2) ?
   72 / sizeof(struct iovec) : 8;
 array = (struct iovec *)malloc(
   sizeof(struct iovec) * nfirst);
 if(array == ((void *)0)) {
  return 0;
 }
 vbuf->tail = array;
 vbuf->end = array + nfirst;
 vbuf->array = array;
 chunk = (struct msgpack_vrefbuffer_chunk *)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + chunk_size);
 if(chunk == ((void *)0)) {
  free(array);
  return 0;
 }
 ib = &vbuf->inner_buffer;
 ib->free = chunk_size;
 ib->ptr = ((char *)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 ib->head = chunk;
 chunk->next = ((void *)0);
 return 1;
}

variable_types: struct msgpack_vrefbuffer { struct iovec { void *iov_base; unsigned long iov_len; } *tail; struct iovec *end; struct iovec *array; unsigned long chunk_size; unsigned long ref_size; struct msgpack_vrefbuffer_inner_buffer { unsigned long free; char *ptr; struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; } *head; } inner_buffer; } *

variable_types:
nfirst
unsigned long

variable_types: struct msgpack_vrefbuffer_inner_buffer { unsigned long free; char *ptr; struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; } *head; } *

user_defined_types: struct msgpack_vrefbuffer { struct iovec *tail; struct iovec *end; struct iovec *array; unsigned long chunk_size; unsigned long ref_size; struct msgpack_vrefbuffer_inner_buffer inner_buffer; }

user_defined_types: struct msgpack_vrefbuffer_inner_buffer { unsigned long free; char *ptr; struct msgpack_vrefbuffer_chunk *head; }


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

v2 = *(_QWORD **)(a1 + 56);
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
free(*(void **)(a1 + 16));
}

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

v2 = *(_QWORD **)(a1 + 56);
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
free(*(void **)(a1 + 16));
}

original_code:
void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf)
{
 msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head;
 while(1) {
  msgpack_vrefbuffer_chunk* n = c->next;
  free(c);
  if(n != ((void *)0)) {
   c = n;
  } else {
   break;
  }
 }
 free(vbuf->array);
}

canonical_original_code:
void msgpack_vrefbuffer_destroy(struct msgpack_vrefbuffer *vbuf)
{
 struct msgpack_vrefbuffer_chunk *c = vbuf->inner_buffer.head;
 while(1) {
  struct msgpack_vrefbuffer_chunk *n = c->next;
  free(c);
  if(n != ((void *)0)) {
   c = n;
  } else {
   break;
  }
 }
 free(vbuf->array);
}

variable_types: struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; } *

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


decompiled_code:
__int64 __fastcall msgpack_vrefbuffer_clear(_QWORD *a1)
{
_QWORD **v2; // rax
_QWORD *v3; // rbx
void *v4; // rdi
__int64 v5; // rdx
__int64 result; // rax

v2 = (_QWORD **)a1[7];
v3 = *v2;
if ( *v2 )
{
do
{
v4 = v3;
v3 = (_QWORD *)*v3;
free(v4);
}
while ( v3 );
v2 = (_QWORD **)a1[7];
}
*v2 = 0LL;
v5 = a1[3];
a1[6] = v2 + 1;
result = a1[2];
a1[5] = v5;
*a1 = result;
return result;
}

original_code:
void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vbuf)
{
 msgpack_vrefbuffer_inner_buffer* ib;
 msgpack_vrefbuffer_chunk* chunk;
 msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head->next;
 msgpack_vrefbuffer_chunk* n;
 while(c != ((void *)0)) {
  n = c->next;
  free(c);
  c = n;
 }
 ib = &vbuf->inner_buffer;
 chunk = ib->head;
 chunk->next = ((void *)0);
 ib->free = vbuf->chunk_size;
 ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 vbuf->tail = vbuf->array;
}

canonical_original_code:
void msgpack_vrefbuffer_clear(struct msgpack_vrefbuffer *vbuf)
{
 struct msgpack_vrefbuffer_inner_buffer *ib;
 struct msgpack_vrefbuffer_chunk *chunk;
 struct msgpack_vrefbuffer_chunk *c = vbuf->inner_buffer.head->next;
 struct msgpack_vrefbuffer_chunk *n;
 while(c != ((void *)0)) {
  n = c->next;
  free(c);
  c = n;
 }
 ib = &vbuf->inner_buffer;
 chunk = ib->head;
 chunk->next = ((void *)0);
 ib->free = vbuf->chunk_size;
 ib->ptr = ((char *)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 vbuf->tail = vbuf->array;
}

user_defined_types: struct msgpack_vrefbuffer_chunk { struct msgpack_vrefbuffer_chunk *next; }


original_code:
int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
  const char* buf, unsigned int len)
{
 if(vbuf->tail == vbuf->end) {
  const size_t nused = vbuf->tail - vbuf->array;
  const size_t nnext = nused * 2;
  struct iovec* nvec = (struct iovec*)realloc(
    vbuf->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   return -1;
  }
  vbuf->array = nvec;
  vbuf->end = nvec + nnext;
  vbuf->tail = nvec + nused;
 }
 vbuf->tail->iov_base = (char*)buf;
 vbuf->tail->iov_len = len;
 ++vbuf->tail;
 return 0;
}

canonical_original_code:
int msgpack_vrefbuffer_append_ref(struct msgpack_vrefbuffer *vbuf, char *buf, unsigned int len)
{
 if(vbuf->tail == vbuf->end) {
  unsigned long nused = vbuf->tail - vbuf->array;
  unsigned long nnext = nused * 2;
  struct iovec *nvec = (struct iovec*)realloc(
    vbuf->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   return -1;
  }
  vbuf->array = nvec;
  vbuf->end = nvec + nnext;
  vbuf->tail = nvec + nused;
 }
 vbuf->tail->iov_base = (char *)buf;
 vbuf->tail->iov_len = len;
 ++vbuf->tail;
 return 0;
}

variable_types:
buf
char *

variable_types:
len
unsigned int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } *


original_code:
int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
  const char* buf, unsigned int len)
{
 msgpack_vrefbuffer_chunk* chunk;
 char* m;
 msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer;
 if(ib->free < len) {
  size_t sz = vbuf->chunk_size;
  if(sz < len) {
   sz = len;
  }
  chunk = (msgpack_vrefbuffer_chunk*)malloc(
    sizeof(msgpack_vrefbuffer_chunk) + sz);
  if(chunk == ((void *)0)) {
   return -1;
  }
  chunk->next = ib->head;
  ib->head = chunk;
  ib->free = sz;
  ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 }
 m = ib->ptr;
 memcpy(m, buf, len);
 ib->free -= len;
 ib->ptr += len;
 if(vbuf->tail != vbuf->array && m ==
   (const char*)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) {
  (vbuf->tail-1)->iov_len += len;
  return 0;
 } else {
  return msgpack_vrefbuffer_append_ref(vbuf, m, len);
 }
}

canonical_original_code:
int msgpack_vrefbuffer_append_copy(struct msgpack_vrefbuffer *vbuf, char *buf, unsigned int len)
{
 struct msgpack_vrefbuffer_chunk *chunk;
 char *m;
 struct msgpack_vrefbuffer_inner_buffer *ib = &vbuf->inner_buffer;
 if(ib->free < len) {
  unsigned long sz = vbuf->chunk_size;
  if(sz < len) {
   sz = len;
  }
  chunk = (struct msgpack_vrefbuffer_chunk *)malloc(
    sizeof(msgpack_vrefbuffer_chunk) + sz);
  if(chunk == ((void *)0)) {
   return -1;
  }
  chunk->next = ib->head;
  ib->head = chunk;
  ib->free = sz;
  ib->ptr = ((char *)chunk) + sizeof(msgpack_vrefbuffer_chunk);
 }
 m = ib->ptr;
 memcpy(m, buf, len);
 ib->free -= len;
 ib->ptr += len;
 if(vbuf->tail != vbuf->array && m ==
   (char *)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) {
  (vbuf->tail-1)->iov_len += len;
  return 0;
 } else {
  return msgpack_vrefbuffer_append_ref(vbuf, m, len);
 }
}

variable_types:
m
char *

variable_types:
sz
unsigned long


original_code:
int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
{
    size_t nused;
 struct iovec* nvec;
 msgpack_vrefbuffer_inner_buffer* ib;
 msgpack_vrefbuffer_inner_buffer* toib;
 msgpack_vrefbuffer_chunk* last;
 size_t sz = vbuf->chunk_size;
 msgpack_vrefbuffer_chunk* empty = (msgpack_vrefbuffer_chunk*)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + sz);
 if(empty == ((void *)0)) {
  return -1;
 }
 empty->next = ((void *)0);
    nused = vbuf->tail - vbuf->array;
 if(to->tail + nused < vbuf->end) {
  const size_t tosize = to->tail - to->array;
  const size_t reqsize = nused + tosize;
  size_t nnext = (to->end - to->array) * 2;
  while(nnext < reqsize) {
   nnext *= 2;
  }
  nvec = (struct iovec*)realloc(
    to->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   free(empty);
   return -1;
  }
  to->array = nvec;
  to->end = nvec + nnext;
  to->tail = nvec + tosize;
 }
 memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused);
 to->tail += nused;
 vbuf->tail = vbuf->array;
 ib = &vbuf->inner_buffer;
 toib = &to->inner_buffer;
 last = ib->head;
 while(last->next != ((void *)0)) {
  last = last->next;
 }
 last->next = toib->head;
 toib->head = ib->head;
 if(toib->free < ib->free) {
  toib->free = ib->free;
  toib->ptr = ib->ptr;
 }
 ib->head = empty;
 ib->free = sz;
 ib->ptr = ((char*)empty) + sizeof(msgpack_vrefbuffer_chunk);
 return 0;
}

canonical_original_code:
int msgpack_vrefbuffer_migrate(struct msgpack_vrefbuffer *vbuf, struct msgpack_vrefbuffer *to)
{
    unsigned long nused;
 struct iovec *nvec;
 struct msgpack_vrefbuffer_inner_buffer *ib;
 struct msgpack_vrefbuffer_inner_buffer *toib;
 struct msgpack_vrefbuffer_chunk *last;
 unsigned long sz = vbuf->chunk_size;
 struct msgpack_vrefbuffer_chunk *empty = (msgpack_vrefbuffer_chunk*)malloc(
   sizeof(msgpack_vrefbuffer_chunk) + sz);
 if(empty == ((void *)0)) {
  return -1;
 }
 empty->next = ((void *)0);
    nused = vbuf->tail - vbuf->array;
 if(to->tail + nused < vbuf->end) {
  unsigned long tosize = to->tail - to->array;
  unsigned long reqsize = nused + tosize;
  unsigned long nnext = (to->end - to->array) * 2;
  while(nnext < reqsize) {
   nnext *= 2;
  }
  nvec = (struct iovec *)realloc(
    to->array, sizeof(struct iovec)*nnext);
  if(nvec == ((void *)0)) {
   free(empty);
   return -1;
  }
  to->array = nvec;
  to->end = nvec + nnext;
  to->tail = nvec + tosize;
 }
 memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused);
 to->tail += nused;
 vbuf->tail = vbuf->array;
 ib = &vbuf->inner_buffer;
 toib = &to->inner_buffer;
 last = ib->head;
 while(last->next != ((void *)0)) {
  last = last->next;
 }
 last->next = toib->head;
 toib->head = ib->head;
 if(toib->free < ib->free) {
  toib->free = ib->free;
  toib->ptr = ib->ptr;
 }
 ib->head = empty;
 ib->free = sz;
 ib->ptr = ((char *)empty) + sizeof(msgpack_vrefbuffer_chunk);
 return 0;
}

variable_types:
to
struct msgpack_vrefbuffer *

variable_types:
tosize
unsigned long

variable_types:
reqsize
unsigned long


decompiled_code:
__int64 __fastcall recon_transform_create_none(_QWORD *a1)
{
*a1 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
*a1 = 0LL;
return 0LL;
}

original_code:
recon_status recon_transform_create_none(char** t) {
    *t = ((void *)0);
    return 0;
}

canonical_original_code:
int recon_transform_create_none(char **t) {
    *t = ((void *)0);
    return 0;
}

variable_types:
t
char **


decompiled_code:
__int64 __fastcall recon_transform_create_inverse(_QWORD *a1)
{
_BYTE *v1; // rax

v1 = malloc(4uLL);
*a1 = v1;
*(_WORD *)v1 = 28265;
v1[2] = 118;
v1[3] = 0;
return 0LL;
}

original_code:
recon_status recon_transform_create_inverse(char** t) {
    *t = (char*) malloc(strlen("inv") + 1);
    memcpy(*t, "inv", strlen("inv"));
    (*t)[strlen("inv")] = '\0';
    return 0;
}

canonical_original_code:
int recon_transform_create_inverse(char **t) {
    *t = (char *) malloc(strlen("inv") + 1);
    memcpy(*t, "inv", strlen("inv"));
    (*t)[strlen("inv")] = '\0';
    return 0;
}


decompiled_code:
__int64 __fastcall recon_transform_create_affine(_QWORD *a1, double a2, double a3)
{
char *v3; // rbp
size_t v5; // r13
void *v6; // rax

v3 = (char *)malloc(0x2BuLL);
if ( a2 == 1.0 && a3 == 0.0 )
return recon_transform_create_none(a1);
if ( a2 == -1.0 && a3 == 0.0 )
return recon_transform_create_inverse(a1);
sprintf(v3, "aff(%.*g,%.*g)", 16, a2, 16, a3);
v5 = strlen(v3) + 1;
v6 = malloc(v5);
*a1 = v6;
memcpy(v6, v3, v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, double a2, double a3)
{
char *v3; // rbp
size_t v5; // r13
void *v6; // rax

v3 = (char *)malloc(0x2BuLL);
if ( a2 == 1.0 && a3 == 0.0 )
return func0(a1);
if ( a2 == -1.0 && a3 == 0.0 )
return func1(a1);
sprintf(v3, "aff(%.*g,%.*g)", 16, a2, 16, a3);
v5 = strlen(v3) + 1;
v6 = malloc(v5);
*a1 = v6;
memcpy(v6, v3, v5);
return 0LL;
}

original_code:
recon_status recon_transform_create_affine(char** t, double scale, double offset) {
    int max_sig_digits = 16;
    char* transform_string;
    transform_string = (char*) malloc(strlen("aff(-.,-.)") + 2 * max_sig_digits + 1);
    if (scale == 1.0 && offset == 0.0) {
        return recon_transform_create_none(t);
    }
    if (scale == -1.0 && offset == 0.0) {
        return recon_transform_create_inverse(t);
    }
    sprintf(transform_string, "aff(%.*g,%.*g)", max_sig_digits, scale, max_sig_digits, offset);
    *t = (char*) malloc(strlen(transform_string) + 1);
    memcpy(*t, transform_string, strlen(transform_string) + 1);
    return 0;
}

canonical_original_code:
int recon_transform_create_affine(char **t, double scale, double offset) {
    int max_sig_digits = 16;
    char *transform_string;
    transform_string = (char *) malloc(strlen("aff(-.,-.)") + 2 * max_sig_digits + 1);
    if (scale == 1.0 && offset == 0.0) {
        return recon_transform_create_none(t);
    }
    if (scale == -1.0 && offset == 0.0) {
        return recon_transform_create_inverse(t);
    }
    sprintf(transform_string, "aff(%.*g,%.*g)", max_sig_digits, scale, max_sig_digits, offset);
    *t = (char *) malloc(strlen(transform_string) + 1);
    memcpy(*t, transform_string, strlen(transform_string) + 1);
    return 0;
}

variable_types: scale double

variable_types: offset double


decompiled_code:
__int64 __fastcall recon_transform_apply_double(const char *a1, double *a2, double a3)
{
__int64 result; // rax
double v4; // [rsp+10h] [rbp-18h] BYREF
double v5; // [rsp+18h] [rbp-10h] BYREF

if ( !a1 )
goto LABEL_5;
if ( !strcmp(a1, "inv") )
{
result = 0LL;
*(_QWORD *)a2 = *(_QWORD *)&a3 ^ LC5;
return result;
}
if ( (unsigned int)_isoc99_sscanf(a1, "aff(%lf,%lf)", &v4, &v5) == 2 )
*a2 = (a3 + v5) * v4;
else
LABEL_5:
*a2 = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, double *a2, double a3)
{
__int64 result; // rax
double v4; // [rsp+10h] [rbp-18h] BYREF
double v5; // [rsp+18h] [rbp-10h] BYREF

if ( !a1 )
goto LABEL_5;
if ( !strcmp(a1, "inv") )
{
result = 0LL;
*(_QWORD *)a2 = *(_QWORD *)&a3 ^ LC5;
return result;
}
if ( (unsigned int)_isoc99_sscanf(a1, "aff(%lf,%lf)", &v4, &v5) == 2 )
*a2 = (a3 + v5) * v4;
else
LABEL_5:
*a2 = a3;
return 0LL;
}

original_code:
recon_status recon_transform_apply_double(char* transform, double in, double* out) {
    double scale;
    double offset;
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1.0;
            return 0;
        }
        if (sscanf(transform, "aff(%lf,%lf)", &scale, &offset) == 2) {
            *out = (in + offset) * scale;
            return 0;
        }
    }
    *out = in;
    return 0;
}

canonical_original_code:
int recon_transform_apply_double(char *transform, double in, double *out) {
    double scale;
    double offset;
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1.0;
            return 0;
        }
        if (sscanf(transform, "aff(%lf,%lf)", &scale, &offset) == 2) {
            *out = (in + offset) * scale;
            return 0;
        }
    }
    *out = in;
    return 0;
}

variable_types:
transform
char *

variable_types: in double

variable_types:
out
double *


decompiled_code:
__int64 __fastcall recon_transform_apply_int(const char *a1, int a2, int *a3)
{
int v3; // eax

v3 = a2;
if ( a1 && !strcmp(a1, "inv") )
v3 = -a2;
*a3 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, int a2, int *a3)
{
int v3; // eax

v3 = a2;
if ( a1 && !strcmp(a1, "inv") )
v3 = -a2;
*a3 = v3;
return 0LL;
}

original_code:
recon_status recon_transform_apply_int(char* transform, int in, int* out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1;
            return 0;
        }
    }
    *out = in;
    return 0;
}

canonical_original_code:
int recon_transform_apply_int(char *transform, int in, int *out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            *out = in * -1;
            return 0;
        }
    }
    *out = in;
    return 0;
}

variable_types: in int

variable_types:
out
int *


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

if ( a1 && !strcmp(a1, "inv") )
{
*a3 = !a2;
result = 0LL;
}
else
{
*a3 = a2;
result = 0LL;
}
return result;
}

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

if ( a1 && !strcmp(a1, "inv") )
{
*a3 = !a2;
result = 0LL;
}
else
{
*a3 = a2;
result = 0LL;
}
return result;
}

original_code:
recon_status recon_transform_apply_boolean(char* transform, recon_booleantype in, recon_booleantype* out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            if (in) {
                *out = 0;;
            } else {
                *out = 1;;
            }
            return 0;
        }
    }
    *out = in;
    return 0;
}

canonical_original_code:
int recon_transform_apply_boolean(char *transform, unsigned char in, unsigned char *out) {
    if (transform) {
        if (strcmp(transform, "inv") == 0) {
            if (in) {
                *out = 0;;
            } else {
                *out = 1;;
            }
            return 0;
        }
    }
    *out = in;
    return 0;
}

variable_types:
in
unsigned char

variable_types:
out
unsigned char *


original_code:
uint32_t recon_util_bytes_to_int(unsigned char* bytes) {
    return (((uint32_t) bytes[0]) << 24) + (((uint32_t) bytes[1]) << 16) + (((uint32_t) bytes[2]) << 8) + (uint32_t) bytes[3];
}

canonical_original_code:
unsigned int recon_util_bytes_to_int(unsigned char *bytes) {
    return (((unsigned int) bytes[0]) << 24) + (((unsigned int) bytes[1]) << 16) + (((unsigned int) bytes[2]) << 8) + (unsigned int) bytes[3];
}

variable_types:
bytes
unsigned char *

return_type: unsigned int


decompiled_code:
void recon_util_tic()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void recon_util_tic(void** t) {
}

canonical_original_code:
void recon_util_tic(void **t) {
}

variable_types:
t
void **


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

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

original_code:
long recon_util_toc(void* t) {
    return 0L;
}

canonical_original_code:
long recon_util_toc(void *t) {
    return 0L;
}

variable_types:
t
void *

return_type: long


decompiled_code:
__int64 __fastcall recon_util_digits(int a1)
{
unsigned int i; // er8

for ( i = 1; a1; a1 /= 10 )
++i;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int i; // er8

for ( i = 1; a1; a1 /= 10 )
++i;
return i;
}

original_code:
int recon_util_digits(int n) {
    int count = 1;
    while (n != 0) {
        n /= 10;
        ++count;
    }
    return count;
}

variable_types: n int

variable_types: count int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
atexit((void (*)(void))&sudokuExit);
printWelcomeScreen(&sudokuExit, argv);
printf("\x1B[2J");
printMenu();
return 0;
}

original_code:
int main(int argc, char** argv) {
    atexit(sudokuExit);
    printWelcomeScreen();
    printf("\033[2J");
    printMenu();
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    atexit(sudokuExit);
    printWelcomeScreen();
    printf("\033[2J");
    printMenu();
    return (0);
}

variable_types: argc int

variable_types:
argv
char **


repo: harshasrisri/tomasulo

decompiled_code:
__int64 create_arch()
{
char *v0; // rbx
char *v1; // rbp
char *v2; // r12
char *v3; // r13
char *v4; // r14
__int64 v5; // rdx
__int64 result; // rax
unsigned int i; // ecx

v0 = (char *)malloc(0xA0uLL);
add_fp_rs = (__int64)v0;
v1 = (char *)malloc(0xA0uLL);
add_int_rs = (__int64)v1;
v2 = (char *)malloc(0x50uLL);
mul_fp_rs = (__int64)v2;
v3 = (char *)malloc(0x50uLL);
mul_int_rs = (__int64)v3;
v4 = (char *)malloc(0x50uLL);
ld_rs = (__int64)v4;
sd_rs = (__int64)malloc(0x50uLL);
v5 = sd_rs;
if ( v4 == 0LL || v3 == 0LL || v2 == 0LL || v0 == 0LL || v1 == 0LL || !sd_rs )
{
fprintf(stderr, "[FATAL] (%s:%d) Error creating the architecture\n", "tomasulo.c", 29LL);
exit(-1);
}
result = 0LL;
for ( i = 0; ; ++i )
{
*(_DWORD *)&v0[result] = 1;
*(_DWORD *)&v0[result + 32] = 0;
*(_QWORD *)&v0[result + 24] = 0LL;
*(_QWORD *)&v0[result + 16] = 0LL;
*(_DWORD *)&v1[result] = 1;
*(_DWORD *)&v1[result + 32] = 0;
*(_QWORD *)&v1[result + 24] = 0LL;
*(_QWORD *)&v1[result + 16] = 0LL;
if ( i <= 1 )
{
*(_DWORD *)&v2[result] = 1;
*(_DWORD *)&v2[result + 32] = 0;
*(_QWORD *)&v2[result + 24] = 0LL;
*(_QWORD *)&v2[result + 16] = 0LL;
*(_DWORD *)&v3[result] = 1;
*(_DWORD *)&v3[result + 32] = 0;
*(_QWORD *)&v3[result + 24] = 0LL;
*(_QWORD *)&v3[result + 16] = 0LL;
*(_DWORD *)&v4[result] = 1;
*(_DWORD *)&v4[result + 32] = 0;
*(_QWORD *)&v4[result + 24] = 0LL;
*(_QWORD *)&v4[result + 16] = 0LL;
*(_DWORD *)(v5 + result) = 1;
*(_DWORD *)(v5 + result + 32) = 0;
*(_QWORD *)(v5 + result + 24) = 0LL;
*(_QWORD *)(v5 + result + 16) = 0LL;
goto LABEL_6;
}
if ( i == 3 )
break;
LABEL_6:
result += 40LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rbx
char *v1; // rbp
char *v2; // r12
char *v3; // r13
char *v4; // r14
__int64 v5; // rdx
__int64 result; // rax
unsigned int i; // ecx

v0 = (char *)malloc(0xA0uLL);
add_fp_rs = (__int64)v0;
v1 = (char *)malloc(0xA0uLL);
add_int_rs = (__int64)v1;
v2 = (char *)malloc(0x50uLL);
mul_fp_rs = (__int64)v2;
v3 = (char *)malloc(0x50uLL);
mul_int_rs = (__int64)v3;
v4 = (char *)malloc(0x50uLL);
ld_rs = (__int64)v4;
sd_rs = (__int64)malloc(0x50uLL);
v5 = sd_rs;
if ( v4 == 0LL || v3 == 0LL || v2 == 0LL || v0 == 0LL || v1 == 0LL || !sd_rs )
{
fprintf(stderr, "[FATAL] (%s:%d) Error creating the architecture\n", "tomasulo.c", 29LL);
exit(-1);
}
result = 0LL;
for ( i = 0; ; ++i )
{
*(_DWORD *)&v0[result] = 1;
*(_DWORD *)&v0[result + 32] = 0;
*(_QWORD *)&v0[result + 24] = 0LL;
*(_QWORD *)&v0[result + 16] = 0LL;
*(_DWORD *)&v1[result] = 1;
*(_DWORD *)&v1[result + 32] = 0;
*(_QWORD *)&v1[result + 24] = 0LL;
*(_QWORD *)&v1[result + 16] = 0LL;
if ( i <= 1 )
{
*(_DWORD *)&v2[result] = 1;
*(_DWORD *)&v2[result + 32] = 0;
*(_QWORD *)&v2[result + 24] = 0LL;
*(_QWORD *)&v2[result + 16] = 0LL;
*(_DWORD *)&v3[result] = 1;
*(_DWORD *)&v3[result + 32] = 0;
*(_QWORD *)&v3[result + 24] = 0LL;
*(_QWORD *)&v3[result + 16] = 0LL;
*(_DWORD *)&v4[result] = 1;
*(_DWORD *)&v4[result + 32] = 0;
*(_QWORD *)&v4[result + 24] = 0LL;
*(_QWORD *)&v4[result + 16] = 0LL;
*(_DWORD *)(v5 + result) = 1;
*(_DWORD *)(v5 + result + 32) = 0;
*(_QWORD *)(v5 + result + 24) = 0LL;
*(_QWORD *)(v5 + result + 16) = 0LL;
goto LABEL_6;
}
if ( i == 3 )
break;
LABEL_6:
result += 40LL;
}
return result;
}

original_code:
void create_arch()
{
 int i;
 add_fp_rs = malloc (4 * sizeof (RS));
 add_int_rs = malloc (4 * sizeof (RS));
 mul_fp_rs = malloc (2 * sizeof (RS));
 mul_int_rs = malloc (2 * sizeof (RS));
 ld_rs = malloc (2 * sizeof (RS));
 sd_rs = malloc (2 * sizeof (RS));
 if(!add_fp_rs || !add_int_rs || !mul_fp_rs || !mul_int_rs || !ld_rs || !sd_rs){
  do {fprintf(stderr, "[FATAL] (%s:%d) " "Error creating the architecture\n", "tomasulo.c", 29); exit(-1); } while (0);
 }
 for (i = 0; i < ((((2)>(2)?(2):(2)))>(((((4)>(2)?(4):(2)))>(((4)>(2)?(4):(2)))?(((4)>(2)?(4):(2))):(((4)>(2)?(4):(2)))))?(((2)>(2)?(2):(2))):(((((4)>(2)?(4):(2)))>(((4)>(2)?(4):(2)))?(((4)>(2)?(4):(2))):(((4)>(2)?(4):(2)))))); i++) {
  if (i < 4) {
   add_fp_rs[i].status = AVAILABLE;
   add_fp_rs[i].timer = 0;
   add_fp_rs[i].qj = add_fp_rs[i].qk = ((void *)0);
  }
  if (i < 4) {
   add_int_rs[i].status = AVAILABLE;
   add_int_rs[i].timer = 0;
   add_int_rs[i].qj = add_int_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   mul_fp_rs[i].status = AVAILABLE;
   mul_fp_rs[i].timer = 0;
   mul_fp_rs[i].qj = mul_fp_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   mul_int_rs[i].status = AVAILABLE;
   mul_int_rs[i].timer = 0;
   mul_int_rs[i].qj = mul_int_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   ld_rs[i].status = AVAILABLE;
   ld_rs[i].timer = 0;
   ld_rs[i].qj = ld_rs[i].qk = ((void *)0);
  }
  if (i < 2) {
   sd_rs[i].status = AVAILABLE;
   sd_rs[i].timer = 0;
   sd_rs[i].qj = sd_rs[i].qk = ((void *)0);
  }
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall dep_lookup(char *s2)
{
__int64 v1; // rbx
unsigned __int64 v2; // r12

if ( instr_proc - 1 <= 0 )
return 0LL;
v1 = iq + ((__int64)(instr_proc - 1) << 6);
v2 = v1 - 64 - ((unsigned __int64)(unsigned int)(instr_proc - 2) << 6);
do
{
if ( !strcmp(*(const char **)(v1 + 8), s2) )
return *(_QWORD *)(v1 + 40);
v1 -= 64LL;
}
while ( v1 != v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
__int64 v1; // rbx
unsigned __int64 v2; // r12

if ( instr_proc - 1 <= 0 )
return 0LL;
v1 = iq + ((__int64)(instr_proc - 1) << 6);
v2 = v1 - 64 - ((unsigned __int64)(unsigned int)(instr_proc - 2) << 6);
do
{
if ( !strcmp(*(const char **)(v1 + 8), s2) )
return *(_QWORD *)(v1 + 40);
v1 -= 64LL;
}
while ( v1 != v2 );
return 0LL;
}

original_code:
RS *dep_lookup(char *src)
{
 int instr = instr_proc-1;
 while(instr>0){
  if(!strcmp(iq[instr].dest,src)){
   return iq[instr].cur;
  }
  instr--;
 }
 return ((void *)0);
}

canonical_original_code:
struct resrv_stn *dep_lookup(char *src)
{
 int instr = instr_proc-1;
 while(instr>0){
  if(!strcmp(iq[instr].dest,src)){
   return iq[instr].cur;
  }
  instr--;
 }
 return ((void *)0);
}

variable_types:
src
char *

variable_types: instr int

return_type: struct resrv_stn { enum rs_status { UNKNOWN=0, AVAILABLE=1, BUSY=2, RESULT_READY=3 } status; struct Instruction { char *opcd; char *dest; char *src1; char *src2; int num_ops; int latency; struct resrv_stn *cur; unsigned int issue_time; unsigned int exec_time; unsigned int write_time; } *instr; struct resrv_stn *qj; struct resrv_stn *qk; int timer; } *

user_defined_types: struct resrv_stn { enum rs_status status; struct Instruction *instr; struct resrv_stn *qj; struct resrv_stn *qk; int timer; }


execute

decompiled_code:
__int64 execute()
{
update_rs_exec(0, 4u);
update_rs_exec(1, 2u);
update_rs_exec(2, 4u);
update_rs_exec(3, 2u);
update_rs_exec(4, 2u);
return update_rs_exec(5, 2u);
}

original_code:
void execute()
{
  update_rs_exec(0,4);
  update_rs_exec(1,2);
 update_rs_exec(2,4);
 update_rs_exec(3,2);
 update_rs_exec(4,2);
 update_rs_exec(5,2);
}


decompiled_code:
__int64 write_back()
{
update_rs_write(0, 4u);
update_rs_write(1, 2u);
update_rs_write(2, 4u);
update_rs_write(3, 2u);
update_rs_write(4, 2u);
return update_rs_write(5, 2u);
}

original_code:
void write_back()
{
  update_rs_write(0,4);
  update_rs_write(1,2);
 update_rs_write(2,4);
 update_rs_write(3,2);
 update_rs_write(4,2);
 update_rs_write(5,2);
}