startscrollright

decompiled_code:
int __fastcall startscrollright(char a1, char a2)
{
ssd1306_command(38);
ssd1306_command(0);
ssd1306_command(a1);
ssd1306_command(0);
ssd1306_command(a2);
ssd1306_command(1);
ssd1306_command(255);
return ssd1306_command(47);
}

canonical_decompiled_code:
int __fastcall func15(char a1, char a2)
{
func8(38);
func8(0);
func8(a1);
func8(0);
func8(a2);
func8(1);
func8(255);
return func8(47);
}

original_code:
void startscrollright(uint8_t start, uint8_t stop)
{
    ssd1306_command(0x26);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0XFF);
    ssd1306_command(0x2F);
}

canonical_original_code:
void startscrollright(unsigned char start, unsigned char stop)
{
    ssd1306_command(0x26);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0XFF);
    ssd1306_command(0x2F);
}

variable_types:
start
unsigned char

variable_types:
stop
unsigned char


startscrollleft

repo: catmaker/rpi-displays

decompiled_code:
int __fastcall startscrollleft(char a1, char a2)
{
ssd1306_command(39);
ssd1306_command(0);
ssd1306_command(a1);
ssd1306_command(0);
ssd1306_command(a2);
ssd1306_command(1);
ssd1306_command(255);
return ssd1306_command(47);
}

canonical_decompiled_code:
int __fastcall func16(char a1, char a2)
{
func8(39);
func8(0);
func8(a1);
func8(0);
func8(a2);
func8(1);
func8(255);
return func8(47);
}

original_code:
void startscrollleft(uint8_t start, uint8_t stop)
{
    ssd1306_command(0x27);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0XFF);
    ssd1306_command(0x2F);
}

canonical_original_code:
void startscrollleft(unsigned char start, unsigned char stop)
{
    ssd1306_command(0x27);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0XFF);
    ssd1306_command(0x2F);
}

return_type: void


startscrolldiagright

decompiled_code:
int __fastcall startscrolldiagright(char a1, char a2)
{
ssd1306_command(163);
ssd1306_command(0);
ssd1306_command(32);
ssd1306_command(41);
ssd1306_command(0);
ssd1306_command(a1);
ssd1306_command(0);
ssd1306_command(a2);
ssd1306_command(1);
return ssd1306_command(47);
}

canonical_decompiled_code:
int __fastcall func17(char a1, char a2)
{
func8(163);
func8(0);
func8(32);
func8(41);
func8(0);
func8(a1);
func8(0);
func8(a2);
func8(1);
return func8(47);
}

original_code:
void startscrolldiagright(uint8_t start, uint8_t stop)
{
    ssd1306_command(0xA3);
    ssd1306_command(0X00);
    ssd1306_command(32);
    ssd1306_command(0x29);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0x2F);
}

canonical_original_code:
void startscrolldiagright(unsigned char start, unsigned char stop)
{
    ssd1306_command(0xA3);
    ssd1306_command(0X00);
    ssd1306_command(32);
    ssd1306_command(0x29);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0x2F);
}


startscrolldiagleft

decompiled_code:
int __fastcall startscrolldiagleft(char a1, char a2)
{
ssd1306_command(163);
ssd1306_command(0);
ssd1306_command(32);
ssd1306_command(42);
ssd1306_command(0);
ssd1306_command(a1);
ssd1306_command(0);
ssd1306_command(a2);
ssd1306_command(1);
return ssd1306_command(47);
}

canonical_decompiled_code:
int __fastcall func18(char a1, char a2)
{
func8(163);
func8(0);
func8(32);
func8(42);
func8(0);
func8(a1);
func8(0);
func8(a2);
func8(1);
return func8(47);
}

original_code:
void startscrolldiagleft(uint8_t start, uint8_t stop)
{
    ssd1306_command(0xA3);
    ssd1306_command(0X00);
    ssd1306_command(32);
    ssd1306_command(0x2A);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0x2F);
}

canonical_original_code:
void startscrolldiagleft(unsigned char start, unsigned char stop)
{
    ssd1306_command(0xA3);
    ssd1306_command(0X00);
    ssd1306_command(32);
    ssd1306_command(0x2A);
    ssd1306_command(0X00);
    ssd1306_command(start);
    ssd1306_command(0X00);
    ssd1306_command(stop);
    ssd1306_command(0X01);
    ssd1306_command(0x2F);
}


map

repo: catskillmarina/wanderer

decompiled_code:
int __fastcall map(__int64 a1)
{
int v1; // ebx
_BYTE *v2; // rbp
int v3; // er12
_BYTE *v4; // rbx
chtype v5; // rsi
int v6; // ebx
int v7; // ebp
int v8; // ebx
int result; // eax

v1 = 40;
wmove(stdscr, 0, 0);
waddch(stdscr, 0x2BuLL);
do
{
waddch(stdscr, 0x2DuLL);
--v1;
}
while ( v1 );
v2 = (_BYTE *)(a1 + 40);
v3 = 0;
waddch(stdscr, 0x2BuLL);
do
{
++v3;
v4 = v2 - 40;
wmove(stdscr, v3, 0);
waddch(stdscr, 0x7CuLL);
do
{
while ( 1 )
{
v5 = (unsigned int)(char)*v4;
if ( !debug_disp )
{
if ( *v4 == 77 || *v4 == 83 )
v5 = 32LL;
goto LABEL_7;
}
if ( !*v4 )
break;
LABEL_7:
waddch(stdscr, v5);
if ( ++v4 == v2 )
goto LABEL_11;
}
++v4;
waddch(stdscr, 0x22uLL);
}
while ( v4 != v2 );
LABEL_11:
v2 = v4 + 41;
waddch(stdscr, 0x7CuLL);
}
while ( v3 != 16 );
v6 = 40;
wmove(stdscr, 17, 0);
waddch(stdscr, 0x2BuLL);
do
{
waddch(stdscr, 0x2DuLL);
--v6;
}
while ( v6 );
waddch(stdscr, 0x2BuLL);
v7 = debug_disp;
if ( debug_disp )
return wrefresh(stdscr);
wmove(stdscr, 18, 0);
waddnstr(stdscr, "Press any key to return to the game.", -1);
wrefresh(stdscr);
getchar();
wmove(stdscr, 18, 0);
waddnstr(stdscr, " ", -1);
wrefresh(stdscr);
do
{
v8 = 43;
wmove(stdscr, v7, 0);
do
{
result = waddch(stdscr, 0x20uLL);
--v8;
}
while ( v8 );
++v7;
}
while ( v7 != 18 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int v1; // ebx
_BYTE *v2; // rbp
int v3; // er12
_BYTE *v4; // rbx
chtype v5; // rsi
int v6; // ebx
int v7; // ebp
int v8; // ebx
int result; // eax

v1 = 40;
wmove(stdscr, 0, 0);
waddch(stdscr, 0x2BuLL);
do
{
waddch(stdscr, 0x2DuLL);
--v1;
}
while ( v1 );
v2 = (_BYTE *)(a1 + 40);
v3 = 0;
waddch(stdscr, 0x2BuLL);
do
{
++v3;
v4 = v2 - 40;
wmove(stdscr, v3, 0);
waddch(stdscr, 0x7CuLL);
do
{
while ( 1 )
{
v5 = (unsigned int)(char)*v4;
if ( !debug_disp )
{
if ( *v4 == 77 || *v4 == 83 )
v5 = 32LL;
goto LABEL_7;
}
if ( !*v4 )
break;
LABEL_7:
waddch(stdscr, v5);
if ( ++v4 == v2 )
goto LABEL_11;
}
++v4;
waddch(stdscr, 0x22uLL);
}
while ( v4 != v2 );
LABEL_11:
v2 = v4 + 41;
waddch(stdscr, 0x7CuLL);
}
while ( v3 != 16 );
v6 = 40;
wmove(stdscr, 17, 0);
waddch(stdscr, 0x2BuLL);
do
{
waddch(stdscr, 0x2DuLL);
--v6;
}
while ( v6 );
waddch(stdscr, 0x2BuLL);
v7 = debug_disp;
if ( debug_disp )
return wrefresh(stdscr);
wmove(stdscr, 18, 0);
waddnstr(stdscr, "Press any key to return to the game.", -1);
wrefresh(stdscr);
getchar();
wmove(stdscr, 18, 0);
waddnstr(stdscr, " ", -1);
wrefresh(stdscr);
do
{
v8 = 43;
wmove(stdscr, v7, 0);
do
{
result = waddch(stdscr, 0x20uLL);
--v8;
}
while ( v8 );
++v7;
}
while ( v7 != 18 );
return result;
}

original_code:
void map(char (*row_ptr)[40 +1])
{
    int x,y;
    char ch;
    wmove(stdscr,(0),(0));
    waddch(stdscr,('+'));
    for(x = 0;x < 40; x++)
        waddch(stdscr,('-'));
    waddch(stdscr,('+'));
    for(y = 0;y < 16; y++)
    {
        wmove(stdscr,(y+1),(0));
        waddch(stdscr,('|'));
        for(x = 0; x < 40; x++)
        {
            ch = (*row_ptr)[x];
            if(!debug_disp)
            {
                if((ch == 'M')||(ch == 'S'))
                    ch = ' ';
                waddch(stdscr,(ch));
            }
            else
                if(ch!='\0')
                    waddch(stdscr,(ch));
                else
                    waddch(stdscr,('"'));
        }
        waddch(stdscr,('|'));
        row_ptr++;
    }
    wmove(stdscr,(y+1),(0));
    waddch(stdscr,('+'));
    for(x = 0;x < 40; x++)
        waddch(stdscr,('-'));
    waddch(stdscr,('+'));
    if(!debug_disp)
    {
        wmove(stdscr,(18),(0));
        waddnstr(stdscr,("Press any key to return to the game."),-1);
        wrefresh(stdscr);
        getchar();
        wmove(stdscr,(18),(0));
        waddnstr(stdscr,("                                    "),-1);
        wrefresh(stdscr);
        for(y=0;y<=(16 +1);y++)
        {
            wmove(stdscr,(y),(0));
            for(x=0;x<=(40 +2);x++)
                waddch(stdscr,(' '));
        }
    }
    else
        wrefresh(stdscr);
}

canonical_original_code:
void map(char (*row_ptr)[-1])
{
    int x; int y;
    char ch;
    wmove(stdscr,(0),(0));
    waddch(stdscr,('+'));
    for(x = 0;x < 40; x++)
        waddch(stdscr,('-'));
    waddch(stdscr,('+'));
    for(y = 0;y < 16; y++)
    {
        wmove(stdscr,(y+1),(0));
        waddch(stdscr,('|'));
        for(x = 0; x < 40; x++)
        {
            ch = (*row_ptr)[x];
            if(!debug_disp)
            {
                if((ch == 'M')||(ch == 'S'))
                    ch = ' ';
                waddch(stdscr,(ch));
            }
            else
                if(ch!='\0')
                    waddch(stdscr,(ch));
                else
                    waddch(stdscr,('"'));
        }
        waddch(stdscr,('|'));
        row_ptr++;
    }
    wmove(stdscr,(y+1),(0));
    waddch(stdscr,('+'));
    for(x = 0;x < 40; x++)
        waddch(stdscr,('-'));
    waddch(stdscr,('+'));
    if(!debug_disp)
    {
        wmove(stdscr,(18),(0));
        waddnstr(stdscr,("Press any key to return to the game."),-1);
        wrefresh(stdscr);
        getchar();
        wmove(stdscr,(18),(0));
        waddnstr(stdscr,("                                    "),-1);
        wrefresh(stdscr);
        for(y=0;y<=(16 +1);y++)
        {
            wmove(stdscr,(y),(0));
            for(x=0;x<=(40 +2);x++)
                waddch(stdscr,(' '));
        }
    }
    else
        wrefresh(stdscr);
}

variable_types: x int

variable_types: y int

variable_types: ch char


display

variable_types: cx int

variable_types: cy int

variable_types: score long


showname

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

wmove(stdscr, 19, 0);
if ( screen_name == 35 || !screen_name )
{
result = waddnstr(stdscr, "Unnamed screen. ", -1);
if ( !edit_memory )
return result;
}
else
{
result = waddnstr(stdscr, &screen_name, -1);
if ( !edit_memory )
return result;
}
wmove(stdscr, 7, 45);
waddnstr(stdscr, "MEMORY: ( Start, ) End,", -1);
wmove(stdscr, 8, 53);
waddnstr(stdscr, "* Play, & Extend.", -1);
wmove(stdscr, 9, 53);
waddnstr(stdscr, "- Chkpt, + Cont.", -1);
wmove(stdscr, 10, 53);
if ( memory_end == edit_memory )
result = waddnstr(stdscr, "--Empty--", -1);
else
result = waddnstr(stdscr, "-Occupied-", -1);
return result;
}

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

wmove(stdscr, 19, 0);
if ( screen_name == 35 || !screen_name )
{
result = waddnstr(stdscr, "Unnamed screen. ", -1);
if ( !edit_memory )
return result;
}
else
{
result = waddnstr(stdscr, &screen_name, -1);
if ( !edit_memory )
return result;
}
wmove(stdscr, 7, 45);
waddnstr(stdscr, "MEMORY: ( Start, ) End,", -1);
wmove(stdscr, 8, 53);
waddnstr(stdscr, "* Play, & Extend.", -1);
wmove(stdscr, 9, 53);
waddnstr(stdscr, "- Chkpt, + Cont.", -1);
wmove(stdscr, 10, 53);
if ( memory_end == edit_memory )
result = waddnstr(stdscr, "--Empty--", -1);
else
result = waddnstr(stdscr, "-Occupied-", -1);
return result;
}

