NURand

decompiled_code:
__int64 __fastcall NURand(unsigned int a1, int a2, int a3)
{
int v3; // er13
int v4; // er14
int v5; // er15
int v7; // ebp

if ( first_3 )
{
v4 = RandomNumber(0, 255);
v5 = RandomNumber(0, 1023);
v3 = RandomNumber(0, 0x1FFF);
first_3 = 0;
}
if ( a1 == 1023 )
{
v3 = v5;
}
else if ( a1 != 0x1FFF )
{
if ( a1 != 255 )
{
fprintf(stderr, "NURand: unexpected value (%d) of A used\n", a1);
abort();
}
v3 = v4;
}
v7 = RandomNumber(0, a1);
return (v3 + (v7 | (unsigned int)RandomNumber(a2, a3))) % (a3 - a2 + 1) + a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2, int a3)
{
int v3; // er13
int v4; // er14
int v5; // er15
int v7; // ebp

if ( first_3 )
{
v4 = func1(0, 255);
v5 = func1(0, 1023);
v3 = func1(0, 0x1FFF);
first_3 = 0;
}
if ( a1 == 1023 )
{
v3 = v5;
}
else if ( a1 != 0x1FFF )
{
if ( a1 != 255 )
{
fprintf(stderr, "NURand: unexpected value (%d) of A used\n", a1);
abort();
}
v3 = v4;
}
v7 = func1(0, a1);
return (v3 + (v7 | (unsigned int)func1(a2, a3))) % (a3 - a2 + 1) + a2;
}

original_code:
int NURand (unsigned A, unsigned x, unsigned y)
{
 static int first = 1;
 unsigned C, C_255, C_1023, C_8191;
 if (first) {
  C_255 = RandomNumber(0, 255);
  C_1023 = RandomNumber(0, 1023);
  C_8191 = RandomNumber(0, 8191);
  first = 0;
 }
 switch (A) {
 case 255: C = C_255; break;
 case 1023: C = C_1023; break;
 case 8191: C = C_8191; break;
 default:
  fprintf(stderr,
   "NURand: unexpected value (%d) of A used\n",
   A);
  abort();
 }
 return (int)
        (((RandomNumber(0, A) | RandomNumber(x, y)) + C) % (y-x+1)) + x;
}

canonical_original_code:
int NURand(unsigned int A, unsigned int x, unsigned int y)
{
 static int first = 1;
 unsigned int C; unsigned int C_255; unsigned int C_1023; unsigned int C_8191;
 if (first) {
  C_255 = RandomNumber(0, 255);
  C_1023 = RandomNumber(0, 1023);
  C_8191 = RandomNumber(0, 8191);
  first = 0;
 }
 switch (A) {
 case 255: C = C_255; break;
 case 1023: C = C_1023; break;
 case 8191: C = C_8191; break;
 default:
  fprintf(stderr,
   "NURand: unexpected value (%d) of A used\n",
   A);
  abort();
 }
 return (int)
        (((RandomNumber(0, A) | RandomNumber(x, y)) + C) % (y-x+1)) + x;
}

variable_types:
A
unsigned int

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types: first int

variable_types:
C
unsigned int


MakeAlphaString

decompiled_code:
__int64 __fastcall MakeAlphaString(int a1, int a2, _BYTE *a3)
{
int v4; // eax
unsigned int v5; // er12
_BYTE *v6; // rbx
__int64 v7; // rbp

v4 = RandomNumber(a1, a2);
v5 = v4;
if ( v4 > 0 )
{
v6 = a3;
v7 = (__int64)&a3[v4 - 1 + 1];
do
*v6++ = byte_3290[(int)RandomNumber(0, 61)];
while ( v6 != (_BYTE *)v7 );
}
return v5;
}

original_code:
int MakeAlphaString (int x, int y, char str[])
{
 static char *alphanum = "0123456789"
           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
           "abcdefghijklmnopqrstuvwxyz";
 int arrmax = 61;
 register int i, len;
 len = RandomNumber(x, y);
 for (i = 0; i < len; i++)
  str[i] = alphanum[RandomNumber(0, arrmax)];
 return len;
}

canonical_original_code:
int MakeAlphaString(int x, int y, char str[])
{
 static char *alphanum = "0123456789"
           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
           "abcdefghijklmnopqrstuvwxyz";
 int arrmax = 61;
 register int i; register int len;
 len = RandomNumber(x, y);
 for (i = 0; i < len; i++)
  str[i] = alphanum[RandomNumber(0, arrmax)];
 return len;
}

variable_types: x int

variable_types: y int

variable_types:
str
char []

variable_types:
alphanum
char *

variable_types: arrmax int

variable_types: i int

variable_types: len int

return_type: int


MakeNumberString

