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

for ( i = 0LL; i != 16; byte_40608F[i] = v3 )
{
v3 = *(_BYTE *)(a1 + i) ^ *((_BYTE *)&iv + i);
++i;
}
xrijndaelEncrypt_constprop_0();
if ( a2 )
*a2 = _mm_load_si128((const __m128i *)&iv);
}

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

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

variable_types:
out
unsigned char *

variable_types:
i
unsigned char


repo: ajtowns/altos

decompiled_code:
void ao_aes_init()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void
ao_aes_init(void)
{
}

canonical_original_code:
void ao_aes_init()
{
}

return_type: void


main

canonical_name: main

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

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

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

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

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

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

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

return_type: int


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

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

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

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


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

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

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

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

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

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

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

variable_types:
a
struct ao_int64_t *

variable_types:
d
unsigned char


decompiled_code:
__int64 __fastcall ao_neg64(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned int v3; // ecx
bool v4; // zf

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

canonical_decompiled_code:
__int64 __fastcall func16(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned int v3; // ecx
bool v4; // zf

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

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

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

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


test

decompiled_code:
__int64 __fastcall test(unsigned int a1, int *a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // [rsp-10h] [rbp-38h]
unsigned int v6; // [rsp+0h] [rbp-28h] BYREF
unsigned int v7; // [rsp+4h] [rbp-24h]
unsigned int v8; // [rsp+8h] [rbp-20h] BYREF
unsigned int v9; // [rsp+Ch] [rbp-1Ch]

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

canonical_decompiled_code:
__int64 __fastcall func21(unsigned int a1, int *a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // [rsp-10h] [rbp-38h]
unsigned int v6; // [rsp+0h] [rbp-28h] BYREF
unsigned int v7; // [rsp+4h] [rbp-24h]
unsigned int v8; // [rsp+8h] [rbp-20h] BYREF
unsigned int v9; // [rsp+Ch] [rbp-1Ch]

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

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

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

variable_types: trial int

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

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


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

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

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


decompiled_code:
__int64 __fastcall ao_pres_to_altitude(__int16 a1)
{
if ( a1 < 0 )
a1 = 0;
return (unsigned int)(((256 - (unsigned __int8)a1) * altitude_table[a1 >> 8]
+ altitude_table[(__int16)((a1 >> 8) + 1)] * (unsigned __int8)a1
+ 128) >> 8);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int16 a1)
{
if ( a1 < 0 )
a1 = 0;
return (unsigned int)(((256 - (unsigned __int8)a1) * altitude_table[a1 >> 8]
+ altitude_table[(__int16)((a1 >> 8) + 1)] * (unsigned __int8)a1
+ 128) >> 8);
}

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

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

variable_types: pres short

variable_types:
o
unsigned char

variable_types: part short

return_type: short


decompiled_code:
__int64 __fastcall ao_altitude_to_pres(__int16 a1)
{
int v2; // esi
int v3; // edx
int v4; // ecx
__int16 v5; // di
int v6; // esi
__int64 result; // rax

LOBYTE(v2) = 0;
v3 = 128;
LABEL_2:
v4 = (unsigned __int8)v2;
while ( v3 - v4 != 1 )
{
v2 = (v3 + v4) >> 1;
if ( altitude_table[v2] >= a1 )
goto LABEL_2;
v3 = (unsigned __int8)v2;
}
v5 = altitude_table[v4] - altitude_table[v3];
v6 = (__int16)(altitude_table[v4] - a1);
result = (unsigned int)(((((v5 - v6) * v4 + v6 * v3) << 8) + (v5 >> 1)) / v5);
if ( (int)result < 0 )
result = 0LL;
if ( (int)result > 0x7FFF )
result = 0x7FFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int16 a1)
{
int v2; // esi
int v3; // edx
int v4; // ecx
__int16 v5; // di
int v6; // esi
__int64 result; // rax

LOBYTE(v2) = 0;
v3 = 128;
LABEL_2:
v4 = (unsigned __int8)v2;
while ( v3 - v4 != 1 )
{
v2 = (v3 + v4) >> 1;
if ( altitude_table[v2] >= a1 )
goto LABEL_2;
v3 = (unsigned __int8)v2;
}
v5 = altitude_table[v4] - altitude_table[v3];
v6 = (__int16)(altitude_table[v4] - a1);
result = (unsigned int)(((((v5 - v6) * v4 + v6 * v3) << 8) + (v5 >> 1)) / v5);
if ( (int)result < 0 )
result = 0LL;
if ( (int)result > 0x7FFF )
result = 0x7FFFLL;
return result;
}

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

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

variable_types: alt short

variable_types: span short

variable_types:
l
unsigned char

variable_types:
h
unsigned char

variable_types:
m
unsigned char

variable_types: pres int


repo: akaehy/Project

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

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

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

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

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

variable_types:
arg
void *

variable_types: id int

return_type: void *


main

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

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

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

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

variable_types: argc int

variable_types:
argv
char **

variable_types:
threads
unsigned long [10]

variable_types: code int

variable_types: i int


partition

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

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

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

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

variable_types:
n
unsigned int

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


main

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

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

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

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

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

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


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

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

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

variable_types:
a
void *

variable_types:
b
void *


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

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

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

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

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


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

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

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


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

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

variable_types:
num
int [5]

variable_types:
strp
char *[5]

variable_types:
maxstrp
char **

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

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


max

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

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

variable_types:
base
void *

variable_types: len int

variable_types: size int

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

variable_types:
baseaddr
char *

variable_types:
maxp
char *


mydiv

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

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

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

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

variable_types: a int

variable_types: b int


main

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

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

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

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

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

variable_types: c char

variable_types: i int


add

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

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

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

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


sub

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

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

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

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


mul

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

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

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

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


insertrecord

decompiled_code:
__int64 __fastcall insertrecord(__int64 a1, __int64 a2)
{
int v2; // ebx
float *v3; // r13
__int64 v4; // rbp
int *v5; // rdx
float v6; // xmm0_4

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // ebx
float *v3; // r13
__int64 v4; // rbp
int *v5; // rdx
float v6; // xmm0_4

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

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

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

variable_types:
filename
char *

variable_types:
head
struct node *

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

variable_types: ID int


myitoa

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

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

variable_types: n int

variable_types:
str
char *

variable_types: radix int

variable_types: j int

variable_types: remain int

variable_types: tmp char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
myprintf((unsigned int)"%d, %o, %x, %c, %s, %%, %f\n", 1248, 8, 15, 65, (unsigned int)"abcd");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8((unsigned int)"%d, %o, %x, %c, %s, %%, %f\n", 1248, 8, 15, 65, (unsigned int)"abcd");
return 0;
}


deleterecord

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

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

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

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

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

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

variable_types: selnum int

variable_types: flag int

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


showinfo

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

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

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

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


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

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

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

variable_types:
p
void *


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

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

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

variable_types:
arg
void *

variable_types: fd int


main

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

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

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

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

variable_types: argc int

variable_types:
argv
char **

variable_types:
tid
unsigned long

variable_types: code int


decompiled_code:
void *__fastcall start_routine(void *a1)
{
int v1; // ebx
int *v3; // rax
char *v4; // rax
int fd; // [rsp+Ch] [rbp-10Ch]
void *ptr; // [rsp+10h] [rbp-108h]
int oldstate; // [rsp+28h] [rbp-F0h] BYREF
int oldtype; // [rsp+2Ch] [rbp-ECh] BYREF
struct __jmp_buf_tag env; // [rsp+30h] [rbp-E8h] BYREF

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

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebx
int *v3; // rax
char *v4; // rax
int fd; // [rsp+Ch] [rbp-10Ch]
void *ptr; // [rsp+10h] [rbp-108h]
int oldstate; // [rsp+28h] [rbp-F0h] BYREF
int oldtype; // [rsp+2Ch] [rbp-ECh] BYREF
struct __jmp_buf_tag env; // [rsp+30h] [rbp-E8h] BYREF

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

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

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

variable_types: oldstate int

variable_types: oldtype int

variable_types:
p
char *

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

variable_types: i int


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

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

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

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

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

variable_types: value int

variable_types:
buffer
char [1024]


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

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

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

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

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


printstr

decompiled_code:
// attributes: thunk
int printstr(const char *s)
{
return puts(s);
}

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

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

variable_types:
str
void *


printnum

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

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

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

variable_types:
n
void *


printmsg

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

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

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

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

variable_types:
fp
void (*)(void *)


main

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

printmsg(printstr, "hello", envp);
printmsg(printnum, 123LL, v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx

func9(printstr, "hello", envp);
func9(printnum, 123LL, v3);
return 0;
}

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

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


showstu

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


showinfo

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

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

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

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


main

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

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

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

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

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

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

variable_types:
argv
char *[]

variable_types: selnum int

variable_types: flagbyaverage int

variable_types: firstsort int

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


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

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

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

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

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

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

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

variable_types: len int


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

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

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

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

variable_types:
msg
char *


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

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

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

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

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

variable_types: sign int


display

decompiled_code:
int __fastcall display(__int64 a1, int a2)
{
int result; // eax
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rcx
__int64 v6; // r8
const char *v7; // rdx
__int64 v8; // rsi

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

canonical_decompiled_code:
int __fastcall func10(__int64 a1, int a2)
{
int result; // eax
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rcx
__int64 v6; // r8
const char *v7; // rdx
__int64 v8; // rsi

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

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

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

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


sort

original_code:
void sort(std_t *stdp, int len, int sign)
{
    int i, j, pos;
    std_t tmp;
    printf("in sort...\n");
    for(i = 0; i < len - 1; i++){
        pos = i;
        for(j = i + 1; j < len; j++){
            switch(sign){
            case 1:if(stdp[pos].average < stdp[j].average)
                    pos = j;
                  break;
            case 2:if(stdp[pos].id > stdp[j].id)
                        pos = j;
                    break;
            }
        }
        if(pos != i){
            tmp = stdp[pos];
            stdp[pos] = stdp[i];
            stdp[i] = tmp;
        }
    }
    if(sign == 1)
        display(stdp, len);
}

canonical_original_code:
void sort(struct std_t *stdp, int len, int sign)
{
    int i; int j; int pos;
    struct std_t tmp;
    printf("in sort...\n");
    for(i = 0; i < len - 1; i++){
        pos = i;
        for(j = i + 1; j < len; j++){
            switch(sign){
            case 1:if(stdp[pos].average < stdp[j].average)
                    pos = j;
                  break;
            case 2:if(stdp[pos].id > stdp[j].id)
                        pos = j;
                    break;
            }
        }
        if(pos != i){
            tmp = stdp[pos];
            stdp[pos] = stdp[i];
            stdp[i] = tmp;
        }
    }
    if(sign == 1)
        display(stdp, len);
}

variable_types: j int

variable_types: pos int

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


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


decompiled_code:
void __noreturn err_sys(char *format, ...)
{
int v1; // ebp
char *v2; // r12
size_t v3; // rax
size_t v4; // rax
FILE *v5; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-140h] BYREF
char s[2]; // [rsp+20h] [rbp-128h] BYREF

va_start(arg, format);
v1 = *__errno_location();
vsnprintf(s, 0x50uLL, format, arg);
v2 = strerror(v1);
v3 = strlen(s);
snprintf(&s[v3], 80 - v3, " : %s", v2);
v4 = strlen(s);
v5 = _bss_start;
*(_WORD *)&s[v4] = 10;
fputs(s, v5);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7(char *format, ...)
{
int v1; // ebp
char *v2; // r12
size_t v3; // rax
size_t v4; // rax
FILE *v5; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-140h] BYREF
char s[2]; // [rsp+20h] [rbp-128h] BYREF

va_start(arg, format);
v1 = *__errno_location();
vsnprintf(s, 0x50uLL, format, arg);
v2 = strerror(v1);
v3 = strlen(s);
snprintf(&s[v3], 80 - v3, " : %s", v2);
v4 = strlen(s);
v5 = _bss_start;
*(_WORD *)&s[v4] = 10;
fputs(s, v5);
exit(1);
}

original_code:
void err_sys(const char *fmt,...)
{
  int err = (*__errno_location ());
  char buf[80 +1];
  va_list ap;
  __builtin_va_start(ap,fmt);
  vsnprintf(buf, 80, fmt, ap);
  snprintf(buf+strlen(buf), 80 -strlen(buf), " : %s", strerror(err));
  strcat(buf, "\n");
  fputs(buf, stderr);
  __builtin_va_end(ap);
  exit(1);
}

canonical_original_code:
void err_sys(char *fmt, ...)
{
  int err = (*__errno_location ());
  char buf[-1];
  __builtin_va_list ap;
  __builtin_va_start(ap,fmt);
  vsnprintf(buf, 80, fmt, ap);
  snprintf(buf+strlen(buf), 80 -strlen(buf), " : %s", strerror(err));
  strcat(buf, "\n");
  fputs(buf, stderr);
  __builtin_va_end(ap);
  exit(1);
}

variable_types:
fmt
char *

variable_types: err int

variable_types:
buf
char [-1]


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

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

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

variable_types: a int

variable_types: b int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
unsigned int v5; // eax

puts("hello!");
v3 = atoi(argv[2]);
v4 = atoi(argv[1]);
v5 = my_div(v4, v3);
printf("div:%d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
unsigned int v5; // eax

puts("hello!");
v3 = atoi(argv[2]);
v4 = atoi(argv[1]);
v5 = func7(v4, v3);
printf("div:%d\n", v5);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 printf("hello!\n");
 printf("div:%d\n", my_div(atoi(argv[1]), atoi(argv[2])));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
char *__fastcall get_a_day(int a1)
{
strcpy(buf_0, (&msg)[a1]);
return buf_0;
}

canonical_decompiled_code:
char *__fastcall func7(int a1)
{
strcpy(buf_0, (&msg)[a1]);
return buf_0;
}

original_code:
char *get_a_day(int idx)
{
 static char buf[20];
 strcpy(buf, msg[idx]);
 return buf;
}

variable_types: idx int

variable_types:
buf
char [20]

return_type: char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx
const char *v5; // rax

v3 = (const char *)get_a_day(1LL, argv, envp);
v5 = (const char *)get_a_day(0LL, argv, v4);
printf("%s %s\n", v5, v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx
const char *v5; // rax

v3 = (const char *)func7(1LL, argv, envp);
v5 = (const char *)func7(0LL, argv, v4);
printf("%s %s\n", v5, v3);
return 0;
}

original_code:
int main(void)
{
 printf("%s %s\n", get_a_day(0), get_a_day(1));
 return 0;
}

canonical_original_code:
int main()
{
 printf("%s %s\n", get_a_day(0), get_a_day(1));
 return 0;
}


repo: akashgangil/LRVM

decompiled_code:
__int64 __fastcall rvm_begin_trans(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
int v4; // ebp
__int64 v6; // rdi
__int64 v7; // rax
unsigned int v10; // er8
__int64 *v11; // rsi
__int64 v12; // rcx
__int64 v13; // rax

v4 = a3;
fprintf(stdout, "Begin transaction on %d segments\n", a3);
v6 = segment_list;
if ( v4 <= 0 )
return (unsigned int)global_tid++;
if ( segment_list )
{
v7 = segment_list;
while ( *(_QWORD *)(*(_QWORD *)v7 + 16LL) != *a4 || *(_DWORD *)(v7 + 8) == -1 )
{
v7 = *(_QWORD *)(v7 + 24);
if ( !v7 )
goto LABEL_9;
}
return (unsigned int)-1;
}
LABEL_9:
v10 = global_tid;
v11 = a4;
++global_tid;
do
{
if ( v6 )
{
v12 = *v11;
v13 = v6;
do
{
while ( *(_QWORD *)(*(_QWORD *)v13 + 16LL) != v12 )
{
v13 = *(_QWORD *)(v13 + 24);
if ( !v13 )
goto LABEL_15;
}
*(_DWORD *)(v13 + 8) = v10;
v13 = *(_QWORD *)(v13 + 24);
}
while ( v13 );
}
LABEL_15:
++v11;
}
while ( &a4[(unsigned int)(v4 - 1) + 1] != v11 );
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
int v4; // ebp
__int64 v6; // rdi
__int64 v7; // rax
unsigned int v10; // er8
__int64 *v11; // rsi
__int64 v12; // rcx
__int64 v13; // rax

v4 = a3;
fprintf(stdout, "Begin transaction on %d segments\n", a3);
v6 = segment_list;
if ( v4 <= 0 )
return (unsigned int)global_tid++;
if ( segment_list )
{
v7 = segment_list;
while ( *(_QWORD *)(*(_QWORD *)v7 + 16LL) != *a4 || *(_DWORD *)(v7 + 8) == -1 )
{
v7 = *(_QWORD *)(v7 + 24);
if ( !v7 )
goto LABEL_9;
}
return (unsigned int)-1;
}
LABEL_9:
v10 = global_tid;
v11 = a4;
++global_tid;
do
{
if ( v6 )
{
v12 = *v11;
v13 = v6;
do
{
while ( *(_QWORD *)(*(_QWORD *)v13 + 16LL) != v12 )
{
v13 = *(_QWORD *)(v13 + 24);
if ( !v13 )
goto LABEL_15;
}
*(_DWORD *)(v13 + 8) = v10;
v13 = *(_QWORD *)(v13 + 24);
}
while ( v13 );
}
LABEL_15:
++v11;
}
while ( &a4[(unsigned int)(v4 - 1) + 1] != v11 );
return v10;
}

original_code:
trans_t rvm_begin_trans(rvm_t rvm, int num_segs, void** seg_bases){
    fprintf(stdout, "Begin transaction on %d segments\n", num_segs);
    segment_list_t* seg_node = segment_list;
    int seg_it = 0;
    for(seg_it=0; seg_it < num_segs; ++seg_it){
        while(seg_node!= ((void *)0)){
            if(seg_node->segment->data == seg_bases[seg_it])
                if(seg_node->txn != -1) return (trans_t)-1;
            seg_node = seg_node -> next_seg;
        }
    }
    trans_t tid = global_tid++;
    seg_it = 0;
    for(seg_it=0; seg_it<num_segs; ++seg_it){
        seg_node = segment_list;
        while(seg_node != ((void *)0)){
            if(seg_node->segment->data == seg_bases[seg_it]) {
                seg_node->txn = tid;
            }
            seg_node = seg_node -> next_seg;
        }
    }
    return tid;
}

canonical_original_code:
int rvm_begin_trans(struct rvm_t rvm, int num_segs, void **seg_bases){
    fprintf(stdout, "Begin transaction on %d segments\n", num_segs);
    struct seg_node *seg_node = segment_list;
    int seg_it = 0;
    for(seg_it=0; seg_it < num_segs; ++seg_it){
        while(seg_node!= ((void *)0)){
            if(seg_node->segment->data == seg_bases[seg_it])
                if(seg_node->txn != -1) return (trans_t)-1;
            seg_node = seg_node -> next_seg;
        }
    }
    int tid = global_tid++;
    seg_it = 0;
    for(seg_it=0; seg_it<num_segs; ++seg_it){
        seg_node = segment_list;
        while(seg_node != ((void *)0)){
            if(seg_node->segment->data == seg_bases[seg_it]) {
                seg_node->txn = tid;
            }
            seg_node = seg_node -> next_seg;
        }
    }
    return tid;
}

variable_types: struct rvm_t { char *directory; char *logfile; }

variable_types: struct seg_node { struct segment_t { char *name; int size; void *data; } *segment; int txn; struct offset_node { int offset_val; int size; struct offset_node *next_offset; } *offset; struct seg_node *next_seg; } *

variable_types: tid int

user_defined_types: struct seg_node { struct segment_t *segment; int txn; struct offset_node *offset; struct seg_node *next_seg; }


decompiled_code:
int check_segment_list()
{
__int64 i; // rbp
int result; // eax
unsigned int *j; // rbx

for ( i = segment_list; i; i = *(_QWORD *)(i + 24) )
{
puts("A NODE!!!!");
printf("TXN Id : %d\n", *(unsigned int *)(i + 8));
printf("Name : %s\n", **(const char ***)i);
result = printf("SIZE: %d\n", *(unsigned int *)(*(_QWORD *)i + 8LL));
for ( j = *(unsigned int **)(i + 16); j; j = (unsigned int *)*((_QWORD *)j + 1) )
{
printf("Offset: %d\n", *j);
printf("SIZE: %d\n", j[1]);
result = printf("Data: %s\n", (const char *)(*(_QWORD *)(*(_QWORD *)i + 16LL) + (int)*j));
}
}
return result;
}

canonical_decompiled_code:
int func1()
{
__int64 i; // rbp
int result; // eax
unsigned int *j; // rbx

for ( i = segment_list; i; i = *(_QWORD *)(i + 24) )
{
puts("A NODE!!!!");
printf("TXN Id : %d\n", *(unsigned int *)(i + 8));
printf("Name : %s\n", **(const char ***)i);
result = printf("SIZE: %d\n", *(unsigned int *)(*(_QWORD *)i + 8LL));
for ( j = *(unsigned int **)(i + 16); j; j = (unsigned int *)*((_QWORD *)j + 1) )
{
printf("Offset: %d\n", *j);
printf("SIZE: %d\n", j[1]);
result = printf("Data: %s\n", (const char *)(*(_QWORD *)(*(_QWORD *)i + 16LL) + (int)*j));
}
}
return result;
}

original_code:
void check_segment_list(){
    segment_list_t* segment_node = segment_list;
    while(segment_node != ((void *)0)){
        printf("A NODE!!!!\n");
        printf("TXN Id : %d\n",segment_node->txn);
        printf("Name   : %s\n", segment_node->segment->name);
        printf("SIZE:    %d\n", segment_node->segment->size);
        offset_t* base_offset = segment_node->offset;
        while(base_offset != ((void *)0)) {
            printf("Offset:  %d\n", base_offset->offset_val);
            printf("SIZE: %d\n", base_offset->size);
            printf("Data:    %s\n", (char*)segment_node->segment->data + base_offset->offset_val);
            base_offset = base_offset -> next_offset;
        }
        segment_node = segment_node -> next_seg;
    }
}

canonical_original_code:
void check_segment_list(){
    struct seg_node *segment_node = segment_list;
    while(segment_node != ((void *)0)){
        printf("A NODE!!!!\n");
        printf("TXN Id : %d\n",segment_node->txn);
        printf("Name   : %s\n", segment_node->segment->name);
        printf("SIZE:    %d\n", segment_node->segment->size);
        struct offset_node *base_offset = segment_node->offset;
        while(base_offset != ((void *)0)) {
            printf("Offset:  %d\n", base_offset->offset_val);
            printf("SIZE: %d\n", base_offset->size);
            printf("Data:    %s\n", (char *)segment_node->segment->data + base_offset->offset_val);
            base_offset = base_offset -> next_offset;
        }
        segment_node = segment_node -> next_seg;
    }
}

variable_types: struct offset_node { int offset_val; int size; struct offset_node *next_offset; } *

user_defined_types: struct segment_t { char *name; int size; void *data; }


decompiled_code:
int __fastcall rvm_about_to_modify(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 i; // rbx
_DWORD *v8; // rax
_DWORD *v9; // rdx
__int64 v10; // rcx

LODWORD(v6) = fprintf(stdout, "About to modify segment in transaction %d with offset %d and size %d\n", a1, a3, a4);
for ( i = segment_list; i; i = *(_QWORD *)(i + 24) )
{
while ( 1 )
{
if ( *(_DWORD *)(i + 8) == a1 )
{
v6 = *(_QWORD *)i;
if ( *(_QWORD *)(*(_QWORD *)i + 16LL) == a2 )
break;
}
LABEL_3:
i = *(_QWORD *)(i + 24);
if ( !i )
return v6;
}
v8 = malloc(0x10uLL);
*v8 = a3;
v9 = v8;
v8[1] = a4;
*((_QWORD *)v8 + 1) = 0LL;
v6 = *(_QWORD *)(i + 16);
if ( v6 )
{
do
{
v10 = v6;
v6 = *(_QWORD *)(v6 + 8);
}
while ( v6 );
*(_QWORD *)(v10 + 8) = v9;
goto LABEL_3;
}
*(_QWORD *)(i + 16) = v9;
}
return v6;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 i; // rbx
_DWORD *v8; // rax
_DWORD *v9; // rdx
__int64 v10; // rcx

LODWORD(v6) = fprintf(stdout, "About to modify segment in transaction %d with offset %d and size %d\n", a1, a3, a4);
for ( i = segment_list; i; i = *(_QWORD *)(i + 24) )
{
while ( 1 )
{
if ( *(_DWORD *)(i + 8) == a1 )
{
v6 = *(_QWORD *)i;
if ( *(_QWORD *)(*(_QWORD *)i + 16LL) == a2 )
break;
}
LABEL_3:
i = *(_QWORD *)(i + 24);
if ( !i )
return v6;
}
v8 = malloc(0x10uLL);
*v8 = a3;
v9 = v8;
v8[1] = a4;
*((_QWORD *)v8 + 1) = 0LL;
v6 = *(_QWORD *)(i + 16);
if ( v6 )
{
do
{
v10 = v6;
v6 = *(_QWORD *)(v6 + 8);
}
while ( v6 );
*(_QWORD *)(v10 + 8) = v9;
goto LABEL_3;
}
*(_QWORD *)(i + 16) = v9;
}
return v6;
}

original_code:
void rvm_about_to_modify(trans_t tid, void* seg_base, int offset, int size){
    fprintf(stdout, "About to modify segment in transaction %d with offset %d and size %d\n",
            tid, offset, size);
    segment_list_t* seg_node = segment_list;
    while(seg_node != ((void *)0)){
        if(seg_node->txn == tid && seg_node->segment->data == seg_base){
            offset_t* new_offset = (offset_t*)malloc(sizeof(offset_t));
            new_offset -> offset_val = offset;
            new_offset -> size = size;
            new_offset -> next_offset = ((void *)0);
            offset_t* seg_offset = seg_node->offset;
            if(seg_offset == ((void *)0)){
                seg_node->offset = new_offset;
            }
            else{
                while(seg_offset -> next_offset != ((void *)0))
                    seg_offset = seg_offset->next_offset;
                seg_offset->next_offset = new_offset;
            }
        }
        seg_node = seg_node -> next_seg;
    }
}

canonical_original_code:
void rvm_about_to_modify(int tid, void *seg_base, int offset, int size){
    fprintf(stdout, "About to modify segment in transaction %d with offset %d and size %d\n",
            tid, offset, size);
    struct seg_node *seg_node = segment_list;
    while(seg_node != ((void *)0)){
        if(seg_node->txn == tid && seg_node->segment->data == seg_base){
            struct offset_node *new_offset = (offset_t*)malloc(sizeof(offset_t));
            new_offset -> offset_val = offset;
            new_offset -> size = size;
            new_offset -> next_offset = ((void *)0);
            struct offset_node *seg_offset = seg_node->offset;
            if(seg_offset == ((void *)0)){
                seg_node->offset = new_offset;
            }
            else{
                while(seg_offset -> next_offset != ((void *)0))
                    seg_offset = seg_offset->next_offset;
                seg_offset->next_offset = new_offset;
            }
        }
        seg_node = seg_node -> next_seg;
    }
}

variable_types: offset int

variable_types: size int

user_defined_types: struct offset_node { int offset_val; int size; struct offset_node *next_offset; }


decompiled_code:
void __fastcall rvm_unmap(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rsi
_QWORD *v5; // rdi
_QWORD *v6; // rcx
__int64 v7; // rax

fwrite("Unmap the segment\n", 1uLL, 0x12uLL, stdout);
v4 = segment_list;
if ( segment_list )
{
while ( 2 )
{
v5 = (_QWORD *)v4;
v6 = 0LL;
while ( 1 )
{
v7 = v5[3];
if ( *(_QWORD *)(*v5 + 16LL) == a3 )
{
if ( v6 )
v6[3] = v7;
else
segment_list = v5[3];
free(v5);
return;
}
v6 = v5;
if ( !v7 )
break;
v5 = (_QWORD *)v5[3];
}
v4 = *(_QWORD *)(v4 + 24);
if ( v4 )
continue;
break;
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rsi
_QWORD *v5; // rdi
_QWORD *v6; // rcx
__int64 v7; // rax

fwrite("Unmap the segment\n", 1uLL, 0x12uLL, stdout);
v4 = segment_list;
if ( segment_list )
{
while ( 2 )
{
v5 = (_QWORD *)v4;
v6 = 0LL;
while ( 1 )
{
v7 = v5[3];
if ( *(_QWORD *)(*v5 + 16LL) == a3 )
{
if ( v6 )
v6[3] = v7;
else
segment_list = v5[3];
free(v5);
return;
}
v6 = v5;
if ( !v7 )
break;
v5 = (_QWORD *)v5[3];
}
v4 = *(_QWORD *)(v4 + 24);
if ( v4 )
continue;
break;
}
}
}

original_code:
void rvm_unmap(rvm_t rvm, void* seg_base){
    fprintf(stdout, "Unmap the segment\n");
    segment_list_t* seg_node = segment_list;
    while(seg_node != ((void *)0)){
        segment_list_t *currP, *prevP;
        prevP = ((void *)0);
        for (currP = seg_node; currP != ((void *)0); prevP = currP, currP = currP->next_seg) {
            if (currP->segment->data == seg_base) {
                if (prevP == ((void *)0)) {
                     segment_list = currP->next_seg;
                } else {
                     prevP->next_seg = currP->next_seg;
                }
                free(currP);
                return;
            }
        }
        seg_node = seg_node -> next_seg;
    }
}

canonical_original_code:
void rvm_unmap(struct rvm_t rvm, void *seg_base){
    fprintf(stdout, "Unmap the segment\n");
    struct seg_node *seg_node = segment_list;
    while(seg_node != ((void *)0)){
        struct seg_node *currP; struct seg_node *prevP;
        prevP = ((void *)0);
        for (currP = seg_node; currP != ((void *)0); prevP = currP, currP = currP->next_seg) {
            if (currP->segment->data == seg_base) {
                if (prevP == ((void *)0)) {
                     segment_list = currP->next_seg;
                } else {
                     prevP->next_seg = currP->next_seg;
                }
                free(currP);
                return;
            }
        }
        seg_node = seg_node -> next_seg;
    }
}

user_defined_types: struct rvm_t { char *directory; char *logfile; }


decompiled_code:
_BOOL8 __fastcall file_exist(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

original_code:
int file_exist (char *filename)
{
    struct stat buffer;
    return (stat(filename, &buffer) == 0);
}

canonical_original_code:
int file_exist(char *filename)
{
    struct stat buffer;
    return (stat(filename, &buffer) == 0);
}

variable_types:
filename
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
const char *__fastcall rvm_init(void *src)
{
const char **v1; // rbx
size_t v2; // rax
size_t v3; // r14
size_t v4; // rbp
char *v5; // r13
char *v6; // rax

fprintf(stdout, "Initialize the rvm library with the directory %s\n", (const char *)src);
segment_list = 0LL;
v1 = (const char **)malloc(0x10uLL);
rvm = (__int64)v1;
v2 = strlen((const char *)src);
v3 = v2 + 1;
v4 = v2;
v5 = (char *)malloc(v2 + 1);
*v1 = v5;
memcpy(v5, src, v3);
v6 = (char *)malloc(v4 + 5);
v1[1] = v6;
strcpy((char *)memcpy(v6, src, v4) + v4, ".log");
if ( file_exist(v5) || !mkdir(*v1, 0x1FDu) )
return *v1;
fwrite("Failed to create RVM directory\n", 1uLL, 0x1FuLL, stderr);
return *(const char **)rvm;
}

canonical_decompiled_code:
const char *__fastcall func5(void *src)
{
const char **v1; // rbx
size_t v2; // rax
size_t v3; // r14
size_t v4; // rbp
char *v5; // r13
char *v6; // rax

fprintf(stdout, "Initialize the rvm library with the directory %s\n", (const char *)src);
segment_list = 0LL;
v1 = (const char **)malloc(0x10uLL);
rvm = (__int64)v1;
v2 = strlen((const char *)src);
v3 = v2 + 1;
v4 = v2;
v5 = (char *)malloc(v2 + 1);
*v1 = v5;
memcpy(v5, src, v3);
v6 = (char *)malloc(v4 + 5);
v1[1] = v6;
strcpy((char *)memcpy(v6, src, v4) + v4, ".log");
if ( func4(v5) || !mkdir(*v1, 0x1FDu) )
return *v1;
fwrite("Failed to create RVM directory\n", 1uLL, 0x1FuLL, stderr);
return *(const char **)rvm;
}

original_code:
rvm_t rvm_init(const char* directory) {
    fprintf(stdout, "Initialize the rvm library with the directory %s\n", directory);
    segment_list = (segment_list_t*) malloc( sizeof(segment_list_t*) );
    segment_list = ((void *)0);
    rvm = (rvm_t*) malloc( sizeof(rvm_t) );
    rvm->directory = (char*) malloc( strlen(directory) + 1 );
    strcpy(rvm -> directory, directory);
    rvm->logfile = (char*) malloc(strlen(directory) + strlen(log_file_ext) + 1);
    strcpy(rvm->logfile, directory);
    strcat(rvm->logfile, log_file_ext);
    if(!file_exist(rvm->directory)){
        if(mkdir(rvm->directory, (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) != 0){
            fprintf(stderr,"Failed to create RVM directory\n");
            return *rvm;
        }
    }
    return *rvm;
}

canonical_original_code:
struct rvm_t rvm_init(char *directory) {
    fprintf(stdout, "Initialize the rvm library with the directory %s\n", directory);
    segment_list = (struct seg_node *) malloc( sizeof(struct seg_node *) );
    segment_list = ((void *)0);
    rvm = (struct rvm_t *) malloc( sizeof(rvm_t) );
    rvm->directory = (char *) malloc( strlen(directory) + 1 );
    strcpy(rvm -> directory, directory);
    rvm->logfile = (char *) malloc(strlen(directory) + strlen(log_file_ext) + 1);
    strcpy(rvm->logfile, directory);
    strcat(rvm->logfile, log_file_ext);
    if(!file_exist(rvm->directory)){
        if(mkdir(rvm->directory, (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) != 0){
            fprintf(stderr,"Failed to create RVM directory\n");
            return *rvm;
        }
    }
    return *rvm;
}

variable_types:
directory
char *

return_type: struct rvm_t { char *directory; char *logfile; }


decompiled_code:
char *__fastcall get_seg_file_path(void *src)
{
const void *v1; // r15
size_t v2; // rbx
size_t v3; // rax
size_t v4; // r14
size_t v5; // r13
char *v6; // r12

v1 = *(const void **)rvm;
v2 = strlen(*(const char **)rvm);
v3 = strlen((const char *)src);
v4 = v2 + v3;
v5 = v3;
v6 = (char *)malloc(v2 + v3 + 5);
memcpy(v6, v1, v2);
v6[v2] = 47;
memcpy(&v6[v2 + 1], src, v5);
strcpy(&v6[v4 + 1], ".seg");
return v6;
}

canonical_decompiled_code:
char *__fastcall func6(void *src)
{
const void *v1; // r15
size_t v2; // rbx
size_t v3; // rax
size_t v4; // r14
size_t v5; // r13
char *v6; // r12

v1 = *(const void **)rvm;
v2 = strlen(*(const char **)rvm);
v3 = strlen((const char *)src);
v4 = v2 + v3;
v5 = v3;
v6 = (char *)malloc(v2 + v3 + 5);
memcpy(v6, v1, v2);
v6[v2] = 47;
memcpy(&v6[v2 + 1], src, v5);
strcpy(&v6[v4 + 1], ".seg");
return v6;
}

original_code:
char* get_seg_file_path(const char* seg_name){
    char *seg_path = (char*) malloc( strlen(rvm->directory)
            + strlen(seg_name) + strlen(seg_file_ext)+1);
    strcpy(seg_path, rvm->directory);
    strcat(seg_path, "/");
    strcat(seg_path, seg_name);
    strcat(seg_path, seg_file_ext);
    return seg_path;
}

canonical_original_code:
char *get_seg_file_path(char *seg_name){
    char *seg_path = (char*) malloc( strlen(rvm->directory)
            + strlen(seg_name) + strlen(seg_file_ext)+1);
    strcpy(seg_path, rvm->directory);
    strcat(seg_path, "/");
    strcat(seg_path, seg_name);
    strcat(seg_path, seg_file_ext);
    return seg_path;
}


decompiled_code:
void __fastcall rvm_destroy(__int64 a1, __int64 a2, char *a3)
{
__int64 v4; // rbx
char *v5; // rbp

fprintf(stdout, "Destroy the segment %s\n", a3);
v4 = segment_list;
if ( segment_list )
{
while ( !strcmp(a3, **(const char ***)v4) )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
goto LABEL_6;
}
fwrite("Segment is currently mapped. Failed to delete", 1uLL, 0x2DuLL, stderr);
}
else
{
LABEL_6:
v5 = get_seg_file_path(a3);
if ( file_exist(v5) )
{
if ( rmdir(v5) )
fprintf(stderr, "Error deleting segment: %s\n", v5);
}
free(v5);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2, char *a3)
{
__int64 v4; // rbx
char *v5; // rbp

fprintf(stdout, "Destroy the segment %s\n", a3);
v4 = segment_list;
if ( segment_list )
{
while ( !strcmp(a3, **(const char ***)v4) )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
goto LABEL_6;
}
fwrite("Segment is currently mapped. Failed to delete", 1uLL, 0x2DuLL, stderr);
}
else
{
LABEL_6:
v5 = func6(a3);
if ( func4(v5) )
{
if ( rmdir(v5) )
fprintf(stderr, "Error deleting segment: %s\n", v5);
}
free(v5);
}
}

original_code:
void rvm_destroy(rvm_t rvm, const char* seg_name){
    fprintf(stdout, "Destroy the segment %s\n", seg_name);
    segment_list_t* seg_node = segment_list;
    while(seg_node != ((void *)0)){
        if(strcmp(seg_name, seg_node->segment->name)){
            fprintf(stderr, "Segment is currently mapped. Failed to delete");
            return;
        }
        seg_node = seg_node->next_seg;
    }
    char* seg_path = get_seg_file_path(seg_name);
    if(file_exist(seg_path)){
        if(rmdir(seg_path)){
            fprintf(stderr, "Error deleting segment: %s\n", seg_path);
        }
    }
    free(seg_path);
}

canonical_original_code:
void rvm_destroy(struct rvm_t rvm, char *seg_name){
    fprintf(stdout, "Destroy the segment %s\n", seg_name);
    struct seg_node *seg_node = segment_list;
    while(seg_node != ((void *)0)){
        if(strcmp(seg_name, seg_node->segment->name)){
            fprintf(stderr, "Segment is currently mapped. Failed to delete");
            return;
        }
        seg_node = seg_node->next_seg;
    }
    char *seg_path = get_seg_file_path(seg_name);
    if(file_exist(seg_path)){
        if(rmdir(seg_path)){
            fprintf(stderr, "Error deleting segment: %s\n", seg_path);
        }
    }
    free(seg_path);
}


decompiled_code:
__int64 __fastcall rvm_map(__int64 a1, __int64 a2, char *a3, int a4)
{
_DWORD *v6; // rbx
char *v7; // rax
void *v8; // rax
_QWORD *v9; // rax
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rcx

fprintf(stdout, "Map the segment %s\n", a3);
v6 = calloc(1uLL, 0x18uLL);
v7 = (char *)malloc(8uLL);
*(_QWORD *)v6 = v7;
strcpy(v7, a3);
v8 = malloc(a4);
v6[2] = a4;
*((_QWORD *)v6 + 2) = v8;
v9 = malloc(0x20uLL);
*v9 = v6;
v10 = (__int64)v9;
v9[3] = 0LL;
*((_DWORD *)v9 + 2) = -1;
v9[2] = 0LL;
v11 = segment_list;
if ( segment_list )
{
do
{
v12 = v11;
v11 = *(_QWORD *)(v11 + 24);
}
while ( v11 );
*(_QWORD *)(v12 + 24) = v10;
}
else
{
segment_list = v10;
}
restore_seg_from_log(a3, (__int64)v6);
return *((_QWORD *)v6 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, char *a3, int a4)
{
_DWORD *v6; // rbx
char *v7; // rax
void *v8; // rax
_QWORD *v9; // rax
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rcx

fprintf(stdout, "Map the segment %s\n", a3);
v6 = calloc(1uLL, 0x18uLL);
v7 = (char *)malloc(8uLL);
*(_QWORD *)v6 = v7;
strcpy(v7, a3);
v8 = malloc(a4);
v6[2] = a4;
*((_QWORD *)v6 + 2) = v8;
v9 = malloc(0x20uLL);
*v9 = v6;
v10 = (__int64)v9;
v9[3] = 0LL;
*((_DWORD *)v9 + 2) = -1;
v9[2] = 0LL;
v11 = segment_list;
if ( segment_list )
{
do
{
v12 = v11;
v11 = *(_QWORD *)(v11 + 24);
}
while ( v11 );
*(_QWORD *)(v12 + 24) = v10;
}
else
{
segment_list = v10;
}
func10(a3, (__int64)v6);
return *((_QWORD *)v6 + 2);
}

original_code:
void* rvm_map(rvm_t rvm, const char* seg_name, int size_to_create){
    fprintf(stdout, "Map the segment %s\n", seg_name);
    segment_t* seg = (segment_t*) calloc(1, sizeof(segment_t));
    seg->name = (char*) malloc(sizeof( strlen(seg_name) + 1));
    strcpy(seg->name, seg_name);
    seg->data = (void*)malloc(sizeof(char) * size_to_create);
    seg->size = size_to_create;
    segment_list_t* new_seg = (segment_list_t*)malloc(sizeof(segment_list_t));
    new_seg->segment = seg;
    new_seg->next_seg = ((void *)0);
    new_seg->txn = -1;
    new_seg->offset = ((void *)0);
    segment_list_t* seg_node = segment_list;
    if(seg_node == ((void *)0))
        segment_list = new_seg;
    else{
        while(seg_node -> next_seg != ((void *)0)){
            seg_node = seg_node->next_seg ;
        }
        seg_node -> next_seg = new_seg;
    }
    restore_seg_from_log(seg_name, seg);
    return seg->data;
}

canonical_original_code:
void *rvm_map(struct rvm_t rvm, char *seg_name, int size_to_create){
    fprintf(stdout, "Map the segment %s\n", seg_name);
    struct segment_t *seg = (segment_t*) calloc(1, sizeof(segment_t));
    seg->name = (char *) malloc(sizeof( strlen(seg_name) + 1));
    strcpy(seg->name, seg_name);
    seg->data = (void *)malloc(sizeof(char) * size_to_create);
    seg->size = size_to_create;
    struct seg_node *new_seg = (segment_list_t*)malloc(sizeof(segment_list_t));
    new_seg->segment = seg;
    new_seg->next_seg = ((void *)0);
    new_seg->txn = -1;
    new_seg->offset = ((void *)0);
    struct seg_node *seg_node = segment_list;
    if(seg_node == ((void *)0))
        segment_list = new_seg;
    else{
        while(seg_node -> next_seg != ((void *)0)){
            seg_node = seg_node->next_seg ;
        }
        seg_node -> next_seg = new_seg;
    }
    restore_seg_from_log(seg_name, seg);
    return seg->data;
}

variable_types: struct segment_t { char *name; int size; void *data; } *


decompiled_code:
int __fastcall rvm_abort_trans(unsigned int a1)
{
int result; // eax
__int64 i; // rbx

result = fprintf(stdout, "Abort transaction %d\n", a1);
for ( i = segment_list; i; i = *(_QWORD *)(i + 24) )
{
while ( *(_DWORD *)(i + 8) != a1 )
{
i = *(_QWORD *)(i + 24);
if ( !i )
return result;
}
result = restore_seg_from_log(**(char ***)i, *(_QWORD *)i);
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1)
{
int result; // eax
__int64 i; // rbx

result = fprintf(stdout, "Abort transaction %d\n", a1);
for ( i = segment_list; i; i = *(_QWORD *)(i + 24) )
{
while ( *(_DWORD *)(i + 8) != a1 )
{
i = *(_QWORD *)(i + 24);
if ( !i )
return result;
}
result = func10(**(char ***)i, *(_QWORD *)i);
}
return result;
}

original_code:
void rvm_abort_trans(trans_t tid) {
    fprintf(stdout, "Abort transaction %d\n", tid);
    segment_list_t* seg_node = segment_list;
    while(seg_node !=((void *)0)) {
        if (seg_node->txn == tid) {
            restore_seg_from_log(seg_node->segment->name, seg_node->segment);
        }
        seg_node = seg_node -> next_seg;
    }
}

canonical_original_code:
void rvm_abort_trans(int tid) {
    fprintf(stdout, "Abort transaction %d\n", tid);
    struct seg_node *seg_node = segment_list;
    while(seg_node !=((void *)0)) {
        if (seg_node->txn == tid) {
            restore_seg_from_log(seg_node->segment->name, seg_node->segment);
        }
        seg_node = seg_node -> next_seg;
    }
}


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

fprintf(stdout, "Removing segment from transaction %d\n", a1);
for ( result = segment_list; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)(result + 8) == a1 )
*(_DWORD *)(result + 8) = -1;
}
return result;
}

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

fprintf(stdout, "Removing segment from transaction %d\n", a1);
for ( result = segment_list; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_DWORD *)(result + 8) == a1 )
*(_DWORD *)(result + 8) = -1;
}
return result;
}

original_code:
void remove_seg_from_transaction(trans_t tid){
    fprintf(stdout, "Removing segment from transaction %d\n", tid);
    segment_list_t* seg_node = segment_list;
    while(seg_node != ((void *)0)){
        if(seg_node->txn == tid){
            seg_node->txn = -1;
        }
        seg_node = seg_node -> next_seg;
    }
}

canonical_original_code:
void remove_seg_from_transaction(int tid){
    fprintf(stdout, "Removing segment from transaction %d\n", tid);
    struct seg_node *seg_node = segment_list;
    while(seg_node != ((void *)0)){
        if(seg_node->txn == tid){
            seg_node->txn = -1;
        }
        seg_node = seg_node -> next_seg;
    }
}


elapsed

decompiled_code:
long double __fastcall elapsed(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return (long double)(a4 - a2) * 0.000001 + (long double)(a3 - a1);
}

canonical_decompiled_code:
long double __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return (long double)(a4 - a2) * 0.000001 + (long double)(a3 - a1);
}

original_code:
static
long double
elapsed (struct timeval start, struct timeval stop)
{
  return (long double)(stop.tv_sec - start.tv_sec)
    + (long double)(stop.tv_usec - start.tv_usec)*1e-6;
}

canonical_original_code:
static long double elapsed(struct timeval start, struct timeval stop)
{
  return (long double)(stop.tv_sec - start.tv_sec)
    + (long double)(stop.tv_usec - start.tv_usec)*1e-6;
}

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

variable_types:
stop
struct timeval

return_type: long double


decompiled_code:
long double __fastcall stopwatch_elapsed(__int64 a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

if ( !a1 )
return 0.0;
if ( !*(_DWORD *)(a1 + 32) )
return elapsed(*(_QWORD *)a1, *(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
gettimeofday(&v2, 0LL);
return elapsed(*(_QWORD *)a1, *(_QWORD *)(a1 + 8), v2.tv_sec, v2.tv_usec);
}

canonical_decompiled_code:
long double __fastcall func1(__int64 a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

if ( !a1 )
return 0.0;
if ( !*(_DWORD *)(a1 + 32) )
return func0(*(_QWORD *)a1, *(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 24));
gettimeofday(&v2, 0LL);
return func0(*(_QWORD *)a1, *(_QWORD *)(a1 + 8), v2.tv_sec, v2.tv_usec);
}

original_code:
long double
stopwatch_elapsed (struct stopwatch_t* T)
{
  long double dt = 0;
  if (T) {
    if (T->is_running_) {
      struct timeval stop;
      gettimeofday (&stop, 0);
      dt = elapsed (T->t_start_, stop);
    } else {
      dt = elapsed (T->t_start_, T->t_stop_);
    }
  }
  return dt;
}

canonical_original_code:
long double stopwatch_elapsed(struct stopwatch_t *T)
{
  long double dt = 0;
  if (T) {
    if (T->is_running_) {
      struct timeval stop;
      gettimeofday (&stop, 0);
      dt = elapsed (T->t_start_, stop);
    } else {
      dt = elapsed (T->t_start_, T->t_stop_);
    }
  }
  return dt;
}

variable_types: struct stopwatch_t { struct timeval { long tv_sec; long tv_usec; } t_start_; struct timeval t_stop_; int is_running_; } *

variable_types:
dt
long double

user_defined_types: struct stopwatch_t { struct timeval t_start_; struct timeval t_stop_; int is_running_; }


decompiled_code:
int stopwatch_init()
{
return fflush(stderr);
}

canonical_decompiled_code:
int func2()
{
return fflush(stderr);
}

original_code:
void
stopwatch_init (void)
{
  fflush (stderr);
}

canonical_original_code:
void stopwatch_init()
{
  fflush (stderr);
}


decompiled_code:
int __fastcall stopwatch_start(__int64 a1)
{
if ( !a1 )
_assert_fail("T", "timer.c", 0x3Eu, "stopwatch_start");
*(_DWORD *)(a1 + 32) = 1;
return gettimeofday((struct timeval *)a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
if ( !a1 )
_assert_fail("T", "timer.c", 0x3Eu, "stopwatch_start");
*(_DWORD *)(a1 + 32) = 1;
return gettimeofday((struct timeval *)a1, 0LL);
}

original_code:
void
stopwatch_start (struct stopwatch_t* T)
{
  ((void) sizeof ((T) ? 1 : 0), __extension__ ({ if (T) ; else __assert_fail ("T", "timer.c", 62, __extension__ __PRETTY_FUNCTION__); }));
  T->is_running_ = 1;
  gettimeofday (&(T->t_start_), 0);
}

canonical_original_code:
void stopwatch_start(struct stopwatch_t *T)
{
  ((void) sizeof ((T) ? 1 : 0), __extension__ ({ if (T) ; else __assert_fail ("T", "timer.c", 62, __extension__ __PRETTY_FUNCTION__); }));
  T->is_running_ = 1;
  gettimeofday (&(T->t_start_), 0);
}

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


decompiled_code:
long double __fastcall stopwatch_stop(__int64 a1)
{
if ( !a1 )
return 0.0;
if ( *(_DWORD *)(a1 + 32) )
{
gettimeofday((struct timeval *)(a1 + 16), 0LL);
*(_DWORD *)(a1 + 32) = 0;
}
return stopwatch_elapsed(a1);
}

canonical_decompiled_code:
long double __fastcall func4(__int64 a1)
{
if ( !a1 )
return 0.0;
if ( *(_DWORD *)(a1 + 32) )
{
gettimeofday((struct timeval *)(a1 + 16), 0LL);
*(_DWORD *)(a1 + 32) = 0;
}
return func1(a1);
}

original_code:
long double
stopwatch_stop (struct stopwatch_t* T)
{
  long double dt = 0;
  if (T) {
    if (T->is_running_) {
      gettimeofday (&(T->t_stop_), 0);
      T->is_running_ = 0;
    }
    dt = stopwatch_elapsed (T);
  }
  return dt;
}

canonical_original_code:
long double stopwatch_stop(struct stopwatch_t *T)
{
  long double dt = 0;
  if (T) {
    if (T->is_running_) {
      gettimeofday (&(T->t_stop_), 0);
      T->is_running_ = 0;
    }
    dt = stopwatch_elapsed (T);
  }
  return dt;
}


decompiled_code:
void *stopwatch_create()
{
return calloc(0x28uLL, 1uLL);
}

canonical_decompiled_code:
void *func5()
{
return calloc(0x28uLL, 1uLL);
}

original_code:
struct stopwatch_t *
stopwatch_create (void)
{
  struct stopwatch_t* new_timer =
    (struct stopwatch_t *)malloc (sizeof (struct stopwatch_t));
  if (new_timer)
    memset (new_timer, 0, sizeof (struct stopwatch_t));
  return new_timer;
}

canonical_original_code:
struct stopwatch_t *stopwatch_create()
{
  struct stopwatch_t *new_timer = (struct stopwatch_t *)malloc (sizeof (struct stopwatch_t));
  if (new_timer)
    memset (new_timer, 0, sizeof (struct stopwatch_t));
  return new_timer;
}

return_type: struct stopwatch_t { struct timeval { long tv_sec; long tv_usec; } t_start_; struct timeval t_stop_; int is_running_; } *


decompiled_code:
void __fastcall stopwatch_destroy(void *ptr)
{
if ( ptr )
{
stopwatch_stop((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
func4((__int64)ptr);
free(ptr);
}
}

original_code:
void
stopwatch_destroy (struct stopwatch_t* T)
{
  if (T) {
    stopwatch_stop (T);
    free (T);
  }
}

canonical_original_code:
void stopwatch_destroy(struct stopwatch_t *T)
{
  if (T) {
    stopwatch_stop (T);
    free (T);
  }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init_threads(argc, argv, envp);
spawn_thread1(EvenOdd);
spawn_thread1(fib);
spawn_thread1(squares);
waitForAllthreads();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(argc, argv, envp);
func10(EvenOdd);
func10(fib);
func10(squares);
func11();
return 0;
}

original_code:
int main()
{
 init_threads();
 spawn_thread1(&EvenOdd);
 spawn_thread1(&fib);
 spawn_thread1(&squares);
 waitForAllthreads();
 return 0;
}


decompiled_code:
__int64 __fastcall thread1Start(void *arg)
{
void (*v1)(void); // rbx

v1 = *(void (**)(void))arg;
free(arg);
v1();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *arg)
{
void (*v1)(void); // rbx

v1 = *(void (**)(void))arg;
free(arg);
v1();
return 0LL;
}

original_code:
static int thread1Start( void* arg )
{
 struct thread1Arguments* arguments = (struct thread1Arguments*) arg;
 void (*function)() = arguments->function;
 free( arguments );
 arguments = ((void *)0);
 ;
 function();
 return 0;
}

canonical_original_code:
static int thread1Start(void *arg)
{
 struct thread1Arguments *arguments = (struct thread1Arguments*) arg;
 void (*function)() = arguments->function;
 free( arguments );
 arguments = ((void *)0);
 ;
 function();
 return 0;
}

variable_types:
arg
void *

variable_types: struct thread1Arguments { void (*function)(); } *

variable_types:
function
void (*)()


decompiled_code:
__pid_t init_threads()
{
__int128 *v0; // rax
__pid_t result; // eax

v0 = &thread1List;
do
{
*(_DWORD *)v0++ = 0;
*((_QWORD *)v0 - 1) = 0LL;
}
while ( v0 != (__int128 *)&end );
result = getpid();
parentPid = result;
return result;
}

canonical_decompiled_code:
__pid_t func8()
{
__int128 *v0; // rax
__pid_t result; // eax

v0 = &thread1List;
do
{
*(_DWORD *)v0++ = 0;
*((_QWORD *)v0 - 1) = 0LL;
}
while ( v0 != (__int128 *)&end );
result = getpid();
parentPid = result;
return result;
}

original_code:
void init_threads()
{
 int i;
 for ( i = 0; i < 10; i++ )
 {
  thread1List[i].pid = 0;
  thread1List[i].stack = 0;
 }
 parentPid = getpid();
}

variable_types: i int


decompiled_code:
int thread1_Yield()
{
return sched_yield();
}

canonical_decompiled_code:
int func9()
{
return sched_yield();
}

original_code:
void thread1_Yield()
{
 int status;
 status=sched_yield();
}

variable_types: status int