original_code:
void showname()
{
    wmove(stdscr,(19),(0));
    if(( screen_name[0] == '#' )||(screen_name[0] == '\0'))
    {
        waddnstr(stdscr,("Unnamed screen.                         "),-1);
    }
    else
        waddnstr(stdscr,(screen_name),-1);
    if( edit_memory )
    {
        wmove(stdscr,(7),(45));
        waddnstr(stdscr,("MEMORY: ( Start, ) End,"),-1);
        wmove(stdscr,(8),(53));
        waddnstr(stdscr,("* Play, & Extend."),-1);
        wmove(stdscr,(9),(53));
        waddnstr(stdscr,("- Chkpt, + Cont."),-1);
        wmove(stdscr,(10),(53));
        if( memory_end == edit_memory )
        {
            waddnstr(stdscr,("--Empty--"),-1);
        }
        else
        {
            waddnstr(stdscr,("-Occupied-"),-1);
        }
    }
}


decompiled_code:
_BOOL8 __fastcall inform_me(char *a1, int a2)
{
int v2; // ebx

wmove(stdscr, 20, 0);
wattrset(stdscr, 0x10000);
waddnstr(stdscr, a1, -1);
wattrset(stdscr, 0);
waddnstr(stdscr, " <MORE>", -1);
if ( a2 )
waddnstr(stdscr, " (q stops)", -1);
wrefresh(stdscr);
v2 = wgetch(stdscr);
wmove(stdscr, 20, 0);
waddnstr(stdscr, " ", -1);
wrefresh(stdscr);
return v2 == 113;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *a1, int a2)
{
int v2; // ebx

wmove(stdscr, 20, 0);
wattrset(stdscr, 0x10000);
waddnstr(stdscr, a1, -1);
wattrset(stdscr, 0);
waddnstr(stdscr, " <MORE>", -1);
if ( a2 )
waddnstr(stdscr, " (q stops)", -1);
wrefresh(stdscr);
v2 = wgetch(stdscr);
wmove(stdscr, 20, 0);
waddnstr(stdscr, " ", -1);
wrefresh(stdscr);
return v2 == 113;
}

original_code:
int inform_me(char *s, int qable)
{
    int retval = 0;
    wmove(stdscr,(20),(0));
    (wattrset(stdscr,((chtype)((1U)) << ((8) + 8))));
    waddnstr(stdscr,(s),-1);
    (wattrset(stdscr,(1U - 1U)));
    waddnstr(stdscr,(" <MORE>"),-1);
    if(qable)
        waddnstr(stdscr,(" (q stops)"),-1);
    wrefresh(stdscr);
    if( wgetch(stdscr) == 'q' )
        retval = 1;
    wmove(stdscr,(20),(0)); waddnstr(stdscr,("                                                                             "),-1);
    wrefresh(stdscr);
    return(retval);
}

variable_types:
s
char *

variable_types: qable int

variable_types: retval int

return_type: int


readline

decompiled_code:
__int64 __fastcall readline(int fd, void *buf, unsigned int a3)
{
char *v4; // r13
unsigned int v5; // er12
char *i; // rbx
__int64 result; // rax

v4 = (char *)buf + a3 - 1;
v5 = 0;
for ( i = (char *)buf; ; ++i )
{
if ( (unsigned int)read(fd, i, 1uLL) != 1 )
{
LABEL_6:
result = v5;
*i = 0;
return result;
}
++v5;
if ( i == v4 )
break;
if ( *i == 10 )
goto LABEL_6;
}
*i = 0;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, unsigned int a3)
{
char *v4; // r13
unsigned int v5; // er12
char *i; // rbx
__int64 result; // rax

v4 = (char *)buf + a3 - 1;
v5 = 0;
for ( i = (char *)buf; ; ++i )
{
if ( (unsigned int)read(fd, i, 1uLL) != 1 )
{
LABEL_6:
result = v5;
*i = 0;
return result;
}
++v5;
if ( i == v4 )
break;
if ( *i == 10 )
goto LABEL_6;
}
*i = 0;
return a3;
}

original_code:
int readline(int fd,char *ptr,int max)
{
  int count=0;
  while(read(fd,ptr,1)==1)
  {
    if(++count==max)
      break;
    if(*ptr=='\n')
      break;
    ptr++;
  }
  *ptr='\0';
  return count;
}

canonical_original_code:
int readline(int fd, char *ptr, int max)
{
  int count = 0;
  while(read(fd,ptr,1)==1)
  {
    if(++count==max)
      break;
    if(*ptr=='\n')
      break;
    ptr++;
  }
  *ptr='\0';
  return count;
}

variable_types: fd int

variable_types:
ptr
char *

variable_types: max int

variable_types: count int


decompiled_code:
char *get_name()
{
signed int v0; // eax
char *v1; // r12

v0 = (unsigned int)getenv("NEWNAME");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("NAME");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("FULLNAME");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("USER");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("LOGNAME");
if ( v0 )
return (char *)v0;
v1 = (char *)malloc(0x50uLL);
if ( !v1 )
{
puts("malloc error");
exit(1);
}
printf("Name? ");
fflush(stdout);
fgets(v1, 80, stdin);
if ( !*v1 )
v1 = "noname";
return v1;
}

canonical_decompiled_code:
char *func2()
{
signed int v0; // eax
char *v1; // r12

v0 = (unsigned int)getenv("NEWNAME");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("NAME");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("FULLNAME");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("USER");
if ( v0 )
return (char *)v0;
v0 = (unsigned int)getenv("LOGNAME");
if ( v0 )
return (char *)v0;
v1 = (char *)malloc(0x50uLL);
if ( !v1 )
{
puts("malloc error");
exit(1);
}
printf("Name? ");
fflush(stdout);
fgets(v1, 80, stdin);
if ( !*v1 )
v1 = "noname";
return v1;
}

original_code:
char *get_name(void)
{
char *name;
char *endchar;
    if((name = (char *)getenv("NEWNAME")) == ((void *)0))
        if((name = (char *)getenv("NAME")) == ((void *)0))
            if((name = (char *)getenv("FULLNAME")) == ((void *)0))
                if((name = (char *)getenv("USER")) == ((void *)0))
                          if((name = (char *)getenv("LOGNAME")) == ((void *)0))
                    {
                        name = (char *)malloc(80);
                        if (name == ((void *)0)) {
                            printf("malloc error\n");
                            exit(1);
                        }
                        printf("Name? "); fflush(stdout);
                        fgets(name,80,stdin);
                        endchar=strchr(name,'\0');
                        endchar='\0';
                        if (name[0] == '\0')
                            name = "noname";
                    }
    return(name);
}

canonical_original_code:
char *get_name()
{
char *name;
char *endchar;
    if((name = (char *)getenv("NEWNAME")) == ((void *)0))
        if((name = (char *)getenv("NAME")) == ((void *)0))
            if((name = (char *)getenv("FULLNAME")) == ((void *)0))
                if((name = (char *)getenv("USER")) == ((void *)0))
                          if((name = (char *)getenv("LOGNAME")) == ((void *)0))
                    {
                        name = (char *)malloc(80);
                        if (name == ((void *)0)) {
                            printf("malloc error\n");
                            exit(1);
                        }
                        printf("Name? "); fflush(stdout);
                        fgets(name,80,stdin);
                        endchar=strchr(name,'\0');
                        endchar='\0';
                        if (name[0] == '\0')
                            name = "noname";
                    }
    return(name);
}

variable_types:
name
char *

variable_types:
endchar
char *

return_type: char *


decompiled_code:
char *get_keys()
{
char *result; // rax

LODWORD(result) = (unsigned int)getenv("NEWKEYS");
if ( (_DWORD)result )
return (char *)(int)result;
result = (char *)malloc(5uLL);
strcpy(result, "kjhl");
return result;
}

canonical_decompiled_code:
char *func3()
{
char *result; // rax

LODWORD(result) = (unsigned int)getenv("NEWKEYS");
if ( (_DWORD)result )
return (char *)(int)result;
result = (char *)malloc(5uLL);
strcpy(result, "kjhl");
return result;
}

original_code:
char *get_keys()
{
    char *keys = ((void *)0);
    if( ! keys ) {
        if((keys = (char *)getenv("NEWKEYS")) == ((void *)0))
            {
            keys = (char *)malloc(5);
           strcpy(keys,"kjhl");
            }
    }
    return(keys);
}

variable_types:
keys
char *


getnum

