decompiled_code:
int quit_out()
{
__int64 v0; // rcx
__int64 v1; // rax
int v2; // eax
int v3; // er12
unsigned int v4; // er12
__int64 v5; // rax
__int64 v7; // [rsp+0h] [rbp-128h] BYREF
unsigned __int64 buf; // [rsp+8h] [rbp-120h] BYREF
char s[16]; // [rsp+10h] [rbp-118h] BYREF
char v10[16]; // [rsp+20h] [rbp-108h] BYREF

v0 = newpts - user_cdt - xfer_pts2;
xfer_pts2 = newpts - user_cdt;
v7 = v0 / 1024;
if ( v0 / 1024 )
{
buf = time_played / 0x3CuLL;
sprintf(s, "%-25.25s", (const char *)&user_name);
v2 = nopen("dpoker.plr", 1089LL);
v3 = v2;
if ( v2 != -1 )
{
write(v2, s, 0x19uLL);
write(v3, &buf, 8uLL);
write(v3, &v7, 8uLL);
close(v3);
}
}
v7 = 0LL;
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
get_game_status(cur_table);
v1 = node_num - 1;
if ( (unsigned __int8)(node[v1] - 1) <= 4u )
{
node[v1] = 0;
--total_players;
put_game_status(0xFFFFFFFF);
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
sprintf(s, asc_20F0, node_num, &user_name);
send_all_message(s, 0);
if ( total_players )
{
LODWORD(v1) = node_num;
if ( node_num == dealer && sys_nodes )
{
v1 = 1LL;
while ( 1 )
{
v4 = v1;
if ( node[v1 - 1] == 1 )
break;
if ( sys_nodes < (int)++v1 )
return v1;
}
dealer = v1;
if ( cur_node == node_num )
cur_node = v1;
if ( total_players == 1 )
{
current_bet = 0LL;
stage = 0;
}
put_game_status(0xFFFFFFFF);
get_player(v4);
v5 = username((unsigned __int16)temp_num);
sprintf(s, asc_2120, v5);
bprintf(s);
send_all_message(s, v4);
strcpy(v10, "w the dealer.");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC11);
LODWORD(v1) = send_player_message(v4, s);
}
}
else
{
sprintf(s, "gamestat.%d", (unsigned int)cur_table);
LODWORD(v1) = unlink(s);
}
}
return v1;
}

canonical_decompiled_code:
int func5()
{
__int64 v0; // rcx
__int64 v1; // rax
int v2; // eax
int v3; // er12
unsigned int v4; // er12
__int64 v5; // rax
__int64 v7; // [rsp+0h] [rbp-128h] BYREF
unsigned __int64 buf; // [rsp+8h] [rbp-120h] BYREF
char s[16]; // [rsp+10h] [rbp-118h] BYREF
char v10[16]; // [rsp+20h] [rbp-108h] BYREF

v0 = newpts - user_cdt - xfer_pts2;
xfer_pts2 = newpts - user_cdt;
v7 = v0 / 1024;
if ( v0 / 1024 )
{
buf = time_played / 0x3CuLL;
sprintf(s, "%-25.25s", (const char *)&user_name);
v2 = nopen("dpoker.plr", 1089LL);
v3 = v2;
if ( v2 != -1 )
{
write(v2, s, 0x19uLL);
write(v3, &buf, 8uLL);
write(v3, &v7, 8uLL);
close(v3);
}
}
v7 = 0LL;
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
func0(cur_table);
v1 = node_num - 1;
if ( (unsigned __int8)(node[v1] - 1) <= 4u )
{
node[v1] = 0;
--total_players;
func1(0xFFFFFFFF);
sprintf(s, "message.%d", node_num);
unlink(s);
sprintf(s, "player.%d", node_num);
unlink(s);
sprintf(s, asc_20F0, node_num, &user_name);
func4(s, 0);
if ( total_players )
{
LODWORD(v1) = node_num;
if ( node_num == dealer && sys_nodes )
{
v1 = 1LL;
while ( 1 )
{
v4 = v1;
if ( node[v1 - 1] == 1 )
break;
if ( sys_nodes < (int)++v1 )
return v1;
}
dealer = v1;
if ( cur_node == node_num )
cur_node = v1;
if ( total_players == 1 )
{
current_bet = 0LL;
stage = 0;
}
func1(0xFFFFFFFF);
func2(v4);
v5 = username((unsigned __int16)temp_num);
sprintf(s, asc_2120, v5);
bprintf(s);
func4(s, v4);
strcpy(v10, "w the dealer.");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC11);
LODWORD(v1) = func3(v4, s);
}
}
else
{
sprintf(s, "gamestat.%d", (unsigned int)cur_table);
LODWORD(v1) = unlink(s);
}
}
return v1;
}

original_code:
void quit_out()
{
    char str[256];
    int num,file;
    long xfer_pts;
    unsigned long x;
    xfer_pts=(newpts-user_cdt)-xfer_pts2;
    xfer_pts2+=xfer_pts;
    xfer_pts=xfer_pts/1024L;
    if (xfer_pts!=0) {
        x=time_played/60;
        sprintf(str,"%-25.25s",user_name);
        if ((file=nopen("dpoker.plr",01|0100|02000))!=-1) {
            write(file,str,25);
            write(file,&x,sizeof(x));
            write(file,&xfer_pts,sizeof(xfer_pts));
            close(file);
        }
    }
    xfer_pts=0;
    sprintf(str,"message.%d",node_num);
    unlink(str);
    sprintf(str,"player.%d",node_num);
    unlink(str);
    get_game_status(cur_table);
    if (node[node_num-1]>0 && node[node_num-1]<6) {
        node[node_num-1]=0; --total_players;
        put_game_status(-1);
        sprintf(str,"message.%d",node_num);
        unlink(str);
        sprintf(str,"player.%d",node_num);
        unlink(str);
        sprintf(str,"\r\n\1n\1gNode %2d: \1h%s \1n\1ghas left the game.\1n"
                ,node_num,user_name);
        send_all_message(str,0);
        if (!total_players) {
            sprintf(str,"gamestat.%d",cur_table);
            unlink(str);
            return;
        } else {
            if (dealer==node_num) {
                for (num=1;num<=sys_nodes;num++) {
                    if (node[num-1]==1) {
                        dealer=num; if (cur_node==node_num) cur_node=num;
                        if (total_players==1) { current_bet=0; stage=0; }
                        put_game_status(-1); get_player(num);
                        sprintf(str,"\r\n\1y\1h%s \1m\1his the new dealer."
                                ,username(temp_num));
                        bprintf(str);
                        send_all_message(str,num);
                        sprintf(str,"\r\n\1m\1hYou are now the dealer.");
                        send_player_message(num,str);
                        return;
                    }
                }
            }
        }
    }
}

canonical_original_code:
void quit_out()
{
    char str[256];
    int num; int file;
    long xfer_pts;
    unsigned long x;
    xfer_pts=(newpts-user_cdt)-xfer_pts2;
    xfer_pts2+=xfer_pts;
    xfer_pts=xfer_pts/1024L;
    if (xfer_pts!=0) {
        x=time_played/60;
        sprintf(str,"%-25.25s",user_name);
        if ((file=nopen("dpoker.plr",01|0100|02000))!=-1) {
            write(file,str,25);
            write(file,&x,sizeof(x));
            write(file,&xfer_pts,sizeof(xfer_pts));
            close(file);
        }
    }
    xfer_pts=0;
    sprintf(str,"message.%d",node_num);
    unlink(str);
    sprintf(str,"player.%d",node_num);
    unlink(str);
    get_game_status(cur_table);
    if (node[node_num-1]>0 && node[node_num-1]<6) {
        node[node_num-1]=0; --total_players;
        put_game_status(-1);
        sprintf(str,"message.%d",node_num);
        unlink(str);
        sprintf(str,"player.%d",node_num);
        unlink(str);
        sprintf(str,"\r\n\1n\1gNode %2d: \1h%s \1n\1ghas left the game.\1n"
                ,node_num,user_name);
        send_all_message(str,0);
        if (!total_players) {
            sprintf(str,"gamestat.%d",cur_table);
            unlink(str);
            return;
        } else {
            if (dealer==node_num) {
                for (num=1;num<=sys_nodes;num++) {
                    if (node[num-1]==1) {
                        dealer=num; if (cur_node==node_num) cur_node=num;
                        if (total_players==1) { current_bet=0; stage=0; }
                        put_game_status(-1); get_player(num);
                        sprintf(str,"\r\n\1y\1h%s \1m\1his the new dealer."
                                ,username(temp_num));
                        bprintf(str);
                        send_all_message(str,num);
                        sprintf(str,"\r\n\1m\1hYou are now the dealer.");
                        send_player_message(num,str);
                        return;
                    }
                }
            }
        }
    }
}

variable_types:
x
unsigned long


main

canonical_name: main

repo: ftnapps/pkg-sbbs

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rsi
const char **v5; // rbx
const char **v6; // r12
const char *v7; // rbp
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v4 = getenv("SBBSNODE");
strcpy(&node_dir, v4);
backslash(&node_dir);
if ( argc > 1 )
{
if ( !strcasecmp(argv[1], "/?") )
{
printf("\r\nDomain Poker Clean-Up Copyright 2005 Domain Entertainment");
puts("\r\n\r\nUsage: DPCLEAN [/options]\r");
printf("\r\nOptions: DAILY = Perform daily clean-up");
return 0;
}
v5 = argv + 1;
v6 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( 1 )
{
v7 = *v5;
if ( !strchr(*v5, 47) )
break;
if ( ++v5 == v6 )
goto LABEL_7;
}
++v5;
strcpy(&node_dir, v7);
backslash(&node_dir);
}
while ( v5 != v6 );
}
LABEL_7:
initdata();
sprintf(v9, "player.%d", node_num);
if ( (unsigned int)fexist(v9) )
{
get_player(node_num);
newpts = temppts;
quit_out();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rsi
const char **v5; // rbx
const char **v6; // r12
const char *v7; // rbp
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v4 = getenv("SBBSNODE");
strcpy(&node_dir, v4);
backslash(&node_dir);
if ( argc > 1 )
{
if ( !strcasecmp(argv[1], "/?") )
{
printf("\r\nDomain Poker Clean-Up Copyright 2005 Domain Entertainment");
puts("\r\n\r\nUsage: DPCLEAN [/options]\r");
printf("\r\nOptions: DAILY = Perform daily clean-up");
return 0;
}
v5 = argv + 1;
v6 = &argv[(unsigned int)(argc - 2) + 2];
do
{
while ( 1 )
{
v7 = *v5;
if ( !strchr(*v5, 47) )
break;
if ( ++v5 == v6 )
goto LABEL_7;
}
++v5;
strcpy(&node_dir, v7);
backslash(&node_dir);
}
while ( v5 != v6 );
}
LABEL_7:
initdata();
sprintf(v9, "player.%d", node_num);
if ( (unsigned int)fexist(v9) )
{
func2(node_num);
newpts = temppts;
func5();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    char str[128];
    int x;
    sprintf(node_dir,"%s",getenv("SBBSNODE"));
    backslash(node_dir);
    if(argc>1 && !strcasecmp(argv[1],"/?")) {
        printf("\r\nDomain Poker Clean-Up  Copyright 2005 Domain "
                "Entertainment");
        printf("\r\n\r\nUsage: DPCLEAN [/options]\r\n");
        printf("\r\nOptions: DAILY = Perform daily clean-up");
        return(0);
    }
    for (x=1; x<argc; x++) {
        if (!strchr(argv[x],'/')) {
            strcpy(node_dir,argv[x]);
            backslash(node_dir); } }
    initdata();
    sprintf(str,"player.%d",node_num);
    if (!fexist(str)) return(0);
    else {
        get_player(node_num);
        newpts=temppts;
        quit_out();
    }
    return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
str
char [128]

variable_types: x int

return_type: int


decompiled_code:
char *__fastcall telnet_cmd_desc(unsigned __int8 a1)
{
if ( a1 >= 0xF1u )
return CSWTCH_1[(unsigned __int8)(a1 + 15)];
sprintf(unknown_1, "%d", a1);
return unknown_1;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 a1)
{
if ( a1 >= 0xF1u )
return CSWTCH_1[(unsigned __int8)(a1 + 15)];
sprintf(unknown_1, "%d", a1);
return unknown_1;
}

original_code:
const char* telnet_cmd_desc(unsigned char cmd)
{
 static char unknown[32];
 switch(cmd) {
     case 255: return("IAC");
     case 254: return("DON'T");
     case 253: return("DO");
     case 252: return("WON'T");
     case 251: return("WILL");
     case 250: return("SB");
     case 249: return("GA");
     case 248: return("EL");
     case 247: return("EC");
     case 246: return("AYT");
     case 245: return("AO");
     case 244: return("IP");
     case 243: return("BRK");
     case 242: return("SYNC");
     case 241: return("NOP");
        default:
   sprintf(unknown,"%d",cmd);
            return(unknown);
 }
}

canonical_original_code:
char *telnet_cmd_desc(unsigned char cmd)
{
 static char unknown[32];
 switch(cmd) {
     case 255: return("IAC");
     case 254: return("DON'T");
     case 253: return("DO");
     case 252: return("WON'T");
     case 251: return("WILL");
     case 250: return("SB");
     case 249: return("GA");
     case 248: return("EL");
     case 247: return("EC");
     case 246: return("AYT");
     case 245: return("AO");
     case 244: return("IP");
     case 243: return("BRK");
     case 242: return("SYNC");
     case 241: return("NOP");
        default:
   sprintf(unknown,"%d",cmd);
            return(unknown);
 }
}

variable_types:
cmd
unsigned char

variable_types:
unknown
char [32]

return_type: char *


decompiled_code:
const char *__fastcall telnet_opt_desc(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 <= 0x28u )
return (&telnet_option_descriptions)[a1];
result = "Extended Options List";
if ( a1 != 0xFF )
{
sprintf(unknown_0, "%d", a1);
result = unknown_0;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 <= 0x28u )
return (&telnet_option_descriptions)[a1];
result = "Extended Options List";
if ( a1 != 0xFF )
{
sprintf(unknown_0, "%d", a1);
result = unknown_0;
}
return result;
}

original_code:
const char* telnet_opt_desc(unsigned char opt)
{
 static char unknown[32];
 if(opt<sizeof(telnet_option_descriptions)/sizeof(char*))
  return(telnet_option_descriptions[opt]);
 if(opt==TELNET_EXOPL)
  return("Extended Options List");
 sprintf(unknown,"%d",opt);
    return(unknown);
}

canonical_original_code:
char *telnet_opt_desc(unsigned char opt)
{
 static char unknown[32];
 if(opt<sizeof(telnet_option_descriptions)/sizeof(char *))
  return(telnet_option_descriptions[opt]);
 if(opt==TELNET_EXOPL)
  return("Extended Options List");
 sprintf(unknown,"%d",opt);
    return(unknown);
}

variable_types:
opt
unsigned char


decompiled_code:
__int64 __fastcall telnet_opt_ack(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 + 5;
result = 0LL;
if ( v1 <= 3u )
result = (unsigned __int8)CSWTCH_4[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

v1 = a1 + 5;
result = 0LL;
if ( v1 <= 3u )
result = (unsigned __int8)CSWTCH_4[v1];
return result;
}

original_code:
unsigned char telnet_opt_ack(unsigned char cmd)
{
 switch(cmd) {
  case 253: return 251;
  case 254: return 252;
  case 251: return 253;
  case 252: return 254;
 }
 return 0;
}

return_type: unsigned char


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

result = (unsigned int)(-7 - a1);
if ( (unsigned __int8)(a1 + 5) >= 4u )
result = 0LL;
return result;
}

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

result = (unsigned int)(-7 - a1);
if ( (unsigned __int8)(a1 + 5) >= 4u )
result = 0LL;
return result;
}

