kbd

decompiled_code:
__int64 __fastcall kbd(int a1, __int64 *a2, int a3, int a4)
{
int v4; // er14
int v5; // er15
_DWORD *v6; // rax
__int64 v7; // rcx
__int64 result; // rax
int v9; // eax
int v10; // edx
int v11; // ebx
int v12; // edx
unsigned int v13; // eax
__int64 v14; // rbx
__int64 *v15; // r12
int v16; // eax
__int64 v17; // rdx
int v18; // ebx
int v19; // edx
int v20; // eax
int v21; // [rsp+0h] [rbp-48h]
int v22; // [rsp+4h] [rbp-44h]

v22 = a3;
v21 = a4;
if ( my_win )
{
v4 = my_win->_cury;
v5 = my_win->_curx;
}
else
{
v4 = -1;
v5 = -1;
}
if ( a1 > 122 )
{
if ( a1 == 260 )
{
v18 = a3;
v19 = (v5 - 1) % (a3 + 2);
v7 = (unsigned int)generation;
if ( v19 )
v18 = v19;
v5 = v18;
goto LABEL_10;
}
if ( a1 <= 260 )
{
if ( a1 == 258 )
{
v20 = v4 + 1;
v4 = 1;
v7 = (unsigned int)generation;
if ( v20 % (v21 + 1) )
v4 = v20 % (v21 + 1);
goto LABEL_10;
}
if ( a1 == 259 )
{
v11 = a4;
v12 = (v4 - 1) % (a4 + 2);
v7 = (unsigned int)generation;
if ( v12 )
v11 = v12;
v4 = v11;
goto LABEL_10;
}
}
else if ( a1 == 261 )
{
v9 = v5 + 1;
v5 = 1;
v10 = v9 % (a3 + 1);
v7 = (unsigned int)generation;
if ( v10 )
v5 = v10;
goto LABEL_10;
}
LABEL_9:
v7 = (unsigned int)generation;
LABEL_10:
mvprintw(
0,
0,
"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures. Generation:%d ",
v7);
wrefresh(stdscr);
wmove(my_win, v4, v5);
wrefresh(my_win);
return 1LL;
}
if ( a1 <= 96 )
{
if ( a1 == 32 )
{
v6 = (_DWORD *)(a2[v4 - 1] + 4LL * v5 - 4);
*v6 = *v6 != 1;
LABEL_8:
show((__int64)a2, v22, v21);
}
goto LABEL_9;
}
switch ( a1 )
{
case 'a':
glider(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'e':
air_carrier(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'n':
run_step(a2, a3, a4);
v7 = (unsigned int)++generation;
goto LABEL_10;
case 'q':
result = 0LL;
break;
case 'r':
v13 = time(0LL);
srand(v13);
if ( v22 > 0 )
{
v14 = 0LL;
do
{
v15 = a2;
if ( v21 > 0 )
{
do
{
v16 = rand();
v17 = *v15++;
*(_DWORD *)(v17 + v14) = v16 <= 214748363;
}
while ( v15 != &a2[(unsigned int)(v21 - 1) + 1] );
}
v14 += 4LL;
}
while ( 4LL * v22 != v14 );
}
goto LABEL_8;
case 's':
lwss(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'w':
block(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'x':
blinker(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'z':
toad(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
default:
goto LABEL_9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 *a2, int a3, int a4)
{
int v4; // er14
int v5; // er15
_DWORD *v6; // rax
__int64 v7; // rcx
__int64 result; // rax
int v9; // eax
int v10; // edx
int v11; // ebx
int v12; // edx
unsigned int v13; // eax
__int64 v14; // rbx
__int64 *v15; // r12
int v16; // eax
__int64 v17; // rdx
int v18; // ebx
int v19; // edx
int v20; // eax
int v21; // [rsp+0h] [rbp-48h]
int v22; // [rsp+4h] [rbp-44h]

v22 = a3;
v21 = a4;
if ( my_win )
{
v4 = my_win->_cury;
v5 = my_win->_curx;
}
else
{
v4 = -1;
v5 = -1;
}
if ( a1 > 122 )
{
if ( a1 == 260 )
{
v18 = a3;
v19 = (v5 - 1) % (a3 + 2);
v7 = (unsigned int)generation;
if ( v19 )
v18 = v19;
v5 = v18;
goto LABEL_10;
}
if ( a1 <= 260 )
{
if ( a1 == 258 )
{
v20 = v4 + 1;
v4 = 1;
v7 = (unsigned int)generation;
if ( v20 % (v21 + 1) )
v4 = v20 % (v21 + 1);
goto LABEL_10;
}
if ( a1 == 259 )
{
v11 = a4;
v12 = (v4 - 1) % (a4 + 2);
v7 = (unsigned int)generation;
if ( v12 )
v11 = v12;
v4 = v11;
goto LABEL_10;
}
}
else if ( a1 == 261 )
{
v9 = v5 + 1;
v5 = 1;
v10 = v9 % (a3 + 1);
v7 = (unsigned int)generation;
if ( v10 )
v5 = v10;
goto LABEL_10;
}
LABEL_9:
v7 = (unsigned int)generation;
LABEL_10:
mvprintw(
0,
0,
"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures. Generation:%d ",
v7);
wrefresh(stdscr);
wmove(my_win, v4, v5);
wrefresh(my_win);
return 1LL;
}
if ( a1 <= 96 )
{
if ( a1 == 32 )
{
v6 = (_DWORD *)(a2[v4 - 1] + 4LL * v5 - 4);
*v6 = *v6 != 1;
LABEL_8:
func0((__int64)a2, v22, v21);
}
goto LABEL_9;
}
switch ( a1 )
{
case 'a':
glider(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'e':
air_carrier(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'n':
func2(a2, a3, a4);
v7 = (unsigned int)++generation;
goto LABEL_10;
case 'q':
result = 0LL;
break;
case 'r':
v13 = time(0LL);
srand(v13);
if ( v22 > 0 )
{
v14 = 0LL;
do
{
v15 = a2;
if ( v21 > 0 )
{
do
{
v16 = rand();
v17 = *v15++;
*(_DWORD *)(v17 + v14) = v16 <= 214748363;
}
while ( v15 != &a2[(unsigned int)(v21 - 1) + 1] );
}
v14 += 4LL;
}
while ( 4LL * v22 != v14 );
}
goto LABEL_8;
case 's':
lwss(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'w':
block(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'x':
blinker(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
case 'z':
toad(a2, (unsigned int)(v4 - 1), (unsigned int)(v5 - 1));
goto LABEL_8;
default:
goto LABEL_9;
}
return result;
}

original_code:
_Bool kbd(int ch, unsigned **world,int width, int height )
{
    int c_x,c_y;
    (c_y = ((0 != (const void *)((my_win))) ? (my_win)->_cury : (-1)), c_x = ((0 != (const void *)((my_win))) ? (my_win)->_curx : (-1)));
    switch(ch)
    {
        case 'q':
            return 0;
            break;
        case 'n':
  run_step(world,width,height);
  generation++;
            break;
        case 'r':
   srand(time(((void *)0)));
   for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) world[y][x] = rand() < 2147483647 / 10 ? 1 : 0;
   show(world,width,height);
   break;
        case ' ':
            if(world[c_y-1][c_x-1]==1)
   {
    world[c_y-1][c_x-1]=0;
   }
   else
   {
    world[c_y-1][c_x-1]=1;
   }
   show(world,width,height);
            break;
        case 0403:
   c_y=(c_y-1)%(height+2);
    if(c_y==0)
   {
    c_y=height;
   }
            break;
        case 0402:
            c_y=(c_y+1)%(height+1);
   if(c_y==0)
   {
    c_y++;
   }
            break;
   case 0404:
            c_x=(c_x-1)%(width+2);
   if(c_x==0)
   {
    c_x=width;
   }
            break;
  case 0405:
            c_x=(c_x+1)%(width+1);
   if(c_x==0)
   {
    c_x++;
   }
            break;
  case 'a':
   glider(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 's':
   lwss(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'z':
   toad(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'x':
   blinker(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'w':
   block(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'e':
   air_carrier(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
    }
 mvprintw(0,0,"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures.    Generation:%d       ",generation);
 wrefresh(stdscr);
 wmove(my_win,c_y, c_x);
 wrefresh(my_win);
    return 1;
}

canonical_original_code:
_Bool kbd(int ch, unsigned int **world, int width, int height)
{
    int c_x; int c_y;
    (c_y = ((0 != (void *)((my_win))) ? (my_win)->_cury : (-1)), c_x = ((0 != (void *)((my_win))) ? (my_win)->_curx : (-1)));
    switch(ch)
    {
        case 'q':
            return 0;
            break;
        case 'n':
  run_step(world,width,height);
  generation++;
            break;
        case 'r':
   srand(time(((void *)0)));
   for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) world[y][x] = rand() < 2147483647 / 10 ? 1 : 0;
   show(world,width,height);
   break;
        case ' ':
            if(world[c_y-1][c_x-1]==1)
   {
    world[c_y-1][c_x-1]=0;
   }
   else
   {
    world[c_y-1][c_x-1]=1;
   }
   show(world,width,height);
            break;
        case 0403:
   c_y=(c_y-1)%(height+2);
    if(c_y==0)
   {
    c_y=height;
   }
            break;
        case 0402:
            c_y=(c_y+1)%(height+1);
   if(c_y==0)
   {
    c_y++;
   }
            break;
   case 0404:
            c_x=(c_x-1)%(width+2);
   if(c_x==0)
   {
    c_x=width;
   }
            break;
  case 0405:
            c_x=(c_x+1)%(width+1);
   if(c_x==0)
   {
    c_x++;
   }
            break;
  case 'a':
   glider(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 's':
   lwss(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'z':
   toad(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'x':
   blinker(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'w':
   block(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
  case 'e':
   air_carrier(world,c_y-1,c_x-1);
   show(world,width,height);
            break;
    }
 mvprintw(0,0,"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures.    Generation:%d       ",generation);
 wrefresh(stdscr);
 wmove(my_win,c_y, c_x);
 wrefresh(my_win);
    return 1;
}

variable_types: ch int


main

canonical_name: main

repo: kobronson/isi-life

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er12
int v5; // ebp
__int64 *v6; // rbx
__int64 *v7; // r15
__int64 v8; // rcx
__int64 *v9; // rax
__int64 v10; // rdx
int v11; // eax
int v13; // [rsp+Ch] [rbp-4Ch]
__int64 v14; // [rsp+18h] [rbp-40h]

initscr();
cbreak();
if ( argc == 3 )
{
v13 = atoi(argv[1]);
v3 = atoi(argv[2]);
}
v4 = v3 - 2;
mvprintw(
0,
0,
"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures. Generation:%d ",
(unsigned int)generation);
wrefresh(stdscr);
v5 = v13 - 2;
my_win = create_newwin(v13, v3, 1, 0);
keypad(stdscr, 1);
v6 = (__int64 *)malloc(8LL * (v13 - 2));
if ( v3 - 2 > 0 )
{
v7 = v6;
v14 = (unsigned int)(v3 - 3);
do
*v7++ = (__int64)malloc(4LL * v4);
while ( v7 != &v6[v14 + 1] );
v8 = 0LL;
do
{
v9 = v6;
if ( v5 > 0 )
{
do
{
v10 = *v9++;
*(_DWORD *)(v10 + v8) = 0;
}
while ( &v6[(unsigned int)(v13 - 3) + 1] != v9 );
}
v8 += 4LL;
}
while ( v8 != 4 * v14 + 4 );
}
do
v11 = wgetch(stdscr);
while ( (unsigned __int8)kbd(v11, v6, v4, v5) );
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er12
int v5; // ebp
__int64 *v6; // rbx
__int64 *v7; // r15
__int64 v8; // rcx
__int64 *v9; // rax
__int64 v10; // rdx
int v11; // eax
int v13; // [rsp+Ch] [rbp-4Ch]
__int64 v14; // [rsp+18h] [rbp-40h]

initscr();
cbreak();
if ( argc == 3 )
{
v13 = atoi(argv[1]);
v3 = atoi(argv[2]);
}
v4 = v3 - 2;
mvprintw(
0,
0,
"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures. Generation:%d ",
(unsigned int)generation);
wrefresh(stdscr);
v5 = v13 - 2;
my_win = create_newwin(v13, v3, 1, 0);
keypad(stdscr, 1);
v6 = (__int64 *)malloc(8LL * (v13 - 2));
if ( v3 - 2 > 0 )
{
v7 = v6;
v14 = (unsigned int)(v3 - 3);
do
*v7++ = (__int64)malloc(4LL * v4);
while ( v7 != &v6[v14 + 1] );
v8 = 0LL;
do
{
v9 = v6;
if ( v5 > 0 )
{
do
{
v10 = *v9++;
*(_DWORD *)(v10 + v8) = 0;
}
while ( &v6[(unsigned int)(v13 - 3) + 1] != v9 );
}
v8 += 4LL;
}
while ( v8 != 4 * v14 + 4 );
}
do
v11 = wgetch(stdscr);
while ( (unsigned __int8)func4(v11, v6, v4, v5) );
endwin();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int startx, starty, width, height;
 int win_width, win_height;
 int ch,l;
 unsigned **world;
 struct winsize w;
 initscr();
 cbreak();
 if(argc==3)
 {
  win_height=atoi(argv[1]) ;
  win_width=atoi(argv[2]);
 }
 mvprintw(0,0,"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures.    Generation:%d       ",generation);
 wrefresh(stdscr);
 my_win = create_newwin(win_height, win_width, 1, 0);
 keypad(stdscr, 1);
 width = win_width-2;
 height = win_height-2;
 world = (unsigned**)malloc(height * sizeof(unsigned*));
 for(l = 0; l < width; l++)
  world[l] = (unsigned*)malloc(width * sizeof(unsigned));
 for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) world[y][x] = 0;
 do
    {
        ch = wgetch(stdscr);
    }
    while(kbd(ch,world,width,height));
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int startx; int starty; int width; int height;
 int win_width; int win_height;
 int ch; int l;
 unsigned int **world;
 struct winsize w;
 initscr();
 cbreak();
 if(argc==3)
 {
  win_height=atoi(argv[1]) ;
  win_width=atoi(argv[2]);
 }
 mvprintw(0,0,"[q] to exit, [r] random mode, [n] next step, [space] togle cell, [arrows] move, [w,e,a,s,z,x] structures.    Generation:%d       ",generation);
 wrefresh(stdscr);
 my_win = create_newwin(win_height, win_width, 1, 0);
 keypad(stdscr, 1);
 width = win_width-2;
 height = win_height-2;
 world = (unsigned int **)malloc(height * sizeof(unsigned int *));
 for(l = 0; l < width; l++)
  world[l] = (unsigned int *)malloc(width * sizeof(unsigned int));
 for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) world[y][x] = 0;
 do
    {
        ch = wgetch(stdscr);
    }
    while(kbd(ch,world,width,height));
 endwin();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: startx int

variable_types: starty int

variable_types: width int

variable_types: height int

variable_types: l int

variable_types:
world
unsigned int **

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

variable_types: x int

variable_types: y int

return_type: int


repo: konanholt/Projects

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

while ( 1 )
{
printf("How many problems do you want to solve? (Please choose 1-10)");
__isoc99_scanf();
if ( v6 <= 10 )
break;
printf("You chose %d. Please choose 10 problems or fewer.\n", (unsigned int)v6);
}
v3 = 1;
if ( v6 > 0 )
{
do
{
v4 = (unsigned int)v3++;
printf(" On to question #%d\n", v4);
buildProblem();
}
while ( v6 >= v3 );
}
return 0;
}

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

while ( 1 )
{
printf("How many problems do you want to solve? (Please choose 1-10)");
__isoc99_scanf();
if ( v6 <= 10 )
break;
printf("You chose %d. Please choose 10 problems or fewer.\n", (unsigned int)v6);
}
v3 = 1;
if ( v6 > 0 )
{
do
{
v4 = (unsigned int)v3++;
printf(" On to question #%d\n", v4);
func7();
}
while ( v6 >= v3 );
}
return 0;
}

original_code:
int main() {
  int number_of_problems;
   printf("How many problems do you want to solve? (Please choose 1-10)");
   scanf("%d", &number_of_problems);
   while ( number_of_problems > 10 ) {
                printf ("You chose %d. Please choose 10 problems or fewer.\n", number_of_problems);
    printf("How many problems do you want to solve? (Please choose 1-10)");
    scanf("%d", &number_of_problems);
   }
  int current_problem = 1;
  while ( current_problem <= number_of_problems ) {
   printf(" On to question #%d\n", current_problem);
   buildProblem();
   current_problem++;
  }
  return 0;
 }


buildProblem

decompiled_code:
int buildProblem()
{
unsigned int *v0; // rbx
unsigned int v1; // eax
int v2; // eax
char v3; // dl
int v4; // eax
__int64 v5; // rsi
__int64 v6; // rcx
__int64 v7; // rdx
double v8; // xmm0_8
int result; // eax

v0 = (unsigned int *)malloc(0x30uLL);
v1 = time(0LL);
srand(v1);
if ( !head )
head = (__int64)v0;
if ( tail )
*(_QWORD *)(tail + 40) = v0;
tail = (__int64)v0;
*((_QWORD *)v0 + 5) = 0LL;
*v0 = rand() % 10 + 1;
v0[1] = rand() % 10 + 1;
v2 = rand();
v3 = v2;
v4 = v2 % 4;
if ( v4 == 2 )
{
v5 = *v0;
v6 = v0[1];
*((_BYTE *)v0 + 8) = 47;
v7 = 47LL;
*((double *)v0 + 3) = (float)((float)(int)v5 / (float)(int)v6);
}
else if ( v4 == 3 )
{
v5 = *v0;
v6 = v0[1];
*((_BYTE *)v0 + 8) = 42;
v7 = 42LL;
*((double *)v0 + 3) = (double)((int)v6 * (int)v5);
}
else if ( (v3 & 3) != 0 )
{
if ( v4 == 1 )
{
v5 = *v0;
v6 = v0[1];
*((_BYTE *)v0 + 8) = 45;
v7 = 45LL;
*((double *)v0 + 3) = (double)((int)v5 - (int)v6);
}
else
{
printf("Hey, wha happen?!");
v6 = v0[1];
v7 = (unsigned int)*((char *)v0 + 8);
v5 = *v0;
}
}
else
{
v5 = *v0;
v6 = v0[1];
*((_BYTE *)v0 + 8) = 43;
v7 = 43LL;
*((double *)v0 + 3) = (double)((int)v5 + (int)v6);
}
printf("%d %c %d\n", v5, v7, v6);
__isoc99_scanf();
v8 = *((double *)v0 + 3);
if ( v8 == *((double *)v0 + 2) )
result = puts("Correct!");
else
result = printf("Incorrect. The correct answer was %f\n", v8);
return result;
}

original_code:
void buildProblem() {
 struct problem *new_problem = malloc(sizeof(struct problem));
 srand (time(((void *)0)));
 if(head == ((void *)0)) {
  head = new_problem;
 }
 if(tail != ((void *)0)) {
  tail->next = new_problem;
 }
 tail = new_problem;
 new_problem->next = ((void *)0);
 new_problem->num1 = rand() % 10 + 1;
 new_problem->num2 = rand() % 10 + 1;
 switch(rand() % 4) {
         case 0 :
   new_problem->correct_answer = new_problem->num1 + new_problem->num2;
   new_problem->operator = '+';
   break;
         case 1 :
   new_problem->correct_answer = new_problem->num1 - new_problem->num2;
   new_problem->operator = '-';
   break;
         case 2 :
   new_problem->correct_answer = (float) new_problem->num1 / (float) new_problem->num2;
   new_problem->operator = '/';
   break;
  case 3 :
   new_problem->correct_answer = new_problem->num1 * new_problem->num2;
   new_problem->operator = '*';
   break;
  default :
   printf("Hey, wha happen?!");
   break;
 }
 printf("%d %c %d\n", new_problem->num1, new_problem->operator, new_problem->num2);
  scanf("%lf", &new_problem->user_answer);
 if(new_problem->user_answer == new_problem->correct_answer) {
  printf("Correct!\n");
 } else {
  printf("Incorrect. The correct answer was %f\n", new_problem->correct_answer);
 }
}

variable_types: struct problem { int num1; int num2; char operator; double user_answer; double correct_answer; double difference; struct problem *next; } *

return_type: void


testDollerInit

decompiled_code:
__int64 testDollerInit()
{
__int64 result; // rax
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

public_doller_init(5LL);
if ( public_doller != 5 )
_assert_fail("5 == public_doller.amount", "test/test_doller.c", 0xAu, "testDollerInit");
result = local_doller_init(v1, 5LL);
if ( v1[0] != 5 )
_assert_fail("5 == local_doller.amount", "test/test_doller.c", 0xCu, "testDollerInit");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

public_doller_init(5LL);
if ( public_doller != 5 )
_assert_fail("5 == public_doller.amount", "test/test_doller.c", 0xAu, "testDollerInit");
result = local_doller_init(v1, 5LL);
if ( v1[0] != 5 )
_assert_fail("5 == local_doller.amount", "test/test_doller.c", 0xCu, "testDollerInit");
return result;
}

original_code:
void testDollerInit(){
    t_doller local_doller;
    public_doller_init( 5 );
    ((void) sizeof ((5 == public_doller.amount) ? 1 : 0), __extension__ ({ if (5 == public_doller.amount) ; else __assert_fail ("5 == public_doller.amount", "test/test_doller.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    local_doller_init( &local_doller, 5 );
    ((void) sizeof ((5 == local_doller.amount) ? 1 : 0), __extension__ ({ if (5 == local_doller.amount) ; else __assert_fail ("5 == local_doller.amount", "test/test_doller.c", 12, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void testDollerInit(){
    struct T_doller local_doller;
    public_doller_init( 5 );
    ((void) sizeof ((5 == public_doller.amount) ? 1 : 0), __extension__ ({ if (5 == public_doller.amount) ; else __assert_fail ("5 == public_doller.amount", "test/test_doller.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    local_doller_init( &local_doller, 5 );
    ((void) sizeof ((5 == local_doller.amount) ? 1 : 0), __extension__ ({ if (5 == local_doller.amount) ; else __assert_fail ("5 == local_doller.amount", "test/test_doller.c", 12, __extension__ __PRETTY_FUNCTION__); }));
}


testDollerMultiplication

decompiled_code:
__int64 testDollerMultiplication()
{
__int64 result; // rax
int v1[4]; // [rsp+8h] [rbp-10h] BYREF

public_doller_init(5LL);
local_doller_init(v1, 10LL);
result = dollerTimes(2LL);
v1[1] = result;
if ( (_DWORD)result != v1[0] )
_assert_fail(
"!memcmp( ( t_doller* ) &local_doller, ( t_doller* ) &cmp_doller, sizeof( t_doller ))",
"test/test_doller.c",
0x1Au,
"testDollerMultiplication");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1[4]; // [rsp+8h] [rbp-10h] BYREF

public_doller_init(5LL);
local_doller_init(v1, 10LL);
result = dollerTimes(2LL);
v1[1] = result;
if ( (_DWORD)result != v1[0] )
_assert_fail(
"!memcmp( ( t_doller* ) &local_doller, ( t_doller* ) &cmp_doller, sizeof( t_doller ))",
"test/test_doller.c",
0x1Au,
"testDollerMultiplication");
return result;
}

original_code:
void testDollerMultiplication(){
    int counter = 0;
    t_doller local_doller;
    t_doller cmp_doller;
    public_doller_init( 5 );
    for( counter = 0; counter < 1; counter ++){
        local_doller_init( &local_doller, 10 );
        cmp_doller = dollerTimes( 2 );
        ((void) sizeof ((!memcmp( ( t_doller* ) &local_doller, ( t_doller* ) &cmp_doller, sizeof( t_doller ))) ? 1 : 0), __extension__ ({ if (!memcmp( ( t_doller* ) &local_doller, ( t_doller* ) &cmp_doller, sizeof( t_doller ))) ; else __assert_fail ("!memcmp( ( t_doller* ) &local_doller, ( t_doller* ) &cmp_doller, sizeof( t_doller ))", "test/test_doller.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    }
}

canonical_original_code:
void testDollerMultiplication(){
    int counter = 0;
    struct T_doller local_doller;
    struct T_doller cmp_doller;
    public_doller_init( 5 );
    for( counter = 0; counter < 1; counter ++){
        local_doller_init( &local_doller, 10 );
        cmp_doller = dollerTimes( 2 );
        ((void) sizeof ((!memcmp( ( struct T_doller * ) &local_doller, ( struct T_doller * ) &cmp_doller, sizeof( t_doller ))) ? 1 : 0), __extension__ ({ if (!memcmp( ( struct T_doller * ) &local_doller, ( struct T_doller * ) &cmp_doller, sizeof( t_doller ))) ; else __assert_fail ("!memcmp( ( t_doller* ) &local_doller, ( t_doller* ) &cmp_doller, sizeof( t_doller ))", "test/test_doller.c", 26, __extension__ __PRETTY_FUNCTION__); }));
    }
}

variable_types: counter int


testDollerEquals

decompiled_code:
__int64 testDollerEquals()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_doller_init(5LL);
local_doller_init(v1, 5LL);
result = dollerEquals((unsigned int)public_doller, v1);
if ( !(_DWORD)result )
_assert_fail("dollerEquals( public_doller, &dst_doller )", "test/test_doller.c", 0x23u, "testDollerEquals");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_doller_init(5LL);
local_doller_init(v1, 5LL);
result = dollerEquals((unsigned int)public_doller, v1);
if ( !(_DWORD)result )
_assert_fail("dollerEquals( public_doller, &dst_doller )", "test/test_doller.c", 0x23u, "testDollerEquals");
return result;
}

original_code:
void testDollerEquals( ){
    t_doller dst_doller;
    public_doller_init( 5 );
    local_doller_init( &dst_doller, 5 );
    ((void) sizeof ((dollerEquals( public_doller, &dst_doller )) ? 1 : 0), __extension__ ({ if (dollerEquals( public_doller, &dst_doller )) ; else __assert_fail ("dollerEquals( public_doller, &dst_doller )", "test/test_doller.c", 35, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void testDollerEquals(){
    struct T_doller dst_doller;
    public_doller_init( 5 );
    local_doller_init( &dst_doller, 5 );
    ((void) sizeof ((dollerEquals( public_doller, &dst_doller )) ? 1 : 0), __extension__ ({ if (dollerEquals( public_doller, &dst_doller )) ; else __assert_fail ("dollerEquals( public_doller, &dst_doller )", "test/test_doller.c", 35, __extension__ __PRETTY_FUNCTION__); }));
}


testDollerFrancCompare

decompiled_code:
__int64 testDollerFrancCompare()
{
__int64 result; // rax
unsigned int v1; // [rsp+8h] [rbp-10h] BYREF
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

local_doller_init(&v1, 5LL);
local_franc_init(v2, 5LL);
if ( !(unsigned int)dollerEquals(v1, v2) )
_assert_fail("dollerEquals( src_doller, &dst_franc )", "test/test_doller.c", 0x2Bu, "testDollerFrancCompare");
result = francEquals((unsigned int)v2[0], &v1);
if ( !(_DWORD)result )
_assert_fail("francEquals( dst_franc, &src_doller )", "test/test_doller.c", 0x2Cu, "testDollerFrancCompare");
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
unsigned int v1; // [rsp+8h] [rbp-10h] BYREF
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

local_doller_init(&v1, 5LL);
local_franc_init(v2, 5LL);
if ( !(unsigned int)dollerEquals(v1, v2) )
_assert_fail("dollerEquals( src_doller, &dst_franc )", "test/test_doller.c", 0x2Bu, "testDollerFrancCompare");
result = francEquals((unsigned int)v2[0], &v1);
if ( !(_DWORD)result )
_assert_fail("francEquals( dst_franc, &src_doller )", "test/test_doller.c", 0x2Cu, "testDollerFrancCompare");
return result;
}

original_code:
void testDollerFrancCompare(){
    t_doller src_doller;
    t_franc dst_franc;
    local_doller_init( &src_doller, 5 );
    local_franc_init( &dst_franc, 5 );
    ((void) sizeof ((dollerEquals( src_doller, &dst_franc )) ? 1 : 0), __extension__ ({ if (dollerEquals( src_doller, &dst_franc )) ; else __assert_fail ("dollerEquals( src_doller, &dst_franc )", "test/test_doller.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((francEquals( dst_franc, &src_doller )) ? 1 : 0), __extension__ ({ if (francEquals( dst_franc, &src_doller )) ; else __assert_fail ("francEquals( dst_franc, &src_doller )", "test/test_doller.c", 44, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void testDollerFrancCompare(){
    struct T_doller src_doller;
    struct T_franc dst_franc;
    local_doller_init( &src_doller, 5 );
    local_franc_init( &dst_franc, 5 );
    ((void) sizeof ((dollerEquals( src_doller, &dst_franc )) ? 1 : 0), __extension__ ({ if (dollerEquals( src_doller, &dst_franc )) ; else __assert_fail ("dollerEquals( src_doller, &dst_franc )", "test/test_doller.c", 43, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((francEquals( dst_franc, &src_doller )) ? 1 : 0), __extension__ ({ if (francEquals( dst_franc, &src_doller )) ; else __assert_fail ("francEquals( dst_franc, &src_doller )", "test/test_doller.c", 44, __extension__ __PRETTY_FUNCTION__); }));
}

user_defined_types:
struct T_doller { int amount; }
struct T_franc { int amount; }


testAll

decompiled_code:
__int64 testAll()
{
testDollerInit();
testDollerMultiplication();
testDollerEquals();
testFrancInit();
testFrancMultiplication();
testFrancEquals();
return testDollerFrancCompare();
}

canonical_decompiled_code:
__int64 func4()
{
func0();
func1();
func2();
testFrancInit();
testFrancMultiplication();
testFrancEquals();
return func3();
}

original_code:
void testAll(){
    testDollerInit();
    testDollerMultiplication();
    testDollerEquals();
    testFrancInit();
    testFrancMultiplication();
    testFrancEquals();
    testDollerFrancCompare();
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return testAll(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func4(argc, argv, envp);
}

original_code:
void main(){
    testAll();
}

canonical_original_code:
void main(){
    testAll();
}


testFrancInit

decompiled_code:
__int64 testFrancInit()
{
__int64 result; // rax
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
if ( public_franc != 5 )
_assert_fail("5 == public_franc.amount", "test/test_franc.c", 9u, "testFrancInit");
result = local_franc_init(v1, 5LL);
if ( v1[0] != 5 )
_assert_fail("5 == local_franc.amount", "test/test_franc.c", 0xBu, "testFrancInit");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
if ( public_franc != 5 )
_assert_fail("5 == public_franc.amount", "test/test_franc.c", 9u, "testFrancInit");
result = local_franc_init(v1, 5LL);
if ( v1[0] != 5 )
_assert_fail("5 == local_franc.amount", "test/test_franc.c", 0xBu, "testFrancInit");
return result;
}

original_code:
void testFrancInit(){
    t_franc local_franc;
    public_franc_init( 5 );
    ((void) sizeof ((5 == public_franc.amount) ? 1 : 0), __extension__ ({ if (5 == public_franc.amount) ; else __assert_fail ("5 == public_franc.amount", "test/test_franc.c", 9, __extension__ __PRETTY_FUNCTION__); }));
    local_franc_init( &local_franc, 5 );
    ((void) sizeof ((5 == local_franc.amount) ? 1 : 0), __extension__ ({ if (5 == local_franc.amount) ; else __assert_fail ("5 == local_franc.amount", "test/test_franc.c", 11, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void testFrancInit(){
    struct T_franc local_franc;
    public_franc_init( 5 );
    ((void) sizeof ((5 == public_franc.amount) ? 1 : 0), __extension__ ({ if (5 == public_franc.amount) ; else __assert_fail ("5 == public_franc.amount", "test/test_franc.c", 9, __extension__ __PRETTY_FUNCTION__); }));
    local_franc_init( &local_franc, 5 );
    ((void) sizeof ((5 == local_franc.amount) ? 1 : 0), __extension__ ({ if (5 == local_franc.amount) ; else __assert_fail ("5 == local_franc.amount", "test/test_franc.c", 11, __extension__ __PRETTY_FUNCTION__); }));
}


testFrancMultiplication

decompiled_code:
__int64 testFrancMultiplication()
{
__int64 result; // rax
int v1[4]; // [rsp+8h] [rbp-10h] BYREF

public_franc_init(5LL);
local_franc_init(v1, 10LL);
result = francTimes(2LL);
v1[1] = result;
if ( (_DWORD)result != v1[0] )
_assert_fail(
"!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))",
"test/test_franc.c",
0x19u,
"testFrancMultiplication");
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1[4]; // [rsp+8h] [rbp-10h] BYREF

public_franc_init(5LL);
local_franc_init(v1, 10LL);
result = francTimes(2LL);
v1[1] = result;
if ( (_DWORD)result != v1[0] )
_assert_fail(
"!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))",
"test/test_franc.c",
0x19u,
"testFrancMultiplication");
return result;
}

original_code:
void testFrancMultiplication(){
    int counter = 0;
    t_franc local_franc;
    t_franc cmp_franc;
    public_franc_init( 5 );
    for( counter = 0; counter < 1; counter ++){
        local_franc_init( &local_franc, 10 );
        cmp_franc = francTimes( 2 );
        ((void) sizeof ((!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))) ? 1 : 0), __extension__ ({ if (!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))) ; else __assert_fail ("!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))", "test/test_franc.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    }
}

canonical_original_code:
void testFrancMultiplication(){
    int counter = 0;
    struct T_franc local_franc;
    struct T_franc cmp_franc;
    public_franc_init( 5 );
    for( counter = 0; counter < 1; counter ++){
        local_franc_init( &local_franc, 10 );
        cmp_franc = francTimes( 2 );
        ((void) sizeof ((!memcmp( ( struct T_franc * ) &local_franc, ( struct T_franc * ) &cmp_franc, sizeof( t_franc ))) ? 1 : 0), __extension__ ({ if (!memcmp( ( struct T_franc * ) &local_franc, ( struct T_franc * ) &cmp_franc, sizeof( t_franc ))) ; else __assert_fail ("!memcmp( ( t_franc* ) &local_franc, ( t_franc* ) &cmp_franc, sizeof( t_franc ))", "test/test_franc.c", 25, __extension__ __PRETTY_FUNCTION__); }));
    }
}


testFrancEquals

decompiled_code:
__int64 testFrancEquals()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
local_franc_init(v1, 5LL);
result = francEquals((unsigned int)public_franc, v1);
if ( !(_DWORD)result )
_assert_fail("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 0x22u, "testFrancEquals");
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

public_franc_init(5LL);
local_franc_init(v1, 5LL);
result = francEquals((unsigned int)public_franc, v1);
if ( !(_DWORD)result )
_assert_fail("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 0x22u, "testFrancEquals");
return result;
}

original_code:
void testFrancEquals(){
    t_franc dst_franc;
    public_franc_init( 5 );
    local_franc_init( &dst_franc, 5 );
    ((void) sizeof ((francEquals( public_franc, &dst_franc )) ? 1 : 0), __extension__ ({ if (francEquals( public_franc, &dst_franc )) ; else __assert_fail ("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 34, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void testFrancEquals(){
    struct T_franc dst_franc;
    public_franc_init( 5 );
    local_franc_init( &dst_franc, 5 );
    ((void) sizeof ((francEquals( public_franc, &dst_franc )) ? 1 : 0), __extension__ ({ if (francEquals( public_franc, &dst_franc )) ; else __assert_fail ("francEquals( public_franc, &dst_franc )", "test/test_franc.c", 34, __extension__ __PRETTY_FUNCTION__); }));
}


setstandardspeed

repo: konkers/sconsole

decompiled_code:
int __fastcall setstandardspeed(int a1, const struct termios *a2, speed_t a3)
{
a2->c_ispeed = a3;
a2->c_ospeed = a3;
a2->c_cflag = a3 | 0x8B0;
return tcsetattr(a1, 0, a2);
}

canonical_decompiled_code:
int __fastcall func0(int a1, const struct termios *a2, speed_t a3)
{
a2->c_ispeed = a3;
a2->c_ospeed = a3;
a2->c_cflag = a3 | 0x8B0;
return tcsetattr(a1, 0, a2);
}

original_code:
static void setstandardspeed(int fd, struct termios *tio, int speed)
{
 tio->c_cflag = speed | 0000060 | 0004000 | 0000200;
 tio->c_ispeed = speed;
 tio->c_ospeed = speed;
 tcsetattr(fd, 0, tio);
}

variable_types: fd int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *

variable_types: speed int


decompiled_code:
int stdin_raw_restore()
{
tcsetattr(0, 0, &tio_save);
return tcflush(0, 0);
}

canonical_decompiled_code:
int func1()
{
tcsetattr(0, 0, &tio_save);
return tcflush(0, 0);
}

original_code:
static void stdin_raw_restore(void)
{
 tcsetattr(0, 0, &tio_save);
 tcflush(0, 0);
}

canonical_original_code:
static void stdin_raw_restore()
{
 tcsetattr(0, 0, &tio_save);
 tcflush(0, 0);
}


oops

decompiled_code:
void __noreturn oops()
{
write(2, "\n[ killed by signal ]\n", 0x16uLL);
stdin_raw_restore();
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
write(2, "\n[ killed by signal ]\n", 0x16uLL);
func1();
exit(1);
}

original_code:
void oops(int x)
{
 char *msg = "\n[ killed by signal ]\n";
 write(2, msg, strlen(msg));
 stdin_raw_restore();
 exit(1);
}

variable_types:
msg
char *


decompiled_code:
int stdin_raw_init()
{
int result; // eax
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

result = tcgetattr(0, &v1);
if ( !result )
{
result = tcgetattr(0, &tio_save);
if ( !result )
{
v1.c_lflag = 0;
*(_WORD *)&v1.c_cc[5] = 256;
tcsetattr(0, 0, &v1);
result = tcflush(0, 0);
}
}
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

result = tcgetattr(0, &v1);
if ( !result )
{
result = tcgetattr(0, &tio_save);
if ( !result )
{
v1.c_lflag = 0;
*(_WORD *)&v1.c_cc[5] = 256;
tcsetattr(0, 0, &v1);
result = tcflush(0, 0);
}
}
return result;
}

original_code:
static void stdin_raw_init(void)
{
 struct termios tio;
 if (tcgetattr(0, &tio))
  return;
 if (tcgetattr(0, &tio_save))
  return;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(0, 0, &tio);
 tcflush(0, 0);
}

canonical_original_code:
static void stdin_raw_init()
{
 struct termios tio;
 if (tcgetattr(0, &tio))
  return;
 if (tcgetattr(0, &tio_save))
  return;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(0, 0, &tio);
 tcflush(0, 0);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


setcustomspeed

decompiled_code:
int __fastcall setcustomspeed(int fd, int a2)
{
_DWORD v3[18]; // [rsp+0h] [rbp-48h] BYREF

ioctl(fd, 0x802C542AuLL, v3);
v3[10] = a2;
v3[9] = a2;
v3[2] = 6320;
return ioctl(fd, 0x402C542BuLL, v3);
}

canonical_decompiled_code:
int __fastcall func4(int fd, int a2)
{
_DWORD v3[18]; // [rsp+0h] [rbp-48h] BYREF

ioctl(fd, 0x802C542AuLL, v3);
v3[10] = a2;
v3[9] = a2;
v3[2] = 6320;
return ioctl(fd, 0x402C542BuLL, v3);
}

variable_types:
speed
unsigned int

variable_types: struct termios2 { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[19]; unsigned int c_ispeed; unsigned int c_ospeed; }


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

if ( a1 == 38400 )
return 15LL;
if ( a1 <= 0x9600 )
{
result = 13LL;
if ( a1 != 9600 )
{
result = 4096LL;
if ( a1 == 19200 )
result = 14LL;
}
}
else
{
result = 4097LL;
if ( a1 != 57600 )
result = 2 * (unsigned int)(a1 == 115200) + 4096;
}
return result;
}

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

if ( a1 == 38400 )
return 15LL;
if ( a1 <= 0x9600 )
{
result = 13LL;
if ( a1 != 9600 )
{
result = 4096LL;
if ( a1 == 19200 )
result = 14LL;
}
}
else
{
result = 4097LL;
if ( a1 != 57600 )
result = 2 * (unsigned int)(a1 == 115200) + 4096;
}
return result;
}

original_code:
int speed2termios(speed_t speed)
{
 switch (speed) {
 case 115200:
  return 0010002;
 case 57600:
  return 0010001;
 case 38400:
  return 0000017;
 case 19200:
  return 0000016;
 case 9600:
  return 0000015;
 default:
  return 0010000;
 }
}

canonical_original_code:
int speed2termios(unsigned int speed)
{
 switch (speed) {
 case 115200:
  return 0010002;
 case 57600:
  return 0010001;
 case 38400:
  return 0000017;
 case 19200:
  return 0000016;
 case 9600:
  return 0000015;
 default:
  return 0010000;
 }
}


openserial

decompiled_code:
__int64 __fastcall openserial(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // eax
tcflag_t v5; // eax
speed_t v6; // edx
int v8; // edi
struct termios v9; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
v4 = fcntl(v2, 3, 0LL);
if ( v4 < 0 || (BYTE1(v4) &= 0xF7u, fcntl(v3, 4, (unsigned int)v4) < 0) )
{
v8 = v3;
v3 = -1;
close(v8);
}
else
{
if ( tcgetattr(v3, &v9) )
{
*(_DWORD *)&v9.c_cc[31] = 0;
v5 = 0;
*(_OWORD *)&v9.c_line = 0LL;
*(_OWORD *)&v9.c_cc[15] = 0LL;
}
else
{
v5 = v9.c_oflag & 0xFFFFFFFB;
}
v9.c_oflag = v5;
v9.c_iflag = 4;
*(_QWORD *)&v9.c_ispeed = 0x100100001001LL;
*(_QWORD *)&v9.c_cflag = 6321LL;
*(_WORD *)&v9.c_cc[5] = 256;
tcsetattr(v3, 0, &v9);
tcflush(v3, 0);
v6 = speed2termios(a2);
if ( v6 == 4096 )
setcustomspeed(v3, a2);
else
setstandardspeed(v3, &v9, v6);
tcflush(v3, 0);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, unsigned int a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // eax
tcflag_t v5; // eax
speed_t v6; // edx
int v8; // edi
struct termios v9; // [rsp+0h] [rbp-58h] BYREF

v2 = open(a1, 2306);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
v4 = fcntl(v2, 3, 0LL);
if ( v4 < 0 || (BYTE1(v4) &= 0xF7u, fcntl(v3, 4, (unsigned int)v4) < 0) )
{
v8 = v3;
v3 = -1;
close(v8);
}
else
{
if ( tcgetattr(v3, &v9) )
{
*(_DWORD *)&v9.c_cc[31] = 0;
v5 = 0;
*(_OWORD *)&v9.c_line = 0LL;
*(_OWORD *)&v9.c_cc[15] = 0LL;
}
else
{
v5 = v9.c_oflag & 0xFFFFFFFB;
}
v9.c_oflag = v5;
v9.c_iflag = 4;
*(_QWORD *)&v9.c_ispeed = 0x100100001001LL;
*(_QWORD *)&v9.c_cflag = 6321LL;
*(_WORD *)&v9.c_cc[5] = 256;
tcsetattr(v3, 0, &v9);
tcflush(v3, 0);
v6 = func5(a2);
if ( v6 == 4096 )
func4(v3, a2);
else
func0(v3, &v9, v6);
tcflush(v3, 0);
}
return v3;
}

original_code:
int openserial(const char *device, speed_t speed)
{
 struct termios tio;
 int fd;
 int fl;
 fd = open(device, 02 | 0400 | 04000);
 if (fd < 0)
  return -1;
 fl = fcntl(fd, 3, 0);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 fl = fcntl(fd, 4, fl & ~04000);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 if (tcgetattr(fd, &tio))
  memset(&tio, 0, sizeof(tio));
 tio.c_cflag = 0010001 | 0000060 | 0004000 | 0000200;
 tio.c_ispeed = 0010001;
 tio.c_ospeed = 0010001;
 tio.c_iflag = 0000004;
 tio.c_oflag &= ~0000004;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(fd, 0, &tio);
 tcflush(fd, 0);
 int termios_speed = speed2termios(speed);
 if (termios_speed == 0010000)
  setcustomspeed(fd, speed);
 else
  setstandardspeed(fd, &tio, termios_speed);
 tcflush(fd, 0);
 return fd;
}

canonical_original_code:
int openserial(char *device, unsigned int speed)
{
 struct termios tio;
 int fd;
 int fl;
 fd = open(device, 02 | 0400 | 04000);
 if (fd < 0)
  return -1;
 fl = fcntl(fd, 3, 0);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 fl = fcntl(fd, 4, fl & ~04000);
 if (fl < 0) {
  close(fd);
  return -1;
 }
 if (tcgetattr(fd, &tio))
  memset(&tio, 0, sizeof(tio));
 tio.c_cflag = 0010001 | 0000060 | 0004000 | 0000200;
 tio.c_ispeed = 0010001;
 tio.c_ospeed = 0010001;
 tio.c_iflag = 0000004;
 tio.c_oflag &= ~0000004;
 tio.c_lflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 1;
 tcsetattr(fd, 0, &tio);
 tcflush(fd, 0);
 int termios_speed = speed2termios(speed);
 if (termios_speed == 0010000)
  setcustomspeed(fd, speed);
 else
  setstandardspeed(fd, &tio, termios_speed);
 tcflush(fd, 0);
 return fd;
}

variable_types:
device
char *

variable_types: fl int

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


main

original_code:
int main(int argc, char *argv[])
{
 struct pollfd fds[2];
 speed_t speed = 115200;
 const char *device = "/dev/ttyUSB0";
 const char *logfile = "console.log";
 const char *speed_arg = ((void *)0);
 int fd, n;
 int escape = 0;
 int logfd = -1;
 unsigned char ESC = 27;
 for (n = ' '; n < 127; n++)
  valid[n] = 1;
 valid[7] = -1;
 valid[8] = 1;
 valid[9] = 1;
 valid[10] = 1;
 valid[13] = 1;
 while ((argc > 1) && (argv[1][0] == '-')) {
  switch (argv[1][1]) {
  case 't':
   for (n = 0; n < 256; n++)
    valid[n] = 1;
   break;
  case 'l':
   if (argv[1][2])
    logfile = &argv[1][2];
   logfd = open(logfile, 0100 | 01, 0644);
   break;
  default:
   fprintf(stderr, "unknown option %s\n", argv[1]);
   return 1;
  }
  argv++;
  argc--;
 }
 if (argc > 1) {
  const char* arg = argv[1];
  if (((*__ctype_b_loc ())[(int) ((arg[0]))] & (unsigned short int) _ISdigit)) {
   speed_arg = arg;
  } else {
   device = arg;
  }
  argc--;
  argv++;
 }
 if (argc > 1) {
  if (!speed_arg)
   speed_arg = argv[1];
  argc--;
  argv++;
 }
 if (speed_arg) {
  unsigned long speed_long;
  char *endptr;
  speed_long = strtoul(speed_arg, &endptr, 0);
  speed = (speed_t)speed_long;
  if (speed_long == (0x7fffffffffffffffL * 2UL + 1UL) || speed_long != speed || *endptr != '\0') {
   fprintf(stderr, "invalid speed '%s'\n", speed_arg);
   return -1;
  }
  fprintf(stderr, "SPEED: %s\n", speed_arg);
 }
 fd = openserial(device, speed);
 if (fd < 0) {
  fprintf(stderr, "stderr open '%s'\n", device);
  return -1;
 }
 stdin_raw_init();
 signal(2, oops);
 fds[0].fd = 0;
 fds[0].events = 0x001;
 fds[1].fd = fd;
 fds[1].events = 0x001;
 fprintf(stderr, "[ %s ]\n", device);
 for (;;) {
  unsigned char x, t;
  if (poll(fds, 2, -1) > 0) {
   if (fds[0].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ stdin port closed ]\n");
    break;
   }
   if (fds[1].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ serial port closed ]\n");
    break;
   }
   if ((fds[0].revents & 0x001) && (read(0, &x, 1) == 1)) {
    switch (escape) {
    case 0:
     if (x == 27) {
      escape = 1;
     } else {
      write(fd, &x, 1);
     }
     break;
    case 1:
     if (x == 27) {
      escape = 2;
      fprintf(stderr, "\n[ (b)reak? e(x)it? ]\n");
     } else {
      escape = 0;
      write(fd, &ESC, 1);
      write(fd, &x, 1);
     }
     break;
    case 2:
     escape = 0;
     switch (x) {
     case 27:
      write(fd, &x, 1);
      break;
     case 'b':
      fprintf(stderr, "[ break ]\n");
      tcsendbreak(fd, 0);
      break;
     case 'x':
      fprintf(stderr, "[ exit ]\n");
      goto done;
     default:
      fprintf(stderr, "[ huh? ]\n");
      break;
     }
     break;
    }
   }
   if ((fds[1].revents & 0x001) && (read(fd, &x, 1) == 1)) {
    unsigned char c = x;
    if (!valid[x])
     c = '.';
    if (valid[x] != -1) {
     write(1, &c, 1);
     if (logfd != -1)
      write(logfd, &c, 1);
    }
   }
  }
 }
done:
 stdin_raw_restore();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct pollfd fds[2];
 unsigned int speed = 115200;
 char *device = "/dev/ttyUSB0";
 char *logfile = "console.log";
 char *speed_arg = ((void *)0);
 int fd; int n;
 int escape = 0;
 int logfd = -1;
 unsigned char ESC = 27;
 for (n = ' '; n < 127; n++)
  valid[n] = 1;
 valid[7] = -1;
 valid[8] = 1;
 valid[9] = 1;
 valid[10] = 1;
 valid[13] = 1;
 while ((argc > 1) && (argv[1][0] == '-')) {
  switch (argv[1][1]) {
  case 't':
   for (n = 0; n < 256; n++)
    valid[n] = 1;
   break;
  case 'l':
   if (argv[1][2])
    logfile = &argv[1][2];
   logfd = open(logfile, 0100 | 01, 0644);
   break;
  default:
   fprintf(stderr, "unknown option %s\n", argv[1]);
   return 1;
  }
  argv++;
  argc--;
 }
 if (argc > 1) {
  char *arg = argv[1];
  if (((*__ctype_b_loc ())[(int) ((arg[0]))] & (unsigned short) _ISdigit)) {
   speed_arg = arg;
  } else {
   device = arg;
  }
  argc--;
  argv++;
 }
 if (argc > 1) {
  if (!speed_arg)
   speed_arg = argv[1];
  argc--;
  argv++;
 }
 if (speed_arg) {
  unsigned long speed_long;
  char *endptr;
  speed_long = strtoul(speed_arg, &endptr, 0);
  speed = (unsigned int)speed_long;
  if (speed_long == (0x7fffffffffffffffL * 2UL + 1UL) || speed_long != speed || *endptr != '\0') {
   fprintf(stderr, "invalid speed '%s'\n", speed_arg);
   return -1;
  }
  fprintf(stderr, "SPEED: %s\n", speed_arg);
 }
 fd = openserial(device, speed);
 if (fd < 0) {
  fprintf(stderr, "stderr open '%s'\n", device);
  return -1;
 }
 stdin_raw_init();
 signal(2, oops);
 fds[0].fd = 0;
 fds[0].events = 0x001;
 fds[1].fd = fd;
 fds[1].events = 0x001;
 fprintf(stderr, "[ %s ]\n", device);
 for (;;) {
  unsigned char x; unsigned char t;
  if (poll(fds, 2, -1) > 0) {
   if (fds[0].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ stdin port closed ]\n");
    break;
   }
   if (fds[1].revents & (0x008 | 0x010)) {
    fprintf(stderr, "\n[ serial port closed ]\n");
    break;
   }
   if ((fds[0].revents & 0x001) && (read(0, &x, 1) == 1)) {
    switch (escape) {
    case 0:
     if (x == 27) {
      escape = 1;
     } else {
      write(fd, &x, 1);
     }
     break;
    case 1:
     if (x == 27) {
      escape = 2;
      fprintf(stderr, "\n[ (b)reak? e(x)it? ]\n");
     } else {
      escape = 0;
      write(fd, &ESC, 1);
      write(fd, &x, 1);
     }
     break;
    case 2:
     escape = 0;
     switch (x) {
     case 27:
      write(fd, &x, 1);
      break;
     case 'b':
      fprintf(stderr, "[ break ]\n");
      tcsendbreak(fd, 0);
      break;
     case 'x':
      fprintf(stderr, "[ exit ]\n");
      goto done;
     default:
      fprintf(stderr, "[ huh? ]\n");
      break;
     }
     break;
    }
   }
   if ((fds[1].revents & 0x001) && (read(fd, &x, 1) == 1)) {
    unsigned char c = x;
    if (!valid[x])
     c = '.';
    if (valid[x] != -1) {
     write(1, &c, 1);
     if (logfd != -1)
      write(logfd, &c, 1);
    }
   }
  }
 }
done:
 stdin_raw_restore();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct pollfd { int fd; short events; short revents; } [2]

variable_types:
logfile
char *

variable_types: n int

variable_types: escape int

variable_types: logfd int

variable_types:
ESC
unsigned char

variable_types:
arg
char *

variable_types:
endptr
char *

variable_types:
x
unsigned char

variable_types:
t
unsigned char

variable_types:
c
unsigned char


repo: koraa/chentropy

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // edx
int v5; // ebx
const char *v6; // r14
const char *v7; // r12
int v8; // er13
const char *v9; // rcx
char v10; // al
const char *v11; // rdi
unsigned int v12; // er15
_BYTE *v13; // r13
_BYTE *v14; // rbp
size_t v16; // rbp
int v17; // [rsp+4h] [rbp-54h]
_BYTE *ptr; // [rsp+8h] [rbp-50h]
int v19; // [rsp+18h] [rbp-40h] BYREF
int v20[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( argc > 0 )
{
v17 = 40;
v4 = 0;
v5 = 40;
v6 = "\n";
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
while ( 1 )
{
v8 = v4 + 1;
v9 = argv[v4];
v10 = v9[1];
if ( *v9 == 45 )
{
if ( argc <= v8 )
goto LABEL_6;
v11 = argv[v4 + 1];
if ( v10 == 120 )
{
v17 = atoi(v11);
v5 = v17;
}
else if ( v10 > 120 )
{
if ( v10 != 122 )
goto LABEL_30;
v17 = atoi(v11);
}
else if ( v10 == 97 )
{
v5 = atoi(v11);
}
else
{
if ( v10 != 115 )
goto LABEL_30;
v6 = argv[v4 + 1];
}
}
else
{
if ( !v10 )
{
if ( argc <= v8 )
LABEL_6:
exit(1);
LABEL_30:
exit(2);
}
v8 = v4;
v7 = argv[v4];
}
v4 = v8 + 1;
if ( argc <= v8 + 1 )
goto LABEL_13;
}
}
v17 = 40;
v5 = 40;
v6 = "\n";
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
LABEL_13:
v12 = strlen(v7);
v20[0] = v17;
ptr = malloc(v17);
v13 = &ptr[v17];
if ( v17 > v5 )
goto LABEL_27;
while ( 1 )
{
v14 = ptr;
if ( ptr < v13 )
break;
LABEL_25:
v16 = fwrite(ptr, 1uLL, v20[0], _bss_start);
printf(v6);
if ( v20[0] != v16 )
return 0;
if ( v17 > v5 )
{
LABEL_27:
if ( !(unsigned __int8)rrandi(v20, (unsigned int)v5, (unsigned int)v17, stdin) )
return 0;
v13 = &ptr[v20[0]];
}
}
while ( (unsigned __int8)rrandi(&v19, 0LL, v12, stdin) )
{
*v14++ = v7[v19];
if ( v14 == v13 )
goto LABEL_25;
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // edx
int v5; // ebx
const char *v6; // r14
const char *v7; // r12
int v8; // er13
const char *v9; // rcx
char v10; // al
const char *v11; // rdi
unsigned int v12; // er15
_BYTE *v13; // r13
_BYTE *v14; // rbp
size_t v16; // rbp
int v17; // [rsp+4h] [rbp-54h]
_BYTE *ptr; // [rsp+8h] [rbp-50h]
int v19; // [rsp+18h] [rbp-40h] BYREF
int v20[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( argc > 0 )
{
v17 = 40;
v4 = 0;
v5 = 40;
v6 = "\n";
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
while ( 1 )
{
v8 = v4 + 1;
v9 = argv[v4];
v10 = v9[1];
if ( *v9 == 45 )
{
if ( argc <= v8 )
goto LABEL_6;
v11 = argv[v4 + 1];
if ( v10 == 120 )
{
v17 = atoi(v11);
v5 = v17;
}
else if ( v10 > 120 )
{
if ( v10 != 122 )
goto LABEL_30;
v17 = atoi(v11);
}
else if ( v10 == 97 )
{
v5 = atoi(v11);
}
else
{
if ( v10 != 115 )
goto LABEL_30;
v6 = argv[v4 + 1];
}
}
else
{
if ( !v10 )
{
if ( argc <= v8 )
LABEL_6:
exit(1);
LABEL_30:
exit(2);
}
v8 = v4;
v7 = argv[v4];
}
v4 = v8 + 1;
if ( argc <= v8 + 1 )
goto LABEL_13;
}
}
v17 = 40;
v5 = 40;
v6 = "\n";
v7 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
LABEL_13:
v12 = strlen(v7);
v20[0] = v17;
ptr = malloc(v17);
v13 = &ptr[v17];
if ( v17 > v5 )
goto LABEL_27;
while ( 1 )
{
v14 = ptr;
if ( ptr < v13 )
break;
LABEL_25:
v16 = fwrite(ptr, 1uLL, v20[0], _bss_start);
printf(v6);
if ( v20[0] != v16 )
return 0;
if ( v17 > v5 )
{
LABEL_27:
if ( !(unsigned __int8)func10(v20, (unsigned int)v5, (unsigned int)v17, stdin) )
return 0;
v13 = &ptr[v20[0]];
}
}
while ( (unsigned __int8)func10(&v19, 0LL, v12, stdin) )
{
*v14++ = v7[v19];
if ( v14 == v13 )
goto LABEL_25;
}
return 0;
}

original_code:
int main(int argc, char**argv) {
  char* lib = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  int libl;
  char *sep = "\n";
  int minl = 40, maxl = 40;
  int ai;
  char* arg;
  char opt;
  for (ai=0; ai<argc; ai++) {
    arg = argv[ai];
    if (arg[0] != '-' && arg[1] != '\0') {
      lib = arg;
      continue;
    }
    opt = arg[1];
    ai++;
    if (ai >= argc)
      exit(1);
    arg = argv[ai];
    switch(opt) {
      case 'a':
        minl = atoi(arg);
        break;
      case 'z':
        maxl = atoi(arg);
        break;
      case 'x':
        minl = maxl = atoi(arg);
        break;
      case 's':
        sep = arg;
        break;
      default:
        exit(2);
    }
  }
  libl = strlen(lib);
  char *lbuf = malloc(maxl), *pt;
  char *tow = lbuf + maxl;
  int c, llen = maxl;
  while(1) {
    pt = lbuf;
    if (minl < maxl) {
      if (!rrandi( &llen, minl, maxl, stdin))
        return 0;
      tow = lbuf + llen;
    }
    while(pt < tow) {
      if (!rrandi(&c, 0, libl, stdin))
        return 0;
      *(pt++) = lib[c];
    }
    size_t wrot = fwrite(lbuf, sizeof(char), llen, stdout);
    printf(sep);
    if (wrot != llen)
      return 0;
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  char *lib = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  int libl;
  char *sep = "\n";
  int minl = 40; int maxl = 40;
  int ai;
  char *arg;
  char opt;
  for (ai=0; ai<argc; ai++) {
    arg = argv[ai];
    if (arg[0] != '-' && arg[1] != '\0') {
      lib = arg;
      continue;
    }
    opt = arg[1];
    ai++;
    if (ai >= argc)
      exit(1);
    arg = argv[ai];
    switch(opt) {
      case 'a':
        minl = atoi(arg);
        break;
      case 'z':
        maxl = atoi(arg);
        break;
      case 'x':
        minl = maxl = atoi(arg);
        break;
      case 's':
        sep = arg;
        break;
      default:
        exit(2);
    }
  }
  libl = strlen(lib);
  char *lbuf = malloc(maxl); char *pt;
  char *tow = lbuf + maxl;
  int c; int llen = maxl;
  while(1) {
    pt = lbuf;
    if (minl < maxl) {
      if (!rrandi( &llen, minl, maxl, stdin))
        return 0;
      tow = lbuf + llen;
    }
    while(pt < tow) {
      if (!rrandi(&c, 0, libl, stdin))
        return 0;
      *(pt++) = lib[c];
    }
    unsigned long wrot = fwrite(lbuf, sizeof(char), llen, stdout);
    printf(sep);
    if (wrot != llen)
      return 0;
  }
}

variable_types:
argv
char **

variable_types:
lib
char *

variable_types: libl int

variable_types:
sep
char *

variable_types: minl int

variable_types: maxl int

variable_types: ai int

variable_types: opt char

variable_types:
lbuf
char *

variable_types:
pt
char *

variable_types:
tow
char *

variable_types: c int

variable_types: llen int

variable_types:
wrot
unsigned long


absmod

decompiled_code:
__int64 __fastcall absmod(int a1, int a2)
{
return abs32(a1 % a2);
}

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

original_code:
int absmod(int i, int m) {
  return abs(i%m);
}

variable_types: i int

variable_types: m int


repo: koreyconway/school-assignments

decompiled_code:
const char *__fastcall get_signal_name(int a1)
{
const char *result; // rax

result = "SIGINT";
if ( a1 != 2 )
{
result = "UNKNOWN";
if ( a1 == 15 )
result = "SIGTERM";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
const char *result; // rax

result = "SIGINT";
if ( a1 != 2 )
{
result = "UNKNOWN";
if ( a1 == 15 )
result = "SIGTERM";
}
return result;
}

original_code:
char* get_signal_name(int sigtype) {
 char *signame;
 switch(sigtype) {
  case 15:
   signame = "SIGTERM";
   break;
  case 2:
   signame = "SIGINT";
   break;
  default:
   signame = "UNKNOWN";
 }
 return signame;
}

canonical_original_code:
char *get_signal_name(int sigtype) {
 char *signame;
 switch(sigtype) {
  case 15:
   signame = "SIGTERM";
   break;
  case 2:
   signame = "SIGINT";
   break;
  default:
   signame = "UNKNOWN";
 }
 return signame;
}

variable_types: sigtype int

variable_types:
signame
char *

return_type: char *


decompiled_code:
__pid_t get_parent_pid()
{
__pid_t result; // eax

result = parent_pid;
if ( parent_pid == -1 )
{
result = getpid();
parent_pid = result;
}
return result;
}

canonical_decompiled_code:
__pid_t func1()
{
__pid_t result; // eax

result = parent_pid;
if ( parent_pid == -1 )
{
result = getpid();
parent_pid = result;
}
return result;
}

original_code:
pid_t get_parent_pid() {
 if (-1 == parent_pid) {
  parent_pid = getpid();
 }
 return parent_pid;
}

canonical_original_code:
int get_parent_pid() {
 if (-1 == parent_pid) {
  parent_pid = getpid();
 }
 return parent_pid;
}


decompiled_code:
bool is_parent()
{
__pid_t v0; // ebx

v0 = getpid();
return v0 == get_parent_pid();
}

canonical_decompiled_code:
bool func2()
{
__pid_t v0; // ebx

v0 = getpid();
return v0 == func1();
}

original_code:
_Bool is_parent() {
 return (getpid() == get_parent_pid());
}


dump

decompiled_code:
int dump(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
if ( is_parent() )
printf("[parent] ");
else
printf("[child] ");
vprintf(format, arg);
return putchar(10);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
if ( func2() )
printf("[parent] ");
else
printf("[child] ");
vprintf(format, arg);
return putchar(10);
}

original_code:
void dump(const char * format, ...) {
 va_list args;
 __builtin_va_start(args,format);
 if (is_parent()) {
  printf("[parent] ");
 } else {
  printf("[child]  ");
 }
 vprintf(format, args);
 printf("\n");
 __builtin_va_end(args);
}

canonical_original_code:
void dump(char *format, ...) {
 __builtin_va_list args;
 __builtin_va_start(args,format);
 if (is_parent()) {
  printf("[parent] ");
 } else {
  printf("[child]  ");
 }
 vprintf(format, args);
 printf("\n");
 __builtin_va_end(args);
}

variable_types:
format
char *


decompiled_code:
int __fastcall setup_signal_handling(int sig, void (*a2)(int))
{
const char *v2; // rax
struct sigaction v4; // [rsp+0h] [rbp-B8h] BYREF

v2 = get_signal_name(sig);
dump("Setup signal handling for signal type: %s", v2);
v4.sa_handler = a2;
memset(&v4.sa_mask, 0, 0x90uLL);
sigemptyset(&v4.sa_mask);
return sigaction(sig, &v4, 0LL);
}

canonical_decompiled_code:
int __fastcall func4(int sig, void (*a2)(int))
{
const char *v2; // rax
struct sigaction v4; // [rsp+0h] [rbp-B8h] BYREF

v2 = func0(sig);
func3("Setup signal handling for signal type: %s", v2);
v4.sa_handler = a2;
memset(&v4.sa_mask, 0, 0x90uLL);
sigemptyset(&v4.sa_mask);
return sigaction(sig, &v4, 0LL);
}

original_code:
void setup_signal_handling(int sigtype, void(*handler)(int)) {
 char *signame = get_signal_name(sigtype);
 dump("Setup signal handling for signal type: %s", signame);
 struct sigaction handle_act = {
  .__sigaction_handler.sa_handler = handler,
  .sa_flags = 0
 };
 sigemptyset(&handle_act.sa_mask);
 sigaction(sigtype, &handle_act, 0);
}

canonical_original_code:
void setup_signal_handling(int sigtype, void (*handler)(int)) {
 char *signame = get_signal_name(sigtype);
 dump("Setup signal handling for signal type: %s", signame);
 struct sigaction handle_act = {
  .__sigaction_handler.sa_handler = handler,
  .sa_flags = 0
 };
 sigemptyset(&handle_act.sa_mask);
 sigaction(sigtype, &handle_act, 0);
}

variable_types:
handler
void (*)(int)

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
char __fastcall send_signal(int sig)
{
const char *v1; // rsi
char v2; // cl
__pid_t v3; // eax
char result; // al
__pid_t v5; // eax

v1 = get_signal_name(sig);
if ( v2 )
{
dump("Sending %s signal to parent process", v1);
if ( is_parent() )
{
LABEL_3:
v3 = getpid();
return kill(v3, sig);
}
v5 = getppid();
result = kill(v5, sig);
}
else
{
dump("Sending %s signal to child process", v1);
result = is_parent();
if ( !result )
goto LABEL_3;
if ( child_pid > 0 )
result = kill(child_pid, sig);
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(int sig)
{
const char *v1; // rsi
char v2; // cl
__pid_t v3; // eax
char result; // al
__pid_t v5; // eax

v1 = func0(sig);
if ( v2 )
{
func3("Sending %s signal to parent process", v1);
if ( func2() )
{
LABEL_3:
v3 = getpid();
return kill(v3, sig);
}
v5 = getppid();
result = kill(v5, sig);
}
else
{
func3("Sending %s signal to child process", v1);
result = func2();
if ( !result )
goto LABEL_3;
if ( child_pid > 0 )
result = kill(child_pid, sig);
}
return result;
}

original_code:
void send_signal(int sigtype, _Bool parent_is_destination) {
 char *signame = get_signal_name(sigtype);
 if (parent_is_destination) {
  dump("Sending %s signal to parent process", signame);
  if (is_parent()) {
   kill(getpid(), sigtype);
  } else {
   kill(getppid(), sigtype);
  }
 } else {
  dump("Sending %s signal to child process", signame);
  if(!is_parent()) {
   kill(getpid(), sigtype);
  } else if (child_pid > 0) {
   kill(child_pid, sigtype);
  }
 }
}


decompiled_code:
__int64 __fastcall fork_process(__int64 (*a1)(void), __int64 (*a2)(void))
{
__pid_t v2; // eax
__int64 result; // rax

get_parent_pid();
v2 = fork();
child_pid = v2;
if ( v2 == -1 )
{
dump("Fork failed");
exit(1);
}
if ( v2 )
result = a1();
else
result = a2();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 (*a1)(void), __int64 (*a2)(void))
{
__pid_t v2; // eax
__int64 result; // rax

func1();
v2 = fork();
child_pid = v2;
if ( v2 == -1 )
{
func3("Fork failed");
exit(1);
}
if ( v2 )
result = a1();
else
result = a2();
return result;
}

original_code:
void fork_process(void(*parent_main)(), void(*child_main)()) {
 get_parent_pid();
 child_pid = fork();
 switch(child_pid) {
  case -1:
   dump("Fork failed");
   exit(1);
  case 0:
   child_main();
   break;
  default:
   parent_main();
   break;
 }
}

canonical_original_code:
void fork_process(void (*parent_main)(), void (*child_main)()) {
 get_parent_pid();
 child_pid = fork();
 switch(child_pid) {
  case -1:
   dump("Fork failed");
   exit(1);
  case 0:
   child_main();
   break;
  default:
   parent_main();
   break;
 }
}


decompiled_code:
__pid_t get_child_pid()
{
__pid_t result; // eax

if ( is_parent() )
result = child_pid;
else
result = getpid();
return result;
}

canonical_decompiled_code:
__pid_t func7()
{
__pid_t result; // eax

if ( func2() )
result = child_pid;
else
result = getpid();
return result;
}

original_code:
pid_t get_child_pid() {
 if (is_parent()) {
  return child_pid;
 } else {
  return getpid();
 }
}

canonical_original_code:
int get_child_pid() {
 if (is_parent()) {
  return child_pid;
 } else {
  return getpid();
 }
}


decompiled_code:
__int64 __fastcall handle_signal(int a1)
{
__int64 result; // rax
const char *v2; // rdi

if ( a1 == 2 )
{
v2 = "Received SIGINT signal";
}
else
{
if ( a1 != 15 )
return dump("Received unknown signal. Ignoring it");
v2 = "Received SIGTERM signal";
}
dump(v2);
running = 0;
result = is_parent();
if ( (_BYTE)result )
result = send_signal(15LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
const char *v2; // rdi

if ( a1 == 2 )
{
v2 = "Received SIGINT signal";
}
else
{
if ( a1 != 15 )
return dump("Received unknown signal. Ignoring it");
v2 = "Received SIGTERM signal";
}
dump(v2);
running = 0;
result = is_parent();
if ( (_BYTE)result )
result = send_signal(15LL, 0LL);
return result;
}

original_code:
void handle_signal(int sigtype) {
 if (2 == sigtype) {
  dump("Received SIGINT signal");
  running = 0;
  if (is_parent()) {
   send_signal(15, 0);
  }
 } else if (15 == sigtype) {
  dump("Received SIGTERM signal");
  running = 0;
  if (is_parent()) {
   send_signal(15, 0);
  }
 } else {
  dump("Received unknown signal. Ignoring it");
 }
}


decompiled_code:
int __fastcall close_monitor(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int result; // eax
int *v4; // rax
int buf[2]; // [rsp+8h] [rbp-40h] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

sprintf(s, "./fifo.monitor.%d", a1);
dump("Opening fifo %s to send terminate request.", s);
v1 = open(s, 1);
if ( v1 == -1 )
{
v4 = _errno_location();
result = dump("Failed to open fifo with error: %d", (unsigned int)*v4);
}
else
{
v2 = v1;
dump("Sending request to terminate to monitor pid: %d", a1);
buf[0] = getpid();
buf[1] = 1;
if ( write(v2, buf, 8uLL) == -1 )
dump("Failed to write to fifo");
result = close(v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
int v1; // eax
int v2; // ebp
int result; // eax
int *v4; // rax
int buf[2]; // [rsp+8h] [rbp-40h] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

sprintf(s, "./fifo.monitor.%d", a1);
dump("Opening fifo %s to send terminate request.", s);
v1 = open(s, 1);
if ( v1 == -1 )
{
v4 = _errno_location();
result = dump("Failed to open fifo with error: %d", (unsigned int)*v4);
}
else
{
v2 = v1;
dump("Sending request to terminate to monitor pid: %d", a1);
buf[0] = getpid();
buf[1] = 1;
if ( write(v2, buf, 8uLL) == -1 )
dump("Failed to write to fifo");
result = close(v2);
}
return result;
}

original_code:
void close_monitor(int monitor_pid) {
 char monitor_fifo_name[sizeof("./fifo.monitor.%d") + 5];
 sprintf(monitor_fifo_name, "./fifo.monitor.%d", monitor_pid);
 dump("Opening fifo %s to send terminate request.", monitor_fifo_name);
 int monitor_fifo_fd = open(monitor_fifo_name, 01);
 if (-1 == monitor_fifo_fd) {
  dump("Failed to open fifo with error: %d", (*__errno_location ()));
  return;
 }
 dump("Sending request to terminate to monitor pid: %d", monitor_pid);
 fifo_data fdata;
 fdata.source_pid = getpid();
 fdata.request_type = STOP;
 if(-1 == write(monitor_fifo_fd, &fdata, sizeof(fdata))) {
  dump("Failed to write to fifo");
 }
 close(monitor_fifo_fd);
}

canonical_original_code:
void close_monitor(int monitor_pid) {
 char monitor_fifo_name[-1];
 sprintf(monitor_fifo_name, "./fifo.monitor.%d", monitor_pid);
 dump("Opening fifo %s to send terminate request.", monitor_fifo_name);
 int monitor_fifo_fd = open(monitor_fifo_name, 01);
 if (-1 == monitor_fifo_fd) {
  dump("Failed to open fifo with error: %d", (*__errno_location ()));
  return;
 }
 dump("Sending request to terminate to monitor pid: %d", monitor_pid);
 struct fifo_data fdata;
 fdata.source_pid = getpid();
 fdata.request_type = STOP;
 if(-1 == write(monitor_fifo_fd, &fdata, sizeof(fdata))) {
  dump("Failed to write to fifo");
 }
 close(monitor_fifo_fd);
}

variable_types: struct fifo_data { int source_pid; enum { START=0, STOP=1, CONNECT=2, STOPPING=3 } request_type; }


repo: korisk/pinc

decompiled_code:
int dumb_fini()
{
int result; // eax

result = incremented;
if ( !incremented )
result = puts("alarm! wrong result");
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax

result = incremented;
if ( !incremented )
result = puts("alarm! wrong result");
return result;
}

original_code:
int dumb_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
}

variable_types: nums int


decompiled_code:
__int64 __fastcall spin_init(unsigned int count)
{
incremented = 0LL;
pthread_spin_init(&spin, 0);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int count)
{
incremented = 0LL;
pthread_spin_init(&spin, 0);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int spin_init(int nums){
 incremented = 0;
 pthread_spin_init(&spin,0);
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall lock_init(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int count)
{
incremented = 0LL;
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int lock_init(int nums){
 incremented = 0;
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
// attributes: thunk
__int64 __fastcall lock2_init(unsigned int a1)
{
return lock_init(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return func2(a1);
}

original_code:
int lock2_init(int nums){
 incremented = 0;
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
// attributes: thunk
__int64 __fastcall dumb_init(unsigned int a1)
{
return lock_init(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return func2(a1);
}

original_code:
int dumb_init(int nums){
 incremented = 0;
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall dumb_thread(__int64 a1)
{
__int64 v1; // rcx
__int64 i; // rdx

pthread_barrier_wait(&barrier);
if ( !*(_DWORD *)(a1 + 8) )
{
v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
for ( i = 0LL; i != v1; ++i )
++incremented;
}
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rcx
__int64 i; // rdx

pthread_barrier_wait(&barrier);
if ( !*(_DWORD *)(a1 + 8) )
{
v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
{
for ( i = 0LL; i != v1; ++i )
++incremented;
}
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *dumb_thread(void *_data){
 position *data = (position*)(_data);
 pthread_barrier_wait(&barrier);
 if(data->my_number != 0)goto ex;
 unsigned long i = 0;
  for(i=0; i< data->big_number; i++){
  incremented++;
 }
ex:
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *dumb_thread(void *_data){
 struct position *data = (position*)(_data);
 pthread_barrier_wait(&barrier);
 if(data->my_number != 0)goto ex;
 unsigned long i = 0;
  for(i=0; i< data->big_number; i++){
  incremented++;
 }
ex:
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

variable_types: struct position { int nprocs; int threads; int my_number; unsigned long big_number; } *

variable_types:
i
unsigned long

return_type: void *


decompiled_code:
__int64 __fastcall spin_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
++v6;
pthread_spin_lock(&spin);
++incremented;
pthread_spin_unlock(&spin);
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
++v6;
pthread_spin_lock(&spin);
++incremented;
pthread_spin_unlock(&spin);
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *spin_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_spin_lock(&spin);
  incremented++;
  pthread_spin_unlock(&spin);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *spin_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_spin_lock(&spin);
  incremented++;
  pthread_spin_unlock(&spin);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }

variable_types: ret int

variable_types:
N
unsigned long

user_defined_types: struct position { int nprocs; int threads; int my_number; unsigned long big_number; }


decompiled_code:
int spin_fini()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_spin_destroy(&spin);
return pthread_barrier_destroy(&barrier);
}

canonical_decompiled_code:
int func7()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_spin_destroy(&spin);
return pthread_barrier_destroy(&barrier);
}

original_code:
int spin_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_spin_destroy(&spin);
 pthread_barrier_destroy(&barrier);
}


decompiled_code:
int lock_fini()
{
if ( !incremented )
puts("alarm! wrong result");
return pthread_barrier_destroy(&barrier);
}

canonical_decompiled_code:
int func8()
{
if ( !incremented )
puts("alarm! wrong result");
return pthread_barrier_destroy(&barrier);
}

original_code:
int lock_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_barrier_destroy(&barrier);
}


decompiled_code:
// attributes: thunk
int lock2_fini()
{
return lock_fini();
}

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

original_code:
int lock2_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_barrier_destroy(&barrier);
}


decompiled_code:
__int64 __fastcall mutex_init(unsigned int count)
{
incremented = 0LL;
pthread_mutex_init(&mut, 0LL);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int count)
{
incremented = 0LL;
pthread_mutex_init(&mut, 0LL);
pthread_barrier_init(&barrier, 0LL, count);
return 0LL;
}

original_code:
int mutex_init(int nums){
 incremented = 0;
 pthread_mutex_init(&mut,((void *)0));
 pthread_barrier_init(&barrier, ((void *)0), nums);
 return 0;
}


decompiled_code:
__int64 __fastcall mutex_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
++v6;
pthread_mutex_lock(&mut);
++incremented;
pthread_mutex_unlock(&mut);
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rbx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
++v6;
pthread_mutex_lock(&mut);
++incremented;
pthread_mutex_unlock(&mut);
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *mutex_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_mutex_lock(&mut);
  incremented++;
  pthread_mutex_unlock(&mut);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *mutex_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  pthread_mutex_lock(&mut);
  incremented++;
  pthread_mutex_unlock(&mut);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


decompiled_code:
int mutex_fini()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_barrier_destroy(&barrier);
return pthread_mutex_destroy(&mut);
}

canonical_decompiled_code:
int func12()
{
if ( !incremented )
puts("alarm! wrong result");
pthread_barrier_destroy(&barrier);
return pthread_mutex_destroy(&mut);
}

original_code:
int mutex_fini(int nums){
 if(incremented == 0)
  printf("alarm! wrong result\n");
 pthread_barrier_destroy(&barrier);
 pthread_mutex_destroy(&mut);
}


decompiled_code:
__int64 __fastcall lock_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
_InterlockedAdd64(&incremented, 1uLL);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rdx
char *v8; // rax
cpu_set_t v9; // [rsp+0h] [rbp-98h] BYREF

memset(&v9, 0, sizeof(v9));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v9.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v9);
if ( v3 )
{
v8 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v8);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
_InterlockedAdd64(&incremented, 1uLL);
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *lock_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  __sync_fetch_and_add(&incremented,1);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *lock_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
  for(i=0; i< N; i++){
  __sync_fetch_and_add(&incremented,1);
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall lock2_thread(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 v7; // rtt
char *v9; // rax
cpu_set_t v10; // [rsp+0h] [rbp-98h] BYREF

memset(&v10, 0, sizeof(v10));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v10.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v10);
if ( v3 )
{
v9 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v9);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
do
v7 = incremented;
while ( v7 != _InterlockedCompareExchange64(&incremented, incremented + 1, incremented) );
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
int v1; // edx
pthread_t v2; // rax
int v3; // eax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 v7; // rtt
char *v9; // rax
cpu_set_t v10; // [rsp+0h] [rbp-98h] BYREF

memset(&v10, 0, sizeof(v10));
v1 = *(_DWORD *)(a1 + 8) % *(_DWORD *)a1;
if ( (unsigned __int64)v1 <= 0x3FF )
v10.__bits[(unsigned __int64)v1 >> 6] |= 1LL << v1;
v2 = pthread_self();
v3 = pthread_setaffinity_np(v2, 0x80uLL, &v10);
if ( v3 )
{
v9 = strerror(v3);
fprintf(stdout, "Set affinity error: %s \n", v9);
exit(1);
}
pthread_barrier_wait(&barrier);
v4 = *(int *)(a1 + 4);
v5 = *(_QWORD *)(a1 + 16) / v4;
if ( *(_QWORD *)(a1 + 16) >= v4 )
{
v6 = 0LL;
do
{
do
v7 = incremented;
while ( v7 != _InterlockedCompareExchange64(&incremented, incremented + 1, incremented) );
++v6;
}
while ( v5 > v6 );
}
pthread_barrier_wait(&barrier);
return 0LL;
}

original_code:
void *lock2_thread(void *_data){
 position *data = (position*)(_data);
 cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
 unsigned long x = 0;
  for(i=0; i< N; i++){
  do{
   x = incremented;
  }while(!__sync_bool_compare_and_swap(&incremented,x , x + 1));
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

canonical_original_code:
void *lock2_thread(void *_data){
 struct position *data = (position*)(_data);
 struct cpu_set_t cpuset;
 do __builtin_memset ((&cpuset), '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = ((data->my_number % data->nprocs)); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) (((&cpuset))->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 int ret;
 ret = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
 if(ret != 0){
  fprintf(stdout,"Set affinity error: %s \n",strerror(ret));
  exit(1);
 }
 pthread_barrier_wait(&barrier);
 unsigned long N = (unsigned long)((data->big_number)/(data->threads));
 unsigned long i = 0;
 unsigned long x = 0;
  for(i=0; i< N; i++){
  do{
   x = incremented;
  }while(!__sync_bool_compare_and_swap(&incremented,x , x + 1));
 }
 pthread_barrier_wait(&barrier);
 return ((void *)0);
}

variable_types:
x
unsigned long


usage

decompiled_code:
int __fastcall usage(char *filename)
{
char *v1; // rax

puts("This test measures time spended for Parallel INCrement of one variable with using of different lock mechanism");
v1 = basename(filename);
printf("Usage: %s [-t addititional threads][-f big number factor][-h|-?]\n", v1);
puts("\t-t addititional theads - number of threads which added to number of processors");
puts("\t-f factor - factor which difine big number. Number of increments = factorial(factor)");
return puts("\t-h,-? - this help");
}

canonical_decompiled_code:
int __fastcall func15(char *filename)
{
char *v1; // rax

puts("This test measures time spended for Parallel INCrement of one variable with using of different lock mechanism");
v1 = basename(filename);
printf("Usage: %s [-t addititional threads][-f big number factor][-h|-?]\n", v1);
puts("\t-t addititional theads - number of threads which added to number of processors");
puts("\t-f factor - factor which difine big number. Number of increments = factorial(factor)");
return puts("\t-h,-? - this help");
}

original_code:
void usage(char *name){
 printf("This test measures time spended for Parallel INCrement of one variable with using of different lock mechanism\n");
 printf("Usage: %s [-t addititional threads][-f big number factor][-h|-?]\n",basename(name));
 printf("\t-t addititional theads - number of threads which added to number of processors\n");
 printf("\t-f factor - factor which difine big number. Number of increments = factorial(factor)\n");
 printf("\t-h,-? - this help\n");
}

variable_types:
name
char *


factor

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

for ( result = 1LL; a1; --a1 )
result *= a1;
return result;
}

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

for ( result = 1LL; a1; --a1 )
result *= a1;
return result;
}

original_code:
unsigned long factor(unsigned long N){
 if(N <= 0)return 1;
 return (N*factor(N-1));
}

return_type: unsigned long


epochmsec

decompiled_code:
__time_t epochmsec()
{
int v0; // er8
__time_t result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v0 = gettimeofday(&v2, 0LL);
result = 0LL;
if ( !v0 )
result = 1000 * v2.tv_sec + v2.tv_usec / 1000;
return result;
}

canonical_decompiled_code:
__time_t func17()
{
int v0; // er8
__time_t result; // rax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v0 = gettimeofday(&v2, 0LL);
result = 0LL;
if ( !v0 )
result = 1000 * v2.tv_sec + v2.tv_usec / 1000;
return result;
}

original_code:
unsigned long epochmsec() {
  struct timeval tv;
 if (gettimeofday(&tv, 0) == 0) {
  return tv.tv_sec * 1000 + tv.tv_usec / 1000;
 }else{
  return 0L;
 }
}

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