decompiled_code:
__int64 getnum()
{
unsigned int v0; // er12
char v1; // bl
int v2; // ebp
char v3; // bl

v0 = 0;
v1 = wgetch(stdscr);
v2 = v1;
waddch(stdscr, (unsigned int)v1);
wrefresh(stdscr);
if ( (unsigned __int8)(v1 - 48) <= 9u )
{
do
{
v0 = v2 + 10 * v0 - 48;
v3 = wgetch(stdscr);
v2 = v3;
waddch(stdscr, (unsigned int)v3);
wrefresh(stdscr);
}
while ( (unsigned __int8)(v3 - 48) <= 9u );
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
char v1; // bl
int v2; // ebp
char v3; // bl

v0 = 0;
v1 = wgetch(stdscr);
v2 = v1;
waddch(stdscr, (unsigned int)v1);
wrefresh(stdscr);
if ( (unsigned __int8)(v1 - 48) <= 9u )
{
do
{
v0 = v2 + 10 * v0 - 48;
v3 = wgetch(stdscr);
v2 = v3;
waddch(stdscr, (unsigned int)v3);
wrefresh(stdscr);
}
while ( (unsigned __int8)(v3 - 48) <= 9u );
}
return v0;
}

original_code:
int getnum()
{
    char ch;
    int num = 0;
    for(ch = wgetch(stdscr),waddch(stdscr,(ch)),wrefresh(stdscr);
        ch >= '0' && ch <= '9';
        ch = wgetch(stdscr),waddch(stdscr,(ch)),wrefresh(stdscr))
    {
        num = num * 10 + ch - '0';
    }
    return num;
}

variable_types: num int


original_code:
void show_scores(score_entry *table,int num)
{
    int tot = num;
    printf("\nNo. Score Level           Names                 How they died\n");
    printf("=============================================================================\n");
    while(num > 0)
    {
        num--;
        printf("%2d %5d %3d      %-20s     killed by %-s\n",(tot - num),table->score,table->level,table->name,table->howdead);
        table++;
    }
    printf("\n\n");
}

canonical_original_code:
void show_scores(struct score_entry *table, int num)
{
    int tot = num;
    printf("\nNo. Score Level           Names                 How they died\n");
    printf("=============================================================================\n");
    while(num > 0)
    {
        num--;
        printf("%2d %5d %3d      %-20s     killed by %-s\n",(tot - num),table->score,table->level,table->name,table->howdead);
        table++;
    }
    printf("\n\n");
}

variable_types: struct score_entry { char howdead[25]; char name[20]; int score; int level; int uid; } *

variable_types: tot int


handler

decompiled_code:
void __fastcall __noreturn handler(unsigned int a1)
{
__int64 i; // rsi
pthread_t *v2; // rax

printf("Hello, signal %d!\n", a1);
printf("list size = %d\n", *(unsigned int *)thread_pool);
for ( i = *(unsigned int *)thread_pool; (int)i > 0; i = *(unsigned int *)thread_pool )
{
v2 = (pthread_t *)list_pop();
pthread_join(*v2, 0LL);
}
printf("list size = %d\n", i);
destroy_list(thread_pool);
destroy_list(clients);
destroy_list(master_list);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
__int64 i; // rsi
pthread_t *v2; // rax

printf("Hello, signal %d!\n", a1);
printf("list size = %d\n", *(unsigned int *)thread_pool);
for ( i = *(unsigned int *)thread_pool; (int)i > 0; i = *(unsigned int *)thread_pool )
{
v2 = (pthread_t *)list_pop();
pthread_join(*v2, 0LL);
}
printf("list size = %d\n", i);
destroy_list(thread_pool);
destroy_list(clients);
destroy_list(master_list);
exit(0);
}

original_code:
static void handler(int signum) {
 printf("Hello, signal %d!\n", signum);
 printf("list size = %d\n", thread_pool->length);
 while (thread_pool->length > 0) {
  pthread_t *thread_ptr = list_pop(thread_pool);
  pthread_join(*thread_ptr, ((void *)0));
 }
 printf("list size = %d\n", thread_pool->length);
 destroy_list(thread_pool);
 destroy_list(clients);
 destroy_list(master_list);
 exit(0);
}

canonical_original_code:
static void handler(int signum) {
 printf("Hello, signal %d!\n", signum);
 printf("list size = %d\n", thread_pool->length);
 while (thread_pool->length > 0) {
  unsigned long *thread_ptr = list_pop(thread_pool);
  pthread_join(*thread_ptr, ((void *)0));
 }
 printf("list size = %d\n", thread_pool->length);
 destroy_list(thread_pool);
 destroy_list(clients);
 destroy_list(master_list);
 exit(0);
}

variable_types: signum int


decompiled_code:
__int64 __fastcall client_exists(char *s1)
{
__int64 v1; // rbx
const char *v2; // rsi
__int64 result; // rax

v1 = list_iterator(clients, 0LL);
while ( 1 )
{
result = list_next(v1);
if ( !result )
break;
v2 = (const char *)list_current(v1);
if ( !strcmp(s1, v2) )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
__int64 v1; // rbx
const char *v2; // rsi
__int64 result; // rax

v1 = list_iterator(clients, 0LL);
while ( 1 )
{
result = list_next(v1);
if ( !result )
break;
v2 = (const char *)list_current(v1);
if ( !strcmp(s1, v2) )
return 1LL;
}
return result;
}

original_code:
int client_exists(char *name) {
 list_iter_p iter = list_iterator(clients, 0);
 while (list_next(iter) != ((void *)0)) {
  client_t *client = list_current(iter);
  if (strcmp(name, client->name) == 0) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int client_exists(char *name) {
 struct list_iter *iter = list_iterator(clients, 0);
 while (list_next(iter) != ((void *)0)) {
  struct client *client = list_current(iter);
  if (strcmp(name, client->name) == 0) {
   return 1;
  }
 }
 return 0;
}

variable_types: struct list_iter { struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *current; char started; } *

variable_types: struct client { char name[64]; char listen_port[24]; int sock; } *

user_defined_types: struct list_iter { struct linked_node *current; char started; }


decompiled_code:
__int64 __fastcall get_client_by_sock(int a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = list_iterator(clients, 0LL);
do
{
result = list_next(v1);
if ( !result )
break;
result = list_current(v1);
}
while ( *(_DWORD *)(result + 88) != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = list_iterator(clients, 0LL);
do
{
result = list_next(v1);
if ( !result )
break;
result = list_current(v1);
}
while ( *(_DWORD *)(result + 88) != a1 );
return result;
}

original_code:
client_t *get_client_by_sock(int sock) {
 list_iter_p iter = list_iterator(clients, 0);
 while (list_next(iter) != ((void *)0)) {
  client_t *client = list_current(iter);
  if (sock == client->sock) {
   return client;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct client *get_client_by_sock(int sock) {
 struct list_iter *iter = list_iterator(clients, 0);
 while (list_next(iter) != ((void *)0)) {
  struct client *client = list_current(iter);
  if (sock == client->sock) {
   return client;
  }
 }
 return ((void *)0);
}

variable_types: sock int

return_type: struct client { char name[64]; char listen_port[24]; int sock; } *

user_defined_types: struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; }


decompiled_code:
__int64 print_client_list()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 result; // rax

v0 = list_iterator(clients, 0LL);
puts("--- Clients ---");
while ( 1 )
{
result = list_next(v0);
if ( !result )
break;
v1 = list_current(v0);
printf("%s, %s, %d\n", (const char *)v1, (const char *)(v1 + 64), *(unsigned int *)(v1 + 88));
}
return result;
}

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

v0 = list_iterator(clients, 0LL);
puts("--- Clients ---");
while ( 1 )
{
result = list_next(v0);
if ( !result )
break;
v1 = list_current(v0);
printf("%s, %s, %d\n", (const char *)v1, (const char *)(v1 + 64), *(unsigned int *)(v1 + 88));
}
return result;
}

original_code:
void print_client_list() {
 list_iter_p iter = list_iterator(clients, 0);
 printf("--- Clients ---\n");
 while (list_next(iter) != ((void *)0)) {
  client_t *client = list_current(iter);
  printf("%s, %s, %d\n", client->name, client->listen_port, client->sock);
 }
}

canonical_original_code:
void print_client_list() {
 struct list_iter *iter = list_iterator(clients, 0);
 printf("--- Clients ---\n");
 while (list_next(iter) != ((void *)0)) {
  struct client *client = list_current(iter);
  printf("%s, %s, %d\n", client->name, client->listen_port, client->sock);
 }
}

user_defined_types: struct client { char name[64]; char listen_port[24]; int sock; }


decompiled_code:
__int64 __fastcall reg_client(__int64 a1, int a2)
{
char v3[32]; // [rsp+0h] [rbp-C8h] BYREF
char src[64]; // [rsp+20h] [rbp-A8h] BYREF
char dest[64]; // [rsp+60h] [rbp-68h] BYREF
char v6[24]; // [rsp+A0h] [rbp-28h] BYREF
int v7; // [rsp+B8h] [rbp-10h]

_isoc99_sscanf(a1, "%s %s", src, v3);
strncpy(dest, src, 0x40uLL);
strncpy(v6, v3, 0x18uLL);
v7 = a2;
list_add(clients, dest, 92LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
char v3[32]; // [rsp+0h] [rbp-C8h] BYREF
char src[64]; // [rsp+20h] [rbp-A8h] BYREF
char dest[64]; // [rsp+60h] [rbp-68h] BYREF
char v6[24]; // [rsp+A0h] [rbp-28h] BYREF
int v7; // [rsp+B8h] [rbp-10h]

_isoc99_sscanf(a1, "%s %s", src, v3);
strncpy(dest, src, 0x40uLL);
strncpy(v6, v3, 0x18uLL);
v7 = a2;
list_add(clients, dest, 92LL);
return 0LL;
}

original_code:
int reg_client(char *str, int sock) {
 char name[64];
 char port[24];
 client_t client;
 sscanf(str, "%s %s", name, port);
 strncpy(client.name, name, sizeof(client.name));
 strncpy(client.listen_port, port, sizeof(client.listen_port));
 client.sock = sock;
 list_add(clients, &client, sizeof(client));
 return 0;
}

canonical_original_code:
int reg_client(char *str, int sock) {
 char name[64];
 char port[24];
 struct client client;
 sscanf(str, "%s %s", name, port);
 strncpy(client.name, name, sizeof(client.name));
 strncpy(client.listen_port, port, sizeof(client.listen_port));
 client.sock = sock;
 list_add(clients, &client, sizeof(client));
 return 0;
}

variable_types:
str
char *

variable_types:
name
char [64]

variable_types:
port
char [24]

variable_types: struct client { char name[64]; char listen_port[24]; int sock; }


decompiled_code:
__int64 __fastcall remove_client(char *s1)
{
_QWORD *v1; // rbx
const char *v2; // rax
__int64 result; // rax
void *v4; // rax

v1 = (_QWORD *)list_iterator(clients, 0LL);
while ( 1 )
{
result = list_next(v1);
if ( !result )
break;
v2 = (const char *)list_current(v1);
if ( !strcmp(s1, v2) )
{
v4 = (void *)list_current(v1);
free(v4);
return list_pluck(clients, *v1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1)
{
_QWORD *v1; // rbx
const char *v2; // rax
__int64 result; // rax
void *v4; // rax

v1 = (_QWORD *)list_iterator(clients, 0LL);
while ( 1 )
{
result = list_next(v1);
if ( !result )
break;
v2 = (const char *)list_current(v1);
if ( !strcmp(s1, v2) )
{
v4 = (void *)list_current(v1);
free(v4);
return list_pluck(clients, *v1);
}
}
return result;
}

original_code:
void remove_client(char *name) {
 list_iter_p iter = list_iterator(clients, 0);
 while (list_next(iter) != ((void *)0)) {
  client_t *client = list_current(iter);
  if (strcmp(name, client->name) == 0) {
   free(list_current(iter));
   list_pluck(clients, iter->current);
   break;
  }
 }
}

canonical_original_code:
void remove_client(char *name) {
 struct list_iter *iter = list_iterator(clients, 0);
 while (list_next(iter) != ((void *)0)) {
  struct client *client = list_current(iter);
  if (strcmp(name, client->name) == 0) {
   free(list_current(iter));
   list_pluck(clients, iter->current);
   break;
  }
 }
}


decompiled_code:
__int64 __fastcall add_files(int fd, char *s)
{
const char *v2; // rbx
char *v3; // rax
char *v4; // rbp
char *v5; // r12
char *v6; // rax
__int64 result; // rax
socklen_t len; // [rsp+Ch] [rbp-110Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-1108h] BYREF
char dest[32]; // [rsp+20h] [rbp-10F8h] BYREF
char v11[4096]; // [rsp+40h] [rbp-10D8h] BYREF
char v12[64]; // [rsp+1040h] [rbp-D8h] BYREF
char v13[64]; // [rsp+1080h] [rbp-98h] BYREF
char v14[24]; // [rsp+10C0h] [rbp-58h] BYREF
char v15[64]; // [rsp+10D8h] [rbp-40h] BYREF

len = 16;
v2 = (const char *)get_client_by_sock(fd);
if ( getpeername(fd, &addr, &len) < 0 )
{
perror("getpeername");
result = 0xFFFFFFFFLL;
}
else
{
v3 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strncpy(dest, v3, 0x18uLL);
v4 = strtok(s, " ");
v5 = strtok(0LL, " ");
if ( v5 && v4 )
{
do
{
strncpy(v11, v4, 0x1000uLL);
strncpy(v14, dest, 0x18uLL);
strncpy(v13, v2, 0x40uLL);
strncpy(v15, v2 + 64, 0x18uLL);
strncpy(v12, v5, 0x40uLL);
list_add(master_list, v11, 4272LL);
v4 = strtok(0LL, " ");
v6 = strtok(0LL, " ");
v5 = v6;
}
while ( v4 && v6 );
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, char *s)
{
const char *v2; // rbx
char *v3; // rax
char *v4; // rbp
char *v5; // r12
char *v6; // rax
__int64 result; // rax
socklen_t len; // [rsp+Ch] [rbp-110Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-1108h] BYREF
char dest[32]; // [rsp+20h] [rbp-10F8h] BYREF
char v11[4096]; // [rsp+40h] [rbp-10D8h] BYREF
char v12[64]; // [rsp+1040h] [rbp-D8h] BYREF
char v13[64]; // [rsp+1080h] [rbp-98h] BYREF
char v14[24]; // [rsp+10C0h] [rbp-58h] BYREF
char v15[64]; // [rsp+10D8h] [rbp-40h] BYREF

len = 16;
v2 = (const char *)func3(fd);
if ( getpeername(fd, &addr, &len) < 0 )
{
perror("getpeername");
result = 0xFFFFFFFFLL;
}
else
{
v3 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strncpy(dest, v3, 0x18uLL);
v4 = strtok(s, " ");
v5 = strtok(0LL, " ");
if ( v5 && v4 )
{
do
{
strncpy(v11, v4, 0x1000uLL);
strncpy(v14, dest, 0x18uLL);
strncpy(v13, v2, 0x40uLL);
strncpy(v15, v2 + 64, 0x18uLL);
strncpy(v12, v5, 0x40uLL);
list_add(master_list, v11, 4272LL);
v4 = strtok(0LL, " ");
v6 = strtok(0LL, " ");
v5 = v6;
}
while ( v4 && v6 );
}
result = 0LL;
}
return result;
}

original_code:
int add_files(int sock, char *data) {
 client_t *client;
 ml_entry_t entry;
 char *filename;
 char ip[24];
 char *bytes;
 struct sockaddr_in addr;
 socklen_t len = sizeof(addr);
 int first = 1;
 client = get_client_by_sock(sock);
 if (getpeername(sock, (struct sockaddr *) &addr, &len) < 0) {
  perror("getpeername");
  return -1;
 }
 strncpy(ip, inet_ntoa(addr.sin_addr), sizeof(ip));
 while (1) {
  if (first) {
   filename = strtok(data, " ");
   bytes = strtok(((void *)0), " ");
   first = 0;
  } else {
   filename = strtok(((void *)0), " ");
   bytes = strtok(((void *)0), " ");
  }
  if (filename == ((void *)0) || bytes == ((void *)0)) {
   break;
  }
  strncpy(entry.filename, filename, sizeof(entry.filename));
  strncpy(entry.ip, ip, sizeof(entry.ip));
  strncpy(entry.owner, client->name, sizeof(entry.owner));
  strncpy(entry.port, client->listen_port, sizeof(entry.port));
  strncpy(entry.size, bytes, sizeof(entry.size));
  list_add(master_list, &entry, sizeof(entry));
 }
 return 0;
}

canonical_original_code:
int add_files(int sock, char *data) {
 struct client *client;
 struct master_list_entry entry;
 char *filename;
 char ip[24];
 char *bytes;
 struct sockaddr_in addr;
 unsigned int len = sizeof(addr);
 int first = 1;
 client = get_client_by_sock(sock);
 if (getpeername(sock, (struct sockaddr *) &addr, &len) < 0) {
  perror("getpeername");
  return -1;
 }
 strncpy(ip, inet_ntoa(addr.sin_addr), sizeof(ip));
 while (1) {
  if (first) {
   filename = strtok(data, " ");
   bytes = strtok(((void *)0), " ");
   first = 0;
  } else {
   filename = strtok(((void *)0), " ");
   bytes = strtok(((void *)0), " ");
  }
  if (filename == ((void *)0) || bytes == ((void *)0)) {
   break;
  }
  strncpy(entry.filename, filename, sizeof(entry.filename));
  strncpy(entry.ip, ip, sizeof(entry.ip));
  strncpy(entry.owner, client->name, sizeof(entry.owner));
  strncpy(entry.port, client->listen_port, sizeof(entry.port));
  strncpy(entry.size, bytes, sizeof(entry.size));
  list_add(master_list, &entry, sizeof(entry));
 }
 return 0;
}

variable_types:
data
char *

variable_types: struct master_list_entry { char filename[4096]; char size[64]; char owner[64]; char ip[24]; char port[24]; }

variable_types:
filename
char *

variable_types:
ip
char [24]

variable_types:
bytes
char *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
len
unsigned int

variable_types: first int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall create_file_list(char *dest)
{
__int64 v1; // rbx
const char *v2; // rax
__int64 result; // rax
char s[4328]; // [rsp+0h] [rbp-10E8h] BYREF

v1 = list_iterator(master_list, 0LL);
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC8);
*((__m128i *)dest + 1) = _mm_load_si128((const __m128i *)&LC9);
*((__m128i *)dest + 2) = _mm_load_si128((const __m128i *)&LC10);
*((__m128i *)dest + 3) = _mm_load_si128((const __m128i *)&LC11);
while ( 1 )
{
result = list_next(v1);
if ( !result )
break;
v2 = (const char *)list_current(v1);
sprintf(s, "%s || %s || %s || %s || %s\n", v2, v2 + 4096, v2 + 4160, v2 + 4224, v2 + 4248);
strcat(dest, s);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *dest)
{
__int64 v1; // rbx
const char *v2; // rax
__int64 result; // rax
char s[4328]; // [rsp+0h] [rbp-10E8h] BYREF

v1 = list_iterator(master_list, 0LL);
*(__m128i *)dest = _mm_load_si128((const __m128i *)&LC8);
*((__m128i *)dest + 1) = _mm_load_si128((const __m128i *)&LC9);
*((__m128i *)dest + 2) = _mm_load_si128((const __m128i *)&LC10);
*((__m128i *)dest + 3) = _mm_load_si128((const __m128i *)&LC11);
while ( 1 )
{
result = list_next(v1);
if ( !result )
break;
v2 = (const char *)list_current(v1);
sprintf(s, "%s || %s || %s || %s || %s\n", v2, v2 + 4096, v2 + 4160, v2 + 4224, v2 + 4248);
strcat(dest, s);
}
return result;
}

original_code:
void create_file_list(char *buf) {
 list_iter_p iter = list_iterator(master_list, 0);
 char line[sizeof(ml_entry_t) + 18];
 sprintf(buf, "File Name || File Size || File Owner || Owner IP || Owner Port\n");
 while (list_next(iter) != ((void *)0)) {
  ml_entry_t *entry = list_current(iter);
  sprintf(line, "%s || %s || %s || %s || %s\n",
    entry->filename, entry->size, entry->owner, entry->ip, entry->port);
  strcat(buf, line);
 }
}

canonical_original_code:
void create_file_list(char *buf) {
 struct list_iter *iter = list_iterator(master_list, 0);
 char line[-1];
 sprintf(buf, "File Name || File Size || File Owner || Owner IP || Owner Port\n");
 while (list_next(iter) != ((void *)0)) {
  struct master_list_entry *entry = list_current(iter);
  sprintf(line, "%s || %s || %s || %s || %s\n",
    entry->filename, entry->size, entry->owner, entry->ip, entry->port);
  strcat(buf, line);
 }
}

variable_types:
buf
char *

variable_types:
line
char [-1]

variable_types: struct master_list_entry { char filename[4096]; char size[64]; char owner[64]; char ip[24]; char port[24]; } *


decompiled_code:
void print_file_list()
{
char *v0; // rbp

v0 = (char *)malloc(0x6400uLL);
create_file_list(v0);
puts(v0);
free(v0);
}

canonical_decompiled_code:
void func9()
{
char *v0; // rbp

v0 = (char *)malloc(0x6400uLL);
func8(v0);
puts(v0);
free(v0);
}

original_code:
void print_file_list() {
 char *buf;
 buf = malloc(1024 * 25);
 create_file_list(buf);
 printf("%s\n", buf);
 free(buf);
}


decompiled_code:
__int64 __fastcall perform_ls(int fd)
{
_QWORD *v1; // rax
__int64 result; // rax
_QWORD *v3; // [rsp+0h] [rbp-18h] BYREF
void *ptr; // [rsp+8h] [rbp-10h] BYREF

v1 = (_QWORD *)create_packet_header();
v3 = v1;
ptr = 0LL;
v1[1] = 3LL;
*v1 = 0LL;
if ( (int)send_packet((unsigned int)fd, &unk_8AF, 0LL, v1) < 0 )
{
perror("send_packet");
result = 0xFFFFFFFFLL;
}
else
{
toreceive((unsigned int)fd, 0LL, &v3, &ptr, 1LL, 0LL);
if ( *((_DWORD *)v3 + 3) == 1 )
{
if ( ptr )
{
printf("Buffer = %s\n", (const char *)ptr);
add_files(fd, (char *)ptr);
}
destroy_packet_header();
free(ptr);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd)
{
_QWORD *v1; // rax
__int64 result; // rax
_QWORD *v3; // [rsp+0h] [rbp-18h] BYREF
void *ptr; // [rsp+8h] [rbp-10h] BYREF

v1 = (_QWORD *)create_packet_header();
v3 = v1;
ptr = 0LL;
v1[1] = 3LL;
*v1 = 0LL;
if ( (int)send_packet((unsigned int)fd, &unk_8AF, 0LL, v1) < 0 )
{
perror("send_packet");
result = 0xFFFFFFFFLL;
}
else
{
toreceive((unsigned int)fd, 0LL, &v3, &ptr, 1LL, 0LL);
if ( *((_DWORD *)v3 + 3) == 1 )
{
if ( ptr )
{
printf("Buffer = %s\n", (const char *)ptr);
func7(fd, (char *)ptr);
}
destroy_packet_header();
free(ptr);
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int perform_ls(int sock) {
 packet_header_p ph = create_packet_header();
 void *buf = ((void *)0);
 ph->command = 3;
 ph->error = 0;
 ph->flags = 0;
 ph->length = 0;
 if (send_packet(sock, "", 0, ph) < 0) {
  perror("send_packet");
  return -1;
 }
 toreceive(sock, 0, &ph, &buf, 1, 0);
 if (ph->error != 1) {
  return -1;
 }
 if (buf != ((void *)0)) {
  printf("Buffer = %s\n", (char *) buf);
  add_files(sock, (char *) buf);
 }
 destroy_packet_header(ph);
 free(buf);
 return 0;
}

canonical_original_code:
int perform_ls(int sock) {
 struct packet_header *ph = create_packet_header();
 void *buf = ((void *)0);
 ph->command = 3;
 ph->error = 0;
 ph->flags = 0;
 ph->length = 0;
 if (send_packet(sock, "", 0, ph) < 0) {
  perror("send_packet");
  return -1;
 }
 toreceive(sock, 0, &ph, &buf, 1, 0);
 if (ph->error != 1) {
  return -1;
 }
 if (buf != ((void *)0)) {
  printf("Buffer = %s\n", (char *) buf);
  add_files(sock, (char *) buf);
 }
 destroy_packet_header(ph);
 free(buf);
 return 0;
}

variable_types: struct packet_header { int flags; int length; int command; int error; } *

variable_types:
buf
void *


decompiled_code:
void *__fastcall thread_process(void *a1)
{
unsigned int v1; // ebx
size_t v2; // r13
char *v3; // r12
int v4; // eax
unsigned int v5; // eax
unsigned int *v6; // rbp
int v7; // eax
char *v8; // r13
__int64 v9; // rax
__int64 v10; // r15

v1 = *(_DWORD *)a1;
puts("Hello thread");
while ( 1 )
{
v6 = (unsigned int *)create_packet_header();
v7 = recv_header(v1, 256LL, v6);
if ( v7 >= 0 )
{
if ( !v7 )
{
puts("client has closed the connection");
destroy_packet_header(v6);
return 0LL;
}
}
else
{
perror("recv_header");
}
printf("command = %d\n", v6[2]);
printf("flags = %d\n", *v6);
printf("length = %d\n", v6[1]);
printf("error = %d\n", v6[3]);
v2 = (int)v6[1];
v3 = (char *)malloc(v2);
v4 = recv_data(v1, 256LL, v3, v2);
if ( v4 >= 0 )
break;
perror("recv_data");
LABEL_5:
printf("data = %s\n", v3);
v5 = v6[2];
if ( v5 == 1 )
{
if ( (unsigned int)client_exists(v3) )
{
puts("client already exists");
send_error(v1, 0LL, 2LL);
}
else
{
printf("registering client %s\n", v3);
reg_client((__int64)v3, v1);
print_client_list();
send_error(v1, 0LL, 1LL);
if ( (int)perform_ls(v1) < 0 )
{
fwrite("ls failed\n", 1uLL, 0xAuLL, stderr);
}
else
{
puts("Printing file list...");
v8 = (char *)malloc(0x6400uLL);
create_file_list(v8);
puts(v8);
v9 = create_packet_header();
*(_QWORD *)(v9 + 8) = 0x100000005LL;
v10 = v9;
*(_DWORD *)(v9 + 4) = strlen(v8) + 1;
send_packet(v1, v8, 0LL, v10);
destroy_packet_header(v10);
free(v8);
}
}
}
else if ( v5 == 2 )
{
remove_client(v3);
print_client_list();
send_error(v1, 0LL, 1LL);
}
else
{
puts("Unknown command");
}
free(v3);
destroy_packet_header(v6);
}
if ( v4 )
goto LABEL_5;
puts("client has closed the connection");
destroy_packet_header(v6);
free(v3);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func11(void *a1)
{
unsigned int v1; // ebx
size_t v2; // r13
char *v3; // r12
int v4; // eax
unsigned int v5; // eax
unsigned int *v6; // rbp
int v7; // eax
char *v8; // r13
__int64 v9; // rax
__int64 v10; // r15

v1 = *(_DWORD *)a1;
puts("Hello thread");
while ( 1 )
{
v6 = (unsigned int *)create_packet_header();
v7 = recv_header(v1, 256LL, v6);
if ( v7 >= 0 )
{
if ( !v7 )
{
puts("client has closed the connection");
destroy_packet_header(v6);
return 0LL;
}
}
else
{
perror("recv_header");
}
printf("command = %d\n", v6[2]);
printf("flags = %d\n", *v6);
printf("length = %d\n", v6[1]);
printf("error = %d\n", v6[3]);
v2 = (int)v6[1];
v3 = (char *)malloc(v2);
v4 = recv_data(v1, 256LL, v3, v2);
if ( v4 >= 0 )
break;
perror("recv_data");
LABEL_5:
printf("data = %s\n", v3);
v5 = v6[2];
if ( v5 == 1 )
{
if ( (unsigned int)func2(v3) )
{
puts("client already exists");
send_error(v1, 0LL, 2LL);
}
else
{
printf("registering client %s\n", v3);
func5((__int64)v3, v1);
func4();
send_error(v1, 0LL, 1LL);
if ( (int)func10(v1) < 0 )
{
fwrite("ls failed\n", 1uLL, 0xAuLL, stderr);
}
else
{
puts("Printing file list...");
v8 = (char *)malloc(0x6400uLL);
func8(v8);
puts(v8);
v9 = create_packet_header();
*(_QWORD *)(v9 + 8) = 0x100000005LL;
v10 = v9;
*(_DWORD *)(v9 + 4) = strlen(v8) + 1;
send_packet(v1, v8, 0LL, v10);
destroy_packet_header(v10);
free(v8);
}
}
}
else if ( v5 == 2 )
{
func6(v3);
func4();
send_error(v1, 0LL, 1LL);
}
else
{
puts("Unknown command");
}
free(v3);
destroy_packet_header(v6);
}
if ( v4 )
goto LABEL_5;
puts("client has closed the connection");
destroy_packet_header(v6);
free(v3);
return 0LL;
}

original_code:
void *thread_process(void *params) {
 int sock = *((int *) params);
 int result;
 char *buf = ((void *)0);
 printf("Hello thread\n");
 for (;;) {
  packet_header_p pkt_hdr = create_packet_header();
  int res = recv_header(sock, MSG_WAITALL, pkt_hdr);
  if (res < 0) {
   perror("recv_header");
  } else if (res == 0) {
   printf("client has closed the connection\n");
   destroy_packet_header(pkt_hdr);
   return 0;
  }
  printf("command = %d\n", pkt_hdr->command);
  printf("flags = %d\n", pkt_hdr->flags);
  printf("length = %d\n", pkt_hdr->length);
  printf("error = %d\n", pkt_hdr->error);
  buf = malloc(pkt_hdr->length);
  res = recv_data(sock, MSG_WAITALL, buf, pkt_hdr->length);
  if (res < 0) {
   perror("recv_data");
  } else if (res == 0) {
   printf("client has closed the connection\n");
   destroy_packet_header(pkt_hdr);
   free(buf);
   return 0;
  }
  printf("data = %s\n", buf);
  if (pkt_hdr->command == 1) {
   if (client_exists(buf)) {
    printf("client already exists\n");
    send_error(sock, 0, 2);
   } else {
    printf("registering client %s\n", buf);
    reg_client(buf, sock);
    print_client_list();
    send_error(sock, 0, 1);
    result = perform_ls(sock);
    if (result < 0) {
     fprintf(stderr, "ls failed\n");
    } else {
     printf("Printing file list...\n");
     char *buf;
     buf = malloc(1024 * 25);
     create_file_list(buf);
     printf("%s\n", buf);
     packet_header_p ph = create_packet_header();
     ph->command = 5;
     ph->error = 1;
     ph->length = strlen(buf) + 1;
     send_packet(sock, buf, 0, ph);
     destroy_packet_header(ph);
     free(buf);
    }
   }
  } else if (pkt_hdr->command == 2) {
   remove_client(buf);
   print_client_list();
   send_error(sock, 0, 1);
  } else {
   printf("Unknown command\n");
  }
  free(buf);
  destroy_packet_header(pkt_hdr);
 }
 close(sock);
 return ((void *)0);
}

canonical_original_code:
void *thread_process(void *params) {
 int sock = *((int *) params);
 int result;
 char *buf = ((void *)0);
 printf("Hello thread\n");
 for (;;) {
  struct packet_header *pkt_hdr = create_packet_header();
  int res = recv_header(sock, MSG_WAITALL, pkt_hdr);
  if (res < 0) {
   perror("recv_header");
  } else if (res == 0) {
   printf("client has closed the connection\n");
   destroy_packet_header(pkt_hdr);
   return 0;
  }
  printf("command = %d\n", pkt_hdr->command);
  printf("flags = %d\n", pkt_hdr->flags);
  printf("length = %d\n", pkt_hdr->length);
  printf("error = %d\n", pkt_hdr->error);
  buf = malloc(pkt_hdr->length);
  res = recv_data(sock, MSG_WAITALL, buf, pkt_hdr->length);
  if (res < 0) {
   perror("recv_data");
  } else if (res == 0) {
   printf("client has closed the connection\n");
   destroy_packet_header(pkt_hdr);
   free(buf);
   return 0;
  }
  printf("data = %s\n", buf);
  if (pkt_hdr->command == 1) {
   if (client_exists(buf)) {
    printf("client already exists\n");
    send_error(sock, 0, 2);
   } else {
    printf("registering client %s\n", buf);
    reg_client(buf, sock);
    print_client_list();
    send_error(sock, 0, 1);
    result = perform_ls(sock);
    if (result < 0) {
     fprintf(stderr, "ls failed\n");
    } else {
     printf("Printing file list...\n");
     char *buf;
     buf = malloc(1024 * 25);
     create_file_list(buf);
     printf("%s\n", buf);
     struct packet_header *ph = create_packet_header();
     ph->command = 5;
     ph->error = 1;
     ph->length = strlen(buf) + 1;
     send_packet(sock, buf, 0, ph);
     destroy_packet_header(ph);
     free(buf);
    }
   }
  } else if (pkt_hdr->command == 2) {
   remove_client(buf);
   print_client_list();
   send_error(sock, 0, 1);
  } else {
   printf("Unknown command\n");
  }
  free(buf);
  destroy_packet_header(pkt_hdr);
 }
 close(sock);
 return ((void *)0);
}

variable_types:
params
void *

variable_types: sock int

variable_types: result int

variable_types: res int

return_type: void *

user_defined_types: struct packet_header { int flags; int length; int command; int error; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
__int16 v4; // bx
int v5; // edx
int v6; // eax
int v7; // ebp
unsigned __int16 v8; // bx
char *v9; // rax
socklen_t v11; // [rsp+0h] [rbp-E8h] BYREF
int arg; // [rsp+4h] [rbp-E4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-E0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-D8h] BYREF
struct sockaddr v15; // [rsp+20h] [rbp-C8h] BYREF
struct sigaction v16; // [rsp+30h] [rbp-B8h] BYREF

if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s %s\n", *argv, "<port number>");
}
else
{
v3 = atoi(argv[1]);
v16.sa_handler = (__sighandler_t)handler;
v4 = v3;
sigemptyset(&v16.sa_mask);
v16.sa_flags = 0x10000000;
if ( sigaction(2, &v16, 0LL) < 0 )
{
perror("sigaction");
}
else
{
thread_pool = create_list();
clients = create_list();
addr = 0LL;
master_list = create_list();
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v4);
v6 = socket(2, 1, v5);
v7 = v6;
if ( v6 < 0 )
{
perror("socket");
}
else if ( bind(v6, &addr, 0x10u) < 0 )
{
perror("bind");
}
else if ( listen(v7, 10) >= 0 )
{
while ( 1 )
{
v11 = 16;
arg = accept(v7, &v15, &v11);
if ( arg < 0 )
break;
v8 = _bswap_16(*(__int16 *)v15.sa_data);
v9 = inet_ntoa(*(struct in_addr *)&v15.sa_data[2]);
printf("Connection accepted from %s %d\n", v9, v8);
pthread_create(&newthread, 0LL, thread_process, &arg);
list_add(thread_pool, &newthread, 8LL);
}
perror("accept");
}
else
{
perror("listen");
}
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
__int16 v4; // bx
int v5; // edx
int v6; // eax
int v7; // ebp
unsigned __int16 v8; // bx
char *v9; // rax
socklen_t v11; // [rsp+0h] [rbp-E8h] BYREF
int arg; // [rsp+4h] [rbp-E4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-E0h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-D8h] BYREF
struct sockaddr v15; // [rsp+20h] [rbp-C8h] BYREF
struct sigaction v16; // [rsp+30h] [rbp-B8h] BYREF

if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s %s\n", *argv, "<port number>");
}
else
{
v3 = atoi(argv[1]);
v16.sa_handler = (__sighandler_t)handler;
v4 = v3;
sigemptyset(&v16.sa_mask);
v16.sa_flags = 0x10000000;
if ( sigaction(2, &v16, 0LL) < 0 )
{
perror("sigaction");
}
else
{
thread_pool = create_list();
clients = create_list();
addr = 0LL;
master_list = create_list();
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(v4);
v6 = socket(2, 1, v5);
v7 = v6;
if ( v6 < 0 )
{
perror("socket");
}
else if ( bind(v6, &addr, 0x10u) < 0 )
{
perror("bind");
}
else if ( listen(v7, 10) >= 0 )
{
while ( 1 )
{
v11 = 16;
arg = accept(v7, &v15, &v11);
if ( arg < 0 )
break;
v8 = func1(*(__int16 *)v15.sa_data);
v9 = inet_ntoa(*(struct in_addr *)&v15.sa_data[2]);
printf("Connection accepted from %s %d\n", v9, v8);
pthread_create(&newthread, 0LL, thread_process, &arg);
list_add(thread_pool, &newthread, 8LL);
}
perror("accept");
}
else
{
perror("listen");
}
}
}
return 1;
}

original_code:
int main(int argc, char *argv[]) {
 int port;
 struct sockaddr_in local_addr;
 struct sockaddr_in remote_addr;
 int sock;
 struct sigaction sigact;
 if (argc < 1 + 1) {
  fprintf(stderr, "Usage: %s %s\n", argv[0], "<port number>");
  return 1;
 }
 port = atoi(argv[1]);
 sigact.__sigaction_handler.sa_handler = handler;
 sigemptyset(&sigact.sa_mask);
 sigact.sa_flags = 0x10000000;
 if (sigaction(2, &sigact, ((void *)0)) < 0) {
  perror("sigaction");
  return 1;
 }
 thread_pool = create_list();
 clients = create_list();
 master_list = create_list();
 memset(&local_addr, '\0', sizeof(local_addr));
 local_addr.sin_family = 2;
 local_addr.sin_port = htons(port);
 local_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  return 1;
 }
 if (bind(sock, (struct sockaddr *) &local_addr, sizeof(local_addr)) < 0) {
  perror("bind");
  return 1;
 }
 if (listen(sock, 10) < 0) {
  perror("listen");
  return 1;
 }
 for (;;) {
  socklen_t len = sizeof(remote_addr);
  int new_sock = accept(sock, (struct sockaddr *) &remote_addr, &len);
  if (new_sock < 0) {
   perror("accept");
   return 1;
  }
  printf("Connection accepted from %s %d\n",
    inet_ntoa(remote_addr.sin_addr), ntohs(remote_addr.sin_port));
  pthread_t thread;
  pthread_create(&thread, ((void *)0), thread_process, &new_sock);
  list_add(thread_pool, &thread, sizeof(thread));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int port;
 struct sockaddr_in local_addr;
 struct sockaddr_in remote_addr;
 int sock;
 struct sigaction sigact;
 if (argc < 1 + 1) {
  fprintf(stderr, "Usage: %s %s\n", argv[0], "<port number>");
  return 1;
 }
 port = atoi(argv[1]);
 sigact.__sigaction_handler.sa_handler = handler;
 sigemptyset(&sigact.sa_mask);
 sigact.sa_flags = 0x10000000;
 if (sigaction(2, &sigact, ((void *)0)) < 0) {
  perror("sigaction");
  return 1;
 }
 thread_pool = create_list();
 clients = create_list();
 master_list = create_list();
 memset(&local_addr, '\0', sizeof(local_addr));
 local_addr.sin_family = 2;
 local_addr.sin_port = htons(port);
 local_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  return 1;
 }
 if (bind(sock, (struct sockaddr *) &local_addr, sizeof(local_addr)) < 0) {
  perror("bind");
  return 1;
 }
 if (listen(sock, 10) < 0) {
  perror("listen");
  return 1;
 }
 for (;;) {
  unsigned int len = sizeof(remote_addr);
  int new_sock = accept(sock, (struct sockaddr *) &remote_addr, &len);
  if (new_sock < 0) {
   perror("accept");
   return 1;
  }
  printf("Connection accepted from %s %d\n",
    inet_ntoa(remote_addr.sin_addr), ntohs(remote_addr.sin_port));
  unsigned long thread;
  pthread_create(&thread, ((void *)0), thread_process, &new_sock);
  list_add(thread_pool, &thread, sizeof(thread));
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: port int

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

variable_types:
thread
unsigned long

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

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


decompiled_code:
_QWORD *create_packet_header()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
packet_header_p create_packet_header() {
 packet_header_p pkt_hdr = (packet_header_p) malloc(sizeof(struct packet_header));
 pkt_hdr->flags = 0;
 pkt_hdr->length = 0;
 pkt_hdr->command = 0;
 pkt_hdr->error = 0;
 return pkt_hdr;
}

canonical_original_code:
struct packet_header *create_packet_header() {
 struct packet_header *pkt_hdr = (packet_header_p) malloc(sizeof(struct packet_header));
 pkt_hdr->flags = 0;
 pkt_hdr->length = 0;
 pkt_hdr->command = 0;
 pkt_hdr->error = 0;
 return pkt_hdr;
}

return_type: struct packet_header { int flags; int length; int command; int error; } *


decompiled_code:
// attributes: thunk
void destroy_packet_header(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func1(void *ptr)
{
free(ptr);
}

original_code:
void destroy_packet_header(packet_header_p pkt_hdr) {
 free(pkt_hdr);
}

canonical_original_code:
void destroy_packet_header(struct packet_header *pkt_hdr) {
 free(pkt_hdr);
}


decompiled_code:
ssize_t __fastcall send_packet(int fd, void *src, int flags, const __m128i *a4)
{
size_t v6; // r15
__m128i *v7; // rbp
size_t n; // [rsp+8h] [rbp-40h]

v6 = a4->m128i_i32[1] + 16LL;
n = a4->m128i_i32[1];
v7 = (__m128i *)calloc(v6, 1uLL);
*v7 = _mm_loadu_si128(a4);
memcpy(&v7[1], src, n);
return send(fd, v7, v6, flags);
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, void *src, int flags, const __m128i *a4)
{
size_t v6; // r15
__m128i *v7; // rbp
size_t n; // [rsp+8h] [rbp-40h]

v6 = a4->m128i_i32[1] + 16LL;
n = a4->m128i_i32[1];
v7 = (__m128i *)calloc(v6, 1uLL);
*v7 = _mm_loadu_si128(a4);
memcpy(&v7[1], src, n);
return send(fd, v7, v6, flags);
}

original_code:
int send_packet(int fd, void *data, int flags, packet_header_p pkt_hdr) {
 int result;
 size_t n;
 char *buf;
 int offset;
 n = pkt_hdr->length + sizeof(struct packet_header);
 buf = (char *) malloc(n);
 offset = sizeof(struct packet_header);
 memset(buf, '\0', n);
 memcpy(buf, pkt_hdr, sizeof(struct packet_header));
 memcpy(buf + offset, data, pkt_hdr->length);
 result = send(fd, buf, n, flags);
 return result;
}

canonical_original_code:
int send_packet(int fd, void *data, int flags, struct packet_header *pkt_hdr) {
 int result;
 unsigned long n;
 char *buf;
 int offset;
 n = pkt_hdr->length + sizeof(struct packet_header);
 buf = (char *) malloc(n);
 offset = sizeof(struct packet_header);
 memset(buf, '\0', n);
 memcpy(buf, pkt_hdr, sizeof(struct packet_header));
 memcpy(buf + offset, data, pkt_hdr->length);
 result = send(fd, buf, n, flags);
 return result;
}

variable_types: fd int

variable_types:
data
void *

variable_types: flags int

variable_types:
n
unsigned long

variable_types: offset int


decompiled_code:
__int64 __fastcall send_error(int fd, int flags, int a3)
{
_DWORD *v4; // rax
void *v5; // rbp
unsigned int v6; // ebx

v4 = create_packet_header();
v4[3] = a3;
v5 = v4;
*v4 = 1;
v6 = send(fd, v4, 0x10uLL, flags);
destroy_packet_header(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int flags, int a3)
{
_DWORD *v4; // rax
void *v5; // rbp
unsigned int v6; // ebx

v4 = func0();
v4[3] = a3;
v5 = v4;
*v4 = 1;
v6 = send(fd, v4, 0x10uLL, flags);
func1(v5);
return v6;
}

original_code:
int send_error(int fd, int flags, int error) {
 int result;
 packet_header_p pkt_hdr;
 pkt_hdr = create_packet_header();
 pkt_hdr->flags = 1;
 pkt_hdr->error = error;
 result = send(fd, pkt_hdr, sizeof(struct packet_header), flags);
 destroy_packet_header(pkt_hdr);
 return result;
}

canonical_original_code:
int send_error(int fd, int flags, int error) {
 int result;
 struct packet_header *pkt_hdr;
 pkt_hdr = create_packet_header();
 pkt_hdr->flags = 1;
 pkt_hdr->error = error;
 result = send(fd, pkt_hdr, sizeof(struct packet_header), flags);
 destroy_packet_header(pkt_hdr);
 return result;
}

variable_types: error int


decompiled_code:
ssize_t __fastcall recv_header(int a1, int a2, void *a3)
{
return recv(a1, a3, 0x10uLL, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int a1, int a2, void *a3)
{
return recv(a1, a3, 0x10uLL, a2);
}

original_code:
int recv_header(int fd, int flags, packet_header_p pkt_hdr) {
 return recv(fd, pkt_hdr, sizeof(struct packet_header), flags);
}

canonical_original_code:
int recv_header(int fd, int flags, struct packet_header *pkt_hdr) {
 return recv(fd, pkt_hdr, sizeof(struct packet_header), flags);
}

variable_types: struct packet_header { int flags; int length; int command; int error; } *


decompiled_code:
ssize_t __fastcall recv_data(int a1, int a2, void *a3, size_t a4)
{
return recv(a1, a3, a4, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1, int a2, void *a3, size_t a4)
{
return recv(a1, a3, a4, a2);
}

original_code:
int recv_data(int fd, int flags, void *data, size_t size) {
 return recv(fd, data, size, flags);
}

canonical_original_code:
int recv_data(int fd, int flags, void *data, unsigned long size) {
 return recv(fd, data, size, flags);
}

variable_types:
size
unsigned long


toreceive

decompiled_code:
__int64 __fastcall toreceive(int a1, int a2, __int64 a3, void **a4, __time_t a5, __suseconds_t a6)
{
__int64 v7; // rbx
__int64 v8; // r15
int v9; // eax
int v10; // er12
void *v11; // rdx
size_t v12; // rcx
void *v13; // rdx
int v14; // eax
_QWORD *v16; // rax
void *v17; // rax
size_t v19; // [rsp+8h] [rbp-D0h]
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

memset(&readfds, 0, sizeof(readfds));
timeout.tv_sec = a5;
timeout.tv_usec = a6;
v7 = a1 / 64;
v8 = 1LL << (a1 % 64);
readfds.fds_bits[v7] |= v8;
v9 = select(a1 + 1, &readfds, 0LL, 0LL, &timeout);
if ( v9 < 0 )
return (unsigned int)-1;
v10 = v9;
if ( v9 )
{
v10 = 0;
if ( (readfds.fds_bits[v7] & v8) != 0 )
{
v11 = *(void **)a3;
if ( !*(_QWORD *)a3 )
{
v16 = create_packet_header();
*(_QWORD *)a3 = v16;
v11 = v16;
}
v10 = recv_header(a1, a2, v11);
if ( v10 <= 0 )
return (unsigned int)-1;
v12 = *(int *)(*(_QWORD *)a3 + 4LL);
if ( (int)v12 > 0 )
{
v13 = *a4;
if ( !*a4 )
{
v19 = *(int *)(*(_QWORD *)a3 + 4LL);
v17 = malloc(v19);
v12 = v19;
v13 = v17;
*a4 = v17;
}
v14 = recv_data(a1, a2, v13, v12);
if ( v14 > 0 )
{
v10 += v14;
return (unsigned int)v10;
}
return (unsigned int)-1;
}
}
}
return (unsigned int)v10;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2, __int64 a3, void **a4, __time_t a5, __suseconds_t a6)
{
__int64 v7; // rbx
__int64 v8; // r15
int v9; // eax
int v10; // er12
void *v11; // rdx
size_t v12; // rcx
void *v13; // rdx
int v14; // eax
_QWORD *v16; // rax
void *v17; // rax
size_t v19; // [rsp+8h] [rbp-D0h]
struct timeval timeout; // [rsp+10h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

memset(&readfds, 0, sizeof(readfds));
timeout.tv_sec = a5;
timeout.tv_usec = a6;
v7 = a1 / 64;
v8 = 1LL << (a1 % 64);
readfds.fds_bits[v7] |= v8;
v9 = select(a1 + 1, &readfds, 0LL, 0LL, &timeout);
if ( v9 < 0 )
return (unsigned int)-1;
v10 = v9;
if ( v9 )
{
v10 = 0;
if ( (readfds.fds_bits[v7] & v8) != 0 )
{
v11 = *(void **)a3;
if ( !*(_QWORD *)a3 )
{
v16 = func0();
*(_QWORD *)a3 = v16;
v11 = v16;
}
v10 = func4(a1, a2, v11);
if ( v10 <= 0 )
return (unsigned int)-1;
v12 = *(int *)(*(_QWORD *)a3 + 4LL);
if ( (int)v12 > 0 )
{
v13 = *a4;
if ( !*a4 )
{
v19 = *(int *)(*(_QWORD *)a3 + 4LL);
v17 = malloc(v19);
v12 = v19;
v13 = v17;
*a4 = v17;
}
v14 = func5(a1, a2, v13, v12);
if ( v14 > 0 )
{
v10 += v14;
return (unsigned int)v10;
}
return (unsigned int)-1;
}
}
}
return (unsigned int)v10;
}

original_code:
int toreceive(int fd, int flags, packet_header_p *pkt_hdr, void **data, long sec, long usec) {
 fd_set fdset;
 struct timeval tv;
 int bytes_recvd = 0;
 int retval;
 packet_header_p ph;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fdset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = sec;
 tv.tv_usec = usec;
 retval = select(fd+1, &fdset, ((void *)0), ((void *)0), &tv);
 if (retval < 0) {
  return -1;
 } else if (retval == 0) {
  return 0;
 } else {
  if (((((&fdset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (*pkt_hdr == ((void *)0)) {
    *pkt_hdr = create_packet_header();
   }
   retval = recv_header(fd, flags, *pkt_hdr);
   if (retval <= 0) {
    return -1;
   }
   ph = *pkt_hdr;
   bytes_recvd += retval;
   if (ph->length > 0) {
    if (*data == ((void *)0)) {
     *data = malloc(ph->length);
    }
    retval = recv_data(fd, flags, *data, ph->length);
    if (retval <= 0) {
     return -1;
    }
    bytes_recvd += retval;
   }
  }
  return bytes_recvd;
 }
}

canonical_original_code:
int toreceive(int fd, int flags, struct packet_header **pkt_hdr, void **data, long sec, long usec) {
 struct fd_set fdset;
 struct timeval tv;
 int bytes_recvd = 0;
 int retval;
 struct packet_header *ph;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdset)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&fdset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 tv.tv_sec = sec;
 tv.tv_usec = usec;
 retval = select(fd+1, &fdset, ((void *)0), ((void *)0), &tv);
 if (retval < 0) {
  return -1;
 } else if (retval == 0) {
  return 0;
 } else {
  if (((((&fdset)->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (*pkt_hdr == ((void *)0)) {
    *pkt_hdr = create_packet_header();
   }
   retval = recv_header(fd, flags, *pkt_hdr);
   if (retval <= 0) {
    return -1;
   }
   ph = *pkt_hdr;
   bytes_recvd += retval;
   if (ph->length > 0) {
    if (*data == ((void *)0)) {
     *data = malloc(ph->length);
    }
    retval = recv_data(fd, flags, *data, ph->length);
    if (retval <= 0) {
     return -1;
    }
    bytes_recvd += retval;
   }
  }
  return bytes_recvd;
 }
}

variable_types: struct packet_header { int flags; int length; int command; int error; } **

variable_types:
data
void **

variable_types: sec long

variable_types: usec long

variable_types:
fdset
struct fd_set { long __fds_bits[-1]; }

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

variable_types: retval int


decompiled_code:
_QWORD *create_list()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
result[3] = &free;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
result[3] = &free;
return result;
}

original_code:
list_p create_list(){
 list_p list = (list_p) malloc(sizeof(struct list));
 list->length = 0;
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->destructor = free;
 return list;
}

canonical_original_code:
struct list *create_list(){
 struct list *list = (list_p) malloc(sizeof(struct list));
 list->length = 0;
 list->first = ((void *)0);
 list->last = ((void *)0);
 list->destructor = free;
 return list;
}

variable_types: struct list { int length; struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *first; struct linked_node *last; void (*destructor)(void *); } *

user_defined_types: struct list { int length; struct linked_node *first; struct linked_node *last; void (*destructor)(void *); }


decompiled_code:
__int64 __fastcall list_first(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return **(_QWORD **)(a1 + 8);
}

original_code:
void* list_first(list_p list){
 return list->first->data;
}

canonical_original_code:
void *list_first(struct list *list){
 return list->first->data;
}


decompiled_code:
__int64 __fastcall list_last(__int64 a1)
{
return **(_QWORD **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return **(_QWORD **)(a1 + 16);
}

original_code:
void* list_last(list_p list){
 return list->last->data;
}

canonical_original_code:
void *list_last(struct list *list){
 return list->last->data;
}


original_code:
void* list_pop(list_p list){
 lnode_p last = list->last;
 if(last == ((void *)0)) return ((void *)0);
 if (list->first == list->last) {
  list->first = ((void *)0);
  list->last = ((void *)0);
 } else {
  list->last = last->prev;
  last->prev->next = ((void *)0);
 }
 void* data = last->data;
 free(last);
 list->length--;
 return data;
}

canonical_original_code:
void *list_pop(struct list *list){
 struct linked_node *last = list->last;
 if(last == ((void *)0)) return ((void *)0);
 if (list->first == list->last) {
  list->first = ((void *)0);
  list->last = ((void *)0);
 } else {
  list->last = last->prev;
  last->prev->next = ((void *)0);
 }
 void *data = last->data;
 free(last);
 list->length--;
 return data;
}

variable_types: struct linked_node { void *data; struct linked_node *next; struct linked_node *prev; } *


original_code:
void* list_poll(list_p list){
 lnode_p first = list->first;
 if(first == ((void *)0))
  return ((void *)0);
 if (list->first == list->last) {
  list->first = ((void *)0);
  list->last = ((void *)0);
 } else {
  list->first = first->next;
  first->next->prev = ((void *)0);
 }
 void* data = first->data;
 free(first);
 list->length--;
 return data;
}

canonical_original_code:
void *list_poll(struct list *list){
 struct linked_node *first = list->first;
 if(first == ((void *)0))
  return ((void *)0);
 if (list->first == list->last) {
  list->first = ((void *)0);
  list->last = ((void *)0);
 } else {
  list->first = first->next;
  first->next->prev = ((void *)0);
 }
 void *data = first->data;
 free(first);
 list->length--;
 return data;
}


original_code:
void list_remove(list_p list, char end){
 void * data;
 if(end == 0)
  data = list_poll(list);
 else if (end == 1)
  data = list_pop(list);
 else return;
 list->destructor(data);
}

canonical_original_code:
void list_remove(struct list *list, char end){
 void *data;
 if(end == 0)
  data = list_poll(list);
 else if (end == 1)
  data = list_pop(list);
 else return;
 list->destructor(data);
}

variable_types: end char


decompiled_code:
void __fastcall destroy_list(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
(*((void (__fastcall **)(_QWORD))ptr + 3))(*v2);
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = (_QWORD *)*((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1];
(*((void (__fastcall **)(_QWORD))ptr + 3))(*v2);
free(v2);
}
free(ptr);
}

original_code:
void destroy_list(list_p list){
 lnode_p cur = list->first;
 lnode_p next;
 while(cur!=((void *)0)){
  next = cur->next;
  list->destructor(cur->data);
  free(cur);
  cur = next;
 }
 free(list);
}

canonical_original_code:
void destroy_list(struct list *list){
 struct linked_node *cur = list->first;
 struct linked_node *next;
 while(cur!=((void *)0)){
  next = cur->next;
  list->destructor(cur->data);
  free(cur);
  cur = next;
 }
 free(list);
}


original_code:
void* list_pluck(list_p list, lnode_p removed){
    if(removed == ((void *)0)){
        return ((void *)0);
    }
    else if(list->first == removed && list->last == removed){
        list->first = ((void *)0);
        list->last = ((void *)0);
    }
    else if(list->first == removed){
        list->first = removed->next;
        removed->next->prev = ((void *)0);
    }
    else if(list->last == removed){
        list->last = removed->prev;
        removed->prev->next = ((void *)0);
    }
    else{
        removed->prev->next = removed->next;
        removed->next->prev = removed->prev;
    }
    void* data = removed->data;
    free(removed);
    list->length--;
    return data;
}

canonical_original_code:
void *list_pluck(struct list *list, struct linked_node *removed){
    if(removed == ((void *)0)){
        return ((void *)0);
    }
    else if(list->first == removed && list->last == removed){
        list->first = ((void *)0);
        list->last = ((void *)0);
    }
    else if(list->first == removed){
        list->first = removed->next;
        removed->next->prev = ((void *)0);
    }
    else if(list->last == removed){
        list->last = removed->prev;
        removed->prev->next = ((void *)0);
    }
    else{
        removed->prev->next = removed->next;
        removed->next->prev = removed->prev;
    }
    void *data = removed->data;
    free(removed);
    list->length--;
    return data;
}

variable_types:
removed
struct linked_node *

variable_types:
data
void *


repo: cbassa/lmt

decompiled_code:
char *__fastcall ascii_header_find(const char *a1, const char *a2)
{
char *result; // rax
char v3; // dl

for ( result = strstr(a1, a2); a1 < result; result = strstr(result + 1, a2) )
{
v3 = *(result - 1);
if ( v3 == 10 )
break;
if ( v3 == 92 )
break;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1, const char *a2)
{
char *result; // rax
char v3; // dl

for ( result = strstr(a1, a2); a1 < result; result = strstr(result + 1, a2) )
{
v3 = *(result - 1);
if ( v3 == 10 )
break;
if ( v3 == 92 )
break;
}
return result;
}

original_code:
char* ascii_header_find (const char* header, const char* keyword)
{
  char* key = strstr (header, keyword);
  while (key > header)
  {
    if ((*(key-1) == '\n') || (*(key-1) == '\\'))
      break;
    key = strstr (key+1, keyword);
  }
  return key;
}

canonical_original_code:
char *ascii_header_find(char *header, char *keyword)
{
  char *key = strstr (header, keyword);
  while (key > header)
  {
    if ((*(key-1) == '\n') || (*(key-1) == '\\'))
      break;
    key = strstr (key+1, keyword);
  }
  return key;
}

variable_types:
header
char *

variable_types:
keyword
char *

variable_types:
key
char *


decompiled_code:
__int64 ascii_header_set(char *s, const char *a2, const char *a3, ...)
{
char *v4; // rax
char *v5; // rbp
const char *v6; // r14
char *v7; // r13
gcc_va_list arg; // [rsp+8h] [rbp-170h] BYREF
char sa[128]; // [rsp+20h] [rbp-158h] BYREF

v4 = ascii_header_find(s, a2);
v5 = v4;
if ( v4 )
{
v6 = &v4[strcspn(v4, "#\n")];
}
else
{
v5 = strstr(s, "DATA\n");
v6 = v5;
if ( !v5 )
{
v5 = &s[strlen(s)];
va_start(arg, a3);
if ( vsnprintf(sa, 0x80uLL, a3, arg) >= 0 )
{
if ( sprintf(v5, "%-12s %-20s ", a2, sa) >= 0 )
{
LABEL_10:
*(_WORD *)&v5[strlen(v5)] = 10;
return 0LL;
}
goto LABEL_14;
}
LABEL_11:
perror("ascii_header_set: error snprintf\n");
return 0xFFFFFFFFLL;
}
}
va_start(arg, a3);
if ( vsnprintf(sa, 0x80uLL, a3, arg) < 0 )
goto LABEL_11;
v7 = strdup(v6);
if ( sprintf(v5, "%-12s %-20s ", a2, sa) >= 0 )
{
if ( v7 )
{
strcat(v5, v7);
free(v7);
return 0LL;
}
goto LABEL_10;
}
if ( v7 )
free(v7);
LABEL_14:
perror("ascii_header_set: error sprintf\n");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1(char *s, const char *a2, const char *a3, ...)
{
char *v4; // rax
char *v5; // rbp
const char *v6; // r14
char *v7; // r13
gcc_va_list arg; // [rsp+8h] [rbp-170h] BYREF
char sa[128]; // [rsp+20h] [rbp-158h] BYREF

v4 = func0(s, a2);
v5 = v4;
if ( v4 )
{
v6 = &v4[strcspn(v4, "#\n")];
}
else
{
v5 = strstr(s, "DATA\n");
v6 = v5;
if ( !v5 )
{
v5 = &s[strlen(s)];
va_start(arg, a3);
if ( vsnprintf(sa, 0x80uLL, a3, arg) >= 0 )
{
if ( sprintf(v5, "%-12s %-20s ", a2, sa) >= 0 )
{
LABEL_10:
*(_WORD *)&v5[strlen(v5)] = 10;
return 0LL;
}
goto LABEL_14;
}
LABEL_11:
perror("ascii_header_set: error snprintf\n");
return 0xFFFFFFFFLL;
}
}
va_start(arg, a3);
if ( vsnprintf(sa, 0x80uLL, a3, arg) < 0 )
goto LABEL_11;
v7 = strdup(v6);
if ( sprintf(v5, "%-12s %-20s ", a2, sa) >= 0 )
{
if ( v7 )
{
strcat(v5, v7);
free(v7);
return 0LL;
}
goto LABEL_10;
}
if ( v7 )
free(v7);
LABEL_14:
perror("ascii_header_set: error sprintf\n");
return 0xFFFFFFFFLL;
}

original_code:
int ascii_header_set (char* header, const char* keyword,
        const char* format, ...)
{
  va_list arguments;
  char value[128];
  char* eol = 0;
  char* dup = 0;
  int ret = 0;
  char* key = ascii_header_find (header, keyword);
  if (key) {
    eol = key + strcspn (key, "#\n");
  }
  else {
    eol = strstr (header, "DATA\n");
    if (eol)
      key = eol;
    else
      key = header + strlen (header);
  }
  __builtin_va_start(arguments,format);
  ret = vsnprintf (value, 128, format, arguments);
  __builtin_va_end(arguments);
  if (ret < 0) {
    perror ("ascii_header_set: error snprintf\n");
    return -1;
  }
  if (eol)
    dup = strdup (eol);
  if (sprintf (key, "%-12s %-20s   ", keyword, value) < 0) {
    if (dup)
      free (dup);
    perror ("ascii_header_set: error sprintf\n");
    return -1;
  }
  if (dup) {
    strcat (key, dup);
    free (dup);
  }
  else
    strcat (key, "\n");
  return 0;
}

canonical_original_code:
int ascii_header_set(char *header, char *keyword, char *format, ...)
{
  __builtin_va_list arguments;
  char value[128];
  char *eol = 0;
  char *dup = 0;
  int ret = 0;
  char *key = ascii_header_find (header, keyword);
  if (key) {
    eol = key + strcspn (key, "#\n");
  }
  else {
    eol = strstr (header, "DATA\n");
    if (eol)
      key = eol;
    else
      key = header + strlen (header);
  }
  __builtin_va_start(arguments,format);
  ret = vsnprintf (value, 128, format, arguments);
  __builtin_va_end(arguments);
  if (ret < 0) {
    perror ("ascii_header_set: error snprintf\n");
    return -1;
  }
  if (eol)
    dup = strdup (eol);
  if (sprintf (key, "%-12s %-20s   ", keyword, value) < 0) {
    if (dup)
      free (dup);
    perror ("ascii_header_set: error sprintf\n");
    return -1;
  }
  if (dup) {
    strcat (key, dup);
    free (dup);
  }
  else
    strcat (key, "\n");
  return 0;
}

variable_types:
format
char *

variable_types:
value
char [128]

variable_types:
eol
char *

variable_types:
dup
char *

variable_types: ret int


decompiled_code:
__int64 ascii_header_get(const char *a1, const char *a2, __int64 a3, ...)
{
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

v4 = ascii_header_find(a1, a2);
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
v6 = strcspn(v4, " \t\n");
va_start(va, a3);
return _isoc99_vsscanf(&v5[v6], a3, va);
}

canonical_decompiled_code:
__int64 func2(const char *a1, const char *a2, __int64 a3, ...)
{
char *v4; // rax
char *v5; // rbx
size_t v6; // rax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

v4 = func0(a1, a2);
v5 = v4;
if ( !v4 )
return 0xFFFFFFFFLL;
v6 = strcspn(v4, " \t\n");
va_start(va, a3);
return _isoc99_vsscanf(&v5[v6], a3, va);
}

original_code:
int ascii_header_get (const char* header, const char* keyword,
        const char* format, ...)
{
  va_list arguments;
  char* value = 0;
  int ret = 0;
  char* key = ascii_header_find (header, keyword);
  if (!key)
    return -1;
  value = key + strcspn (key, whitespace);
  __builtin_va_start(arguments,format);
  ret = vsscanf (value, format, arguments);
  __builtin_va_end(arguments);
  return ret;
}

canonical_original_code:
int ascii_header_get(char *header, char *keyword, char *format, ...)
{
  __builtin_va_list arguments;
  char *value = 0;
  int ret = 0;
  char *key = ascii_header_find (header, keyword);
  if (!key)
    return -1;
  value = key + strcspn (key, whitespace);
  __builtin_va_start(arguments,format);
  ret = vsscanf (value, format, arguments);
  __builtin_va_end(arguments);
  return ret;
}

variable_types:
value
char *


original_code:
void mjd2date(double mjd,char *date)
{
  double f,jd,dday;
  int z,alpha,a,b,c,d,e;
  int year,month,day,hour,min;
  float sec,x;
  jd=mjd+2400000.5;
  jd+=0.5;
  z=floor(jd);
  f=fmod(jd,1.);
  if (z<2299161)
    a=z;
  else {
    alpha=floor((z-1867216.25)/36524.25);
    a=z+1+alpha-floor(alpha/4.);
  }
  b=a+1524;
  c=floor((b-122.1)/365.25);
  d=floor(365.25*c);
  e=floor((b-d)/30.6001);
  dday=b-d-floor(30.6001*e)+f;
  if (e<14)
    month=e-1;
  else
    month=e-13;
  if (month>2)
    year=c-4716;
  else
    year=c-4715;
  day=(int) floor(dday);
  x=24.0*(dday-day);
  x=3600.*fabs(x);
  sec=fmod(x,60.);
  x=(x-sec)/60.;
  min=fmod(x,60.);
  x=(x-min)/60.;
  hour=x;
  sprintf(date,"%04d-%02d-%02d-%02d:%02d:%02.0f",year,month,day,hour,min,sec);
  return;
}

canonical_original_code:
void mjd2date(double mjd, char *date)
{
  double f; double jd; double dday;
  int z; int alpha; int a; int b; int c; int d; int e;
  int year; int month; int day; int hour; int min;
  float sec; float x;
  jd=mjd+2400000.5;
  jd+=0.5;
  z=floor(jd);
  f=fmod(jd,1.);
  if (z<2299161)
    a=z;
  else {
    alpha=floor((z-1867216.25)/36524.25);
    a=z+1+alpha-floor(alpha/4.);
  }
  b=a+1524;
  c=floor((b-122.1)/365.25);
  d=floor(365.25*c);
  e=floor((b-d)/30.6001);
  dday=b-d-floor(30.6001*e)+f;
  if (e<14)
    month=e-1;
  else
    month=e-13;
  if (month>2)
    year=c-4716;
  else
    year=c-4715;
  day=(int) floor(dday);
  x=24.0*(dday-day);
  x=3600.*fabs(x);
  sec=fmod(x,60.);
  x=(x-sec)/60.;
  min=fmod(x,60.);
  x=(x-min)/60.;
  hour=x;
  sprintf(date,"%04d-%02d-%02d-%02d:%02d:%02.0f",year,month,day,hour,min,sec);
  return;
}

variable_types: mjd double

variable_types:
date
char *

variable_types: f double

variable_types: jd double

variable_types: dday double

variable_types: z int

variable_types: alpha int

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: e int

variable_types: year int

variable_types: month int

variable_types: day int

variable_types: hour int

variable_types: min int

variable_types: sec float

variable_types: x float


decompiled_code:
__int64 __fastcall read_uint64_value(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], &unk_63F, v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v6[0];
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], &unk_63F, v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v6[0];
}

original_code:
uint64_t read_uint64_value(char *keyword,char *buffer)
{
  uint64_t result;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0))
    sscanf(pch+strlen(keyword)+1,"%Lu",&result);
  else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

canonical_original_code:
unsigned long read_uint64_value(char *keyword, char *buffer)
{
  unsigned long result;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0))
    sscanf(pch+strlen(keyword)+1,"%Lu",&result);
  else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

variable_types:
keyword
char *

variable_types:
buffer
char *

variable_types:
result
unsigned long

variable_types:
pch
char *

return_type: unsigned long


decompiled_code:
__int64 __fastcall read_integer_value(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
unsigned int v6; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%d", &v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
unsigned int v6; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%d", &v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v6;
}

original_code:
int read_integer_value(char *keyword,char *buffer)
{
  int result;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0))
    sscanf(pch+strlen(keyword)+1,"%d",&result);
  else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

canonical_original_code:
int read_integer_value(char *keyword, char *buffer)
{
  int result;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0))
    sscanf(pch+strlen(keyword)+1,"%d",&result);
  else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

variable_types: result int


decompiled_code:
void *__fastcall read_string_value(char *s, char *haystack, int a3)
{
void *v3; // r12
char *v4; // rax
char *v5; // rbx
size_t v6; // rax

v3 = malloc(a3);
v4 = strstr(haystack, s);
if ( v4 )
{
v5 = v4;
v6 = strlen(s);
_isoc99_sscanf(&v5[v6 + 1], "%s", v3);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func2(char *s, char *haystack, int a3)
{
void *v3; // r12
char *v4; // rax
char *v5; // rbx
size_t v6; // rax

v3 = malloc(a3);
v4 = strstr(haystack, s);
if ( v4 )
{
v5 = v4;
v6 = strlen(s);
_isoc99_sscanf(&v5[v6 + 1], "%s", v3);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v3;
}

original_code:
char *read_string_value(char *keyword,char *buffer,int len)
{
  char *result;
  char *pch;
  result=(char *) malloc(len*sizeof(char));
  if ((pch=strstr(buffer,keyword))!=((void *)0)) {
    sscanf(pch+strlen(keyword)+1,"%s",result);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

canonical_original_code:
char *read_string_value(char *keyword, char *buffer, int len)
{
  char *result;
  char *pch;
  result=(char *) malloc(len*sizeof(char));
  if ((pch=strstr(buffer,keyword))!=((void *)0)) {
    sscanf(pch+strlen(keyword)+1,"%s",result);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

variable_types: len int

variable_types:
result
char *


decompiled_code:
char *__fastcall read_double_array(char *s, char *haystack, int a3)
{
char *v4; // r12
char *v5; // rax
char *result; // rax
char *v7; // rbp
size_t v8; // rax

v4 = (char *)malloc(8LL * a3);
v5 = strstr(haystack, s);
if ( v5 && a3 == 6 )
{
v7 = v5;
v8 = strlen(s);
_isoc99_sscanf(&v7[v8 + 1], "%lf %lf %lf %lf %lf %lf", v4, v4 + 8, v4 + 16, v4 + 24, v4 + 32, v4 + 40);
result = v4;
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
result = v4;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, char *haystack, int a3)
{
char *v4; // r12
char *v5; // rax
char *result; // rax
char *v7; // rbp
size_t v8; // rax

v4 = (char *)malloc(8LL * a3);
v5 = strstr(haystack, s);
if ( v5 && a3 == 6 )
{
v7 = v5;
v8 = strlen(s);
_isoc99_sscanf(&v7[v8 + 1], "%lf %lf %lf %lf %lf %lf", v4, v4 + 8, v4 + 16, v4 + 24, v4 + 32, v4 + 40);
result = v4;
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
result = v4;
}
return result;
}

original_code:
double *read_double_array(char *keyword,char *buffer,int n)
{
  double *result;
  char *pch;
  result=(double *) malloc(sizeof(double)*n);
  if ((pch=strstr(buffer,keyword))!=((void *)0) && n==6) {
    sscanf(pch+strlen(keyword)+1,"%lf %lf %lf %lf %lf %lf",&result[0],&result[1],&result[2],&result[3],&result[4],&result[5]);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

canonical_original_code:
double *read_double_array(char *keyword, char *buffer, int n)
{
  double *result;
  char *pch;
  result=(double *) malloc(sizeof(double)*n);
  if ((pch=strstr(buffer,keyword))!=((void *)0) && n==6) {
    sscanf(pch+strlen(keyword)+1,"%lf %lf %lf %lf %lf %lf",&result[0],&result[1],&result[2],&result[3],&result[4],&result[5]);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

variable_types: n int

variable_types:
result
double *

return_type: double *


decompiled_code:
double __fastcall read_double_value(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
double v6; // [rsp+8h] [rbp-20h] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%lf", &v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v6;
}

canonical_decompiled_code:
double __fastcall func4(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
double v6; // [rsp+8h] [rbp-20h] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%lf", &v6);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return v6;
}

original_code:
double read_double_value(char *keyword,char *buffer)
{
  double result;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0))
    sscanf(pch+strlen(keyword)+1,"%lf",&result);
  else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

canonical_original_code:
double read_double_value(char *keyword, char *buffer)
{
  double result;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0))
    sscanf(pch+strlen(keyword)+1,"%lf",&result);
  else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  return result;
}

variable_types: result double

return_type: double


decompiled_code:
__int64 __fastcall read_timestamp(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
char v6; // [rsp+8h] [rbp-30h] BYREF
char v7; // [rsp+Ch] [rbp-2Ch] BYREF
char v8; // [rsp+10h] [rbp-28h] BYREF
int v9; // [rsp+14h] [rbp-24h] BYREF
int v10; // [rsp+18h] [rbp-20h] BYREF
int v11; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%04d-%02d-%02d-%02d:%02d:%02d", &v6, &v7, &v8, &v9, &v10, &v11);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return (unsigned int)(v11 + 60 * v10 + 3600 * v9);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, char *haystack)
{
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
char v6; // [rsp+8h] [rbp-30h] BYREF
char v7; // [rsp+Ch] [rbp-2Ch] BYREF
char v8; // [rsp+10h] [rbp-28h] BYREF
int v9; // [rsp+14h] [rbp-24h] BYREF
int v10; // [rsp+18h] [rbp-20h] BYREF
int v11; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = strstr(haystack, s);
if ( v2 )
{
v3 = v2;
v4 = strlen(s);
_isoc99_sscanf(&v3[v4 + 1], "%04d-%02d-%02d-%02d:%02d:%02d", &v6, &v7, &v8, &v9, &v10, &v11);
}
else
{
fprintf(stderr, "Error reading keyword %s\n", s);
}
return (unsigned int)(v11 + 60 * v10 + 3600 * v9);
}

original_code:
int read_timestamp(char *keyword,char *buffer)
{
  int result;
  int iyear,imonth,iday,ihour,imin,isec;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0)) {
    sscanf(pch+strlen(keyword)+1,"%04d-%02d-%02d-%02d:%02d:%02d",&iyear,&imonth,&iday,&ihour,&imin,&isec);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  result=3600*ihour+60*imin+isec;
  return result;
}

canonical_original_code:
int read_timestamp(char *keyword, char *buffer)
{
  int result;
  int iyear; int imonth; int iday; int ihour; int imin; int isec;
  char *pch;
  if ((pch=strstr(buffer,keyword))!=((void *)0)) {
    sscanf(pch+strlen(keyword)+1,"%04d-%02d-%02d-%02d:%02d:%02d",&iyear,&imonth,&iday,&ihour,&imin,&isec);
  } else {
    fprintf(stderr,"Error reading keyword %s\n",keyword);
    exit;
  }
  result=3600*ihour+60*imin+isec;
  return result;
}

variable_types: iyear int

variable_types: imonth int

variable_types: iday int

variable_types: ihour int

variable_types: imin int

variable_types: isec int


RotateVec

decompiled_code:
void __fastcall RotateVec(float *a1, float *a2, float a3)
{
float v3; // xmm3_4
float v4; // xmm4_4
float v5; // [rsp+0h] [rbp-30h]
float v6; // [rsp+4h] [rbp-2Ch]
double cosx; // [rsp+8h] [rbp-28h] BYREF
double sinx[4]; // [rsp+10h] [rbp-20h] BYREF

v6 = *a1;
v5 = *a2;
sincos(a3, sinx, &cosx);
v3 = cosx;
v4 = sinx[0];
*a1 = (float)(v6 * v3) - (float)(v5 * v4);
*a2 = (float)(v6 * v4) + (float)(v5 * v3);
}

canonical_decompiled_code:
void __fastcall func2(float *a1, float *a2, float a3)
{
float v3; // xmm3_4
float v4; // xmm4_4
float v5; // [rsp+0h] [rbp-30h]
float v6; // [rsp+4h] [rbp-2Ch]
double cosx; // [rsp+8h] [rbp-28h] BYREF
double sinx[4]; // [rsp+10h] [rbp-20h] BYREF

v6 = *a1;
v5 = *a2;
sincos(a3, sinx, &cosx);
v3 = cosx;
v4 = sinx[0];
*a1 = (float)(v6 * v3) - (float)(v5 * v4);
*a2 = (float)(v6 * v4) + (float)(v5 * v3);
}

original_code:
void RotateVec(float *re, float *im, float angle)
{
  float x, y, cosangle, sinangle;
  x = *re;
  y = *im;
  cosangle = cos(angle);
  sinangle = sin(angle);
  *re = x*cosangle - y*sinangle;
  *im = x*sinangle + y*cosangle;
}

canonical_original_code:
void RotateVec(float *re, float *im, float angle)
{
  float x; float y; float cosangle; float sinangle;
  x = *re;
  y = *im;
  cosangle = cos(angle);
  sinangle = sin(angle);
  *re = x*cosangle - y*sinangle;
  *im = x*sinangle + y*cosangle;
}

variable_types:
re
float *

variable_types:
im
float *

variable_types: angle float

variable_types: x float

variable_types: y float

variable_types: cosangle float

variable_types: sinangle float


GetTimedelay

decompiled_code:
double __fastcall GetTimedelay(__int64 a1, _QWORD *a2, int a3, double a4)
{
double v4; // xmm2_8
__int64 v5; // rbx
double v6; // r14
double v7; // xmm0_8

v4 = 0.0;
v5 = 0LL;
v6 = (double)a3 * a4;
do
{
v7 = pow(v6, (double)(int)v5) * *(double *)(*a2 + 8 * v5);
++v5;
v4 = v4 + v7;
}
while ( v5 != 6 );
return (double)(int)*(_QWORD *)(a1 + 16) * a4 + v4;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1, _QWORD *a2, int a3, double a4)
{
double v4; // xmm2_8
__int64 v5; // rbx
double v6; // r14
double v7; // xmm0_8

v4 = 0.0;
v5 = 0LL;
v6 = (double)a3 * a4;
do
{
v7 = pow(v6, (double)(int)v5) * *(double *)(*a2 + 8 * v5);
++v5;
v4 = v4 + v7;
}
while ( v5 != 6 );
return (double)(int)*(_QWORD *)(a1 + 16) * a4 + v4;
}

original_code:
double GetTimedelay(delays_type *delays, calc_type *Calc, double samptime, long reducedbinnumber)
{
  int i;
  double timedelay = 0;
  for (i=0; i<6; i++) {
    timedelay += pow(reducedbinnumber*samptime, i) * Calc->Poly[i];
  }
  timedelay += delays->geoshifted*samptime;
  return timedelay;
}

canonical_original_code:
double GetTimedelay(struct delays_type *delays, struct calc_type *Calc, double samptime, long reducedbinnumber)
{
  int i;
  double timedelay = 0;
  for (i=0; i<6; i++) {
    timedelay += pow(reducedbinnumber*samptime, i) * Calc->Poly[i];
  }
  timedelay += delays->geoshifted*samptime;
  return timedelay;
}

variable_types: struct delays_type { long skipsamples; long samplesshifted; long geoshifted; float frac_delay_pol1; float frac_delay_pol2; float phase_offset_pol1; float phase_offset_pol2; float fringe_drift; } *

variable_types: struct calc_type { double *Poly; char *filename; double Offset; int CountCalcSteps; double CalcMJD; } *

variable_types: samptime double

variable_types: reducedbinnumber long

variable_types: i int

variable_types: timedelay double


Usage

decompiled_code:
int Usage()
{
return puts(
"Usage: reader -i <input file> -o <output file> [-b <blocksize> (64000)] -c <calcfile> -g <gpsfile> -r <refgps"
"file> -s <samples to skip>");
}

canonical_decompiled_code:
int func0()
{
return puts(
"Usage: reader -i <input file> -o <output file> [-b <blocksize> (64000)] -c <calcfile> -g <gpsfile> -r <refgps"
"file> -s <samples to skip>");
}

original_code:
void Usage()
{
  printf("Usage: reader -i <input file> -o <output file> [-b <blocksize> (64000)] -c <calcfile> -g <gpsfile> -r <refgpsfile> -s <samples to skip>\n");
}


digitize

original_code:
char digitize(float f,float scale,float offset)
{
  char c;
  f=f*scale+offset;
  if (f>127.0)
    f=127.0;
  else if (f<-128.0)
    f=-128.0;
  c=(char) floor(f);
  return c;
}

canonical_original_code:
char digitize(float f, float scale, float offset)
{
  char c;
  f=f*scale+offset;
  if (f>127.0)
    f=127.0;
  else if (f<-128.0)
    f=-128.0;
  c=(char) floor(f);
  return c;
}

variable_types: f float

variable_types: scale float

variable_types: offset float

variable_types: c char

return_type: char


decompiled_code:
__int64 __fastcall shm_close_server(void *shmaddr)
{
int v1; // er12

sem_wait((sem_t *)shmaddr + 2);
*((_QWORD *)shmaddr + 14) = 0x100000000LL;
sem_destroy((sem_t *)shmaddr);
sem_destroy((sem_t *)shmaddr + 1);
sem_destroy((sem_t *)shmaddr + 2);
v1 = *((_DWORD *)shmaddr + 25);
shmdt(shmaddr);
shmctl(v1, 0, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *shmaddr)
{
int v1; // er12

sem_wait((sem_t *)shmaddr + 2);
*((_QWORD *)shmaddr + 14) = 0x100000000LL;
sem_destroy((sem_t *)shmaddr);
sem_destroy((sem_t *)shmaddr + 1);
sem_destroy((sem_t *)shmaddr + 2);
v1 = *((_DWORD *)shmaddr + 25);
shmdt(shmaddr);
shmctl(v1, 0, 0LL);
return 0LL;
}

original_code:
int shm_close_server(shm_socket_t* sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_destroy(&(sock->empty));
 sem_destroy(&(sock->full));
 sem_destroy(&(sock->mutex));
 int shmID = sock->shmID;
 shmdt(&(sock->empty));
 shmctl(shmID, 0, 0);
 return 0;
}

canonical_original_code:
int shm_close_server(struct shm_socket_t *sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_destroy(&(sock->empty));
 sem_destroy(&(sock->full));
 sem_destroy(&(sock->mutex));
 int shmID = sock->shmID;
 shmdt(&(sock->empty));
 shmctl(shmID, 0, 0);
 return 0;
}

variable_types: struct shm_socket_t { union sem_t { char __size[32]; long __align; } empty; union sem_t full; union sem_t mutex; int buflen; int shmID; int bufhead; int buftail; int connected; int sigclose; char buffer[5]; } *

variable_types: shmID int

user_defined_types: struct shm_socket_t { union sem_t empty; union sem_t full; union sem_t mutex; int buflen; int shmID; int bufhead; int buftail; int connected; int sigclose; char buffer[5]; }


decompiled_code:
__int64 __fastcall shm_close_client(void *shmaddr)
{
sem_wait((sem_t *)shmaddr + 2);
*((_QWORD *)shmaddr + 14) = 0x100000000LL;
sem_post((sem_t *)shmaddr + 2);
sem_post((sem_t *)shmaddr);
sem_post((sem_t *)shmaddr + 1);
shmdt(shmaddr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *shmaddr)
{
sem_wait((sem_t *)shmaddr + 2);
*((_QWORD *)shmaddr + 14) = 0x100000000LL;
sem_post((sem_t *)shmaddr + 2);
sem_post((sem_t *)shmaddr);
sem_post((sem_t *)shmaddr + 1);
shmdt(shmaddr);
return 0LL;
}

original_code:
int shm_close_client(shm_socket_t* sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_post(&(sock->mutex));
 sem_post(&(sock->empty));
 sem_post(&(sock->full));
 shmdt(sock);
 return 0;
}

canonical_original_code:
int shm_close_client(struct shm_socket_t *sock){
 sem_wait(&(sock->mutex));
 sock->connected = 0;
 sock->sigclose = 1;
 sem_post(&(sock->mutex));
 sem_post(&(sock->empty));
 sem_post(&(sock->full));
 shmdt(sock);
 return 0;
}

user_defined_types: union sem_t { char __size[32]; long __align; }