original_code:
unsigned char telnet_opt_nak(unsigned char cmd)
{
 switch(cmd) {
  case 253: return 252;
  case 254: return 251;
  case 251: return 254;
  case 252: return 253;
 }
 return 0;
}


getSocketOptionByName

decompiled_code:
__int64 __fastcall getSocketOptionByName(char *nptr, _DWORD *a2)
{
const char *v3; // rsi
const char **v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( a2 )
*a2 = 1;
v3 = socket_options;
if ( socket_options )
{
v4 = (const char **)&off_698;
v5 = 0;
while ( strcasecmp(nptr, v3) )
{
v3 = *v4;
v4 += 3;
++v5;
if ( !v3 )
goto LABEL_10;
}
if ( a2 )
*a2 = dword_68C[6 * v5];
result = (unsigned int)dword_690[6 * v5];
}
else
{
LABEL_10:
if ( (unsigned int)(*nptr - 48) > 9 )
result = 0xFFFFFFFFLL;
else
result = strtol(nptr, 0LL, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr, _DWORD *a2)
{
const char *v3; // rsi
const char **v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( a2 )
*a2 = 1;
v3 = socket_options;
if ( socket_options )
{
v4 = (const char **)&off_698;
v5 = 0;
while ( strcasecmp(nptr, v3) )
{
v3 = *v4;
v4 += 3;
++v5;
if ( !v3 )
goto LABEL_10;
}
if ( a2 )
*a2 = dword_68C[6 * v5];
result = (unsigned int)dword_690[6 * v5];
}
else
{
LABEL_10:
if ( (unsigned int)(*nptr - 48) > 9 )
result = 0xFFFFFFFFLL;
else
result = strtol(nptr, 0LL, 0);
}
return result;
}

original_code:
int getSocketOptionByName(const char* name, int* level)
{
 int i;
 if(level!=((void *)0))
  *level=1;
 for(i=0;socket_options[i].name;i++) {
  if(strcasecmp(name,socket_options[i].name)==0) {
   if(level!=((void *)0))
    *level = socket_options[i].level;
   return(socket_options[i].value);
  }
 }
 if(!isdigit(*name))
  return(-1);
 return(strtol(name,((void *)0),0));
}

canonical_original_code:
int getSocketOptionByName(char *name, int *level)
{
 int i;
 if(level!=((void *)0))
  *level=1;
 for(i=0;socket_options[i].name;i++) {
  if(strcasecmp(name,socket_options[i].name)==0) {
   if(level!=((void *)0))
    *level = socket_options[i].level;
   return(socket_options[i].value);
  }
 }
 if(!isdigit(*name))
  return(-1);
 return(strtol(name,((void *)0),0));
}

variable_types:
name
char *

variable_types:
level
int *

variable_types: i int


getSocketOptionList

decompiled_code:
char **getSocketOptionList()
{
return &socket_options;
}

canonical_decompiled_code:
char **func2()
{
return &socket_options;
}

original_code:
socket_option_t* getSocketOptionList(void)
{
 return(socket_options);
}

canonical_original_code:
struct socket_option_t *getSocketOptionList()
{
 return(socket_options);
}

return_type: struct socket_option_t { char *name; int type; int level; int value; } *


sendfilesocket

decompiled_code:
__int64 __fastcall sendfilesocket(int fd, unsigned int a2, __off_t *a3, __int64 a4)
{
__off_t *v5; // rbp
__int64 v6; // rbx
__int64 v7; // rbx
int v8; // eax
int v9; // er13
int v10; // ebp
int v11; // ebx
int v12; // eax
unsigned int v13; // er8
__int64 v15; // rbx
signed int v16; // [rsp+4h] [rbp-4054h]
struct timeval timeout; // [rsp+10h] [rbp-4048h] BYREF
char buf[16440]; // [rsp+20h] [rbp-4038h] BYREF

v5 = a3;
v6 = filelength(a2);
if ( v5 && lseek(a2, *v5, 0) < 0 )
return (unsigned int)-1;
if ( a4 > 0 && v6 >= a4 )
{
LABEL_5:
v16 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(a2, buf, 0x4000uLL);
v9 = v8;
v10 = v8;
if ( v8 == -1 )
return (unsigned int)-1;
if ( !v8 )
{
v13 = v16;
goto LABEL_24;
}
if ( v8 <= 0 )
return (unsigned int)-1;
v11 = 0;
do
{
while ( 1 )
{
v12 = write(fd, &buf[v11], v10 - v11);
v13 = v12;
if ( v12 <= 0 )
break;
v11 += v12;
if ( v11 >= v10 )
goto LABEL_15;
}
if ( v12 != -1 )
return v13;
if ( *_errno_location() != 11 )
return (unsigned int)-1;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &timeout);
}
while ( v11 < v10 );
LABEL_15:
if ( v11 != v9 )
return (unsigned int)-1;
v16 += v11;
v7 = v16;
if ( v16 >= a4 )
{
v13 = v16;
goto LABEL_24;
}
}
}
v15 = v6 - lseek(a2, 0LL, 1);
a4 = v15;
if ( v15 < 0 )
{
*_errno_location() = 22;
return (unsigned int)-1;
}
if ( v15 )
goto LABEL_5;
v7 = 0LL;
v13 = 0;
LABEL_24:
if ( a3 )
*a3 += v7;
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, unsigned int a2, __off_t *a3, __int64 a4)
{
__off_t *v5; // rbp
__int64 v6; // rbx
__int64 v7; // rbx
int v8; // eax
int v9; // er13
int v10; // ebp
int v11; // ebx
int v12; // eax
unsigned int v13; // er8
__int64 v15; // rbx
signed int v16; // [rsp+4h] [rbp-4054h]
struct timeval timeout; // [rsp+10h] [rbp-4048h] BYREF
char buf[16440]; // [rsp+20h] [rbp-4038h] BYREF

v5 = a3;
v6 = filelength(a2);
if ( v5 && lseek(a2, *v5, 0) < 0 )
return (unsigned int)-1;
if ( a4 > 0 && v6 >= a4 )
{
LABEL_5:
v16 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = read(a2, buf, 0x4000uLL);
v9 = v8;
v10 = v8;
if ( v8 == -1 )
return (unsigned int)-1;
if ( !v8 )
{
v13 = v16;
goto LABEL_24;
}
if ( v8 <= 0 )
return (unsigned int)-1;
v11 = 0;
do
{
while ( 1 )
{
v12 = write(fd, &buf[v11], v10 - v11);
v13 = v12;
if ( v12 <= 0 )
break;
v11 += v12;
if ( v11 >= v10 )
goto LABEL_15;
}
if ( v12 != -1 )
return v13;
if ( *_errno_location() != 11 )
return (unsigned int)-1;
timeout.tv_sec = 0LL;
timeout.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &timeout);
}
while ( v11 < v10 );
LABEL_15:
if ( v11 != v9 )
return (unsigned int)-1;
v16 += v11;
v7 = v16;
if ( v16 >= a4 )
{
v13 = v16;
goto LABEL_24;
}
}
}
v15 = v6 - lseek(a2, 0LL, 1);
a4 = v15;
if ( v15 < 0 )
{
*_errno_location() = 22;
return (unsigned int)-1;
}
if ( v15 )
goto LABEL_5;
v7 = 0LL;
v13 = 0;
LABEL_24:
if ( a3 )
*a3 += v7;
return v13;
}

original_code:
int sendfilesocket(int sock, int file, long *offset, long count)
{
 char buf[1024*16];
 long len;
 int rd;
 int wr=0;
 int total=0;
 int i;
 len=filelength(file);
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 if(count<1 || count>len) {
  count=len;
  count-=lseek(file,0,1);
 }
 if(count<0) {
  (*__errno_location ())=22;
  return(-1);
 }
 while(total<count) {
  rd=read(file,buf,sizeof(buf));
  if(rd==-1)
   return(-1);
  if(rd==0)
   break;
  for(i=wr=0;i<rd;i+=wr) {
   wr=write(sock,buf+i,rd-i);
   if(wr>0)
    continue;
   if(wr==-1 && (*__errno_location ())==11) {
    wr=0;
    ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
    continue;
   }
   return(wr);
  }
  if(i!=rd)
   return(-1);
  total+=rd;
 }
 if(offset!=((void *)0))
  (*offset)+=total;
 return(total);
}

canonical_original_code:
int sendfilesocket(int sock, int file, long *offset, long count)
{
 char buf[-1];
 long len;
 int rd;
 int wr = 0;
 int total = 0;
 int i;
 len=filelength(file);
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 if(count<1 || count>len) {
  count=len;
  count-=lseek(file,0,1);
 }
 if(count<0) {
  (*__errno_location ())=22;
  return(-1);
 }
 while(total<count) {
  rd=read(file,buf,sizeof(buf));
  if(rd==-1)
   return(-1);
  if(rd==0)
   break;
  for(i=wr=0;i<rd;i+=wr) {
   wr=write(sock,buf+i,rd-i);
   if(wr>0)
    continue;
   if(wr==-1 && (*__errno_location ())==11) {
    wr=0;
    ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
    continue;
   }
   return(wr);
  }
  if(i!=rd)
   return(-1);
  total+=rd;
 }
 if(offset!=((void *)0))
  (*offset)+=total;
 return(total);
}

variable_types: sock int

variable_types: file int

variable_types:
offset
long *

variable_types: count long

variable_types:
buf
char [-1]

variable_types: len long

variable_types: rd int

variable_types: wr int

variable_types: total int

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


recvfilesocket

decompiled_code:
__int64 __fastcall recvfilesocket(int fd, int a2, __off_t *a3, signed __int64 a4)
{
void *v6; // rsp
unsigned int v7; // er8
size_t v9; // rdx
int *v10; // rax
_BYTE v11[15]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 <= 0 )
{
v10 = _errno_location();
v7 = -1;
*v10 = 34;
return v7;
}
v6 = alloca(a4 + 8);
if ( !a3 )
{
v9 = (int)read(fd, v11, a4);
if ( v9 == a4 )
return (unsigned int)write(a2, v11, v9);
return (unsigned int)-1;
}
if ( lseek(a2, *a3, 0) < 0 || a4 != (int)read(fd, v11, a4) )
return (unsigned int)-1;
v7 = write(a2, v11, a4);
*a3 += (int)v7;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2, __off_t *a3, signed __int64 a4)
{
void *v6; // rsp
unsigned int v7; // er8
size_t v9; // rdx
int *v10; // rax
_BYTE v11[15]; // [rsp+0h] [rbp-30h] BYREF

if ( a4 <= 0 )
{
v10 = _errno_location();
v7 = -1;
*v10 = 34;
return v7;
}
v6 = alloca(a4 + 8);
if ( !a3 )
{
v9 = (int)read(fd, v11, a4);
if ( v9 == a4 )
return (unsigned int)write(a2, v11, v9);
return (unsigned int)-1;
}
if ( lseek(a2, *a3, 0) < 0 || a4 != (int)read(fd, v11, a4) )
return (unsigned int)-1;
v7 = write(a2, v11, a4);
*a3 += (int)v7;
return v7;
}

original_code:
int recvfilesocket(int sock, int file, long *offset, long count)
{
 char* buf;
 int rd;
 int wr;
 if(count<1) {
  (*__errno_location ())=34;
  return(-1);
 }
 if((buf=(char*)__builtin_alloca (count))==((void *)0)) {
  (*__errno_location ())=12;
  return(-1);
 }
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 rd=read(sock,buf,count);
 if(rd!=count)
  return(-1);
 wr=write(file,buf,rd);
 if(offset!=((void *)0))
  (*offset)+=wr;
 return(wr);
}