decompiled_code:
__int64 __fastcall MakeNumberString(int a1, int a2, _BYTE *a3)
{
int v4; // eax
unsigned int v5; // er12
_BYTE *v6; // rbx
__int64 v7; // rbp

v4 = RandomNumber(a1, a2);
v5 = v4;
if ( v4 > 0 )
{
v6 = a3;
v7 = (__int64)&a3[v4 - 1 + 1];
do
*v6++ = byte_331B[(int)RandomNumber(0, 9)];
while ( v6 != (_BYTE *)v7 );
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, _BYTE *a3)
{
int v4; // eax
unsigned int v5; // er12
_BYTE *v6; // rbx
__int64 v7; // rbp

v4 = func1(a1, a2);
v5 = v4;
if ( v4 > 0 )
{
v6 = a3;
v7 = (__int64)&a3[v4 - 1 + 1];
do
*v6++ = byte_331B[(int)func1(0, 9)];
while ( v6 != (_BYTE *)v7 );
}
return v5;
}

original_code:
int MakeNumberString (int x, int y, char str[])
{
 static char *numeric = "0123456789";
 int arrmax = 9;
 register int i, len;
 len = RandomNumber(x, y);
 for (i = 0; i < len; i++)
  str[i] = numeric[RandomNumber(0, arrmax)];
 return len;
}

canonical_original_code:
int MakeNumberString(int x, int y, char str[])
{
 static char *numeric = "0123456789";
 int arrmax = 9;
 register int i; register int len;
 len = RandomNumber(x, y);
 for (i = 0; i < len; i++)
  str[i] = numeric[RandomNumber(0, arrmax)];
 return len;
}

variable_types:
numeric
char *


gettimestamp

decompiled_code:
size_t __fastcall gettimestamp(char *s, char *format, size_t maxsize)
{
struct tm *v4; // rax
size_t result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v4 = localtime(&timer);
result = strftime(s, maxsize, format, v4);
if ( !result )
{
fwrite("error writing timestamp to string\n", 1uLL, 0x22uLL, stderr);
abort();
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func5(char *s, char *format, size_t maxsize)
{
struct tm *v4; // rax
size_t result; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v4 = localtime(&timer);
result = strftime(s, maxsize, format, v4);
if ( !result )
{
fwrite("error writing timestamp to string\n", 1uLL, 0x22uLL, stderr);
abort();
}
return result;
}

original_code:
void gettimestamp (char str[], char *format, size_t len)
{
 time_t t;
 struct tm *datetime;
 t = time(((void *)0));
 datetime = localtime(&t);
 if ( !strftime(str, len, format, datetime) ) {
  fprintf(stderr, "error writing timestamp to string\n");
  abort();
 }
}

canonical_original_code:
void gettimestamp(char str[], char *format, unsigned long len)
{
 long t;
 struct tm *datetime;
 t = time(((void *)0));
 datetime = localtime(&t);
 if ( !strftime(str, len, format, datetime) ) {
  fprintf(stderr, "error writing timestamp to string\n");
  abort();
 }
}

variable_types:
format
char *

variable_types:
len
unsigned long

variable_types: t long

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

return_type: void


InitPermutation

decompiled_code:
__int64 InitPermutation()
{
__int64 i; // rax
__int64 j; // rbx
int v2; // edx
__int64 result; // rax

perm_count = 0;
for ( i = 0LL; i != 3000; ++i )
nums[i] = i + 1;
for ( j = 1LL; j != 3000; ++j )
{
LODWORD(result) = RandomNumber(j, 2999);
v2 = dword_37C[j];
result = (int)result;
dword_37C[j] = nums[(int)result];
nums[(int)result] = v2;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 i; // rax
__int64 j; // rbx
int v2; // edx
__int64 result; // rax

perm_count = 0;
for ( i = 0LL; i != 3000; ++i )
nums[i] = i + 1;
for ( j = 1LL; j != 3000; ++j )
{
LODWORD(result) = func1(j, 2999);
v2 = dword_37C[j];
result = (int)result;
dword_37C[j] = nums[(int)result];
nums[(int)result] = v2;
}
return result;
}

original_code:
void InitPermutation (void)
{
 int *cur;
 int i,j;
 perm_count = 0;
 for (i = 0, cur = nums; i < 3000; i++, cur++) {
  *cur = i + 1;
 }
 for (i = 0; i < 3000 -1; i++) {
  j = (int)RandomNumber(i+1, 3000 -1);
  {int tmp; tmp=nums[i]; nums[i]=nums[j]; nums[j]=tmp;};
 }
}

canonical_original_code:
void InitPermutation()
{
 int *cur;
 int i; int j;
 perm_count = 0;
 for (i = 0, cur = nums; i < 3000; i++, cur++) {
  *cur = i + 1;
 }
 for (i = 0; i < 3000 -1; i++) {
  j = (int)RandomNumber(i+1, 3000 -1);
  {int tmp; tmp=nums[i]; nums[i]=nums[j]; nums[j]=tmp;};
 }
}

variable_types:
cur
int *

variable_types: j int

variable_types: tmp int


GetPermutation

decompiled_code:
__int64 GetPermutation()
{
int v0; // eax

v0 = perm_count;
if ( perm_count > 2999 )
{
fwrite("GetPermutation: past end of list!\n", 1uLL, 0x22uLL, stderr);
abort();
}
++perm_count;
return (unsigned int)nums[v0];
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax

v0 = perm_count;
if ( perm_count > 2999 )
{
fwrite("GetPermutation: past end of list!\n", 1uLL, 0x22uLL, stderr);
abort();
}
++perm_count;
return (unsigned int)nums[v0];
}

original_code:
int GetPermutation (void)
{
 if ( perm_count >= 3000 ) {
  fprintf(stderr, "GetPermutation: past end of list!\n");
  abort();
 }
 return nums[perm_count++];
}

canonical_original_code:
int GetPermutation()
{
 if ( perm_count >= 3000 ) {
  fprintf(stderr, "GetPermutation: past end of list!\n");
  abort();
 }
 return nums[perm_count++];
}


decompiled_code:
char *hist_init()
{
char *v0; // rdx
char *result; // rax

v0 = (char *)&unk_13880;
do
{
result = v0 - 80000;
do
{
*(int *)((char *)&cur_hist + (_QWORD)result) = 0;
*(int *)((char *)&total_hist + (_QWORD)result) = 0;
result += 4;
}
while ( result != v0 );
v0 += 80000;
}
while ( v0 != (char *)&unk_75300 );
return result;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rdx
char *result; // rax

v0 = (char *)&unk_13880;
do
{
result = v0 - 80000;
do
{
*(int *)((char *)&cur_hist + (_QWORD)result) = 0;
*(int *)((char *)&total_hist + (_QWORD)result) = 0;
result += 4;
}
while ( result != v0 );
v0 += 80000;
}
while ( v0 != (char *)&unk_75300 );
return result;
}


decompiled_code:
__int64 __fastcall hist_inc(int a1, double a2)
{
__int64 result; // rax

LODWORD(result) = (int)(a2 * 1000.0);
if ( (int)result > 19999 )
LODWORD(result) = 19999;
if ( a2 > *((double *)&cur_max_rt + a1) )
*((double *)&cur_max_rt + a1) = a2;
result = (int)result;
++cur_hist[20000 * a1 + (int)result];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, double a2)
{
__int64 result; // rax

LODWORD(result) = (int)(a2 * 1000.0);
if ( (int)result > 19999 )
LODWORD(result) = 19999;
if ( a2 > *((double *)&cur_max_rt + a1) )
*((double *)&cur_max_rt + a1) = a2;
result = (int)result;
++cur_hist[20000 * a1 + (int)result];
return result;
}

original_code:
void hist_inc( int transaction, double rtclk )
{
  int i;
  i = ( rtclk * (double)1000 );
  if(i >= (20 * 1000)){
    i = (20 * 1000) - 1;
  }
  if (rtclk > cur_max_rt[transaction]) cur_max_rt[transaction] = rtclk;
  ++cur_hist[transaction][i];
}

canonical_original_code:
void hist_inc(int transaction, double rtclk)
{
  int i;
  i = ( rtclk * (double)1000 );
  if(i >= (20 * 1000)){
    i = (20 * 1000) - 1;
  }
  if (rtclk > cur_max_rt[transaction]) cur_max_rt[transaction] = rtclk;
  ++cur_hist[transaction][i];
}

variable_types: transaction int

variable_types: rtclk double


original_code:
double hist_ckp( int transaction )
{
  int i;
  int total,tmp,line,line_set;
  total = tmp = line_set = 0;
  line = 20 * 1000;
  for( i=0; i<(20 * 1000); i++){
    total += cur_hist[transaction][i];
  }
  for( i=0; i<(20 * 1000); i++){
    tmp += cur_hist[transaction][i];
    total_hist[transaction][i] += cur_hist[transaction][i];
    cur_hist[transaction][i] = 0;
    if (( tmp >= (total*99/100) ) && (line_set ==0)){
      line = i;
      line_set=1;
    }
  }
  return ( (double)(line)/(double)(1000) );
}

canonical_original_code:
double hist_ckp(int transaction)
{
  int i;
  int total; int tmp; int line; int line_set;
  total = tmp = line_set = 0;
  line = 20 * 1000;
  for( i=0; i<(20 * 1000); i++){
    total += cur_hist[transaction][i];
  }
  for( i=0; i<(20 * 1000); i++){
    tmp += cur_hist[transaction][i];
    total_hist[transaction][i] += cur_hist[transaction][i];
    cur_hist[transaction][i] = 0;
    if (( tmp >= (total*99/100) ) && (line_set ==0)){
      line = i;
      line_set=1;
    }
  }
  return ( (double)(line)/(double)(1000) );
}

variable_types: total int

variable_types: line int

return_type: double


decompiled_code:
int hist_report()
{
char *v0; // r11
char *v1; // r10
int *v2; // rbx
int *v3; // rbp
unsigned __int64 v4; // rdi
int *v5; // r9
char *v6; // rsi
__int64 v7; // rax
int v8; // er13
_DWORD *v9; // rax
int v10; // ecx
int i; // er14
unsigned int *v12; // r13
int j; // er12
int v14; // ebp
__int64 v15; // rbx
int result; // eax
int v17[8]; // [rsp+0h] [rbp-88h] BYREF
char v18; // [rsp+20h] [rbp-68h] BYREF
char v19; // [rsp+40h] [rbp-48h] BYREF

v0 = &v18;
v1 = &v19;
v2 = v17;
v3 = total_hist;
v4 = (unsigned int)((_DWORD)total_hist + 80000);
v5 = v17;
v6 = 0LL;
do
{
*(_DWORD *)v0 = 0;
*v5 = 20000;
v9 = (_DWORD *)(v4 - 80000);
v10 = 0;
do
v10 += *v9++;
while ( v9 != (_DWORD *)v4 );
*(_DWORD *)v1 = v10;
v7 = 19999LL;
v8 = 0;
do
{
v8 += *(int *)((char *)total_hist + (_QWORD)&v6[4 * v7]);
if ( v10 >= 10 * v8 )
*v5 = v7;
--v7;
}
while ( v7 != -1 );
v0 += 4;
v1 += 4;
++v5;
v6 += 80000;
v4 += 80000LL;
}
while ( v6 != (char *)&unk_61A80 );
puts("\n<RT Histogram>");
for ( i = 0; i != 5; ++i )
{
switch ( i )
{
case 0:
puts("\n1.New-Order\n");
break;
case 1:
puts("\n2.Payment\n");
break;
case 2:
puts("\n3.Order-Status\n");
break;
case 3:
puts("\n4.Delivery\n");
break;
case 4:
puts("\n5.Stock-Level\n");
break;
default:
break;
}
v12 = (unsigned int *)v3;
for ( j = 0; j != 20000; printf("%3.2f, %6d\n", (double)++j / 1000.0, *v12++) )
{
if ( 4 * *v2 < j )
break;
}
putchar(10);
v3 += 20000;
++v2;
}
puts("\n<90th Percentile RT (MaxRT)>");
v14 = 1;
v15 = 0LL;
while ( 2 )
{
switch ( (int)v15 )
{
case 0:
printf(" New-Order : ");
goto LABEL_22;
case 1:
printf(" Payment : ");
goto LABEL_22;
case 2:
printf("Order-Status : ");
goto LABEL_22;
case 3:
printf(" Delivery : ");
LABEL_22:
printf("%3.2f (%.2f)\n", (double)v17[v15] / 1000.0, max_rt[v15]);
goto LABEL_23;
case 4:
printf(" Stock-Level : ");
return printf("%3.2f (%.2f)\n", (double)v17[4] / 1000.0, max_rt[4]);
default:
result = printf("%3.2f (%.2f)\n", (double)v17[v15] / 1000.0, max_rt[v15]);
if ( v14 <= 4 )
{
LABEL_23:
++v15;
++v14;
continue;
}
return result;
}
}
}

canonical_decompiled_code:
int func3()
{
char *v0; // r11
char *v1; // r10
int *v2; // rbx
int *v3; // rbp
unsigned __int64 v4; // rdi
int *v5; // r9
char *v6; // rsi
__int64 v7; // rax
int v8; // er13
_DWORD *v9; // rax
int v10; // ecx
int i; // er14
unsigned int *v12; // r13
int j; // er12
int v14; // ebp
__int64 v15; // rbx
int result; // eax
int v17[8]; // [rsp+0h] [rbp-88h] BYREF
char v18; // [rsp+20h] [rbp-68h] BYREF
char v19; // [rsp+40h] [rbp-48h] BYREF

v0 = &v18;
v1 = &v19;
v2 = v17;
v3 = total_hist;
v4 = (unsigned int)((_DWORD)total_hist + 80000);
v5 = v17;
v6 = 0LL;
do
{
*(_DWORD *)v0 = 0;
*v5 = 20000;
v9 = (_DWORD *)(v4 - 80000);
v10 = 0;
do
v10 += *v9++;
while ( v9 != (_DWORD *)v4 );
*(_DWORD *)v1 = v10;
v7 = 19999LL;
v8 = 0;
do
{
v8 += *(int *)((char *)total_hist + (_QWORD)&v6[4 * v7]);
if ( v10 >= 10 * v8 )
*v5 = v7;
--v7;
}
while ( v7 != -1 );
v0 += 4;
v1 += 4;
++v5;
v6 += 80000;
v4 += 80000LL;
}
while ( v6 != (char *)&unk_61A80 );
puts("\n<RT Histogram>");
for ( i = 0; i != 5; ++i )
{
switch ( i )
{
case 0:
puts("\n1.New-Order\n");
break;
case 1:
puts("\n2.Payment\n");
break;
case 2:
puts("\n3.Order-Status\n");
break;
case 3:
puts("\n4.Delivery\n");
break;
case 4:
puts("\n5.Stock-Level\n");
break;
default:
break;
}
v12 = (unsigned int *)v3;
for ( j = 0; j != 20000; printf("%3.2f, %6d\n", (double)++j / 1000.0, *v12++) )
{
if ( 4 * *v2 < j )
break;
}
putchar(10);
v3 += 20000;
++v2;
}
puts("\n<90th Percentile RT (MaxRT)>");
v14 = 1;
v15 = 0LL;
while ( 2 )
{
switch ( (int)v15 )
{
case 0:
printf(" New-Order : ");
goto LABEL_22;
case 1:
printf(" Payment : ");
goto LABEL_22;
case 2:
printf("Order-Status : ");
goto LABEL_22;
case 3:
printf(" Delivery : ");
LABEL_22:
printf("%3.2f (%.2f)\n", (double)v17[v15] / 1000.0, max_rt[v15]);
goto LABEL_23;
case 4:
printf(" Stock-Level : ");
return printf("%3.2f (%.2f)\n", (double)v17[4] / 1000.0, max_rt[4]);
default:
result = printf("%3.2f (%.2f)\n", (double)v17[v15] / 1000.0, max_rt[v15]);
if ( v14 <= 4 )
{
LABEL_23:
++v15;
++v14;
continue;
}
return result;
}
}
}

original_code:
void hist_report()
{
  int i,j;
  int total[5],tmp[5],line[5];
  for( j=0; j<5; j++){
    total[j] = tmp[j] = 0;
    line[j] = 20 * 1000;
    for( i=0; i<(20 * 1000); i++){
      total[j] += total_hist[j][i];
    }
    for( i=(20 * 1000)-1; i >= 0 ; i--){
      tmp[j] += total_hist[j][i];
      if( (tmp[j] * 10) <= total[j] ){
 line[j] = i;
      }
    }
  }
  printf("\n<RT Histogram>\n");
  for( j=0; j<5; j++){
    switch(j){
    case 0:
      printf("\n1.New-Order\n\n");
      break;
    case 1:
      printf("\n2.Payment\n\n");
      break;
    case 2:
      printf("\n3.Order-Status\n\n");
      break;
    case 3:
      printf("\n4.Delivery\n\n");
      break;
    case 4:
      printf("\n5.Stock-Level\n\n");
    }
    for( i=0; (i<(20 * 1000))&&(i <= line[j]*4); i++){
      printf("%3.2f, %6d\n",(double)(i+1)/(double)(1000),total_hist[j][i]);
    }
    printf("\n");
  }
  printf("\n<90th Percentile RT (MaxRT)>\n");
  for( j=0; j<5; j++){
    switch(j){
    case 0:
      printf("   New-Order : ");
      break;
    case 1:
      printf("     Payment : ");
      break;
    case 2:
      printf("Order-Status : ");
      break;
    case 3:
      printf("    Delivery : ");
      break;
    case 4:
      printf(" Stock-Level : ");
    }
    printf("%3.2f  (%.2f)\n",(double)(line[j])/(double)(1000),max_rt[j]);
  }
}

canonical_original_code:
void hist_report()
{
  int i; int j;
  int total[5]; int tmp[5]; int line[5];
  for( j=0; j<5; j++){
    total[j] = tmp[j] = 0;
    line[j] = 20 * 1000;
    for( i=0; i<(20 * 1000); i++){
      total[j] += total_hist[j][i];
    }
    for( i=(20 * 1000)-1; i >= 0 ; i--){
      tmp[j] += total_hist[j][i];
      if( (tmp[j] * 10) <= total[j] ){
 line[j] = i;
      }
    }
  }
  printf("\n<RT Histogram>\n");
  for( j=0; j<5; j++){
    switch(j){
    case 0:
      printf("\n1.New-Order\n\n");
      break;
    case 1:
      printf("\n2.Payment\n\n");
      break;
    case 2:
      printf("\n3.Order-Status\n\n");
      break;
    case 3:
      printf("\n4.Delivery\n\n");
      break;
    case 4:
      printf("\n5.Stock-Level\n\n");
    }
    for( i=0; (i<(20 * 1000))&&(i <= line[j]*4); i++){
      printf("%3.2f, %6d\n",(double)(i+1)/(double)(1000),total_hist[j][i]);
    }
    printf("\n");
  }
  printf("\n<90th Percentile RT (MaxRT)>\n");
  for( j=0; j<5; j++){
    switch(j){
    case 0:
      printf("   New-Order : ");
      break;
    case 1:
      printf("     Payment : ");
      break;
    case 2:
      printf("Order-Status : ");
      break;
    case 3:
      printf("    Delivery : ");
      break;
    case 4:
      printf(" Stock-Level : ");
    }
    printf("%3.2f  (%.2f)\n",(double)(line[j])/(double)(1000),max_rt[j]);
  }
}

variable_types:
total
int [5]

variable_types:
tmp
int [5]

variable_types:
line
int [5]


shuffle

canonical_original_code:
static void shuffle()
{
  int i; int j; int rnd; int tmp;
  for( i=0, j=0; i < no ; i++, j++ ){
    seq[j]=0;
  }
  for( i=0; i < py ; i++, j++){
    seq[j]=1;
  }
  for( i=0; i < os ; i++, j++){
    seq[j]=2;
  }
  for( i=0; i < dl ; i++, j++){
    seq[j]=3;
  }
  for( i=0; i < sl ; i++, j++){
    seq[j]=4;
  }
  for( i=0, j = total - 1; j>0; i++, j--){
    rnd = rand()%(j+1);
    tmp = seq[rnd+i];
    seq[rnd+i] = seq[i];
    seq[i] = tmp;
  }
}

variable_types: i int

variable_types: rnd int


decompiled_code:
void __fastcall seq_init(int a1, int a2, int a3, int a4, int a5)
{
pthread_mutex_init(&mutex, 0LL);
no = a1;
py = a2;
os = a3;
dword_290 = a4;
sl = a5;
total = a5 + a4 + a3 + a1 + a2;
seq = (__int64)malloc(4LL * total);
shuffle();
next_num = 0;
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2, int a3, int a4, int a5)
{
pthread_mutex_init(&mutex, 0LL);
no = a1;
py = a2;
os = a3;
dword_290 = a4;
sl = a5;
total = a5 + a4 + a3 + a1 + a2;
seq = (__int64)malloc(4LL * total);
func0();
next_num = 0;
}

original_code:
void seq_init( int n, int p, int o, int d, int s )
{
  pthread_mutex_init( &mutex, ((void *)0) );
  no = n;
  py = p;
  os = o;
  dl = d;
  sl = s;
  total = n + p + o + d + s;
  seq = malloc( sizeof(int) * total );
  shuffle();
  next_num = 0;
}

canonical_original_code:
void seq_init(int n, int p, int o, int d, int s)
{
  pthread_mutex_init( &mutex, ((void *)0) );
  no = n;
  py = p;
  os = o;
  dl = d;
  sl = s;
  total = n + p + o + d + s;
  seq = malloc( sizeof(int) * total );
  shuffle();
  next_num = 0;
}

variable_types: n int

variable_types: p int

variable_types: o int

variable_types: d int

variable_types: s int


decompiled_code:
__int64 seq_get()
{
unsigned int v0; // ebx

pthread_mutex_lock(&mutex);
if ( next_num >= total )
{
shuffle();
next_num = 0;
}
v0 = *(_DWORD *)(seq + 4LL * next_num++);
pthread_mutex_unlock(&mutex);
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx

pthread_mutex_lock(&mutex);
if ( next_num >= total )
{
func0();
next_num = 0;
}
v0 = *(_DWORD *)(seq + 4LL * next_num++);
pthread_mutex_unlock(&mutex);
return v0;
}

original_code:
int seq_get()
{
  int retval;
  pthread_mutex_lock( &mutex );
  if(next_num >= total){
    shuffle();
    next_num = 0;
  }
  retval = seq[next_num];
  ++next_num;
  pthread_mutex_unlock( &mutex );
  return(retval);
}

variable_types: retval int


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

result = a1;
if ( num_ware != 1 )
{
do
result = RandomNumber(1LL, num_ware);
while ( (_DWORD)result == a1 );
}
return result;
}

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

result = a1;
if ( num_ware != 1 )
{
do
result = RandomNumber(1LL, num_ware);
while ( (_DWORD)result == a1 );
}
return result;
}

original_code:
static int other_ware (int home_ware)
{
    int tmp;
    if (num_ware == 1) return home_ware;
    while ((tmp = RandomNumber(1, num_ware)) == home_ware);
    return tmp;
}

canonical_original_code:
static int other_ware(int home_ware)
{
    int tmp;
    if (num_ware == 1) return home_ware;
    while ((tmp = RandomNumber(1, num_ware)) == home_ware);
    return tmp;
}


driver

decompiled_code:
__int64 __fastcall driver(unsigned int a1)
{
while ( activate_transaction )
{
switch ( (unsigned int)seq_get() )
{
case 0u:
do_neword(a1);
break;
case 1u:
do_payment(a1);
break;
case 2u:
do_ordstat(a1);
break;
case 3u:
do_delivery(a1);
break;
case 4u:
do_slev(a1);
break;
default:
puts("Error - Unknown sequence.");
break;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
while ( activate_transaction )
{
switch ( (unsigned int)seq_get() )
{
case 0u:
func1(a1);
break;
case 1u:
func2(a1);
break;
case 2u:
func3(a1);
break;
case 3u:
func4(a1);
break;
case 4u:
func5(a1);
break;
default:
puts("Error - Unknown sequence.");
break;
}
}
return 0LL;
}

original_code:
int driver (int t_num)
{
    int i, j;
    while( activate_transaction ){
      switch(seq_get()){
      case 0:
 do_neword(t_num);
 break;
      case 1:
 do_payment(t_num);
 break;
      case 2:
 do_ordstat(t_num);
 break;
      case 3:
 do_delivery(t_num);
 break;
      case 4:
 do_slev(t_num);
 break;
      default:
 printf("Error - Unknown sequence.\n");
      }
    }
    return(0);
}

canonical_original_code:
int driver(int t_num)
{
    int i; int j;
    while( activate_transaction ){
      switch(seq_get()){
      case 0:
 do_neword(t_num);
 break;
      case 1:
 do_payment(t_num);
 break;
      case 2:
 do_ordstat(t_num);
 break;
      case 3:
 do_delivery(t_num);
 break;
      case 4:
 do_slev(t_num);
 break;
      default:
 printf("Error - Unknown sequence.\n");
      }
    }
    return(0);
}

variable_types: j int


usage

repo: kyoto/sendkeys

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"usage: %s [-window <id>|root]\n"
" [-count <count>]\n"
" [-display <name>] [Modifier+[Modifier+]]Key\n"
"(looks up keysyms in <X11/keysymdef.h>)\n"
"'Alt', 'Control', 'Shift' are replaced by\n"
"'Alt_L', 'Control_L', 'Shift_L'...\n"
" example:\n"
" %s Control+Alt+Right\n",
(const char *)progname,
(const char *)progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func10()
{
fprintf(
stderr,
"usage: %s [-window <id>|root]\n"
" [-count <count>]\n"
" [-display <name>] [Modifier+[Modifier+]]Key\n"
"(looks up keysyms in <X11/keysymdef.h>)\n"
"'Alt', 'Control', 'Shift' are replaced by\n"
"'Alt_L', 'Control_L', 'Shift_L'...\n"
" example:\n"
" %s Control+Alt+Right\n",
(const char *)progname,
(const char *)progname);
exit(1);
}

original_code:
void usage()
{
    fprintf(stderr,
        "usage: %s [-window <id>|root]\n"
        "            [-count <count>]\n"
        "            [-display <name>] [Modifier+[Modifier+]]Key\n"
        "(looks up keysyms in <X11/keysymdef.h>)\n"
        "'Alt',   'Control',   'Shift' are replaced by\n"
        "'Alt_L', 'Control_L', 'Shift_L'...\n"
        "  example:\n"
        "     %s Control+Alt+Right\n", progname, progname);
    exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
int v7; // er14
int i; // ebp
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
bool v12; // cf
bool v13; // zf
char v14; // al
bool v15; // cf
bool v16; // zf
__int64 v17; // rdx
const char *v18; // rdi
__int64 v19; // rcx
const char *v20; // rsi
char v21; // al
const char *v22; // rdi
__int64 v23; // rcx
const char *v24; // rsi
char *j; // rbx
int v26; // eax
Display *v27; // rax
int k; // ebx
int v30[11]; // [rsp+Ch] [rbp-2Ch] BYREF

progname = (__int64)*argv;
v3 = argc == 0;
v4 = argc == 1;
if ( argc <= 1 )
{
v7 = 1;
}
else
{
v7 = 1;
for ( i = 1; i < argc; v4 = argc == i )
{
v17 = i;
v18 = "-display";
v19 = 9LL;
v20 = argv[v17];
do
{
if ( !v19 )
break;
v3 = *v20 < (unsigned int)*v18;
v4 = *v20++ == *v18++;
--v19;
}
while ( v4 );
v21 = (!v3 && !v4) - v3;
v12 = 0;
v13 = v21 == 0;
if ( v21 )
{
v9 = "-count";
v10 = 7LL;
v11 = argv[i];
do
{
if ( !v10 )
break;
v12 = *v11 < (unsigned int)*v9;
v13 = *v11++ == *v9++;
--v10;
}
while ( v13 );
v14 = (!v12 && !v13) - v12;
v15 = 0;
v16 = v14 == 0;
if ( v14 )
{
v22 = "-window";
v23 = 8LL;
v24 = argv[i];
do
{
if ( !v23 )
break;
v15 = *v24 < (unsigned int)*v22;
v16 = *v24++ == *v22++;
--v23;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
{
if ( argc == ++i )
usage(v22, v24, v17 * 8);
if ( !strcmp(argv[v17 + 1], "root") )
window = -1LL;
else
window = strtoul(argv[v17 + 1], 0LL, 0);
}
else
{
if ( *argv[i] == 45 )
{
fprintf(stderr, "%s: bad option `%s'.\n", (const char *)progname, argv[i]);
((void (*)(void))usage)();
}
strncpy(&keyname, argv[i], 0x3FFuLL);
keysym = 0;
shift = 0;
for ( j = strtok(&keyname, "+"); j; j = strtok(0LL, "+") )
{
if ( !strcmp(j, "Alt") )
{
LABEL_41:
shift |= 8u;
}
else if ( !strcmp(j, "Control") )
{
LABEL_34:
shift |= 4u;
}
else if ( !strcmp(j, "Shift") )
{
LABEL_39:
shift |= 1u;
}
else
{
v26 = XStringToKeysym(j);
if ( !v26 )
{
fprintf(stderr, "unknown: %s\n", j);
((void (*)(void))usage)();
}
switch ( v26 )
{
case 65505:
case 65506:
goto LABEL_39;
case 65507:
case 65508:
goto LABEL_34;
case 65509:
case 65510:
shift |= 2u;
break;
case 65511:
case 65512:
case 65513:
case 65514:
goto LABEL_41;
case 65515:
case 65516:
case 65517:
case 65518:
continue;
default:
keysym = v26;
break;
}
}
}
}
}
else
{
if ( argc == ++i )
usage(v9, v11, v17 * 8);
v7 = strtoul(argv[v17 + 1], 0LL, 0);
}
}
else
{
if ( argc == ++i )
usage(v18, v20, v17 * 8);
displayname = (char *)argv[v17 + 1];
}
v3 = argc < (unsigned int)++i;
}
}
if ( !keyname )
{
fprintf(stderr, "%s: you must specify a keyname.\n", (const char *)progname);
exit(1);
}
if ( !displayname )
{
displayname = getenv("DISPLAY");
if ( !displayname )
displayname = ":0.0";
}
v27 = XOpenDisplay(displayname);
display = v27;
if ( !v27 )
{
fprintf(stderr, "%s: can't open display `%s'.\n", (const char *)progname, displayname);
exit(1);
}
if ( !window )
XGetInputFocus(v27, &window, v30);
if ( window == -1LL )
window = display->screens->root;
if ( v7 > 0 )
{
for ( k = 0; k != v7; ++k )
SendKeyPressedEvent(keysym, shift);
}
XCloseDisplay(display);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
int v7; // er14
int i; // ebp
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
bool v12; // cf
bool v13; // zf
char v14; // al
bool v15; // cf
bool v16; // zf
__int64 v17; // rdx
const char *v18; // rdi
__int64 v19; // rcx
const char *v20; // rsi
char v21; // al
const char *v22; // rdi
__int64 v23; // rcx
const char *v24; // rsi
char *j; // rbx
int v26; // eax
Display *v27; // rax
int k; // ebx
int v30[11]; // [rsp+Ch] [rbp-2Ch] BYREF

progname = (__int64)*argv;
v3 = argc == 0;
v4 = argc == 1;
if ( argc <= 1 )
{
v7 = 1;
}
else
{
v7 = 1;
for ( i = 1; i < argc; v4 = argc == i )
{
v17 = i;
v18 = "-display";
v19 = 9LL;
v20 = argv[v17];
do
{
if ( !v19 )
break;
v3 = *v20 < (unsigned int)*v18;
v4 = *v20++ == *v18++;
--v19;
}
while ( v4 );
v21 = (!v3 && !v4) - v3;
v12 = 0;
v13 = v21 == 0;
if ( v21 )
{
v9 = "-count";
v10 = 7LL;
v11 = argv[i];
do
{
if ( !v10 )
break;
v12 = *v11 < (unsigned int)*v9;
v13 = *v11++ == *v9++;
--v10;
}
while ( v13 );
v14 = (!v12 && !v13) - v12;
v15 = 0;
v16 = v14 == 0;
if ( v14 )
{
v22 = "-window";
v23 = 8LL;
v24 = argv[i];
do
{
if ( !v23 )
break;
v15 = *v24 < (unsigned int)*v22;
v16 = *v24++ == *v22++;
--v23;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
{
if ( argc == ++i )
func10(v22, v24, v17 * 8);
if ( !strcmp(argv[v17 + 1], "root") )
window = -1LL;
else
window = strtoul(argv[v17 + 1], 0LL, 0);
}
else
{
if ( *argv[i] == 45 )
{
fprintf(stderr, "%s: bad option `%s'.\n", (const char *)progname, argv[i]);
((void (*)(void))usage)();
}
strncpy(&keyname, argv[i], 0x3FFuLL);
keysym = 0;
shift = 0;
for ( j = strtok(&keyname, "+"); j; j = strtok(0LL, "+") )
{
if ( !strcmp(j, "Alt") )
{
LABEL_41:
shift |= 8u;
}
else if ( !strcmp(j, "Control") )
{
LABEL_34:
shift |= 4u;
}
else if ( !strcmp(j, "Shift") )
{
LABEL_39:
shift |= 1u;
}
else
{
v26 = XStringToKeysym(j);
if ( !v26 )
{
fprintf(stderr, "unknown: %s\n", j);
((void (*)(void))usage)();
}
switch ( v26 )
{
case 65505:
case 65506:
goto LABEL_39;
case 65507:
case 65508:
goto LABEL_34;
case 65509:
case 65510:
shift |= 2u;
break;
case 65511:
case 65512:
case 65513:
case 65514:
goto LABEL_41;
case 65515:
case 65516:
case 65517:
case 65518:
continue;
default:
keysym = v26;
break;
}
}
}
}
}
else
{
if ( argc == ++i )
func10(v9, v11, v17 * 8);
v7 = strtoul(argv[v17 + 1], 0LL, 0);
}
}
else
{
if ( argc == ++i )
func10(v18, v20, v17 * 8);
displayname = (char *)argv[v17 + 1];
}
v3 = argc < (unsigned int)++i;
}
}
if ( !keyname )
{
fprintf(stderr, "%s: you must specify a keyname.\n", (const char *)progname);
exit(1);
}
if ( !displayname )
{
displayname = getenv("DISPLAY");
if ( !displayname )
displayname = ":0.0";
}
v27 = XOpenDisplay(displayname);
display = v27;
if ( !v27 )
{
fprintf(stderr, "%s: can't open display `%s'.\n", (const char *)progname, displayname);
exit(1);
}
if ( !window )
XGetInputFocus(v27, &window, v30);
if ( window == -1LL )
window = display->screens->root;
if ( v7 > 0 )
{
for ( k = 0; k != v7; ++k )
func9(keysym, shift);
}
XCloseDisplay(display);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int ii, Junk;
    int c;
    char *temp;
    unsigned long count = 1;
    progname = argv[0];
    for(ii=1; ii<argc; ii++) {
        if(strcmp(argv[ii], "-display") == 0) {
            if(++ii == argc)
                usage();
            displayname = argv[ii];
        }
        else if(strcmp(argv[ii], "-count") == 0) {
            if(++ii == argc)
                usage();
            count = strtoul(argv[ii],((void *)0),0);
        }
        else if(strcmp(argv[ii], "-window") == 0) {
            if(++ii == argc)
                usage();
            if(strcmp(argv[ii], "root") == 0)
                window = (Window)-1;
            else
                window = (Window)strtoul(argv[ii], ((void *)0), 0);
        }
        else if(argv[ii][0] == '-') {
            fprintf(stderr, "%s: bad option `%s'.\n",
                progname, argv[ii]);
            usage();
        }
        else {
            strncpy(keyname, argv[ii], 1023);
            keysym = 0;
            shift = 0;
            temp = strtok((char *)keyname, "+");
            while (temp != ((void *)0)) {
                if (strcmp(temp, "Alt") == 0)
                    c = 0xffe9;
                else if (strcmp(temp, "Control") == 0)
                    c = 0xffe3;
                else if (strcmp(temp, "Shift") == 0)
                    c = 0xffe1;
                else
                    c = XStringToKeysym(temp);
                if (c == 0) {
                    fprintf(stderr, "unknown: %s\n", temp);
                    usage();
                }
                switch (c) {
                    case 0xffe1:
                    case 0xffe2:
                        shift |= (1<<0);
                        break;
                    case 0xffe3:
                    case 0xffe4:
                        shift |= (1<<2);
                        break;
                    case 0xffe5:
                    case 0xffe6:
                        shift |= (1<<1);
                        break;
                    case 0xffe7:
                    case 0xffe8:
                    case 0xffe9:
                    case 0xffea:
                        shift |= (1<<3);
                        break;
                    case 0xffeb:
                    case 0xffec:
                    case 0xffed:
                    case 0xffee:
                        break;
                    default:
                        keysym = c;
                }
                temp = strtok(((void *)0), "+");
            }
        }
    }
    if (keyname[0] == 0) {
        fprintf(stderr, "%s: you must specify a keyname.\n", progname);
        exit(1);
    }
    if(displayname == ((void *)0))
 displayname = getenv("DISPLAY");
    if(displayname == ((void *)0))
 displayname = ":0.0";
    display = XOpenDisplay(displayname);
    if(display == ((void *)0))
    {
 fprintf(stderr, "%s: can't open display `%s'.\n",
  progname, displayname);
 exit(1);
    }
    if(window == 0)
        XGetInputFocus(display, &window, &Junk);
    if(window == (Window)-1)
    {
        window = ((&((_XPrivDisplay)(display))->screens[0])->root);
    }
    for (ii=0;ii<(int)count;ii++)
      SendKeyPressedEvent(keysym, shift);
    XCloseDisplay(display);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int ii; int Junk;
    int c;
    char *temp;
    unsigned long count = 1;
    progname = argv[0];
    for(ii=1; ii<argc; ii++) {
        if(strcmp(argv[ii], "-display") == 0) {
            if(++ii == argc)
                usage();
            displayname = argv[ii];
        }
        else if(strcmp(argv[ii], "-count") == 0) {
            if(++ii == argc)
                usage();
            count = strtoul(argv[ii],((void *)0),0);
        }
        else if(strcmp(argv[ii], "-window") == 0) {
            if(++ii == argc)
                usage();
            if(strcmp(argv[ii], "root") == 0)
                window = (Window)-1;
            else
                window = (unsigned long)strtoul(argv[ii], ((void *)0), 0);
        }
        else if(argv[ii][0] == '-') {
            fprintf(stderr, "%s: bad option `%s'.\n",
                progname, argv[ii]);
            usage();
        }
        else {
            strncpy(keyname, argv[ii], 1023);
            keysym = 0;
            shift = 0;
            temp = strtok((char *)keyname, "+");
            while (temp != ((void *)0)) {
                if (strcmp(temp, "Alt") == 0)
                    c = 0xffe9;
                else if (strcmp(temp, "Control") == 0)
                    c = 0xffe3;
                else if (strcmp(temp, "Shift") == 0)
                    c = 0xffe1;
                else
                    c = XStringToKeysym(temp);
                if (c == 0) {
                    fprintf(stderr, "unknown: %s\n", temp);
                    usage();
                }
                switch (c) {
                    case 0xffe1:
                    case 0xffe2:
                        shift |= (1<<0);
                        break;
                    case 0xffe3:
                    case 0xffe4:
                        shift |= (1<<2);
                        break;
                    case 0xffe5:
                    case 0xffe6:
                        shift |= (1<<1);
                        break;
                    case 0xffe7:
                    case 0xffe8:
                    case 0xffe9:
                    case 0xffea:
                        shift |= (1<<3);
                        break;
                    case 0xffeb:
                    case 0xffec:
                    case 0xffed:
                    case 0xffee:
                        break;
                    default:
                        keysym = c;
                }
                temp = strtok(((void *)0), "+");
            }
        }
    }
    if (keyname[0] == 0) {
        fprintf(stderr, "%s: you must specify a keyname.\n", progname);
        exit(1);
    }
    if(displayname == ((void *)0))
 displayname = getenv("DISPLAY");
    if(displayname == ((void *)0))
 displayname = ":0.0";
    display = XOpenDisplay(displayname);
    if(display == ((void *)0))
    {
 fprintf(stderr, "%s: can't open display `%s'.\n",
  progname, displayname);
 exit(1);
    }
    if(window == 0)
        XGetInputFocus(display, &window, &Junk);
    if(window == (Window)-1)
    {
        window = ((&((_XPrivDisplay)(display))->screens[0])->root);
    }
    for (ii=0;ii<(int)count;ii++)
      SendKeyPressedEvent(keysym, shift);
    XCloseDisplay(display);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ii int

variable_types: Junk int

variable_types: c int

variable_types:
temp
char *

variable_types:
count
unsigned long


repo: kyuba/curie

original_code:
sexpr sx_set_add (sexpr set, sexpr item)
{
    sexpr c = set;
    while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
    {
        if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), item)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return set;
        }
        c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return cons (item, set);
}

canonical_original_code:
unsigned long sx_set_add(unsigned long set, unsigned long item)
{
    unsigned long c = set;
    while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
    {
        if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), item)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return set;
        }
        c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return cons (item, set);
}

variable_types:
set
unsigned long

variable_types:
item
unsigned long

variable_types:
c
unsigned long

return_type: unsigned long

user_defined_types: struct sexpr_cons { enum sx_type type; unsigned long car; unsigned long cdr; }

user_defined_types: enum sx_type { sxt_string=4, sxt_symbol=5, sxt_cons=6, sxt_rational=20 }


original_code:
sexpr sx_set_remove (sexpr set, sexpr item)
{
    sexpr rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)), c = set, t;
    while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        if (((sexpr)(equalp (t, item)) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
        {
            rv = cons (t, rv);
        }
        c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}

canonical_original_code:
unsigned long sx_set_remove(unsigned long set, unsigned long item)
{
    unsigned long rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)); unsigned long c = set; unsigned long t;
    while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        if (((sexpr)(equalp (t, item)) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
        {
            rv = cons (t, rv);
        }
        c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}

variable_types:
rv
unsigned long

variable_types:
t
unsigned long


original_code:
sexpr sx_set_merge (sexpr a, sexpr b)
{
    sexpr c, t;
    while ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = a;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                goto next;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        a = cons (t, a);
      next:
        b = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return a;
}

canonical_original_code:
unsigned long sx_set_merge(unsigned long a, unsigned long b)
{
    unsigned long c; unsigned long t;
    while ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = a;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                goto next;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        a = cons (t, a);
      next:
        b = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return a;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


original_code:
sexpr sx_set_intersect (sexpr a, sexpr b)
{
    sexpr rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)), c, t;
    while ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = a;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                rv = cons (t, rv);
                goto next;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
      next:
        b = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}

canonical_original_code:
unsigned long sx_set_intersect(unsigned long a, unsigned long b)
{
    unsigned long rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)); unsigned long c; unsigned long t;
    while ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = a;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                rv = cons (t, rv);
                goto next;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
      next:
        b = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}


