decompiled_code:
int print_help()
{
puts("The current commands are:");
puts("\tclients");
puts("\thelp");
puts("\tserverinfo");
return puts("\tshutdown");
}

canonical_decompiled_code:
int func0()
{
puts("The current commands are:");
puts("\tclients");
puts("\thelp");
puts("\tserverinfo");
return puts("\tshutdown");
}

original_code:
static void print_help (void)
{
  printf ("The current commands are:\n");
  printf ("\tclients\n");
  printf ("\thelp\n");
  printf ("\tserverinfo\n");
  printf ("\tshutdown\n");
  return;
}

canonical_original_code:
static void print_help()
{
  printf ("The current commands are:\n");
  printf ("\tclients\n");
  printf ("\thelp\n");
  printf ("\tserverinfo\n");
  printf ("\tshutdown\n");
  return;
}


decompiled_code:
__int64 server_info()
{
__int64 v0; // rax
void *v1; // rbx
unsigned int v2; // ebp
char *v3; // rbx
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = get_config_value("INTERFACE_CONFIG", "../conf/ftp.conf");
if ( !v0 )
return (unsigned int)-1;
v1 = (void *)v0;
v2 = get_interface_address(v0, v5);
if ( v2 == -1 )
{
free(v1);
}
else
{
free(v1);
v3 = (char *)get_config_value("DEFAULT_PORT_CONFIG", "../conf/ftp.conf");
if ( v3 )
{
puts("The server can be reached at:");
printf("\tIP address: %s\n", v5);
printf("\ton port : %s\n", v3);
free(v3);
v2 = 0;
}
else
{
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
void *v1; // rbx
unsigned int v2; // ebp
char *v3; // rbx
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = get_config_value("INTERFACE_CONFIG", "../conf/ftp.conf");
if ( !v0 )
return (unsigned int)-1;
v1 = (void *)v0;
v2 = get_interface_address(v0, v5);
if ( v2 == -1 )
{
free(v1);
}
else
{
free(v1);
v3 = (char *)get_config_value("DEFAULT_PORT_CONFIG", "../conf/ftp.conf");
if ( v3 )
{
puts("The server can be reached at:");
printf("\tIP address: %s\n", v5);
printf("\ton port : %s\n", v3);
free(v3);
v2 = 0;
}
else
{
v2 = -1;
}
}
return v2;
}

original_code:
static int server_info (void)
{
  char *interface;
  char address[16];
  char *port;
  if ((interface = get_config_value ("INTERFACE_CONFIG",
         "../conf/ftp.conf")) == ((void *)0))
    return -1;
  if (get_interface_address (interface, &address) == -1) {
    free (interface);
    return -1;
  }
  free (interface);
  if ((port = get_config_value ("DEFAULT_PORT_CONFIG",
    "../conf/ftp.conf")) == ((void *)0))
    return -1;
  printf ("The server can be reached at:\n");
  printf ("\tIP address: %s\n", address);
  printf ("\ton port   : %s\n", port);
  free (port);
  return 0;
}

canonical_original_code:
static int server_info()
{
  char *interface;
  char address[16];
  char *port;
  if ((interface = get_config_value ("INTERFACE_CONFIG",
         "../conf/ftp.conf")) == ((void *)0))
    return -1;
  if (get_interface_address (interface, &address) == -1) {
    free (interface);
    return -1;
  }
  free (interface);
  if ((port = get_config_value ("DEFAULT_PORT_CONFIG",
    "../conf/ftp.conf")) == ((void *)0))
    return -1;
  printf ("The server can be reached at:\n");
  printf ("\tIP address: %s\n", address);
  printf ("\ton port   : %s\n", port);
  free (port);
  return 0;
}

variable_types:
interface
char *

variable_types:
address
char [16]

variable_types:
port
char *

return_type: int


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

puts("The server is now ready to accept client connections.\n");
result = server_info();
if ( (_DWORD)result != -1 )
{
printf("\nYou may enter commands to this console. ");
puts("Enter \"help\" for a list of commands.");
result = 0LL;
}
return result;
}

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

puts("The server is now ready to accept client connections.\n");
result = func1();
if ( (_DWORD)result != -1 )
{
printf("\nYou may enter commands to this console. ");
puts("Enter \"help\" for a list of commands.");
result = 0LL;
}
return result;
}

original_code:
int welcome_message (void)
{
  printf ("The server is now ready to accept client connections.\n\n");
  if (server_info () == -1)
    return -1;
  printf ("\nYou may enter commands to this console. ");
  printf ("Enter \"help\" for a list of commands.\n");
  return 0;
}

canonical_original_code:
int welcome_message()
{
  printf ("The server is now ready to accept client connections.\n\n");
  if (server_info () == -1)
    return -1;
  printf ("\nYou may enter commands to this console. ");
  printf ("Enter \"help\" for a list of commands.\n");
  return 0;
}