canonical_original_code:
int recvfilesocket(int sock, int file, long *offset, long count)
{
 char *buf;
 int rd;
 int wr;
 if(count<1) {
  (*__errno_location ())=34;
  return(-1);
 }
 if((buf=(char *)__builtin_alloca (count))==((void *)0)) {
  (*__errno_location ())=12;
  return(-1);
 }
 if(offset!=((void *)0))
  if(lseek(file,*offset,0)<0)
   return(-1);
 rd=read(sock,buf,count);
 if(rd!=count)
  return(-1);
 wr=write(file,buf,rd);
 if(offset!=((void *)0))
  (*offset)+=wr;
 return(wr);
}

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall socket_check(int fd, _DWORD *a2, _DWORD *a3, unsigned __int64 a4)
{
fd_set *v5; // r9
fd_set *v6; // r15
__int64 v7; // rbx
__int64 v8; // r14
int v9; // eax
int v11; // edx
char buf; // [rsp+Fh] [rbp-149h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-148h] BYREF
fd_set readfds; // [rsp+20h] [rbp-138h] BYREF
__int64 v15[23]; // [rsp+A0h] [rbp-B8h] BYREF

if ( a2 )
*a2 = 0;
if ( a3 )
*a3 = 0;
if ( fd == -1 )
return 0LL;
v5 = &readfds;
memset(&readfds, 0, sizeof(readfds));
v6 = 0LL;
v7 = fd / 64;
v8 = 1LL << (fd % 64);
readfds.fds_bits[v7] |= v8;
if ( a3 )
{
v6 = (fd_set *)v15;
memset(v15, 0, 0x80uLL);
v15[v7] |= v8;
if ( !a2 )
v5 = 0LL;
}
timeout.tv_sec = a4 / 0x3E8;
timeout.tv_usec = 1000 * (a4 % 0x3E8);
v9 = select(fd + 1, v5, v6, 0LL, &timeout);
if ( v9 == -1 )
return 0LL;
if ( !v9 )
return 1LL;
if ( a3 )
{
if ( (v6->fds_bits[v7] & v8) != 0 )
{
*a3 = 1;
if ( v9 == 1 )
return 1LL;
}
if ( !a2 )
return 0LL;
v11 = recv(fd, &buf, 1uLL, 2);
if ( v11 == 1 )
goto LABEL_20;
}
else
{
v11 = recv(fd, &buf, 1uLL, 2);
if ( v11 == 1 )
goto LABEL_19;
}
if ( v11 != -1 || *_errno_location() != 90 )
return 0LL;
LABEL_19:
if ( a2 )
LABEL_20:
*a2 = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, _DWORD *a2, _DWORD *a3, unsigned __int64 a4)
{
fd_set *v5; // r9
fd_set *v6; // r15
__int64 v7; // rbx
__int64 v8; // r14
int v9; // eax
int v11; // edx
char buf; // [rsp+Fh] [rbp-149h] BYREF
struct timeval timeout; // [rsp+10h] [rbp-148h] BYREF
fd_set readfds; // [rsp+20h] [rbp-138h] BYREF
__int64 v15[23]; // [rsp+A0h] [rbp-B8h] BYREF

if ( a2 )
*a2 = 0;
if ( a3 )
*a3 = 0;
if ( fd == -1 )
return 0LL;
v5 = &readfds;
memset(&readfds, 0, sizeof(readfds));
v6 = 0LL;
v7 = fd / 64;
v8 = 1LL << (fd % 64);
readfds.fds_bits[v7] |= v8;
if ( a3 )
{
v6 = (fd_set *)v15;
memset(v15, 0, 0x80uLL);
v15[v7] |= v8;
if ( !a2 )
v5 = 0LL;
}
timeout.tv_sec = a4 / 0x3E8;
timeout.tv_usec = 1000 * (a4 % 0x3E8);
v9 = select(fd + 1, v5, v6, 0LL, &timeout);
if ( v9 == -1 )
return 0LL;
if ( !v9 )
return 1LL;
if ( a3 )
{
if ( (v6->fds_bits[v7] & v8) != 0 )
{
*a3 = 1;
if ( v9 == 1 )
return 1LL;
}
if ( !a2 )
return 0LL;
v11 = recv(fd, &buf, 1uLL, 2);
if ( v11 == 1 )
goto LABEL_20;
}
else
{
v11 = recv(fd, &buf, 1uLL, 2);
if ( v11 == 1 )
goto LABEL_19;
}
if ( v11 != -1 || *_errno_location() != 90 )
return 0LL;
LABEL_19:
if ( a2 )
LABEL_20:
*a2 = 1;
return 1LL;
}

original_code:
int socket_check(int sock, int* rd_p, int* wr_p, ulong timeout)
{
 char ch;
 int i,rd;
 fd_set rd_set;
 fd_set* rd_set_p=&rd_set;
 fd_set wr_set;
 fd_set* wr_set_p=((void *)0);
 struct timeval tv;
 if(rd_p!=((void *)0))
  *rd_p=0;
 if(wr_p!=((void *)0))
  *wr_p=0;
 if(sock==(int)(~0))
  return(0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 if(wr_p!=((void *)0)) {
  wr_set_p=&wr_set;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wr_set_p)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  if(rd_p==((void *)0))
   rd_set_p=((void *)0);
 }
 tv.tv_sec=timeout/1000;
 tv.tv_usec=(timeout%1000)*1000;
 i=select(sock+1,rd_set_p,wr_set_p,((void *)0),&tv);
 if(i==-1)
  return(0);
 if(i==0)
  return(1);
 if(wr_p!=((void *)0) && ((((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  *wr_p=1;
  if(i==1)
   return(1);
 }
 if(rd_p !=((void *)0) || wr_p==((void *)0)) {
  rd=recv(sock,&ch,1,MSG_PEEK);
  if(rd==1
   || (rd==-1 && (*__errno_location ())==90)) {
   if(rd_p!=((void *)0))
    *rd_p=1;
   return(1);
  }
 }
 return(0);
}

canonical_original_code:
int socket_check(int sock, int *rd_p, int *wr_p, unsigned long timeout)
{
 char ch;
 int i; int rd;
 struct fd_set rd_set;
 struct fd_set *rd_set_p = &rd_set;
 struct fd_set wr_set;
 struct fd_set *wr_set_p = ((void *)0);
 struct timeval tv;
 if(rd_p!=((void *)0))
  *rd_p=0;
 if(wr_p!=((void *)0))
  *wr_p=0;
 if(sock==(int)(~0))
  return(0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd_set)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&rd_set)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
 if(wr_p!=((void *)0)) {
  wr_set_p=&wr_set;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wr_set_p)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
  if(rd_p==((void *)0))
   rd_set_p=((void *)0);
 }
 tv.tv_sec=timeout/1000;
 tv.tv_usec=(timeout%1000)*1000;
 i=select(sock+1,rd_set_p,wr_set_p,((void *)0),&tv);
 if(i==-1)
  return(0);
 if(i==0)
  return(1);
 if(wr_p!=((void *)0) && ((((wr_set_p)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
  *wr_p=1;
  if(i==1)
   return(1);
 }
 if(rd_p !=((void *)0) || wr_p==((void *)0)) {
  rd=recv(sock,&ch,1,MSG_PEEK);
  if(rd==1
   || (rd==-1 && (*__errno_location ())==90)) {
   if(rd_p!=((void *)0))
    *rd_p=1;
   return(1);
  }
 }
 return(0);
}

variable_types:
timeout
unsigned long

variable_types: ch char

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

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


decompiled_code:
__int64 __fastcall retry_bind(int fd, __int64 a2, socklen_t a3, unsigned int a4, unsigned int a5, const char *a6, __int64 a7)
{
unsigned int i; // ebp
__int64 v9; // rcx
unsigned int v10; // er12
unsigned int v11; // ebx
unsigned __int16 v13; // ax
__int64 v14; // rdx
struct timeval timeout; // [rsp+30h] [rbp-C8h] BYREF
char v19[184]; // [rsp+40h] [rbp-B8h] BYREF

if ( *(_WORD *)a2 == 2 )
{
v13 = _bswap_16(*(_WORD *)(a2 + 2));
safe_snprintf(v19, 128LL, v14, v13);
v19[127] = 0;
}
else
{
v19[0] = 0;
}
for ( i = 0; ; ++i )
{
v10 = bind(fd, (const struct sockaddr *)a2, a3);
if ( !v10 )
break;
v11 = i + 1;
if ( a7 )
{
v9 = (unsigned int)*_errno_location();
if ( i >= a4 )
{
((void (*)(__int64, const char *, ...))a7)(
3LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v9,
a6,
v19);
}
else
{
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v9,
a6,
v19);
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d Will retry in %u seconds (%u of %u)",
(unsigned int)fd,
a5,
v11,
a4);
LABEL_6:
timeout.tv_sec = (int)(1000 * a5) / 1000;
timeout.tv_usec = 1000 * ((int)(1000 * a5) % 1000);
select(0, 0LL, 0LL, 0LL, &timeout);
}
if ( a4 < v11 )
return v10;
continue;
}
if ( i < a4 )
goto LABEL_6;
if ( a4 < v11 )
return v10;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, __int64 a2, socklen_t a3, unsigned int a4, unsigned int a5, const char *a6, __int64 a7)
{
unsigned int i; // ebp
__int64 v9; // rcx
unsigned int v10; // er12
unsigned int v11; // ebx
unsigned __int16 v13; // ax
__int64 v14; // rdx
struct timeval timeout; // [rsp+30h] [rbp-C8h] BYREF
char v19[184]; // [rsp+40h] [rbp-B8h] BYREF

if ( *(_WORD *)a2 == 2 )
{
v13 = func0(*(_WORD *)(a2 + 2));
safe_snprintf(v19, 128LL, v14, v13);
v19[127] = 0;
}
else
{
v19[0] = 0;
}
for ( i = 0; ; ++i )
{
v10 = bind(fd, (const struct sockaddr *)a2, a3);
if ( !v10 )
break;
v11 = i + 1;
if ( a7 )
{
v9 = (unsigned int)*_errno_location();
if ( i >= a4 )
{
((void (*)(__int64, const char *, ...))a7)(
3LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v9,
a6,
v19);
}
else
{
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d !ERROR %d binding %s socket%s",
(unsigned int)fd,
v9,
a6,
v19);
((void (*)(__int64, const char *, ...))a7)(
4LL,
"%04d Will retry in %u seconds (%u of %u)",
(unsigned int)fd,
a5,
v11,
a4);
LABEL_6:
timeout.tv_sec = (int)(1000 * a5) / 1000;
timeout.tv_usec = 1000 * ((int)(1000 * a5) % 1000);
select(0, 0LL, 0LL, 0LL, &timeout);
}
if ( a4 < v11 )
return v10;
continue;
}
if ( i < a4 )
goto LABEL_6;
if ( a4 < v11 )
return v10;
}
return v10;
}

original_code:
int retry_bind(int s, const struct sockaddr *addr, socklen_t addrlen
      ,uint retries, uint wait_secs
      ,const char* prot
      ,int (*lprintf)(int level, char *fmt, ...))
{
 char port_str[128];
 int result=-1;
 uint i;
 if(addr->sa_family==2)
  safe_snprintf(port_str,sizeof(port_str)," to port %u",ntohs(((struct sockaddr_in *)(addr))->sin_port)), port_str[sizeof(port_str)-1]=0;
 else
  port_str[0]=0;
 for(i=0;i<=retries;i++) {
  if((result=bind(s,addr,addrlen))==0)
   break;
  if(lprintf!=((void *)0))
   lprintf(i<retries ? 4:3
    ,"%04d !ERROR %d binding %s socket%s", s, (*__errno_location ()), prot, port_str);
  if(i<retries) {
   if(lprintf!=((void *)0))
    lprintf(4,"%04d Will retry in %u seconds (%u of %u)"
     ,s, wait_secs, i+1, retries);
   ({ int sleep_msecs=wait_secs*1000; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  }
 }
 return(result);
}

canonical_original_code:
int retry_bind(int s, struct sockaddr *addr, unsigned int addrlen, unsigned int retries, unsigned int wait_secs, char *prot, int (*lprintf)(int level, char *fmt, ...))
{
 char port_str[128];
 int result = -1;
 unsigned int i;
 if(addr->sa_family==2)
  safe_snprintf(port_str,sizeof(port_str)," to port %u",ntohs(((struct sockaddr_in *)(addr))->sin_port)), port_str[sizeof(port_str)-1]=0;
 else
  port_str[0]=0;
 for(i=0;i<=retries;i++) {
  if((result=bind(s,addr,addrlen))==0)
   break;
  if(lprintf!=((void *)0))
   lprintf(i<retries ? 4:3
    ,"%04d !ERROR %d binding %s socket%s", s, (*__errno_location ()), prot, port_str);
  if(i<retries) {
   if(lprintf!=((void *)0))
    lprintf(4,"%04d Will retry in %u seconds (%u of %u)"
     ,s, wait_secs, i+1, retries);
   ({ int sleep_msecs = wait_secs*1000; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  }
 }
 return(result);
}

variable_types: s int

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

variable_types:
addrlen
unsigned int

variable_types:
retries
unsigned int

variable_types:
prot
char *

variable_types:
lprintf
int (*)(int level, char *fmt, ...)

variable_types: result int

variable_types:
i
unsigned 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]; }


decompiled_code:
time_t __fastcall sane_mktime(struct tm *tp)
{
int v1; // eax
int v2; // eax

v1 = tp->tm_year;
if ( v1 > 1899 )
tp->tm_year = v1 - 1900;
v2 = tp->tm_mon;
if ( v2 )
tp->tm_mon = v2 - 1;
tp->tm_isdst = -1;
return mktime(tp);
}

canonical_decompiled_code:
time_t __fastcall func0(struct tm *tp)
{
int v1; // eax
int v2; // eax

v1 = tp->tm_year;
if ( v1 > 1899 )
tp->tm_year = v1 - 1900;
v2 = tp->tm_mon;
if ( v2 )
tp->tm_mon = v2 - 1;
tp->tm_isdst = -1;
return mktime(tp);
}

original_code:
time_t sane_mktime(struct tm* tm)
{
 if(tm->tm_year>=1900)
  tm->tm_year-=1900;
 if(tm->tm_mon)
  tm->tm_mon--;
 tm->tm_isdst=-1;
 return mktime(tm);
}

canonical_original_code:
long sane_mktime(struct tm *tm)
{
 if(tm->tm_year>=1900)
  tm->tm_year-=1900;
 if(tm->tm_mon)
  tm->tm_mon--;
 tm->tm_isdst=-1;
 return mktime(tm);
}

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

return_type: long


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

*(_DWORD *)(a1 + 4) = a3;
result = a1;
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 8) = a4;
*(_DWORD *)(a1 + 12) = a5;
*(_DWORD *)(a1 + 16) = a6;
*(_DWORD *)(a1 + 24) = a8;
*(float *)(a1 + 20) = a7;
return result;
}

original_code:
xpDateTime_t xpDateTime_create(unsigned year, unsigned month, unsigned day
         ,unsigned hour, unsigned minute, float second
         ,xpTimeZone_t zone)
{
 xpDateTime_t xpDateTime;
 xpDateTime.date.year = year;
 xpDateTime.date.month = month;
 xpDateTime.date.day = day;
 xpDateTime.time.hour = hour;
 xpDateTime.time.minute = minute;
 xpDateTime.time.second = second;
 xpDateTime.zone = zone;
 return xpDateTime;
}

canonical_original_code:
struct xpDateTime_t xpDateTime_create(unsigned int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, float second, int zone)
{
 struct xpDateTime_t xpDateTime;
 xpDateTime.date.year = year;
 xpDateTime.date.month = month;
 xpDateTime.date.day = day;
 xpDateTime.time.hour = hour;
 xpDateTime.time.minute = minute;
 xpDateTime.time.second = second;
 xpDateTime.zone = zone;
 return xpDateTime;
}

variable_types:
year
unsigned int

variable_types:
month
unsigned int

variable_types:
day
unsigned int

variable_types:
hour
unsigned int

variable_types:
minute
unsigned int

variable_types: second float

variable_types: zone int

variable_types: struct xpDateTime_t { struct xpDate_t { unsigned int year; unsigned int month; unsigned int day; } date; struct xpTime_t { unsigned int hour; unsigned int minute; float second; } time; int zone; }

user_defined_types: struct xpDateTime_t { struct xpDate_t date; struct xpTime_t time; int zone; }


decompiled_code:
__int64 xpTimeZone_local()
{
return timezone / -60;
}

canonical_decompiled_code:
__int64 func2()
{
return timezone / -60;
}

original_code:
xpTimeZone_t xpTimeZone_local(void)
{
 return -timezone/60;
}

canonical_original_code:
int xpTimeZone_local()
{
 return -timezone/60;
}


decompiled_code:
__int64 __fastcall xpDateTime_now(__int64 a1)
{
int v1; // eax
float v2; // xmm0_4
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
struct tm tp; // [rsp+20h] [rbp-48h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
localtime_r(&timer, &tp);
v1 = xpTimeZone_local(a1, 0.0, 0.0);
v2 = (double)SLODWORD(tv.tv_usec) * 0.00001 + (float)tp.tm_sec;
xpDateTime_create(a1, tp.tm_year + 1900, tp.tm_mon + 1, tp.tm_mday, tp.tm_hour, tp.tm_min, v2, v1);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
float v2; // xmm0_4
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct timeval tv; // [rsp+10h] [rbp-58h] BYREF
struct tm tp; // [rsp+20h] [rbp-48h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
localtime_r(&timer, &tp);
v1 = func2(a1, 0.0, 0.0);
v2 = (double)SLODWORD(tv.tv_usec) * 0.00001 + (float)tp.tm_sec;
func1(a1, tp.tm_year + 1900, tp.tm_mon + 1, tp.tm_mday, tp.tm_hour, tp.tm_min, v2, v1);
return a1;
}

original_code:
xpDateTime_t xpDateTime_now(void)
{
 struct tm tm;
 struct timeval tv;
 time_t t;
 gettimeofday(&tv, ((void *)0));
 t=tv.tv_sec;
 localtime_r(&t,&tm);
 return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday
  ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec+(tv.tv_usec*0.00001)
  ,xpTimeZone_local());
}

canonical_original_code:
struct xpDateTime_t xpDateTime_now()
{
 struct tm tm;
 struct timeval tv;
 long t;
 gettimeofday(&tv, ((void *)0));
 t=tv.tv_sec;
 localtime_r(&t,&tm);
 return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday
  ,tm.tm_hour,tm.tm_min,(float)tm.tm_sec+(tv.tv_usec*0.00001)
  ,xpTimeZone_local());
}

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

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

variable_types: t long

return_type: struct xpDateTime_t { struct xpDate_t { unsigned int year; unsigned int month; unsigned int day; } date; struct xpTime_t { unsigned int hour; unsigned int minute; float second; } time; int zone; }


decompiled_code:
time_t __fastcall xpDateTime_to_time(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
time_t result; // rax
struct tm v10; // [rsp+0h] [rbp-48h] BYREF

result = 0LL;
*(_OWORD *)&v10.tm_mon = 0LL;
v10.tm_zone = 0LL;
*(_OWORD *)&v10.tm_isdst = 0LL;
if ( (_DWORD)a7 )
{
v10.tm_mon = HIDWORD(a7);
v10.tm_year = a7;
v10.tm_hour = HIDWORD(a8);
v10.tm_mday = a8;
v10.tm_min = a9;
v10.tm_sec = (int)*((float *)&a9 + 1);
result = sane_mktime(&v10);
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
time_t result; // rax
struct tm v10; // [rsp+0h] [rbp-48h] BYREF

result = 0LL;
*(_OWORD *)&v10.tm_mon = 0LL;
v10.tm_zone = 0LL;
*(_OWORD *)&v10.tm_isdst = 0LL;
if ( (_DWORD)a7 )
{
v10.tm_mon = HIDWORD(a7);
v10.tm_year = a7;
v10.tm_hour = HIDWORD(a8);
v10.tm_mday = a8;
v10.tm_min = a9;
v10.tm_sec = (int)*((float *)&a9 + 1);
result = func0(&v10);
}
return result;
}

original_code:
time_t xpDateTime_to_time(xpDateTime_t xpDateTime)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(xpDateTime.date.year==0)
  return(0);
 tm.tm_year = xpDateTime.date.year;
 tm.tm_mon = xpDateTime.date.month;
 tm.tm_mday = xpDateTime.date.day;
 tm.tm_hour = xpDateTime.time.hour;
 tm.tm_min = xpDateTime.time.minute;
 tm.tm_sec = (int)xpDateTime.time.second;
 return sane_mktime(&tm);
}

canonical_original_code:
long xpDateTime_to_time(struct xpDateTime_t xpDateTime)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(xpDateTime.date.year==0)
  return(0);
 tm.tm_year = xpDateTime.date.year;
 tm.tm_mon = xpDateTime.date.month;
 tm.tm_mday = xpDateTime.date.day;
 tm.tm_hour = xpDateTime.time.hour;
 tm.tm_min = xpDateTime.time.minute;
 tm.tm_sec = (int)xpDateTime.time.second;
 return sane_mktime(&tm);
}

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