original_code:
sexpr sx_set_difference (sexpr a, sexpr b)
{
    sexpr rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)), c, t, ob = b;
    while ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = a;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                goto next_a;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        rv = cons (t, rv);
      next_a:
        b = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    while ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = ob;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                goto next_b;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        rv = cons (t, rv);
      next_b:
        a = ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}

canonical_original_code:
unsigned long sx_set_difference(unsigned long a, unsigned long b)
{
    unsigned long rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)); unsigned long c; unsigned long t; unsigned long ob = b;
    while ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = a;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                goto next_a;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        rv = cons (t, rv);
      next_a:
        b = ((((((int_pointer)(b)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)b))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)b))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    while ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)))
    {
        t = ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        c = ob;
        while ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)))
        {
            if (((sexpr)(equalp (((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), t)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                goto next_b;
            }
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        rv = cons (t, rv);
      next_b:
        a = ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}

variable_types:
ob
unsigned long


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

result = 21LL;
if ( (a1 & 1) == 0 )
{
do
{
if ( *(_DWORD *)a1 != 6 )
return 21LL;
result = equalp(*(_QWORD *)(a1 + 8), a2);
if ( result == 29 )
return result;
if ( *(_DWORD *)a1 != 6 )
return 21LL;
a1 = *(_QWORD *)(a1 + 16);
}
while ( (a1 & 1) == 0 );
result = 21LL;
}
return result;
}

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

result = 21LL;
if ( (a1 & 1) == 0 )
{
do
{
if ( *(_DWORD *)a1 != 6 )
return 21LL;
result = equalp(*(_QWORD *)(a1 + 8), a2);
if ( result == 29 )
return result;
if ( *(_DWORD *)a1 != 6 )
return 21LL;
a1 = *(_QWORD *)(a1 + 16);
}
while ( (a1 & 1) == 0 );
result = 21LL;
}
return result;
}

original_code:
sexpr sx_set_memberp (sexpr set, sexpr item)
{
    while ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)))
    {
        if (((sexpr)(equalp (((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), item)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
        }
        set = ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
unsigned long sx_set_memberp(unsigned long set, unsigned long item)
{
    while ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)))
    {
        if (((sexpr)(equalp (((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), item)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
        }
        set = ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}


decompiled_code:
__int64 __fastcall sx_list1(__int64 a1)
{
return cons(a1, 45LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return cons(a1, 45LL);
}

original_code:
sexpr sx_list1
    (sexpr alpha)
{
    return cons (alpha, ((sexpr)((((int_pointer)(5)) << 3) | 0x5)));
}

canonical_original_code:
unsigned long sx_list1(unsigned long alpha)
{
    return cons (alpha, ((sexpr)((((int_pointer)(5)) << 3) | 0x5)));
}

variable_types:
alpha
unsigned long


decompiled_code:
__int64 __fastcall sx_list2(__int64 a1, __int64 a2)
{
__int64 v2; // rsi

v2 = sx_list1(a2);
return cons(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rsi

v2 = func0(a2);
return cons(a1, v2);
}

original_code:
sexpr sx_list2
    (sexpr alpha, sexpr beta)
{
    return cons (alpha,
                 sx_list1 (beta));
}

canonical_original_code:
unsigned long sx_list2(unsigned long alpha, unsigned long beta)
{
    return cons (alpha,
                 sx_list1 (beta));
}

variable_types:
beta
unsigned long


decompiled_code:
__int64 __fastcall sx_list3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

v3 = sx_list2(a2, a3);
return cons(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

v3 = func1(a2, a3);
return cons(a1, v3);
}

original_code:
sexpr sx_list3
    (sexpr alpha, sexpr beta, sexpr gamma)
{
    return cons (alpha,
                 sx_list2 (beta, gamma));
}

canonical_original_code:
unsigned long sx_list3(unsigned long alpha, unsigned long beta, unsigned long gamma)
{
    return cons (alpha,
                 sx_list2 (beta, gamma));
}

variable_types:
gamma
unsigned long


decompiled_code:
__int64 __fastcall sx_list4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rax

v4 = sx_list3(a2, a3, a4);
return cons(a1, v4);
}

original_code:
sexpr sx_list4
    (sexpr alpha, sexpr beta, sexpr gamma, sexpr delta)
{
    return cons (alpha,
                 sx_list3 (beta, gamma, delta));
}

canonical_original_code:
unsigned long sx_list4(unsigned long alpha, unsigned long beta, unsigned long gamma, unsigned long delta)
{
    return cons (alpha,
                 sx_list3 (beta, gamma, delta));
}

variable_types:
delta
unsigned long


original_code:
sexpr sx_list5
    (sexpr alpha, sexpr beta, sexpr gamma, sexpr delta, sexpr epsilon)
{
    return cons (alpha,
                 sx_list4 (beta, gamma, delta, epsilon));
}

canonical_original_code:
unsigned long sx_list5(unsigned long alpha, unsigned long beta, unsigned long gamma, unsigned long delta, unsigned long epsilon)
{
    return cons (alpha,
                 sx_list4 (beta, gamma, delta, epsilon));
}

variable_types:
epsilon
unsigned long


original_code:
sexpr sx_list6
    (sexpr alpha, sexpr beta, sexpr gamma, sexpr delta, sexpr epsilon,
     sexpr zeta)
{
    return cons (alpha,
                 sx_list5 (beta, gamma, delta, epsilon, zeta));
}

canonical_original_code:
unsigned long sx_list6(unsigned long alpha, unsigned long beta, unsigned long gamma, unsigned long delta, unsigned long epsilon, unsigned long zeta)
{
    return cons (alpha,
                 sx_list5 (beta, gamma, delta, epsilon, zeta));
}

variable_types:
zeta
unsigned long


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

result = get_pool_mem(&pool_3);
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
*(_QWORD *)(result + 24) = list;
list = result;
return result;
}

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

result = get_pool_mem(&pool_3);
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
*(_QWORD *)(result + 24) = list;
list = result;
return result;
}

original_code:
static void multiplex_add_tail
        (int fd, void (*on_connect)(struct io *, struct io *, void *),
         void *aux)
{
    static struct memory_pool pool
            = { mpft_static_header, ((((unsigned long)sizeof (struct net_socket_listener)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct net_socket_listener)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct net_socket_listener))) ? ((unsigned short)8) : 0)) };
    struct net_socket_listener *l = get_pool_mem (&pool);
    l->socket = fd;
    l->on_connect = on_connect;
    l->data = aux;
    l->next = list;
    list = l;
}

canonical_original_code:
static void multiplex_add_tail(int fd, void (*on_connect)(struct io *, struct io *, void *), void *aux)
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct net_socket_listener)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct net_socket_listener)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct net_socket_listener))) ? ((unsigned short)8) : 0)) };
    struct net_socket_listener *l = get_pool_mem (&pool);
    l->socket = fd;
    l->on_connect = on_connect;
    l->data = aux;
    l->next = list;
    list = l;
}

