stdinit

decompiled_code:
void stdinit()
{
int *v0; // rbx
int *v1; // rbp
int *v2; // rax
int v3; // ecx
int *v4; // rbx
int *v5; // rbp
int *v6; // rax
int v7; // edx
int v8; // edx
int v9; // edi
int *v10; // rax
int *v11; // rcx
_BOOL4 v12; // er8
int *v13; // rsi

v0 = &standardchar;
v1 = &standardchar;
if ( standardchar )
{
while ( 1 )
{
if ( *((_QWORD *)v1 + 1) )
*((_QWORD *)v1 + 1) = xstrdup();
*((_QWORD *)v1 + 2) = v0;
v2 = v0;
v3 = *v0;
v0 += 6;
if ( !v3 )
break;
v1 = v2;
}
}
v4 = &standardstring;
chardef = (__int64)&standardchar;
v5 = &standardstring;
if ( standardstring )
{
while ( 1 )
{
if ( *((_QWORD *)v5 + 1) )
*((_QWORD *)v5 + 1) = xstrdup();
*((_QWORD *)v5 + 2) = v4;
v6 = v4;
v7 = *v4;
v4 += 6;
if ( !v7 )
break;
v5 = v6;
}
}
v8 = standardint;
strdef = (__int64)&standardstring;
if ( standardint )
{
v9 = nroff;
v10 = &standardint;
v11 = &standardint;
v12 = nroff == 0;
while ( 1 )
{
if ( v8 == -666 )
{
*v11 = v9;
}
else if ( v8 == -667 )
{
*v11 = v12;
}
*((_QWORD *)v11 + 2) = v10;
v13 = v10;
v8 = *v10;
v10 += 6;
if ( !v8 )
break;
v11 = v13;
}
}
intdef = (__int64)&standardint;
defdef = 0LL;
}

canonical_decompiled_code:
void func0()
{
int *v0; // rbx
int *v1; // rbp
int *v2; // rax
int v3; // ecx
int *v4; // rbx
int *v5; // rbp
int *v6; // rax
int v7; // edx
int v8; // edx
int v9; // edi
int *v10; // rax
int *v11; // rcx
_BOOL4 v12; // er8
int *v13; // rsi

v0 = &standardchar;
v1 = &standardchar;
if ( standardchar )
{
while ( 1 )
{
if ( *((_QWORD *)v1 + 1) )
*((_QWORD *)v1 + 1) = xstrdup();
*((_QWORD *)v1 + 2) = v0;
v2 = v0;
v3 = *v0;
v0 += 6;
if ( !v3 )
break;
v1 = v2;
}
}
v4 = &standardstring;
chardef = (__int64)&standardchar;
v5 = &standardstring;
if ( standardstring )
{
while ( 1 )
{
if ( *((_QWORD *)v5 + 1) )
*((_QWORD *)v5 + 1) = xstrdup();
*((_QWORD *)v5 + 2) = v4;
v6 = v4;
v7 = *v4;
v4 += 6;
if ( !v7 )
break;
v5 = v6;
}
}
v8 = standardint;
strdef = (__int64)&standardstring;
if ( standardint )
{
v9 = nroff;
v10 = &standardint;
v11 = &standardint;
v12 = nroff == 0;
while ( 1 )
{
if ( v8 == -666 )
{
*v11 = v9;
}
else if ( v8 == -667 )
{
*v11 = v12;
}
*((_QWORD *)v11 + 2) = v10;
v13 = v10;
v8 = *v10;
v10 += 6;
if ( !v8 )
break;
v11 = v13;
}
}
intdef = (__int64)&standardint;
defdef = 0LL;
}

original_code:
void stdinit(void) {
    STRDEF *stdf;
    int i;
    stdf = &standardchar[0];
    i = 0;
    while (stdf->nr) {
 if (stdf->st) stdf->st = xstrdup(stdf->st);
 stdf->next = &standardchar[i];
 stdf = stdf->next;
 i++;
    }
    chardef=&standardchar[0];
    stdf=&standardstring[0];
    i=0;
    while (stdf->nr) {
 if (stdf->st) stdf->st = xstrdup(stdf->st);
 stdf->next = &standardstring[i];
 stdf = stdf->next;
 i++;
    }
    strdef=&standardstring[0];
    intdef=&standardint[0];
    i=0;
    while (intdef->nr) {
 if (intdef->nr == (-666)) intdef->nr = nroff; else
 if (intdef->nr == (-667)) intdef->nr = !nroff;
 intdef->next = &standardint[i];
 intdef = intdef->next;
 i++;
    }
    intdef = &standardint[0];
    defdef = ((void *) 0);
}

canonical_original_code:
void stdinit() {
    struct STRDEF *stdf;
    int i;
    stdf = &standardchar[0];
    i = 0;
    while (stdf->nr) {
 if (stdf->st) stdf->st = xstrdup(stdf->st);
 stdf->next = &standardchar[i];
 stdf = stdf->next;
 i++;
    }
    chardef=&standardchar[0];
    stdf=&standardstring[0];
    i=0;
    while (stdf->nr) {
 if (stdf->st) stdf->st = xstrdup(stdf->st);
 stdf->next = &standardstring[i];
 stdf = stdf->next;
 i++;
    }
    strdef=&standardstring[0];
    intdef=&standardint[0];
    i=0;
    while (intdef->nr) {
 if (intdef->nr == (-666)) intdef->nr = nroff; else
 if (intdef->nr == (-667)) intdef->nr = !nroff;
 intdef->next = &standardint[i];
 intdef = intdef->next;
 i++;
    }
    intdef = &standardint[0];
    defdef = ((void *) 0);
}

variable_types: struct STRDEF { int nr; char *st; struct STRDEF *next; } *


main

canonical_name: main

repo: hancyxhx/Shuffle

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

parse_arg(argc, (char **)argv);
v3 = shuffle(global_args);
show_deck(v3);
return 0;
}

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

func9(argc, (char **)argv);
v3 = shuffle(global_args);
func11(v3);
return 0;
}

original_code:
int main (int argc, char *argv[] ){
    parse_arg(argc, argv);
    Poker *shuffle_deck;
    shuffle_deck = shuffle(global_args.draw_deck);
    show_deck(shuffle_deck);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    parse_arg(argc, argv);
    char **shuffle_deck;
    shuffle_deck = shuffle(global_args.draw_deck);
    show_deck(shuffle_deck);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


usage

decompiled_code:
void __noreturn usage()
{
puts("Usage: shuffle [FILE]");
puts("try `shuffle -h' for more information.");
exit(-1);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("Usage: shuffle [FILE]");
puts("try `shuffle -h' for more information.");
exit(-1);
}

original_code:
void usage(){
    printf("Usage: shuffle [FILE]\n");
    printf("try `shuffle -h' for more information.\n");
    exit(-1);
}

return_type: void


man

decompiled_code:
void __noreturn man()
{
puts("NAME");
puts("\tshuffle - shuffle lines of text file");
puts("SYNOPSIS");
puts("\tshuffle [OPTION] [FILE]");
puts("AUTHOR");
puts("\tWritten by hancy hush");
puts("REPORTING BUGS");
puts("\tReport bugs to <hancyxhx@gmail.com>");
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
puts("NAME");
puts("\tshuffle - shuffle lines of text file");
puts("SYNOPSIS");
puts("\tshuffle [OPTION] [FILE]");
puts("AUTHOR");
puts("\tWritten by hancy hush");
puts("REPORTING BUGS");
puts("\tReport bugs to <hancyxhx@gmail.com>");
exit(0);
}

original_code:
void man(){
    printf("NAME\n");
    printf("\tshuffle - shuffle lines of text file\n");
    printf("SYNOPSIS\n");
    printf("\tshuffle [OPTION] [FILE]\n");
    printf("AUTHOR\n");
    printf("\tWritten by hancy hush\n");
    printf("REPORTING BUGS\n");
    printf("\tReport bugs to <hancyxhx@gmail.com>\n");
    exit(0);
}


decompiled_code:
int __fastcall show_deck(const char **a1)
{
const char *v1; // rsi
const char **v2; // rbx
int result; // eax

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
++v2;
result = printf("%s", v1);
v1 = *(v2 - 1);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char **a1)
{
const char *v1; // rsi
const char **v2; // rbx
int result; // eax

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
++v2;
result = printf("%s", v1);
v1 = *(v2 - 1);
}
while ( v1 );
}
return result;
}

original_code:
void show_deck(Poker deck[]){
    int i;
    for (i=0; deck[i] != ((void *)0); i++)
 printf("%s",deck[i]);
}

canonical_original_code:
void show_deck(char *deck[]){
    int i;
    for (i=0; deck[i] != ((void *)0); i++)
 printf("%s",deck[i]);
}

variable_types:
deck
char *[]

variable_types: i int


decompiled_code:
int __fastcall show_tank(int a1, int a2, __int64 a3)
{
mvwprintw(
stdscr,
a1,
a2,
"(%d,%d)(dir:%d)=%d=(cm:%d)=%p=%p",
*(unsigned int *)(a3 + 4),
*(unsigned int *)(a3 + 8),
*(unsigned int *)(a3 + 20),
*(unsigned int *)(a3 + 32),
*(unsigned int *)(a3 + 36),
(const void *)a3,
*(const void **)(a3 + 40));
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, __int64 a3)
{
mvwprintw(
stdscr,
a1,
a2,
"(%d,%d)(dir:%d)=%d=(cm:%d)=%p=%p",
*(unsigned int *)(a3 + 4),
*(unsigned int *)(a3 + 8),
*(unsigned int *)(a3 + 20),
*(unsigned int *)(a3 + 32),
*(unsigned int *)(a3 + 36),
(const void *)a3,
*(const void **)(a3 + 40));
return wrefresh(stdscr);
}

original_code:
void show_tank(int y, int x, const object_type_t *tank)
{
 const object_type_t *tk=tank;
 mvwprintw(stdscr,y,x,"(%d,%d)(dir:%d)=%d=(cm:%d)=%p=%p",tk->coordinate.y, tk->coordinate.x,tk->dir,tk->number,tk->canmove,tk,tk->next);
 wrefresh(stdscr);
}

canonical_original_code:
void show_tank(int y, int x, struct object_type *tank)
{
 struct object_type *tk = tank;
 mvwprintw(stdscr,y,x,"(%d,%d)(dir:%d)=%d=(cm:%d)=%p=%p",tk->coordinate.y, tk->coordinate.x,tk->dir,tk->number,tk->canmove,tk,tk->next);
 wrefresh(stdscr);
}

variable_types: y int

variable_types: x int

variable_types: struct object_type { enum object { OBJECT_TANK=0, OBJECT_BULLET=1, OBJECT_BARRIER=2 } object; struct coordinate { int y; int x; } coordinate; struct size { int h; int w; } size; enum dir { DIR_UP=0, DIR_RIGHT=1, DIR_DOWN=2, DIR_LEFT=3, DIR_NONE=4 } dir; enum standpoint { STANDPOINT_WHITE=0, STANDPOINT_GREEN=1, STANDPOINT_BLUE=2 } standpoint; int hp; int number; int canmove; struct object_type *next; } *

user_defined_types: struct object_type { enum object object; struct coordinate coordinate; struct size size; enum dir dir; enum standpoint standpoint; int hp; int number; int canmove; struct object_type *next; }


original_code:
object_type_t *object_type_copy(object_type_t *dest,const object_type_t *src)
{
 if(((void *)0)==dest||((void *)0)==src){
  return ((void *)0);
 }
 dest->object=src->object;
 coordinate_copy(&dest->coordinate,&src->coordinate);
 size_copy(&dest->size,&src->size);
 dest->dir=src->dir;
 dest->standpoint=src->standpoint;
 dest->hp=src->hp;
 dest->number=src->number;
 dest->canmove=src->canmove;
 dest->next=src->next;
 return dest;
}

canonical_original_code:
struct object_type *object_type_copy(struct object_type *dest, struct object_type *src)
{
 if(((void *)0)==dest||((void *)0)==src){
  return ((void *)0);
 }
 dest->object=src->object;
 coordinate_copy(&dest->coordinate,&src->coordinate);
 size_copy(&dest->size,&src->size);
 dest->dir=src->dir;
 dest->standpoint=src->standpoint;
 dest->hp=src->hp;
 dest->number=src->number;
 dest->canmove=src->canmove;
 dest->next=src->next;
 return dest;
}

variable_types:
dest
struct object_type *

variable_types:
src
struct object_type *

return_type: struct object_type { enum object { OBJECT_TANK=0, OBJECT_BULLET=1, OBJECT_BARRIER=2 } object; struct coordinate { int y; int x; } coordinate; struct size { int h; int w; } size; enum dir { DIR_UP=0, DIR_RIGHT=1, DIR_DOWN=2, DIR_LEFT=3, DIR_NONE=4 } dir; enum standpoint { STANDPOINT_WHITE=0, STANDPOINT_GREEN=1, STANDPOINT_BLUE=2 } standpoint; int hp; int number; int canmove; struct object_type *next; } *