user_defined_types: struct xpDate_t { unsigned int year; unsigned int month; unsigned int day; }

user_defined_types: struct xpTime_t { unsigned int hour; unsigned int minute; float second; }


decompiled_code:
__int64 __fastcall xpDateTime_to_isoDateTime(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
if ( a1 )
{
*a1 = 0LL;
if ( (_DWORD)a7 )
{
*a1 = (unsigned int)((int)*((float *)&a9 + 1) + 100 * a9 + 10000 * HIDWORD(a8));
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
}
}
else if ( (_DWORD)a7 )
{
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
if ( a1 )
{
*a1 = 0LL;
if ( (_DWORD)a7 )
{
*a1 = (unsigned int)((int)*((float *)&a9 + 1) + 100 * a9 + 10000 * HIDWORD(a8));
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
}
}
else if ( (_DWORD)a7 )
{
return (unsigned int)(a8 + 10000 * a7 + 100 * HIDWORD(a7));
}
return 0LL;
}

original_code:
isoDate_t xpDateTime_to_isoDateTime(xpDateTime_t xpDateTime, isoTime_t* isoTime)
{
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(xpDateTime.date.year==0)
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((xpDateTime.time.hour)*10000)+((xpDateTime.time.minute)*100)+((unsigned)xpDateTime.time.second));
 return (((xpDateTime.date.year)*10000)+((xpDateTime.date.month)*100)+(xpDateTime.date.day));
}

canonical_original_code:
unsigned long xpDateTime_to_isoDateTime(struct xpDateTime_t xpDateTime, unsigned long *isoTime)
{
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(xpDateTime.date.year==0)
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((xpDateTime.time.hour)*10000)+((xpDateTime.time.minute)*100)+((unsigned int)xpDateTime.time.second));
 return (((xpDateTime.date.year)*10000)+((xpDateTime.date.month)*100)+(xpDateTime.date.day));
}

variable_types:
isoTime
unsigned long *

return_type: unsigned long


original_code:
xpDateTime_t isoDateTime_to_xpDateTime(isoDate_t date, isoTime_t ti)
{
 return xpDateTime_create(((date)/10000),(((date)/100)%100),((date)%100)
  ,((ti)/10000),(((ti)/100)%100),(float)((ti)%100),xpTimeZone_local());
}

canonical_original_code:
struct xpDateTime_t isoDateTime_to_xpDateTime(unsigned long date, unsigned long ti)
{
 return xpDateTime_create(((date)/10000),(((date)/100)%100),((date)%100)
  ,((ti)/10000),(((ti)/100)%100),(float)((ti)%100),xpTimeZone_local());
}

variable_types:
date
unsigned long

variable_types:
ti
unsigned long


decompiled_code:
__int64 __fastcall time_to_isoDateTime(time_t a1, _QWORD *a2)
{
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
if ( a2 )
*a2 = 0LL;
if ( !timer )
return 0LL;
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
if ( !gmtime_r(&timer, &tp) )
return 0LL;
if ( a2 )
*a2 = (unsigned int)(tp.tm_sec + 100 * tp.tm_min + 10000 * tp.tm_hour);
return tp.tm_mday + 100 * (tp.tm_mon + 1) + 10000 * (tp.tm_year + 1900);
}

canonical_decompiled_code:
__int64 __fastcall func8(time_t a1, _QWORD *a2)
{
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
if ( a2 )
*a2 = 0LL;
if ( !timer )
return 0LL;
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
if ( !gmtime_r(&timer, &tp) )
return 0LL;
if ( a2 )
*a2 = (unsigned int)(tp.tm_sec + 100 * tp.tm_min + 10000 * tp.tm_hour);
return tp.tm_mday + 100 * (tp.tm_mon + 1) + 10000 * (tp.tm_year + 1900);
}

original_code:
isoDate_t time_to_isoDateTime(time_t ti, isoTime_t* isoTime)
{
 struct tm tm;
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(ti==0)
  return(0);
 memset(&(tm),0,sizeof(tm));
 if(gmtime_r(&ti,&tm)==((void *)0))
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((tm.tm_hour)*10000)+((tm.tm_min)*100)+((unsigned)tm.tm_sec));
 return (((1900+tm.tm_year)*10000)+((1+tm.tm_mon)*100)+(tm.tm_mday));
}

canonical_original_code:
unsigned long time_to_isoDateTime(long ti, unsigned long *isoTime)
{
 struct tm tm;
 if(isoTime!=((void *)0))
  *isoTime=0;
 if(ti==0)
  return(0);
 memset(&(tm),0,sizeof(tm));
 if(gmtime_r(&ti,&tm)==((void *)0))
  return(0);
 if(isoTime!=((void *)0))
  *isoTime=(((tm.tm_hour)*10000)+((tm.tm_min)*100)+((unsigned int)tm.tm_sec));
 return (((1900+tm.tm_year)*10000)+((1+tm.tm_mon)*100)+(tm.tm_mday));
}

variable_types: ti long