variable_types: fd int

variable_types: void (*)(struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *, struct io *, void *)

variable_types:
aux
void *

variable_types: struct memory_pool { enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 } type; unsigned int entitysize; }

variable_types: struct net_socket_listener { int socket; void (*on_connect)(struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *, struct io *, void *); void *data; struct net_socket_listener *next; } *

user_defined_types: struct memory_pool { enum memory_pool_frame_type type; unsigned int entitysize; }

user_defined_types: struct net_socket_listener { int socket; void (*on_connect)(struct io *, struct io *, void *); void *data; struct net_socket_listener *next; }

user_defined_types: struct io { int fd; char *buffer; enum io_type type; enum io_result status; unsigned int length; unsigned int position; unsigned int buffersize; }


decompiled_code:
__int64 multiplex_network()
{
__int64 result; // rax

if ( !installed_5 )
{
result = multiplex_add(mx_functions_4);
installed_5 = 1;
}
return result;
}

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

if ( !installed_5 )
{
result = multiplex_add(mx_functions_4);
installed_5 = 1;
}
return result;
}

original_code:
void multiplex_network() {
    static struct multiplex_functions mx_functions =
    {
        .count = mx_f_count,
        .augment = mx_f_augment,
        .callback = mx_f_callback,
        .next = (struct multiplex_functions *)0
    };
    static char installed = (char)0;
    if (installed == (char)0) {
        multiplex_add (&mx_functions);
        installed = (char)1;
    }
}