decompiled_code:
void __fastcall open_colors(int a1, int a2, int a3)
{
if ( a1 == 1 )
{
if ( a2 == 1 )
{
switch ( a3 )
{
case -2:
if ( has_colors() )
wattr_on(stdscr, 0x200A00uLL, 0LL);
break;
case -1:
if ( has_colors() )
wattr_on(stdscr, 0x200900uLL, 0LL);
break;
case -4:
if ( has_colors() )
wattr_on(stdscr, 0x200B00uLL, 0LL);
break;
default:
if ( has_colors() )
wattr_on(stdscr, 0x200800uLL, 0LL);
break;
}
}
else if ( a2 == 2 && has_colors() )
{
wattr_on(stdscr, 0x200700uLL, 0LL);
}
}
else if ( a1 == 2 )
{
if ( !a2 && has_colors() )
wattr_on(stdscr, 0x200C00uLL, 0LL);
}
else
{
if ( a1 )
return;
if ( a2 != 1 )
{
if ( a2 != 2 )
return;
if ( a3 != -2 )
{
if ( a3 != -1 )
{
if ( a3 != -4 )
{
if ( has_colors() )
wattr_on(stdscr, 0x200200uLL, 0LL);
return;
}
goto LABEL_33;
}
goto LABEL_29;
}
goto LABEL_31;
}
switch ( a3 )
{
case -2:
LABEL_31:
if ( has_colors() )
wattr_on(stdscr, 0x200500uLL, 0LL);
return;
case -1:
LABEL_29:
if ( has_colors() )
wattr_on(stdscr, 0x200400uLL, 0LL);
return;
case -4:
LABEL_33:
if ( has_colors() )
wattr_on(stdscr, 0x200600uLL, 0LL);
return;
}
if ( has_colors() )
wattr_on(stdscr, 0x200300uLL, 0LL);
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2, int a3)
{
if ( a1 == 1 )
{
if ( a2 == 1 )
{
switch ( a3 )
{
case -2:
if ( has_colors() )
wattr_on(stdscr, 0x200A00uLL, 0LL);
break;
case -1:
if ( has_colors() )
wattr_on(stdscr, 0x200900uLL, 0LL);
break;
case -4:
if ( has_colors() )
wattr_on(stdscr, 0x200B00uLL, 0LL);
break;
default:
if ( has_colors() )
wattr_on(stdscr, 0x200800uLL, 0LL);
break;
}
}
else if ( a2 == 2 && has_colors() )
{
wattr_on(stdscr, 0x200700uLL, 0LL);
}
}
else if ( a1 == 2 )
{
if ( !a2 && has_colors() )
wattr_on(stdscr, 0x200C00uLL, 0LL);
}
else
{
if ( a1 )
return;
if ( a2 != 1 )
{
if ( a2 != 2 )
return;
if ( a3 != -2 )
{
if ( a3 != -1 )
{
if ( a3 != -4 )
{
if ( has_colors() )
wattr_on(stdscr, 0x200200uLL, 0LL);
return;
}
goto LABEL_33;
}
goto LABEL_29;
}
goto LABEL_31;
}
switch ( a3 )
{
case -2:
LABEL_31:
if ( has_colors() )
wattr_on(stdscr, 0x200500uLL, 0LL);
return;
case -1:
LABEL_29:
if ( has_colors() )
wattr_on(stdscr, 0x200400uLL, 0LL);
return;
case -4:
LABEL_33:
if ( has_colors() )
wattr_on(stdscr, 0x200600uLL, 0LL);
return;
}
if ( has_colors() )
wattr_on(stdscr, 0x200300uLL, 0LL);
}
}

variable_types: enum object { OBJECT_TANK=0, OBJECT_BULLET=1, OBJECT_BARRIER=2 }

variable_types: enum standpoint { STANDPOINT_WHITE=0, STANDPOINT_GREEN=1, STANDPOINT_BLUE=2 }

variable_types: number int


decompiled_code:
void __fastcall close_colors(int a1, int a2, int a3)
{
if ( a1 != 1 )
{
if ( a1 == 2 )
{
if ( !a2 && has_colors() )
wattr_off(stdscr, 0x200C00uLL, 0LL);
}
else if ( !a1 && (a2 == 1 || a2 == 2) )
{
switch ( a3 )
{
case -2:
if ( has_colors() )
wattr_off(stdscr, 0x200500uLL, 0LL);
break;
case -1:
if ( has_colors() )
wattr_off(stdscr, 0x200400uLL, 0LL);
break;
case -4:
if ( has_colors() )
wattr_off(stdscr, 0x200600uLL, 0LL);
break;
default:
if ( has_colors() )
wattr_off(stdscr, 0x200300uLL, 0LL);
break;
}
}
return;
}
if ( a2 != 1 )
{
if ( a2 != 2 )
return;
goto LABEL_7;
}
switch ( a3 )
{
case -2:
if ( has_colors() )
wattr_off(stdscr, 0x200A00uLL, 0LL);
break;
case -1:
if ( has_colors() )
wattr_off(stdscr, 0x200900uLL, 0LL);
break;
case -4:
if ( has_colors() )
wattr_off(stdscr, 0x200B00uLL, 0LL);
break;
default:
LABEL_7:
if ( has_colors() )
wattr_off(stdscr, 0x200700uLL, 0LL);
return;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2, int a3)
{
if ( a1 != 1 )
{
if ( a1 == 2 )
{
if ( !a2 && has_colors() )
wattr_off(stdscr, 0x200C00uLL, 0LL);
}
else if ( !a1 && (a2 == 1 || a2 == 2) )
{
switch ( a3 )
{
case -2:
if ( has_colors() )
wattr_off(stdscr, 0x200500uLL, 0LL);
break;
case -1:
if ( has_colors() )
wattr_off(stdscr, 0x200400uLL, 0LL);
break;
case -4:
if ( has_colors() )
wattr_off(stdscr, 0x200600uLL, 0LL);
break;
default:
if ( has_colors() )
wattr_off(stdscr, 0x200300uLL, 0LL);
break;
}
}
return;
}
if ( a2 != 1 )
{
if ( a2 != 2 )
return;
goto LABEL_7;
}
switch ( a3 )
{
case -2:
if ( has_colors() )
wattr_off(stdscr, 0x200A00uLL, 0LL);
break;
case -1:
if ( has_colors() )
wattr_off(stdscr, 0x200900uLL, 0LL);
break;
case -4:
if ( has_colors() )
wattr_off(stdscr, 0x200B00uLL, 0LL);
break;
default:
LABEL_7:
if ( has_colors() )
wattr_off(stdscr, 0x200700uLL, 0LL);
return;
}
}

user_defined_types: enum object { OBJECT_TANK=0, OBJECT_BULLET=1, OBJECT_BARRIER=2 }

user_defined_types: enum standpoint { STANDPOINT_WHITE=0, STANDPOINT_GREEN=1, STANDPOINT_BLUE=2 }


repo: handsomezhou/tetris

original_code:
static int init_grid(grid_t (*pgrid)[10])
{
 grid_t (*pg)[10]=pgrid;
 int y,x;
 if(((void *)0)==pg){
  return -1;
 }
 for(y=0; y<20; y++){
  for(x=0; x<10; x++){
   pg[y][x].y=y;
   pg[y][x].x=x;
   pg[y][x].type=BLOCK_TYPE_NONE;
   pg[y][x].value='0';
  }
 }
 return 0;
}

canonical_original_code:
static int init_grid(struct grid (*pgrid)[10])
{
 grid_t (*pg)[10]=pgrid;
 int y; int x;
 if(((void *)0)==pg){
  return -1;
 }
 for(y=0; y<20; y++){
  for(x=0; x<10; x++){
   pg[y][x].y=y;
   pg[y][x].x=x;
   pg[y][x].type=BLOCK_TYPE_NONE;
   pg[y][x].value='0';
  }
 }
 return 0;
}

variable_types: struct grid { int y; int x; enum block_type { BLOCK_I=0, BLOCK_J=1, BLOCK_L=2, BLOCK_O=3, BLOCK_S=4, BLOCK_Z=5, BLOCK_T=6, BLOCK_TYPE_NONE=7 } type; char value; } (*)[10]

user_defined_types: struct grid { int y; int x; enum block_type type; char value; }


decompiled_code:
void __fastcall exit_prompt(_QWORD *a1)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = (void *)a1[2];
if ( v2 )
{
free(v2);
a1[2] = 0LL;
}
v3 = (void *)a1[5];
if ( v3 )
{
free(v3);
a1[5] = 0LL;
}
v4 = (void *)a1[8];
if ( v4 )
{
free(v4);
a1[8] = 0LL;
}
}

original_code:
static void exit_prompt(prompt_t *prompt)
{
 prompt_t *ppt=prompt;
 if(((void *)0)==ppt){
  return;
 }
 if(((void *)0)!=ppt->level_show){
  free(ppt->level_show);
  ppt->level_show=((void *)0);
 }
 if(((void *)0)!=ppt->lines_show){
  free(ppt->lines_show);
  ppt->lines_show=((void *)0);
 }
 if(((void *)0)!=ppt->score_show){
  free(ppt->score_show);
  ppt->score_show=((void *)0);
 }
 return;
}

canonical_original_code:
static void exit_prompt(struct prompt *prompt)
{
 struct prompt *ppt = prompt;
 if(((void *)0)==ppt){
  return;
 }
 if(((void *)0)!=ppt->level_show){
  free(ppt->level_show);
  ppt->level_show=((void *)0);
 }
 if(((void *)0)!=ppt->lines_show){
  free(ppt->lines_show);
  ppt->lines_show=((void *)0);
 }
 if(((void *)0)!=ppt->score_show){
  free(ppt->score_show);
  ppt->score_show=((void *)0);
 }
 return;
}

variable_types: struct prompt { char level_key[-1]; int level_value; char *level_show; char lines_key[-1]; int lines_value; char *lines_show; char score_key[-1]; int score_value; char *score_show; char start[-1]; char pause[-1]; char quit[-1]; char title[-1]; } *


original_code:
static int init_prompt(prompt_t *prompt)
{
 prompt_t *ppt=prompt;
 char level_prompt[]="Failed to allocate space for level_show";
 char lines_prompt[]="Failed to allocate space for lines_show";
 char score_prompt[]="Failed to allocate space for score_show";
 int scr_y,scr_x;
 (scr_y = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), scr_x = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 if(((void *)0)==ppt){
  return -1;
 }
 if(((void *)0)!=ppt->level_show||((void *)0)!=ppt->lines_show||((void *)0)!=ppt->score_show){
  exit_prompt(ppt);
  ppt->level_show=((void *)0);
  ppt->lines_show=((void *)0);
  ppt->score_show=((void *)0);
 }
 memset(ppt->level_key,0,(sizeof("Level")));
 strncpy(ppt->level_key,"Level",(sizeof("Level")));
 ppt->level_value=0;
 ppt->level_show=malloc((10*sizeof(char)+1));
 if(((void *)0)==ppt->level_show){
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,(scr_x-strlen(level_prompt))/2,"%s",level_prompt);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  nodelay(stdscr,0);
  wgetch(stdscr);
  nodelay(stdscr,1);
  return -1;
 }
 snprintf(ppt->level_show,(10*sizeof(char)+1),"%s%5d",ppt->level_key,ppt->level_value);
 memset(ppt->lines_key,0,(sizeof("Lines")));
 strncpy(ppt->lines_key,"Lines",(sizeof("Lines")));
 ppt->lines_value=0;
 ppt->lines_show=malloc((10*sizeof(char)+1));
 if(((void *)0)==ppt->lines_show){
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,(scr_x-strlen(lines_prompt))/2,"%s",lines_prompt);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  nodelay(stdscr,0);
  wgetch(stdscr);
  nodelay(stdscr,1);
  return -1;
 }
 snprintf(ppt->lines_show,(10*sizeof(char)+1),"%s%5d",ppt->lines_key,ppt->lines_value);
 memset(ppt->score_key,0,(sizeof("Score")));
 strncpy(ppt->score_key,"Score",(sizeof("Score")));
 ppt->score_value=0;
 ppt->score_show=malloc((10*sizeof(char)+1));
 if(((void *)0)==ppt->score_show){
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,(scr_x-strlen(score_prompt))/2,"%s",score_prompt);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  nodelay(stdscr,0);
  wgetch(stdscr);
  nodelay(stdscr,1);
  return -1;
 }
 snprintf(ppt->score_show,(10*sizeof(char)+1),"%s%5d",ppt->score_key,ppt->score_value);
 memset(ppt->start,0,sizeof("BEGIN"));
 strncpy(ppt->start,"BEGIN",sizeof("BEGIN"));
 memset(ppt->pause,0,sizeof("PAUSE"));
 strncpy(ppt->pause,"PAUSE",sizeof("PAUSE"));
 memset(ppt->quit,0,sizeof("QUIT"));
 strncpy(ppt->quit,"QUIT",sizeof("QUIT"));
 memset(ppt->title,0,sizeof("Tetris"));
 strncpy(ppt->title,"Tetris",sizeof("Tetris"));
 return 0;
}

canonical_original_code:
static int init_prompt(struct prompt *prompt)
{
 struct prompt *ppt = prompt;
 char level_prompt[] = "Failed to allocate space for level_show";
 char lines_prompt[] = "Failed to allocate space for lines_show";
 char score_prompt[] = "Failed to allocate space for score_show";
 int scr_y; int scr_x;
 (scr_y = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), scr_x = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 if(((void *)0)==ppt){
  return -1;
 }
 if(((void *)0)!=ppt->level_show||((void *)0)!=ppt->lines_show||((void *)0)!=ppt->score_show){
  exit_prompt(ppt);
  ppt->level_show=((void *)0);
  ppt->lines_show=((void *)0);
  ppt->score_show=((void *)0);
 }
 memset(ppt->level_key,0,(sizeof("Level")));
 strncpy(ppt->level_key,"Level",(sizeof("Level")));
 ppt->level_value=0;
 ppt->level_show=malloc((10*sizeof(char)+1));
 if(((void *)0)==ppt->level_show){
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,(scr_x-strlen(level_prompt))/2,"%s",level_prompt);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  nodelay(stdscr,0);
  wgetch(stdscr);
  nodelay(stdscr,1);
  return -1;
 }
 snprintf(ppt->level_show,(10*sizeof(char)+1),"%s%5d",ppt->level_key,ppt->level_value);
 memset(ppt->lines_key,0,(sizeof("Lines")));
 strncpy(ppt->lines_key,"Lines",(sizeof("Lines")));
 ppt->lines_value=0;
 ppt->lines_show=malloc((10*sizeof(char)+1));
 if(((void *)0)==ppt->lines_show){
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,(scr_x-strlen(lines_prompt))/2,"%s",lines_prompt);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  nodelay(stdscr,0);
  wgetch(stdscr);
  nodelay(stdscr,1);
  return -1;
 }
 snprintf(ppt->lines_show,(10*sizeof(char)+1),"%s%5d",ppt->lines_key,ppt->lines_value);
 memset(ppt->score_key,0,(sizeof("Score")));
 strncpy(ppt->score_key,"Score",(sizeof("Score")));
 ppt->score_value=0;
 ppt->score_show=malloc((10*sizeof(char)+1));
 if(((void *)0)==ppt->score_show){
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,(scr_x-strlen(score_prompt))/2,"%s",score_prompt);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_ERROR_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));}
  nodelay(stdscr,0);
  wgetch(stdscr);
  nodelay(stdscr,1);
  return -1;
 }
 snprintf(ppt->score_show,(10*sizeof(char)+1),"%s%5d",ppt->score_key,ppt->score_value);
 memset(ppt->start,0,sizeof("BEGIN"));
 strncpy(ppt->start,"BEGIN",sizeof("BEGIN"));
 memset(ppt->pause,0,sizeof("PAUSE"));
 strncpy(ppt->pause,"PAUSE",sizeof("PAUSE"));
 memset(ppt->quit,0,sizeof("QUIT"));
 strncpy(ppt->quit,"QUIT",sizeof("QUIT"));
 memset(ppt->title,0,sizeof("Tetris"));
 strncpy(ppt->title,"Tetris",sizeof("Tetris"));
 return 0;
}