decompiled_code:
__int64 __fastcall time_to_isoTime(time_t a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

time_to_isoDateTime(a1, &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(time_t a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

func8(a1, &v2);
return v2;
}

original_code:
isoTime_t time_to_isoTime(time_t ti)
{
 isoTime_t isoTime;
 time_to_isoDateTime(ti,&isoTime);
 return isoTime;
}

canonical_original_code:
unsigned long time_to_isoTime(long ti)
{
 unsigned long isoTime;
 time_to_isoDateTime(ti,&isoTime);
 return isoTime;
}

variable_types:
isoTime
unsigned long


decompiled_code:
time_t __fastcall isoDateTime_to_time(unsigned __int64 a1, unsigned __int64 a2)
{
time_t result; // rax
unsigned __int64 v3; // rax
unsigned __int64 v4; // rax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

result = 0LL;
v5.tm_zone = 0LL;
*(_OWORD *)&v5.tm_mon = 0LL;
*(_OWORD *)&v5.tm_isdst = 0LL;
if ( a1 )
{
v5.tm_year = a1 / 0x2710;
v3 = (0x28F5C28F5C28F5C3LL * (unsigned __int128)(a1 / 0x190)) >> 64;
v5.tm_mon = a1 / 0x64 - 20 * ((v3 >> 2) + (v3 & 0xFFFFFFFC));
v5.tm_mday = a1 % 0x64;
v5.tm_hour = a2 / 0x2710;
v4 = (0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 / 0x190)) >> 64;
v5.tm_min = a2 / 0x64 - 20 * ((v4 >> 2) + (v4 & 0xFFFFFFFC));
v5.tm_sec = a2 % 0x64;
result = sane_mktime(&v5);
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func10(unsigned __int64 a1, unsigned __int64 a2)
{
time_t result; // rax
unsigned __int64 v3; // rax
unsigned __int64 v4; // rax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

result = 0LL;
v5.tm_zone = 0LL;
*(_OWORD *)&v5.tm_mon = 0LL;
*(_OWORD *)&v5.tm_isdst = 0LL;
if ( a1 )
{
v5.tm_year = a1 / 0x2710;
v3 = (0x28F5C28F5C28F5C3LL * (unsigned __int128)(a1 / 0x190)) >> 64;
v5.tm_mon = a1 / 0x64 - 20 * ((v3 >> 2) + (v3 & 0xFFFFFFFC));
v5.tm_mday = a1 % 0x64;
v5.tm_hour = a2 / 0x2710;
v4 = (0x28F5C28F5C28F5C3LL * (unsigned __int128)(a2 / 0x190)) >> 64;
v5.tm_min = a2 / 0x64 - 20 * ((v4 >> 2) + (v4 & 0xFFFFFFFC));
v5.tm_sec = a2 % 0x64;
result = func0(&v5);
}
return result;
}

original_code:
time_t isoDateTime_to_time(isoDate_t date, isoTime_t ti)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(date==0)
  return(0);
 tm.tm_year = ((date)/10000);
 tm.tm_mon = (((date)/100)%100);
 tm.tm_mday = ((date)%100);
 tm.tm_hour = ((ti)/10000);
 tm.tm_min = (((ti)/100)%100);
 tm.tm_sec = ((ti)%100);
 return sane_mktime(&tm);
}

canonical_original_code:
long isoDateTime_to_time(unsigned long date, unsigned long ti)
{
 struct tm tm;
 memset(&(tm),0,sizeof(tm));
 if(date==0)
  return(0);
 tm.tm_year = ((date)/10000);
 tm.tm_mon = (((date)/100)%100);
 tm.tm_mday = ((date)%100);
 tm.tm_hour = ((ti)/10000);
 tm.tm_min = (((ti)/100)%100);
 tm.tm_sec = ((ti)%100);
 return sane_mktime(&tm);
}


decompiled_code:
__int64 __fastcall isoTimeZone_parse(char *a1, _DWORD *a2, double a3, double a4)
{
char v4; // al
__int64 result; // rax
int v6; // er8
int v7; // edx
int v8; // [rsp+8h] [rbp-20h] BYREF
int v9; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = *a1;
v8 = 0;
v9 = 0;
if ( v4 == 45 )
goto LABEL_7;
if ( v4 > 45 )
{
if ( v4 == 90 )
{
*a2 = 0;
return 1LL;
}
return 0LL;
}
if ( !v4 )
{
*a2 = xpTimeZone_local(a1, a3, a4);
return 1LL;
}
if ( v4 != 43 )
return 0LL;
LABEL_7:
v6 = _isoc99_sscanf(a1 + 1, "%2u%*s%2u", &v8, &v9);
result = 0LL;
if ( v6 > 0 )
{
v7 = v9 + 60 * v8;
result = 1LL;
*a2 = v7;
if ( *a1 == 45 )
*a2 = -v7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1, _DWORD *a2, double a3, double a4)
{
char v4; // al
__int64 result; // rax
int v6; // er8
int v7; // edx
int v8; // [rsp+8h] [rbp-20h] BYREF
int v9; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = *a1;
v8 = 0;
v9 = 0;
if ( v4 == 45 )
goto LABEL_7;
if ( v4 > 45 )
{
if ( v4 == 90 )
{
*a2 = 0;
return 1LL;
}
return 0LL;
}
if ( !v4 )
{
*a2 = func2(a1, a3, a4);
return 1LL;
}
if ( v4 != 43 )
return 0LL;
LABEL_7:
v6 = _isoc99_sscanf(a1 + 1, "%2u%*s%2u", &v8, &v9);
result = 0LL;
if ( v6 > 0 )
{
v7 = v9 + 60 * v8;
result = 1LL;
*a2 = v7;
if ( *a1 == 45 )
*a2 = -v7;
}
return result;
}

original_code:
int isoTimeZone_parse(const char* str, xpTimeZone_t* zone)
{
 unsigned hour=0,minute=0;
 switch(*str) {
  case 0:
   *zone = xpTimeZone_local();
   return 1;
  case 'Z':
   *zone = 0;
   return 1;
  case '+':
  case '-':
   if(sscanf(str+1,"%2u%*s%2u",&hour,&minute)>=1) {
    *zone = (hour*60) + minute;
    if(*str=='-')
     *zone = -(*zone);
    return 1;
   }
   break;
 }
 return 0;
}

canonical_original_code:
int isoTimeZone_parse(char *str, int *zone)
{
 unsigned int hour = 0; unsigned int minute = 0;
 switch(*str) {
  case 0:
   *zone = xpTimeZone_local();
   return 1;
  case 'Z':
   *zone = 0;
   return 1;
  case '+':
  case '-':
   if(sscanf(str+1,"%2u%*s%2u",&hour,&minute)>=1) {
    *zone = (hour*60) + minute;
    if(*str=='-')
     *zone = -(*zone);
    return 1;
   }
   break;
 }
 return 0;
}

variable_types:
str
char *

variable_types:
zone
int *


decompiled_code:
__int64 __fastcall xp_getdate(__int64 a1)
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
*(_WORD *)a1 = LOWORD(tp.tm_year) + 1900;
*(_BYTE *)(a1 + 2) = tp.tm_mday;
result = (unsigned int)LOBYTE(tp.tm_mon) + 1;
*(_BYTE *)(a1 + 3) = LOBYTE(tp.tm_mon) + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = time(0LL);
localtime_r(&timer, &tp);
*(_WORD *)a1 = LOWORD(tp.tm_year) + 1900;
*(_BYTE *)(a1 + 2) = tp.tm_mday;
result = (unsigned int)LOBYTE(tp.tm_mon) + 1;
*(_BYTE *)(a1 + 3) = LOBYTE(tp.tm_mon) + 1;
return result;
}

original_code:
void xp_getdate(struct date* nyd)
{
 time_t tim;
 struct tm dte;
 tim=time(((void *)0));
 localtime_r(&tim,&dte);
 nyd->da_year=dte.tm_year+1900;
 nyd->da_day=dte.tm_mday;
 nyd->da_mon=dte.tm_mon+1;
}

canonical_original_code:
void xp_getdate(struct date *nyd)
{
 long tim;
 struct tm dte;
 tim=time(((void *)0));
 localtime_r(&tim,&dte);
 nyd->da_year=dte.tm_year+1900;
 nyd->da_day=dte.tm_mday;
 nyd->da_mon=dte.tm_mon+1;
}

variable_types: struct date { short da_year; char da_day; char da_mon; } *

variable_types: tim long

return_type: void


getflagoff

decompiled_code:
__int64 __fastcall getflagoff(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 2);
result = 499LL;
if ( (unsigned int)v1 <= 2 )
result = (__int64)*(&CSWTCH_30 + v1);
return result;
}

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

v1 = (unsigned int)(a1 - 2);
result = 499LL;
if ( (unsigned int)v1 <= 2 )
result = (__int64)*(&CSWTCH_30 + v1);
return result;
}

variable_types: set int


kbhit

decompiled_code:
int kbhit()
{
int result; // eax
struct timeval v1; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v1.tv_sec = 0LL;
v1.tv_usec = 0LL;
if ( istty )
{
if ( beensetup )
{
LABEL_3:
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
return select(1, &readfds, 0LL, 0LL, &v1) > 0;
}
LABEL_7:
termios_setup();
goto LABEL_3;
}
result = isatty(0);
istty = result;
if ( result )
{
if ( beensetup )
goto LABEL_3;
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax
struct timeval v1; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v1.tv_sec = 0LL;
v1.tv_usec = 0LL;
if ( istty )
{
if ( beensetup )
{
LABEL_3:
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[0] |= 1uLL;
return select(1, &readfds, 0LL, 0LL, &v1) > 0;
}
LABEL_7:
func3();
goto LABEL_3;
}
result = isatty(0);
istty = result;
if ( result )
{
if ( beensetup )
goto LABEL_3;
goto LABEL_7;
}
return result;
}

original_code:
int kbhit(void)
{
 fd_set inp;
 struct timeval timeout = {0, 0};
 if(!istty) {
  istty = isatty(0);
  if(!istty)
   return 0;
 }
    if(!beensetup)
     _termios_setup();
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&inp)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&inp)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if(select(0 +1, &inp, ((void *)0), ((void *)0), &timeout)<1)
  return 0;
 return 1;
}

canonical_original_code:
int kbhit()
{
 struct fd_set inp;
 struct timeval timeout = {0, 0};
 if(!istty) {
  istty = isatty(0);
  if(!istty)
   return 0;
 }
    if(!beensetup)
     _termios_setup();
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&inp)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&inp)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if(select(0 +1, &inp, ((void *)0), ((void *)0), &timeout)<1)
  return 0;
 return 1;
}

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


getch

decompiled_code:
__int64 getch()
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( !beensetup )
termios_setup();
read(0, buf, 1uLL);
return (unsigned int)buf[0];
}

canonical_decompiled_code:
__int64 func5()
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

if ( !beensetup )
func3();
read(0, buf, 1uLL);
return (unsigned int)buf[0];
}

original_code:
int getch(void)
{
 char c;
    if(!beensetup)
     _termios_setup();
    read(0, &c, 1);
    return c;
}

canonical_original_code:
int getch()
{
 char c;
    if(!beensetup)
     _termios_setup();
    read(0, &c, 1);
    return c;
}

variable_types: c char


getgamedat