variable_types: struct multiplex_functions { enum multiplex_result { mx_ok=0, mx_nothing_to_do=1, mx_immediate_action=2 } (*count)(int *, int *); void (*augment)(int *, int *, int *, int *); void (*callback)(int *, int, int *, int); struct multiplex_functions *next; }

variable_types: installed char

user_defined_types: struct multiplex_functions { enum multiplex_result (*count)(int *, int *); void (*augment)(int *, int *, int *, int *); void (*callback)(int *, int, int *, int); struct multiplex_functions *next; }


decompiled_code:
__int64 __fastcall multiplex_add_socket(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a_open_listen_socket(v5, a1);
if ( (_DWORD)result == 5 )
result = multiplex_add_tail(v5[0], a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a_open_listen_socket(v5, a1);
if ( (_DWORD)result == 5 )
result = func4(v5[0], a2, a3);
return result;
}

original_code:
void multiplex_add_socket
        (const char *path, void (*on_connect)(struct io *, struct io *, void *),
         void *aux)
{
    int fd;
    if (a_open_listen_socket (&fd, path) == io_complete)
    {
        multiplex_add_tail (fd, on_connect, aux);
    }
}

canonical_original_code:
void multiplex_add_socket(char *path, void (*on_connect)(struct io *, struct io *, void *), void *aux)
{
    int fd;
    if (a_open_listen_socket (&fd, path) == io_complete)
    {
        multiplex_add_tail (fd, on_connect, aux);
    }
}

variable_types:
path
char *

user_defined_types: enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 }

