decompiled_code:
__int64 __fastcall command_switch(int *a1)
{
int v2; // eax
unsigned int v3; // er14
unsigned int v4; // er12
__int64 v5; // rax
char *v6; // r13
__int64 v7; // rbp
bool v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
char *v13; // rsi
bool v15; // al
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
char *v20; // rsi
bool v21; // al
bool v22; // cf
bool v23; // zf
const char *v24; // rdi
__int64 v25; // rcx
char *v26; // rsi
char v27; // al
bool v28; // cf
bool v29; // zf
const char *v30; // rdi
__int64 v31; // rcx
char *v32; // rsi
char *s1; // [rsp+8h] [rbp-40h] 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;
v7 = v5;
log_received_cmd(a1 + 1026, s1, v5, v4);
if ( !strcmp(v6, "APPE") )
{
cmd_appe(a1, v7);
}
else if ( !strcmp(v6, "CDUP") )
{
cmd_cdup(a1, v7);
}
else
{
v8 = strcmp(v6, "CWD") != 0;
v9 = 0;
v10 = !v8;
if ( v8 )
{
v11 = "HELP";
v12 = 5LL;
v13 = v6;
do
{
if ( !v12 )
break;
v9 = (unsigned __int8)*v13 < (unsigned int)*v11;
v10 = *v13++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
{
if ( v7 )
convert_to_upper(v7, v13);
cmd_help(a1, v7);
}
else if ( !strcmp(v6, "LIST") )
{
cmd_list_nlst(a1, v7, 1LL);
}
else if ( !strcmp(v6, "MKD") )
{
cmd_mkd(a1, v7);
}
else if ( !strcmp(v6, "MODE") )
{
cmd_mode(a1, v7);
}
else if ( !strcmp(v6, "NLST") )
{
cmd_list_nlst(a1, v7, 0LL);
}
else
{
v15 = strcmp(v6, "PASS") != 0;
v16 = 0;
v17 = !v15;
if ( v15 )
{
v18 = "PASV";
v19 = 5LL;
v20 = v6;
do
{
if ( !v19 )
break;
v16 = (unsigned __int8)*v20 < (unsigned int)*v18;
v17 = *v20++ == *v18++;
--v19;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
{
cmd_pasv(a1, v20);
}
else
{
v21 = strcmp(v6, "PORT") != 0;
v22 = 0;
v23 = !v21;
if ( v21 )
{
v24 = "PWD";
v25 = 4LL;
v26 = v6;
do
{
if ( !v25 )
break;
v22 = (unsigned __int8)*v26 < (unsigned int)*v24;
v23 = *v26++ == *v24++;
--v25;
}
while ( v23 );
v27 = (!v22 && !v23) - v22;
v28 = 0;
v29 = v27 == 0;
if ( v27 )
{
v30 = "QUIT";
v31 = 5LL;
v32 = v6;
do
{
if ( !v31 )
break;
v28 = (unsigned __int8)*v32 < (unsigned int)*v30;
v29 = *v32++ == *v30++;
--v31;
}
while ( v29 );
if ( (!v28 && !v29) == v28 )
{
cmd_quit(a1, v32);
}
else if ( !strcmp(v6, "RETR") )
{
cmd_retr(a1, v7);
}
else if ( !strcmp(v6, "STOR") )
{
cmd_stor(a1, v7);
}
else if ( !strcmp(v6, "STOU") )
{
cmd_stou(a1, v7);
}
else if ( !strcmp(v6, "STRU") )
{
cmd_stru(a1, v7, v4);
}
else if ( !strcmp(v6, "SYST") )
{
cmd_syst(a1);
}
else if ( !strcmp(v6, "TYPE") )
{
cmd_type(a1, v7);
}
else if ( !strcmp(v6, "USER") )
{
cmd_user(a1, v7);
}
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, v26);
}
}
else
{
cmd_port(a1, v7);
}
}
}
else
{
cmd_pass(a1, v7);
}
}
}
else
{
cmd_cwd(a1, v7);
}
}
*((_BYTE *)a1 + 4169) = 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v2; // eax
unsigned int v3; // er14
unsigned int v4; // er12
__int64 v5; // rax
char *v6; // r13
__int64 v7; // rbp
bool v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
__int64 v12; // rcx
char *v13; // rsi
bool v15; // al
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
char *v20; // rsi
bool v21; // al
bool v22; // cf
bool v23; // zf
const char *v24; // rdi
__int64 v25; // rcx
char *v26; // rsi
char v27; // al
bool v28; // cf
bool v29; // zf
const char *v30; // rdi
__int64 v31; // rcx
char *v32; // rsi
char *s1; // [rsp+8h] [rbp-40h] 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;
v7 = v5;
log_received_cmd(a1 + 1026, s1, v5, v4);
if ( !strcmp(v6, "APPE") )
{
cmd_appe(a1, v7);
}
else if ( !strcmp(v6, "CDUP") )
{
cmd_cdup(a1, v7);
}
else
{
v8 = strcmp(v6, "CWD") != 0;
v9 = 0;
v10 = !v8;
if ( v8 )
{
v11 = "HELP";
v12 = 5LL;
v13 = v6;
do
{
if ( !v12 )
break;
v9 = (unsigned __int8)*v13 < (unsigned int)*v11;
v10 = *v13++ == *v11++;
--v12;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
{
if ( v7 )
convert_to_upper(v7, v13);
cmd_help(a1, v7);
}
else if ( !strcmp(v6, "LIST") )
{
cmd_list_nlst(a1, v7, 1LL);
}
else if ( !strcmp(v6, "MKD") )
{
cmd_mkd(a1, v7);
}
else if ( !strcmp(v6, "MODE") )
{
cmd_mode(a1, v7);
}
else if ( !strcmp(v6, "NLST") )
{
cmd_list_nlst(a1, v7, 0LL);
}
else
{
v15 = strcmp(v6, "PASS") != 0;
v16 = 0;
v17 = !v15;
if ( v15 )
{
v18 = "PASV";
v19 = 5LL;
v20 = v6;
do
{
if ( !v19 )
break;
v16 = (unsigned __int8)*v20 < (unsigned int)*v18;
v17 = *v20++ == *v18++;
--v19;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
{
cmd_pasv(a1, v20);
}
else
{
v21 = strcmp(v6, "PORT") != 0;
v22 = 0;
v23 = !v21;
if ( v21 )
{
v24 = "PWD";
v25 = 4LL;
v26 = v6;
do
{
if ( !v25 )
break;
v22 = (unsigned __int8)*v26 < (unsigned int)*v24;
v23 = *v26++ == *v24++;
--v25;
}
while ( v23 );
v27 = (!v22 && !v23) - v22;
v28 = 0;
v29 = v27 == 0;
if ( v27 )
{
v30 = "QUIT";
v31 = 5LL;
v32 = v6;
do
{
if ( !v31 )
break;
v28 = (unsigned __int8)*v32 < (unsigned int)*v30;
v29 = *v32++ == *v30++;
--v31;
}
while ( v29 );
if ( (!v28 && !v29) == v28 )
{
cmd_quit(a1, v32);
}
else if ( !strcmp(v6, "RETR") )
{
cmd_retr(a1, v7);
}
else if ( !strcmp(v6, "STOR") )
{
cmd_stor(a1, v7);
}
else if ( !strcmp(v6, "STOU") )
{
cmd_stou(a1, v7);
}
else if ( !strcmp(v6, "STRU") )
{
cmd_stru(a1, v7, v4);
}
else if ( !strcmp(v6, "SYST") )
{
cmd_syst(a1);
}
else if ( !strcmp(v6, "TYPE") )
{
cmd_type(a1, v7);
}
else if ( !strcmp(v6, "USER") )
{
cmd_user(a1, v7);
}
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, v26);
}
}
else
{
cmd_port(a1, v7);
}
}
}
else
{
cmd_pass(a1, v7);
}
}
}
else
{
cmd_cwd(a1, v7);
}
}
*((_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; // er8
__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; // er8
__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]; }

return_type: int

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 *

return_type: void


pathFunc

decompiled_code:
char *pathFunc()
{
char *v0; // r12
char *v1; // rax
char *v2; // rbp
size_t v3; // r15
char *v5; // rdi

v0 = (char *)malloc(0x100uLL);
v1 = getenv("HOME");
v2 = stpcpy(v0, v1);
v3 = v2 - v0 + 1;
memcpy(v0 + 64, v0, v3);
memcpy(v0 + 128, v0, v3);
memcpy(v0 + 192, v0, v3);
strcpy(v2, "/.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);
v5 = v0;
v0 = 0LL;
free(v5);
}
else
{
strcat(v0, "gisps.conf");
*(__m128i *)&v0[strlen(v0 + 64) + 64] = _mm_load_si128((const __m128i *)&LC5);
strcat(v0 + 128, "nodeusage.xml");
*(__m128i *)&v0[strlen(v0 + 192) + 192] = _mm_load_si128((const __m128i *)&LC6);
}
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // r12
char *v1; // rax
char *v2; // rbp
size_t v3; // r15
char *v5; // rdi

v0 = (char *)malloc(0x100uLL);
v1 = getenv("HOME");
v2 = stpcpy(v0, v1);
v3 = v2 - v0 + 1;
memcpy(v0 + 64, v0, v3);
memcpy(v0 + 128, v0, v3);
memcpy(v0 + 192, v0, v3);
strcpy(v2, "/.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);
v5 = v0;
v0 = 0LL;
free(v5);
}
else
{
strcat(v0, "gisps.conf");
*(__m128i *)&v0[strlen(v0 + 64) + 64] = _mm_load_si128((const __m128i *)&LC5);
strcat(v0 + 128, "nodeusage.xml");
*(__m128i *)&v0[strlen(v0 + 192) + 192] = _mm_load_si128((const __m128i *)&LC6);
}
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; // rbp
double v4; // xmm0_8
const char *v5; // r12
const char *v6; // rax
const char *v7; // rax
double v8; // rbp
double v10; // [rsp+8h] [rbp-20h]

internodeInit(0LL, 0LL, "31");
v3 = pathFunc();
v4 = get_usage(v3 + 192, "traffic", "total");
v3 += 128LL;
printf("total Usage for last %s days %0.2f GB\n", "31", v4 / 1000.0);
v5 = (const char *)get_attrib_val(v3, "traffic", "rollover");
v6 = (const char *)get_attrib_val(v3, "traffic", "quota");
v10 = atof(v6);
v7 = (const char *)get_element_content(v3, "traffic");
v8 = atof(v7);
printf("Monthly Quota: %0.2lf GB\n", v10 / 1000000.0 / 1000.0);
printf("This month usage: %0.2lf GB\n", v8 / 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);
*(_DWORD *)(a1 + 24) = a2;
*(_QWORD *)(a1 + 16) = result;
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)a1 = result;
return result;
}

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

result = xmalloc(a2);
*(_DWORD *)(a1 + 24) = a2;
*(_QWORD *)(a1 + 16) = result;
*(_QWORD *)(a1 + 8) = result;
*(_QWORD *)a1 = result;
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;
 }
}