decompiled_code:
ssize_t __fastcall getgamedat(char a1)
{
int v1; // ebx
ssize_t result; // rax
char v3; // si
char v4; // cl
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v1 = 0;
while ( 1 )
{
filelength((unsigned int)gamedab);
if ( (unsigned int)lock(gamedab) != -1 )
break;
if ( ++v1 == 101 )
goto LABEL_15;
v5.tv_sec = 0LL;
v5.tv_usec = 30000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
if ( v1 != 100 )
goto LABEL_6;
LABEL_15:
puts("\agetgamedat: error locking game.dab\r");
LABEL_6:
lseek(gamedab, 0LL, 0);
read(gamedab, &misc, 1uLL);
read(gamedab, &curplayer, 1uLL);
read(gamedab, &total_nodes, 1uLL);
read(gamedab, node, 2 * (unsigned __int8)total_nodes);
result = read(gamedab, status, (unsigned __int8)total_nodes);
total_players = 0;
if ( total_nodes )
{
result = 0LL;
v3 = 0;
v4 = 0;
do
{
if ( node[result] )
{
++v4;
v3 = 1;
}
++result;
}
while ( (unsigned __int8)total_nodes > (int)result );
if ( v3 )
total_players = v4;
}
if ( !a1 )
{
filelength((unsigned int)gamedab);
result = unlock(gamedab);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func7(char a1)
{
int v1; // ebx
ssize_t result; // rax
char v3; // si
char v4; // cl
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v1 = 0;
while ( 1 )
{
func11((unsigned int)gamedab);
if ( (unsigned int)func12(gamedab) != -1 )
break;
if ( ++v1 == 101 )
goto LABEL_15;
v5.tv_sec = 0LL;
v5.tv_usec = 30000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
if ( v1 != 100 )
goto LABEL_6;
LABEL_15:
puts("\agetgamedat: error locking game.dab\r");
LABEL_6:
lseek(gamedab, 0LL, 0);
read(gamedab, &misc, 1uLL);
read(gamedab, &curplayer, 1uLL);
read(gamedab, &total_nodes, 1uLL);
read(gamedab, node, 2 * (unsigned __int8)total_nodes);
result = read(gamedab, status, (unsigned __int8)total_nodes);
total_players = 0;
if ( total_nodes )
{
result = 0LL;
v3 = 0;
v4 = 0;
do
{
if ( node[result] )
{
++v4;
v3 = 1;
}
++result;
}
while ( (unsigned __int8)total_nodes > (int)result );
if ( v3 )
total_players = v4;
}
if ( !a1 )
{
func11((unsigned int)gamedab);
result = func13(gamedab);
}
return result;
}

original_code:
void getgamedat(char lockit)
{
    int i=0;
while(lock(gamedab,0L,filelength(gamedab))==-1 && i++<100)
 ({ int sleep_msecs=30; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
if(i>=100) {
 printf("\7getgamedat: error locking game.dab\r\n"); }
lseek(gamedab,0L,0);
read(gamedab,&misc,1);
read(gamedab,&curplayer,1);
read(gamedab,&total_nodes,1);
read(gamedab,node,total_nodes*2);
read(gamedab,status,total_nodes);
total_players=0;
for(i=0;i<total_nodes;i++)
    if(node[i])
        total_players++;
if(!lockit)
 unlock(gamedab,0L,filelength(gamedab));
}

canonical_original_code:
void getgamedat(char lockit)
{
    int i = 0;
while(lock(gamedab,0L,filelength(gamedab))==-1 && i++<100)
 ({ int sleep_msecs = 30; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
if(i>=100) {
 printf("\7getgamedat: error locking game.dab\r\n"); }
lseek(gamedab,0L,0);
read(gamedab,&misc,1);
read(gamedab,&curplayer,1);
read(gamedab,&total_nodes,1);
read(gamedab,node,total_nodes*2);
read(gamedab,status,total_nodes);
total_players=0;
for(i=0;i<total_nodes;i++)
    if(node[i])
        total_players++;
if(!lockit)
 unlock(gamedab,0L,filelength(gamedab));
}

variable_types: lockit char

variable_types: i int


putgamedat

decompiled_code:
__int64 putgamedat()
{
lseek(gamedab, 0LL, 0);
write(gamedab, &misc, 1uLL);
write(gamedab, &curplayer, 1uLL);
write(gamedab, &total_nodes, 1uLL);
write(gamedab, node, 2 * (unsigned __int8)total_nodes);
write(gamedab, status, (unsigned __int8)total_nodes);
filelength((unsigned int)gamedab);
return unlock(gamedab);
}

canonical_decompiled_code:
__int64 func8()
{
lseek(gamedab, 0LL, 0);
write(gamedab, &misc, 1uLL);
write(gamedab, &curplayer, 1uLL);
write(gamedab, &total_nodes, 1uLL);
write(gamedab, node, 2 * (unsigned __int8)total_nodes);
write(gamedab, status, (unsigned __int8)total_nodes);
func11((unsigned int)gamedab);
return func13(gamedab);
}

original_code:
void putgamedat()
{
lseek(gamedab,0L,0);
write(gamedab,&misc,1);
write(gamedab,&curplayer,1);
write(gamedab,&total_nodes,1);
write(gamedab,node,total_nodes*2);
write(gamedab,status,total_nodes);
unlock(gamedab,0L,filelength(gamedab));
}


nextplayer

decompiled_code:
__int64 nextplayer()
{
__int64 v0; // rax
int v2; // ecx
__int64 v3; // rax
int v4; // edx

getgamedat(1);
v0 = (unsigned __int8)curplayer;
if ( (!curplayer || total_players == 1) && node[(unsigned __int8)node_num - 1] )
{
curplayer = node_num;
}
else if ( (unsigned __int8)curplayer < (int)(unsigned __int8)total_nodes )
{
while ( !node[v0] )
{
if ( (unsigned __int8)total_nodes <= (int)++v0 )
goto LABEL_11;
}
curplayer = v0 + 1;
}
else
{
LABEL_11:
v2 = (unsigned __int8)curplayer - 1;
if ( v2 <= 0 )
{
v4 = 0;
LABEL_17:
if ( v2 == v4 )
{
curplayer = 0;
return putgamedat();
}
}
else
{
v3 = 0LL;
while ( 1 )
{
LOBYTE(v4) = v3;
if ( node[v3] )
break;
v4 = ++v3;
if ( v2 <= (int)v3 )
goto LABEL_17;
}
}
curplayer = v4 + 1;
}
return putgamedat();
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax
int v2; // ecx
__int64 v3; // rax
int v4; // edx

func7(1);
v0 = (unsigned __int8)curplayer;
if ( (!curplayer || total_players == 1) && node[(unsigned __int8)node_num - 1] )
{
curplayer = node_num;
}
else if ( (unsigned __int8)curplayer < (int)(unsigned __int8)total_nodes )
{
while ( !node[v0] )
{
if ( (unsigned __int8)total_nodes <= (int)++v0 )
goto LABEL_11;
}
curplayer = v0 + 1;
}
else
{
LABEL_11:
v2 = (unsigned __int8)curplayer - 1;
if ( v2 <= 0 )
{
v4 = 0;
LABEL_17:
if ( v2 == v4 )
{
curplayer = 0;
return func8();
}
}
else
{
v3 = 0LL;
while ( 1 )
{
LOBYTE(v4) = v3;
if ( node[v3] )
break;
v4 = ++v3;
if ( v2 <= (int)v3 )
goto LABEL_17;
}
}
curplayer = v4 + 1;
}
return func8();
}

original_code:
void nextplayer()
{
    int i;
getgamedat(1);
if((!curplayer
    || total_players==1)
    && node[node_num-1]) {
 curplayer=node_num;
    putgamedat();
    return; }
for(i=curplayer;i<total_nodes;i++)
    if(node[i])
        break;
if(i>=total_nodes) {
 for(i=0;i<curplayer-1;i++)
        if(node[i])
            break;
 if(i==curplayer-1)
  curplayer=0;
    else
  curplayer=i+1; }
else
 curplayer=i+1;
putgamedat();
}


filetime

decompiled_code:
__time_t __fastcall filetime(int a1)
{
__time_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)fstat(a1, &v2) )
result = -1LL;
else
result = v2.st_mtim.tv_sec;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func10(int a1)
{
__time_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func17(a1, &v2) )
result = -1LL;
else
result = v2.st_mtim.tv_sec;
return result;
}

original_code:
time_t filetime(int fd)
{
 struct stat st;
 if(fstat(fd, &st)!=0)
  return(-1);
 return(st.st_mtim.tv_sec);
}

canonical_original_code:
long filetime(int fd)
{
 struct stat st;
 if(fstat(fd, &st)!=0)
  return(-1);
 return(st.st_mtim.tv_sec);
}

variable_types: fd int

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

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


filelength

decompiled_code:
__off_t __fastcall filelength(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)fstat(a1, &v2) )
result = -1LL;
else
result = v2.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func11(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func17(a1, &v2) )
result = -1LL;
else
result = v2.st_size;
return result;
}

original_code:
long filelength(int fd)
{
 struct stat st;
 if(fstat(fd, &st)!=0)
  return(-1L);
 return(st.st_size);
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


lock

decompiled_code:
int __fastcall lock(int fd, __int64 a2, int a3)
{
int v4; // eax
int result; // eax
__int16 v6[4]; // [rsp+0h] [rbp-38h] BYREF
__int64 v7; // [rsp+8h] [rbp-30h]
__int64 v8; // [rsp+10h] [rbp-28h]

v4 = fcntl(fd, 3);
if ( v4 == -1 )
return -1;
v7 = a2;
v8 = a3;
v6[0] = v4 != 0;
v6[1] = 0;
if ( fcntl(fd, 6, v6) == -1 && *__errno_location() != 22 )
return -1;
result = flock(fd, 6);
if ( result )
result = -(*__errno_location() != 95);
return result;
}

canonical_decompiled_code:
int __fastcall func12(int fd, __int64 a2, int a3)
{
int v4; // eax
int result; // eax
__int16 v6[4]; // [rsp+0h] [rbp-38h] BYREF
__int64 v7; // [rsp+8h] [rbp-30h]
__int64 v8; // [rsp+10h] [rbp-28h]

v4 = fcntl(fd, 3);
if ( v4 == -1 )
return -1;
v7 = a2;
v8 = a3;
v6[0] = v4 != 0;
v6[1] = 0;
if ( fcntl(fd, 6, v6) == -1 && *__errno_location() != 22 )
return -1;
result = flock(fd, 6);
if ( result )
result = -(*__errno_location() != 95);
return result;
}

original_code:
int lock(int fd, long pos, long len)
{
   struct flock alock;
  int flags;
  if((flags=fcntl(fd,3))==-1)
   return -1;
  if(flags==00)
   alock.l_type = 0;
  else
   alock.l_type = 1;
  alock.l_whence = 0;
  alock.l_start = pos;
  alock.l_len = (int)len;
  if(fcntl(fd, 6, &alock)==-1 && (*__errno_location ()) != 22)
   return(-1);
  if(flock(fd,2|4)!=0 && (*__errno_location ()) != 95)
   return(-1);
  return(0);
}

variable_types: pos long

variable_types: len long

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }

variable_types: flags int


unlock

original_code:
int unlock(int fd, long pos, long len)
{
 struct flock alock;
 alock.l_type = 2;
 alock.l_whence = 0;
 alock.l_start = pos;
 alock.l_len = (int)len;
 if(fcntl(fd, 6, &alock)==-1 && (*__errno_location ()) != 22)
  return(-1);
 if(flock(fd,8|4)!=0 && (*__errno_location ()) != 95)
  return(-1);
 return(0);
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
char *v5; // rdi
int v6; // ecx
int v7; // er8
int v8; // er9
char v9; // al
__int64 v10; // rax
int result; // eax
char v12[297]; // [rsp+1h] [rbp-129h]
char v13[296]; // [rsp+2h] [rbp-128h] BYREF

v3 = getenv("SBBSNODE");
if ( v3 )
{
v4 = stpcpy(v13, v3);
v5 = getenv("SBBSNNUM");
if ( v5 )
{
node_num = atoi(v5);
v9 = v12[v4 - v13];
if ( v9 != 47 && v9 != 92 )
*(_WORD *)v4 = 47;
gamedab = sopen((unsigned int)"GAME.DAB", 2, 2, v6, v7, v8, v13[0]);
if ( gamedab == -1 )
{
fwrite("Error opening GAME.DAB\r\n", 1uLL, 0x18uLL, stderr);
result = 1;
}
else
{
getgamedat(1LL);
v10 = (unsigned __int8)node_num - 1;
node[v10] = 0;
status[v10] = 0;
putgamedat();
if ( curplayer == node_num )
nextplayer();
close(gamedab);
result = 0;
}
}
else
{
fwrite("!Need SBBSNNUM env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
}
else
{
fwrite("!Need SBBSNODE env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbx
char *v5; // rdi
int v6; // ecx
int v7; // er8
int v8; // er9
char v9; // al
__int64 v10; // rax
int result; // eax
char v12[297]; // [rsp+1h] [rbp-129h]
char v13[296]; // [rsp+2h] [rbp-128h] BYREF

v3 = getenv("SBBSNODE");
if ( v3 )
{
v4 = stpcpy(v13, v3);
v5 = getenv("SBBSNNUM");
if ( v5 )
{
node_num = atoi(v5);
v9 = v12[v4 - v13];
if ( v9 != 47 && v9 != 92 )
*(_WORD *)v4 = 47;
gamedab = func14((unsigned int)"GAME.DAB", 2, 2, v6, v7, v8, v13[0]);
if ( gamedab == -1 )
{
fwrite("Error opening GAME.DAB\r\n", 1uLL, 0x18uLL, stderr);
result = 1;
}
else
{
func7(1LL);
v10 = (unsigned __int8)node_num - 1;
node[v10] = 0;
status[v10] = 0;
func8();
if ( curplayer == node_num )
func9();
close(gamedab);
result = 0;
}
}
else
{
fwrite("!Need SBBSNNUM env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
}
else
{
fwrite("!Need SBBSNODE env var\n", 1uLL, 0x17uLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 char* p;
 char node_dir[260 +1];
 if((p=getenv("SBBSNODE"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNODE env var\n");
  return(-1);
 }
 strcpy(node_dir,p);
 if((p=getenv("SBBSNNUM"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNNUM env var\n");
  return(-1);
 }
 node_num=atoi(p);
 if(node_dir[strlen(node_dir)-1]!='\\'
  && node_dir[strlen(node_dir)-1]!='/')
  strcat(node_dir,"/");
 if((gamedab=sopen("GAME.DAB",02|0,2))==-1) {
  fprintf(stderr,"Error opening GAME.DAB\r\n");
  return(1);
 }
 getgamedat(1);
 node[node_num-1]=0;
 status[node_num-1]=0;
 putgamedat();
 if(curplayer==node_num)
  nextplayer();
 close(gamedab);
 return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *p;
 char node_dir[-1];
 if((p=getenv("SBBSNODE"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNODE env var\n");
  return(-1);
 }
 strcpy(node_dir,p);
 if((p=getenv("SBBSNNUM"))==((void *)0)) {
  fprintf(stderr,"!Need SBBSNNUM env var\n");
  return(-1);
 }
 node_num=atoi(p);
 if(node_dir[strlen(node_dir)-1]!='\\'
  && node_dir[strlen(node_dir)-1]!='/')
  strcat(node_dir,"/");
 if((gamedab=sopen("GAME.DAB",02|0,2))==-1) {
  fprintf(stderr,"Error opening GAME.DAB\r\n");
  return(1);
 }
 getgamedat(1);
 node[node_num-1]=0;
 status[node_num-1]=0;
 putgamedat();
 if(curplayer==node_num)
  nextplayer();
 close(gamedab);
 return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
p
char *


makewave

original_code:
void makewave(double freq, unsigned char *wave, int samples, enum WAVE_SHAPE shape)
{
 int i;
 int midpoint;
 double inc;
 double pos;
 int endhigh;
 midpoint=samples/2;
 inc=8.0*atan(1.0);
 inc *= ((double)freq / (double)22050);
 for(i=0;i<samples;i++) {
  pos=(inc*(double)i);
  pos -= (int)(pos/6.28318530717958647692)*6.28318530717958647692;
  switch(shape) {
   case WAVE_SHAPE_SINE:
    wave[i]=(sin (pos))*127+128;
    break;
   case WAVE_SHAPE_SINE_HARM:
    wave[i]=(sin (pos))*64+128;
    wave[i]=(sin ((inc*2)*(double)i))*24;
    wave[i]=(sin ((inc*3)*(double)i))*16;
    break;
   case WAVE_SHAPE_SAWTOOTH:
    wave[i]=(6.28318530717958647692 -pos)*40.5;
    break;
   case WAVE_SHAPE_SQUARE:
    wave[i]=(pos<3.14159265358979323846)?255:0;
    break;
   case WAVE_SHAPE_SINE_SAW:
    wave[i]=(((sin (pos))*127+128)+((6.28318530717958647692 -pos)*40.5))/2;
    break;
   case WAVE_SHAPE_SINE_SAW_CHORD:
    wave[i]=(((sin (pos))*64+128)+((6.28318530717958647692 -pos)*6.2))/2;
    wave[i]+=(sin ((inc/2)*(double)i))*24;
    wave[i]+=(sin ((inc/3)*(double)i))*16;
    break;
   case WAVE_SHAPE_SINE_SAW_HARM:
    wave[i]=(((sin (pos))*64+128)+((6.28318530717958647692 -pos)*6.2))/2;
    wave[i]+=(sin ((inc*2)*(double)i))*24;
    wave[i]+=(sin ((inc*3)*(double)i))*16;
    break;
  }
 }
 if(wave[samples-1]>128)
  endhigh=1;
 else
  endhigh=0;
 i=samples-1;
 if(wave[i]!=128) {
  for(;i>midpoint;i--) {
   if(endhigh && wave[i]<128)
    break;
   if(!endhigh && wave[i]>128)
    break;
   wave[i]=128;
  }
 }
}

variable_types: freq double

variable_types:
wave
unsigned char *

variable_types: samples int

variable_types: enum WAVE_SHAPE { WAVE_SHAPE_SINE=0, WAVE_SHAPE_SAWTOOTH=1, WAVE_SHAPE_SQUARE=2, WAVE_SHAPE_SINE_SAW=3, WAVE_SHAPE_SINE_HARM=4, WAVE_SHAPE_SINE_SAW_CHORD=5, WAVE_SHAPE_SINE_SAW_HARM=6 }

variable_types: midpoint int

variable_types: inc double

variable_types: pos double

variable_types: endhigh int


decompiled_code:
__int64 xptone_open()
{
unsigned int v0; // er12
__int64 result; // rax
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = handle_type;
v2 = 8;
v3 = 1;
v4 = 22050;
v5[0] = 2147418116;
if ( handle_type )
return 1LL;
if ( sound_device_open_failed )
return v0;
dsp = open("/dev/dsp", 1, 0LL);
if ( dsp >= 0 )
{
ioctl(dsp, 0xC004500AuLL, v5);
if ( ioctl(dsp, 0xC0045005uLL, &v2) == -1
|| v2 != 8
|| ioctl(dsp, 0xC0045006uLL, &v3) == -1
|| v3 != 1
|| ioctl(dsp, 0xC0045002uLL, &v4) == -1
|| v4 != 22050 )
{
sound_device_open_failed = 1;
close(dsp);
}
if ( sound_device_open_failed )
return v0;
handle_type = 3;
result = 1LL;
}
else
{
sound_device_open_failed = 1;
result = v0;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
__int64 result; // rax
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = handle_type;
v2 = 8;
v3 = 1;
v4 = 22050;
v5[0] = 2147418116;
if ( handle_type )
return 1LL;
if ( sound_device_open_failed )
return v0;
dsp = open("/dev/dsp", 1, 0LL);
if ( dsp >= 0 )
{
ioctl(dsp, 0xC004500AuLL, v5);
if ( ioctl(dsp, 0xC0045005uLL, &v2) == -1
|| v2 != 8
|| ioctl(dsp, 0xC0045006uLL, &v3) == -1
|| v3 != 1
|| ioctl(dsp, 0xC0045002uLL, &v4) == -1
|| v4 != 22050 )
{
sound_device_open_failed = 1;
close(dsp);
}
if ( sound_device_open_failed )
return v0;
handle_type = 3;
result = 1LL;
}
else
{
sound_device_open_failed = 1;
result = v0;
}
return result;
}

variable_types: format int

variable_types: channels int

variable_types: rate int

variable_types: fragsize int


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

if ( handle_type == 3 )
close(dsp);
handle_type = 0;
result = 1LL;
sound_device_open_failed = 0;
return result;
}

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

if ( handle_type == 3 )
close(dsp);
handle_type = 0;
result = 1LL;
sound_device_open_failed = 0;
return result;
}

original_code:
int xptone_close(void)
{
 if(handle_type==SOUND_DEVICE_OSS)
  close(dsp);
 handle_type=SOUND_DEVICE_CLOSED;
 sound_device_open_failed=0;
 alsa_device_open_failed=0;
 sdl_device_open_failed=0;
 return(1);
}

canonical_original_code:
int xptone_close()
{
 if(handle_type==SOUND_DEVICE_OSS)
  close(dsp);
 handle_type=SOUND_DEVICE_CLOSED;
 sound_device_open_failed=0;
 alsa_device_open_failed=0;
 sdl_device_open_failed=0;
 return(1);
}


xptone

decompiled_code:
__int64 __fastcall xptone(__int64 a1, int a2, double a3)
{
unsigned int v3; // er12
int v4; // er14
double v5; // xmm1_8
int v6; // ebp
int v8; // eax
int v9; // ebx
int v10; // eax
_BYTE v11[165416]; // [rsp+10h] [rbp-28628h] BYREF

v3 = 0;
v4 = handle_type;
if ( !handle_type )
{
v3 = 1;
v8 = xptone_open();
v4 = handle_type;
if ( !v8 )
return 0;
}
if ( a3 < 17.0 )
{
v5 = *(double *)&LC13;
a3 = *(double *)&LC14;
}
else
{
v5 = 22050.0 / a3 + 22050.0 / a3;
}
v6 = 22050 * a1 / 0x3E8uLL;
if ( v5 >= (double)v6 )
v6 = (int)v5;
makewave(v11, v6, a2, a3);
if ( v4 != 3 )
{
if ( v3 )
xptone_close();
return 0;
}
v9 = 0;
while ( v9 < v6 )
{
v10 = write(dsp, &v11[v9], v6 - v9);
if ( v10 >= 0 )
v9 += v10;
}
if ( !v3 )
return 1;
xptone_close();
return v3;
}

original_code:
int xptone(double freq, ulong duration, enum WAVE_SHAPE shape)
{
 int must_close=0;
 unsigned char wave[22050*15/2+1];
 int samples;
 int wr;
 int i;
 if(handle_type==SOUND_DEVICE_CLOSED) {
  must_close=1;
  if(!xptone_open())
   return(0);
 }
 if(freq<17)
  freq=17;
 samples=22050*duration/1000;
 if(samples<=22050/freq*2)
  samples=22050/freq*2;
 makewave(freq,wave,samples,shape);
 if(handle_type==SOUND_DEVICE_OSS) {
  wr=0;
  while(wr<samples) {
   i=write(dsp, wave+wr, samples-wr);
   if(i>=0)
    wr+=i;
  }
  if(must_close)
   xptone_close();
  return(1);
 }
 if(must_close)
  xptone_close();
 return(0);
}

canonical_original_code:
int xptone(double freq, unsigned long duration, enum WAVE_SHAPE shape)
{
 int must_close = 0;
 unsigned char wave[-1];
 int samples;
 int wr;
 int i;
 if(handle_type==SOUND_DEVICE_CLOSED) {
  must_close=1;
  if(!xptone_open())
   return(0);
 }
 if(freq<17)
  freq=17;
 samples=22050*duration/1000;
 if(samples<=22050/freq*2)
  samples=22050/freq*2;
 makewave(freq,wave,samples,shape);
 if(handle_type==SOUND_DEVICE_OSS) {
  wr=0;
  while(wr<samples) {
   i=write(dsp, wave+wr, samples-wr);
   if(i>=0)
    wr+=i;
  }
  if(must_close)
   xptone_close();
  return(1);
 }
 if(must_close)
  xptone_close();
 return(0);
}

variable_types:
duration
unsigned long

variable_types:
wave
unsigned char [-1]

variable_types: wr int

variable_types: i int

user_defined_types: enum WAVE_SHAPE { WAVE_SHAPE_SINE=0, WAVE_SHAPE_SAWTOOTH=1, WAVE_SHAPE_SQUARE=2, WAVE_SHAPE_SINE_SAW=3, WAVE_SHAPE_SINE_HARM=4, WAVE_SHAPE_SINE_SAW_CHORD=5, WAVE_SHAPE_SINE_SAW_HARM=6 }


decompiled_code:
int __fastcall unix_beep(int a1, int a2)
{
int v3; // edi
int result; // eax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v3 = console_fd_0;
if ( console_fd_0 != -1 || (result = open("/dev/console", 256), console_fd_0 = result, v3 = result, result != -1) )
{
if ( a1 )
ioctl(v3, 0x4B2FuLL, (unsigned int)(1193180 / a1));
v5.tv_sec = a2 / 1000;
v5.tv_usec = 1000 * (a2 % 1000);
select(0, 0LL, 0LL, 0LL, &v5);
result = ioctl(console_fd_0, 0x4B2FuLL, 0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, int a2)
{
int v3; // edi
int result; // eax
struct timeval v5; // [rsp+0h] [rbp-28h] BYREF

v3 = console_fd_0;
if ( console_fd_0 != -1 || (result = open("/dev/console", 256), console_fd_0 = result, v3 = result, result != -1) )
{
if ( a1 )
ioctl(v3, 0x4B2FuLL, (unsigned int)(1193180 / a1));
v5.tv_sec = a2 / 1000;
v5.tv_usec = 1000 * (a2 % 1000);
select(0, 0LL, 0LL, 0LL, &v5);
result = ioctl(console_fd_0, 0x4B2FuLL, 0LL);
}
return result;
}

original_code:
void unix_beep(int freq, int dur)
{
 static int console_fd=-1;
 if(console_fd == -1)
    console_fd = open("/dev/console", 0400);
 if(console_fd != -1) {
  if(freq != 0)
   ioctl(console_fd, 0x4B2F, (int) (1193180 / freq));
  ({ int sleep_msecs=dur; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  ioctl(console_fd, 0x4B2F, 0);
 }
}

canonical_original_code:
void unix_beep(int freq, int dur)
{
 static int console_fd = -1;
 if(console_fd == -1)
    console_fd = open("/dev/console", 0400);
 if(console_fd != -1) {
  if(freq != 0)
   ioctl(console_fd, 0x4B2F, (int) (1193180 / freq));
  ({ int sleep_msecs = dur; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  ioctl(console_fd, 0x4B2F, 0);
 }
}

variable_types: freq int

variable_types: dur int

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


xpbeep

decompiled_code:
int __fastcall xpbeep(__int64 a1, double a2)
{
int result; // eax

result = xptone(a1, 6, a2);
if ( !result )
result = unix_beep((int)(a2 + 0.5), a1);
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, double a2)
{
int result; // eax

result = func3(a1, 6, a2);
if ( !result )
result = func4((int)(a2 + 0.5), a1);
return result;
}

original_code:
void xpbeep(double freq, ulong duration)
{
 if(xptone(freq,duration,WAVE_SHAPE_SINE_SAW_HARM))
  return;
 unix_beep((int)(freq+.5),duration);
}

canonical_original_code:
void xpbeep(double freq, unsigned long duration)
{
 if(xptone(freq,duration,WAVE_SHAPE_SINE_SAW_HARM))
  return;
 unix_beep((int)(freq+.5),duration);
}

variable_types: freq double


sethelp

decompiled_code:
void __fastcall sethelp(int a1, char *a2)
{
helpline = a1;
helpfile = a2;
}

canonical_decompiled_code:
void __fastcall func2(int a1, char *a2)
{
helpline = a1;
helpfile = a2;
}

original_code:
void sethelp(int line, char* file)
{
    helpline=line;
    helpfile=file;
}

canonical_original_code:
void sethelp(int line, char *file)
{
    helpline=line;
    helpfile=file;
}

variable_types: line int

variable_types:
file
char *


upop

decompiled_code:
int __fastcall upop(const char *a1)
{
int result; // eax

if ( a1 )
result = printf("\r%-79s", a1);
else
result = putchar(10);
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1)
{
int result; // eax

if ( a1 )
result = printf("\r%-79s", a1);
else
result = putchar(10);
return result;
}

original_code:
void upop(char *str)
{
    if(str==((void *)0))
        printf("\n");
    else
        printf("\r%-79s",str);
}

variable_types:
str
char *


which

decompiled_code:
__int64 __fastcall which(const char *a1, int a2)
{
int v2; // eax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

do
{
do
{
printf("%s which (1-%d): ", a1, (unsigned int)a2);
v4[0] = 0;
getstr_isra_0((__int64)v4, 40);
v2 = atoi(v4);
}
while ( v2 <= 0 );
}
while ( a2 < v2 );
return (unsigned int)(v2 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, int a2)
{
int v2; // eax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

do
{
do
{
printf("%s which (1-%d): ", a1, (unsigned int)a2);
v4[0] = 0;
func7((__int64)v4, 40);
v2 = atoi(v4);
}
while ( v2 <= 0 );
}
while ( a2 < v2 );
return (unsigned int)(v2 - 1);
}

original_code:
static int which(char* prompt, int max)
{
    char str[41];
    int i;
    while(1) {
        printf("%s which (1-%d): ",prompt,max);
        str[0]=0;
  getstr(str,sizeof(str)-1);
        i=atoi(str);
        if(i>0 && i<=max)
            return(i-1);
    }
}

canonical_original_code:
static int which(char *prompt, int max)
{
    char str[41];
    int i;
    while(1) {
        printf("%s which (1-%d): ",prompt,max);
        str[0]=0;
  getstr(str,sizeof(str)-1);
        i=atoi(str);
        if(i>0 && i<=max)
            return(i-1);
    }
}

variable_types:
prompt
char *

variable_types: max int

variable_types:
str
char [41]


uinput

decompiled_code:
char *__fastcall uinput(__int64 a1, __int64 a2, __int64 a3, const char *a4, char *a5, unsigned int a6, char a7)
{
__int16 v11[140]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
printf("%s (maxlen=%u): ", a4, a6);
getstr_isra_0((__int64)v11, a6);
truncsp((const char *)v11);
if ( v11[0] != 63 )
break;
help();
}
if ( strcmp(a5, (const char *)v11) )
*(_DWORD *)(api + 16) = 1;
if ( (a7 & 1) != 0 )
strupr_isra_0((char *)v11);
return (char *)(stpcpy(a5, (const char *)v11) - a5);
}

canonical_decompiled_code:
char *__fastcall func10(__int64 a1, __int64 a2, __int64 a3, const char *a4, char *a5, unsigned int a6, char a7)
{
__int16 v11[140]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
printf("%s (maxlen=%u): ", a4, a6);
func7((__int64)v11, a6);
func3((const char *)v11);
if ( v11[0] != 63 )
break;
func9();
}
if ( strcmp(a5, (const char *)v11) )
*(_DWORD *)(api + 16) = 1;
if ( (a7 & 1) != 0 )
func6((char *)v11);
return (char *)(stpcpy(a5, (const char *)v11) - a5);
}

original_code:
int uinput(int mode, int left, int top, char *prompt, char *outstr,
 int max, int kmode)
{
    char str[256];
    while(1) {
        printf("%s (maxlen=%u): ",prompt,max);
        getstr(str,max);
        truncsp(str);
        if(strcmp(str,"?"))
            break;
        help();
    }
 if(strcmp(outstr,str))
  api->changes=1;
    if(kmode&(1L<<0))
     strupr(str);
    strcpy(outstr,str);
    return(strlen(outstr));
}

variable_types: mode int

variable_types: left int

variable_types: top int

variable_types:
outstr
char *

variable_types: kmode int

variable_types:
str
char [256]


ulist

original_code:
int ulist(int mode, int left, int top, int width, int *cur, int *bar
 , char *title, char **option)
{
    char str[128];
 int i,opts;
    int optnumlen;
    int yesno=0;
    int lines;
    for(opts=0;opts<10000;opts++)
     if(option[opts]==((void *)0) || option[opts][0]==0)
      break;
    if((*cur)>=opts)
        (*cur)=opts-1;
    if((*cur)<0)
        (*cur)=0;
    if(opts>999)
        optnumlen=4;
    else if(opts>99)
        optnumlen=3;
    else if(opts>9)
        optnumlen=2;
    else
        optnumlen=1;
    while(1) {
        if(opts==2 && !strcasecmp(option[0],"Yes") && !strcasecmp(option[1],"No")) {
            yesno=1;
            printf("%s? ",title);
        } else {
            printf("\n[%s]\n",title);
            lines=2;
            for(i=0;i<opts;i++) {
                printf("%*d: %s\n",optnumlen,i+1,option[i]);
                lines++;
                if(!(lines%api->scrn_len)) {
                    printf("More? ");
                    str[0]=0;
                    getstr(str,sizeof(str)-1);
                    if(toupper(*str)=='N')
                        break;
                }
            }
            str[0]=0;
            if(mode&(1<<12))
                strcat(str,", Copy");
            if(mode&(1<<13))
                strcat(str,", Paste");
            if(mode&(1<<5))
                strcat(str,", Add");
            if(mode&(1<<7))
                strcat(str,", Delete");
            printf("\nWhich (Help%s or Quit): ",str);
        }
        str[0]=0;
        getstr(str,sizeof(str)-1);
        truncsp(str);
        i=atoi(str);
        if(i>0 && i<=opts) {
            *cur=--i;
            return(*cur);
        }
        i=atoi(str+1);
        switch(toupper(*str)) {
            case 0:
            case 0x1b:
            case 'Q':
                printf("Quit\n");
                return(-1);
            case 'Y':
                if(!yesno)
                    break;
                printf("Yes\n");
                return(0);
            case 'N':
                if(!yesno)
                    break;
                printf("No\n");
                return(1);
            case 'H':
            case '?':
                printf("Help\n");
                help();
                break;
            case 'A':
    if(!(mode&(1<<5)))
     break;
    if(!opts)
        return(0x10000000);
                if(i>0 && i<=opts+1)
           return((i-1)|0x10000000);
                return(which("Add before",opts+1)|0x10000000);
            case 'D':
    if(!(mode&(1<<7)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x20000000);
                if(opts==1)
                    return(0x20000000);
                return(which("Delete",opts)|0x20000000);
            case 'C':
    if(!(mode&(1<<12)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x30000000);
                if(opts==1)
                    return(0x30000000);
                return(which("Copy",opts)|0x30000000);
            case 'P':
    if(!(mode&(1<<13)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x40000000);
                if(opts==1)
                    return(0x40000000);
                return(which("Paste",opts)|0x40000000);
        }
    }
}

canonical_original_code:
int ulist(int mode, int left, int top, int width, int *cur, int *bar, char *title, char **option)
{
    char str[128];
 int i; int opts;
    int optnumlen;
    int yesno = 0;
    int lines;
    for(opts=0;opts<10000;opts++)
     if(option[opts]==((void *)0) || option[opts][0]==0)
      break;
    if((*cur)>=opts)
        (*cur)=opts-1;
    if((*cur)<0)
        (*cur)=0;
    if(opts>999)
        optnumlen=4;
    else if(opts>99)
        optnumlen=3;
    else if(opts>9)
        optnumlen=2;
    else
        optnumlen=1;
    while(1) {
        if(opts==2 && !strcasecmp(option[0],"Yes") && !strcasecmp(option[1],"No")) {
            yesno=1;
            printf("%s? ",title);
        } else {
            printf("\n[%s]\n",title);
            lines=2;
            for(i=0;i<opts;i++) {
                printf("%*d: %s\n",optnumlen,i+1,option[i]);
                lines++;
                if(!(lines%api->scrn_len)) {
                    printf("More? ");
                    str[0]=0;
                    getstr(str,sizeof(str)-1);
                    if(toupper(*str)=='N')
                        break;
                }
            }
            str[0]=0;
            if(mode&(1<<12))
                strcat(str,", Copy");
            if(mode&(1<<13))
                strcat(str,", Paste");
            if(mode&(1<<5))
                strcat(str,", Add");
            if(mode&(1<<7))
                strcat(str,", Delete");
            printf("\nWhich (Help%s or Quit): ",str);
        }
        str[0]=0;
        getstr(str,sizeof(str)-1);
        truncsp(str);
        i=atoi(str);
        if(i>0 && i<=opts) {
            *cur=--i;
            return(*cur);
        }
        i=atoi(str+1);
        switch(toupper(*str)) {
            case 0:
            case 0x1b:
            case 'Q':
                printf("Quit\n");
                return(-1);
            case 'Y':
                if(!yesno)
                    break;
                printf("Yes\n");
                return(0);
            case 'N':
                if(!yesno)
                    break;
                printf("No\n");
                return(1);
            case 'H':
            case '?':
                printf("Help\n");
                help();
                break;
            case 'A':
    if(!(mode&(1<<5)))
     break;
    if(!opts)
        return(0x10000000);
                if(i>0 && i<=opts+1)
           return((i-1)|0x10000000);
                return(which("Add before",opts+1)|0x10000000);
            case 'D':
    if(!(mode&(1<<7)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x20000000);
                if(opts==1)
                    return(0x20000000);
                return(which("Delete",opts)|0x20000000);
            case 'C':
    if(!(mode&(1<<12)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x30000000);
                if(opts==1)
                    return(0x30000000);
                return(which("Copy",opts)|0x30000000);
            case 'P':
    if(!(mode&(1<<13)))
     break;
    if(!opts)
        break;
                if(i>0 && i<=opts)
           return((i-1)|0x40000000);
                if(opts==1)
                    return(0x40000000);
                return(which("Paste",opts)|0x40000000);
        }
    }
}

variable_types: width int

variable_types:
cur
int *

variable_types:
bar
int *

variable_types:
title
char *

variable_types:
option
char **

variable_types:
str
char [128]

variable_types: i int

variable_types: opts int

variable_types: optnumlen int

variable_types: yesno int

variable_types: lines int


uifcinix

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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 != 8384LL )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8280) = uifcbail;
*(_QWORD *)(a1 + 8288) = uscrn;
*(_QWORD *)(a1 + 8296) = umsg;
*(_QWORD *)(a1 + 8304) = upop;
*(_QWORD *)(a1 + 8312) = ulist;
*(_QWORD *)(a1 + 8320) = uinput;
*(_QWORD *)(a1 + 8328) = sethelp;
*(_QWORD *)(a1 + 8336) = help;
*(_QWORD *)(a1 + 8344) = 0LL;
*(_QWORD *)(a1 + 8352) = 0LL;
api = a1;
setvbuf(stdin, 0LL, 2, 0LL);
setvbuf(stdout, 0LL, 2, 0LL);
*(_DWORD *)(a1 + 28) = 24;
result = 0LL;
*(_DWORD *)(a1 + 8276) = 1;
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 != 8384LL )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8280) = uifcbail;
*(_QWORD *)(a1 + 8288) = uscrn;
*(_QWORD *)(a1 + 8296) = umsg;
*(_QWORD *)(a1 + 8304) = upop;
*(_QWORD *)(a1 + 8312) = ulist;
*(_QWORD *)(a1 + 8320) = uinput;
*(_QWORD *)(a1 + 8328) = sethelp;
*(_QWORD *)(a1 + 8336) = help;
*(_QWORD *)(a1 + 8344) = 0LL;
*(_QWORD *)(a1 + 8352) = 0LL;
api = a1;
setvbuf(stdin, 0LL, 2, 0LL);
setvbuf(stdout, 0LL, 2, 0LL);
*(_DWORD *)(a1 + 28) = 24;
result = 0LL;
*(_DWORD *)(a1 + 8276) = 1;
return result;
}

original_code:
int uifcinix(uifcapi_t* uifcapi)
{
    if(uifcapi==((void *)0) || uifcapi->size!=sizeof(uifcapi_t))
        return(-1);
    api=uifcapi;
    api->bail=uifcbail;
    api->scrn=uscrn;
    api->msg=umsg;
    api->pop=upop;
    api->list=ulist;
    api->input=uinput;
    api->sethelp=sethelp;
    api->showhelp=help;
 api->showbuf=((void *)0);
 api->timedisplay=((void *)0);
    setvbuf(stdin,((void *)0),2,0);
    setvbuf(stdout,((void *)0),2,0);
    api->scrn_len=24;
 api->initialized=1;
    return(0);
}

canonical_original_code:
int uifcinix(struct uifcapi_t *uifcapi)
{
    if(uifcapi==((void *)0) || uifcapi->size!=sizeof(uifcapi_t))
        return(-1);
    api=uifcapi;
    api->bail=uifcbail;
    api->scrn=uscrn;
    api->msg=umsg;
    api->pop=upop;
    api->list=ulist;
    api->input=uinput;
    api->sethelp=sethelp;
    api->showhelp=help;
 api->showbuf=((void *)0);
 api->timedisplay=((void *)0);
    setvbuf(stdin,((void *)0),2,0);
    setvbuf(stdout,((void *)0),2,0);
    api->scrn_len=24;
 api->initialized=1;
    return(0);
}

variable_types: struct uifcapi_t { unsigned long size; long mode; int changes; unsigned int savnum; unsigned int savdepth; unsigned int scrn_len; unsigned int scrn_width; unsigned int esc_delay; char *helpbuf; char helpdatfile[-1]; char helpixbfile[-1]; int buttony; int exitstart; int exitend; int helpstart; int helpend; int list_height; unsigned char hclr; int initialized; void (*bail)(); int (*scrn)(char *str); void (*msg)(char *str); void (*pop)(char *str); int (*list)(int mode, int left, int top, int width, int *dflt, int *bar, char *title, char **option); int (*input)(int mode, int left, int top, char *prompt, char *str, int len, int kmode); void (*sethelp)(int line, char *file); void (*showhelp)(); void (*showbuf)(int mode, int left, int top, int width, int height, char *title, char *hbuf, int *curp, int *barp); void (*timedisplay)(int force); void (*bottomline)(int line); int (*getstrxy)(int left, int top, int width, char *outstr, int max, long mode, int *lastkey); int (*printf)(int x, int y, unsigned int attr, char *fmat, ...); } *


mimegetboundary

decompiled_code:
_BYTE *mimegetboundary()
{
_BYTE *v0; // r12
unsigned int v1; // eax
_BYTE *v2; // rbp
_BYTE *v3; // rbx
int v4; // eax
unsigned int v5; // ecx
char v6; // dl
char v7; // al

v0 = malloc(0x25uLL);
v1 = time(0LL);
srand(v1);
if ( v0 )
{
v2 = v0;
v3 = v0 + 36;
do
{
while ( 1 )
{
v4 = rand() % 62;
if ( v4 > 9 )
break;
*v2++ = v4 + 48;
if ( v2 == v3 )
goto LABEL_8;
}
v5 = v4 - 10;
v6 = v4 + 55;
v7 = v4 + 61;
if ( v5 <= 0x19 )
v7 = v6;
*v2++ = v7;
}
while ( v2 != v3 );
LABEL_8:
v0[36] = 0;
}
return v0;
}

canonical_decompiled_code:
_BYTE *func0()
{
_BYTE *v0; // r12
unsigned int v1; // eax
_BYTE *v2; // rbp
_BYTE *v3; // rbx
int v4; // eax
unsigned int v5; // ecx
char v6; // dl
char v7; // al

v0 = malloc(0x25uLL);
v1 = time(0LL);
srand(v1);
if ( v0 )
{
v2 = v0;
v3 = v0 + 36;
do
{
while ( 1 )
{
v4 = rand() % 62;
if ( v4 > 9 )
break;
*v2++ = v4 + 48;
if ( v2 == v3 )
goto LABEL_8;
}
v5 = v4 - 10;
v6 = v4 + 55;
v7 = v4 + 61;
if ( v5 <= 0x19 )
v7 = v6;
*v2++ = v7;
}
while ( v2 != v3 );
LABEL_8:
v0[36] = 0;
}
return v0;
}

original_code:
char* mimegetboundary()
{
    int i, num;
    char* boundaryString = (char*)malloc(36 + 1);
    srand(time(((void *)0)));
    if (boundaryString == ((void *)0))
        return ((void *)0);
    for (i=0;i<36;i++) {
        num=(rand()%62);
        if(num<10)
            num+=48;
        else if(num>=10 && num<36)
            num+=55;
        else
            num+=61;
        boundaryString[i]=(char)num;
    }
    boundaryString[i]='\0';
    return boundaryString;
}

canonical_original_code:
char *mimegetboundary()
{
    int i; int num;
    char *boundaryString = (char*)malloc(36 + 1);
    srand(time(((void *)0)));
    if (boundaryString == ((void *)0))
        return ((void *)0);
    for (i=0;i<36;i++) {
        num=(rand()%62);
        if(num<10)
            num+=48;
        else if(num>=10 && num<36)
            num+=55;
        else
            num+=61;
        boundaryString[i]=(char)num;
    }
    boundaryString[i]='\0';
    return boundaryString;
}

variable_types: num int

variable_types:
boundaryString
char *


mimeheaders

decompiled_code:
__int64 __fastcall mimeheaders(__int64 a1, const char *a2)
{
sockprintf(a1, "MIME-Version: 1.0");
sockprintf((unsigned int)a1, "Content-Type: multipart/mixed;");
return sockprintf((unsigned int)a1, " boundary=\"%s\"", a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
sockprintf(a1, "MIME-Version: 1.0");
sockprintf((unsigned int)a1, "Content-Type: multipart/mixed;");
return sockprintf((unsigned int)a1, " boundary=\"%s\"", a2);
}

original_code:
void mimeheaders(int socket, char* boundary)
{
    sockprintf(socket,"MIME-Version: 1.0");
    sockprintf(socket,"Content-Type: multipart/mixed;");
    sockprintf(socket," boundary=\"%s\"",boundary);
}

canonical_original_code:
void mimeheaders(int socket, char *boundary)
{
    sockprintf(socket,"MIME-Version: 1.0");
    sockprintf(socket,"Content-Type: multipart/mixed;");
    sockprintf(socket," boundary=\"%s\"",boundary);
}

variable_types: socket int

variable_types:
boundary
char *


mimeblurb

decompiled_code:
__int64 __fastcall mimeblurb(__int64 a1)
{
sockprintf(a1, "This is a multi-part message in MIME format.");
return sockprintf((unsigned int)a1, (const char *)&unk_324);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
sockprintf(a1, "This is a multi-part message in MIME format.");
return sockprintf((unsigned int)a1, (const char *)&unk_324);
}

original_code:
void mimeblurb(int socket, char* boundary)
{
    sockprintf(socket,"This is a multi-part message in MIME format.");
    sockprintf(socket,"");
}

canonical_original_code:
void mimeblurb(int socket, char *boundary)
{
    sockprintf(socket,"This is a multi-part message in MIME format.");
    sockprintf(socket,"");
}