user_defined_types: enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 }


decompiled_code:
__int64 __fastcall multiplex_add_ip4(unsigned int a1, unsigned __int16 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a_open_listen_ip4(v7, a1, a2);
if ( (_DWORD)result == 5 )
result = multiplex_add_tail(v7[0], a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, unsigned __int16 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a_open_listen_ip4(v7, a1, a2);
if ( (_DWORD)result == 5 )
result = func4(v7[0], a3, a4);
return result;
}

original_code:
void multiplex_add_ip4
        (int_32 addr, int_16 port,
         void (*on_connect)(struct io *, struct io *, void *), void *aux)
{
    int fd;
    if (a_open_listen_ip4 (&fd, addr, port) == io_complete)
    {
        multiplex_add_tail (fd, on_connect, aux);
    }
}

canonical_original_code:
void multiplex_add_ip4(unsigned int addr, unsigned short port, void (*on_connect)(struct io *, struct io *, void *), void *aux)
{
    int fd;
    if (a_open_listen_ip4 (&fd, addr, port) == io_complete)
    {
        multiplex_add_tail (fd, on_connect, aux);
    }
}

variable_types:
addr
unsigned int

variable_types:
port
unsigned short


decompiled_code:
__int64 __fastcall multiplex_add_ip6(__int64 a1, unsigned __int16 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a_open_listen_ip6(v7, a1, a2);
if ( (_DWORD)result == 5 )
result = multiplex_add_tail(v7[0], a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned __int16 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

result = a_open_listen_ip6(v7, a1, a2);
if ( (_DWORD)result == 5 )
result = func4(v7[0], a3, a4);
return result;
}

original_code:
void multiplex_add_ip6
        (int_8 addr[16], int_16 port,
         void (*on_connect)(struct io *, struct io *, void *), void *aux)
{
    int fd;
    if (a_open_listen_ip6 (&fd, addr, port) == io_complete)
    {
        multiplex_add_tail (fd, on_connect, aux);
    }
}

canonical_original_code:
void multiplex_add_ip6(unsigned char addr[16], unsigned short port, void (*on_connect)(struct io *, struct io *, void *), void *aux)
{
    int fd;
    if (a_open_listen_ip6 (&fd, addr, port) == io_complete)
    {
        multiplex_add_tail (fd, on_connect, aux);
    }
}

variable_types:
addr
unsigned char [16]


decompiled_code:
__int64 __fastcall mx_f_count(_DWORD *a1)
{
__int64 i; // rax

for ( i = list; i; i = *(_QWORD *)(i + 24) )
{
if ( *(int *)i >= 0 )
++*a1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 i; // rax

for ( i = list; i; i = *(_QWORD *)(i + 24) )
{
if ( *(int *)i >= 0 )
++*a1;
}
return 0LL;
}

original_code:
static enum multiplex_result mx_f_count(int *r, int *w) {
    struct net_socket_listener *l = list;
    while (l != (struct net_socket_listener *)0)
    {
        if (l->socket >= 0)
        {
            (*r) += 1;
        }
        l = l->next;
    }
    return mx_ok;
}

variable_types:
r
int *

variable_types:
w
int *

return_type: enum multiplex_result { mx_ok=0, mx_nothing_to_do=1, mx_immediate_action=2 }


original_code:
static void mx_f_augment(int *rs, int *r, int *ws, int *w)
{
    struct net_socket_listener *l = list;
    while (l != (struct net_socket_listener *)0)
    {
        if (l->socket >= 0)
        {
            int i, j = (*r);
            for (i = 0; i < j; i++)
            {
                if (rs[i] == l->socket)
                {
                    goto next;
                }
            }
            rs[i] = l->socket;
            (*r) += 1;
        }
        next:
        l = l->next;
    }
}

canonical_original_code:
static void mx_f_augment(int *rs, int *r, int *ws, int *w)
{
    struct net_socket_listener *l = list;
    while (l != (struct net_socket_listener *)0)
    {
        if (l->socket >= 0)
        {
            int i; int j = (*r);
            for (i = 0; i < j; i++)
            {
                if (rs[i] == l->socket)
                {
                    goto next;
                }
            }
            rs[i] = l->socket;
            (*r) += 1;
        }
        next:
        l = l->next;
    }
}

variable_types:
rs
int *

variable_types:
ws
int *

variable_types: i int

variable_types: j int


original_code:
static void mx_f_callback(int *rs, int r, int *ws, int w)
{
    struct net_socket_listener *l = list, *p = (struct net_socket_listener *)0;
    while (l != (struct net_socket_listener *)0)
    {
        next:
        if (l->socket >= 0)
        {
            int i;
            for (i = 0; i < r; i++)
            {
                if (rs[i] == l->socket)
                {
                    int fdr, fdw;
                    enum io_result res;
                    if ((res = a_accept_socket (&fdr, l->socket))== io_complete)
                    {
                        fdw = a_dup_n (fdr);
                        if (fdw >= 0)
                        {
                            struct io *in, *out;
                            in = io_open (fdr);
                            out = io_open (fdw);
                            in->type = iot_read;
                            out->type = iot_write;
                            l->on_connect(in, out, l->data);
                        }
                        else
                        {
                            (void)a_close (fdr);
                        }
                    }
                    else if (res == io_unrecoverable_error)
                    {
                        (void)a_close (rs[i]);
                        if (p == (struct net_socket_listener *)0)
                        {
                            list = l->next;
                            free_pool_mem (l);
                            l = list->next;
                        }
                        else
                        {
                            p->next = l->next;
                            free_pool_mem (l);
                            l = p->next;
                        }
                        if (l != (struct net_socket_listener *)0)
                        {
                            goto next;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
        p = l;
        l = l->next;
    }
}

canonical_original_code:
static void mx_f_callback(int *rs, int r, int *ws, int w)
{
    struct net_socket_listener *l = list; struct net_socket_listener *p = (struct net_socket_listener *)0;
    while (l != (struct net_socket_listener *)0)
    {
        next:
        if (l->socket >= 0)
        {
            int i;
            for (i = 0; i < r; i++)
            {
                if (rs[i] == l->socket)
                {
                    int fdr; int fdw;
                    enum io_result res;
                    if ((res = a_accept_socket (&fdr, l->socket))== io_complete)
                    {
                        fdw = a_dup_n (fdr);
                        if (fdw >= 0)
                        {
                            struct io *in; struct io *out;
                            in = io_open (fdr);
                            out = io_open (fdw);
                            in->type = iot_read;
                            out->type = iot_write;
                            l->on_connect(in, out, l->data);
                        }
                        else
                        {
                            (void)a_close (fdr);
                        }
                    }
                    else if (res == io_unrecoverable_error)
                    {
                        (void)a_close (rs[i]);
                        if (p == (struct net_socket_listener *)0)
                        {
                            list = l->next;
                            free_pool_mem (l);
                            l = list->next;
                        }
                        else
                        {
                            p->next = l->next;
                            free_pool_mem (l);
                            l = p->next;
                        }
                        if (l != (struct net_socket_listener *)0)
                        {
                            goto next;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
        p = l;
        l = l->next;
    }
}

variable_types: r int

variable_types: w int

variable_types: fdr int

variable_types: fdw int

variable_types: struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *


multiplex

decompiled_code:
__int64 multiplex()
{
__int64 v0; // rbx
void *v1; // rsp
void *v2; // rsp
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+8h] [rbp-28h] BYREF
int v9[9]; // [rsp+Ch] [rbp-24h] BYREF

v0 = mx_func_list;
v9[0] = 0;
v8 = 0;
if ( !mx_func_list )
return 1LL;
do
{
if ( (*(unsigned int (__fastcall **)(int *, unsigned int *))v0)(v9, &v8) == 2 )
{
v6 = mx_func_list;
if ( !mx_func_list )
return 0LL;
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(v6 + 16))(0LL, 0LL, 0LL, 0LL);
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
return 0LL;
}
v0 = *(_QWORD *)(v0 + 24);
}
while ( v0 );
if ( !v9[0] && !v8 )
return 1LL;
v1 = alloca(16 * ((4LL * v9[0] + 15) / 0x10uLL));
v2 = alloca(16 * ((4LL * (int)v8 + 15) / 0x10uLL));
v9[0] = 0;
v8 = 0;
v3 = mx_func_list;
if ( !mx_func_list )
return 1LL;
do
{
(*(void (__fastcall **)(__int64 *, int *, __int64 *, unsigned int *))(v3 + 8))(&v7, v9, &v7, &v8);
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
if ( v9[0] || (result = 1LL, v8) )
{
a_select_with_fds(&v7, (unsigned int)v9[0], &v7, v8);
v5 = mx_func_list;
if ( mx_func_list )
{
do
{
(*(void (__fastcall **)(__int64 *, _QWORD, __int64 *, _QWORD))(v5 + 16))(&v7, (unsigned int)v9[0], &v7, v8);
v5 = *(_QWORD *)(v5 + 24);
}
while ( v5 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
void *v1; // rsp
void *v2; // rsp
__int64 v3; // rbx
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+8h] [rbp-28h] BYREF
int v9[9]; // [rsp+Ch] [rbp-24h] BYREF

v0 = mx_func_list;
v9[0] = 0;
v8 = 0;
if ( !mx_func_list )
return 1LL;
do
{
if ( (*(unsigned int (__fastcall **)(int *, unsigned int *))v0)(v9, &v8) == 2 )
{
v6 = mx_func_list;
if ( !mx_func_list )
return 0LL;
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(v6 + 16))(0LL, 0LL, 0LL, 0LL);
v6 = *(_QWORD *)(v6 + 24);
}
while ( v6 );
return 0LL;
}
v0 = *(_QWORD *)(v0 + 24);
}
while ( v0 );
if ( !v9[0] && !v8 )
return 1LL;
v1 = alloca(16 * ((4LL * v9[0] + 15) / 0x10uLL));
v2 = alloca(16 * ((4LL * (int)v8 + 15) / 0x10uLL));
v9[0] = 0;
v8 = 0;
v3 = mx_func_list;
if ( !mx_func_list )
return 1LL;
do
{
(*(void (__fastcall **)(__int64 *, int *, __int64 *, unsigned int *))(v3 + 8))(&v7, v9, &v7, &v8);
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
if ( v9[0] || (result = 1LL, v8) )
{
a_select_with_fds(&v7, (unsigned int)v9[0], &v7, v8);
v5 = mx_func_list;
if ( mx_func_list )
{
do
{
(*(void (__fastcall **)(__int64 *, _QWORD, __int64 *, _QWORD))(v5 + 16))(&v7, (unsigned int)v9[0], &v7, v8);
v5 = *(_QWORD *)(v5 + 24);
}
while ( v5 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
enum multiplex_result multiplex () {
    struct multiplex_functions *cur = mx_func_list;
    int rnum = 0, wnum = 0;
    for (cur = mx_func_list;
         cur != (struct multiplex_functions *)0;
         cur = cur->next)
    {
        if (cur->count (&rnum, &wnum) == mx_immediate_action)
        {
            for (cur = mx_func_list;
                 cur != (struct multiplex_functions *)0;
                 cur = cur->next)
            {
                cur->callback ((int *)0, 0, (int *)0, 0);
            }
            return mx_ok;
        }
    }
    if ((rnum == 0) && (wnum == 0)) {
        return mx_nothing_to_do;
    } else {
        int rfds[rnum], wfds[wnum];
        rnum = 0;
        wnum = 0;
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->augment (rfds, &rnum, wfds, &wnum);
        }
        if ((rnum == 0) && (wnum == 0)) {
            return mx_nothing_to_do;
        }
        a_select_with_fds (rfds, rnum, wfds, wnum);
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->callback (rfds, rnum, wfds, wnum);
        }
        return mx_ok;
    }
}

canonical_original_code:
enum multiplex_result multiplex() {
    struct multiplex_functions *cur = mx_func_list;
    int rnum = 0; int wnum = 0;
    for (cur = mx_func_list;
         cur != (struct multiplex_functions *)0;
         cur = cur->next)
    {
        if (cur->count (&rnum, &wnum) == mx_immediate_action)
        {
            for (cur = mx_func_list;
                 cur != (struct multiplex_functions *)0;
                 cur = cur->next)
            {
                cur->callback ((int *)0, 0, (int *)0, 0);
            }
            return mx_ok;
        }
    }
    if ((rnum == 0) && (wnum == 0)) {
        return mx_nothing_to_do;
    } else {
        int rfds[-1]; int wfds[-1];
        rnum = 0;
        wnum = 0;
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->augment (rfds, &rnum, wfds, &wnum);
        }
        if ((rnum == 0) && (wnum == 0)) {
            return mx_nothing_to_do;
        }
        a_select_with_fds (rfds, rnum, wfds, wnum);
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->callback (rfds, rnum, wfds, wnum);
        }
        return mx_ok;
    }
}

variable_types: struct multiplex_functions { enum multiplex_result { mx_ok=0, mx_nothing_to_do=1, mx_immediate_action=2 } (*count)(int *, int *); void (*augment)(int *, int *, int *, int *); void (*callback)(int *, int, int *, int); struct multiplex_functions *next; } *

variable_types: rnum int

variable_types: wnum int

variable_types:
rfds
int [-1]

variable_types:
wfds
int [-1]


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

result = mx_func_list;
*(_QWORD *)(a1 + 24) = mx_func_list;
mx_func_list = a1;
return result;
}

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

result = mx_func_list;
*(_QWORD *)(a1 + 24) = mx_func_list;
mx_func_list = a1;
return result;
}

original_code:
void multiplex_add (struct multiplex_functions *mx) {
    mx->next = mx_func_list;
    mx_func_list = mx;
}

canonical_original_code:
void multiplex_add(struct multiplex_functions *mx) {
    mx->next = mx_func_list;
    mx_func_list = mx;
}

user_defined_types: enum multiplex_result { mx_ok=0, mx_nothing_to_do=1, mx_immediate_action=2 }


decompiled_code:
__int64 __fastcall sx_register_type(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax

result = get_pool_mem(&pool_0);
if ( result )
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a5;
*(_QWORD *)(result + 40) = a6;
*(_QWORD *)(result + 48) = a7;
*(_QWORD *)(result + 56) = sxcd;
sxcd = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax

result = get_pool_mem(&pool_0);
if ( result )
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a5;
*(_QWORD *)(result + 40) = a6;
*(_QWORD *)(result + 48) = a7;
*(_QWORD *)(result + 56) = sxcd;
sxcd = result;
}
return result;
}

original_code:
void sx_register_type
        (unsigned int type,
         sexpr (*serialise) (sexpr), sexpr (*unserialise) (sexpr),
         void (*tag) (sexpr), void (*destroy) (sexpr), void (*call) (),
         sexpr (*equalp) (sexpr, sexpr))
{
    static struct memory_pool pool =
            { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_type_descriptor))) ? ((unsigned short)8) : 0)) };
    struct sexpr_type_descriptor *d = get_pool_mem (&pool);
    if (d == (struct sexpr_type_descriptor *)0)
    {
        return;
    }
    d->type = type;
    d->serialise = serialise;
    d->unserialise = unserialise;
    d->tag = tag;
    d->destroy = destroy;
    d->call = call;
    d->equalp = equalp;
    d->next = sxcd;
    sxcd = d;
}

canonical_original_code:
void sx_register_type(unsigned int type, unsigned long (*serialise)(unsigned long), unsigned long (*unserialise)(unsigned long), void (*tag)(unsigned long), void (*destroy)(unsigned long), void (*call)(), unsigned long (*equalp)(unsigned long, unsigned long))
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_type_descriptor))) ? ((unsigned short)8) : 0)) };
    struct sexpr_type_descriptor *d = get_pool_mem (&pool);
    if (d == (struct sexpr_type_descriptor *)0)
    {
        return;
    }
    d->type = type;
    d->serialise = serialise;
    d->unserialise = unserialise;
    d->tag = tag;
    d->destroy = destroy;
    d->call = call;
    d->equalp = equalp;
    d->next = sxcd;
    sxcd = d;
}