user_defined_types: struct prompt { char level_key[-1]; int level_value; char *level_show; char lines_key[-1]; int lines_value; char *lines_show; char score_key[-1]; int score_value; char *score_show; char start[-1]; char pause[-1]; char quit[-1]; char title[-1]; }


decompiled_code:
void __fastcall open_colors(int a1)
{
switch ( a1 )
{
case 0:
if ( has_colors() )
wattr_on(stdscr, 0x200100uLL, 0LL);
break;
case 1:
if ( has_colors() )
wattr_on(stdscr, 0x200200uLL, 0LL);
break;
case 2:
if ( has_colors() )
wattr_on(stdscr, 0x200300uLL, 0LL);
break;
case 3:
if ( has_colors() )
wattr_on(stdscr, 0x200400uLL, 0LL);
break;
case 4:
if ( has_colors() )
wattr_on(stdscr, 0x200500uLL, 0LL);
break;
case 5:
if ( has_colors() )
wattr_on(stdscr, 0x200600uLL, 0LL);
break;
case 6:
if ( has_colors() )
wattr_on(stdscr, 0x200700uLL, 0LL);
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
switch ( a1 )
{
case 0:
if ( has_colors() )
wattr_on(stdscr, 0x200100uLL, 0LL);
break;
case 1:
if ( has_colors() )
wattr_on(stdscr, 0x200200uLL, 0LL);
break;
case 2:
if ( has_colors() )
wattr_on(stdscr, 0x200300uLL, 0LL);
break;
case 3:
if ( has_colors() )
wattr_on(stdscr, 0x200400uLL, 0LL);
break;
case 4:
if ( has_colors() )
wattr_on(stdscr, 0x200500uLL, 0LL);
break;
case 5:
if ( has_colors() )
wattr_on(stdscr, 0x200600uLL, 0LL);
break;
case 6:
if ( has_colors() )
wattr_on(stdscr, 0x200700uLL, 0LL);
break;
default:
return;
}
}

variable_types: enum block_type { BLOCK_I=0, BLOCK_J=1, BLOCK_L=2, BLOCK_O=3, BLOCK_S=4, BLOCK_Z=5, BLOCK_T=6, BLOCK_TYPE_NONE=7 }


decompiled_code:
void __fastcall close_colors(int a1)
{
switch ( a1 )
{
case 0:
if ( has_colors() )
wattr_off(stdscr, 0x200100uLL, 0LL);
break;
case 1:
if ( has_colors() )
wattr_off(stdscr, 0x200200uLL, 0LL);
break;
case 2:
if ( has_colors() )
wattr_off(stdscr, 0x200300uLL, 0LL);
break;
case 3:
if ( has_colors() )
wattr_off(stdscr, 0x200400uLL, 0LL);
break;
case 4:
if ( has_colors() )
wattr_off(stdscr, 0x200500uLL, 0LL);
break;
case 5:
if ( has_colors() )
wattr_off(stdscr, 0x200600uLL, 0LL);
break;
case 6:
if ( has_colors() )
wattr_off(stdscr, 0x200700uLL, 0LL);
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
switch ( a1 )
{
case 0:
if ( has_colors() )
wattr_off(stdscr, 0x200100uLL, 0LL);
break;
case 1:
if ( has_colors() )
wattr_off(stdscr, 0x200200uLL, 0LL);
break;
case 2:
if ( has_colors() )
wattr_off(stdscr, 0x200300uLL, 0LL);
break;
case 3:
if ( has_colors() )
wattr_off(stdscr, 0x200400uLL, 0LL);
break;
case 4:
if ( has_colors() )
wattr_off(stdscr, 0x200500uLL, 0LL);
break;
case 5:
if ( has_colors() )
wattr_off(stdscr, 0x200600uLL, 0LL);
break;
case 6:
if ( has_colors() )
wattr_off(stdscr, 0x200700uLL, 0LL);
break;
default:
return;
}
}

user_defined_types: enum block_type { BLOCK_I=0, BLOCK_J=1, BLOCK_L=2, BLOCK_O=3, BLOCK_S=4, BLOCK_Z=5, BLOCK_T=6, BLOCK_TYPE_NONE=7 }


decompiled_code:
int draw_confirm_exit()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // er12
size_t v3; // rax
int v4; // edx
size_t v5; // rax
bool v6; // cf
size_t v7; // rax
int v8; // edx
unsigned __int64 v9; // rbx
__m128i v11; // [rsp+0h] [rbp-88h] BYREF
char v12[16]; // [rsp+10h] [rbp-78h] BYREF
char s[16]; // [rsp+20h] [rbp-68h] BYREF
__m128i v14; // [rsp+30h] [rbp-58h]
__m128i v15; // [rsp+40h] [rbp-48h]
char v16[16]; // [rsp+50h] [rbp-38h] BYREF

strcpy(v16, "program,");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC2);
strcpy(v12, " to continue!");
v14 = _mm_load_si128((const __m128i *)&LC3);
v15 = _mm_load_si128((const __m128i *)&LC4);
v11 = _mm_load_si128((const __m128i *)&LC5);
if ( stdscr )
{
v0 = stdscr->_maxx + 1;
v1 = (stdscr->_maxy + 1) / 2;
v2 = v1 + 1;
if ( !has_colors() )
goto LABEL_3;
goto LABEL_13;
}
if ( has_colors() )
{
v2 = 1;
v1 = 0;
v0 = -1LL;
LABEL_13:
wattr_on(stdscr, 0x200A00uLL, 0LL);
LABEL_3:
v3 = strlen(s);
v4 = 1;
v6 = v0 == v3;
v5 = v0 - v3;
if ( v6 || v5 == 1 )
goto LABEL_4;
goto LABEL_11;
}
v2 = 1;
v1 = 0;
v0 = -1LL;
v5 = ~strlen(s);
LABEL_11:
v4 = v5 >> 1;
LABEL_4:
mvwprintw(stdscr, v1, v4, "%s", s);
v7 = strlen(v11.m128i_i8);
v8 = 1;
v9 = v0 - v7;
if ( v9 > 1 )
v8 = v9 >> 1;
mvwprintw(stdscr, v2, v8, "%s", &v11);
if ( has_colors() )
wattr_off(stdscr, 0x200A00uLL, 0LL);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func9()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // er12
size_t v3; // rax
int v4; // edx
size_t v5; // rax
bool v6; // cf
size_t v7; // rax
int v8; // edx
unsigned __int64 v9; // rbx
__m128i v11; // [rsp+0h] [rbp-88h] BYREF
char v12[16]; // [rsp+10h] [rbp-78h] BYREF
char s[16]; // [rsp+20h] [rbp-68h] BYREF
__m128i v14; // [rsp+30h] [rbp-58h]
__m128i v15; // [rsp+40h] [rbp-48h]
char v16[16]; // [rsp+50h] [rbp-38h] BYREF

strcpy(v16, "program,");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC2);
strcpy(v12, " to continue!");
v14 = _mm_load_si128((const __m128i *)&LC3);
v15 = _mm_load_si128((const __m128i *)&LC4);
v11 = _mm_load_si128((const __m128i *)&LC5);
if ( stdscr )
{
v0 = stdscr->_maxx + 1;
v1 = (stdscr->_maxy + 1) / 2;
v2 = v1 + 1;
if ( !has_colors() )
goto LABEL_3;
goto LABEL_13;
}
if ( has_colors() )
{
v2 = 1;
v1 = 0;
v0 = -1LL;
LABEL_13:
wattr_on(stdscr, 0x200A00uLL, 0LL);
LABEL_3:
v3 = strlen(s);
v4 = 1;
v6 = v0 == v3;
v5 = v0 - v3;
if ( v6 || v5 == 1 )
goto LABEL_4;
goto LABEL_11;
}
v2 = 1;
v1 = 0;
v0 = -1LL;
v5 = ~strlen(s);
LABEL_11:
v4 = v5 >> 1;
LABEL_4:
mvwprintw(stdscr, v1, v4, "%s", s);
v7 = strlen(v11.m128i_i8);
v8 = 1;
v9 = v0 - v7;
if ( v9 > 1 )
v8 = v9 >> 1;
mvwprintw(stdscr, v2, v8, "%s", &v11);
if ( has_colors() )
wattr_off(stdscr, 0x200A00uLL, 0LL);
return wrefresh(stdscr);
}

original_code:
void draw_confirm_exit()
{
  char confirm_quit[]="Please press key 'y' or 'Y' to confirm exit the program,";
  char confirm_continue[]="press others key to continue!";
  int scr_y,scr_x;
  (scr_y = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), scr_x = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,((scr_x-strlen(confirm_quit))/2>0)?((scr_x-strlen(confirm_quit))/2):(1),"%s",confirm_quit);
  mvwprintw(stdscr,scr_y/2+1,((scr_x-strlen(confirm_continue))/2>0)?((scr_x-strlen(confirm_continue))/2):(1),"%s",confirm_continue);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  wrefresh(stdscr);
}

canonical_original_code:
void draw_confirm_exit()
{
  char confirm_quit[] = "Please press key 'y' or 'Y' to confirm exit the program,";
  char confirm_continue[] = "press others key to continue!";
  int scr_y; int scr_x;
  (scr_y = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), scr_x = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  mvwprintw(stdscr,scr_y/2,((scr_x-strlen(confirm_quit))/2>0)?((scr_x-strlen(confirm_quit))/2):(1),"%s",confirm_quit);
  mvwprintw(stdscr,scr_y/2+1,((scr_x-strlen(confirm_continue))/2>0)?((scr_x-strlen(confirm_continue))/2):(1),"%s",confirm_continue);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  wrefresh(stdscr);
}


original_code:
void draw_help_info()
{
 char ttrs_title[]="Tetris help";
 char ttrs_rotate[]="Rotate:[W] [w] [I] [i] [Arrow keys UP] ";
 char ttrs_right[] ="Right :[D] [d] [L] [l] [Arrow keys Right]";
 char ttrs_down[] ="Down  :[S] [s] [K] [k] [Arrow keys Down]";
 char ttrs_left[] ="Left  :[A] [a] [J] [j] [Arrow keys Left]";
 char ttrs_begin[] ="begin :[B] [b]";
 char ttrs_pause[] ="Pause :[P] [p] [Spacebar]";
 char ttrs_quit[] ="Quit  :[Q] [q] [Esc]";
 char ttrs_help[] ="Help  :[H] [h]";
 char ttrs_continue[]="Press any key or click mouse to continue!";
 int y=0;
 int x=1;
 int scr_y;
 int scr_x;
 int ch=(-1);
 nodelay(stdscr,1);
 werase(stdscr);
 while(ch==(-1)){
  y=0;
  (scr_y = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), scr_x = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  wclear(stdscr);
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  mvwprintw(stdscr,++y,(scr_x-strlen(ttrs_title))/2,"%s",ttrs_title);
  y++;
  mvwprintw(stdscr,++y,x,"%s",ttrs_rotate);
  mvwprintw(stdscr,++y,x,"%s",ttrs_right);
  mvwprintw(stdscr,++y,x,"%s",ttrs_down);
  mvwprintw(stdscr,++y,x,"%s",ttrs_left);
  mvwprintw(stdscr,++y,x,"%s",ttrs_begin);
  mvwprintw(stdscr,++y,x,"%s",ttrs_pause);
  mvwprintw(stdscr,++y,x,"%s",ttrs_quit);
  mvwprintw(stdscr,++y,x,"%s",ttrs_help);
  wborder(stdscr, 0, 0, 0, 0, 0, 0, 0, 0);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  y++;
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_BUTTON))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  mvwprintw(stdscr,((scr_y/2)>y)?(scr_y/2):(y),(scr_x-strlen(ttrs_continue))/2,"%s",ttrs_continue);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_BUTTON))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  ch=wgetch(stdscr);
  wrefresh(stdscr);
  usleep(100000*2);
 }
 return;
}