decompiled_code:
__int64 read_server_cmd()
{
unsigned int v0; // ebx
bool v1; // cf
bool v2; // zf
char *v3; // rsi
const char *v4; // rdi
__int64 v5; // rcx
bool v6; // al
bool v7; // cf
bool v8; // zf
char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx
unsigned int v12; // eax
char v14[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !fgets(v14, 79, stdin) )
return (unsigned int)-1;
v0 = strcmp(v14, "help\n") != 0;
v1 = 0;
v2 = v0 == 0;
if ( v0 )
{
v3 = v14;
v4 = "serverinfo\n";
v5 = 12LL;
do
{
if ( !v5 )
break;
v1 = (unsigned __int8)*v3 < (unsigned int)*v4;
v2 = *v3++ == *v4++;
--v5;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
{
v0 = -((unsigned int)server_info(v4, v3) == -1);
}
else
{
v6 = strcmp(v14, "shutdown\n") != 0;
v7 = 0;
v8 = !v6;
if ( v6 )
{
v9 = v14;
v10 = "clients\n";
v11 = 9LL;
do
{
if ( !v11 )
break;
v7 = (unsigned __int8)*v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
v0 = (char)((!v7 && !v8) - v7);
if ( (!v7 && !v8) == v7 )
{
v12 = get_cthread_count(v10, v9);
printf("Current number of clients: %d\n", v12);
}
else
{
puts("Command not recognized, enter \"help\" for a list of commands.");
v0 = 0;
}
}
else
{
v0 = -999;
}
}
}
else
{
print_help();
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
bool v1; // cf
bool v2; // zf
char *v3; // rsi
const char *v4; // rdi
__int64 v5; // rcx
bool v6; // al
bool v7; // cf
bool v8; // zf
char *v9; // rsi
const char *v10; // rdi
__int64 v11; // rcx
unsigned int v12; // eax
char v14[88]; // [rsp+0h] [rbp-58h] BYREF

if ( !fgets(v14, 79, stdin) )
return (unsigned int)-1;
v0 = strcmp(v14, "help\n") != 0;
v1 = 0;
v2 = v0 == 0;
if ( v0 )
{
v3 = v14;
v4 = "serverinfo\n";
v5 = 12LL;
do
{
if ( !v5 )
break;
v1 = (unsigned __int8)*v3 < (unsigned int)*v4;
v2 = *v3++ == *v4++;
--v5;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
{
v0 = -((unsigned int)func1(v4, v3) == -1);
}
else
{
v6 = strcmp(v14, "shutdown\n") != 0;
v7 = 0;
v8 = !v6;
if ( v6 )
{
v9 = v14;
v10 = "clients\n";
v11 = 9LL;
do
{
if ( !v11 )
break;
v7 = (unsigned __int8)*v9 < (unsigned int)*v10;
v8 = *v9++ == *v10++;
--v11;
}
while ( v8 );
v0 = (char)((!v7 && !v8) - v7);
if ( (!v7 && !v8) == v7 )
{
v12 = get_cthread_count(v10, v9);
printf("Current number of clients: %d\n", v12);
}
else
{
puts("Command not recognized, enter \"help\" for a list of commands.");
v0 = 0;
}
}
else
{
v0 = -999;
}
}
}
else
{
func0();
}
return v0;
}

original_code:
int read_server_cmd (void)
{
  char cmd[80];
  if (fgets (cmd, 80 - 1, stdin) == ((void *)0))
    return -1;
  if (strcmp (cmd, "help\n") == 0) {
    print_help ();
    return 0;
  } else if (strcmp (cmd, "serverinfo\n") == 0) {
    if (server_info () == -1)
      return -1;
    return 0;
  } else if (strcmp (cmd, "shutdown\n") == 0) {
    return -999;
  } else if (strcmp (cmd, "clients\n") == 0) {
    printf ("Current number of clients: %d\n", get_cthread_count());
  } else {
    printf ("Command not recognized, enter \"help\" for a list of commands.\n");
  }
  return 0;
}

canonical_original_code:
int read_server_cmd()
{
  char cmd[80];
  if (fgets (cmd, 80 - 1, stdin) == ((void *)0))
    return -1;
  if (strcmp (cmd, "help\n") == 0) {
    print_help ();
    return 0;
  } else if (strcmp (cmd, "serverinfo\n") == 0) {
    if (server_info () == -1)
      return -1;
    return 0;
  } else if (strcmp (cmd, "shutdown\n") == 0) {
    return -999;
  } else if (strcmp (cmd, "clients\n") == 0) {
    printf ("Current number of clients: %d\n", get_cthread_count());
  } else {
    printf ("Command not recognized, enter \"help\" for a list of commands.\n");
  }
  return 0;
}

variable_types:
cmd
char [80]


decompiled_code:
__int64 __fastcall cmd_help(unsigned int *a1, const char *a2)
{
unsigned int v2; // ebp

v2 = *a1;
if ( !a2 )
return send_mesg_214_general(v2);
if ( !strcmp(a2, "USER") )
return send_mesg_214_specific(v2, "To use: USER <SP> <username> <CRLF>\n", "\tSend new user information\n");
if ( !strcmp(a2, "PASS") )
return send_mesg_214_specific(v2, "To use: PASS <SP> <password> <CRLF>\n", "\tSend a user password\n");
if ( !strcmp(a2, "QUIT") )
return send_mesg_214_specific(v2, "To use: QUIT <CRLF>\n", "\tTerminate the FTP session and exit\n");
if ( !strcmp(a2, "PORT") )
return send_mesg_214_specific(v2, "To use: PORT <SP> <host-port> <CRLF>\n", "\tOpen a specified data port\n");
if ( !strcmp(a2, "PASV") )
return send_mesg_214_specific(v2, "To use: PASV <CRLF>\n", "\tEnter passive transfer mode\n");
if ( !strcmp(a2, "TYPE") )
return send_mesg_214_specific(v2, "To use: TYPE <SP> <type-code> <CRLF>\n", "\tSet file transfer type\n");
if ( !strcmp(a2, "STRU") )
return send_mesg_214_specific(v2, "To use: STRU <SP> <structure-code> <CRLF>\n", "\tSet file transfer structure\n");
if ( !strcmp(a2, "MODE") )
return send_mesg_214_specific(v2, "To use: MODE <SP> <mode-code> <CRLF>\n", "\tSet file transfer mode\n");
if ( !strcmp(a2, "RETR") )
return send_mesg_214_specific(
v2,
"To use: RETR <SP> <pathname> <CRLF>\n",
"\tRetrieve a file from the remote host\n");
if ( !strcmp(a2, "STOR") )
return send_mesg_214_specific(v2, "To use: STOR <SP> <pathname> <CRLF>\n", "\tStore a file on the remote host\n");
if ( !strcmp(a2, "STOU") )
return send_mesg_214_specific(v2, "To use: STOU <CRLF>\n", "\tStore a file uniquely\n");
if ( !strcmp(a2, "APPE") )
return send_mesg_214_specific(v2, "To use: APPE <SP> <pathname> <CRLF>\n", "\tAppend to a remote file\n");
if ( !strcmp(a2, "ABOR") )
return send_mesg_214_specific(v2, "To use: ABOR <CRLF>\n", "\tAbort a file transfer\n");
if ( !strcmp(a2, "LIST") )
return send_mesg_214_specific(v2, "To use: LIST [<SP> <pathname>] <CRLF>\n", "\tList contents of remote path\n");
if ( !strcmp(a2, "NLST") )
return send_mesg_214_specific(v2, "To use: NLST [<SP> <pathname>] <CRLF>\n", "\tName list of remote directory\n");
if ( !strcmp(a2, "SYST") )
return send_mesg_214_specific(v2, "To use: SYST <CRLF>\n", "\tReturn remote system type\n");
if ( !strcmp(a2, "HELP") )
return send_mesg_214_specific(
v2,
"To use: HELP [<SP> <string>] <CRLF>\n",
"\tPrint local help information on using the server\n");
if ( !strcmp(a2, "NOOP") )
return send_mesg_214_specific(v2, "To use: NOOP <CRLF>\n", "\tDo nothing; server sends an OK reply\n");
if ( !strcmp(a2, "ACCT") )
return send_mesg_214_specific(
v2,
"To use: ACCT <SP> <account-information> <CRLF>\n",
"\tSend account command to the remote server\n");
if ( !strcmp(a2, "CDUP") )
return send_mesg_214_specific(
v2,
"To use: CDUP <CRLF>\n",
"\tChange remote working directory to parent directory\n");
if ( !strcmp(a2, "SMNT") )
return send_mesg_214_specific(
v2,
"To use: SMNT <SP> <pathname> <CRLF>\n",
"\tMount a different file system data structure withoutaltering their login\n\tor accounting information\n");
if ( !strcmp(a2, "REIN") )
return send_mesg_214_specific(v2, "To use: REIN <CRLF>\n", "\tReinitialize the connection\n");
if ( !strcmp(a2, "ALLO") )
return send_mesg_214_specific(
v2,
"To use: ALLO <SP> <decimal-integer> [<SP> R <SP> <decimal-integer>] <CRLF>\n",
"\tAllocate sufficient storage space to receive a file\n");
if ( !strcmp(a2, "REST") )
return send_mesg_214_specific(v2, "To use: REST <SP> <marker> <CRLF>\n", "\tRestart transfer at bytecount marker\n");
if ( !strcmp(a2, "RNFR") )
return send_mesg_214_specific(
v2,
"To use: RNFR <SP> <pathname> <CRLF>\n",
"\tUsed when renaming a file; rename from\n");
if ( !strcmp(a2, "RNTO") )
return send_mesg_214_specific(
v2,
"To use: RNTO <SP> <pathname> <CRLF>\n",
"\tUsed when renaming a file; rename to\n");
if ( !strcmp(a2, "DELE") )
return send_mesg_214_specific(v2, "To use: DELE <SP> <pathname> <CRLF>\n", "\tDelete a remote file\n");
if ( !strcmp(a2, "SITE") )
return send_mesg_214_specific(
v2,
"To use: SITE <SP> <string> <CRLF>\n",
"\tSend site specific command to the remote server\n");
if ( !strcmp(a2, "STAT") )
return send_mesg_214_specific(v2, "To use: STAT [<SP> <pathname>] <CRLF>\n", "\tReturn current server status\n");
if ( !strcmp(a2, "CWD") )
return send_mesg_214_specific(
v2,
"To use: CWD <SP> <pathname> <CRLF>\n",
"\tChange the current working directory on the remote machine\n");
if ( !strcmp(a2, "RMD") )
return send_mesg_214_specific(
v2,
"To use: RMD <SP> <pathname> <CRLF>\n",
"\tRemove a directory on the remote machine\n");
if ( !strcmp(a2, "MKD") )
return send_mesg_214_specific(
v2,
"To use: MKD <SP> <pathname> <CRLF>\n",
"\tCreate a directory on the remote machine\n");
if ( !strcmp(a2, "PWD") )
return send_mesg_214_specific(
v2,
"To use: PWD <CRLF>\n",
"\tPrint the current working directory on the remote machine\n");
return send_mesg_501(v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, const char *a2)
{
unsigned int v2; // ebp

v2 = *a1;
if ( !a2 )
return send_mesg_214_general(v2);
if ( !strcmp(a2, "USER") )
return send_mesg_214_specific(v2, "To use: USER <SP> <username> <CRLF>\n", "\tSend new user information\n");
if ( !strcmp(a2, "PASS") )
return send_mesg_214_specific(v2, "To use: PASS <SP> <password> <CRLF>\n", "\tSend a user password\n");
if ( !strcmp(a2, "QUIT") )
return send_mesg_214_specific(v2, "To use: QUIT <CRLF>\n", "\tTerminate the FTP session and exit\n");
if ( !strcmp(a2, "PORT") )
return send_mesg_214_specific(v2, "To use: PORT <SP> <host-port> <CRLF>\n", "\tOpen a specified data port\n");
if ( !strcmp(a2, "PASV") )
return send_mesg_214_specific(v2, "To use: PASV <CRLF>\n", "\tEnter passive transfer mode\n");
if ( !strcmp(a2, "TYPE") )
return send_mesg_214_specific(v2, "To use: TYPE <SP> <type-code> <CRLF>\n", "\tSet file transfer type\n");
if ( !strcmp(a2, "STRU") )
return send_mesg_214_specific(v2, "To use: STRU <SP> <structure-code> <CRLF>\n", "\tSet file transfer structure\n");
if ( !strcmp(a2, "MODE") )
return send_mesg_214_specific(v2, "To use: MODE <SP> <mode-code> <CRLF>\n", "\tSet file transfer mode\n");
if ( !strcmp(a2, "RETR") )
return send_mesg_214_specific(
v2,
"To use: RETR <SP> <pathname> <CRLF>\n",
"\tRetrieve a file from the remote host\n");
if ( !strcmp(a2, "STOR") )
return send_mesg_214_specific(v2, "To use: STOR <SP> <pathname> <CRLF>\n", "\tStore a file on the remote host\n");
if ( !strcmp(a2, "STOU") )
return send_mesg_214_specific(v2, "To use: STOU <CRLF>\n", "\tStore a file uniquely\n");
if ( !strcmp(a2, "APPE") )
return send_mesg_214_specific(v2, "To use: APPE <SP> <pathname> <CRLF>\n", "\tAppend to a remote file\n");
if ( !strcmp(a2, "ABOR") )
return send_mesg_214_specific(v2, "To use: ABOR <CRLF>\n", "\tAbort a file transfer\n");
if ( !strcmp(a2, "LIST") )
return send_mesg_214_specific(v2, "To use: LIST [<SP> <pathname>] <CRLF>\n", "\tList contents of remote path\n");
if ( !strcmp(a2, "NLST") )
return send_mesg_214_specific(v2, "To use: NLST [<SP> <pathname>] <CRLF>\n", "\tName list of remote directory\n");
if ( !strcmp(a2, "SYST") )
return send_mesg_214_specific(v2, "To use: SYST <CRLF>\n", "\tReturn remote system type\n");
if ( !strcmp(a2, "HELP") )
return send_mesg_214_specific(
v2,
"To use: HELP [<SP> <string>] <CRLF>\n",
"\tPrint local help information on using the server\n");
if ( !strcmp(a2, "NOOP") )
return send_mesg_214_specific(v2, "To use: NOOP <CRLF>\n", "\tDo nothing; server sends an OK reply\n");
if ( !strcmp(a2, "ACCT") )
return send_mesg_214_specific(
v2,
"To use: ACCT <SP> <account-information> <CRLF>\n",
"\tSend account command to the remote server\n");
if ( !strcmp(a2, "CDUP") )
return send_mesg_214_specific(
v2,
"To use: CDUP <CRLF>\n",
"\tChange remote working directory to parent directory\n");
if ( !strcmp(a2, "SMNT") )
return send_mesg_214_specific(
v2,
"To use: SMNT <SP> <pathname> <CRLF>\n",
"\tMount a different file system data structure withoutaltering their login\n\tor accounting information\n");
if ( !strcmp(a2, "REIN") )
return send_mesg_214_specific(v2, "To use: REIN <CRLF>\n", "\tReinitialize the connection\n");
if ( !strcmp(a2, "ALLO") )
return send_mesg_214_specific(
v2,
"To use: ALLO <SP> <decimal-integer> [<SP> R <SP> <decimal-integer>] <CRLF>\n",
"\tAllocate sufficient storage space to receive a file\n");
if ( !strcmp(a2, "REST") )
return send_mesg_214_specific(v2, "To use: REST <SP> <marker> <CRLF>\n", "\tRestart transfer at bytecount marker\n");
if ( !strcmp(a2, "RNFR") )
return send_mesg_214_specific(
v2,
"To use: RNFR <SP> <pathname> <CRLF>\n",
"\tUsed when renaming a file; rename from\n");
if ( !strcmp(a2, "RNTO") )
return send_mesg_214_specific(
v2,
"To use: RNTO <SP> <pathname> <CRLF>\n",
"\tUsed when renaming a file; rename to\n");
if ( !strcmp(a2, "DELE") )
return send_mesg_214_specific(v2, "To use: DELE <SP> <pathname> <CRLF>\n", "\tDelete a remote file\n");
if ( !strcmp(a2, "SITE") )
return send_mesg_214_specific(
v2,
"To use: SITE <SP> <string> <CRLF>\n",
"\tSend site specific command to the remote server\n");
if ( !strcmp(a2, "STAT") )
return send_mesg_214_specific(v2, "To use: STAT [<SP> <pathname>] <CRLF>\n", "\tReturn current server status\n");
if ( !strcmp(a2, "CWD") )
return send_mesg_214_specific(
v2,
"To use: CWD <SP> <pathname> <CRLF>\n",
"\tChange the current working directory on the remote machine\n");
if ( !strcmp(a2, "RMD") )
return send_mesg_214_specific(
v2,
"To use: RMD <SP> <pathname> <CRLF>\n",
"\tRemove a directory on the remote machine\n");
if ( !strcmp(a2, "MKD") )
return send_mesg_214_specific(
v2,
"To use: MKD <SP> <pathname> <CRLF>\n",
"\tCreate a directory on the remote machine\n");
if ( !strcmp(a2, "PWD") )
return send_mesg_214_specific(
v2,
"To use: PWD <CRLF>\n",
"\tPrint the current working directory on the remote machine\n");
return send_mesg_501(v2);
}

original_code:
void cmd_help (session_info_t *si, char *arg)
{
  int csfd = si->csfd;
  if (arg == ((void *)0)) {
    send_mesg_214_general (csfd);
    return;
  }
  if (strcmp (arg, "USER") == 0) {
    send_mesg_214_specific (csfd, "To use: USER <SP> <username> <CRLF>\n",
       "\tSend new user information\n");
  } else if (strcmp (arg, "PASS") == 0) {
    send_mesg_214_specific (csfd, "To use: PASS <SP> <password> <CRLF>\n",
       "\tSend a user password\n");
  } else if (strcmp (arg, "QUIT") == 0) {
    send_mesg_214_specific (csfd, "To use: QUIT <CRLF>\n",
       "\tTerminate the FTP session and exit\n");
  } else if (strcmp (arg, "PORT") == 0) {
    send_mesg_214_specific (csfd, "To use: PORT <SP> <host-port> <CRLF>\n",
       "\tOpen a specified data port\n");
  } else if (strcmp (arg, "PASV") == 0) {
    send_mesg_214_specific (csfd, "To use: PASV <CRLF>\n",
       "\tEnter passive transfer mode\n");
  } else if (strcmp (arg, "TYPE") == 0) {
    send_mesg_214_specific (csfd, "To use: TYPE <SP> <type-code> <CRLF>\n",
       "\tSet file transfer type\n");
  } else if (strcmp (arg, "STRU") == 0) {
    send_mesg_214_specific (csfd, "To use: STRU <SP> <structure-code> <CRLF>\n",
       "\tSet file transfer structure\n");
  } else if (strcmp (arg, "MODE") == 0) {
    send_mesg_214_specific (csfd, "To use: MODE <SP> <mode-code> <CRLF>\n",
       "\tSet file transfer mode\n");
  } else if (strcmp (arg, "RETR") == 0) {
    send_mesg_214_specific (csfd, "To use: RETR <SP> <pathname> <CRLF>\n",
       "\tRetrieve a file from the remote host\n");
  } else if (strcmp (arg, "STOR") == 0) {
    send_mesg_214_specific (csfd, "To use: STOR <SP> <pathname> <CRLF>\n",
       "\tStore a file on the remote host\n");
  } else if (strcmp (arg, "STOU") == 0) {
    send_mesg_214_specific (csfd, "To use: STOU <CRLF>\n",
       "\tStore a file uniquely\n");
  } else if (strcmp (arg, "APPE") == 0) {
    send_mesg_214_specific (csfd, "To use: APPE <SP> <pathname> <CRLF>\n",
       "\tAppend to a remote file\n");
  } else if (strcmp (arg, "ABOR") == 0) {
    send_mesg_214_specific (csfd, "To use: ABOR <CRLF>\n",
       "\tAbort a file transfer\n");
  } else if (strcmp (arg, "LIST") == 0) {
    send_mesg_214_specific (csfd, "To use: LIST [<SP> <pathname>] <CRLF>\n",
       "\tList contents of remote path\n");
  } else if (strcmp (arg, "NLST") == 0) {
    send_mesg_214_specific (csfd, "To use: NLST [<SP> <pathname>] <CRLF>\n",
       "\tName list of remote directory\n");
  } else if (strcmp (arg, "SYST") == 0) {
    send_mesg_214_specific (csfd, "To use: SYST <CRLF>\n",
       "\tReturn remote system type\n");
  } else if (strcmp (arg, "HELP") == 0) {
    send_mesg_214_specific (csfd, "To use: HELP [<SP> <string>] <CRLF>\n",
       "\tPrint local help information on using the server\n");
  } else if (strcmp (arg, "NOOP") == 0) {
    send_mesg_214_specific (csfd, "To use: NOOP <CRLF>\n",
       "\tDo nothing; server sends an OK reply\n");
  } else if (strcmp (arg, "ACCT") == 0) {
    send_mesg_214_specific (csfd, "To use: ACCT <SP> <account-information> <CRLF>\n",
       "\tSend account command to the remote server\n");
  } else if (strcmp (arg, "CDUP") == 0) {
    send_mesg_214_specific (csfd, "To use: CDUP <CRLF>\n",
       "\tChange remote working directory to parent directory\n");
  } else if (strcmp (arg, "SMNT") == 0) {
    send_mesg_214_specific (csfd, "To use: SMNT <SP> <pathname> <CRLF>\n",
       "\tMount a different file system data structure without"
       "altering their login\n\tor accounting information\n");
  } else if (strcmp (arg, "REIN") == 0) {
    send_mesg_214_specific (csfd, "To use: REIN <CRLF>\n",
       "\tReinitialize the connection\n");
  } else if (strcmp (arg, "ALLO") == 0) {
    send_mesg_214_specific (csfd, "To use: ALLO <SP> <decimal-integer> "
       "[<SP> R <SP> <decimal-integer>] <CRLF>\n",
       "\tAllocate sufficient storage space to receive a file\n");
  } else if (strcmp (arg, "REST") == 0) {
    send_mesg_214_specific (csfd, "To use: REST <SP> <marker> <CRLF>\n",
       "\tRestart transfer at bytecount marker\n");
  } else if (strcmp (arg, "RNFR") == 0) {
    send_mesg_214_specific (csfd, "To use: RNFR <SP> <pathname> <CRLF>\n",
       "\tUsed when renaming a file; rename from\n");
  } else if (strcmp (arg, "RNTO") == 0) {
    send_mesg_214_specific (csfd, "To use: RNTO <SP> <pathname> <CRLF>\n",
       "\tUsed when renaming a file; rename to\n");
  } else if (strcmp (arg, "DELE") == 0) {
    send_mesg_214_specific (csfd, "To use: DELE <SP> <pathname> <CRLF>\n",
       "\tDelete a remote file\n");
  } else if (strcmp (arg, "SITE") == 0) {
    send_mesg_214_specific (csfd, "To use: SITE <SP> <string> <CRLF>\n",
       "\tSend site specific command to the remote server\n");
  } else if (strcmp (arg, "STAT") == 0) {
    send_mesg_214_specific (csfd, "To use: STAT [<SP> <pathname>] <CRLF>\n",
       "\tReturn current server status\n");
  }else if (strcmp (arg, "CWD") == 0) {
    send_mesg_214_specific (csfd, "To use: CWD <SP> <pathname> <CRLF>\n",
       "\tChange the current working directory on the remote machine\n");
  } else if (strcmp (arg, "RMD") == 0) {
    send_mesg_214_specific (csfd, "To use: RMD <SP> <pathname> <CRLF>\n",
       "\tRemove a directory on the remote machine\n");
  } else if (strcmp (arg, "MKD") == 0) {
    send_mesg_214_specific (csfd, "To use: MKD <SP> <pathname> <CRLF>\n",
       "\tCreate a directory on the remote machine\n");
  } else if (strcmp (arg, "PWD") == 0) {
    send_mesg_214_specific (csfd, "To use: PWD <CRLF>\n",
       "\tPrint the current working directory on the remote machine\n");
  } else {
    send_mesg_501 (csfd);
  }
}

canonical_original_code:
void cmd_help(struct session_info_t *si, char *arg)
{
  int csfd = si->csfd;
  if (arg == ((void *)0)) {
    send_mesg_214_general (csfd);
    return;
  }
  if (strcmp (arg, "USER") == 0) {
    send_mesg_214_specific (csfd, "To use: USER <SP> <username> <CRLF>\n",
       "\tSend new user information\n");
  } else if (strcmp (arg, "PASS") == 0) {
    send_mesg_214_specific (csfd, "To use: PASS <SP> <password> <CRLF>\n",
       "\tSend a user password\n");
  } else if (strcmp (arg, "QUIT") == 0) {
    send_mesg_214_specific (csfd, "To use: QUIT <CRLF>\n",
       "\tTerminate the FTP session and exit\n");
  } else if (strcmp (arg, "PORT") == 0) {
    send_mesg_214_specific (csfd, "To use: PORT <SP> <host-port> <CRLF>\n",
       "\tOpen a specified data port\n");
  } else if (strcmp (arg, "PASV") == 0) {
    send_mesg_214_specific (csfd, "To use: PASV <CRLF>\n",
       "\tEnter passive transfer mode\n");
  } else if (strcmp (arg, "TYPE") == 0) {
    send_mesg_214_specific (csfd, "To use: TYPE <SP> <type-code> <CRLF>\n",
       "\tSet file transfer type\n");
  } else if (strcmp (arg, "STRU") == 0) {
    send_mesg_214_specific (csfd, "To use: STRU <SP> <structure-code> <CRLF>\n",
       "\tSet file transfer structure\n");
  } else if (strcmp (arg, "MODE") == 0) {
    send_mesg_214_specific (csfd, "To use: MODE <SP> <mode-code> <CRLF>\n",
       "\tSet file transfer mode\n");
  } else if (strcmp (arg, "RETR") == 0) {
    send_mesg_214_specific (csfd, "To use: RETR <SP> <pathname> <CRLF>\n",
       "\tRetrieve a file from the remote host\n");
  } else if (strcmp (arg, "STOR") == 0) {
    send_mesg_214_specific (csfd, "To use: STOR <SP> <pathname> <CRLF>\n",
       "\tStore a file on the remote host\n");
  } else if (strcmp (arg, "STOU") == 0) {
    send_mesg_214_specific (csfd, "To use: STOU <CRLF>\n",
       "\tStore a file uniquely\n");
  } else if (strcmp (arg, "APPE") == 0) {
    send_mesg_214_specific (csfd, "To use: APPE <SP> <pathname> <CRLF>\n",
       "\tAppend to a remote file\n");
  } else if (strcmp (arg, "ABOR") == 0) {
    send_mesg_214_specific (csfd, "To use: ABOR <CRLF>\n",
       "\tAbort a file transfer\n");
  } else if (strcmp (arg, "LIST") == 0) {
    send_mesg_214_specific (csfd, "To use: LIST [<SP> <pathname>] <CRLF>\n",
       "\tList contents of remote path\n");
  } else if (strcmp (arg, "NLST") == 0) {
    send_mesg_214_specific (csfd, "To use: NLST [<SP> <pathname>] <CRLF>\n",
       "\tName list of remote directory\n");
  } else if (strcmp (arg, "SYST") == 0) {
    send_mesg_214_specific (csfd, "To use: SYST <CRLF>\n",
       "\tReturn remote system type\n");
  } else if (strcmp (arg, "HELP") == 0) {
    send_mesg_214_specific (csfd, "To use: HELP [<SP> <string>] <CRLF>\n",
       "\tPrint local help information on using the server\n");
  } else if (strcmp (arg, "NOOP") == 0) {
    send_mesg_214_specific (csfd, "To use: NOOP <CRLF>\n",
       "\tDo nothing; server sends an OK reply\n");
  } else if (strcmp (arg, "ACCT") == 0) {
    send_mesg_214_specific (csfd, "To use: ACCT <SP> <account-information> <CRLF>\n",
       "\tSend account command to the remote server\n");
  } else if (strcmp (arg, "CDUP") == 0) {
    send_mesg_214_specific (csfd, "To use: CDUP <CRLF>\n",
       "\tChange remote working directory to parent directory\n");
  } else if (strcmp (arg, "SMNT") == 0) {
    send_mesg_214_specific (csfd, "To use: SMNT <SP> <pathname> <CRLF>\n",
       "\tMount a different file system data structure without"
       "altering their login\n\tor accounting information\n");
  } else if (strcmp (arg, "REIN") == 0) {
    send_mesg_214_specific (csfd, "To use: REIN <CRLF>\n",
       "\tReinitialize the connection\n");
  } else if (strcmp (arg, "ALLO") == 0) {
    send_mesg_214_specific (csfd, "To use: ALLO <SP> <decimal-integer> "
       "[<SP> R <SP> <decimal-integer>] <CRLF>\n",
       "\tAllocate sufficient storage space to receive a file\n");
  } else if (strcmp (arg, "REST") == 0) {
    send_mesg_214_specific (csfd, "To use: REST <SP> <marker> <CRLF>\n",
       "\tRestart transfer at bytecount marker\n");
  } else if (strcmp (arg, "RNFR") == 0) {
    send_mesg_214_specific (csfd, "To use: RNFR <SP> <pathname> <CRLF>\n",
       "\tUsed when renaming a file; rename from\n");
  } else if (strcmp (arg, "RNTO") == 0) {
    send_mesg_214_specific (csfd, "To use: RNTO <SP> <pathname> <CRLF>\n",
       "\tUsed when renaming a file; rename to\n");
  } else if (strcmp (arg, "DELE") == 0) {
    send_mesg_214_specific (csfd, "To use: DELE <SP> <pathname> <CRLF>\n",
       "\tDelete a remote file\n");
  } else if (strcmp (arg, "SITE") == 0) {
    send_mesg_214_specific (csfd, "To use: SITE <SP> <string> <CRLF>\n",
       "\tSend site specific command to the remote server\n");
  } else if (strcmp (arg, "STAT") == 0) {
    send_mesg_214_specific (csfd, "To use: STAT [<SP> <pathname>] <CRLF>\n",
       "\tReturn current server status\n");
  }else if (strcmp (arg, "CWD") == 0) {
    send_mesg_214_specific (csfd, "To use: CWD <SP> <pathname> <CRLF>\n",
       "\tChange the current working directory on the remote machine\n");
  } else if (strcmp (arg, "RMD") == 0) {
    send_mesg_214_specific (csfd, "To use: RMD <SP> <pathname> <CRLF>\n",
       "\tRemove a directory on the remote machine\n");
  } else if (strcmp (arg, "MKD") == 0) {
    send_mesg_214_specific (csfd, "To use: MKD <SP> <pathname> <CRLF>\n",
       "\tCreate a directory on the remote machine\n");
  } else if (strcmp (arg, "PWD") == 0) {
    send_mesg_214_specific (csfd, "To use: PWD <CRLF>\n",
       "\tPrint the current working directory on the remote machine\n");
  } else {
    send_mesg_501 (csfd);
  }
}

variable_types: struct session_info_t { int csfd; int dsfd; char cwd[4096]; char user[64]; _Bool loggedin; _Bool cmdComplete; _Bool cmdAbort; _Bool cmdQuit; char cmdString[4096]; char type; } *

variable_types:
arg
char *

variable_types: csfd int

return_type: void


decompiled_code:
__int64 __fastcall modify_cthread_count(int a1)
{
unsigned int v1; // ebx
int v3; // eax

v1 = a1;
if ( a1 )
{
if ( pthread_mutex_lock(&ctrlCountMutex) )
{
fprintf(stderr, "%s: pthread_mutex_lock error\n", "modify_cthread_count");
v1 = -1;
}
else
{
if ( a1 <= 0 )
v3 = activeControlThreads - 1;
else
v3 = activeControlThreads + 1;
activeControlThreads = v3;
v1 = pthread_mutex_unlock(&ctrlCountMutex);
if ( v1 )
{
fprintf(stderr, "%s: pthread_mutex_unlock error\n", "modify_cthread_count");
v1 = -1;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // ebx
int v3; // eax

v1 = a1;
if ( a1 )
{
if ( pthread_mutex_lock(&ctrlCountMutex) )
{
fprintf(stderr, "%s: pthread_mutex_lock error\n", "modify_cthread_count");
v1 = -1;
}
else
{
if ( a1 <= 0 )
v3 = activeControlThreads - 1;
else
v3 = activeControlThreads + 1;
activeControlThreads = v3;
v1 = pthread_mutex_unlock(&ctrlCountMutex);
if ( v1 )
{
fprintf(stderr, "%s: pthread_mutex_unlock error\n", "modify_cthread_count");
v1 = -1;
}
}
}
return v1;
}

original_code:
int modify_cthread_count (int value)
{
  if (value == 0)
    return 0;
  if (pthread_mutex_lock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_lock error\n", __FUNCTION__);
    return -1;
  }
  if (value > 0)
    activeControlThreads++;
  else
    activeControlThreads--;
  if (pthread_mutex_unlock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_unlock error\n", __FUNCTION__);
    return -1;
  }
  return 0;
}

canonical_original_code:
int modify_cthread_count(int value)
{
  if (value == 0)
    return 0;
  if (pthread_mutex_lock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_lock error\n", __FUNCTION__);
    return -1;
  }
  if (value > 0)
    activeControlThreads++;
  else
    activeControlThreads--;
  if (pthread_mutex_unlock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_unlock error\n", __FUNCTION__);
    return -1;
  }
  return 0;
}

variable_types: value int


decompiled_code:
__int64 __fastcall control_thread(void *ptr)
{
while ( (unsigned int)send_mesg_220(*(unsigned int *)ptr) )
;
session(*(unsigned int *)ptr);
close(*(_DWORD *)ptr);
free(ptr);
modify_cthread_count(-1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
while ( (unsigned int)send_mesg_220(*(unsigned int *)ptr) )
;
session(*(unsigned int *)ptr);
close(*(_DWORD *)ptr);
free(ptr);
func0(-1);
return 0LL;
}

original_code:
void *control_thread (void *arg) {
  int *csfd = arg;
  while (send_mesg_220 (*csfd) != 0);
  session (*csfd);
  close (*csfd);
  free (csfd);
  modify_cthread_count (-1);
  return ((void *)0);
}

canonical_original_code:
void *control_thread(void *arg) {
  int *csfd = arg;
  while (send_mesg_220 (*csfd) != 0);
  session (*csfd);
  close (*csfd);
  free (csfd);
  modify_cthread_count (-1);
  return ((void *)0);
}

variable_types:
arg
void *

variable_types:
csfd
int *

return_type: void *


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

if ( pthread_mutex_lock(&ctrlCountMutex) )
{
fprintf(stderr, "%s: pthread_mutex_lock error\n", "get_cthread_count");
v0 = -1;
}
else
{
v0 = activeControlThreads;
if ( pthread_mutex_unlock(&ctrlCountMutex) )
{
fprintf(stderr, "%s: pthread_mutex_unlock error\n", "get_cthread_count");
v0 = -1;
}
}
return v0;
}

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

if ( pthread_mutex_lock(&ctrlCountMutex) )
{
fprintf(stderr, "%s: pthread_mutex_lock error\n", "get_cthread_count");
v0 = -1;
}
else
{
v0 = activeControlThreads;
if ( pthread_mutex_unlock(&ctrlCountMutex) )
{
fprintf(stderr, "%s: pthread_mutex_unlock error\n", "get_cthread_count");
v0 = -1;
}
}
return v0;
}

original_code:
int get_cthread_count (void)
{
  int count;
  if (pthread_mutex_lock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_lock error\n", __FUNCTION__);
    return -1;
  }
  count = activeControlThreads;
  if (pthread_mutex_unlock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_unlock error\n", __FUNCTION__);
    return -1;
  }
  return count;
}

canonical_original_code:
int get_cthread_count()
{
  int count;
  if (pthread_mutex_lock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_lock error\n", __FUNCTION__);
    return -1;
  }
  count = activeControlThreads;
  if (pthread_mutex_unlock (&ctrlCountMutex) != 0) {
    fprintf (stderr, "%s: pthread_mutex_unlock error\n", __FUNCTION__);
    return -1;
  }
  return count;
}

variable_types: count int


decompiled_code:
int __fastcall cmd_stou(unsigned int *a1)
{
void *v1; // rbp
int *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

if ( *((_BYTE *)a1 + 4168) && strcmp((const char *)a1 + 4104, "anonymous") )
{
v3 = time(0LL);
srand(v3);
do
{
if ( v1 )
free(v1);
v4 = rand();
sprintf(v6, "%d", v4);
v1 = (void *)merge_paths(a1 + 2, v6, 0LL);
}
while ( access((const char *)v1, 0) != -1 );
v2 = _errno_location();
if ( *v2 == 2 )
{
free(v1);
LODWORD(v2) = store((__int64)a1, (__int64)v6, "w");
}
}
else
{
send_mesg_530(*a1, 114LL);
LODWORD(v2) = close(a1[1]);
a1[1] = 0;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int *a1)
{
void *v1; // rbp
int *v2; // rax
unsigned int v3; // eax
unsigned int v4; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

if ( *((_BYTE *)a1 + 4168) && strcmp((const char *)a1 + 4104, "anonymous") )
{
v3 = time(0LL);
srand(v3);
do
{
if ( v1 )
free(v1);
v4 = rand();
sprintf(v6, "%d", v4);
v1 = (void *)merge_paths(a1 + 2, v6, 0LL);
}
while ( access((const char *)v1, 0) != -1 );
v2 = _errno_location();
if ( *v2 == 2 )
{
free(v1);
LODWORD(v2) = func2((__int64)a1, (__int64)v6, "w");
}
}
else
{
send_mesg_530(*a1, 114LL);
LODWORD(v2) = close(a1[1]);
a1[1] = 0;
}
return (int)v2;
}

original_code:
void cmd_stou (session_info_t *si, char *arg)
{
  int rt;
  char tempname[256];
  char *fullpath;
  int csfd = si->csfd;
  if (si->loggedin == 0 || strcmp (si->user, "anonymous") == 0) {
    send_mesg_530 (csfd, 'r');
    close (si->dsfd);
    si->dsfd = 0;
    return;
  }
  srand (time (((void *)0)));
  do {
    if (fullpath)
      free (fullpath);
    sprintf (tempname, "%d", rand());
    fullpath = merge_paths (si->cwd, tempname, ((void *)0));
    if ((rt = access (fullpath, 0)) == -1) {
      if ((*__errno_location ()) == 2)
 continue;
      else
 return;
    }
  } while (rt != -1);
  free (fullpath);
  store (si, tempname, "w");
  return;
}

canonical_original_code:
void cmd_stou(struct session_info_t *si, char *arg)
{
  int rt;
  char tempname[256];
  char *fullpath;
  int csfd = si->csfd;
  if (si->loggedin == 0 || strcmp (si->user, "anonymous") == 0) {
    send_mesg_530 (csfd, 'r');
    close (si->dsfd);
    si->dsfd = 0;
    return;
  }
  srand (time (((void *)0)));
  do {
    if (fullpath)
      free (fullpath);
    sprintf (tempname, "%d", rand());
    fullpath = merge_paths (si->cwd, tempname, ((void *)0));
    if ((rt = access (fullpath, 0)) == -1) {
      if ((*__errno_location ()) == 2)
 continue;
      else
 return;
    }
  } while (rt != -1);
  free (fullpath);
  store (si, tempname, "w");
  return;
}

variable_types: rt int

variable_types:
tempname
char [256]

variable_types:
fullpath
char *

user_defined_types: struct session_info_t { int csfd; int dsfd; char cwd[4096]; char user[64]; _Bool loggedin; _Bool cmdComplete; _Bool cmdAbort; _Bool cmdQuit; char cmdString[4096]; char type; }


decompiled_code:
__int64 __fastcall perm_neg_check(unsigned int *a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx

if ( !*((_BYTE *)a1 + 4168) || !strcmp((const char *)a1 + 4104, "anonymous") )
{
send_mesg_530(*a1, 114LL);
close(a1[1]);
a1[1] = 0;
v3 = -1;
}
else
{
v2 = check_future_file(a1 + 2, a2, 0LL);
v3 = v2;
if ( v2 == -1 )
{
cleanup_stor_recv(a1, 0LL, 450);
}
else if ( v2 == -2 || v2 == -3 )
{
cleanup_stor_recv(a1, 0LL, 553);
v3 = -1;
}
else
{
v3 = 0;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // ebx

if ( !*((_BYTE *)a1 + 4168) || !strcmp((const char *)a1 + 4104, "anonymous") )
{
send_mesg_530(*a1, 114LL);
close(a1[1]);
a1[1] = 0;
v3 = -1;
}
else
{
v2 = check_future_file(a1 + 2, a2, 0LL);
v3 = v2;
if ( v2 == -1 )
{
func1(a1, 0LL, 450);
}
else if ( v2 == -2 || v2 == -3 )
{
func1(a1, 0LL, 553);
v3 = -1;
}
else
{
v3 = 0;
}
}
return v3;
}

original_code:
static int perm_neg_check (session_info_t *si, char *arg)
{
  int pathCheck;
  if (si->loggedin == 0 || strcmp (si->user, "anonymous") == 0) {
    send_mesg_530 (si->csfd, 'r');
    close (si->dsfd);
    si->dsfd = 0;
    return -1;
  }
  if ((pathCheck = check_future_file (si->cwd, arg, 0)) == -1) {
    cleanup_stor_recv (si, ((void *)0), 450);
    return -1;
  } else if (pathCheck == -2) {
    cleanup_stor_recv (si, ((void *)0), 553);
    return -1;
  } else if (pathCheck == -3) {
    cleanup_stor_recv (si, ((void *)0), 553);
    return -1;
  }
  return 0;
}

canonical_original_code:
static int perm_neg_check(struct session_info_t *si, char *arg)
{
  int pathCheck;
  if (si->loggedin == 0 || strcmp (si->user, "anonymous") == 0) {
    send_mesg_530 (si->csfd, 'r');
    close (si->dsfd);
    si->dsfd = 0;
    return -1;
  }
  if ((pathCheck = check_future_file (si->cwd, arg, 0)) == -1) {
    cleanup_stor_recv (si, ((void *)0), 450);
    return -1;
  } else if (pathCheck == -2) {
    cleanup_stor_recv (si, ((void *)0), 553);
    return -1;
  } else if (pathCheck == -3) {
    cleanup_stor_recv (si, ((void *)0), 553);
    return -1;
  }
  return 0;
}

variable_types: pathCheck int


decompiled_code:
int __fastcall cmd_stor(unsigned int *a1, __int64 a2)
{
int result; // eax

result = perm_neg_check(a1, a2);
if ( result != -1 )
result = store((__int64)a1, a2, "w");
return result;
}

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

result = func4(a1, a2);
if ( result != -1 )
result = func2((__int64)a1, a2, "w");
return result;
}

original_code:
void cmd_stor (session_info_t *si, char *cmd)
{
  if (perm_neg_check (si, cmd) == -1)
    return;
  store (si, cmd, "w");
  return;
}

canonical_original_code:
void cmd_stor(struct session_info_t *si, char *cmd)
{
  if (perm_neg_check (si, cmd) == -1)
    return;
  store (si, cmd, "w");
  return;
}

variable_types:
cmd
char *


decompiled_code:
int __fastcall cmd_appe(unsigned int *a1, __int64 a2)
{
int result; // eax

result = perm_neg_check(a1, a2);
if ( result != -1 )
result = store((__int64)a1, a2, "a");
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1, __int64 a2)
{
int result; // eax

result = func4(a1, a2);
if ( result != -1 )
result = func2((__int64)a1, a2, "a");
return result;
}

original_code:
void cmd_appe (session_info_t *si, char *cmd)
{
  if (perm_neg_check (si, cmd) == -1)
    return;
  store (si, cmd, "a");
  return;
}

canonical_original_code:
void cmd_appe(struct session_info_t *si, char *cmd)
{
  if (perm_neg_check (si, cmd) == -1)
    return;
  store (si, cmd, "a");
  return;
}


decompiled_code:
__int64 __fastcall read_cmd(__int64 a1, int a2, __int64 a3)
{
unsigned int v5; // ebx
int v6; // edi
int v7; // eax
unsigned int v8; // er14
_BYTE *v9; // rax
char *v11; // rax

v5 = 0;
do
{
while ( 1 )
{
while ( 1 )
{
v7 = recv(a2, (void *)(a1 + (int)v5), 1uLL, 0);
v8 = v7;
if ( v7 != -1 )
break;
v6 = *_errno_location();
if ( v6 != 4 )
{
v11 = strerror(v6);
fprintf(stderr, "%s: recv: %s\n", "read_cmd", v11);
return v8;
}
}
if ( v7 <= 0 )
break;
v5 += v7;
v9 = (_BYTE *)(a1 + (int)v5 - 1);
if ( *v9 == 10 )
{
*v9 = 0;
return v5;
}
}
}
while ( v7 );
*(_BYTE *)(a3 + 4170) = 1;
*(_BYTE *)(a3 + 4171) = 1;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3)
{
unsigned int v5; // ebx
int v6; // edi
int v7; // eax
unsigned int v8; // er14
_BYTE *v9; // rax
char *v11; // rax

v5 = 0;
do
{
while ( 1 )
{
while ( 1 )
{
v7 = recv(a2, (void *)(a1 + (int)v5), 1uLL, 0);
v8 = v7;
if ( v7 != -1 )
break;
v6 = *_errno_location();
if ( v6 != 4 )
{
v11 = strerror(v6);
fprintf(stderr, "%s: recv: %s\n", "read_cmd", v11);
return v8;
}
}
if ( v7 <= 0 )
break;
v5 += v7;
v9 = (_BYTE *)(a1 + (int)v5 - 1);
if ( *v9 == 10 )
{
*v9 = 0;
return v5;
}
}
}
while ( v7 );
*(_BYTE *)(a3 + 4170) = 1;
*(_BYTE *)(a3 + 4171) = 1;
return v5;
}

original_code:
int read_cmd (char *str, int sock, session_info_t *si)
{
  int rt = 0;
  int len = 0;
  while (1) {
    if ((rt = recv (sock, str+len, 1, 0)) == -1) {
      if ((*__errno_location ()) == 4)
 continue;
      fprintf (stderr, "%s: recv: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      return -1;
    }
    if (rt > 0) {
      len += rt;
      if (str[len-1] == '\n') {
 str[len-1] = '\0';
 break;
      }
    } else if (rt == 0) {
      si->cmdAbort = 1;
      si->cmdQuit = 1;
      break;
    }
  }
  return len;
}

canonical_original_code:
int read_cmd(char *str, int sock, struct session_info_t *si)
{
  int rt = 0;
  int len = 0;
  while (1) {
    if ((rt = recv (sock, str+len, 1, 0)) == -1) {
      if ((*__errno_location ()) == 4)
 continue;
      fprintf (stderr, "%s: recv: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      return -1;
    }
    if (rt > 0) {
      len += rt;
      if (str[len-1] == '\n') {
 str[len-1] = '\0';
 break;
      }
    } else if (rt == 0) {
      si->cmdAbort = 1;
      si->cmdQuit = 1;
      break;
    }
  }
  return len;
}

variable_types:
str
char *

variable_types: sock int

variable_types: len int


session

decompiled_code:
__int64 __fastcall session(int a1)
{
int v2; // er14
__int64 v3; // r15
__int64 v4; // rbp
int v5; // edi
unsigned int v6; // ebx
int *v7; // rax
char *v8; // rax
char *v9; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
fd_set v15; // [rsp+0h] [rbp-3168h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-30E8h] BYREF
char s1[4096]; // [rsp+90h] [rbp-30D8h] BYREF
pthread_attr_t attr; // [rsp+1090h] [rbp-20D8h] BYREF
int arg; // [rsp+10D0h] [rbp-2098h] BYREF
int fd; // [rsp+10D4h] [rbp-2094h]
__int16 v21; // [rsp+10D8h] [rbp-2090h]
char v22; // [rsp+20D8h] [rbp-1090h]
char v23; // [rsp+2118h] [rbp-1050h]
char v24; // [rsp+2119h] [rbp-104Fh]
char v25; // [rsp+211Ah] [rbp-104Eh]
char v26; // [rsp+211Bh] [rbp-104Dh]
char dest[4108]; // [rsp+211Ch] [rbp-104Ch] BYREF
pthread_t newthread[8]; // [rsp+3128h] [rbp-40h] BYREF

newthread[0] = 0LL;
pthread_attr_init(&attr);
arg = a1;
fd = 0;
v25 = 0;
v26 = 0;
v23 = 0;
v24 = 0;
v22 = 0;
dest[0] = 0;
dest[4096] = 97;
v21 = 47;
s1[0] = 0;
if ( !shutdownServer )
{
v2 = a1 / 64;
v3 = 1LL << (a1 % 64);
v4 = 0LL;
while ( 1 )
{
memset(&v15, 0, sizeof(v15));
v15.fds_bits[v2] |= v3;
timeout.tv_sec = 0LL;
timeout.tv_usec = 100000LL;
v6 = select(a1 + 1, &v15, 0LL, 0LL, &timeout);
if ( v6 == -1 )
{
v5 = *_errno_location();
if ( v5 != 4 )
{
v9 = strerror(v5);
fprintf(stderr, "%s: select: %s\n", "session", v9);
free_queue(v4);
return v6;
}
}
else
{
if ( (v15.fds_bits[v2] & v3) != 0 )
{
v6 = read_cmd((__int64)s1, a1, (__int64)&arg);
if ( v6 == -1 )
{
free_queue(v4);
return v6;
}
v4 = add_to_queue(s1, v4);
}
if ( !strncasecmp(s1, "ABOR", 4uLL) )
{
v25 = 1;
s1[0] = 0;
send_mesg_226((unsigned int)a1, 97LL);
}
else if ( newthread[0] || !v4 )
{
if ( v24 )
{
v6 = pthread_join(newthread[0], 0LL);
if ( v6 == -1 )
goto LABEL_28;
newthread[0] = 0LL;
dest[0] = 0;
v24 = 0;
}
}
else
{
v4 = pull_from_queue(s1, v4);
strcpy(dest, s1);
s1[0] = 0;
v6 = pthread_create(newthread, &attr, (void *(*)(void *))&command_switch, &arg);
if ( v6 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: pthread_create: %s\n", "session", v8);
free_queue(v4);
return v6;
}
}
}
if ( shutdownServer || v26 )
goto LABEL_23;
}
}
v4 = 0LL;
LABEL_23:
v25 = 1;
if ( newthread[0] && (v6 = pthread_join(newthread[0], 0LL), v6 == -1) )
{
LABEL_28:
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s: pthread_join: %s\n", "session", v12);
free_queue(v4);
}
else
{
if ( fd > 0 && close(fd) == -1 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "%s: close: %s\n", "session", v14);
}
free_queue(v4);
pthread_attr_destroy(&attr);
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v2; // er14
__int64 v3; // r15
__int64 v4; // rbp
int v5; // edi
unsigned int v6; // ebx
int *v7; // rax
char *v8; // rax
char *v9; // rax
int *v11; // rax
char *v12; // rax
int *v13; // rax
char *v14; // rax
fd_set v15; // [rsp+0h] [rbp-3168h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-30E8h] BYREF
char s1[4096]; // [rsp+90h] [rbp-30D8h] BYREF
pthread_attr_t attr; // [rsp+1090h] [rbp-20D8h] BYREF
int arg; // [rsp+10D0h] [rbp-2098h] BYREF
int fd; // [rsp+10D4h] [rbp-2094h]
__int16 v21; // [rsp+10D8h] [rbp-2090h]
char v22; // [rsp+20D8h] [rbp-1090h]
char v23; // [rsp+2118h] [rbp-1050h]
char v24; // [rsp+2119h] [rbp-104Fh]
char v25; // [rsp+211Ah] [rbp-104Eh]
char v26; // [rsp+211Bh] [rbp-104Dh]
char dest[4108]; // [rsp+211Ch] [rbp-104Ch] BYREF
pthread_t newthread[8]; // [rsp+3128h] [rbp-40h] BYREF

newthread[0] = 0LL;
pthread_attr_init(&attr);
arg = a1;
fd = 0;
v25 = 0;
v26 = 0;
v23 = 0;
v24 = 0;
v22 = 0;
dest[0] = 0;
dest[4096] = 97;
v21 = 47;
s1[0] = 0;
if ( !shutdownServer )
{
v2 = a1 / 64;
v3 = 1LL << (a1 % 64);
v4 = 0LL;
while ( 1 )
{
memset(&v15, 0, sizeof(v15));
v15.fds_bits[v2] |= v3;
timeout.tv_sec = 0LL;
timeout.tv_usec = 100000LL;
v6 = select(a1 + 1, &v15, 0LL, 0LL, &timeout);
if ( v6 == -1 )
{
v5 = *_errno_location();
if ( v5 != 4 )
{
v9 = strerror(v5);
fprintf(stderr, "%s: select: %s\n", "session", v9);
free_queue(v4);
return v6;
}
}
else
{
if ( (v15.fds_bits[v2] & v3) != 0 )
{
v6 = func0((__int64)s1, a1, (__int64)&arg);
if ( v6 == -1 )
{
free_queue(v4);
return v6;
}
v4 = add_to_queue(s1, v4);
}
if ( !strncasecmp(s1, "ABOR", 4uLL) )
{
v25 = 1;
s1[0] = 0;
send_mesg_226((unsigned int)a1, 97LL);
}
else if ( newthread[0] || !v4 )
{
if ( v24 )
{
v6 = pthread_join(newthread[0], 0LL);
if ( v6 == -1 )
goto LABEL_28;
newthread[0] = 0LL;
dest[0] = 0;
v24 = 0;
}
}
else
{
v4 = pull_from_queue(s1, v4);
strcpy(dest, s1);
s1[0] = 0;
v6 = pthread_create(newthread, &attr, (void *(*)(void *))&command_switch, &arg);
if ( v6 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
fprintf(stderr, "%s: pthread_create: %s\n", "session", v8);
free_queue(v4);
return v6;
}
}
}
if ( shutdownServer || v26 )
goto LABEL_23;
}
}
v4 = 0LL;
LABEL_23:
v25 = 1;
if ( newthread[0] && (v6 = pthread_join(newthread[0], 0LL), v6 == -1) )
{
LABEL_28:
v11 = _errno_location();
v12 = strerror(*v11);
fprintf(stderr, "%s: pthread_join: %s\n", "session", v12);
free_queue(v4);
}
else
{
if ( fd > 0 && close(fd) == -1 )
{
v13 = _errno_location();
v14 = strerror(*v13);
fprintf(stderr, "%s: close: %s\n", "session", v14);
}
free_queue(v4);
pthread_attr_destroy(&attr);
v6 = 0;
}
return v6;
}

original_code:
int session (int csfd)
{
  queue *cmdQueuePtr = ((void *)0);
  pthread_t commandThread = 0;
  session_info_t sessioninfo;
  pthread_attr_t attr;
  char commandstr[4096];
  struct timeval timeout;
  fd_set rfds;
  pthread_attr_init (&attr);
  sessioninfo.csfd = csfd;
  sessioninfo.dsfd = 0;
  sessioninfo.cmdAbort = 0;
  sessioninfo.cmdQuit = 0;
  sessioninfo.loggedin = 0;
  sessioninfo.cmdComplete = 0;
  sessioninfo.user[0] = '\0';
  sessioninfo.cmdString[0] = '\0';
  sessioninfo.type = 'a';
  strcpy (sessioninfo.cwd, "/");
  commandstr[0] = '\0';
  while (!shutdownServer && !sessioninfo.cmdQuit) {
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rfds)->fds_bits)[((csfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((csfd) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 0;
    timeout.tv_usec = 100000;
    if (select (csfd+1, &rfds, ((void *)0), ((void *)0), &timeout) == -1) {
      if ((*__errno_location ()) == 4)
 continue;
      fprintf (stderr, "%s: select: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      free_queue (cmdQueuePtr);
      return -1;
    }
    if (((((&rfds)->fds_bits)[((csfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((csfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      if (read_cmd (commandstr, csfd, &sessioninfo) == -1) {
 free_queue (cmdQueuePtr);
 return -1;
      }
      cmdQueuePtr = add_to_queue (commandstr, cmdQueuePtr);
    }
    if (strncasecmp (commandstr, "ABOR", 4) == 0) {
      sessioninfo.cmdAbort = 1;
      commandstr[0] = '\0';
      send_mesg_226 (csfd, 'a');
    }
    else if (commandThread == 0 && cmdQueuePtr) {
      if (cmdQueuePtr) {
 cmdQueuePtr = pull_from_queue (commandstr, cmdQueuePtr);
      }
      strcpy (sessioninfo.cmdString, commandstr);
      commandstr[0] = '\0';
      if (pthread_create (&commandThread, &attr, &command_switch, (void*) &sessioninfo) == -1) {
 fprintf (stderr, "%s: pthread_create: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
 free_queue (cmdQueuePtr);
 return -1;
      }
    } else if (sessioninfo.cmdComplete) {
      if (pthread_join (commandThread, ((void *)0)) == -1) {
 fprintf (stderr, "%s: pthread_join: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
 free_queue (cmdQueuePtr);
 return -1;
      }
      commandThread = 0;
      sessioninfo.cmdString[0] = '\0';
      sessioninfo.cmdComplete = 0;
    }
  }
  sessioninfo.cmdAbort = 1;
  if (commandThread) {
    if (pthread_join (commandThread, ((void *)0)) == -1) {
      fprintf (stderr, "%s: pthread_join: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      free_queue (cmdQueuePtr);
      return -1;
    }
  }
  if (sessioninfo.dsfd > 0) {
    if (close (sessioninfo.dsfd) == -1)
      fprintf (stderr, "%s: close: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
  }
  free_queue (cmdQueuePtr);
  pthread_attr_destroy (&attr);
  return 0;
}

canonical_original_code:
int session(int csfd)
{
  struct node *cmdQueuePtr = ((void *)0);
  unsigned long commandThread = 0;
  struct session_info_t sessioninfo;
  union pthread_attr_t attr;
  char commandstr[4096];
  struct timeval timeout;
  struct fd_set rfds;
  pthread_attr_init (&attr);
  sessioninfo.csfd = csfd;
  sessioninfo.dsfd = 0;
  sessioninfo.cmdAbort = 0;
  sessioninfo.cmdQuit = 0;
  sessioninfo.loggedin = 0;
  sessioninfo.cmdComplete = 0;
  sessioninfo.user[0] = '\0';
  sessioninfo.cmdString[0] = '\0';
  sessioninfo.type = 'a';
  strcpy (sessioninfo.cwd, "/");
  commandstr[0] = '\0';
  while (!shutdownServer && !sessioninfo.cmdQuit) {
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&rfds)->fds_bits)[((csfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((csfd) % (8 * (int) sizeof (__fd_mask)))))));
    timeout.tv_sec = 0;
    timeout.tv_usec = 100000;
    if (select (csfd+1, &rfds, ((void *)0), ((void *)0), &timeout) == -1) {
      if ((*__errno_location ()) == 4)
 continue;
      fprintf (stderr, "%s: select: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      free_queue (cmdQueuePtr);
      return -1;
    }
    if (((((&rfds)->fds_bits)[((csfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((csfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      if (read_cmd (commandstr, csfd, &sessioninfo) == -1) {
 free_queue (cmdQueuePtr);
 return -1;
      }
      cmdQueuePtr = add_to_queue (commandstr, cmdQueuePtr);
    }
    if (strncasecmp (commandstr, "ABOR", 4) == 0) {
      sessioninfo.cmdAbort = 1;
      commandstr[0] = '\0';
      send_mesg_226 (csfd, 'a');
    }
    else if (commandThread == 0 && cmdQueuePtr) {
      if (cmdQueuePtr) {
 cmdQueuePtr = pull_from_queue (commandstr, cmdQueuePtr);
      }
      strcpy (sessioninfo.cmdString, commandstr);
      commandstr[0] = '\0';
      if (pthread_create (&commandThread, &attr, &command_switch, (void *) &sessioninfo) == -1) {
 fprintf (stderr, "%s: pthread_create: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
 free_queue (cmdQueuePtr);
 return -1;
      }
    } else if (sessioninfo.cmdComplete) {
      if (pthread_join (commandThread, ((void *)0)) == -1) {
 fprintf (stderr, "%s: pthread_join: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
 free_queue (cmdQueuePtr);
 return -1;
      }
      commandThread = 0;
      sessioninfo.cmdString[0] = '\0';
      sessioninfo.cmdComplete = 0;
    }
  }
  sessioninfo.cmdAbort = 1;
  if (commandThread) {
    if (pthread_join (commandThread, ((void *)0)) == -1) {
      fprintf (stderr, "%s: pthread_join: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
      free_queue (cmdQueuePtr);
      return -1;
    }
  }
  if (sessioninfo.dsfd > 0) {
    if (close (sessioninfo.dsfd) == -1)
      fprintf (stderr, "%s: close: %s\n", __FUNCTION__, strerror ((*__errno_location ())));
  }
  free_queue (cmdQueuePtr);
  pthread_attr_destroy (&attr);
  return 0;
}

variable_types: struct node { char cmd[4096]; struct node *next; } *

variable_types:
commandThread
unsigned long

variable_types: struct session_info_t { int csfd; int dsfd; char cwd[4096]; char user[64]; _Bool loggedin; _Bool cmdComplete; _Bool cmdAbort; _Bool cmdQuit; char cmdString[4096]; char type; }

variable_types: union pthread_attr_t { char __size[56]; long __align; }

variable_types:
commandstr
char [4096]

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

variable_types:
rfds
struct fd_set { long fds_bits[-1]; }


decompiled_code:
__int64 __fastcall putLittleEnd32(unsigned int *a1, unsigned int a2)
{
*a1 = a2;
return HIBYTE(a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int a2)
{
*a1 = a2;
return HIBYTE(a2);
}

original_code:
static inline void putLittleEnd32(byte_t *location, uint32_t value)
{
  location[0] = (byte_t)((value ) & 0xFF);
  location[1] = (byte_t)((value >> 8) & 0xFF);
  location[2] = (byte_t)((value >> 16) & 0xFF);
  location[3] = (byte_t)((value >> 24) & 0xFF);
}

canonical_original_code:
static inline void putLittleEnd32(unsigned char *location, unsigned int value)
{
  location[0] = (byte_t)((value ) & 0xFF);
  location[1] = (byte_t)((value >> 8) & 0xFF);
  location[2] = (byte_t)((value >> 16) & 0xFF);
  location[3] = (byte_t)((value >> 24) & 0xFF);
}

variable_types:
location
unsigned char *

variable_types:
value
unsigned int


decompiled_code:
unsigned __int64 __fastcall putLittleEnd64(unsigned __int64 *a1, unsigned __int64 a2)
{
*a1 = a2;
return HIWORD(a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 *a1, unsigned __int64 a2)
{
*a1 = a2;
return HIWORD(a2);
}

original_code:
static inline void putLittleEnd64(byte_t *location, uint64_t value)
{
  location[0] = (byte_t)((value ) & 0xFF);
  location[1] = (byte_t)((value >> 8) & 0xFF);
  location[2] = (byte_t)((value >> 16) & 0xFF);
  location[3] = (byte_t)((value >> 24) & 0xFF);
  location[4] = (byte_t)((value >> 32) & 0xFF);
  location[5] = (byte_t)((value >> 40) & 0xFF);
  location[6] = (byte_t)((value >> 48) & 0xFF);
  location[7] = (byte_t)((value >> 56) & 0xFF);
}

canonical_original_code:
static inline void putLittleEnd64(unsigned char *location, unsigned long value)
{
  location[0] = (byte_t)((value ) & 0xFF);
  location[1] = (byte_t)((value >> 8) & 0xFF);
  location[2] = (byte_t)((value >> 16) & 0xFF);
  location[3] = (byte_t)((value >> 24) & 0xFF);
  location[4] = (byte_t)((value >> 32) & 0xFF);
  location[5] = (byte_t)((value >> 40) & 0xFF);
  location[6] = (byte_t)((value >> 48) & 0xFF);
  location[7] = (byte_t)((value >> 56) & 0xFF);
}

variable_types:
value
unsigned long


original_code:
static inline uint32_t getLittleEnd32(const byte_t *location)
{
  return
    (((uint32_t)(location[0])) ) |
    (((uint32_t)(location[1])) << 8) |
    (((uint32_t)(location[2])) << 16) |
    (((uint32_t)(location[3])) << 24);
}

canonical_original_code:
static inline unsigned int getLittleEnd32(unsigned char *location)
{
  return
    (((unsigned int)(location[0])) ) |
    (((unsigned int)(location[1])) << 8) |
    (((unsigned int)(location[2])) << 16) |
    (((unsigned int)(location[3])) << 24);
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall circShiftLeft32(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

original_code:
static inline uint32_t circShiftLeft32(uint32_t value, int amount)
{
  if ((amount &= 31) == 0)
    return value;
  return (value << amount) | (value >> (32 - amount));
}

canonical_original_code:
static inline unsigned int circShiftLeft32(unsigned int value, int amount)
{
  if ((amount &= 31) == 0)
    return value;
  return (value << amount) | (value >> (32 - amount));
}

variable_types: amount int


canonical_original_code:
static void md5ProcessBlock(struct md5CTX *ctx, unsigned char *block)
{
  unsigned int a = ctx->h[0];
  unsigned int b = ctx->h[1];
  unsigned int c = ctx->h[2];
  unsigned int d = ctx->h[3];
  unsigned int w[16];
  unsigned int f; unsigned int k; unsigned int temp;
  int i;
  for (i = 0; i < 16; i++)
    w[i] = getLittleEnd32(block + i*4);
  for (i = 0; i < 64; i++) {
    if (i < 16) {
      f = (b & c) | ((~b) & d);
      k = i;
    }
    else if (i < 32) {
      f = (d & b) | ((~d) & c);
      k = ((i << 2) + i + 1) & (0x0F);
    }
    else if (i < 48) {
      f = b ^ c ^ d;
      k = ((i << 1) + i + 5) & (0x0F);
    }
    else {
      f = c ^ (b | (~d));
      k = ((i << 3) - i) & (0x0F);
    }
    temp = d;
    d = c;
    c = b;
    b = b + circShiftLeft32((a + f + SINE[i] + w[k]), ROTATION[i]);
    a = temp;
  }
  ctx->h[0] += a;
  ctx->h[1] += b;
  ctx->h[2] += c;
  ctx->h[3] += d;
}

variable_types: struct md5CTX { unsigned int h[4]; unsigned long bytesProcessed; unsigned char block[-1]; unsigned char bytesInBlock; } *

variable_types:
block
unsigned char *

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
c
unsigned int

variable_types:
d
unsigned int

variable_types:
w
unsigned int [16]

variable_types:
f
unsigned int

variable_types:
k
unsigned int

variable_types:
temp
unsigned int

variable_types: i int


original_code:
void md5Start(void *c)
{
  struct md5CTX *ctx = (struct md5CTX *)c;
  ctx->h[0] = (uint32_t)0x67452301;
  ctx->h[1] = (uint32_t)0xEFCDAB89;
  ctx->h[2] = (uint32_t)0x98BADCFE;
  ctx->h[3] = (uint32_t)0x10325476;
  ctx->bytesProcessed = 0;
  ctx->bytesInBlock = 0;
}

canonical_original_code:
void md5Start(void *c)
{
  struct md5CTX *ctx = (struct md5CTX *)c;
  ctx->h[0] = (unsigned int)0x67452301;
  ctx->h[1] = (unsigned int)0xEFCDAB89;
  ctx->h[2] = (unsigned int)0x98BADCFE;
  ctx->h[3] = (unsigned int)0x10325476;
  ctx->bytesProcessed = 0;
  ctx->bytesInBlock = 0;
}

variable_types:
c
void *

user_defined_types: struct md5CTX { unsigned int h[4]; unsigned long bytesProcessed; unsigned char block[-1]; unsigned char bytesInBlock; }


decompiled_code:
__int64 __fastcall md5Add(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rax
unsigned __int64 v7; // rax
size_t v8; // rbx
char v9; // al
unsigned __int8 v10; // di
unsigned int v12; // [rsp+Ch] [rbp-3Ch]

v5 = a3;
v12 = sizeIsLargerThan64(a3);
if ( v12 )
return (unsigned int)-1;
v6 = *(_QWORD *)(a1 + 16);
if ( ~v5 < v6 )
return (unsigned int)-1;
v7 = v5 + v6;
*(_QWORD *)(a1 + 16) = v7;
if ( v7 > 0x1FFFFFFFFFFFFFFFLL )
return (unsigned int)-1;
while ( v5 )
{
v10 = *(_BYTE *)(a1 + 88);
if ( v5 <= 0x3F || v10 )
{
v8 = 64 - v10;
if ( v8 > v5 )
v8 = v5;
memcpy((void *)(a1 + 24 + v10), a2, v8);
v9 = *(_BYTE *)(a1 + 88) + v8;
a2 += v8;
v5 -= v8;
if ( v9 == 64 )
{
*(_BYTE *)(a1 + 88) = 0;
md5ProcessBlock((int *)a1, (unsigned __int8 *)(a1 + 24));
}
else
{
*(_BYTE *)(a1 + 88) = v9;
}
}
else
{
md5ProcessBlock((int *)a1, (unsigned __int8 *)a2);
a2 += 64;
v5 -= 64LL;
}
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2, unsigned __int64 a3)
{
unsigned __int64 v5; // rbp
unsigned __int64 v6; // rax
unsigned __int64 v7; // rax
size_t v8; // rbx
char v9; // al
unsigned __int8 v10; // di
unsigned int v12; // [rsp+Ch] [rbp-3Ch]

v5 = a3;
v12 = func0(a3);
if ( v12 )
return (unsigned int)-1;
v6 = *(_QWORD *)(a1 + 16);
if ( ~v5 < v6 )
return (unsigned int)-1;
v7 = v5 + v6;
*(_QWORD *)(a1 + 16) = v7;
if ( v7 > 0x1FFFFFFFFFFFFFFFLL )
return (unsigned int)-1;
while ( v5 )
{
v10 = *(_BYTE *)(a1 + 88);
if ( v5 <= 0x3F || v10 )
{
v8 = 64 - v10;
if ( v8 > v5 )
v8 = v5;
memcpy((void *)(a1 + 24 + v10), a2, v8);
v9 = *(_BYTE *)(a1 + 88) + v8;
a2 += v8;
v5 -= v8;
if ( v9 == 64 )
{
*(_BYTE *)(a1 + 88) = 0;
func5((int *)a1, (unsigned __int8 *)(a1 + 24));
}
else
{
*(_BYTE *)(a1 + 88) = v9;
}
}
else
{
func5((int *)a1, (unsigned __int8 *)a2);
a2 += 64;
v5 -= 64LL;
}
}
return v12;
}

original_code:
int md5Add(void *c, const byte_t *bytes, size_t numBytes)
{
  struct md5CTX *ctx = (struct md5CTX *)c;
  size_t toFillBlock, addToCtx;
  if (sizeIsLargerThan64(numBytes) ||
      (18446744073709551615UL) - (uint64_t)numBytes < ctx->bytesProcessed)
    return -1;
  ctx->bytesProcessed = (uint64_t)numBytes + ctx->bytesProcessed;
  if (ctx->bytesProcessed > ((uint64_t)(0x1FFFFFFFFFFFFFFFLLU)))
    return -1;
  while (numBytes > 0) {
    if (ctx->bytesInBlock == 0 && numBytes >= (64)) {
      md5ProcessBlock(ctx, bytes);
      bytes += (64);
      numBytes -= (64);
    }
    else {
      toFillBlock = (64) - ctx->bytesInBlock;
      addToCtx = (toFillBlock < numBytes ? toFillBlock : numBytes);
      memcpy(ctx->block + ctx->bytesInBlock, bytes, addToCtx);
      ctx->bytesInBlock += addToCtx;
      bytes += addToCtx;
      numBytes -= addToCtx;
      if (ctx->bytesInBlock == (64)) {
 ctx->bytesInBlock = 0;
 md5ProcessBlock(ctx, ctx->block);
      }
    }
  }
  return 0;
}

canonical_original_code:
int md5Add(void *c, unsigned char *bytes, unsigned long numBytes)
{
  struct md5CTX *ctx = (struct md5CTX *)c;
  unsigned long toFillBlock; unsigned long addToCtx;
  if (sizeIsLargerThan64(numBytes) ||
      (18446744073709551615UL) - (unsigned long)numBytes < ctx->bytesProcessed)
    return -1;
  ctx->bytesProcessed = (unsigned long)numBytes + ctx->bytesProcessed;
  if (ctx->bytesProcessed > ((unsigned long)(0x1FFFFFFFFFFFFFFFLLU)))
    return -1;
  while (numBytes > 0) {
    if (ctx->bytesInBlock == 0 && numBytes >= (64)) {
      md5ProcessBlock(ctx, bytes);
      bytes += (64);
      numBytes -= (64);
    }
    else {
      toFillBlock = (64) - ctx->bytesInBlock;
      addToCtx = (toFillBlock < numBytes ? toFillBlock : numBytes);
      memcpy(ctx->block + ctx->bytesInBlock, bytes, addToCtx);
      ctx->bytesInBlock += addToCtx;
      bytes += addToCtx;
      numBytes -= addToCtx;
      if (ctx->bytesInBlock == (64)) {
 ctx->bytesInBlock = 0;
 md5ProcessBlock(ctx, ctx->block);
      }
    }
  }
  return 0;
}

variable_types:
bytes
unsigned char *

variable_types:
numBytes
unsigned long

variable_types:
toFillBlock
unsigned long

variable_types:
addToCtx
unsigned long


original_code:
void md5End(void *c, byte_t *digest)
{
  struct md5CTX *ctx = (struct md5CTX *)c;
  byte_t toAppend[(64)+8];
  uint64_t totalBits;
  size_t numToAppend;
  int i;
  totalBits = ctx->bytesProcessed * 8;
  if (ctx->bytesInBlock < 56)
    numToAppend = 56 - ctx->bytesInBlock;
  else
    numToAppend = (64) - (ctx->bytesInBlock - 56);
  toAppend[0] = (byte_t)(0x80);
  memset(toAppend+1, 0, numToAppend-1);
  putLittleEnd64(toAppend + numToAppend, totalBits);
  md5Add(ctx, toAppend, numToAppend + 8);
  for (i = 0; i < 4; i++)
    putLittleEnd32(digest + i*4, ctx->h[i]);
}

canonical_original_code:
void md5End(void *c, unsigned char *digest)
{
  struct md5CTX *ctx = (struct md5CTX *)c;
  unsigned char toAppend[-1];
  unsigned long totalBits;
  unsigned long numToAppend;
  int i;
  totalBits = ctx->bytesProcessed * 8;
  if (ctx->bytesInBlock < 56)
    numToAppend = 56 - ctx->bytesInBlock;
  else
    numToAppend = (64) - (ctx->bytesInBlock - 56);
  toAppend[0] = (byte_t)(0x80);
  memset(toAppend+1, 0, numToAppend-1);
  putLittleEnd64(toAppend + numToAppend, totalBits);
  md5Add(ctx, toAppend, numToAppend + 8);
  for (i = 0; i < 4; i++)
    putLittleEnd32(digest + i*4, ctx->h[i]);
}

variable_types:
digest
unsigned char *

variable_types:
toAppend
unsigned char [-1]

variable_types:
totalBits
unsigned long

variable_types:
numToAppend
unsigned long


decompiled_code:
__int64 __fastcall trim_whitespace(const char *a1)
{
char *v1; // r12
const char *v2; // rbx
__int64 v3; // r13
char *v4; // rbp
const unsigned __int16 *v5; // rax
__int64 result; // rax

v1 = (char *)a1;
v2 = a1 - 1;
v3 = (int)strlen(a1);
v4 = (char *)&a1[v3];
v5 = *_ctype_b_loc();
do
++v2;
while ( (v5[*v2] & 0x2000) != 0 );
do
--v4;
while ( (v5[*v4] & 0x2000) != 0 && v2 != v4 );
result = (__int64)&a1[v3 - 1];
if ( v4 != (char *)result )
{
v4[1] = 0;
goto LABEL_7;
}
if ( a1 == v2 || v2 != v4 )
{
LABEL_7:
if ( a1 == v2 )
return result;
goto LABEL_8;
}
*a1 = 0;
LABEL_8:
for ( result = *(unsigned __int8 *)v2; (_BYTE)result; result = *(unsigned __int8 *)v2 )
{
++v2;
*v1++ = result;
}
*v1 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char *v1; // r12
const char *v2; // rbx
__int64 v3; // r13
char *v4; // rbp
const unsigned __int16 *v5; // rax
__int64 result; // rax

v1 = (char *)a1;
v2 = a1 - 1;
v3 = (int)strlen(a1);
v4 = (char *)&a1[v3];
v5 = *_ctype_b_loc();
do
++v2;
while ( (v5[*v2] & 0x2000) != 0 );
do
--v4;
while ( (v5[*v4] & 0x2000) != 0 && v2 != v4 );
result = (__int64)&a1[v3 - 1];
if ( v4 != (char *)result )
{
v4[1] = 0;
goto LABEL_7;
}
if ( a1 == v2 || v2 != v4 )
{
LABEL_7:
if ( a1 == v2 )
return result;
goto LABEL_8;
}
*a1 = 0;
LABEL_8:
for ( result = *(unsigned __int8 *)v2; (_BYTE)result; result = *(unsigned __int8 *)v2 )
{
++v2;
*v1++ = result;
}
*v1 = 0;
return result;
}

original_code:
static void trim_whitespace (char *string)
{
  int length;
  char *head;
  char *tail;
  length = strlen (string);
  head = string - 1;
  tail = string + length;
  while (((*__ctype_b_loc ())[(int) ((*(++head)))] & (unsigned short int) _ISspace));
  while (((*__ctype_b_loc ())[(int) ((*(--tail)))] & (unsigned short int) _ISspace) && (tail != head));
  if ((string + length - 1) != tail) {
    *(tail + 1) = '\0';
  } else if ((head != string) && (tail == head)) {
    *string = '\0';
  }
  tail = string;
  if (head != string) {
    while (*head) *tail++ = *head++;
    *tail = '\0';
  }
}

canonical_original_code:
static void trim_whitespace(char *string)
{
  int length;
  char *head;
  char *tail;
  length = strlen (string);
  head = string - 1;
  tail = string + length;
  while (((*__ctype_b_loc ())[(int) ((*(++head)))] & (unsigned short) _ISspace));
  while (((*__ctype_b_loc ())[(int) ((*(--tail)))] & (unsigned short) _ISspace) && (tail != head));
  if ((string + length - 1) != tail) {
    *(tail + 1) = '\0';
  } else if ((head != string) && (tail == head)) {
    *string = '\0';
  }
  tail = string;
  if (head != string) {
    while (*head) *tail++ = *head++;
    *tail = '\0';
  }
}

variable_types:
string
char *

variable_types: length int

variable_types:
head
char *

variable_types:
tail
char *


decompiled_code:
__int64 __fastcall get_arg_count(const char *a1)
{
size_t v1; // rbp
int v2; // ebx
unsigned int v3; // er13
const unsigned __int16 **v4; // rax
const unsigned __int16 *v5; // rsi
size_t v6; // rdx
unsigned __int8 v7; // al
bool v8; // cl

v1 = strlen(a1);
v2 = 0;
v3 = 0;
while ( v2 < v1 )
{
v4 = _ctype_b_loc();
v5 = *v4;
if ( ((*v4)[a1[v2]] & 0x2000) == 0 )
{
v6 = v2 + 1;
do
{
v2 = v6;
v7 = (v5[a1[v6]] >> 13) ^ 1;
v8 = v1 > v6++;
}
while ( (v7 & v8) != 0 );
++v3;
}
++v2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
size_t v1; // rbp
int v2; // ebx
unsigned int v3; // er13
const unsigned __int16 **v4; // rax
const unsigned __int16 *v5; // rsi
size_t v6; // rdx
unsigned __int8 v7; // al
bool v8; // cl

v1 = strlen(a1);
v2 = 0;
v3 = 0;
while ( v2 < v1 )
{
v4 = _ctype_b_loc();
v5 = *v4;
if ( ((*v4)[a1[v2]] & 0x2000) == 0 )
{
v6 = v2 + 1;
do
{
v2 = v6;
v7 = (v5[a1[v6]] >> 13) ^ 1;
v8 = v1 > v6++;
}
while ( (v7 & v8) != 0 );
++v3;
}
++v2;
}
return v3;
}

original_code:
int get_arg_count (const char *cmdString)
{
  int argCount = 0;
  for (int i = 0; i < strlen (cmdString); i++) {
    if (!((*__ctype_b_loc ())[(int) ((cmdString[i]))] & (unsigned short int) _ISspace)) {
      while (!((*__ctype_b_loc ())[(int) ((cmdString[i]))] & (unsigned short int) _ISspace) && (i < strlen (cmdString))) {
 i++;
      }
      argCount++;
    }
  }
  return argCount;
}

canonical_original_code:
int get_arg_count(char *cmdString)
{
  int argCount = 0;
  for (int i = 0; i < strlen (cmdString); i++) {
    if (!((*__ctype_b_loc ())[(int) ((cmdString[i]))] & (unsigned short) _ISspace)) {
      while (!((*__ctype_b_loc ())[(int) ((cmdString[i]))] & (unsigned short) _ISspace) && (i < strlen (cmdString))) {
 i++;
      }
      argCount++;
    }
  }
  return argCount;
}

variable_types:
cmdString
char *

variable_types: argCount int


decompiled_code:
size_t __fastcall convert_to_upper(char *s)
{
unsigned __int64 i; // rbx
size_t result; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
s[i] = (*_ctype_toupper_loc())[s[i]];
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(char *s)
{
unsigned __int64 i; // rbx
size_t result; // rax

for ( i = 0LL; ; ++i )
{
result = strlen(s);
if ( result <= i )
break;
s[i] = (*_ctype_toupper_loc())[s[i]];
}
return result;
}

original_code:
void convert_to_upper (char *string)
{
  int i;
  for (i = 0; i < strlen (string); i++) {
    string[i] = toupper (string[i]);
  }
}

canonical_original_code:
void convert_to_upper(char *string)
{
  int i;
  for (i = 0; i < strlen (string); i++) {
    string[i] = toupper (string[i]);
  }
}


decompiled_code:
const char *__fastcall separate_cmd_from_args(const char **a1, int a2)
{
const char *v2; // rbx
const unsigned __int16 *v3; // rcx
const char *v4; // rdx

trim_whitespace(*a1);
if ( a2 == 1 )
{
convert_to_upper((char *)*a1);
v2 = 0LL;
}
else
{
v2 = *a1;
v3 = *_ctype_b_loc();
do
v4 = v2++;
while ( (v3[*(v2 - 1)] & 0x2000) == 0 );
*v4 = 0;
convert_to_upper((char *)*a1);
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func3(const char **a1, int a2)
{
const char *v2; // rbx
const unsigned __int16 *v3; // rcx
const char *v4; // rdx

func0(*a1);
if ( a2 == 1 )
{
func2((char *)*a1);
v2 = 0LL;
}
else
{
v2 = *a1;
v3 = *_ctype_b_loc();
do
v4 = v2++;
while ( (v3[*(v2 - 1)] & 0x2000) == 0 );
*v4 = 0;
func2((char *)*a1);
}
return v2;
}

original_code:
char *separate_cmd_from_args (char **cmdLineStr, int numArgs)
{
  char *args;
  trim_whitespace (*cmdLineStr);
  if (numArgs == 1) {
    convert_to_upper (*cmdLineStr);
    return ((void *)0);
  }
  args = *cmdLineStr;
  while (!((*__ctype_b_loc ())[(int) ((*(args++)))] & (unsigned short int) _ISspace));
  *(args - 1) = '\0';
  convert_to_upper (*cmdLineStr);
  return args;
}

canonical_original_code:
char *separate_cmd_from_args(char **cmdLineStr, int numArgs)
{
  char *args;
  trim_whitespace (*cmdLineStr);
  if (numArgs == 1) {
    convert_to_upper (*cmdLineStr);
    return ((void *)0);
  }
  args = *cmdLineStr;
  while (!((*__ctype_b_loc ())[(int) ((*(args++)))] & (unsigned short) _ISspace));
  *(args - 1) = '\0';
  convert_to_upper (*cmdLineStr);
  return args;
}

variable_types:
cmdLineStr
char **

variable_types: numArgs int

variable_types:
args
char *

return_type: char *


decompiled_code:
__int64 __fastcall command_switch(int *a1)
{
int v2; // eax
unsigned int v3; // er14
unsigned int v4; // ebp
__int64 v5; // r12
char *v6; // r13
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
char *v12; // rsi
bool v14; // al
bool v15; // cf
bool v16; // zf
const char *v17; // rdi
__int64 v18; // rcx
char *v19; // rsi
bool v20; // al
bool v21; // cf
bool v22; // zf
const char *v23; // rdi
__int64 v24; // rcx
char *v25; // rsi
char v26; // al
bool v27; // cf
bool v28; // zf
const char *v29; // rdi
__int64 v30; // rcx
char *v31; // rsi
char *s1; // [rsp+8h] [rbp-30h] BYREF

s1 = (char *)(a1 + 1043);
v2 = get_arg_count();
v3 = *a1;
if ( v2 <= 0 )
{
log_received_cmd(a1 + 1026, 0LL, 0LL, 0LL);
send_mesg_500(v3);
*((_BYTE *)a1 + 4169) = 1;
}
else
{
v4 = v2;
v5 = separate_cmd_from_args(&s1, (unsigned int)v2);
v6 = s1;
log_received_cmd(a1 + 1026, s1, v5, v4);
if ( !strcmp(v6, "APPE") )
{
cmd_appe(a1, v5);
}
else if ( !strcmp(v6, "CDUP") )
{
cmd_cdup(a1, v5);
}
else
{
v7 = strcmp(v6, "CWD") != 0;
v8 = 0;
v9 = !v7;
if ( v7 )
{
v10 = "HELP";
v11 = 5LL;
v12 = v6;
do
{
if ( !v11 )
break;
v8 = (unsigned __int8)*v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
if ( v5 )
convert_to_upper(v5, v12);
cmd_help(a1, v5);
}
else if ( !strcmp(v6, "LIST") )
{
cmd_list_nlst(a1, v5, 1LL);
}
else if ( !strcmp(v6, "MKD") )
{
cmd_mkd(a1, v5);
}
else if ( !strcmp(v6, "MODE") )
{
cmd_mode(a1, v5);
}
else if ( !strcmp(v6, "NLST") )
{
cmd_list_nlst(a1, v5, 0LL);
}
else
{
v14 = strcmp(v6, "PASS") != 0;
v15 = 0;
v16 = !v14;
if ( v14 )
{
v17 = "PASV";
v18 = 5LL;
v19 = v6;
do
{
if ( !v18 )
break;
v15 = (unsigned __int8)*v19 < (unsigned int)*v17;
v16 = *v19++ == *v17++;
--v18;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
{
cmd_pasv(a1, v19);
}
else
{
v20 = strcmp(v6, "PORT") != 0;
v21 = 0;
v22 = !v20;
if ( v20 )
{
v23 = "PWD";
v24 = 4LL;
v25 = v6;
do
{
if ( !v24 )
break;
v21 = (unsigned __int8)*v25 < (unsigned int)*v23;
v22 = *v25++ == *v23++;
--v24;
}
while ( v22 );
v26 = (!v21 && !v22) - v21;
v27 = 0;
v28 = v26 == 0;
if ( v26 )
{
v29 = "QUIT";
v30 = 5LL;
v31 = v6;
do
{
if ( !v30 )
break;
v27 = (unsigned __int8)*v31 < (unsigned int)*v29;
v28 = *v31++ == *v29++;
--v30;
}
while ( v28 );
if ( (!v27 && !v28) == v27 )
{
cmd_quit(a1, v31);
}
else if ( !strcmp(v6, "RETR") )
{
cmd_retr(a1, v5);
}
else if ( !strcmp(v6, "STOR") )
{
cmd_stor(a1, v5);
}
else if ( !strcmp(v6, "STOU") )
{
cmd_stou(a1, v5);
}
else if ( !strcmp(v6, "STRU") )
{
cmd_stru(a1, v5, v4);
}
else if ( !strcmp(v6, "SYST") )
{
cmd_syst(a1);
}
else if ( !strcmp(v6, "TYPE") )
{
cmd_type(a1, v5);
}
else if ( !strcmp(v6, "USER") )
{
cmd_user(a1, v5);
}
else if ( !strcmp(v6, "ABOR")
|| !strcmp(v6, "ACCT")
|| !strcmp(v6, "ALLO")
|| !strcmp(v6, "DELE")
|| !strcmp(v6, "NOOP")
|| !strcmp(v6, "REIN")
|| !strcmp(v6, "REST")
|| !strcmp(v6, "RMD")
|| !strcmp(v6, "RNFR")
|| !strcmp(v6, "RNTO")
|| !strcmp(v6, "SITE")
|| !strcmp(v6, "SMNT")
|| !strcmp(v6, "STAT") )
{
send_mesg_504(v3);
}
else
{
send_mesg_500(v3);
}
}
else
{
cmd_pwd(a1, v25);
}
}
else
{
cmd_port(a1, v5);
}
}
}
else
{
cmd_pass(a1, v5);
}
}
}
else
{
cmd_cwd(a1, v5);
}
}
*((_BYTE *)a1 + 4169) = 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v2; // eax
unsigned int v3; // er14
unsigned int v4; // ebp
__int64 v5; // r12
char *v6; // r13
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
char *v12; // rsi
bool v14; // al
bool v15; // cf
bool v16; // zf
const char *v17; // rdi
__int64 v18; // rcx
char *v19; // rsi
bool v20; // al
bool v21; // cf
bool v22; // zf
const char *v23; // rdi
__int64 v24; // rcx
char *v25; // rsi
char v26; // al
bool v27; // cf
bool v28; // zf
const char *v29; // rdi
__int64 v30; // rcx
char *v31; // rsi
char *s1; // [rsp+8h] [rbp-30h] BYREF

s1 = (char *)(a1 + 1043);
v2 = get_arg_count();
v3 = *a1;
if ( v2 <= 0 )
{
log_received_cmd(a1 + 1026, 0LL, 0LL, 0LL);
send_mesg_500(v3);
*((_BYTE *)a1 + 4169) = 1;
}
else
{
v4 = v2;
v5 = separate_cmd_from_args(&s1, (unsigned int)v2);
v6 = s1;
log_received_cmd(a1 + 1026, s1, v5, v4);
if ( !strcmp(v6, "APPE") )
{
cmd_appe(a1, v5);
}
else if ( !strcmp(v6, "CDUP") )
{
cmd_cdup(a1, v5);
}
else
{
v7 = strcmp(v6, "CWD") != 0;
v8 = 0;
v9 = !v7;
if ( v7 )
{
v10 = "HELP";
v11 = 5LL;
v12 = v6;
do
{
if ( !v11 )
break;
v8 = (unsigned __int8)*v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
if ( v5 )
convert_to_upper(v5, v12);
cmd_help(a1, v5);
}
else if ( !strcmp(v6, "LIST") )
{
cmd_list_nlst(a1, v5, 1LL);
}
else if ( !strcmp(v6, "MKD") )
{
cmd_mkd(a1, v5);
}
else if ( !strcmp(v6, "MODE") )
{
cmd_mode(a1, v5);
}
else if ( !strcmp(v6, "NLST") )
{
cmd_list_nlst(a1, v5, 0LL);
}
else
{
v14 = strcmp(v6, "PASS") != 0;
v15 = 0;
v16 = !v14;
if ( v14 )
{
v17 = "PASV";
v18 = 5LL;
v19 = v6;
do
{
if ( !v18 )
break;
v15 = (unsigned __int8)*v19 < (unsigned int)*v17;
v16 = *v19++ == *v17++;
--v18;
}
while ( v16 );
if ( (!v15 && !v16) == v15 )
{
cmd_pasv(a1, v19);
}
else
{
v20 = strcmp(v6, "PORT") != 0;
v21 = 0;
v22 = !v20;
if ( v20 )
{
v23 = "PWD";
v24 = 4LL;
v25 = v6;
do
{
if ( !v24 )
break;
v21 = (unsigned __int8)*v25 < (unsigned int)*v23;
v22 = *v25++ == *v23++;
--v24;
}
while ( v22 );
v26 = (!v21 && !v22) - v21;
v27 = 0;
v28 = v26 == 0;
if ( v26 )
{
v29 = "QUIT";
v30 = 5LL;
v31 = v6;
do
{
if ( !v30 )
break;
v27 = (unsigned __int8)*v31 < (unsigned int)*v29;
v28 = *v31++ == *v29++;
--v30;
}
while ( v28 );
if ( (!v27 && !v28) == v27 )
{
cmd_quit(a1, v31);
}
else if ( !strcmp(v6, "RETR") )
{
cmd_retr(a1, v5);
}
else if ( !strcmp(v6, "STOR") )
{
cmd_stor(a1, v5);
}
else if ( !strcmp(v6, "STOU") )
{
cmd_stou(a1, v5);
}
else if ( !strcmp(v6, "STRU") )
{
cmd_stru(a1, v5, v4);
}
else if ( !strcmp(v6, "SYST") )
{
cmd_syst(a1);
}
else if ( !strcmp(v6, "TYPE") )
{
cmd_type(a1, v5);
}
else if ( !strcmp(v6, "USER") )
{
cmd_user(a1, v5);
}
else if ( !strcmp(v6, "ABOR")
|| !strcmp(v6, "ACCT")
|| !strcmp(v6, "ALLO")
|| !strcmp(v6, "DELE")
|| !strcmp(v6, "NOOP")
|| !strcmp(v6, "REIN")
|| !strcmp(v6, "REST")
|| !strcmp(v6, "RMD")
|| !strcmp(v6, "RNFR")
|| !strcmp(v6, "RNTO")
|| !strcmp(v6, "SITE")
|| !strcmp(v6, "SMNT")
|| !strcmp(v6, "STAT") )
{
send_mesg_504(v3);
}
else
{
send_mesg_500(v3);
}
}
else
{
cmd_pwd(a1, v25);
}
}
else
{
cmd_port(a1, v5);
}
}
}
else
{
cmd_pass(a1, v5);
}
}
}
else
{
cmd_cwd(a1, v5);
}
}
*((_BYTE *)a1 + 4169) = 1;
}
return 0LL;
}

original_code:
void *command_switch (void *param) {
  session_info_t *si;
  char *cmdLine;
  char *cmd;
  char *arg;
  int numArgs;
  int csfd;
  si = (session_info_t *)param;
  cmdLine = si->cmdString;
  numArgs = get_arg_count (cmdLine);
  csfd = si->csfd;
  if (numArgs < 1) {
    log_received_cmd (si->user, ((void *)0), ((void *)0), 0);
    send_mesg_500 (csfd);
    si->cmdComplete = 1;
    return ((void *)0);
  }
  arg = separate_cmd_from_args (&cmdLine, numArgs);
  cmd = cmdLine;
  log_received_cmd (si->user, cmd, arg, numArgs);
  if (strcmp (cmd, "APPE") == 0) {
    cmd_appe (si, arg);
  } else if (strcmp (cmd, "CDUP") == 0) {
    cmd_cdup (si, arg);
  } else if (strcmp (cmd, "CWD") == 0) {
    cmd_cwd (si, arg);
  } else if (strcmp (cmd, "HELP") == 0) {
    if (arg != ((void *)0))
      convert_to_upper (arg);
    cmd_help (si, arg);
  } else if (strcmp (cmd, "LIST") == 0) {
    cmd_list_nlst (si, arg, 1);
  } else if (strcmp (cmd, "MKD") == 0) {
    cmd_mkd (si, arg);
  } else if (strcmp (cmd, "MODE") == 0) {
    cmd_mode (si, arg);
  } else if (strcmp (cmd, "NLST") == 0) {
    cmd_list_nlst (si, arg, 0);
  } else if (strcmp (cmd, "PASS") == 0) {
    cmd_pass (si, arg);
  } else if (strcmp (cmd, "PASV") == 0) {
    cmd_pasv (si);
  } else if (strcmp (cmd, "PORT") == 0) {
    cmd_port (si, arg);
  } else if (strcmp (cmd, "PWD") == 0) {
    cmd_pwd (si);
  } else if (strcmp (cmd, "QUIT") == 0) {
    cmd_quit (si);
  } else if (strcmp (cmd, "RETR") == 0) {
    cmd_retr (si, arg);
  } else if (strcmp (cmd, "STOR") == 0) {
    cmd_stor (si, arg);
  } else if (strcmp (cmd, "STOU") == 0) {
    cmd_stou (si, arg);
  } else if (strcmp (cmd, "STRU") == 0) {
    cmd_stru (si, arg, numArgs);
  } else if (strcmp (cmd, "SYST") == 0) {
    cmd_syst (si);
  } else if (strcmp (cmd, "TYPE") == 0) {
    cmd_type (si, arg);
  } else if (strcmp (cmd, "USER") == 0) {
    cmd_user (si, arg);
  } else if (strcmp (cmd, "ABOR") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "ACCT") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "ALLO") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "DELE") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "NOOP") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "REIN") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "REST") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "RMD") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "RNFR") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "RNTO") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "SITE") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "SMNT") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "STAT") == 0) {
    send_mesg_504 (csfd);
  } else {
    send_mesg_500 (csfd);
  }
  si->cmdComplete = 1;
  return ((void *)0);
}

canonical_original_code:
void *command_switch(void *param) {
  struct session_info_t *si;
  char *cmdLine;
  char *cmd;
  char *arg;
  int numArgs;
  int csfd;
  si = (struct session_info_t *)param;
  cmdLine = si->cmdString;
  numArgs = get_arg_count (cmdLine);
  csfd = si->csfd;
  if (numArgs < 1) {
    log_received_cmd (si->user, ((void *)0), ((void *)0), 0);
    send_mesg_500 (csfd);
    si->cmdComplete = 1;
    return ((void *)0);
  }
  arg = separate_cmd_from_args (&cmdLine, numArgs);
  cmd = cmdLine;
  log_received_cmd (si->user, cmd, arg, numArgs);
  if (strcmp (cmd, "APPE") == 0) {
    cmd_appe (si, arg);
  } else if (strcmp (cmd, "CDUP") == 0) {
    cmd_cdup (si, arg);
  } else if (strcmp (cmd, "CWD") == 0) {
    cmd_cwd (si, arg);
  } else if (strcmp (cmd, "HELP") == 0) {
    if (arg != ((void *)0))
      convert_to_upper (arg);
    cmd_help (si, arg);
  } else if (strcmp (cmd, "LIST") == 0) {
    cmd_list_nlst (si, arg, 1);
  } else if (strcmp (cmd, "MKD") == 0) {
    cmd_mkd (si, arg);
  } else if (strcmp (cmd, "MODE") == 0) {
    cmd_mode (si, arg);
  } else if (strcmp (cmd, "NLST") == 0) {
    cmd_list_nlst (si, arg, 0);
  } else if (strcmp (cmd, "PASS") == 0) {
    cmd_pass (si, arg);
  } else if (strcmp (cmd, "PASV") == 0) {
    cmd_pasv (si);
  } else if (strcmp (cmd, "PORT") == 0) {
    cmd_port (si, arg);
  } else if (strcmp (cmd, "PWD") == 0) {
    cmd_pwd (si);
  } else if (strcmp (cmd, "QUIT") == 0) {
    cmd_quit (si);
  } else if (strcmp (cmd, "RETR") == 0) {
    cmd_retr (si, arg);
  } else if (strcmp (cmd, "STOR") == 0) {
    cmd_stor (si, arg);
  } else if (strcmp (cmd, "STOU") == 0) {
    cmd_stou (si, arg);
  } else if (strcmp (cmd, "STRU") == 0) {
    cmd_stru (si, arg, numArgs);
  } else if (strcmp (cmd, "SYST") == 0) {
    cmd_syst (si);
  } else if (strcmp (cmd, "TYPE") == 0) {
    cmd_type (si, arg);
  } else if (strcmp (cmd, "USER") == 0) {
    cmd_user (si, arg);
  } else if (strcmp (cmd, "ABOR") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "ACCT") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "ALLO") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "DELE") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "NOOP") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "REIN") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "REST") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "RMD") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "RNFR") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "RNTO") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "SITE") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "SMNT") == 0) {
    send_mesg_504 (csfd);
  } else if (strcmp (cmd, "STAT") == 0) {
    send_mesg_504 (csfd);
  } else {
    send_mesg_500 (csfd);
  }
  si->cmdComplete = 1;
  return ((void *)0);
}

variable_types:
param
void *

variable_types: struct session_info_t { int csfd; int dsfd; char cwd[4096]; char user[64]; _Bool loggedin; _Bool cmdComplete; _Bool cmdAbort; _Bool cmdQuit; char cmdString[4096]; char type; } *

variable_types:
cmdLine
char *

variable_types:
cmd
char *

variable_types:
arg
char *

variable_types: csfd int


dirExists

decompiled_code:
__int64 __fastcall dirExists(const char *a1)
{
int v1; // edx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // edx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

original_code:
static int dirExists(const char *path)
{
    struct stat info;
    if (stat(path, &info) !=0)
        return 0;
    else if(info.st_mode & 0040000)
        return 1;
    else
        return 0;
}

canonical_original_code:
static int dirExists(char *path)
{
    struct stat info;
    if (stat(path, &info) !=0)
        return 0;
    else if(info.st_mode & 0040000)
        return 1;
    else
        return 0;
}

variable_types:
path
char *

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]; }


fromKeboard

decompiled_code:
__int64 __fastcall fromKeboard(__int64 a1, __int64 a2)
{
printf("Enter your Internode Username: ");
_isoc99_scanf("%s", a1);
printf("Enter your Inetrnode Password: ");
return _isoc99_scanf("%s", a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
printf("Enter your Internode Username: ");
_isoc99_scanf("%s", a1);
printf("Enter your Inetrnode Password: ");
return _isoc99_scanf("%s", a2);
}

original_code:
static void fromKeboard(char *uname, char *secret)
{
    printf("Enter your Internode Username: ");
    scanf("%s", uname);
    printf("Enter your Inetrnode Password: ");
    scanf("%s", secret);
}

variable_types:
uname
char *

variable_types:
secret
char *


pathFunc

decompiled_code:
char *pathFunc()
{
char *v0; // rbx
char *v1; // rax

v0 = (char *)malloc(0x100uLL);
v1 = getenv("HOME");
strcpy(v0, v1);
strcpy(v0 + 64, v0);
strcpy(v0 + 128, v0);
strcpy(v0 + 192, v0);
strcat(v0, "/.gisps.d/");
strcat(v0 + 64, "/.gisps.d/");
strcat(v0 + 128, "/.gisps.d/");
strcat(v0 + 192, "/.gisps.d/");
if ( !(unsigned int)dirExists(v0) && mkdir(v0, 0x1F0u) == -1 )
{
fprintf(stderr, "Could not create %s\n", v0);
free(v0);
v0 = 0LL;
}
else
{
strcat(v0, "gisps.conf");
strcat(v0 + 64, "nodeservice.xml");
strcat(v0 + 128, "nodeusage.xml");
strcat(v0 + 192, "nodehistory.xml");
}
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx
char *v1; // rax

v0 = (char *)malloc(0x100uLL);
v1 = getenv("HOME");
strcpy(v0, v1);
strcpy(v0 + 64, v0);
strcpy(v0 + 128, v0);
strcpy(v0 + 192, v0);
strcat(v0, "/.gisps.d/");
strcat(v0 + 64, "/.gisps.d/");
strcat(v0 + 128, "/.gisps.d/");
strcat(v0 + 192, "/.gisps.d/");
if ( !(unsigned int)func0(v0) && mkdir(v0, 0x1F0u) == -1 )
{
fprintf(stderr, "Could not create %s\n", v0);
free(v0);
v0 = 0LL;
}
else
{
strcat(v0, "gisps.conf");
strcat(v0 + 64, "nodeservice.xml");
strcat(v0 + 128, "nodeusage.xml");
strcat(v0 + 192, "nodehistory.xml");
}
return v0;
}

original_code:
confPaths *pathFunc()
{
    confPaths *path = malloc(sizeof(confPaths));
    if (!strcpy(path->conf, getenv("HOME")))
    {
        struct passwd* pwd = getpwuid(getuid());
        if (pwd){
            strcpy(path->conf, pwd->pw_dir);
        }
        else {
            free(path);
            return ((void *)0);
        }
    }
    strcpy(path->basexml, path->conf);
    strcpy(path->usagexml, path->conf);
    strcpy(path->historyxml, path->conf);
    strcat(path->conf, "/.gisps.d/");
    strcat(path->basexml, "/.gisps.d/");
    strcat(path->usagexml, "/.gisps.d/");
    strcat(path->historyxml, "/.gisps.d/");
    if(!dirExists(path->conf))
    {
        if (mkdir(path->conf,0760) == -1)
        {
            fprintf(stderr, "Could not create %s\n" ,path->conf);
            free(path);
            return ((void *)0);
        }
    }
    strcat(path->conf, "gisps.conf");
    strcat(path->basexml, "nodeservice.xml");
    strcat(path->usagexml, "nodeusage.xml");
    strcat(path->historyxml, "nodehistory.xml");
    return path;
}

canonical_original_code:
struct confPaths *pathFunc()
{
    struct confPaths *path = malloc(sizeof(confPaths));
    if (!strcpy(path->conf, getenv("HOME")))
    {
        struct passwd *pwd = getpwuid(getuid());
        if (pwd){
            strcpy(path->conf, pwd->pw_dir);
        }
        else {
            free(path);
            return ((void *)0);
        }
    }
    strcpy(path->basexml, path->conf);
    strcpy(path->usagexml, path->conf);
    strcpy(path->historyxml, path->conf);
    strcat(path->conf, "/.gisps.d/");
    strcat(path->basexml, "/.gisps.d/");
    strcat(path->usagexml, "/.gisps.d/");
    strcat(path->historyxml, "/.gisps.d/");
    if(!dirExists(path->conf))
    {
        if (mkdir(path->conf,0760) == -1)
        {
            fprintf(stderr, "Could not create %s\n" ,path->conf);
            free(path);
            return ((void *)0);
        }
    }
    strcat(path->conf, "gisps.conf");
    strcat(path->basexml, "nodeservice.xml");
    strcat(path->usagexml, "nodeusage.xml");
    strcat(path->historyxml, "nodehistory.xml");
    return path;
}

variable_types: struct confPaths { char conf[64]; char basexml[64]; char usagexml[64]; char historyxml[64]; } *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
double v4; // xmm0_8
const char *v5; // rbp
const char *v6; // rax
double v7; // r12
const char *v8; // rax
double v9; // rbx

internodeInit(0LL, 0LL, "31");
v3 = pathFunc();
v4 = get_usage(v3 + 192, "traffic", "total");
printf("total Usage for last %s days %0.2f GB\n", "31", v4 / 1000.0);
v3 += 128LL;
v5 = (const char *)get_attrib_val(v3, "traffic", "rollover");
v6 = (const char *)get_attrib_val(v3, "traffic", "quota");
v7 = atof(v6);
v8 = (const char *)get_element_content(v3, "traffic");
v9 = atof(v8);
printf("Monthly Quota: %0.2lf GB\n", v7 / 1000000.0 / 1000.0);
printf("This month usage: %0.2lf GB\n", v9 / 1000000.0 / 1000.0);
printf("Rollover Date: %s\n", v5);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
    char *days = "31";
    internodeInit(((void *)0) , ((void *)0), days);
    confPaths *xmlfiles = pathFunc();
    double totalusage = get_usage(xmlfiles->historyxml, "traffic", "total");
    printf("total Usage for last %s days %0.2f GB\n",days, totalusage/1000);
    char *rollover = get_attrib_val(xmlfiles->usagexml, "traffic", "rollover");
    double quota = atof((char *)
                        get_attrib_val(xmlfiles->usagexml, "traffic", "quota"));
    double current_usage = atof((char *)
                                get_element_content(xmlfiles->usagexml, "traffic"));
    printf("Monthly Quota: %0.2lf GB\n" ,quota/1000000/1000);
    printf("This month usage: %0.2lf GB\n" ,current_usage/1000000/1000);
    printf("Rollover Date: %s\n" ,rollover);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *days = "31";
    internodeInit(((void *)0) , ((void *)0), days);
    struct confPaths *xmlfiles = pathFunc();
    double totalusage = get_usage(xmlfiles->historyxml, "traffic", "total");
    printf("total Usage for last %s days %0.2f GB\n",days, totalusage/1000);
    char *rollover = get_attrib_val(xmlfiles->usagexml, "traffic", "rollover");
    double quota = atof((char *)
                        get_attrib_val(xmlfiles->usagexml, "traffic", "quota"));
    double current_usage = atof((char *)
                                get_element_content(xmlfiles->usagexml, "traffic"));
    printf("Monthly Quota: %0.2lf GB\n" ,quota/1000000/1000);
    printf("This month usage: %0.2lf GB\n" ,current_usage/1000000/1000);
    printf("Rollover Date: %s\n" ,rollover);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
days
char *

variable_types: totalusage double

variable_types:
rollover
char *

variable_types: quota double

user_defined_types: struct confPaths { char conf[64]; char basexml[64]; char usagexml[64]; char historyxml[64]; }


internodeInit

original_code:
void
internodeInit(char *start_date, char *stop_date, char *days_count)
{
    char baseurl[80] = "https://customer-webtools-api.internode.on.net/api/v1.5/";
    char usage_opts[128] = "verbose=1";
    if (start_date != ((void *)0))
    {
        strcat(usage_opts,"&start=");
        strcat(usage_opts,start_date);
    }
    if (stop_date != ((void *)0))
    {
 strcat(usage_opts,"&stop=");
 strcat(usage_opts,stop_date);
    }
    if (days_count != ((void *)0))
    {
 strcat(usage_opts,"&count=");
 strcat(usage_opts,days_count);
    }
    confPaths *xmlfiles = pathFunc();
    getNodeXml(baseurl, xmlfiles->basexml, ((void *)0));
    char *service_id = get_element_content(xmlfiles->basexml, "service");
    strcat(baseurl, service_id);
    char *history = (char*)malloc(sizeof(char) * 128);
    strcpy(history, baseurl);
    strcat(history,"/history/");
    char *usage = (char*)malloc(sizeof(char) * 128);
    strcpy(usage, baseurl);
    strcat(usage,"/usage/");
    getNodeXml(usage, xmlfiles->usagexml, "verbose=1");
    getNodeXml(history, xmlfiles->historyxml, usage_opts);
    free(service_id);
    free(usage);
    free(history);
    free(xmlfiles);
}

canonical_original_code:
void internodeInit(char *start_date, char *stop_date, char *days_count)
{
    char baseurl[80] = "https://customer-webtools-api.internode.on.net/api/v1.5/";
    char usage_opts[128] = "verbose=1";
    if (start_date != ((void *)0))
    {
        strcat(usage_opts,"&start=");
        strcat(usage_opts,start_date);
    }
    if (stop_date != ((void *)0))
    {
 strcat(usage_opts,"&stop=");
 strcat(usage_opts,stop_date);
    }
    if (days_count != ((void *)0))
    {
 strcat(usage_opts,"&count=");
 strcat(usage_opts,days_count);
    }
    struct confPaths *xmlfiles = pathFunc();
    getNodeXml(baseurl, xmlfiles->basexml, ((void *)0));
    char *service_id = get_element_content(xmlfiles->basexml, "service");
    strcat(baseurl, service_id);
    char *history = (char*)malloc(sizeof(char) * 128);
    strcpy(history, baseurl);
    strcat(history,"/history/");
    char *usage = (char*)malloc(sizeof(char) * 128);
    strcpy(usage, baseurl);
    strcat(usage,"/usage/");
    getNodeXml(usage, xmlfiles->usagexml, "verbose=1");
    getNodeXml(history, xmlfiles->historyxml, usage_opts);
    free(service_id);
    free(usage);
    free(history);
    free(xmlfiles);
}

variable_types:
baseurl
char [80]

variable_types:
history
char *

variable_types:
usage
char *


repo: mykmo/tcpproxy

decompiled_code:
__int64 __fastcall bavail_read(__int64 a1)
{
return *(_QWORD *)a1 + *(int *)(a1 + 24) - *(_QWORD *)(a1 + 16);
}

original_code:
static inline int bavail_read(struct buffer *b)
{
 return b->addr + b->size - b->end;
}

variable_types: struct buffer { char *addr; char *begin; char *end; int size; } *


binit

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

result = xmalloc(a2);
*(_QWORD *)(a1 + 16) = result;
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 24) = a2;
return result;
}

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

result = xmalloc(a2);
*(_QWORD *)(a1 + 16) = result;
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)a1 = result;
*(_DWORD *)(a1 + 24) = a2;
return result;
}

original_code:
void binit(struct buffer *b, size_t size)
{
 char *p;
 p = (char *) xmalloc(size);
 b->addr = b->begin = b->end = p;
 b->size = size;
}

canonical_original_code:
void binit(struct buffer *b, unsigned long size)
{
 char *p;
 p = (char *) xmalloc(size);
 b->addr = b->begin = b->end = p;
 b->size = size;
}

variable_types:
size
unsigned long

variable_types:
p
char *

user_defined_types: struct buffer { char *addr; char *begin; char *end; int size; }


bfree

original_code:
void bfree(struct buffer *b)
{
 if (b->addr != ((void *)0)) {
  free(b->addr);
  b->addr = b->begin = b->end = ((void *)0);
  b->size = 0;
 }
}