variable_types:
type
unsigned int

variable_types:
unserialise
unsigned long (*)(unsigned long)

variable_types:
tag
void (*)(unsigned long)

variable_types:
destroy
void (*)(unsigned long)

variable_types:
call
void (*)()

variable_types: unsigned long (*)(unsigned long, unsigned long)

variable_types: struct memory_pool { enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 } type; unsigned int entitysize; }

variable_types: struct sexpr_type_descriptor { unsigned int type; unsigned long (*serialise)(unsigned long); unsigned long (*unserialise)(unsigned long); void (*tag)(unsigned long); void (*destroy)(unsigned long); void (*call)(); unsigned long (*equalp)(unsigned long, unsigned long); struct sexpr_type_descriptor *next; } *


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

for ( result = sxcd; result; result = *(_QWORD *)(result + 56) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = sxcd; result; result = *(_QWORD *)(result + 56) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
struct sexpr_type_descriptor *sx_get_descriptor (unsigned int type)
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->type == type)
        {
            return d;
        }
        d = d->next;
    }
    return (struct sexpr_type_descriptor *)0;
}

canonical_original_code:
struct sexpr_type_descriptor *sx_get_descriptor(unsigned int type)
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->type == type)
        {
            return d;
        }
        d = d->next;
    }
    return (struct sexpr_type_descriptor *)0;
}

return_type: struct sexpr_type_descriptor { unsigned int type; unsigned long (*serialise)(unsigned long); unsigned long (*unserialise)(unsigned long); void (*tag)(unsigned long); void (*destroy)(unsigned long); void (*call)(); unsigned long (*equalp)(unsigned long, unsigned long); struct sexpr_type_descriptor *next; } *


decompiled_code:
__int64 sx_call_custom()
{
__int64 i; // rbx
__int64 result; // rax
__int64 (*v2)(void); // rdx

for ( i = sxcd; i; i = *(_QWORD *)(i + 56) )
{
v2 = *(__int64 (**)(void))(i + 40);
if ( v2 )
result = v2();
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 i; // rbx
__int64 result; // rax
__int64 (*v2)(void); // rdx

for ( i = sxcd; i; i = *(_QWORD *)(i + 56) )
{
v2 = *(__int64 (**)(void))(i + 40);
if ( v2 )
result = v2();
}
return result;
}

original_code:
void sx_call_custom ( void )
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->call != (void *)0)
        {
            d->call ();
        }
        d = d->next;
    }
}

canonical_original_code:
void sx_call_custom()
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->call != (void *)0)
        {
            d->call ();
        }
        d = d->next;
    }
}

user_defined_types: struct sexpr_type_descriptor { unsigned int type; unsigned long (*serialise)(unsigned long); unsigned long (*unserialise)(unsigned long); void (*tag)(unsigned long); void (*destroy)(unsigned long); void (*call)(); unsigned long (*equalp)(unsigned long, unsigned long); struct sexpr_type_descriptor *next; }


partition

decompiled_code:
__int64 __fastcall partition(unsigned int a1, int a2, int a3)
{
__int64 v4; // r8
unsigned __int64 *v5; // rax
unsigned __int64 v6; // rsi
unsigned __int64 *v7; // r11
unsigned __int64 *v8; // rax
unsigned __int64 v9; // r9
unsigned __int64 v10; // rdx
unsigned __int64 *v11; // rcx
__int64 *v12; // rax
__int64 v13; // rdx

v4 = gc_calls;
v5 = (unsigned __int64 *)(gc_calls + 8LL * a3);
v6 = *v5;
v7 = (unsigned __int64 *)(gc_calls + 8LL * a2);
*v5 = *v7;
*v7 = v6;
if ( a2 > (int)a1 )
{
v8 = (unsigned __int64 *)(v4 + 8LL * (int)a1);
v9 = v4 + 8 * ((int)a1 + (unsigned __int64)(a2 - a1 - 1)) + 8;
do
{
v10 = *v8;
if ( *v8 <= v6 )
{
v11 = (unsigned __int64 *)(v4 + 8LL * (int)a1);
*v8 = *v11;
*v11 = v10;
++a1;
}
++v8;
}
while ( v8 != (unsigned __int64 *)v9 );
}
v12 = (__int64 *)(v4 + 8LL * (int)a1);
v13 = *v12;
*v12 = *v7;
*v7 = v13;
return a1;
}

original_code:
static int partition (int left, int right, int pivot)
{
    int index, i;
    sexpr value = gc_calls[pivot], t;
    gc_calls[pivot] = gc_calls[right];
    gc_calls[right] = value;
    index = left;
    for (i = left; i < right; i++)
    {
        if (gc_calls[i] <= value)
        {
            t = gc_calls[i];
            gc_calls[i] = gc_calls[index];
            gc_calls[index] = t;
            index++;
        }
    }
    t = gc_calls[index];
    gc_calls[index] = gc_calls[right];
    gc_calls[right] = t;
    return index;
}

canonical_original_code:
static int partition(int left, int right, int pivot)
{
    int index; int i;
    unsigned long value = gc_calls[pivot]; unsigned long t;
    gc_calls[pivot] = gc_calls[right];
    gc_calls[right] = value;
    index = left;
    for (i = left; i < right; i++)
    {
        if (gc_calls[i] <= value)
        {
            t = gc_calls[i];
            gc_calls[i] = gc_calls[index];
            gc_calls[index] = t;
            index++;
        }
    }
    t = gc_calls[index];
    gc_calls[index] = gc_calls[right];
    gc_calls[right] = t;
    return index;
}

variable_types: left int

variable_types: right int

variable_types: pivot int

variable_types: index int

variable_types: i int

variable_types:
value
unsigned long

variable_types:
t
unsigned long


decompiled_code:
__int64 __fastcall gc_tag(__int64 a1)
{
return gc_tag_sub(a1, gc_calls, gc_pointer);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return func3(a1, gc_calls, gc_pointer);
}