canonical_original_code:
void draw_help_info()
{
 char ttrs_title[] = "Tetris help";
 char ttrs_rotate[] = "Rotate:[W] [w] [I] [i] [Arrow keys UP] ";
 char ttrs_right[] = "Right :[D] [d] [L] [l] [Arrow keys Right]";
 char ttrs_down[] = "Down  :[S] [s] [K] [k] [Arrow keys Down]";
 char ttrs_left[] = "Left  :[A] [a] [J] [j] [Arrow keys Left]";
 char ttrs_begin[] = "begin :[B] [b]";
 char ttrs_pause[] = "Pause :[P] [p] [Spacebar]";
 char ttrs_quit[] = "Quit  :[Q] [q] [Esc]";
 char ttrs_help[] = "Help  :[H] [h]";
 char ttrs_continue[] = "Press any key or click mouse to continue!";
 int y = 0;
 int x = 1;
 int scr_y;
 int scr_x;
 int ch = (-1);
 nodelay(stdscr,1);
 werase(stdscr);
 while(ch==(-1)){
  y=0;
  (scr_y = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), scr_x = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  wclear(stdscr);
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  mvwprintw(stdscr,++y,(scr_x-strlen(ttrs_title))/2,"%s",ttrs_title);
  y++;
  mvwprintw(stdscr,++y,x,"%s",ttrs_rotate);
  mvwprintw(stdscr,++y,x,"%s",ttrs_right);
  mvwprintw(stdscr,++y,x,"%s",ttrs_down);
  mvwprintw(stdscr,++y,x,"%s",ttrs_left);
  mvwprintw(stdscr,++y,x,"%s",ttrs_begin);
  mvwprintw(stdscr,++y,x,"%s",ttrs_pause);
  mvwprintw(stdscr,++y,x,"%s",ttrs_quit);
  mvwprintw(stdscr,++y,x,"%s",ttrs_help);
  wborder(stdscr, 0, 0, 0, 0, 0, 0, 0, 0);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_NORMAL_PROMPT))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  y++;
  if(has_colors()){wattr_on(stdscr, (attr_t)(((((chtype)(((COLOR_BUTTON))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  mvwprintw(stdscr,((scr_y/2)>y)?(scr_y/2):(y),(scr_x-strlen(ttrs_continue))/2,"%s",ttrs_continue);
  if(has_colors()){wattr_off(stdscr, (attr_t)(((((chtype)(((COLOR_BUTTON))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))|((chtype)((1U)) << ((13) + 8)))), ((void *)0));}
  ch=wgetch(stdscr);
  wrefresh(stdscr);
  usleep(100000*2);
 }
 return;
}

variable_types: ch int


main

repo: haneefmubarak/snippets

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
unsigned int v4; // esi

for ( i = 310; i != 1114422; i += 17 )
{
v4 = i;
printf("%u\n", v4 % 0xB);
}
return 0;
}

variable_types:
x
unsigned int


usage

decompiled_code:
void __noreturn usage()
{
const char *v0; // [rsp+0h] [rbp-10h]

fprintf(
stderr,
"set the environment variable %s to a valid destination.\n"
"\n"
"examples:\n"
"\ttcp mode:\n"
"\t\t%s %s=tcp:wii\n"
"\t\t%s %s=tcp:192.168.0.30\n"
"\n"
"usage:\n"
"\t%s <filename> <application arguments>\n"
"\n",
"PS3LOAD",
"export",
"PS3LOAD",
"export",
"PS3LOAD",
v0);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
const char *v0; // [rsp+0h] [rbp-10h]

fprintf(
stderr,
"set the environment variable %s to a valid destination.\n"
"\n"
"examples:\n"
"\ttcp mode:\n"
"\t\t%s %s=tcp:wii\n"
"\t\t%s %s=tcp:192.168.0.30\n"
"\n"
"usage:\n"
"\t%s <filename> <application arguments>\n"
"\n",
"PS3LOAD",
"export",
"PS3LOAD",
"export",
"PS3LOAD",
v0);
exit(1);
}

original_code:
static void usage (const char *argv0) {
 fprintf (stderr, "set the environment variable %s to a valid "
    "destination.\n\n"
    "examples:\n"
    "\ttcp mode:\n"
    "\t\t%s %s=tcp:wii\n"
    "\t\t%s %s=tcp:192.168.0.30\n\n"
    "usage:\n"
    "\t%s <filename> <application arguments>\n\n",
    envvar,
    desc_export, envvar,
    desc_export, envvar,
    argv0);
 exit (1);
}

canonical_original_code:
static void usage(char *argv0) {
 fprintf (stderr, "set the environment variable %s to a valid "
    "destination.\n\n"
    "examples:\n"
    "\ttcp mode:\n"
    "\t\t%s %s=tcp:wii\n"
    "\t\t%s %s=tcp:192.168.0.30\n\n"
    "usage:\n"
    "\t%s <filename> <application arguments>\n\n",
    envvar,
    desc_export, envvar,
    desc_export, envvar,
    argv0);
 exit (1);
}


repo: hanmouse/test

decompiled_code:
__int64 __fastcall init_queue(_QWORD *a1, __int64 a2)
{
void *v2; // rax
int *v4; // rbp
char *v5; // rax

*a1 = a2 + 1;
a1[1] = 0LL;
v2 = calloc(a2 + 1, 0x40uLL);
a1[2] = v2;
if ( v2 )
return 0LL;
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "calloc() failed: size=%zu, E=%d[ %s ]\n", *a1 << 6, (unsigned int)*v4, v5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
void *v2; // rax
int *v4; // rbp
char *v5; // rax

*a1 = a2 + 1;
a1[1] = 0LL;
v2 = calloc(a2 + 1, 0x40uLL);
a1[2] = v2;
if ( v2 )
return 0LL;
v4 = _errno_location();
v5 = strerror(*v4);
fprintf(stderr, "calloc() failed: size=%zu, E=%d[ %s ]\n", *a1 << 6, (unsigned int)*v4, v5);
return 0xFFFFFFFFLL;
}

original_code:
int init_queue( queue_t *queue, size_t size)
{
 queue->size = size + 1;
 queue->front = queue->rear = 0;
 queue->data = calloc( queue->size, 64);
 if (queue->data == ((void *)0)) {
  fprintf( stderr, "calloc() failed: size=%zu, E=%d[ %s ]\n", queue->size * 64, (*__errno_location ()), strerror( (*__errno_location ())));
  return -1;
 }
 return 0;
}

canonical_original_code:
int init_queue(struct queue_s *queue, unsigned long size)
{
 queue->size = size + 1;
 queue->front = queue->rear = 0;
 queue->data = calloc( queue->size, 64);
 if (queue->data == ((void *)0)) {
  fprintf( stderr, "calloc() failed: size=%zu, E=%d[ %s ]\n", queue->size * 64, (*__errno_location ()), strerror( (*__errno_location ())));
  return -1;
 }
 return 0;
}

variable_types: struct queue_s { unsigned long size; int front; int rear; unsigned char *data; unsigned long data_size[128]; } *

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall insert_queue_data(__int64 a1, __int64 a2, size_t a3)
{
int v4; // ecx
const void *v5; // r8
unsigned int v6; // er13
int v7; // eax

if ( queue_is_full_isra_0(*(_QWORD *)a1, *(_DWORD *)(a1 + 8), *(_DWORD *)(a1 + 12)) )
{
v6 = -1;
fwrite("queue is full\n", 1uLL, 0xEuLL, stderr);
}
else if ( a3 > 0x40 )
{
v6 = -1;
fprintf(stderr, "data is too big: data_size=%zu, max_size=%zu\n", a3, 0x40uLL);
}
else
{
v6 = 0;
memcpy((void *)(*(_QWORD *)(a1 + 16) + (v4 << 6)), v5, a3);
v7 = *(_DWORD *)(a1 + 12);
*(_QWORD *)(a1 + 8LL * v7 + 24) = a3;
*(_DWORD *)(a1 + 12) = (unsigned __int64)(v7 + 1) % *(_QWORD *)a1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, size_t a3)
{
int v4; // ecx
const void *v5; // r8
unsigned int v6; // er13
int v7; // eax

if ( func1(*(_QWORD *)a1, *(_DWORD *)(a1 + 8), *(_DWORD *)(a1 + 12)) )
{
v6 = -1;
fwrite("queue is full\n", 1uLL, 0xEuLL, stderr);
}
else if ( a3 > 0x40 )
{
v6 = -1;
fprintf(stderr, "data is too big: data_size=%zu, max_size=%zu\n", a3, 0x40uLL);
}
else
{
v6 = 0;
memcpy((void *)(*(_QWORD *)(a1 + 16) + (v4 << 6)), v5, a3);
v7 = *(_DWORD *)(a1 + 12);
*(_QWORD *)(a1 + 8LL * v7 + 24) = a3;
*(_DWORD *)(a1 + 12) = (unsigned __int64)(v7 + 1) % *(_QWORD *)a1;
}
return v6;
}

original_code:
int insert_queue_data( queue_t *queue, const unsigned char *data, size_t data_size)
{
 if (queue_is_full( queue)) {
  fprintf( stderr, "queue is full\n");
  return -1;
 }
 if (data_size > 64) {
  fprintf( stderr, "data is too big: data_size=%zu, max_size=%zu\n", data_size, 64);
  return -1;
 }
 memcpy( &queue->data[queue->rear * 64], data, data_size);
 queue->data_size[queue->rear] = data_size;
 queue->rear = (queue->rear + 1) % queue->size;
 return 0;
}

canonical_original_code:
int insert_queue_data(struct queue_s *queue, unsigned char *data, unsigned long data_size)
{
 if (queue_is_full( queue)) {
  fprintf( stderr, "queue is full\n");
  return -1;
 }
 if (data_size > 64) {
  fprintf( stderr, "data is too big: data_size=%zu, max_size=%zu\n", data_size, 64);
  return -1;
 }
 memcpy( &queue->data[queue->rear * 64], data, data_size);
 queue->data_size[queue->rear] = data_size;
 queue->rear = (queue->rear + 1) % queue->size;
 return 0;
}

variable_types:
data
unsigned char *

user_defined_types: struct queue_s { unsigned long size; int front; int rear; unsigned char *data; unsigned long data_size[128]; }


original_code:
int get_queue_data( queue_t *queue, unsigned char *data, size_t *data_size)
{
 *data_size = 0;
 if (queue_is_empty( queue)) {
  return 0;
 }
 memcpy( data, &queue->data[queue->front * 64], queue->data_size[queue->front]);
 *data_size = queue->data_size[queue->front];
 queue->front = (queue->front + 1) % queue->size;
 return 0;
}

canonical_original_code:
int get_queue_data(struct queue_s *queue, unsigned char *data, unsigned long *data_size)
{
 *data_size = 0;
 if (queue_is_empty( queue)) {
  return 0;
 }
 memcpy( data, &queue->data[queue->front * 64], queue->data_size[queue->front]);
 *data_size = queue->data_size[queue->front];
 queue->front = (queue->front + 1) % queue->size;
 return 0;
}


decompiled_code:
void clear_buffer()
{
buffer = 0LL;
xmmword_404070 = 0LL;
xmmword_404080 = 0LL;
xmmword_404090 = 0LL;
}

canonical_decompiled_code:
void func7()
{
buffer = 0LL;
xmmword_404070 = 0LL;
xmmword_404080 = 0LL;
xmmword_404090 = 0LL;
}

original_code:
void clear_buffer( void)
{
 memset( buffer, 0, sizeof( buffer));
}

canonical_original_code:
void clear_buffer()
{
 memset( buffer, 0, sizeof( buffer));
}


next

decompiled_code:
__int64 __fastcall next(char a1)
{
return (a1 + 1) & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return (a1 + 1) & 0xF;
}

original_code:
int next( int current)
{
 return (current + 1) & (16 - 1);
}

canonical_original_code:
int next(int current)
{
 return (current + 1) & (16 - 1);
}

variable_types: current int


decompiled_code:
__int64 add_to_buffer()
{
int v0; // edx
__int64 result; // rax

while ( *((_DWORD *)&buffer + (int)next(add_here)) )
;
*((_DWORD *)&buffer + add_here) = v0;
result = next(add_here);
add_here = result;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // edx
__int64 result; // rax

while ( *((_DWORD *)&buffer + (int)func8(add_here)) )
;
*((_DWORD *)&buffer + add_here) = v0;
result = func8(add_here);
add_here = result;
return result;
}

original_code:
void add_to_buffer( int value)
{
 while (buffer[next( add_here)]) {}
 buffer[add_here] = value;
 add_here = next( add_here);
}

canonical_original_code:
void add_to_buffer(int value)
{
 while (buffer[next( add_here)]) {}
 buffer[add_here] = value;
 add_here = next( add_here);
}

variable_types: value int


decompiled_code:
__int64 remove_from_buffer()
{
while ( !*((_DWORD *)&buffer + remove_here) )
;
*((_DWORD *)&buffer + remove_here) = 0;
remove_here = next(remove_here);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
while ( !*((_DWORD *)&buffer + remove_here) )
;
*((_DWORD *)&buffer + remove_here) = 0;
remove_here = func8(remove_here);
return 0LL;
}

original_code:
int remove_from_buffer( void)
{
 int value;
 while (value = buffer[remove_here] == 0) {}
 buffer[remove_here] = 0;
 remove_here = next( remove_here);
 return value;
}

canonical_original_code:
int remove_from_buffer()
{
 int value;
 while (value = buffer[remove_here] == 0) {}
 buffer[remove_here] = 0;
 remove_here = next( remove_here);
 return value;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *(*v3)(void *); // rdx
void *v4; // rcx
pthread_t v6; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

clear_buffer(argc, 0LL, producer, 0LL);
pthread_create(&v6, 0LL, v3, v4);
pthread_create(newthread, 0LL, consumer, 0LL);
pthread_join((pthread_t)&v6, 0LL);
pthread_join((pthread_t)newthread, 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *(*v3)(void *); // rdx
void *v4; // rcx
pthread_t v6; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

func7(argc, 0LL, producer, 0LL);
pthread_create(&v6, 0LL, v3, v4);
pthread_create(newthread, 0LL, consumer, 0LL);
pthread_join((pthread_t)&v6, 0LL);
pthread_join((pthread_t)newthread, 0LL);
return 0;
}

original_code:
int main( int argc, char **argv)
{
 pthread_t threads[2];
 clear_buffer();
 pthread_create( &threads[0], ((void *)0), producer, 0);
 pthread_create( &threads[1], ((void *)0), consumer, 0);
 pthread_join( &threads[0], ((void *)0));
 pthread_join( &threads[1], ((void *)0));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned long threads[2];
 clear_buffer();
 pthread_create( &threads[0], ((void *)0), producer, 0);
 pthread_create( &threads[1], ((void *)0), consumer, 0);
 pthread_join( &threads[0], ((void *)0));
 pthread_join( &threads[1], ((void *)0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
threads
unsigned long [2]


producer

decompiled_code:
__int64 __fastcall producer(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int i; // ecx
__int64 result; // rax

for ( i = 1; i != 10000000; result = add_to_buffer(i, a2, a3, i + 1) )
;
return result;
}

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

for ( i = 1; i != 10000000; result = func9(i, a2, a3, i + 1) )
;
return result;
}

original_code:
void *producer( void *param)
{
 int i;
 for (i = 1; i < 10000000; i++) {
  add_to_buffer( i);
 }
}

canonical_original_code:
void *producer(void *param)
{
 int i;
 for (i = 1; i < 10000000; i++) {
  add_to_buffer( i);
 }
}

variable_types:
param
void *

variable_types: i int

return_type: void *


consumer

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

do
result = (void *)remove_from_buffer(a1);
while ( (_DWORD)result != 9999999 );
return result;
}

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

do
result = (void *)func11(a1);
while ( (_DWORD)result != 9999999 );
return result;
}

original_code:
void *consumer( void *param)
{
 while (remove_from_buffer() != 9999999) {}
}

canonical_original_code:
void *consumer(void *param)
{
 while (remove_from_buffer() != 9999999) {}
}


decompiled_code:
void *__fastcall count_func(void *a1)
{
int v1; // ebx
__int64 v2; // rcx

v1 = 10;
do
{
v2 = __readfsdword(0xFFFFFFFC) + 1;
__writefsdword(0xFFFFFFFC, v2);
fprintf(stderr, "[thread %d] count=%d\n", (unsigned int)a1, v2);
usleep(0x3E8u);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebx
__int64 v2; // rcx

v1 = 10;
do
{
v2 = __readfsdword(0xFFFFFFFC) + 1;
__writefsdword(0xFFFFFFFC, v2);
fprintf(stderr, "[thread %d] count=%d\n", (unsigned int)a1, v2);
usleep(0x3E8u);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *count_func( void *param)
{
 int thread_id = (int) param;
 int i;
 for (i = 0; i < 10; i++) {
  count++;
  fprintf( stderr, "[thread %d] count=%d\n", thread_id, count);
  usleep( 1000);
 }
 return ((void *)0);
}

canonical_original_code:
void *count_func(void *param)
{
 int thread_id = (int) param;
 int i;
 for (i = 0; i < 10; i++) {
  count++;
  fprintf( stderr, "[thread %d] count=%d\n", thread_id, count);
  usleep( 1000);
 }
 return ((void *)0);
}


main

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

v3 = 0LL;
v4 = (__int64 *)v8;
v5 = (pthread_t *)v8;
do
pthread_create(v5++, 0LL, count_func, v3++);
while ( v3 != (char *)10 );
do
{
v6 = (pthread_t)v4++;
pthread_join(v6, 0LL);
}
while ( v4 != &v9 );
return 0;
}

original_code:
int main( int argc, char **argv)
{
 int i;
 pthread_t threads[10];
 for (i = 0; i < 10; i++) {
  pthread_create( &threads[i], ((void *)0), count_func, (void *) i);
 }
 for (i = 0; i < 10; i++) {
  pthread_join( &threads[i], ((void *)0));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 unsigned long threads[10];
 for (i = 0; i < 10; i++) {
  pthread_create( &threads[i], ((void *)0), count_func, (void *) i);
 }
 for (i = 0; i < 10; i++) {
  pthread_join( &threads[i], ((void *)0));
 }
 return 0;
}

variable_types:
threads
unsigned long [10]


count

decompiled_code:
__int64 __fastcall count(void *a1)
{
int v1; // ebx
int v2; // eax
unsigned int v3; // er13
int v4; // eax
int v5; // eax
unsigned int v6; // er13
int v7; // eax
unsigned int v8; // er13
char *v9; // rax
char *v11; // rax
char *v12; // rax
struct timeval v13; // [rsp+0h] [rbp-38h] BYREF

v1 = 10;
while ( 1 )
{
while ( 1 )
{
v7 = gettimeofday(&v13, 0LL);
v8 = v7;
if ( v7 >= 0 )
break;
v9 = strerror(v7);
fprintf(stderr, "gettimeofday() failed: E=%d[ %s ]\n", v8, v9);
if ( !--v1 )
return (int)a1;
}
v2 = pthread_mutex_lock(&mutex);
v3 = v2;
if ( v2 )
{
v11 = strerror(v2);
fprintf(stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", v3, v11);
return (int)a1;
}
printf("[thread %d] number=%d\n", (unsigned int)a1, (unsigned int)++number);
v4 = rand_r((unsigned int *)&v13.tv_usec);
usleep(v4 % 10000);
v5 = pthread_mutex_unlock(&mutex);
v6 = v5;
if ( v5 )
break;
if ( !--v1 )
return (int)a1;
}
v12 = strerror(v5);
fprintf(stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", v6, v12);
return (int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *a1)
{
int v1; // ebx
int v2; // eax
unsigned int v3; // er13
int v4; // eax
int v5; // eax
unsigned int v6; // er13
int v7; // eax
unsigned int v8; // er13
char *v9; // rax
char *v11; // rax
char *v12; // rax
struct timeval v13; // [rsp+0h] [rbp-38h] BYREF

v1 = 10;
while ( 1 )
{
while ( 1 )
{
v7 = gettimeofday(&v13, 0LL);
v8 = v7;
if ( v7 >= 0 )
break;
v9 = strerror(v7);
fprintf(stderr, "gettimeofday() failed: E=%d[ %s ]\n", v8, v9);
if ( !--v1 )
return (int)a1;
}
v2 = pthread_mutex_lock(&mutex);
v3 = v2;
if ( v2 )
{
v11 = strerror(v2);
fprintf(stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", v3, v11);
return (int)a1;
}
printf("[thread %d] number=%d\n", (unsigned int)a1, (unsigned int)++number);
v4 = rand_r((unsigned int *)&v13.tv_usec);
usleep(v4 % 10000);
v5 = pthread_mutex_unlock(&mutex);
v6 = v5;
if ( v5 )
break;
if ( !--v1 )
return (int)a1;
}
v12 = strerror(v5);
fprintf(stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", v6, v12);
return (int)a1;
}

original_code:
void *count( void *param)
{
 int i;
 int id = (int) param;
 int e;
 struct timeval tv;
 useconds_t usleep_time;
 for (i = 0; i < 10; i++) {
  e = gettimeofday( &tv, ((void *)0));
  if (e < 0) {
   fprintf( stderr, "gettimeofday() failed: E=%d[ %s ]\n", e, strerror( e));
   continue;
  }
  e = pthread_mutex_lock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
  number++;
  printf( "[thread %d] number=%d\n", id, number);
  usleep_time = rand_r( &tv.tv_usec) % 10000;
  usleep( usleep_time);
  e = pthread_mutex_unlock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
 }
 return (void *) id;
}

canonical_original_code:
void *count(void *param)
{
 int i;
 int id = (int) param;
 int e;
 struct timeval tv;
 unsigned int usleep_time;
 for (i = 0; i < 10; i++) {
  e = gettimeofday( &tv, ((void *)0));
  if (e < 0) {
   fprintf( stderr, "gettimeofday() failed: E=%d[ %s ]\n", e, strerror( e));
   continue;
  }
  e = pthread_mutex_lock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
  number++;
  printf( "[thread %d] number=%d\n", id, number);
  usleep_time = rand_r( &tv.tv_usec) % 10000;
  usleep( usleep_time);
  e = pthread_mutex_unlock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
 }
 return (void *) id;
}

variable_types: id int

variable_types: e int

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


main

repo: haosdent/sniffer

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // er12
int v5; // ebx
int v6; // er13
__int16 v7; // r14
__int16 v8; // r15
__int64 v9; // rax
__int64 *v10; // rdx
_DWORD *v11; // rax
__int64 v12[2]; // [rsp+0h] [rbp-8E8h] BYREF
struct sigaction v13; // [rsp+10h] [rbp-8D8h] BYREF
__int128 buf; // [rsp+B0h] [rbp-838h] BYREF
char v15[2088]; // [rsp+C0h] [rbp-828h] BYREF

puts("Use Ctrl + C to kill this program. The results would be written to result.txt.");
sigemptyset(&v13.sa_mask);
v13.sa_handler = (__sighandler_t)break_handler;
v13.sa_flags = 0;
sigaction(2, &v13, 0LL);
sigaction(15, &v13, 0LL);
sigaction(3, &v13, 0LL);
v12[0] = (__int64)v12;
memset(v15, 0, 0x7F0uLL);
buf = 0LL;
v12[1] = (__int64)v12;
record_list = (__int64)v12;
v3 = _bswap_16_constprop_0(17LL, 3LL);
v4 = socket(17, 3, v3);
while ( 1 )
{
while ( 1 )
{
if ( (int)recvfrom(v4, &buf, 0x800uLL, 0, 0LL, 0LL) <= 41 )
{
printf("Incomplete packet");
close(v4);
exit(0);
}
v5 = convert_ip(&v15[10], 0.0);
v6 = convert_ip(&v15[14], 0.0);
v7 = (unsigned __int8)v15[19] + ((unsigned __int8)v15[18] << 8);
v8 = (unsigned __int8)v15[21] + ((unsigned __int8)v15[20] << 8);
v9 = v12[0] - 24;
if ( v12 != (__int64 *)v12[0] )
break;
LABEL_11:
v11 = malloc(0x28uLL);
*v11 = v5;
v11[2] = v6;
*((_WORD *)v11 + 2) = v7;
*((_WORD *)v11 + 6) = v8;
v11[4] = 1;
list_add((_QWORD *)v11 + 3, v12);
}
while ( *(_DWORD *)v9 != v5 || *(_DWORD *)(v9 + 8) != v6 || *(_WORD *)(v9 + 4) != v7 || *(_WORD *)(v9 + 12) != v8 )
{
v10 = *(__int64 **)(v9 + 24);
v9 = (__int64)(v10 - 3);
if ( v12 == v10 )
goto LABEL_11;
}
++*(_DWORD *)(v9 + 16);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // er12
int v5; // ebx
int v6; // er13
__int16 v7; // r14
__int16 v8; // r15
__int64 v9; // rax
__int64 *v10; // rdx
_DWORD *v11; // rax
__int64 v12[2]; // [rsp+0h] [rbp-8E8h] BYREF
struct sigaction v13; // [rsp+10h] [rbp-8D8h] BYREF
__int128 buf; // [rsp+B0h] [rbp-838h] BYREF
char v15[2088]; // [rsp+C0h] [rbp-828h] BYREF

puts("Use Ctrl + C to kill this program. The results would be written to result.txt.");
sigemptyset(&v13.sa_mask);
v13.sa_handler = (__sighandler_t)break_handler;
v13.sa_flags = 0;
sigaction(2, &v13, 0LL);
sigaction(15, &v13, 0LL);
sigaction(3, &v13, 0LL);
v12[0] = (__int64)v12;
memset(v15, 0, 0x7F0uLL);
buf = 0LL;
v12[1] = (__int64)v12;
record_list = (__int64)v12;
v3 = func3(17LL, 3LL);
v4 = socket(17, 3, v3);
while ( 1 )
{
while ( 1 )
{
if ( (int)recvfrom(v4, &buf, 0x800uLL, 0, 0LL, 0LL) <= 41 )
{
printf("Incomplete packet");
close(v4);
exit(0);
}
v5 = convert_ip(&v15[10], 0.0);
v6 = convert_ip(&v15[14], 0.0);
v7 = (unsigned __int8)v15[19] + ((unsigned __int8)v15[18] << 8);
v8 = (unsigned __int8)v15[21] + ((unsigned __int8)v15[20] << 8);
v9 = v12[0] - 24;
if ( v12 != (__int64 *)v12[0] )
break;
LABEL_11:
v11 = malloc(0x28uLL);
*v11 = v5;
v11[2] = v6;
*((_WORD *)v11 + 2) = v7;
*((_WORD *)v11 + 6) = v8;
v11[4] = 1;
func1((_QWORD *)v11 + 3, v12);
}
while ( *(_DWORD *)v9 != v5 || *(_DWORD *)(v9 + 8) != v6 || *(_WORD *)(v9 + 4) != v7 || *(_WORD *)(v9 + 12) != v8 )
{
v10 = *(__int64 **)(v9 + 24);
v9 = (__int64)(v10 - 3);
if ( v12 == v10 )
goto LABEL_11;
}
++*(_DWORD *)(v9 + 16);
}
}

original_code:
int main(int argc, char *argv[])
{
 int sd;
 unsigned char buf[2048] = {0};
 for(;;){
  buf[0] = 0;
 };
}

variable_types:
argv
char *[]

variable_types: sd int

variable_types:
buf
unsigned char [2048]


decompiled_code:
__int64 __fastcall convert_ip(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
__int64 result; // rax
int v3; // edx

v1 = a1 + 4;
LODWORD(result) = 0;
do
{
v3 = *a1++;
result = (unsigned int)(v3 + ((_DWORD)result << 8));
}
while ( v1 != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
__int64 result; // rax
int v3; // edx

v1 = a1 + 4;
LODWORD(result) = 0;
do
{
v3 = *a1++;
result = (unsigned int)(v3 + ((_DWORD)result << 8));
}
while ( v1 != a1 );
return result;
}

original_code:
uint32_t convert_ip(unsigned char *start)
{
 uint32_t result = 0;
 int i;
 for (i = 0; i < 4; i++) {
  result *= 256;
  result += *start;
  start++;
 };
 return result;
}

canonical_original_code:
unsigned int convert_ip(unsigned char *start)
{
 unsigned int result = 0;
 int i;
 for (i = 0; i < 4; i++) {
  result *= 256;
  result += *start;
  start++;
 };
 return result;
}

variable_types:
start
unsigned char *

variable_types:
result
unsigned int

return_type: unsigned int


strrep

repo: haozhigh/fftz

decompiled_code:
__int64 __fastcall strrep(void *dest, void *src, char *s, char *a4)
{
char *v6; // rax
char *v7; // rbx
size_t v8; // rax
char *v9; // r15
size_t v10; // rax
char *v11; // rax

v6 = strstr((const char *)dest, s);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
do
{
mystrncpy_isra_0(src, (__int64)dest, (_DWORD)v7 - (_DWORD)dest);
v8 = strlen((const char *)src);
v9 = stpcpy((char *)src + v8, a4);
v10 = strlen(s);
v11 = stpcpy(v9, &v7[v10]);
memcpy(dest, src, v11 - (_BYTE *)src + 1);
v7 = strstr((const char *)dest, s);
}
while ( v7 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *dest, void *src, char *s, char *a4)
{
char *v6; // rax
char *v7; // rbx
size_t v8; // rax
char *v9; // r15
size_t v10; // rax
char *v11; // rax

v6 = strstr((const char *)dest, s);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
do
{
func0(src, (__int64)dest, (_DWORD)v7 - (_DWORD)dest);
v8 = strlen((const char *)src);
v9 = stpcpy((char *)src + v8, a4);
v10 = strlen(s);
v11 = stpcpy(v9, &v7[v10]);
memcpy(dest, src, v11 - (_BYTE *)src + 1);
v7 = strstr((const char *)dest, s);
}
while ( v7 );
return 0LL;
}

original_code:
int strrep(char *src, char * src_temp, char *match, char *replace){
 char *find_pos;
 find_pos = strstr(src, match);
 if((!find_pos) || (!match))
  return -1;
 while(find_pos){
  mystrncpy(src_temp, src, find_pos - src);
  strcat(src_temp, replace);
  strcat(src_temp, find_pos + strlen(match));
  strcpy(src, src_temp);
  find_pos = strstr(src, match);
 }
 return 0;
}

canonical_original_code:
int strrep(char *src, char *src_temp, char *match, char *replace){
 char *find_pos;
 find_pos = strstr(src, match);
 if((!find_pos) || (!match))
  return -1;
 while(find_pos){
  mystrncpy(src_temp, src, find_pos - src);
  strcat(src_temp, replace);
  strcat(src_temp, find_pos + strlen(match));
  strcpy(src, src_temp);
  find_pos = strstr(src, match);
 }
 return 0;
}

variable_types:
src
char *

variable_types:
match
char *

variable_types:
replace
char *


repo: harlanji/university-coursework

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

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

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

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

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

return_type: double

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


strrev

decompiled_code:
char *__fastcall strrev(char *dest)
{
int v1; // ebx
char *v2; // rbp
int v3; // ebx
char *v4; // rax
char *v5; // rdx
char v6; // cl

v1 = strlen(dest);
v2 = (char *)malloc(v1 + 1);
if ( v2 )
{
v2[v1] = 0;
v3 = v1 - 1;
if ( v3 >= 0 )
{
v4 = v2;
v5 = &dest[v3];
do
{
v6 = *v5;
++v4;
--v5;
*(v4 - 1) = v6;
}
while ( v4 != &v2[v3 + 1] );
}
}
strcpy(dest, v2);
free(v2);
return dest;
}

canonical_decompiled_code:
char *__fastcall func1(char *dest)
{
int v1; // ebx
char *v2; // rbp
int v3; // ebx
char *v4; // rax
char *v5; // rdx
char v6; // cl

v1 = strlen(dest);
v2 = (char *)malloc(v1 + 1);
if ( v2 )
{
v2[v1] = 0;
v3 = v1 - 1;
if ( v3 >= 0 )
{
v4 = v2;
v5 = &dest[v3];
do
{
v6 = *v5;
++v4;
--v5;
*(v4 - 1) = v6;
}
while ( v4 != &v2[v3 + 1] );
}
}
strcpy(dest, v2);
free(v2);
return dest;
}

original_code:
char* strrev(char * string) {
 int length = strlen(string);
 char * result = malloc(length+1);
 if( result != ((void *)0) ) {
  int i,j;
  result[length] = '\0';
  for ( i = length-1, j=0; i >= 0; i--, j++ )
   result[j] = string[i];
 }
 strcpy(string, result);
 free(result);
 return string;
}

canonical_original_code:
char *strrev(char *string) {
 int length = strlen(string);
 char *result = malloc(length+1);
 if( result != ((void *)0) ) {
  int i; int j;
  result[length] = '\0';
  for ( i = length-1, j=0; i >= 0; i--, j++ )
   result[j] = string[i];
 }
 strcpy(string, result);
 free(result);
 return string;
}

variable_types:
string
char *

variable_types: length int

variable_types:
result
char *

variable_types: j int

return_type: char *


decompiled_code:
_BOOL8 __fastcall parse_args(int a1, __int64 a2, _QWORD *a3, _QWORD *a4, int *a5)
{
_BOOL8 result; // rax
int v7; // eax

result = 0LL;
if ( a1 > 2 )
{
*a3 = *(_QWORD *)(a2 + 8);
*a4 = *(_QWORD *)(a2 + 16);
result = 1LL;
if ( a5 )
{
if ( a1 == 3 )
{
*a5 = 1;
}
else
{
v7 = atoi(*(const char **)(a2 + 24));
*a5 = v7;
result = v7 != 0;
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1, __int64 a2, _QWORD *a3, _QWORD *a4, int *a5)
{
_BOOL8 result; // rax
int v7; // eax

result = 0LL;
if ( a1 > 2 )
{
*a3 = *(_QWORD *)(a2 + 8);
*a4 = *(_QWORD *)(a2 + 16);
result = 1LL;
if ( a5 )
{
if ( a1 == 3 )
{
*a5 = 1;
}
else
{
v7 = atoi(*(const char **)(a2 + 24));
*a5 = v7;
result = v7 != 0;
}
}
}
return result;
}

original_code:
int parse_args( int argc, char* argv[], char** file1, char** file2, int* p ) {
 if( argc < 3 ) {
  return 0;
 }
 *file1 = argv[1];
 *file2 = argv[2];
 if( p != ((void *)0)) {
  if(argc >= 4) {
   *p = atoi( argv[3] );
   if( !*p ) {
    return 0;
   }
  } else {
   *p = 1;
  }
 }
 return 1;
}

canonical_original_code:
int parse_args(int argc, char *argv[], char **file1, char **file2, int *p) {
 if( argc < 3 ) {
  return 0;
 }
 *file1 = argv[1];
 *file2 = argv[2];
 if( p != ((void *)0)) {
  if(argc >= 4) {
   *p = atoi( argv[3] );
   if( !*p ) {
    return 0;
   }
  } else {
   *p = 1;
  }
 }
 return 1;
}

variable_types: argc int

variable_types:
p
int *


decompiled_code:
void *__fastcall grid_init(__int64 a1, const char *a2, const char *a3)
{
int v4; // eax
int v5; // ebx
int v6; // eax
void *result; // rax

*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
v4 = strlen(a2);
*(_DWORD *)a1 = v4;
v5 = v4;
v6 = strlen(a3);
*(_DWORD *)(a1 + 4) = v6;
result = calloc(8LL * (v6 + 1) * (v5 + 1), 1uLL);
*(_QWORD *)(a1 + 24) = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, const char *a2, const char *a3)
{
int v4; // eax
int v5; // ebx
int v6; // eax
void *result; // rax

*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
v4 = strlen(a2);
*(_DWORD *)a1 = v4;
v5 = v4;
v6 = strlen(a3);
*(_DWORD *)(a1 + 4) = v6;
result = calloc(8LL * (v6 + 1) * (v5 + 1), 1uLL);
*(_QWORD *)(a1 + 24) = result;
return result;
}

original_code:
void grid_init(grid_t* grid, const char* s1, const char* s2) {
 grid->s1 = s1;
 grid->s2 = s2;
 grid->m = strlen(s1);
 grid->n = strlen(s2);
 size_t size = (grid->m + 1) * (grid->n + 1) * sizeof(cell_t);
 grid->cells = (cell_t*)malloc( size );
 memset( grid->cells, 0, size );
}

canonical_original_code:
void grid_init(struct grid_t *grid, char *s1, char *s2) {
 grid->s1 = s1;
 grid->s2 = s2;
 grid->m = strlen(s1);
 grid->n = strlen(s2);
 unsigned long size = (grid->m + 1) * (grid->n + 1) * sizeof(cell_t);
 grid->cells = (struct cell_t *)malloc( size );
 memset( grid->cells, 0, size );
}

variable_types: struct grid_t { int m; int n; char *s1; char *s2; struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; } *cells; } *

variable_types:
size
unsigned long

user_defined_types: struct grid_t { int m; int n; char *s1; char *s2; struct cell_t *cells; }


decompiled_code:
__int64 __fastcall grid_cell(__int64 a1, int a2, int a3)
{
return *(_QWORD *)(a1 + 24) + 8LL * (a3 + a2 * (*(_DWORD *)a1 + 1));
}

original_code:
cell_t* grid_cell(const grid_t* grid, const int i, const int j) {
 return &(grid->cells[ (grid->m + 1)*i + j ]);
}

canonical_original_code:
struct cell_t *grid_cell(struct grid_t *grid, int i, int j) {
 return &(grid->cells[ (grid->m + 1)*i + j ]);
}

variable_types: struct grid_t { int m; int n; char *s1; char *s2; struct cell_t *cells; } *

variable_types: i int

return_type: struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; } *


decompiled_code:
void *__fastcall grid_alloc_block(int a1, int a2)
{
return malloc(8LL * a2 * a1);
}

canonical_decompiled_code:
void *__fastcall func7(int a1, int a2)
{
return malloc(8LL * a2 * a1);
}

original_code:
cell_t* grid_alloc_block( const int h, const int w ) {
 cell_t* block = (cell_t*)malloc( h * w * sizeof(cell_t) );
 return block;
}

canonical_original_code:
struct cell_t *grid_alloc_block(int h, int w) {
 struct cell_t *block = (cell_t*)malloc( h * w * sizeof(cell_t) );
 return block;
}

variable_types: h int

variable_types: w int

variable_types: struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; } *


decompiled_code:
void *__fastcall grid_serialize_block(__int64 a1, int a2, int a3, int a4, int a5)
{
int v5; // er15
__int64 v9; // rbp
char *v10; // rax
size_t v11; // rbp
char *v12; // rbx
int v13; // er12
int v14; // esi
const void *v15; // rax
void *v16; // rdi
void *v18; // [rsp+8h] [rbp-40h]

v5 = a2;
v9 = a5;
v10 = (char *)grid_alloc_block(a4, a5);
v18 = v10;
if ( a4 > 0 )
{
v11 = 8 * v9;
v12 = v10;
v13 = a2 + a4;
do
{
v14 = v5++;
v15 = (const void *)grid_cell(a1, v14, a3);
v16 = v12;
v12 += v11;
memcpy(v16, v15, v11);
}
while ( v5 != v13 );
}
return v18;
}

original_code:
cell_t* grid_serialize_block( const grid_t* grid, const int y, const int x, const int h, const int w ) {
 cell_t* serialized = grid_alloc_block(h, w);
 int i;
 for( i = 0; i < h; i++ ) {
  cell_t* cell = grid_cell( grid, y + i, x );
  memcpy(&serialized[w*i], cell, w*sizeof(cell_t));
 }
 return serialized;
}

canonical_original_code:
struct cell_t *grid_serialize_block(struct grid_t *grid, int y, int x, int h, int w) {
 struct cell_t *serialized = grid_alloc_block(h, w);
 int i;
 for( i = 0; i < h; i++ ) {
  struct cell_t *cell = grid_cell( grid, y + i, x );
  memcpy(&serialized[w*i], cell, w*sizeof(cell_t));
 }
 return serialized;
}

variable_types: y int

variable_types: x int

user_defined_types: struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; }


decompiled_code:
void __fastcall grid_deserialize_block(__int64 a1, char *a2, int a3, int a4, int a5, int a6)
{
int v6; // er15
size_t v8; // r12
int v10; // ebx
int v11; // esi
void *v12; // rax
const void *v13; // rsi

if ( a5 > 0 )
{
v6 = a5 + a3;
v8 = 8LL * a6;
v10 = a3;
do
{
v11 = v10++;
v12 = (void *)grid_cell(a1, v11, a4);
v13 = a2;
a2 += v8;
memcpy(v12, v13, v8);
}
while ( v10 != v6 );
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, char *a2, int a3, int a4, int a5, int a6)
{
int v6; // er15
size_t v8; // r12
int v10; // ebx
int v11; // esi
void *v12; // rax
const void *v13; // rsi

if ( a5 > 0 )
{
v6 = a5 + a3;
v8 = 8LL * a6;
v10 = a3;
do
{
v11 = v10++;
v12 = (void *)func6(a1, v11, a4);
v13 = a2;
a2 += v8;
memcpy(v12, v13, v8);
}
while ( v10 != v6 );
}
}

original_code:
void grid_deserialize_block( const grid_t* grid, const cell_t* serialized, const int y, const int x, const int h, const int w ) {
 int i;
 for( i = 0; i < h; i++ ) {
  cell_t* cell = grid_cell( grid, y + i, x );
  memcpy(cell, &serialized[w*i], w*sizeof(cell_t));
 }
}

canonical_original_code:
void grid_deserialize_block(struct grid_t *grid, struct cell_t *serialized, int y, int x, int h, int w) {
 int i;
 for( i = 0; i < h; i++ ) {
  struct cell_t *cell = grid_cell( grid, y + i, x );
  memcpy(cell, &serialized[w*i], w*sizeof(cell_t));
 }
}

variable_types:
serialized
struct cell_t *


decompiled_code:
__int64 __fastcall lcs_length_block(__int64 a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax
int v6; // er10
__int64 v7; // r15
int v9; // ebx
int v10; // ebp
__int64 v11; // r12
int v12; // ecx
_BYTE *v13; // r14
int v14; // er10
int v15; // er11
int v16; // ecx
_DWORD *v17; // r8
_DWORD *v18; // r9
__int64 v19; // rcx
int v20; // er11
int v21; // eax
_DWORD *v22; // r8
int v23; // [rsp+0h] [rbp-34h]

result = (unsigned int)(a2 + a4);
if ( a2 < (int)result )
{
result = (unsigned int)(result - 1);
v6 = a2 - 1;
v7 = a2 - 1LL;
v9 = a3 + a5;
v23 = result;
do
{
v10 = v6++;
if ( v9 > a3 )
{
v11 = *(_QWORD *)(a1 + 16);
v12 = a3;
v13 = (_BYTE *)(v7 + *(_QWORD *)(a1 + 8));
do
{
while ( 1 )
{
grid_cell(a1, v6, v12);
if ( *v13 != *(_BYTE *)(v11 + v19 - 1) )
break;
v21 = *(_DWORD *)grid_cell(a1, v10, v20);
v22[1] = 3;
result = (unsigned int)(v21 + 1);
*v22 = result;
if ( v9 <= v12 )
goto LABEL_10;
}
grid_cell(a1, v10, v19);
result = *(unsigned int *)grid_cell(a1, v14, v15);
if ( *v18 < (int)result )
{
*v17 = result;
v17[1] = 2;
}
else
{
*v17 = *v18;
v17[1] = 1;
}
v12 = v16 + 1;
}
while ( v9 > v12 );
}
LABEL_10:
++v7;
}
while ( v23 != v6 );
}
return result;
}

original_code:
void lcs_length_block( const grid_t* grid, const int y, const int x, const int h, const int w ) {
 int i, j;
 for(i = y; i < y + h; i++) {
  for(j = x; j < x + w; j++) {
   cell_t* cell = grid_cell( grid, i, j );
   if(grid->s1[i-1] == grid->s2[j-1]) {
    cell->len = grid_cell( grid, i-1, j-1 )->len + 1;
    cell->dir = upleft;
   } else {
    cell_t* cell_up = grid_cell( grid, i-1, j );
    cell_t* cell_left = grid_cell( grid, i, j-1 );
    if(cell_up->len >= cell_left->len) {
     cell->len = cell_up->len;
     cell->dir = up;
    } else {
     cell->len = cell_left->len;
     cell->dir = left;
    }
   }
  }
 }
}

canonical_original_code:
void lcs_length_block(struct grid_t *grid, int y, int x, int h, int w) {
 int i; int j;
 for(i = y; i < y + h; i++) {
  for(j = x; j < x + w; j++) {
   struct cell_t *cell = grid_cell( grid, i, j );
   if(grid->s1[i-1] == grid->s2[j-1]) {
    cell->len = grid_cell( grid, i-1, j-1 )->len + 1;
    cell->dir = upleft;
   } else {
    struct cell_t *cell_up = grid_cell( grid, i-1, j );
    struct cell_t *cell_left = grid_cell( grid, i, j-1 );
    if(cell_up->len >= cell_left->len) {
     cell->len = cell_up->len;
     cell->dir = up;
    } else {
     cell->len = cell_left->len;
     cell->dir = left;
    }
   }
  }
 }
}


max

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

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

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

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

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

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall queue_init(__int64 a1, int a2)
{
void *v2; // rax

*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = 0LL;
v2 = malloc(8LL * a2);
*(_QWORD *)(a1 + 16) = v2;
return (unsigned int)-(v2 == 0LL);
}

original_code:
int queue_init( queue_t* q, int capacity ) {
 q->capacity = capacity;
 q->head = 0;
 q->tail = 0;
 q->size = 0;
 q->items = (void**)malloc( capacity * sizeof(void*) );
 return q->items == ((void *)0) ? -1 : 0;
}

canonical_original_code:
int queue_init(struct queue *q, int capacity) {
 q->capacity = capacity;
 q->head = 0;
 q->tail = 0;
 q->size = 0;
 q->items = (void **)malloc( capacity * sizeof(void *) );
 return q->items == ((void *)0) ? -1 : 0;
}

variable_types: struct queue { int capacity; int size; int head; int tail; void **items; } *

variable_types: capacity int


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

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void queue_destroy( queue_t* q ) {
 free( q->items );
}

canonical_original_code:
void queue_destroy(struct queue *q) {
 free( q->items );
}

user_defined_types: struct queue { int capacity; int size; int head; int tail; void **items; }


original_code:
int queue_requeue( queue_t* q, void* item ) {
 int i;
 for(i = 0; i < q->size; i++) {
  int pos = q_pos(q, q->head + i);
  if( item == q->items[pos] ) {
   int j;
   for(j = i; j < q->size - 1; j++) {
    int from = q_pos(q, q->head + j + 1);
    int to = q_pos(q, q->head + j);
    q->items[ to ] = q->items[ from ];
   }
   int current_tail = q_pos(q, q->tail - 1);
   q->items[ current_tail ] = item;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int queue_requeue(struct queue *q, void *item) {
 int i;
 for(i = 0; i < q->size; i++) {
  int pos = q_pos(q, q->head + i);
  if( item == q->items[pos] ) {
   int j;
   for(j = i; j < q->size - 1; j++) {
    int from = q_pos(q, q->head + j + 1);
    int to = q_pos(q, q->head + j);
    q->items[ to ] = q->items[ from ];
   }
   int current_tail = q_pos(q, q->tail - 1);
   q->items[ current_tail ] = item;
   return 0;
  }
 }
 return -1;
}

variable_types:
item
void *

variable_types: pos int

variable_types: j int

variable_types: from int

variable_types: to int


decompiled_code:
_BOOL8 __fastcall queue_isempty(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

original_code:
int queue_isempty( queue_t* q ) {
 return q->size == 0;
}

canonical_original_code:
int queue_isempty(struct queue *q) {
 return q->size == 0;
}


decompiled_code:
__int64 __fastcall queue_dequeue(int *a1)
{
int v1; // er9
__int64 v2; // rcx
__int64 v3; // r8
__int64 result; // rax

if ( queue_isempty((__int64)a1) )
return 0LL;
v1 = q_pos_isra_0(*a1, a1[2] + 1);
result = *(_QWORD *)(*(_QWORD *)(v2 + 16) + 8 * v3);
--*(_DWORD *)(v2 + 4);
*(_DWORD *)(v2 + 8) = v1;
return result;
}

original_code:
void* queue_dequeue( queue_t* q ) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int new_head = q_pos(q, q->head + 1);
 void* item = q->items[ q->head ];
 q->head = new_head;
 q->size--;
 return item;
}

canonical_original_code:
void *queue_dequeue(struct queue *q) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int new_head = q_pos(q, q->head + 1);
 void *item = q->items[ q->head ];
 q->head = new_head;
 q->size--;
 return item;
}


decompiled_code:
__int64 __fastcall queue_search(__int64 a1, unsigned int (__fastcall *a2)(__int64, __int64, __int64), __int64 a3)
{
int v5; // edi
int v6; // er12
__int64 v7; // rbp
__int64 v8; // r15

if ( queue_isempty(a1) )
return 0LL;
v5 = *(_DWORD *)a1;
v6 = 0;
if ( v5 <= 0 )
return 0LL;
while ( 1 )
{
v7 = (int)q_pos_isra_0(v5, v6 + *(_DWORD *)(a1 + 8));
v8 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v7);
if ( a2(a1, v8, a3) )
break;
if ( *(_DWORD *)(a1 + 12) - 1 != (_DWORD)v7 )
{
v5 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 > ++v6 )
continue;
}
return 0LL;
}
return v8;
}

original_code:
void* queue_search( queue_t* q, queue_search_cb cb, void* arg ) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int i;
 for( i = 0; i < q->capacity; i++ ) {
  int pos = q_pos(q, q->head + i);
  void* item = q->items[ pos ];
  if( cb( q, item, arg ) ) {
   return item;
  }
  if( pos == q->tail - 1 ) {
    return (void*)((void *)0);
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *queue_search(struct queue *q, int (*cb)(struct queue *q, void *item, void *arg), void *arg) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int i;
 for( i = 0; i < q->capacity; i++ ) {
  int pos = q_pos(q, q->head + i);
  void *item = q->items[ pos ];
  if( cb( q, item, arg ) ) {
   return item;
  }
  if( pos == q->tail - 1 ) {
    return (void *)((void *)0);
  }
 }
 return ((void *)0);
}

variable_types: int (*)(struct queue *q, void *item, void *arg)

variable_types:
arg
void *


decompiled_code:
_BOOL8 __fastcall queue_isfull(_DWORD *a1)
{
return a1[1] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_DWORD *a1)
{
return a1[1] == *a1;
}

original_code:
int queue_isfull( queue_t* q ) {
 return q->size == q->capacity;
}

canonical_original_code:
int queue_isfull(struct queue *q) {
 return q->size == q->capacity;
}


decompiled_code:
__int64 __fastcall queue_enqueue(int *a1)
{
_DWORD *v1; // rcx
__int64 result; // rax
int v3; // edx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9

q_pos_isra_0(*a1, a1[3] + 1);
result = queue_isfull(v1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_QWORD *)(*(_QWORD *)(v4 + 16) + 8 * v5) = v6;
++*(_DWORD *)(v4 + 4);
*(_DWORD *)(v4 + 12) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1)
{
_DWORD *v1; // rcx
__int64 result; // rax
int v3; // edx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9

func0(*a1, a1[3] + 1);
result = func7(v1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_QWORD *)(*(_QWORD *)(v4 + 16) + 8 * v5) = v6;
++*(_DWORD *)(v4 + 4);
*(_DWORD *)(v4 + 12) = v3;
return result;
}

original_code:
int queue_enqueue( queue_t* q, void* item ) {
 int new_tail = q_pos(q, q->tail + 1);
 if( queue_isfull( q ) ) {
  return -1;
 }
 q->items[ q->tail ] = item;
 q->tail = new_tail;
 q->size++;
 return 0;
}

canonical_original_code:
int queue_enqueue(struct queue *q, void *item) {
 int new_tail = q_pos(q, q->tail + 1);
 if( queue_isfull( q ) ) {
  return -1;
 }
 q->items[ q->tail ] = item;
 q->tail = new_tail;
 q->size++;
 return 0;
}


decompiled_code:
__int64 __fastcall prodcon_queue_init(pthread_cond_t *cond, int a2)
{
pthread_cond_t *v3; // rdi
unsigned int v4; // er12

v3 = cond + 1;
*((_DWORD *)&v3[2].__align + 4) = 0;
if ( pthread_cond_init(v3, 0LL) == -1 )
{
v4 = -1;
fwrite("pthread_cond_init error for full queue condition", 1uLL, 0x30uLL, stderr);
}
else
{
v4 = pthread_cond_init(cond, 0LL);
if ( v4 == -1 )
{
fwrite("pthread_cond_init error for empty queue condition", 1uLL, 0x31uLL, stderr);
}
else
{
v4 = pthread_mutex_init((pthread_mutex_t *)&cond[2], 0LL);
if ( v4 == -1 )
{
fwrite("pthread_mutex_init error on queue", 1uLL, 0x21uLL, stderr);
}
else
{
v4 = queue_init((__int64)(&cond[2].__align + 5), a2);
if ( v4 == -1 )
fwrite("queue_init error", 1uLL, 0x10uLL, stderr);
else
v4 = 0;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_cond_t *cond, int a2)
{
pthread_cond_t *v3; // rdi
unsigned int v4; // er12

v3 = cond + 1;
*((_DWORD *)&v3[2].__align + 4) = 0;
if ( pthread_cond_init(v3, 0LL) == -1 )
{
v4 = -1;
fwrite("pthread_cond_init error for full queue condition", 1uLL, 0x30uLL, stderr);
}
else
{
v4 = pthread_cond_init(cond, 0LL);
if ( v4 == -1 )
{
fwrite("pthread_cond_init error for empty queue condition", 1uLL, 0x31uLL, stderr);
}
else
{
v4 = pthread_mutex_init((pthread_mutex_t *)&cond[2], 0LL);
if ( v4 == -1 )
{
fwrite("pthread_mutex_init error on queue", 1uLL, 0x21uLL, stderr);
}
else
{
v4 = func1((__int64)(&cond[2].__align + 5), a2);
if ( v4 == -1 )
fwrite("queue_init error", 1uLL, 0x10uLL, stderr);
else
v4 = 0;
}
}
}
return v4;
}

original_code:
int prodcon_queue_init( prodcon_queue_t* q, int capacity ) {
 q->consume_all = 0;
 if (pthread_cond_init( &q->full_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for full queue condition");
  return -1;
 }
 if (pthread_cond_init( &q->empty_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for empty queue condition");
  return -1;
 }
 if (pthread_mutex_init( &q->mx, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_mutex_init error on queue");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "queue_init error");
  return -1;
 }
 return 0;
}

canonical_original_code:
int prodcon_queue_init(struct prodcon_queue *q, int capacity) {
 q->consume_all = 0;
 if (pthread_cond_init( &q->full_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for full queue condition");
  return -1;
 }
 if (pthread_cond_init( &q->empty_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for empty queue condition");
  return -1;
 }
 if (pthread_mutex_init( &q->mx, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_mutex_init error on queue");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "queue_init error");
  return -1;
 }
 return 0;
}

variable_types: struct prodcon_queue { union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } empty_cv; union pthread_cond_t full_cv; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mx; struct queue { int capacity; int size; int head; int tail; void **items; } q; int consume_all; } *

user_defined_types: struct prodcon_queue { union pthread_cond_t empty_cv; union pthread_cond_t full_cv; union pthread_mutex_t mx; struct queue q; int consume_all; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall prodcon_queue_destroy(pthread_cond_t *cond)
{
int result; // eax

queue_destroy((__int64)(&cond[2].__align + 5));
if ( pthread_mutex_destroy((pthread_mutex_t *)&cond[2]) == -1 )
return fwrite("Failed to destroy prodcon mutex lock", 1uLL, 0x24uLL, stderr);
if ( pthread_cond_destroy(cond + 1) == -1 )
return fwrite("Failed to destroy prodcon full_cv", 1uLL, 0x21uLL, stderr);
result = pthread_cond_destroy(cond);
if ( result == -1 )
result = fwrite("Failed to destroy prodcon empty_cv", 1uLL, 0x22uLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func10(pthread_cond_t *cond)
{
int result; // eax

func2((__int64)(&cond[2].__align + 5));
if ( pthread_mutex_destroy((pthread_mutex_t *)&cond[2]) == -1 )
return fwrite("Failed to destroy prodcon mutex lock", 1uLL, 0x24uLL, stderr);
if ( pthread_cond_destroy(cond + 1) == -1 )
return fwrite("Failed to destroy prodcon full_cv", 1uLL, 0x21uLL, stderr);
result = pthread_cond_destroy(cond);
if ( result == -1 )
result = fwrite("Failed to destroy prodcon empty_cv", 1uLL, 0x22uLL, stderr);
return result;
}

original_code:
void prodcon_queue_destroy( prodcon_queue_t* q) {
 queue_destroy( &q->q );
 if (pthread_mutex_destroy( &q->mx ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon mutex lock");
  return;
 }
 if (pthread_cond_destroy( &q->full_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon full_cv");
  return;
 }
 if (pthread_cond_destroy( &q->empty_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon empty_cv");
  return;
 }
}

canonical_original_code:
void prodcon_queue_destroy(struct prodcon_queue *q) {
 queue_destroy( &q->q );
 if (pthread_mutex_destroy( &q->mx ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon mutex lock");
  return;
 }
 if (pthread_cond_destroy( &q->full_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon full_cv");
  return;
 }
 if (pthread_cond_destroy( &q->empty_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon empty_cv");
  return;
 }
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall queue_produce(pthread_cond_t *cond)
{
pthread_mutex_t *v1; // rbp
unsigned int v2; // er12

v1 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( 1 )
{
v2 = queue_isfull(&cond[2].__nwaiters);
if ( !v2 )
break;
pthread_cond_wait(cond, v1);
}
queue_enqueue((int *)&cond[2].__nwaiters);
pthread_cond_signal(cond + 1);
if ( pthread_mutex_unlock(v1) == -1 )
{
v2 = -1;
fwrite("queue_produce - Failed to release lock.", 1uLL, 0x27uLL, stderr);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(pthread_cond_t *cond)
{
pthread_mutex_t *v1; // rbp
unsigned int v2; // er12

v1 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( 1 )
{
v2 = func7(&cond[2].__nwaiters);
if ( !v2 )
break;
pthread_cond_wait(cond, v1);
}
func8((int *)&cond[2].__nwaiters);
pthread_cond_signal(cond + 1);
if ( pthread_mutex_unlock(v1) == -1 )
{
v2 = -1;
fwrite("queue_produce - Failed to release lock.", 1uLL, 0x27uLL, stderr);
}
return v2;
}

original_code:
int queue_produce( prodcon_queue_t* q, void* item ) {
 pthread_mutex_lock( &q->mx );
 while( queue_isfull(&q->q) ) {
  pthread_cond_wait( &q->empty_cv, &q->mx );
 }
 queue_enqueue( &q->q, item );
 pthread_cond_signal( &q->full_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_produce - Failed to release lock.");
  return -1;
 }
 return 0;
}

canonical_original_code:
int queue_produce(struct prodcon_queue *q, void *item) {
 pthread_mutex_lock( &q->mx );
 while( queue_isfull(&q->q) ) {
  pthread_cond_wait( &q->empty_cv, &q->mx );
 }
 queue_enqueue( &q->q, item );
 pthread_cond_signal( &q->full_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_produce - Failed to release lock.");
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall queue_consume(pthread_cond_t *cond)
{
pthread_mutex_t *v1; // r12
__int64 v2; // r13

v1 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( queue_isempty((__int64)(&cond[2].__align + 5)) )
{
if ( *((_DWORD *)&cond[3].__align + 4) )
return -1LL;
pthread_cond_wait(cond + 1, v1);
}
v2 = queue_dequeue((int *)&cond[2].__nwaiters);
pthread_cond_signal(cond);
if ( pthread_mutex_unlock(v1) == -1 )
{
v2 = 0LL;
fwrite("queue_consume - Failed to release lock.", 1uLL, 0x27uLL, stderr);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(pthread_cond_t *cond)
{
pthread_mutex_t *v1; // r12
__int64 v2; // r13

v1 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( func4((__int64)(&cond[2].__align + 5)) )
{
if ( *((_DWORD *)&cond[3].__align + 4) )
return -1LL;
pthread_cond_wait(cond + 1, v1);
}
v2 = func5((int *)&cond[2].__nwaiters);
pthread_cond_signal(cond);
if ( pthread_mutex_unlock(v1) == -1 )
{
v2 = 0LL;
fwrite("queue_consume - Failed to release lock.", 1uLL, 0x27uLL, stderr);
}
return v2;
}

original_code:
void* queue_consume( prodcon_queue_t* q ) {
 pthread_mutex_lock( &q->mx );
 while( queue_isempty(&q->q) ) {
  if( q->consume_all ) {
   return (void*)-1;
  }
  pthread_cond_wait( &q->full_cv, &q->mx );
 }
 void* item = queue_dequeue( &q->q );
 pthread_cond_signal( &q->empty_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_consume - Failed to release lock.");
  return ((void *)0);
 }
 return item;
}

canonical_original_code:
void *queue_consume(struct prodcon_queue *q) {
 pthread_mutex_lock( &q->mx );
 while( queue_isempty(&q->q) ) {
  if( q->consume_all ) {
   return (void *)-1;
  }
  pthread_cond_wait( &q->full_cv, &q->mx );
 }
 void *item = queue_dequeue( &q->q );
 pthread_cond_signal( &q->empty_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_consume - Failed to release lock.");
  return ((void *)0);
 }
 return item;
}


decompiled_code:
int __fastcall queue_consume_all(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 96));
*(_DWORD *)(a1 + 160) = 1;
while ( !queue_isempty(a1 + 136) )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 96));
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 96));
*(_DWORD *)(a1 + 160) = 1;
while ( !func4(a1 + 136) )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 96));
}

original_code:
void queue_consume_all( prodcon_queue_t* q ) {
 pthread_mutex_lock( &q->mx );
 q->consume_all = 1;
 while( !queue_isempty( &q->q ) ) {
  pthread_cond_broadcast( &q->full_cv );
 }
 pthread_mutex_unlock( &q->mx );
}

canonical_original_code:
void queue_consume_all(struct prodcon_queue *q) {
 pthread_mutex_lock( &q->mx );
 q->consume_all = 1;
 while( !queue_isempty( &q->q ) ) {
  pthread_cond_broadcast( &q->full_cv );
 }
 pthread_mutex_unlock( &q->mx );
}


decompiled_code:
__int64 __fastcall rwlock_queue_init(pthread_rwlock_t *a1, int a2)
{
unsigned int v2; // er12

if ( pthread_rwlock_init(a1, 0LL) == -1 )
{
v2 = -1;
fwrite("Failed to initialize RW lock", 1uLL, 0x1CuLL, stderr);
}
else
{
v2 = queue_init((__int64)&a1[1], a2);
if ( v2 == -1 )
fwrite("Failed to initialize RW queue", 1uLL, 0x1DuLL, stderr);
else
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(pthread_rwlock_t *a1, int a2)
{
unsigned int v2; // er12

if ( pthread_rwlock_init(a1, 0LL) == -1 )
{
v2 = -1;
fwrite("Failed to initialize RW lock", 1uLL, 0x1CuLL, stderr);
}
else
{
v2 = func1((__int64)&a1[1], a2);
if ( v2 == -1 )
fwrite("Failed to initialize RW queue", 1uLL, 0x1DuLL, stderr);
else
v2 = 0;
}
return v2;
}

original_code:
int rwlock_queue_init( rwlock_queue_t* q, int capacity ) {
 if (pthread_rwlock_init( &q->rwl, ((void *)0) ) == -1) {
  fprintf(stderr, "Failed to initialize RW lock");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "Failed to initialize RW queue");
  return -1;
 }
 return 0;
}

canonical_original_code:
int rwlock_queue_init(struct rwlock_queue *q, int capacity) {
 if (pthread_rwlock_init( &q->rwl, ((void *)0) ) == -1) {
  fprintf(stderr, "Failed to initialize RW lock");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "Failed to initialize RW queue");
  return -1;
 }
 return 0;
}

variable_types: struct rwlock_queue { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } rwl; struct queue { int capacity; int size; int head; int tail; void **items; } q; } *

user_defined_types: struct rwlock_queue { union pthread_rwlock_t rwl; struct queue q; }

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }


decompiled_code:
int __fastcall rwlock_queue_destroy(pthread_rwlock_t *rwlock)
{
int result; // eax

queue_destroy((__int64)&rwlock[1]);
result = pthread_rwlock_destroy(rwlock);
if ( result == -1 )
result = fwrite("Failed to destry RW lock", 1uLL, 0x18uLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func15(pthread_rwlock_t *rwlock)
{
int result; // eax

func2((__int64)&rwlock[1]);
result = pthread_rwlock_destroy(rwlock);
if ( result == -1 )
result = fwrite("Failed to destry RW lock", 1uLL, 0x18uLL, stderr);
return result;
}

original_code:
void rwlock_queue_destroy( rwlock_queue_t* q ) {
 queue_destroy( &q->q );
 if (pthread_rwlock_destroy( &q->rwl ) == -1) {
  fprintf(stderr, "Failed to destry RW lock");
 }
}

canonical_original_code:
void rwlock_queue_destroy(struct rwlock_queue *q) {
 queue_destroy( &q->q );
 if (pthread_rwlock_destroy( &q->rwl ) == -1) {
  fprintf(stderr, "Failed to destry RW lock");
 }
}

user_defined_types: struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; }


decompiled_code:
__int64 __fastcall queue_write(pthread_rwlock_t *rwlock)
{
unsigned int v1; // er12

pthread_rwlock_wrlock(rwlock);
v1 = queue_enqueue(&rwlock[1].__lock);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
v1 = -1;
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func16(pthread_rwlock_t *rwlock)
{
unsigned int v1; // er12

pthread_rwlock_wrlock(rwlock);
v1 = func8(&rwlock[1].__lock);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
v1 = -1;
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
}
return v1;
}

original_code:
int queue_write( rwlock_queue_t* q, void* item ) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_enqueue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}

canonical_original_code:
int queue_write(struct rwlock_queue *q, void *item) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_enqueue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}


decompiled_code:
__int64 __fastcall queue_rewrite(pthread_rwlock_t *rwlock)
{
unsigned int v1; // er12

pthread_rwlock_wrlock(rwlock);
v1 = queue_requeue(&rwlock[1].__lock);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
v1 = -1;
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func17(pthread_rwlock_t *rwlock)
{
unsigned int v1; // er12

pthread_rwlock_wrlock(rwlock);
v1 = func3(&rwlock[1].__lock);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
v1 = -1;
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
}
return v1;
}

original_code:
int queue_rewrite( rwlock_queue_t* q, void* item ) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_requeue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}

canonical_original_code:
int queue_rewrite(struct rwlock_queue *q, void *item) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_requeue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}


decompiled_code:
__int64 __fastcall queue_read(pthread_rwlock_t *rwlock)
{
__int64 v1; // r12

pthread_rwlock_wrlock(rwlock);
v1 = queue_dequeue(&rwlock[1].__lock);
if ( pthread_rwlock_unlock(rwlock) != -1 )
return v1;
fwrite("queue_read - Failed to release RW lock", 1uLL, 0x26uLL, stderr);
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(pthread_rwlock_t *rwlock)
{
__int64 v1; // r12

pthread_rwlock_wrlock(rwlock);
v1 = func5(&rwlock[1].__lock);
if ( pthread_rwlock_unlock(rwlock) != -1 )
return v1;
fwrite("queue_read - Failed to release RW lock", 1uLL, 0x26uLL, stderr);
return -1LL;
}

original_code:
void* queue_read( rwlock_queue_t* q ) {
 pthread_rwlock_wrlock( &q->rwl );
 void* item = queue_dequeue( &q->q );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_read - Failed to release RW lock");
  return (void*)-1;
 }
 return item;
}

canonical_original_code:
void *queue_read(struct rwlock_queue *q) {
 pthread_rwlock_wrlock( &q->rwl );
 void *item = queue_dequeue( &q->q );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_read - Failed to release RW lock");
  return (void *)-1;
 }
 return item;
}


decompiled_code:
__int64 __fastcall rwlock_queue_search(pthread_rwlock_t *rwlock, unsigned int (__fastcall *a2)(__int64, __int64, __int64), __int64 a3)
{
__int64 v4; // r12

pthread_rwlock_rdlock(rwlock);
v4 = queue_search((__int64)&rwlock[1], a2, a3);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
v4 = 0LL;
fwrite("rwlock_queue_search - Failed to release RW lock", 1uLL, 0x2FuLL, stderr);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func19(pthread_rwlock_t *rwlock, unsigned int (__fastcall *a2)(__int64, __int64, __int64), __int64 a3)
{
__int64 v4; // r12

pthread_rwlock_rdlock(rwlock);
v4 = func6((__int64)&rwlock[1], a2, a3);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
v4 = 0LL;
fwrite("rwlock_queue_search - Failed to release RW lock", 1uLL, 0x2FuLL, stderr);
}
return v4;
}

original_code:
void* rwlock_queue_search( rwlock_queue_t* q, queue_search_cb cb, void* arg ) {
 pthread_rwlock_rdlock( &q->rwl );
 void* item = queue_search( &q->q, cb, arg );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "rwlock_queue_search - Failed to release RW lock");
  return (void*)((void *)0);
 }
 return item;
}

canonical_original_code:
void *rwlock_queue_search(struct rwlock_queue *q, int (*cb)(struct queue *q, void *item, void *arg), void *arg) {
 pthread_rwlock_rdlock( &q->rwl );
 void *item = queue_search( &q->q, cb, arg );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "rwlock_queue_search - Failed to release RW lock");
  return (void *)((void *)0);
 }
 return item;
}