bread

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

result = bavail_read(a1);
if ( (_DWORD)result )
{
result = read(a2, *(void **)(a1 + 16), (int)result);
if ( (int)result <= 0 )
result = 0xFFFFFFFFLL;
else
*(_QWORD *)(a1 + 16) += (int)result;
}
return result;
}

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

result = func0(a1);
if ( (_DWORD)result )
{
result = read(a2, *(void **)(a1 + 16), (int)result);
if ( (int)result <= 0 )
result = 0xFFFFFFFFLL;
else
*(_QWORD *)(a1 + 16) += (int)result;
}
return result;
}

original_code:
int bread(struct buffer *b, int fd)
{
 int size;
 int n;
 size = bavail_read(b);
 if (size == 0)
  return 0;
 n = read(fd, b->end, size);
 if (n < 1)
  return -1;
 b->end += n;
 return n;
}

variable_types: fd int

variable_types: size int

variable_types: n int


bwrite

decompiled_code:
__int64 __fastcall bwrite(__int64 *a1)
{
int v1; // eax
int v2; // er9
const void *v3; // r10
unsigned int v4; // er8
int v6; // eax
unsigned int v7; // er8

v1 = bavail_write_isra_0(a1[1], a1[2]);
v4 = v1;
if ( !v1 )
return v4;
v6 = write(v2, v3, v1);
if ( v6 <= 0 )
return (unsigned int)-1;
a1[1] += v6;
bcheck_empty(a1);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
int v1; // eax
int v2; // er9
const void *v3; // r10
unsigned int v4; // er8
int v6; // eax
unsigned int v7; // er8

v1 = func2(a1[1], a1[2]);
v4 = v1;
if ( !v1 )
return v4;
v6 = write(v2, v3, v1);
if ( v6 <= 0 )
return (unsigned int)-1;
a1[1] += v6;
func1(a1);
return v7;
}

original_code:
int bwrite(struct buffer *b, int fd)
{
 int size;
 int n;
 size = bavail_write(b);
 if (size == 0)
  return 0;
 n = write(fd, b->begin, size);
 if (n < 1)
  return -1;
 b->begin += n;
 bcheck_empty(b);
 return n;
}


bgets