original_code:
void gc_tag (sexpr sx)
{
    gc_tag_sub (sx, gc_calls, gc_pointer);
}

canonical_original_code:
void gc_tag(unsigned long sx)
{
    gc_tag_sub (sx, gc_calls, gc_pointer);
}

variable_types:
sx
unsigned long


decompiled_code:
__int64 gc_initialise_memory()
{
__int64 **v0; // rbx
unsigned __int64 v1; // rbp
__int64 result; // rax

gc_call_size = (gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096;
gc_calls = get_mem((gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096);
gc_pointer = gc_calls;
sx_call_all();
sx_call_custom();
if ( cancel )
{
free_mem(gc_call_size, gc_calls);
result = 0LL;
}
else
{
sort_calls(0, ((gc_pointer - gc_calls) >> 3) - 1);
if ( gc_roots_size )
{
v0 = (__int64 **)gc_roots;
v1 = gc_roots + gc_roots_size;
if ( gc_roots < (unsigned __int64)(gc_roots + gc_roots_size) )
{
do
{
if ( *v0 )
gc_tag(**v0);
++v0;
}
while ( v1 > (unsigned __int64)v0 );
}
}
cancel = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 **v0; // rbx
unsigned __int64 v1; // rbp
__int64 result; // rax

gc_call_size = (gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096;
gc_calls = get_mem((gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096);
gc_pointer = gc_calls;
sx_call_all();
sx_call_custom();
if ( cancel )
{
free_mem(gc_call_size, gc_calls);
result = 0LL;
}
else
{
func1(0, ((gc_pointer - gc_calls) >> 3) - 1);
if ( gc_roots_size )
{
v0 = (__int64 **)gc_roots;
v1 = gc_roots + gc_roots_size;
if ( gc_roots < (unsigned __int64)(gc_roots + gc_roots_size) )
{
do
{
if ( *v0 )
func2(**v0);
++v0;
}
while ( v1 > (unsigned __int64)v0 );
}
}
cancel = 0;
result = 1LL;
}
return result;
}

original_code:
static int gc_initialise_memory ()
{
    gc_call_size = (gc_base_items & (~(0x1000 - 1)))
                  + 0x1000;
    gc_calls = get_mem (gc_call_size);
    gc_pointer = gc_calls;
    sx_call_all();
    sx_call_custom();
    if (cancel)
    {
        free_mem (gc_call_size, gc_calls);
        return 0;
    }
    sort_calls (0, gc_pointer - gc_calls - 1);
    if (gc_roots_size != 0)
    {
        sexpr **rootp, **roote;
        for (rootp = gc_roots,
             roote = (sexpr**)((int_pointer)rootp + gc_roots_size);
             rootp < roote; rootp++)
        {
            if ((*rootp) != (sexpr *)0)
            {
                gc_tag (**rootp);
            }
        }
    }
    cancel = 0;
    return 1;
}

canonical_original_code:
static int gc_initialise_memory()
{
    gc_call_size = (gc_base_items & (~(0x1000 - 1)))
                  + 0x1000;
    gc_calls = get_mem (gc_call_size);
    gc_pointer = gc_calls;
    sx_call_all();
    sx_call_custom();
    if (cancel)
    {
        free_mem (gc_call_size, gc_calls);
        return 0;
    }
    sort_calls (0, gc_pointer - gc_calls - 1);
    if (gc_roots_size != 0)
    {
        unsigned long **rootp; unsigned long **roote;
        for (rootp = gc_roots,
             roote = (unsigned long **)((unsigned long)rootp + gc_roots_size);
             rootp < roote; rootp++)
        {
            if ((*rootp) != (unsigned long *)0)
            {
                gc_tag (**rootp);
            }
        }
    }
    cancel = 0;
    return 1;
}

variable_types:
rootp
unsigned long **

variable_types:
roote
unsigned long **


decompiled_code:
void __fastcall gc_call(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax

if ( !cancel )
{
if ( gc_pointer >= (unsigned __int64)(gc_calls + gc_call_size) )
{
v2 = resize_mem(gc_call_size, gc_calls, gc_call_size + 4096);
gc_pointer = gc_pointer + v2 - gc_calls;
gc_calls = v2;
gc_call_size += 4096LL;
}
v1 = gc_pointer;
*(_QWORD *)gc_pointer = a1;
gc_pointer = v1 + 8;
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax

if ( !cancel )
{
if ( gc_pointer >= (unsigned __int64)(gc_calls + gc_call_size) )
{
v2 = resize_mem(gc_call_size, gc_calls, gc_call_size + 4096);
gc_pointer = gc_pointer + v2 - gc_calls;
gc_calls = v2;
gc_call_size += 4096LL;
}
v1 = gc_pointer;
*(_QWORD *)gc_pointer = a1;
gc_pointer = v1 + 8;
}
}

original_code:
void gc_call (sexpr sx)
{
    sexpr *map;
    if (cancel) return;
    if (gc_pointer < (sexpr*)((int_pointer)gc_calls + gc_call_size))
    {
      add:
        *gc_pointer = sx;
        gc_pointer++;
        return;
    }
    map = resize_mem (gc_call_size, gc_calls, gc_call_size + 0x1000);
    gc_pointer = (sexpr *)((int_pointer)map +
                   ((int_pointer)gc_pointer - (int_pointer)gc_calls));
    gc_calls = map;
    gc_call_size += 0x1000;
    goto add;
}

canonical_original_code:
void gc_call(unsigned long sx)
{
    unsigned long *map;
    if (cancel) return;
    if (gc_pointer < (unsigned long *)((unsigned long)gc_calls + gc_call_size))
    {
      add:
        *gc_pointer = sx;
        gc_pointer++;
        return;
    }
    map = resize_mem (gc_call_size, gc_calls, gc_call_size + 0x1000);
    gc_pointer = (unsigned long *)((unsigned long)map +
                   ((unsigned long)gc_pointer - (unsigned long)gc_calls));
    gc_calls = map;
    gc_call_size += 0x1000;
    goto add;
}

variable_types:
map
unsigned long *


decompiled_code:
__int64 gc_invoke()
{
int v0; // ebp
__int64 *v1; // rbx
__int64 v2; // rdi
__int64 i; // rbp
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

if ( stack_growth )
{
v5[0] = 45LL;
v0 = 1;
if ( stack_growth == 1 )
{
if ( stack_start_address > (unsigned __int64)v5 )
return 0LL;
v0 = 1;
}
}
else
{
v5[0] = 45LL;
v0 = -1;
if ( stack_start_address < (unsigned __int64)v5 )
return 0LL;
}
if ( (unsigned int)gc_initialise_memory() )
{
v1 = (__int64 *)stack_start_address;
for ( i = 8LL * v0; ; v1 = (__int64 *)((char *)v1 + i) )
{
v2 = *v1;
if ( (*v1 & 1) == 0 )
{
if ( v2 )
gc_tag(v2);
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // ebp
__int64 *v1; // rbx
__int64 v2; // rdi
__int64 i; // rbp
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

if ( stack_growth )
{
v5[0] = 45LL;
v0 = 1;
if ( stack_growth == 1 )
{
if ( stack_start_address > (unsigned __int64)v5 )
return 0LL;
v0 = 1;
}
}
else
{
v5[0] = 45LL;
v0 = -1;
if ( stack_start_address < (unsigned __int64)v5 )
return 0LL;
}
if ( (unsigned int)func4() )
{
v1 = (__int64 *)stack_start_address;
for ( i = 8LL * v0; ; v1 = (__int64 *)((char *)v1 + i) )
{
v2 = *v1;
if ( (*v1 & 1) == 0 )
{
if ( v2 )
func2(v2);
}
}
}
return 0LL;
}

original_code:
unsigned long gc_invoke ()
{
    int step = (stack_growth == sg_down) ? -1 : 1;
    sexpr end = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    sexpr *t, *l = &end;
    unsigned int i, k;
    unsigned long rv = 0;
    if (((stack_growth == sg_down) && (stack_start_address < (void *)l)) ||
        ((stack_growth == sg_up) && (stack_start_address > (void *)l)))
    {
        return 0;
    }
    if (((int_pointer)l & (~ (sizeof(sexpr) - 1))) != (int_pointer)l) return 0;
    if (!gc_initialise_memory ()) return 0;
    for (t = stack_start_address; t != l; t += step)
    {
        sexpr e = *t;
        if (((((int_pointer)(e)) & 0x1) == 0x0) && (e != (sexpr)0))
        {
            gc_tag (e);
        }
    }
    for (i = 0, k = (gc_pointer - gc_calls); i < k; i++)
    {
        sexpr sx = gc_calls[i];
        if (sx != (sexpr)0)
        {
            sx_destroy (sx);
            rv++;
        }
    }
    gc_deinitialise_memory ();
    optimise_static_memory_pools ();
    return rv;
}

canonical_original_code:
unsigned long gc_invoke()
{
    int step = (stack_growth == sg_down) ? -1 : 1;
    unsigned long end = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    unsigned long *t; unsigned long *l = &end;
    unsigned int i; unsigned int k;
    unsigned long rv = 0;
    if (((stack_growth == sg_down) && (stack_start_address < (void *)l)) ||
        ((stack_growth == sg_up) && (stack_start_address > (void *)l)))
    {
        return 0;
    }
    if (((unsigned long)l & (~ (sizeof(sexpr) - 1))) != (unsigned long)l) return 0;
    if (!gc_initialise_memory ()) return 0;
    for (t = stack_start_address; t != l; t += step)
    {
        unsigned long e = *t;
        if (((((int_pointer)(e)) & 0x1) == 0x0) && (e != (unsigned long)0))
        {
            gc_tag (e);
        }
    }
    for (i = 0, k = (gc_pointer - gc_calls); i < k; i++)
    {
        unsigned long sx = gc_calls[i];
        if (sx != (unsigned long)0)
        {
            sx_destroy (sx);
            rv++;
        }
    }
    gc_deinitialise_memory ();
    optimise_static_memory_pools ();
    return rv;
}

variable_types: step int

variable_types:
end
unsigned long

variable_types:
t
unsigned long *

variable_types:
l
unsigned long *

variable_types:
i
unsigned int

variable_types:
k
unsigned int

variable_types:
rv
unsigned long

variable_types:
e
unsigned long


decompiled_code:
void __fastcall sort_calls(int a1, int a2)
{
unsigned int v2; // ebx
int v3; // ebp

v2 = a1;
if ( a1 < a2 )
{
do
{
v3 = partition(v2, a2, v2);
sort_calls(v2, (unsigned int)(v3 - 1));
v2 = v3 + 1;
}
while ( a2 > v3 + 1 );
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
unsigned int v2; // ebx
int v3; // ebp

v2 = a1;
if ( a1 < a2 )
{
do
{
v3 = func0(v2, a2, v2);
func1(v2, (unsigned int)(v3 - 1));
v2 = v3 + 1;
}
while ( a2 > v3 + 1 );
}
}

original_code:
static void sort_calls (int left, int right)
{
    int pivot;
    while (right > left)
    {
        pivot = partition (left, right, left);
        sort_calls (left, pivot - 1);
        left = pivot + 1;
    }
}

canonical_original_code:
static void sort_calls(int left, int right)
{
    int pivot;
    while (right > left)
    {
        pivot = partition (left, right, left);
        sort_calls (left, pivot - 1);
        left = pivot + 1;
    }
}

variable_types: left int

variable_types: right int

variable_types: pivot int