decompiled_code:
__int64 __fastcall bgets(__int64 *a1, void *a2, __int64 a3)
{
__int64 result; // rax
const void *v4; // r13
size_t v5; // rdx
size_t v6; // rbx
void *v7; // rdx
int v8; // edx

result = 0LL;
if ( a3 )
{
v4 = (const void *)a1[1];
result = bavail_write_isra_0((__int64)v4, a1[2]);
if ( (_DWORD)result )
{
v6 = v5;
v7 = memchr(v4, 10, (int)result);
result = 0LL;
if ( v7 )
{
v8 = (_DWORD)v7 - (_DWORD)v4;
if ( v8 + 1 <= v6 )
v6 = v8 + 1;
memcpy(a2, v4, v6);
a1[1] += v6;
bcheck_empty(a1);
result = (unsigned int)v6;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, void *a2, __int64 a3)
{
__int64 result; // rax
const void *v4; // r13
size_t v5; // rdx
size_t v6; // rbx
void *v7; // rdx
int v8; // edx

result = 0LL;
if ( a3 )
{
v4 = (const void *)a1[1];
result = func2((__int64)v4, a1[2]);
if ( (_DWORD)result )
{
v6 = v5;
v7 = memchr(v4, 10, (int)result);
result = 0LL;
if ( v7 )
{
v8 = (_DWORD)v7 - (_DWORD)v4;
if ( v8 + 1 <= v6 )
v6 = v8 + 1;
memcpy(a2, v4, v6);
a1[1] += v6;
func1(a1);
result = (unsigned int)v6;
}
}
}
return result;
}

original_code:
int bgets(struct buffer *b, char *s, size_t len)
{
 int size;
 char *p;
 int n;
 if (len == 0)
  return 0;
 size = bavail_write(b);
 if (size == 0)
  return 0;
 if ((p = memchr(b->begin, '\n', size)) == ((void *)0))
  return 0;
 n = p - b->begin + 1;
 if (len > n)
  len = n;
 memcpy(s, b->begin, len);
 b->begin += len;
 bcheck_empty(b);
 return len;
}

canonical_original_code:
int bgets(struct buffer *b, char *s, unsigned long len)
{
 int size;
 char *p;
 int n;
 if (len == 0)
  return 0;
 size = bavail_write(b);
 if (size == 0)
  return 0;
 if ((p = memchr(b->begin, '\n', size)) == ((void *)0))
  return 0;
 n = p - b->begin + 1;
 if (len > n)
  len = n;
 memcpy(s, b->begin, len);
 b->begin += len;
 bcheck_empty(b);
 return len;
}

variable_types:
s
char *

variable_types:
len
unsigned long


bputs

decompiled_code:
__int64 __fastcall bputs(__int64 a1, const void *a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v5; // rdx
size_t v6; // rbx
void *v7; // rdi

result = 0LL;
if ( a3 )
{
result = bavail_read(a1);
if ( (_DWORD)result )
{
v6 = v5;
v7 = *(void **)(a1 + 16);
if ( (int)result <= v5 )
v6 = (int)result;
memcpy(v7, a2, v6);
*(_QWORD *)(a1 + 16) += v6;
result = (unsigned int)v6;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v5; // rdx
size_t v6; // rbx
void *v7; // rdi

result = 0LL;
if ( a3 )
{
result = func0(a1);
if ( (_DWORD)result )
{
v6 = v5;
v7 = *(void **)(a1 + 16);
if ( (int)result <= v5 )
v6 = (int)result;
memcpy(v7, a2, v6);
*(_QWORD *)(a1 + 16) += v6;
result = (unsigned int)v6;
}
}
return result;
}

original_code:
int bputs(struct buffer *b, char *s, size_t len)
{
 int size;
 if (len == 0)
  return 0;
 size = bavail_read(b);
 if (size == 0)
  return 0;
 if (len > size)
  len = size;
 memcpy(b->end, s, len);
 b->end += len;
 return len;
}

canonical_original_code:
int bputs(struct buffer *b, char *s, unsigned long len)
{
 int size;
 if (len == 0)
  return 0;
 size = bavail_read(b);
 if (size == 0)
  return 0;
 if (len > size)
  len = size;
 memcpy(b->end, s, len);
 b->end += len;
 return len;
}


bcanfill

decompiled_code:
_BOOL8 __fastcall bcanfill(__int64 a1)
{
return (int)bavail_read(a1) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
return (int)func0(a1) > 0;
}

original_code:
int bcanfill(struct buffer *b)
{
 return bavail_read(b) > 0;
}


bhasdata

decompiled_code:
_BOOL8 __fastcall bhasdata(__int64 a1)
{
return (int)bavail_write_isra_0(*(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16)) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1)
{
return (int)func2(*(_QWORD *)(a1 + 8), *(_QWORD *)(a1 + 16)) > 0;
}

original_code:
int bhasdata(struct buffer *b)
{
 return bavail_write(b) > 0;
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s:%d: malloc %zd bytes: %s\n", "xwrap.c", 12LL, a1, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s:%d: malloc %zd bytes: %s\n", "xwrap.c", 12LL, a1, v3);
exit(1);
}
return result;
}

original_code:
void *xmalloc(size_t size)
{
 void *p;
 p = malloc(size);
 if (p == ((void *)0))
  do { fprintf(stderr, "%s" ":" "%d" ": " "malloc %zd bytes" ": " "%s" "\n", "xwrap.c", 12, size, strerror((*__errno_location ()))); exit(1); } while (0);
 return p;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
 void *p;
 p = malloc(size);
 if (p == ((void *)0))
  do { fprintf(stderr, "%s" ":" "%d" ": " "malloc %zd bytes" ": " "%s" "\n", "xwrap.c", 12, size, strerror((*__errno_location ()))); exit(1); } while (0);
 return p;
}

variable_types:
p
void *

return_type: void *


xstrdup

decompiled_code:
void *__fastcall xstrdup(void *src)
{
size_t v1; // r12
void *v2; // rax

if ( !src )
return 0LL;
v1 = (int)(strlen((const char *)src) + 1);
v2 = xmalloc(v1);
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func1(void *src)
{
size_t v1; // r12
void *v2; // rax

if ( !src )
return 0LL;
v1 = (int)(strlen((const char *)src) + 1);
v2 = func0(v1);
return memcpy(v2, src, v1);
}

original_code:
char *xstrdup(const char *s)
{
 int len;
 if (s == ((void *)0))
  return ((void *)0);
 len = strlen(s) + 1;
 return memcpy(xmalloc(len), s, len);
}

canonical_original_code:
char *xstrdup(char *s)
{
 int len;
 if (s == ((void *)0))
  return ((void *)0);
 len = strlen(s) + 1;
 return memcpy(xmalloc(len), s, len);
}

variable_types: len int

return_type: char *


unitBitcount

original_code:
int unitBitcount(unsigned char* d, int cnum){
  int i;
  int b, s, n;
  b = (int)ceil((double)cnum / (sizeof(unsigned char)*8));
  s = 0;
  for(i=b-1;i>=0;i--){
    n = d[i];
    n = (unsigned char)( ((n & 0xAA) >> 1) + (n & 0x55) );
    n = (unsigned char)( ((n & 0xCC) >> 2) + (n & 0x33) );
    n = (unsigned char)( ((n & 0xF0) >> 4) + (n & 0x0F) );
    s += n;
  }
  return s;
}

canonical_original_code:
int unitBitcount(unsigned char *d, int cnum){
  int i;
  int b; int s; int n;
  b = (int)ceil((double)cnum / (sizeof(unsigned char)*8));
  s = 0;
  for(i=b-1;i>=0;i--){
    n = d[i];
    n = (unsigned char)( ((n & 0xAA) >> 1) + (n & 0x55) );
    n = (unsigned char)( ((n & 0xCC) >> 2) + (n & 0x33) );
    n = (unsigned char)( ((n & 0xF0) >> 4) + (n & 0x0F) );
    s += n;
  }
  return s;
}

variable_types:
d
unsigned char *

variable_types: cnum int

variable_types: i int

variable_types: b int

variable_types: s int


decompiled_code:
__int64 __fastcall udata2uint(__int64 a1, int a2)
{
double v2; // xmm0_8
__m128d v3; // xmm3
__m128d v4; // xmm1
int v5; // esi
unsigned int v6; // er8
unsigned __int8 *v7; // rax
int v8; // edx

v2 = (double)a2 * 0.125;
if ( COERCE_DOUBLE(*(_QWORD *)&v2 & LC2) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = (double)a2 * 0.125;
v4.m128d_f64[0] = (double)(int)v2;
*(_QWORD *)&v2 = COERCE_UNSIGNED_INT64(v4.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v3, v4) & LC3)) | ~LC2 & *(_QWORD *)&v2;
}
v5 = (int)v2 - 1;
if ( v5 < 0 )
return 0LL;
v6 = 0;
v7 = (unsigned __int8 *)(a1 + v5);
do
{
v8 = *v7--;
v6 = v8 + (v6 << 8);
}
while ( v7 != (unsigned __int8 *)(a1 + (int)v2 - 2 - (unsigned int)v5) );
return v6;
}

original_code:
unsigned int udata2uint(unsigned char* a, int n){
  int i;
  int b;
  unsigned int ret;
  b = (int)ceil((double)n / (sizeof(unsigned char)*8));
  ret = 0;
  for(i=b-1;i>=0;i--){
    ret *= 256;
    ret += a[i];
  }
  return ret;
}

canonical_original_code:
unsigned int udata2uint(unsigned char *a, int n){
  int i;
  int b;
  unsigned int ret;
  b = (int)ceil((double)n / (sizeof(unsigned char)*8));
  ret = 0;
  for(i=b-1;i>=0;i--){
    ret *= 256;
    ret += a[i];
  }
  return ret;
}

variable_types:
a
unsigned char *

variable_types:
ret
unsigned int

return_type: unsigned int


unitFree

decompiled_code:
void __fastcall unitFree(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
free(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
free(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void unitFree(unit* u){
  int i;
  for(i=0;i<u->num;i++) free(u->array[i]);
  free(u->array);
  free(u);
}

canonical_original_code:
void unitFree(struct _unit *u){
  int i;
  for(i=0;i<u->num;i++) free(u->array[i]);
  free(u->array);
  free(u);
}

variable_types: struct _unit { int num; unsigned char **array; } *


uintCmp

decompiled_code:
__int64 __fastcall uintCmp(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
int v5; // edx
int v6; // ecx
bool v7; // si

if ( a3 < 0 )
return 0LL;
v4 = a3 - 1;
do
{
v5 = *(unsigned __int8 *)(a1 + v4 + 1) - *(unsigned __int8 *)(a2 + v4 + 1);
v6 = ~(_DWORD)v4;
v7 = *(unsigned __int8 *)(a1 + v4 + 1) == *(unsigned __int8 *)(a2 + v4 + 1);
--v4;
}
while ( v6 < 0 && v7 );
if ( v5 < 0 )
return 1LL;
if ( v5 )
v5 = 2;
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
int v5; // edx
int v6; // ecx
bool v7; // si

if ( a3 < 0 )
return 0LL;
v4 = a3 - 1;
do
{
v5 = *(unsigned __int8 *)(a1 + v4 + 1) - *(unsigned __int8 *)(a2 + v4 + 1);
v6 = ~(_DWORD)v4;
v7 = *(unsigned __int8 *)(a1 + v4 + 1) == *(unsigned __int8 *)(a2 + v4 + 1);
--v4;
}
while ( v6 < 0 && v7 );
if ( v5 < 0 )
return 1LL;
if ( v5 )
v5 = 2;
return (unsigned int)v5;
}

original_code:
int uintCmp(unsigned char* a1, unsigned char* a2, int b){
  int i;
  int t=0;
  int ret=0;
  t=0; i=b;
  while((t == 0) & (i>=0)){
    t = (int)(a1[i] - a2[i]);
    i--;
  };
  if(t<0) ret = 1;
  else if(t>0) ret = 2;
  else ret = 0;
  return ret;
}

canonical_original_code:
int uintCmp(unsigned char *a1, unsigned char *a2, int b){
  int i;
  int t = 0;
  int ret = 0;
  t=0; i=b;
  while((t == 0) & (i>=0)){
    t = (int)(a1[i] - a2[i]);
    i--;
  };
  if(t<0) ret = 1;
  else if(t>0) ret = 2;
  else ret = 0;
  return ret;
}

variable_types: t int

variable_types: ret int


decompiled_code:
__int64 __fastcall uintMed3(__int64 a1, __int64 a2, __int64 a3, int a4)
{
__int64 v4; // r9
int v5; // er10
__int64 v6; // r11
int v7; // er8
int v8; // er10
__int64 v9; // r11
__int64 result; // rax
bool v11; // zf
__int64 v12; // r9
int v13; // er8
int v14; // er10
__int64 v15; // r11
__int64 v16; // r9
__int64 v17; // r11

if ( (unsigned int)uintCmp(a1, a2, a4) == 1 )
{
v13 = uintCmp(v4, v6, v5);
result = v16;
if ( v13 != 1 )
{
v11 = (unsigned int)uintCmp(v15, a1, v14) == 1;
result = a1;
if ( !v11 )
result = v17;
}
}
else
{
v7 = uintCmp(v6, v4, v5);
result = v9;
if ( v7 != 1 )
{
v11 = (unsigned int)uintCmp(a1, v9, v8) == 1;
result = a1;
if ( !v11 )
result = v12;
}
}
return result;
}

original_code:
unsigned char* uintMed3(unsigned char* x, unsigned char* y, unsigned char* z, int b){
  unsigned char* ret;
  if(uintCmp(x, y, b) == 1){
    if(uintCmp(y, z, b) == 1) ret = y;
    else if(uintCmp(z, x, b) == 1) ret = x;
    else ret = z;
  }
  else{
    if(uintCmp(z, y, b) == 1) ret = z;
    else if(uintCmp(x, z, b) == 1) ret = x;
    else ret = y;
  }
  return ret;
}

canonical_original_code:
unsigned char *uintMed3(unsigned char *x, unsigned char *y, unsigned char *z, int b){
  unsigned char *ret;
  if(uintCmp(x, y, b) == 1){
    if(uintCmp(y, z, b) == 1) ret = y;
    else if(uintCmp(z, x, b) == 1) ret = x;
    else ret = z;
  }
  else{
    if(uintCmp(z, y, b) == 1) ret = z;
    else if(uintCmp(x, z, b) == 1) ret = x;
    else ret = y;
  }
  return ret;
}

variable_types:
x
unsigned char *

variable_types:
y
unsigned char *

variable_types:
z
unsigned char *

variable_types:
ret
unsigned char *

return_type: unsigned char *


uintQuicksort

original_code:
void uintQuicksort(unsigned char** a, int left, int right, int b){
  int i, j;
  unsigned char *tmp, *pivot;
  if(left < right){
    i = left; j = right;
    pivot = uintMed3(a[i], a[i+(j-i)/2], a[j], b);
    while(1){
      while(uintCmp(a[i], pivot, b) == 1) i++;
      while(uintCmp(pivot, a[j], b) == 1) j--;
      if(i>=j) break;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      i++; j--;
    }
    uintQuicksort(a, left, i-1, b);
    uintQuicksort(a, j+1, right, b);
  }
}

canonical_original_code:
void uintQuicksort(unsigned char **a, int left, int right, int b){
  int i; int j;
  unsigned char *tmp; unsigned char *pivot;
  if(left < right){
    i = left; j = right;
    pivot = uintMed3(a[i], a[i+(j-i)/2], a[j], b);
    while(1){
      while(uintCmp(a[i], pivot, b) == 1) i++;
      while(uintCmp(pivot, a[j], b) == 1) j--;
      if(i>=j) break;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      i++; j--;
    }
    uintQuicksort(a, left, i-1, b);
    uintQuicksort(a, j+1, right, b);
  }
}

variable_types:
a
unsigned char **

variable_types: left int

variable_types: right int

variable_types: j int

variable_types:
tmp
unsigned char *

variable_types:
pivot
unsigned char *


uintSort

decompiled_code:
void __fastcall uintSort(__int64 a1, int a2, unsigned int a3)
{
uintQuicksort(a1, 0, a2 - 1, a3);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2, unsigned int a3)
{
func5(a1, 0, a2 - 1, a3);
}

original_code:
void uintSort(unsigned char** array, int num, int b){
  uintQuicksort(array, 0, num-1, b);
}

canonical_original_code:
void uintSort(unsigned char **array, int num, int b){
  uintQuicksort(array, 0, num-1, b);
}

variable_types:
array
unsigned char **

variable_types: num int

variable_types: b int


uintCpy

decompiled_code:
__int64 __fastcall uintCpy(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
__int64 result; // rax

LODWORD(v3) = a3 - 1;
if ( (int)v3 >= 0 )
{
v3 = (int)v3;
do
{
result = *(unsigned __int8 *)(a2 + v3);
*(_BYTE *)(a1 + v3--) = result;
}
while ( (int)v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
__int64 result; // rax

LODWORD(v3) = a3 - 1;
if ( (int)v3 >= 0 )
{
v3 = (int)v3;
do
{
result = *(unsigned __int8 *)(a2 + v3);
*(_BYTE *)(a1 + v3--) = result;
}
while ( (int)v3 >= 0 );
}
return result;
}

original_code:
void uintCpy(unsigned char* d, unsigned char* s, int b){
  int i;
  for(i=b-1;i>=0;i--) d[i] = s[i];
}

canonical_original_code:
void uintCpy(unsigned char *d, unsigned char *s, int b){
  int i;
  for(i=b-1;i>=0;i--) d[i] = s[i];
}

variable_types:
d
unsigned char *

variable_types:
s
unsigned char *

variable_types: i int


hammingView

decompiled_code:
int __fastcall hammingView(unsigned int *a1, __int64 a2)
{
int result; // eax
__int64 i; // rbp
__int64 j; // rbx
__int64 v5; // rax

result = printf(" n: %d \n", *a1);
for ( i = *((_QWORD *)a1 + 1); i; i = *(_QWORD *)(i + 24) )
{
for ( j = 0LL; *(_DWORD *)(i + 8) > (int)j; ++j )
{
v5 = *(unsigned int *)(*(_QWORD *)(i + 16) + 4 * j);
printf("[%d] %04X ", v5, *(unsigned int *)(a2 + 4 * v5));
}
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int *a1, __int64 a2)
{
int result; // eax
__int64 i; // rbp
__int64 j; // rbx
__int64 v5; // rax

result = printf(" n: %d \n", *a1);
for ( i = *((_QWORD *)a1 + 1); i; i = *(_QWORD *)(i + 24) )
{
for ( j = 0LL; *(_DWORD *)(i + 8) > (int)j; ++j )
{
v5 = *(unsigned int *)(*(_QWORD *)(i + 16) + 4 * j);
printf("[%d] %04X ", v5, *(unsigned int *)(a2 + 4 * v5));
}
result = putchar(10);
}
return result;
}

original_code:
void hammingView(hamming* h, unsigned int* term){
  hammingData *lp;
  int i;
  printf(" n: %d \n", h->len);
  lp = h->head;
  while(lp != ((void *)0)){
    for(i=0;i<lp->arraysize;i++){
      printf("[%d] %04X ", lp->array[i], term[lp->array[i]]);
    }
    printf("\n");
    lp = lp->next;
  }
}

canonical_original_code:
void hammingView(struct _hamming *h, unsigned int *term){
  struct _hammingData *lp;
  int i;
  printf(" n: %d \n", h->len);
  lp = h->head;
  while(lp != ((void *)0)){
    for(i=0;i<lp->arraysize;i++){
      printf("[%d] %04X ", lp->array[i], term[lp->array[i]]);
    }
    printf("\n");
    lp = lp->next;
  }
}

variable_types: struct _hamming { int len; struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; } *head; } *

variable_types:
term
unsigned int *

user_defined_types: struct _hamming { int len; struct _hammingData *head; }


hammingNew

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

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
hamming* hammingNew(){
  hamming* h;
  h = (hamming*)malloc(sizeof(hamming));
  h->len = 0;
  h->head = ((void *)0);
  h->tail = ((void *)0);
  return h;
}

canonical_original_code:
struct _hamming *hammingNew(){
  struct _hamming *h;
  h = (struct _hamming *)malloc(sizeof(hamming));
  h->len = 0;
  h->head = ((void *)0);
  h->tail = ((void *)0);
  return h;
}

return_type: struct _hamming { int len; struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; } *head; } *


hammingFree

decompiled_code:
void __fastcall hammingFree(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

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

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rbx
void **v2; // rbp

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

original_code:
void hammingFree(hamming* h){
  hammingData *p, *d;
  p = h->head;
  while(p != ((void *)0)){
    d = p;
    p = p->next;
    free(d->array);
    free(d);
  }
  free(h);
}

canonical_original_code:
void hammingFree(struct _hamming *h){
  struct _hammingData *p; struct _hammingData *d;
  p = h->head;
  while(p != ((void *)0)){
    d = p;
    p = p->next;
    free(d->array);
    free(d);
  }
  free(h);
}

variable_types: struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; } *


hammingDistance

decompiled_code:
__int64 __fastcall hammingDistance(int a1, int a2, int a3, int a4)
{
unsigned int v4; // er8
int v5; // eax
int v6; // edx

bitcount((a3 | a2 | a4) ^ (a1 | a4 | a3));
v5 = bitcount(v4);
return (unsigned int)(v6 + v5);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, int a3, int a4)
{
unsigned int v4; // er8
int v5; // eax
int v6; // edx

func3((a3 | a2 | a4) ^ (a1 | a4 | a3));
v5 = func3(v4);
return (unsigned int)(v6 + v5);
}

original_code:
int hammingDistance(unsigned int a, unsigned int b, unsigned int ma, unsigned int mb){
  unsigned int d, dm;
  d = (a|ma|mb) ^ (b|ma|mb);
  dm = ma ^ mb;
  return bitcount(d)+bitcount(dm);
}

canonical_original_code:
int hammingDistance(unsigned int a, unsigned int b, unsigned int ma, unsigned int mb){
  unsigned int d; unsigned int dm;
  d = (a|ma|mb) ^ (b|ma|mb);
  dm = ma ^ mb;
  return bitcount(d)+bitcount(dm);
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
ma
unsigned int

variable_types:
mb
unsigned int

variable_types:
d
unsigned int

variable_types:
dm
unsigned int


bitExpression

original_code:
void bitExpression(unsigned int* term, hammingData* hd, int blen){
  int i;
  unsigned int d;
  unsigned int m;
  char *c;
  d = term[hd->array[0]];
  m = hd->mask;
  c = ((void *)0);
  c = (char*)malloc(sizeof(char)*(blen));
  if(c == ((void *)0)){
    printf("memory Allocation Error.\n");
    exit(1);
  }
  for(i=0;i<blen;i++){
    if(m % 2) c[i] = 'X';
    else c[i] = '0'+(d%2);
    m /= 2;
    d /= 2;
  }
  for(i=blen-1;i>=0;i--) printf("%c", c[i]);
  free(c);
  c = ((void *)0);
}

canonical_original_code:
void bitExpression(unsigned int *term, struct _hammingData *hd, int blen){
  int i;
  unsigned int d;
  unsigned int m;
  char *c;
  d = term[hd->array[0]];
  m = hd->mask;
  c = ((void *)0);
  c = (char *)malloc(sizeof(char)*(blen));
  if(c == ((void *)0)){
    printf("memory Allocation Error.\n");
    exit(1);
  }
  for(i=0;i<blen;i++){
    if(m % 2) c[i] = 'X';
    else c[i] = '0'+(d%2);
    m /= 2;
    d /= 2;
  }
  for(i=blen-1;i>=0;i--) printf("%c", c[i]);
  free(c);
  c = ((void *)0);
}

variable_types: blen int

variable_types:
m
unsigned int

variable_types:
c
char *

user_defined_types: struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; }


hammingMatch

original_code:
void hammingMatch(hamming* h, hammingData *a, hammingData *b, unsigned int *term){
  int i;
  int midx, nidx;
  unsigned int m, n;
  int dist;
  unsigned int dc, cb;
  hammingData *hd;
  hammingData *p;
  unsigned int diff;
  int flag;
  dist = hammingDistance(term[a->array[0]], term[b->array[0]],
                         a->mask, b->mask);
  printf("dist: %d  a:[%4d]%04X b:[%4d]%04X\n",
         dist, a->array[0], term[a->array[0]],
         b->array[0], term[b->array[0]]);
  if(dist == 1){
    dc = ((term[a->array[0]]|a->mask) ^ (term[b->array[0]]|b->mask))
      | a->mask | b->mask;
    cb = bitcount(term[a->array[0]]|dc)-bitcount(dc);
    printf("  DC:%04X, cb:%d\n",dc, cb);
    hd = (hammingData*)malloc(sizeof(hammingData));
    hd->flag = 0; hd->mask = dc; hd->next=((void *)0);
    hd->arraysize = a->arraysize + b->arraysize;
    hd->array = (unsigned int*)malloc(sizeof(unsigned int)*hd->arraysize);
    printf("  ArraySize : %d\n", hd->arraysize);
    midx=0; nidx=0;
    for(i=0;i<hd->arraysize;i++){
      if(midx < a->arraysize) m = a->array[midx];
      else m = (0x7fffffff * 2U + 1U);
      if(nidx < b->arraysize) n = b->array[nidx];
      else n = (0x7fffffff * 2U + 1U);
      if(m < n){ hd->array[i] = m; midx++; }
      else{ hd->array[i] = n; nidx++; }
    }
    flag=0; p=h->head;
    while((p != ((void *)0)) && (flag == 0)){
      if((p->mask == hd->mask) && (hd->arraysize == p->arraysize)){
        diff = 0;
        for(i=0;i<hd->arraysize;i++){
          diff += p->array[i] - hd->array[i];
          if(diff != 0) break;
        }
        if(diff == 0) flag = 1;
      }
      p=p->next;
    }
    if(flag == 0) printf("  Unique: true\n");
    else printf("  Unique: false\n");
    if(flag == 0){
      if(h->len == 0) h->tail = hd;
      else hd->next = h->head;
      h->head = hd;
      h->len++;
    }
    a->flag++; b->flag++;
  }
}

canonical_original_code:
void hammingMatch(struct _hamming *h, struct _hammingData *a, struct _hammingData *b, unsigned int *term){
  int i;
  int midx; int nidx;
  unsigned int m; unsigned int n;
  int dist;
  unsigned int dc; unsigned int cb;
  struct _hammingData *hd;
  struct _hammingData *p;
  unsigned int diff;
  int flag;
  dist = hammingDistance(term[a->array[0]], term[b->array[0]],
                         a->mask, b->mask);
  printf("dist: %d  a:[%4d]%04X b:[%4d]%04X\n",
         dist, a->array[0], term[a->array[0]],
         b->array[0], term[b->array[0]]);
  if(dist == 1){
    dc = ((term[a->array[0]]|a->mask) ^ (term[b->array[0]]|b->mask))
      | a->mask | b->mask;
    cb = bitcount(term[a->array[0]]|dc)-bitcount(dc);
    printf("  DC:%04X, cb:%d\n",dc, cb);
    hd = (struct _hammingData *)malloc(sizeof(hammingData));
    hd->flag = 0; hd->mask = dc; hd->next=((void *)0);
    hd->arraysize = a->arraysize + b->arraysize;
    hd->array = (unsigned int *)malloc(sizeof(unsigned int)*hd->arraysize);
    printf("  ArraySize : %d\n", hd->arraysize);
    midx=0; nidx=0;
    for(i=0;i<hd->arraysize;i++){
      if(midx < a->arraysize) m = a->array[midx];
      else m = (0x7fffffff * 2U + 1U);
      if(nidx < b->arraysize) n = b->array[nidx];
      else n = (0x7fffffff * 2U + 1U);
      if(m < n){ hd->array[i] = m; midx++; }
      else{ hd->array[i] = n; nidx++; }
    }
    flag=0; p=h->head;
    while((p != ((void *)0)) && (flag == 0)){
      if((p->mask == hd->mask) && (hd->arraysize == p->arraysize)){
        diff = 0;
        for(i=0;i<hd->arraysize;i++){
          diff += p->array[i] - hd->array[i];
          if(diff != 0) break;
        }
        if(diff == 0) flag = 1;
      }
      p=p->next;
    }
    if(flag == 0) printf("  Unique: true\n");
    else printf("  Unique: false\n");
    if(flag == 0){
      if(h->len == 0) h->tail = hd;
      else hd->next = h->head;
      h->head = hd;
      h->len++;
    }
    a->flag++; b->flag++;
  }
}

variable_types:
a
struct _hammingData *

variable_types:
b
struct _hammingData *

variable_types: midx int

variable_types: nidx int

variable_types:
n
unsigned int

variable_types: dist int

variable_types:
dc
unsigned int

variable_types:
cb
unsigned int

variable_types:
diff
unsigned int

variable_types: flag int


decompiled_code:
__int64 __fastcall send_to_serv(char *s2, char *src)
{
unsigned int v2; // ebp
unsigned int v3; // eax
int v4; // ebp
char *v5; // rbx
unsigned int v6; // eax
int v7; // ebp
char *v8; // r14
const char *v10; // rbx
const char *v11; // r12
__pid_t v12; // er14
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
const char *v17; // [rsp+8h] [rbp-40h]

v2 = ftok("/item/platform/route/etc/SHMKEY", 11);
if ( v2 == -1 )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf(&byte_2020, "comm.c", 18LL, v14);
return v2;
}
printf(&format, "comm.c", 21LL);
v3 = shmget(v2, 0x283C0uLL, 1024);
v4 = v3;
if ( v3 == -1 )
goto LABEL_20;
printf("shmget ok shmid is [%d]\n", v3);
v5 = (char *)shmat(v4, 0LL, 0);
if ( v5 == (char *)-1LL )
{
LABEL_21:
v2 = -1;
perror("shmat error");
return v2;
}
v2 = ftok("/item/platform/route/etc/SHMKEY", 14);
if ( v2 == -1 )
{
v15 = __errno_location();
v16 = strerror(*v15);
printf(&byte_2020, "comm.c", 38LL, v16);
return v2;
}
printf(&format, "comm.c", 41LL);
v6 = shmget(v2, 0x3E8uLL, 1024);
v7 = v6;
if ( v6 == -1 )
{
LABEL_20:
v2 = -1;
perror("shm get error");
return v2;
}
printf("shmget ok shmid is [%d]\n", v6);
v8 = (char *)shmat(v7, 0LL, 0);
if ( v8 == (char *)-1LL )
goto LABEL_21;
v2 = 0;
while ( *(_QWORD *)v5 )
{
++v2;
v5 += 16480;
if ( v2 == 10 )
{
v2 = -1;
puts(&s);
return v2;
}
}
memset(v5, 0, 0x4060uLL);
strcpy(v5 + 24, "QDTX");
*(_QWORD *)v5 = getpid();
strcpy(v5 + 39, src);
*((_WORD *)v5 + 8232) = 87;
*((_WORD *)v5 + 8233) = 81;
v10 = v8 + 6;
v17 = v8 + 1006;
do
{
v11 = v10 - 2;
printf("%ld %s %s\n", *(unsigned int *)(v10 - 6), v10, v10 - 2);
v12 = *(_DWORD *)(v10 - 6);
if ( v12 && !strcmp(v10, s2) && *v11 == 83 && !v11[1] )
{
kill(v12, 12);
return v2;
}
v10 += 20;
}
while ( v10 != v17 );
v2 = -1;
puts(&byte_2040);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2, char *src)
{
unsigned int v2; // ebp
unsigned int v3; // eax
int v4; // ebp
char *v5; // rbx
unsigned int v6; // eax
int v7; // ebp
char *v8; // r14
const char *v10; // rbx
const char *v11; // r12
__pid_t v12; // er14
int *v13; // rax
char *v14; // rax
int *v15; // rax
char *v16; // rax
const char *v17; // [rsp+8h] [rbp-40h]

v2 = ftok("/item/platform/route/etc/SHMKEY", 11);
if ( v2 == -1 )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf(&byte_2020, "comm.c", 18LL, v14);
return v2;
}
printf(&format, "comm.c", 21LL);
v3 = shmget(v2, 0x283C0uLL, 1024);
v4 = v3;
if ( v3 == -1 )
goto LABEL_20;
printf("shmget ok shmid is [%d]\n", v3);
v5 = (char *)shmat(v4, 0LL, 0);
if ( v5 == (char *)-1LL )
{
LABEL_21:
v2 = -1;
perror("shmat error");
return v2;
}
v2 = ftok("/item/platform/route/etc/SHMKEY", 14);
if ( v2 == -1 )
{
v15 = __errno_location();
v16 = strerror(*v15);
printf(&byte_2020, "comm.c", 38LL, v16);
return v2;
}
printf(&format, "comm.c", 41LL);
v6 = shmget(v2, 0x3E8uLL, 1024);
v7 = v6;
if ( v6 == -1 )
{
LABEL_20:
v2 = -1;
perror("shm get error");
return v2;
}
printf("shmget ok shmid is [%d]\n", v6);
v8 = (char *)shmat(v7, 0LL, 0);
if ( v8 == (char *)-1LL )
goto LABEL_21;
v2 = 0;
while ( *(_QWORD *)v5 )
{
++v2;
v5 += 16480;
if ( v2 == 10 )
{
v2 = -1;
puts(&s);
return v2;
}
}
memset(v5, 0, 0x4060uLL);
strcpy(v5 + 24, "QDTX");
*(_QWORD *)v5 = getpid();
strcpy(v5 + 39, src);
*((_WORD *)v5 + 8232) = 87;
*((_WORD *)v5 + 8233) = 81;
v10 = v8 + 6;
v17 = v8 + 1006;
do
{
v11 = v10 - 2;
printf("%ld %s %s\n", *(unsigned int *)(v10 - 6), v10, v10 - 2);
v12 = *(_DWORD *)(v10 - 6);
if ( v12 && !strcmp(v10, s2) && *v11 == 83 && !v11[1] )
{
kill(v12, 12);
return v2;
}
v10 += 20;
}
while ( v10 != v17 );
v2 = -1;
puts(&byte_2040);
return v2;
}

original_code:
int send_to_serv(char *servtype,char *buffer)
{
    int shmid = 0,i=0;
    key_t key;
 _transhm *trandata=((void *)0);
 _servershm *server=((void *)0);
 int maxtran = 10;
 int maxserver = 50;
    key = ftok("/item/platform/route/etc/SHMKEY",11);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",18,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",21);
    shmid = shmget(key,maxtran*sizeof(_transhm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((trandata=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
    key = ftok("/item/platform/route/etc/SHMKEY",14);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",38,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",41);
    shmid = shmget(key,maxserver*sizeof(_servershm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((server=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
 for(i=0;i<maxtran;i++)
 {
  if((trandata+i)->s_pid==0)
  {
   memset(trandata+i,0X00,sizeof(_transhm));
   (trandata+i)->s_pid = (pid_t)getpid();
   strcpy((trandata+i)->send_chnl,"QDTX");
   strcpy((trandata+i)->chnl_data,buffer);
   strcpy((trandata+i)->cur_stat,"W");
   strcpy((trandata+i)->require_serv,"Q");
   for(int j=0;j<50;j++)
   {
    printf("%ld %s %s\n",(server+j)->serverpid,(server+j)->require_serv,(server+j)->servtype);
    if((server+j)->serverpid!=0&&!strcmp((server+j)->require_serv,servtype)&&!strcmp((server+j)->servtype,"S"))
    {
     kill((server+j)->serverpid,12);
     return i;
     break;
    }
    if(j==49)
    {
     printf("该交易没有对应核心服务\n");
     return -1;
    }
   }
  }
 }
 printf("共享内存全部在使用中...\n");
 return -1;
}

canonical_original_code:
int send_to_serv(char *servtype, char *buffer)
{
    int shmid = 0; int i = 0;
    int key;
 struct TRANSHM *trandata = ((void *)0);
 struct SERVERSHM *server = ((void *)0);
 int maxtran = 10;
 int maxserver = 50;
    key = ftok("/item/platform/route/etc/SHMKEY",11);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",18,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",21);
    shmid = shmget(key,maxtran*sizeof(_transhm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((trandata=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
    key = ftok("/item/platform/route/etc/SHMKEY",14);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",38,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",41);
    shmid = shmget(key,maxserver*sizeof(_servershm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((server=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
 for(i=0;i<maxtran;i++)
 {
  if((trandata+i)->s_pid==0)
  {
   memset(trandata+i,0X00,sizeof(_transhm));
   (trandata+i)->s_pid = (int)getpid();
   strcpy((trandata+i)->send_chnl,"QDTX");
   strcpy((trandata+i)->chnl_data,buffer);
   strcpy((trandata+i)->cur_stat,"W");
   strcpy((trandata+i)->require_serv,"Q");
   for(int j = 0;j<50;j++)
   {
    printf("%ld %s %s\n",(server+j)->serverpid,(server+j)->require_serv,(server+j)->servtype);
    if((server+j)->serverpid!=0&&!strcmp((server+j)->require_serv,servtype)&&!strcmp((server+j)->servtype,"S"))
    {
     kill((server+j)->serverpid,12);
     return i;
     break;
    }
    if(j==49)
    {
     printf("该交易没有对应核心服务\n");
     return -1;
    }
   }
  }
 }
 printf("共享内存全部在使用中...\n");
 return -1;
}

variable_types:
servtype
char *

variable_types:
buffer
char *

variable_types: shmid int

variable_types: i int

variable_types: key int

variable_types: struct TRANSHM { unsigned long s_pid; unsigned long a_pid; unsigned long r_pid; char send_chnl[5]; char serv_name[5]; char recv_chnl[5]; char chnl_data[4096]; char senv_data[4096]; struct FLOW { int flowid; char flow_mark[60]; char func_name[20]; char dl_name[10]; char flow_type[2]; char errflow[60]; char timeoutflow[60]; } *do_flow; struct DATA { char varname[10]; char value[100]; } *do_data; char return_serv[4096]; char return_chnl[4096]; long stime; long dtime; long etime; char cur_stat[2]; char require_serv[3]; char xxx1[1]; char xxx2[1]; char xxx3[1]; char xxx4[1]; } *

variable_types: struct SERVERSHM { int serverpid; char servtype[2]; char require_serv[3]; char chnlid[5]; int cnt; } *

variable_types: maxtran int

variable_types: maxserver int

variable_types: j int

user_defined_types: struct TRANSHM { unsigned long s_pid; unsigned long a_pid; unsigned long r_pid; char send_chnl[5]; char serv_name[5]; char recv_chnl[5]; char chnl_data[4096]; char senv_data[4096]; struct FLOW *do_flow; struct DATA *do_data; char return_serv[4096]; char return_chnl[4096]; long stime; long dtime; long etime; char cur_stat[2]; char require_serv[3]; char xxx1[1]; char xxx2[1]; char xxx3[1]; char xxx4[1]; }


repo: n-west/udev-hso

decompiled_code:
void release_usb_device()
{
usb_release_interface(usb_hd, 0LL);
usb_close(usb_hd);
}

canonical_decompiled_code:
void func0()
{
usb_release_interface(usb_hd, 0LL);
usb_close(usb_hd);
}

original_code:
void release_usb_device(int param) {
 (void)usb_release_interface(usb_hd, 0);
 (void)usb_close(usb_hd);
}

variable_types: param int


decompiled_code:
int print_usage()
{
puts("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n");
puts(" -h, --help this help");
puts(" -i, --device_id <n> target USB device id, required option");
puts(" -f, --usb_filename <str> target USB file name");
printf(" -n, --namelen <n> target USB file name len (default %d)\n", (unsigned int)namelength);
puts(" -w, --warn_only print warnings instead of errors without program abort");
puts(" -q, --quiet don't show messages");
puts(" -t, --test test only, nothing send");
puts(" -l, --log write message into log file instead of stderr");
puts(" -s, --searchtime <n> ms tries to search at least <n> ms for the Zero-CD device");
puts(" -d, --debug output some debug messages");
puts(" -v, --version show version string\n");
puts("Examples:");
puts(" ozerocdoff -i 0xc031");
return puts(" ozerocdoff -i 0xc031 -f usbdev5.28 -n 2");
}

canonical_decompiled_code:
int func1()
{
puts("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n");
puts(" -h, --help this help");
puts(" -i, --device_id <n> target USB device id, required option");
puts(" -f, --usb_filename <str> target USB file name");
printf(" -n, --namelen <n> target USB file name len (default %d)\n", (unsigned int)namelength);
puts(" -w, --warn_only print warnings instead of errors without program abort");
puts(" -q, --quiet don't show messages");
puts(" -t, --test test only, nothing send");
puts(" -l, --log write message into log file instead of stderr");
puts(" -s, --searchtime <n> ms tries to search at least <n> ms for the Zero-CD device");
puts(" -d, --debug output some debug messages");
puts(" -v, --version show version string\n");
puts("Examples:");
puts(" ozerocdoff -i 0xc031");
return puts(" ozerocdoff -i 0xc031 -f usbdev5.28 -n 2");
}

original_code:
void print_usage(void) {
        printf ("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n\n");
 printf (" -h, --help               this help\n");
 printf (" -i, --device_id <n>      target USB device id, required option\n");
 printf (" -f, --usb_filename <str> target USB file name\n");
 printf (" -n, --namelen <n>        target USB file name len (default %d)\n", namelength);
 printf (" -w, --warn_only          print warnings instead of errors without program abort\n");
 printf (" -q, --quiet              don't show messages\n");
 printf (" -t, --test               test only, nothing send\n");
 printf (" -l, --log                write message into log file instead of stderr\n");
 printf (" -s, --searchtime <n> ms  tries to search at least <n> ms for the Zero-CD device\n");
 printf (" -d, --debug              output some debug messages\n");
 printf (" -v, --version            show version string\n\n");
 printf ("Examples:\n");
 printf ("   ozerocdoff -i 0xc031\n");
 printf ("   ozerocdoff -i 0xc031 -f usbdev5.28 -n 2\n");
}

canonical_original_code:
void print_usage() {
        printf ("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n\n");
 printf (" -h, --help               this help\n");
 printf (" -i, --device_id <n>      target USB device id, required option\n");
 printf (" -f, --usb_filename <str> target USB file name\n");
 printf (" -n, --namelen <n>        target USB file name len (default %d)\n", namelength);
 printf (" -w, --warn_only          print warnings instead of errors without program abort\n");
 printf (" -q, --quiet              don't show messages\n");
 printf (" -t, --test               test only, nothing send\n");
 printf (" -l, --log                write message into log file instead of stderr\n");
 printf (" -s, --searchtime <n> ms  tries to search at least <n> ms for the Zero-CD device\n");
 printf (" -d, --debug              output some debug messages\n");
 printf (" -v, --version            show version string\n\n");
 printf ("Examples:\n");
 printf ("   ozerocdoff -i 0xc031\n");
 printf ("   ozerocdoff -i 0xc031 -f usbdev5.28 -n 2\n");
}


strrcut

decompiled_code:
const char *__fastcall strrcut(const char *a1, int a2)
{
size_t v2; // rax
const char *v3; // rbx
bool v4; // cf
const char *result; // rax

v2 = strlen(a1);
v3 = &a1[v2 - a2];
v4 = v2 < a2;
result = (const char *)&unk_C59;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1, int a2)
{
size_t v2; // rax
const char *v3; // rbx
bool v4; // cf
const char *result; // rax

v2 = strlen(a1);
v3 = &a1[v2 - a2];
v4 = v2 < a2;
result = (const char *)&unk_C59;
if ( !v4 )
result = v3;
return result;
}

original_code:
const char *strrcut(const char *s, int n) {
        if (strlen(s)>=n) {
         return &(s[strlen(s)-n]);
 } else {
         return "";
 }
}

canonical_original_code:
char *strrcut(char *s, int n) {
        if (strlen(s)>=n) {
         return &(s[strlen(s)-n]);
 } else {
         return "";
 }
}

variable_types:
s
char *

variable_types: n int


strrcmp

decompiled_code:
int __fastcall strrcmp(char *s1, char *s2)
{
size_t v2; // rbx
size_t v3; // rax
const char *v4; // rax
int result; // eax
const char *v6; // rax

v2 = strlen(s1);
v3 = strlen(s2);
if ( v2 > v3 )
{
v6 = strrcut(s1, v3);
result = strcmp(v6, s2);
}
else
{
v4 = strrcut(s2, v2);
result = strcmp(s1, v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *s1, char *s2)
{
size_t v2; // rbx
size_t v3; // rax
const char *v4; // rax
int result; // eax
const char *v6; // rax

v2 = strlen(s1);
v3 = strlen(s2);
if ( v2 > v3 )
{
v6 = func2(s1, v3);
result = strcmp(v6, s2);
}
else
{
v4 = func2(s2, v2);
result = strcmp(s1, v4);
}
return result;
}

original_code:
int strrcmp(const char *s1, const char *s2) {
      if (strlen(s1)<=strlen(s2)) {
       return strcmp(s1,strrcut(s2,strlen(s1)));
      } else {
       return strcmp(strrcut(s1,strlen(s2)),s2);
      }
}

canonical_original_code:
int strrcmp(char *s1, char *s2) {
      if (strlen(s1)<=strlen(s2)) {
       return strcmp(s1,strrcut(s2,strlen(s1)));
      } else {
       return strcmp(strrcut(s1,strlen(s2)),s2);
      }
}


original_code:
int search_message_endp(struct usb_device *dev) {
        if ( ((dev->config[0].interface[0].altsetting[0].endpoint[0].bmAttributes & 0x03) == 2)
     &&((dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress & 0x80) == 0)) {
         return dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress;
 } else
         if ( ((dev->config[0].interface[0].altsetting[0].endpoint[1].bmAttributes & 0x03) == 2)
             &&((dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress & 0x80) == 0)) {
                 return dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress;
 }
 return 0;
}

variable_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *

user_defined_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor descriptor; struct usb_config_descriptor *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; }

user_defined_types: struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface *interface; unsigned char *extra; int extralen; }

user_defined_types: struct usb_interface { struct usb_interface_descriptor *altsetting; int num_altsetting; }

user_defined_types: struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor *endpoint; unsigned char *extra; int extralen; }


original_code:
int search_response_endp(struct usb_device *dev) {
        if ( ((dev->config[0].interface[0].altsetting[0].endpoint[0].bmAttributes & 0x03) == 2)
     &&((dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress & 0x80) == 0x80)) {
         return dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress;
 } else
         if ( ((dev->config[0].interface[0].altsetting[0].endpoint[1].bmAttributes & 0x03) == 2)
             &&((dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress & 0x80) == 0x80)) {
                 return dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress;
 }
 return 0;
}

user_defined_types: struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; }

user_defined_types: struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; }

user_defined_types: struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; }


version

decompiled_code:
void __noreturn version()
{
printf("racker-%.2f, © 2009-2010 Matthias Fassl\n\n", *(double *)&LC0);
printf("build machine: %s\nbuild date: %s\n", "5.15.0-139-generic x86_64 GNU/Linux", "2025-05-23");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
printf("racker-%.2f, © 2009-2010 Matthias Fassl\n\n", *(double *)&LC0);
printf("build machine: %s\nbuild date: %s\n", "5.15.0-139-generic x86_64 GNU/Linux", "2025-05-23");
exit(0);
}

original_code:
void version() {
        printf("racker-%.2f, © 2009-2010 Matthias Fassl\n\n",0.2);
 printf("build machine: %s\nbuild date: %s\n","5.15.0-100-generic x86_64 GNU/Linux","2024-04-20");
 exit(0);
}


usage

decompiled_code:
void __noreturn usage()
{
puts("Usage:");
puts("\t-v for version information");
puts("\t-f \"FILE\" specify which configuration file to use (necessary)");
puts("\t-d debug mode");
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts("Usage:");
puts("\t-v for version information");
puts("\t-f \"FILE\" specify which configuration file to use (necessary)");
puts("\t-d debug mode");
exit(1);
}

original_code:
void usage() {
 printf("Usage:\n");
 printf("\t-v for version information\n");
 printf("\t-f \"FILE\" specify which configuration file to use (necessary)\n");
 printf("\t-d debug mode\n");
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
__int64 v5; // rbp

debug = 0;
v3 = 0LL;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "dvf:");
if ( v4 == -1 )
break;
if ( v4 == 102 )
{
v3 = optarg;
}
else if ( v4 > 102 )
{
if ( v4 == 118 )
version();
}
else
{
if ( v4 == 63 )
goto LABEL_21;
if ( v4 == 100 )
debug = 1;
}
}
if ( !v3 )
{
if ( debug )
fwrite("You need to specify a configuration file\n", 1uLL, 0x29uLL, stderr);
else
syslog(3, "You need to specify a configuration file\n");
LABEL_21:
usage();
}
if ( debug || (openlog(*argv, 3, 24), debug) )
printf("----- racker is starting -----");
else
syslog(6, "----- racker is starting -----");
v5 = config_initialize(v3);
config_other(v5);
if ( !debug )
daemonize();
signal(15, (__sighandler_t)&sig_handler);
config_listeners(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
int v4; // eax
__int64 v5; // rbp

debug = 0;
v3 = 0LL;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "dvf:");
if ( v4 == -1 )
break;
if ( v4 == 102 )
{
v3 = optarg;
}
else if ( v4 > 102 )
{
if ( v4 == 118 )
func0();
}
else
{
if ( v4 == 63 )
goto LABEL_21;
if ( v4 == 100 )
debug = 1;
}
}
if ( !v3 )
{
if ( debug )
fwrite("You need to specify a configuration file\n", 1uLL, 0x29uLL, stderr);
else
syslog(3, "You need to specify a configuration file\n");
LABEL_21:
func1();
}
if ( debug || (openlog(*argv, 3, 24), debug) )
printf("----- racker is starting -----");
else
syslog(6, "----- racker is starting -----");
v5 = config_initialize(v3);
config_other(v5);
if ( !debug )
daemonize();
signal(15, (__sighandler_t)&sig_handler);
config_listeners(v5);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int c;
 char* configfile = ((void *)0);
 extern char *optarg;
 debug = 0;
 while ((c = getopt(argc, argv, "dvf:")) != -1) {
      switch(c) {
       case 'v':
    version();
    break;
       case 'f':
    configfile = optarg;
    break;
   case 'd':
    debug = 1;
    break;
       case '?':
    usage();
      }
 }
 if(configfile == ((void *)0)) {
  if(debug) { if(3 == 3) { fprintf(stderr,"You need to specify a configuration file\n"); } else { printf("You need to specify a configuration file\n"); } } else { syslog(3,"You need to specify a configuration file\n"); };
  usage();
 }
 if(!debug) {
  openlog(argv[0], 0x01|0x02, (3<<3));
 }
 if(debug) { if(6 == 3) { fprintf(stderr,"----- racker is starting -----"); } else { printf("----- racker is starting -----"); } } else { syslog(6,"----- racker is starting -----"); };
 config_t *cfg = config_initialize(configfile);
 config_other(cfg);
 if(!debug) {
  daemonize();
 }
 signal(15,sig_handler);
 config_listeners(cfg);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int c;
 char *configfile = ((void *)0);
 extern char *optarg;
 debug = 0;
 while ((c = getopt(argc, argv, "dvf:")) != -1) {
      switch(c) {
       case 'v':
    version();
    break;
       case 'f':
    configfile = optarg;
    break;
   case 'd':
    debug = 1;
    break;
       case '?':
    usage();
      }
 }
 if(configfile == ((void *)0)) {
  if(debug) { if(3 == 3) { fprintf(stderr,"You need to specify a configuration file\n"); } else { printf("You need to specify a configuration file\n"); } } else { syslog(3,"You need to specify a configuration file\n"); };
  usage();
 }
 if(!debug) {
  openlog(argv[0], 0x01|0x02, (3<<3));
 }
 if(debug) { if(6 == 3) { fprintf(stderr,"----- racker is starting -----"); } else { printf("----- racker is starting -----"); } } else { syslog(6,"----- racker is starting -----"); };
 struct config_t *cfg = config_initialize(configfile);
 config_other(cfg);
 if(!debug) {
  daemonize();
 }
 signal(15,sig_handler);
 config_listeners(cfg);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
configfile
char *

variable_types:
optarg
char *

variable_types: struct config_t { struct config_setting_t { char *name; short type; short format; union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t { unsigned int length; struct config_setting_t **elements; } *list; } value; struct config_setting_t *parent; struct config_t *config; void *hook; unsigned int line; char *file; } *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t { CONFIG_ERR_NONE=0, CONFIG_ERR_FILE_IO=1, CONFIG_ERR_PARSE=2 } error_type; char **filenames; unsigned int num_filenames; } *

user_defined_types: struct config_t { struct config_setting_t *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t error_type; char **filenames; unsigned int num_filenames; }

user_defined_types: struct config_setting_t { char *name; short type; short format; union config_value_t value; struct config_setting_t *parent; struct config_t *config; void *hook; unsigned int line; char *file; }

user_defined_types: union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t *list; }


decompiled_code:
__int64 __fastcall bind4(const char *a1, __int16 a2)
{
const char *v4; // rsi
void *v5; // rdx
unsigned int v6; // er12
struct sockaddr v8; // [rsp+0h] [rbp-18h] BYREF

v4 = a1;
v8.sa_family = 2;
*(_WORD *)v8.sa_data = _bswap_16(a2);
inet_pton(2, v4, v5);
v6 = socket(2, 2, 0);
if ( bind(v6, &v8, 0x10u) != -1 )
return v6;
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int16 a2)
{
const char *v4; // rsi
void *v5; // rdx
unsigned int v6; // er12
struct sockaddr v8; // [rsp+0h] [rbp-18h] BYREF

v4 = a1;
v8.sa_family = 2;
*(_WORD *)v8.sa_data = func0(a2);
inet_pton(2, v4, v5);
v6 = socket(2, 2, 0);
if ( bind(v6, &v8, 0x10u) != -1 )
return v6;
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
return v6;
}

original_code:
int bind4(const char* host, int port) {
 struct sockaddr_in ip4addr;
 int s;
 ip4addr.sin_family = 2;
 ip4addr.sin_port = htons(port);
 inet_pton(2, host, &ip4addr.sin_addr);
 s = socket(2, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr*)&ip4addr, sizeof ip4addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

canonical_original_code:
int bind4(char *host, int port) {
 struct sockaddr_in ip4addr;
 int s;
 ip4addr.sin_family = 2;
 ip4addr.sin_port = htons(port);
 inet_pton(2, host, &ip4addr.sin_addr);
 s = socket(2, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr *)&ip4addr, sizeof ip4addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

variable_types:
host
char *

variable_types: port int

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

variable_types: s int

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

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


decompiled_code:
__int64 __fastcall bind6(const char *a1, __int16 a2)
{
const char *v4; // rsi
void *v5; // rdx
unsigned int v6; // er12
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

v4 = a1;
v8.sa_family = 10;
*(_WORD *)v8.sa_data = _bswap_16(a2);
inet_pton(10, v4, v5);
v6 = socket(10, 2, 0);
if ( bind(v6, &v8, 0x1Cu) != -1 )
return v6;
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int16 a2)
{
const char *v4; // rsi
void *v5; // rdx
unsigned int v6; // er12
struct sockaddr v8; // [rsp+0h] [rbp-28h] BYREF

v4 = a1;
v8.sa_family = 10;
*(_WORD *)v8.sa_data = func0(a2);
inet_pton(10, v4, v5);
v6 = socket(10, 2, 0);
if ( bind(v6, &v8, 0x1Cu) != -1 )
return v6;
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
return v6;
}

original_code:
int bind6(const char* host, int port) {
 struct sockaddr_in6 ip6addr;
 int s;
 ip6addr.sin6_family = 10;
 ip6addr.sin6_port = htons(port);
 inet_pton(10, host, &ip6addr.sin6_addr);
 s = socket(10, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr*)&ip6addr, sizeof ip6addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

canonical_original_code:
int bind6(char *host, int port) {
 struct sockaddr_in6 ip6addr;
 int s;
 ip6addr.sin6_family = 10;
 ip6addr.sin6_port = htons(port);
 inet_pton(10, host, &ip6addr.sin6_addr);
 s = socket(10, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr *)&ip6addr, sizeof ip6addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
__int64 pack_announce4()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
char* pack_announce4(int *msgLen, struct bt_announce4_reply *reply) {
 return ((void *)0);
}

canonical_original_code:
char *pack_announce4(int *msgLen, struct bt_announce4_reply *reply) {
 return ((void *)0);
}

variable_types:
msgLen
int *

variable_types: struct bt_announce4_reply { int action; int transaction_id; int interval; int leechers; int seeders; struct bt_peer4 { unsigned int ipv4; unsigned short port; struct bt_peer4 *next; } *list; } *

user_defined_types: struct bt_announce4_reply { int action; int transaction_id; int interval; int leechers; int seeders; struct bt_peer4 *list; }


decompiled_code:
void __fastcall send_receive(int fd)
{
void *v1; // rsp
unsigned int v2; // ebx
unsigned int *v3; // r12
int v4; // eax
void *v5; // rbx
void *v6; // r15
__m128i *v7; // r13
__m128i *v8; // r15
__m128i v9; // [rsp+0h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-40h] BYREF

v1 = alloca(mtu);
memset(&v9, 0, mtu);
*_errno_location() = 0;
v9.m128i_i32[2] = 16;
v2 = recvfrom(fd, &v9, mtu, 0, &addr, &v9.m128i_u32[2]);
if ( v2 == -1 )
perror("couldn't receive data");
if ( debug )
printf("Received %d Bytes of Data\n", v2);
else
syslog(7, "Received %d Bytes of Data\n", v2);
v3 = (unsigned int *)unpack_connect(v2, (unsigned __int64 *)&v9);
v4 = v3[2];
if ( v4 == 2 )
{
puts("SCRAPE");
v7 = (__m128i *)(int)scrape((char *)&v9.m128i_u64[1] + 4, *(_QWORD *)v3, v3[3], &v9, v2);
goto LABEL_10;
}
if ( v4 > 2 )
{
if ( v4 == 4 )
{
puts("ANNOUNCE IPv6");
v7 = (__m128i *)(int)announce6((char *)&v9.m128i_u64[1] + 4, *(_QWORD *)v3, v3[3], &v9);
goto LABEL_10;
}
goto LABEL_18;
}
if ( v4 )
{
if ( v4 == 1 )
{
puts("ANNOUNCE IPv4");
v5 = (void *)unpack_announce4(v2, &v9);
v6 = (void *)(int)announce4(v5);
v7 = (__m128i *)pack_announce4((char *)&v9.m128i_u64[1] + 4, v6);
free(v5);
free(v6);
goto LABEL_10;
}
LABEL_18:
v7 = (__m128i *)(int)errormsg((char *)&v9.m128i_u64[1] + 4, v3[3], "Unkown action");
goto LABEL_10;
}
puts("CONNECT REQUEST");
v8 = (__m128i *)(int)connect_request(v3);
v7 = pack_connect(&v9.m128i_i32[3], v8);
free(v8);
LABEL_10:
if ( sendto(fd, v7, v9.m128i_i32[3], 0, &addr, v9.m128i_u32[2]) == -1 )
{
if ( debug )
fwrite("Couldn't send Data", 1uLL, 0x12uLL, stderr);
else
syslog(3, "Couldn't send Data");
}
free(v7);
free(v3);
}

canonical_decompiled_code:
void __fastcall func8(int fd)
{
void *v1; // rsp
unsigned int v2; // ebx
unsigned int *v3; // r12
int v4; // eax
void *v5; // rbx
void *v6; // r15
__m128i *v7; // r13
__m128i *v8; // r15
__m128i v9; // [rsp+0h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-40h] BYREF

v1 = alloca(mtu);
memset(&v9, 0, mtu);
*_errno_location() = 0;
v9.m128i_i32[2] = 16;
v2 = recvfrom(fd, &v9, mtu, 0, &addr, &v9.m128i_u32[2]);
if ( v2 == -1 )
perror("couldn't receive data");
if ( debug )
printf("Received %d Bytes of Data\n", v2);
else
syslog(7, "Received %d Bytes of Data\n", v2);
v3 = (unsigned int *)func5(v2, (unsigned __int64 *)&v9);
v4 = v3[2];
if ( v4 == 2 )
{
puts("SCRAPE");
v7 = (__m128i *)(int)scrape((char *)&v9.m128i_u64[1] + 4, *(_QWORD *)v3, v3[3], &v9, v2);
goto LABEL_10;
}
if ( v4 > 2 )
{
if ( v4 == 4 )
{
puts("ANNOUNCE IPv6");
v7 = (__m128i *)(int)announce6((char *)&v9.m128i_u64[1] + 4, *(_QWORD *)v3, v3[3], &v9);
goto LABEL_10;
}
goto LABEL_18;
}
if ( v4 )
{
if ( v4 == 1 )
{
puts("ANNOUNCE IPv4");
v5 = (void *)func6(v2, &v9);
v6 = (void *)(int)announce4(v5);
v7 = (__m128i *)func7((char *)&v9.m128i_u64[1] + 4, v6);
free(v5);
free(v6);
goto LABEL_10;
}
LABEL_18:
v7 = (__m128i *)(int)errormsg((char *)&v9.m128i_u64[1] + 4, v3[3], "Unkown action");
goto LABEL_10;
}
puts("CONNECT REQUEST");
v8 = (__m128i *)(int)connect_request(v3);
v7 = pack_connect(&v9.m128i_i32[3], v8);
free(v8);
LABEL_10:
if ( sendto(fd, v7, v9.m128i_i32[3], 0, &addr, v9.m128i_u32[2]) == -1 )
{
if ( debug )
fwrite("Couldn't send Data", 1uLL, 0x12uLL, stderr);
else
syslog(3, "Couldn't send Data");
}
free(v7);
free(v3);
}

original_code:
void send_receive(int sock) {
 char msg[mtu], *sbuffer;
 struct sockaddr_in cliAddr;
 int cliLen, msgLen, sbufLen;
 uint64_t connection_id;
 int32_t action;
 uint32_t transaction_id;
 memset(msg,0x0,mtu);
 (*__errno_location ()) = 0;
 cliLen = sizeof(struct sockaddr_in);
 msgLen = recvfrom(sock, msg, mtu, 0, (struct sockaddr *) &cliAddr, &cliLen);
 if(msgLen == -1) {
  perror("couldn't receive data");
 }
 if(debug) { if(7 == 3) { fprintf(stderr,"Received %d Bytes of Data\n",msgLen); } else { printf("Received %d Bytes of Data\n",msgLen); } } else { syslog(7,"Received %d Bytes of Data\n",msgLen); };
 struct bt_connect_request *request = unpack_connect(msgLen,msg);
 switch(request->action) {
  case 0:
   printf("CONNECT REQUEST\n");
   struct bt_connect_reply *reply_connect = (struct bt_connect_reply*) connect_request(request);
   sbuffer = (char*) pack_connect(&sbufLen,reply_connect);
   free(reply_connect);
   break;
  case 1:
   printf("ANNOUNCE IPv4\n");
   struct bt_announce4_request *request_announce4 = (struct bt_announce4_request*) unpack_announce4(msgLen,msg);
   struct bt_announce4_reply *reply_announce4 = (struct bt_announce4_reply*) announce4(request_announce4);
   sbuffer = (char*) pack_announce4(&sbufLen, reply_announce4);
   free(request_announce4);
   free(reply_announce4);
   break;
  case 2:
   printf("SCRAPE\n");
   sbuffer = (char*)scrape(&sbufLen,request->connection_id,request->transaction_id,msg,msgLen);
   break;
  case 4:
   printf("ANNOUNCE IPv6\n");
   sbuffer = (char*)announce6(&sbufLen,request->connection_id,request->transaction_id,msg);
   break;
  default:
   sbuffer = (char*)errormsg(&sbufLen,request->transaction_id,"Unkown action");
 }
 if(sendto(sock,sbuffer,sbufLen,0,(struct sockaddr*) &cliAddr,(socklen_t) cliLen) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"Couldn't send Data"); } else { printf("Couldn't send Data"); } } else { syslog(3,"Couldn't send Data"); };
 }
 free(sbuffer);
 free(request);
}

canonical_original_code:
void send_receive(int sock) {
 char msg[-1]; char *sbuffer;
 struct sockaddr_in cliAddr;
 int cliLen; int msgLen; int sbufLen;
 unsigned long connection_id;
 int action;
 unsigned int transaction_id;
 memset(msg,0x0,mtu);
 (*__errno_location ()) = 0;
 cliLen = sizeof(struct sockaddr_in);
 msgLen = recvfrom(sock, msg, mtu, 0, (struct sockaddr *) &cliAddr, &cliLen);
 if(msgLen == -1) {
  perror("couldn't receive data");
 }
 if(debug) { if(7 == 3) { fprintf(stderr,"Received %d Bytes of Data\n",msgLen); } else { printf("Received %d Bytes of Data\n",msgLen); } } else { syslog(7,"Received %d Bytes of Data\n",msgLen); };
 struct bt_connect_request *request = unpack_connect(msgLen,msg);
 switch(request->action) {
  case 0:
   printf("CONNECT REQUEST\n");
   struct bt_connect_reply *reply_connect = (struct bt_connect_reply*) connect_request(request);
   sbuffer = (char *) pack_connect(&sbufLen,reply_connect);
   free(reply_connect);
   break;
  case 1:
   printf("ANNOUNCE IPv4\n");
   struct bt_announce4_request *request_announce4 = (struct bt_announce4_request*) unpack_announce4(msgLen,msg);
   struct bt_announce4_reply *reply_announce4 = (struct bt_announce4_reply*) announce4(request_announce4);
   sbuffer = (char *) pack_announce4(&sbufLen, reply_announce4);
   free(request_announce4);
   free(reply_announce4);
   break;
  case 2:
   printf("SCRAPE\n");
   sbuffer = (char *)scrape(&sbufLen,request->connection_id,request->transaction_id,msg,msgLen);
   break;
  case 4:
   printf("ANNOUNCE IPv6\n");
   sbuffer = (char *)announce6(&sbufLen,request->connection_id,request->transaction_id,msg);
   break;
  default:
   sbuffer = (char *)errormsg(&sbufLen,request->transaction_id,"Unkown action");
 }
 if(sendto(sock,sbuffer,sbufLen,0,(struct sockaddr *) &cliAddr,(unsigned int) cliLen) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"Couldn't send Data"); } else { printf("Couldn't send Data"); } } else { syslog(3,"Couldn't send Data"); };
 }
 free(sbuffer);
 free(request);
}

variable_types: sock int

variable_types:
msg
char [-1]

variable_types:
sbuffer
char *

variable_types: cliLen int

variable_types: msgLen int

variable_types: sbufLen int

variable_types: action int

variable_types: struct bt_connect_request { long connection_id; int action; int transaction_id; } *

variable_types: struct bt_connect_reply { int action; int transaction_id; long connection_id; } *

variable_types: struct bt_announce4_request { long connection_id; int action; int transaction_id; char info_hash[20]; char peer_id[20]; long downloaded; long left; long uploaded; int event; unsigned int ip; unsigned int key; int num_want; unsigned short port; unsigned short extensions; } *

user_defined_types: struct bt_peer4 { unsigned int ipv4; unsigned short port; struct bt_peer4 *next; }


decompiled_code:
void __noreturn check_readable_socket()
{
int v0; // eax
int v1; // edi
int *v2; // rsi
__int64 v3; // r8
int v4; // edx
int v5; // eax
int v6; // edi
__int64 v7; // r12
unsigned __int64 v8; // r14
int v9; // edi
int v10; // eax
fd_set vars0; // [rsp+0h] [rbp+0h] BYREF

while ( 1 )
{
memset(&vars0, 0, sizeof(vars0));
v0 = num_sockets - 1;
if ( num_sockets )
{
v1 = 0;
v2 = (int *)(sockets + 4LL * v0);
v3 = (__int64)&v2[-v0 - 1];
do
{
v4 = *v2;
v5 = *v2 + 63;
if ( *v2 >= 0 )
v5 = *v2;
vars0.fds_bits[v5 >> 6] |= 1LL << (*v2 % 64);
if ( v1 < v4 )
v1 = v4;
--v2;
}
while ( (int *)v3 != v2 );
v6 = v1 + 1;
}
else
{
v6 = 1;
}
select(v6, &vars0, 0LL, 0LL, 0LL);
if ( num_sockets )
{
v7 = 4LL * (num_sockets - 1);
v8 = 4 * (num_sockets - (unsigned __int64)(unsigned int)(num_sockets - 1)) - 8;
do
{
v9 = *(_DWORD *)(sockets + v7);
v10 = v9 + 63;
if ( v9 >= 0 )
v10 = *(_DWORD *)(sockets + v7);
if ( (vars0.fds_bits[v10 >> 6] & (1LL << (*(_DWORD *)(sockets + v7) % 64))) != 0 )
send_receive(v9);
v7 -= 4LL;
}
while ( v8 != v7 );
}
}
}

canonical_decompiled_code:
void __noreturn func9()
{
int v0; // eax
int v1; // edi
int *v2; // rsi
__int64 v3; // r8
int v4; // edx
int v5; // eax
int v6; // edi
__int64 v7; // r12
unsigned __int64 v8; // r14
int v9; // edi
int v10; // eax
fd_set vars0; // [rsp+0h] [rbp+0h] BYREF

while ( 1 )
{
memset(&vars0, 0, sizeof(vars0));
v0 = num_sockets - 1;
if ( num_sockets )
{
v1 = 0;
v2 = (int *)(sockets + 4LL * v0);
v3 = (__int64)&v2[-v0 - 1];
do
{
v4 = *v2;
v5 = *v2 + 63;
if ( *v2 >= 0 )
v5 = *v2;
vars0.fds_bits[v5 >> 6] |= 1LL << (*v2 % 64);
if ( v1 < v4 )
v1 = v4;
--v2;
}
while ( (int *)v3 != v2 );
v6 = v1 + 1;
}
else
{
v6 = 1;
}
select(v6, &vars0, 0LL, 0LL, 0LL);
if ( num_sockets )
{
v7 = 4LL * (num_sockets - 1);
v8 = 4 * (num_sockets - (unsigned __int64)(unsigned int)(num_sockets - 1)) - 8;
do
{
v9 = *(_DWORD *)(sockets + v7);
v10 = v9 + 63;
if ( v9 >= 0 )
v10 = *(_DWORD *)(sockets + v7);
if ( (vars0.fds_bits[v10 >> 6] & (1LL << (*(_DWORD *)(sockets + v7) % 64))) != 0 )
func8(v9);
v7 -= 4LL;
}
while ( v8 != v7 );
}
}
}

original_code:
void check_readable_socket() {
 fd_set fds;
 int numfds, maxfd;
 while(1) {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  numfds = num_sockets;
  maxfd = 0;
  while(numfds--) {
   ((void) (((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))));
   if(sockets[numfds] > maxfd) {
    maxfd = sockets[numfds];
   }
  }
  select(maxfd+1,&fds,((void *)0),((void *)0),((void *)0));
  numfds = num_sockets;
  while(numfds--) {
   if(((((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    send_receive(sockets[numfds]);
   }
  }
 }
}

canonical_original_code:
void check_readable_socket() {
 struct fd_set fds;
 int numfds; int maxfd;
 while(1) {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  numfds = num_sockets;
  maxfd = 0;
  while(numfds--) {
   ((void) (((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))));
   if(sockets[numfds] > maxfd) {
    maxfd = sockets[numfds];
   }
  }
  select(maxfd+1,&fds,((void *)0),((void *)0),((void *)0));
  numfds = num_sockets;
  while(numfds--) {
   if(((((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    send_receive(sockets[numfds]);
   }
  }
 }
}

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

variable_types: numfds int

variable_types: maxfd int


decompiled_code:
__int64 announce4()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
struct bt_announce4_reply* announce4(struct bt_announce4_request *request) {
 return ((void *)0);
}

canonical_original_code:
struct bt_announce4_reply *announce4(struct bt_announce4_request *request) {
 return ((void *)0);
}

return_type: struct bt_announce4_reply { int action; int transaction_id; int interval; int leechers; int seeders; struct bt_peer4 { unsigned int ipv4; unsigned short port; struct bt_peer4 *next; } *list; } *

user_defined_types: struct bt_announce4_request { long connection_id; int action; int transaction_id; char info_hash[20]; char peer_id[20]; long downloaded; long left; long uploaded; int event; unsigned int ip; unsigned int key; int num_want; unsigned short port; unsigned short extensions; }