decompiled_code:
char *__fastcall vsf_parseconf_load_setting(char *a1, int a2)
{
char **v4; // rbp
char *v5; // rsi
char *v6; // rbx
char *result; // rax
char **v8; // rbp
char *v9; // rsi
__int64 v10; // rax
char **v11; // rbp
char *v12; // rsi
char *v13; // rbx
int v14; // er8
__int64 v15; // rax
__int64 v16; // rax

while ( (unsigned int)vsf_sysutil_isspace((unsigned int)*a1) )
++a1;
str_alloc_text(&s_setting_str_1, a1);
str_split_char(&s_setting_str_1, &s_value_str_0, 61LL);
if ( parseconf_str_array )
{
v4 = &parseconf_str_array;
while ( !(unsigned int)str_equal_text(&s_setting_str_1) )
{
v5 = v4[2];
v4 += 2;
if ( !v5 )
goto LABEL_13;
}
v6 = v4[1];
if ( *(_QWORD *)v6 )
vsf_sysutil_free();
result = (char *)str_isempty(&s_value_str_0);
if ( (_DWORD)result )
{
*(_QWORD *)v6 = 0LL;
}
else
{
result = (char *)str_strdup(&s_value_str_0);
*(_QWORD *)v6 = result;
}
}
else
{
LABEL_13:
result = (char *)str_isempty(&s_value_str_0);
if ( (_DWORD)result )
{
if ( !a2 )
return result;
v10 = str_getbuf(&s_setting_str_1);
result = (char *)die2("missing value in config file for: ", v10);
}
if ( parseconf_bool_array )
{
v8 = &parseconf_bool_array;
while ( 1 )
{
result = (char *)str_equal_text(&s_setting_str_1);
if ( (_DWORD)result )
break;
v9 = v8[2];
v8 += 2;
if ( !v9 )
goto LABEL_22;
}
str_upper(&s_value_str_0);
if ( (unsigned int)str_equal_text(&s_value_str_0)
|| (unsigned int)str_equal_text(&s_value_str_0)
|| (unsigned int)str_equal_text(&s_value_str_0) )
{
result = v8[1];
*(_DWORD *)result = 1;
}
else if ( (unsigned int)str_equal_text(&s_value_str_0)
|| (unsigned int)str_equal_text(&s_value_str_0)
|| (result = (char *)str_equal_text(&s_value_str_0), (_DWORD)result) )
{
result = v8[1];
*(_DWORD *)result = 0;
}
else if ( a2 )
{
v16 = str_getbuf(&s_setting_str_1);
result = (char *)die2("bad bool value in config file for: ", v16);
}
}
else
{
LABEL_22:
if ( parseconf_uint_array )
{
v11 = &parseconf_uint_array;
while ( 1 )
{
result = (char *)str_equal_text(&s_setting_str_1);
if ( (_DWORD)result )
break;
v12 = v11[2];
v11 += 2;
if ( !v12 )
goto LABEL_31;
}
if ( (unsigned int)str_isempty(&s_value_str_0) || (unsigned __int8)str_get_char_at(&s_value_str_0, 0LL) != 48 )
{
v14 = str_atoi(&s_value_str_0);
result = v11[1];
*(_DWORD *)result = v14;
}
else
{
v13 = v11[1];
result = (char *)str_octal_to_uint(&s_value_str_0);
*(_DWORD *)v13 = (_DWORD)result;
}
}
else
{
LABEL_31:
if ( a2 )
{
v15 = str_getbuf(&s_setting_str_1);
result = (char *)die2("unrecognised variable in config file: ", v15);
}
}
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1, int a2)
{
char **v4; // rbp
char *v5; // rsi
char *v6; // rbx
char *result; // rax
char **v8; // rbp
char *v9; // rsi
__int64 v10; // rax
char **v11; // rbp
char *v12; // rsi
char *v13; // rbx
int v14; // er8
__int64 v15; // rax
__int64 v16; // rax

while ( (unsigned int)vsf_sysutil_isspace((unsigned int)*a1) )
++a1;
str_alloc_text(&s_setting_str_1, a1);
str_split_char(&s_setting_str_1, &s_value_str_0, 61LL);
if ( parseconf_str_array )
{
v4 = &parseconf_str_array;
while ( !(unsigned int)str_equal_text(&s_setting_str_1) )
{
v5 = v4[2];
v4 += 2;
if ( !v5 )
goto LABEL_13;
}
v6 = v4[1];
if ( *(_QWORD *)v6 )
vsf_sysutil_free();
result = (char *)str_isempty(&s_value_str_0);
if ( (_DWORD)result )
{
*(_QWORD *)v6 = 0LL;
}
else
{
result = (char *)str_strdup(&s_value_str_0);
*(_QWORD *)v6 = result;
}
}
else
{
LABEL_13:
result = (char *)str_isempty(&s_value_str_0);
if ( (_DWORD)result )
{
if ( !a2 )
return result;
v10 = str_getbuf(&s_setting_str_1);
result = (char *)die2("missing value in config file for: ", v10);
}
if ( parseconf_bool_array )
{
v8 = &parseconf_bool_array;
while ( 1 )
{
result = (char *)str_equal_text(&s_setting_str_1);
if ( (_DWORD)result )
break;
v9 = v8[2];
v8 += 2;
if ( !v9 )
goto LABEL_22;
}
str_upper(&s_value_str_0);
if ( (unsigned int)str_equal_text(&s_value_str_0)
|| (unsigned int)str_equal_text(&s_value_str_0)
|| (unsigned int)str_equal_text(&s_value_str_0) )
{
result = v8[1];
*(_DWORD *)result = 1;
}
else if ( (unsigned int)str_equal_text(&s_value_str_0)
|| (unsigned int)str_equal_text(&s_value_str_0)
|| (result = (char *)str_equal_text(&s_value_str_0), (_DWORD)result) )
{
result = v8[1];
*(_DWORD *)result = 0;
}
else if ( a2 )
{
v16 = str_getbuf(&s_setting_str_1);
result = (char *)die2("bad bool value in config file for: ", v16);
}
}
else
{
LABEL_22:
if ( parseconf_uint_array )
{
v11 = &parseconf_uint_array;
while ( 1 )
{
result = (char *)str_equal_text(&s_setting_str_1);
if ( (_DWORD)result )
break;
v12 = v11[2];
v11 += 2;
if ( !v12 )
goto LABEL_31;
}
if ( (unsigned int)str_isempty(&s_value_str_0) || (unsigned __int8)str_get_char_at(&s_value_str_0, 0LL) != 48 )
{
v14 = str_atoi(&s_value_str_0);
result = v11[1];
*(_DWORD *)result = v14;
}
else
{
v13 = v11[1];
result = (char *)str_octal_to_uint(&s_value_str_0);
*(_DWORD *)v13 = (_DWORD)result;
}
}
else
{
LABEL_31:
if ( a2 )
{
v15 = str_getbuf(&s_setting_str_1);
result = (char *)die2("unrecognised variable in config file: ", v15);
}
}
}
}
return result;
}

original_code:
void
vsf_parseconf_load_setting(const char* p_setting, int errs_fatal)
{
  static struct mystr s_setting_str;
  static struct mystr s_value_str;
  while (vsf_sysutil_isspace(*p_setting))
  {
    p_setting++;
  }
  str_alloc_text(&s_setting_str, p_setting);
  str_split_char(&s_setting_str, &s_value_str, '=');
  {
    const struct parseconf_str_setting* p_str_setting = parseconf_str_array;
    while (p_str_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_str_setting->p_setting_name))
      {
        const char** p_curr_setting = p_str_setting->p_variable;
        if (*p_curr_setting)
        {
          vsf_sysutil_free((char*) *p_curr_setting);
        }
        if (str_isempty(&s_value_str))
        {
          *p_curr_setting = 0;
        }
        else
        {
          *p_curr_setting = str_strdup(&s_value_str);
        }
        return;
      }
      p_str_setting++;
    }
  }
  if (str_isempty(&s_value_str))
  {
    if (errs_fatal)
    {
      die2("missing value in config file for: ", str_getbuf(&s_setting_str));
    }
    else
    {
      return;
    }
  }
  {
    const struct parseconf_bool_setting* p_bool_setting = parseconf_bool_array;
    while (p_bool_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_bool_setting->p_setting_name))
      {
        str_upper(&s_value_str);
        if (str_equal_text(&s_value_str, "YES") ||
            str_equal_text(&s_value_str, "TRUE") ||
            str_equal_text(&s_value_str, "1"))
        {
          *(p_bool_setting->p_variable) = 1;
        }
        else if (str_equal_text(&s_value_str, "NO") ||
                 str_equal_text(&s_value_str, "FALSE") ||
                 str_equal_text(&s_value_str, "0"))
        {
          *(p_bool_setting->p_variable) = 0;
        }
        else if (errs_fatal)
        {
          die2("bad bool value in config file for: ",
               str_getbuf(&s_setting_str));
        }
        return;
      }
      p_bool_setting++;
    }
  }
  {
    const struct parseconf_uint_setting* p_uint_setting = parseconf_uint_array;
    while (p_uint_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_uint_setting->p_setting_name))
      {
        if (!str_isempty(&s_value_str) &&
            str_get_char_at(&s_value_str, 0) == '0')
        {
          *(p_uint_setting->p_variable) = str_octal_to_uint(&s_value_str);
        }
        else
        {
          *(p_uint_setting->p_variable) = str_atoi(&s_value_str);
        }
        return;
      }
      p_uint_setting++;
    }
  }
  if (errs_fatal)
  {
    die2("unrecognised variable in config file: ", str_getbuf(&s_setting_str));
  }
}

canonical_original_code:
void vsf_parseconf_load_setting(char *p_setting, int errs_fatal)
{
  static struct mystr s_setting_str;
  static struct mystr s_value_str;
  while (vsf_sysutil_isspace(*p_setting))
  {
    p_setting++;
  }
  str_alloc_text(&s_setting_str, p_setting);
  str_split_char(&s_setting_str, &s_value_str, '=');
  {
    struct parseconf_str_setting *p_str_setting = parseconf_str_array;
    while (p_str_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_str_setting->p_setting_name))
      {
        char **p_curr_setting = p_str_setting->p_variable;
        if (*p_curr_setting)
        {
          vsf_sysutil_free((char *) *p_curr_setting);
        }
        if (str_isempty(&s_value_str))
        {
          *p_curr_setting = 0;
        }
        else
        {
          *p_curr_setting = str_strdup(&s_value_str);
        }
        return;
      }
      p_str_setting++;
    }
  }
  if (str_isempty(&s_value_str))
  {
    if (errs_fatal)
    {
      die2("missing value in config file for: ", str_getbuf(&s_setting_str));
    }
    else
    {
      return;
    }
  }
  {
    struct parseconf_bool_setting *p_bool_setting = parseconf_bool_array;
    while (p_bool_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_bool_setting->p_setting_name))
      {
        str_upper(&s_value_str);
        if (str_equal_text(&s_value_str, "YES") ||
            str_equal_text(&s_value_str, "TRUE") ||
            str_equal_text(&s_value_str, "1"))
        {
          *(p_bool_setting->p_variable) = 1;
        }
        else if (str_equal_text(&s_value_str, "NO") ||
                 str_equal_text(&s_value_str, "FALSE") ||
                 str_equal_text(&s_value_str, "0"))
        {
          *(p_bool_setting->p_variable) = 0;
        }
        else if (errs_fatal)
        {
          die2("bad bool value in config file for: ",
               str_getbuf(&s_setting_str));
        }
        return;
      }
      p_bool_setting++;
    }
  }
  {
    struct parseconf_uint_setting *p_uint_setting = parseconf_uint_array;
    while (p_uint_setting->p_setting_name != 0)
    {
      if (str_equal_text(&s_setting_str, p_uint_setting->p_setting_name))
      {
        if (!str_isempty(&s_value_str) &&
            str_get_char_at(&s_value_str, 0) == '0')
        {
          *(p_uint_setting->p_variable) = str_octal_to_uint(&s_value_str);
        }
        else
        {
          *(p_uint_setting->p_variable) = str_atoi(&s_value_str);
        }
        return;
      }
      p_uint_setting++;
    }
  }
  if (errs_fatal)
  {
    die2("unrecognised variable in config file: ", str_getbuf(&s_setting_str));
  }
}

variable_types: struct parseconf_str_setting { char *p_setting_name; char **p_variable; } *

variable_types: struct parseconf_bool_setting { char *p_setting_name; int *p_variable; } *

variable_types: struct parseconf_uint_setting { char *p_setting_name; unsigned int *p_variable; } *


repo: arrrbiter/flowftpd

decompiled_code:
__int64 ssl_write()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func10()
{
return 0xFFFFFFFFLL;
}

original_code:
int
ssl_write(void* p_ssl, const char* p_buf, unsigned int len)
{
  (void) p_ssl;
  (void) p_buf;
  (void) len;
  return -1;
}

canonical_original_code:
int ssl_write(void *p_ssl, char *p_buf, unsigned int len)
{
  (void) p_ssl;
  (void) p_buf;
  (void) len;
  return -1;
}

variable_types:
len
unsigned int

return_type: int


decompiled_code:
__int64 ssl_write_str()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0xFFFFFFFFLL;
}

original_code:
int
ssl_write_str(void* p_ssl, const struct mystr* p_str)
{
  (void) p_ssl;
  (void) p_str;
  return -1;
}

canonical_original_code:
int ssl_write_str(void *p_ssl, struct mystr *p_str)
{
  (void) p_ssl;
  (void) p_str;
  return -1;
}

variable_types: struct mystr { char *PRIVATE_HANDS_OFF_p_buf; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; } *


bug

decompiled_code:
__int64 __fastcall bug(__int64 a1)
{
unsigned int v1; // eax

vsf_sysutil_activate_noblock(0LL);
vsf_sysutil_write_loop(0LL, "500 OOPS: ", 10LL);
v1 = vsf_sysutil_strlen(a1);
vsf_sysutil_write_loop(0LL, a1, v1);
vsf_sysutil_write_loop(0LL, "\r\n", 2LL);
return vsf_sysutil_exit(1LL);
}

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

vsf_sysutil_activate_noblock(0LL);
vsf_sysutil_write_loop(0LL, "500 OOPS: ", 10LL);
v1 = vsf_sysutil_strlen(a1);
vsf_sysutil_write_loop(0LL, a1, v1);
vsf_sysutil_write_loop(0LL, "\r\n", 2LL);
return vsf_sysutil_exit(1LL);
}

original_code:
void
bug(const char* p_text)
{
  vsf_sysutil_activate_noblock(0);
  (void) vsf_sysutil_write_loop(0, "500 OOPS: ", 10);
  (void) vsf_sysutil_write_loop(0, p_text,
                                vsf_sysutil_strlen(p_text));
  (void) vsf_sysutil_write_loop(0, "\r\n", 2);
  vsf_sysutil_exit(1);
}

canonical_original_code:
void bug(char *p_text)
{
  vsf_sysutil_activate_noblock(0);
  (void) vsf_sysutil_write_loop(0, "500 OOPS: ", 10);
  (void) vsf_sysutil_write_loop(0, p_text,
                                vsf_sysutil_strlen(p_text));
  (void) vsf_sysutil_write_loop(0, "\r\n", 2);
  vsf_sysutil_exit(1);
}

return_type: void


die

decompiled_code:
__int64 __fastcall die(__int64 a1)
{
bug(a1);
return vsf_sysutil_exit(1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
func0(a1);
return vsf_sysutil_exit(1LL);
}

original_code:
void
die(const char* p_text)
{
  bug(p_text);
  vsf_sysutil_exit(1);
}

canonical_original_code:
void die(char *p_text)
{
  bug(p_text);
  vsf_sysutil_exit(1);
}


decompiled_code:
__int64 __fastcall die2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
str_alloc_text(v4, a1);
str_append_text(v4, a2);
v2 = str_getbuf(v4);
return die(v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = 0LL;
v4[1] = 0LL;
str_alloc_text(v4, a1);
str_append_text(v4, a2);
v2 = str_getbuf(v4);
return func1(v2);
}

original_code:
void
die2(const char* p_text1, const char* p_text2)
{
  struct mystr die_str = { (void*)0, 0, 0 };
  str_alloc_text(&die_str, p_text1);
  str_append_text(&die_str, p_text2);
  die(str_getbuf(&die_str));
}

canonical_original_code:
void die2(char *p_text1, char *p_text2)
{
  struct mystr die_str = { (void*)0, 0, 0 };
  str_alloc_text(&die_str, p_text1);
  str_append_text(&die_str, p_text2);
  die(str_getbuf(&die_str));
}

variable_types: struct mystr { char *PRIVATE_HANDS_OFF_p_buf; unsigned int PRIVATE_HANDS_OFF_len; unsigned int PRIVATE_HANDS_OFF_alloc_bytes; }


decompiled_code:
__int64 __fastcall vsf_exit(__int64 a1)
{
unsigned int v1; // eax

v1 = vsf_sysutil_strlen(a1);
vsf_sysutil_write_loop(0LL, a1, v1);
return vsf_sysutil_exit(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // eax

v1 = vsf_sysutil_strlen(a1);
vsf_sysutil_write_loop(0LL, a1, v1);
return vsf_sysutil_exit(0LL);
}

original_code:
void
vsf_exit(const char* p_text)
{
  (void) vsf_sysutil_write_loop(0, p_text,
                                vsf_sysutil_strlen(p_text));
  vsf_sysutil_exit(0);
}

canonical_original_code:
void vsf_exit(char *p_text)
{
  (void) vsf_sysutil_write_loop(0, p_text,
                                vsf_sysutil_strlen(p_text));
  vsf_sysutil_exit(0);
}


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

result = vsf_sysutil_running_as_root();
if ( !(_DWORD)result )
result = die("flowftpd: must be started as root (see run_as_launching_user option)");
return result;
}

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

result = vsf_sysutil_running_as_root();
if ( !(_DWORD)result )
result = die("flowftpd: must be started as root (see run_as_launching_user option)");
return result;
}

original_code:
static void
die_unless_privileged(void)
{
  if (!vsf_sysutil_running_as_root())
  {
    die("flowftpd" ": must be started as root (see run_as_launching_user option)");
  }
}

canonical_original_code:
static void die_unless_privileged()
{
  if (!vsf_sysutil_running_as_root())
  {
    die("flowftpd" ": must be started as root (see run_as_launching_user option)");
  }
}


decompiled_code:
__int64 env_init()
{
vsf_sysutil_make_session_leader();
vsf_sysutil_set_umask(63LL);
vsf_sysutil_tzset();
return vsf_sysutil_install_null_sighandler(4LL);
}

canonical_decompiled_code:
__int64 func3()
{
vsf_sysutil_make_session_leader();
vsf_sysutil_set_umask(63LL);
vsf_sysutil_tzset();
return vsf_sysutil_install_null_sighandler(4LL);
}

original_code:
static void
env_init(void)
{
  vsf_sysutil_make_session_leader();
  vsf_sysutil_set_umask(077);
  vsf_sysutil_tzset();
  vsf_sysutil_install_null_sighandler(kVSFSysUtilSigPIPE);
}

canonical_original_code:
static void env_init()
{
  vsf_sysutil_make_session_leader();
  vsf_sysutil_set_umask(077);
  vsf_sysutil_tzset();
  vsf_sysutil_install_null_sighandler(kVSFSysUtilSigPIPE);
}


decompiled_code:
__int64 limits_init()
{
return vsf_sysutil_set_address_space_limit((-(__int64)(tunable_text_userdb_names == 0) & 0xFFFFFFFFF3800000LL) + 314572800);
}

canonical_decompiled_code:
__int64 func4()
{
return vsf_sysutil_set_address_space_limit((-(__int64)(tunable_text_userdb_names == 0) & 0xFFFFFFFFF3800000LL) + 314572800);
}

original_code:
static void
limits_init(void)
{
  unsigned long limit = 100UL * 1024 * 1024;
  if (tunable_text_userdb_names)
  {
    limit *= 3;
  }
  vsf_sysutil_set_address_space_limit(limit);
}

canonical_original_code:
static void limits_init()
{
  unsigned long limit = 100UL * 1024 * 1024;
  if (tunable_text_userdb_names)
  {
    limit *= 3;
  }
  vsf_sysutil_set_address_space_limit(limit);
}

variable_types:
limit
unsigned long


decompiled_code:
_BOOL8 __fastcall vsf_log_type_is_transfer(int a1)
{
return (unsigned int)(a1 - 2) <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
return (unsigned int)(a1 - 2) <= 1;
}

original_code:
static int
vsf_log_type_is_transfer(enum EVSFLogEntryType type)
{
  return (type == kVSFLogEntryDownload || type == kVSFLogEntryUpload);
}

variable_types: enum EVSFLogEntryType { kVSFLogEntryNull=1, kVSFLogEntryDownload=2, kVSFLogEntryUpload=3, kVSFLogEntryMkdir=4, kVSFLogEntryLogin=5, kVSFLogEntryFTPInput=6, kVSFLogEntryFTPOutput=7, kVSFLogEntryConnection=8, kVSFLogEntryDelete=9, kVSFLogEntryRename=10, kVSFLogEntryRmdir=11, kVSFLogEntryChmod=12, kVSFLogEntryDebug=13 }


decompiled_code:
__int64 vsf_cmdio_sock_setup()
{
vsf_sysutil_activate_keepalive(0LL);
vsf_sysutil_set_nodelay(0LL);
return vsf_sysutil_activate_oobinline(0LL);
}

canonical_decompiled_code:
__int64 func2()
{
vsf_sysutil_activate_keepalive(0LL);
vsf_sysutil_set_nodelay(0LL);
return vsf_sysutil_activate_oobinline(0LL);
}

original_code:
void
vsf_cmdio_sock_setup(void)
{
  vsf_sysutil_activate_keepalive(0);
  vsf_sysutil_set_nodelay(0);
  vsf_sysutil_activate_oobinline(0);
}

canonical_original_code:
void vsf_cmdio_sock_setup()
{
  vsf_sysutil_activate_keepalive(0);
  vsf_sysutil_set_nodelay(0);
  vsf_sysutil_activate_oobinline(0);
}


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

result = tunable_delay_failed_login;
if ( tunable_delay_failed_login )
result = vsf_sysutil_sleep((double)tunable_delay_failed_login);
return result;
}

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

result = tunable_delay_failed_login;
if ( tunable_delay_failed_login )
result = vsf_sysutil_sleep((double)tunable_delay_failed_login);
return result;
}

original_code:
static void check_login_delay()
{
  if (tunable_delay_failed_login)
  {
    vsf_sysutil_sleep((double) tunable_delay_failed_login);
  }
}


decompiled_code:
void ptrace_sandbox_attach_point()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void
ptrace_sandbox_attach_point(void)
{
}

canonical_original_code:
void ptrace_sandbox_attach_point()
{
}


decompiled_code:
void tunables_load_defaults()
{
tunable_anonymous_enable = 1;
tunable_local_enable = 0;
tunable_pasv_enable = 1;
tunable_port_enable = 1;
tunable_chroot_local_user = 0;
tunable_write_enable = 0;
tunable_anon_upload_enable = 0;
tunable_anon_mkdir_write_enable = 0;
tunable_anon_other_write_enable = 0;
tunable_chown_uploads = 0;
tunable_connect_from_port_20 = 0;
tunable_xferlog_enable = 0;
tunable_dirmessage_enable = 0;
tunable_anon_world_readable_only = 1;
tunable_async_abor_enable = 0;
tunable_ascii_upload_enable = 0;
tunable_ascii_download_enable = 0;
tunable_one_process_model = 0;
tunable_xferlog_std_format = 0;
tunable_pasv_promiscuous = 0;
tunable_deny_email_enable = 0;
tunable_chroot_list_enable = 0;
tunable_setproctitle_enable = 0;
tunable_text_userdb_names = 0;
tunable_ls_recurse_enable = 0;
tunable_log_ftp_protocol = 0;
tunable_guest_enable = 0;
tunable_userlist_enable = 0;
tunable_userlist_deny = 1;
tunable_use_localtime = 0;
tunable_check_shell = 1;
tunable_hide_ids = 0;
tunable_listen = 0;
tunable_port_promiscuous = 0;
tunable_passwd_chroot_enable = 0;
tunable_no_anon_password = 0;
tunable_tcp_wrappers = 0;
tunable_use_sendfile = 1;
tunable_force_dot_files = 0;
tunable_listen_ipv6 = 0;
tunable_dual_log_enable = 0;
tunable_syslog_enable = 0;
tunable_background = 0;
tunable_virtual_use_local_privs = 0;
tunable_session_support = 0;
tunable_download_enable = 1;
tunable_dirlist_enable = 1;
tunable_chmod_enable = 1;
tunable_secure_email_list_enable = 0;
tunable_run_as_launching_user = 0;
tunable_no_log_lock = 0;
tunable_ssl_enable = 0;
tunable_allow_anon_ssl = 0;
tunable_force_local_logins_ssl = 1;
tunable_force_local_data_ssl = 1;
tunable_sslv2 = 0;
tunable_sslv3 = 0;
tunable_tlsv1 = 1;
tunable_tilde_user_enable = 0;
tunable_force_anon_logins_ssl = 0;
tunable_force_anon_data_ssl = 0;
tunable_mdtm_write = 1;
tunable_lock_upload_files = 1;
tunable_pasv_addr_resolve = 0;
tunable_debug_ssl = 0;
tunable_require_cert = 0;
tunable_validate_cert = 0;
tunable_strict_ssl_read_eof = 0;
tunable_strict_ssl_write_shutdown = 0;
tunable_ssl_request_cert = 1;
tunable_delete_failed_uploads = 0;
tunable_implicit_ssl = 0;
tunable_sandbox = 0;
tunable_require_ssl_reuse = 1;
tunable_isolate = 1;
tunable_isolate_network = 1;
tunable_ftp_enable = 1;
tunable_http_enable = 0;
tunable_calc_crc32 = 0;
tunable_accept_timeout = 60;
tunable_connect_timeout = 60;
tunable_local_umask = 63;
tunable_anon_umask = 63;
tunable_ftp_data_port = 20;
tunable_idle_session_timeout = 300;
tunable_data_connection_timeout = 300;
tunable_pasv_min_port = 5001;
tunable_pasv_max_port = 0;
tunable_anon_max_rate = 0;
tunable_local_max_rate = 0;
tunable_listen_port = 21;
tunable_max_clients = 2000;
tunable_file_open_mode = 438;
tunable_max_per_ip = 50;
tunable_trans_chunk_size = 0;
tunable_delay_failed_login = 1;
tunable_delay_successful_login = 0;
tunable_max_login_fails = 3;
tunable_chown_upload_mode = 384;
install_str_setting((__int64)"/usr/share/empty", &tunable_secure_chroot_dir);
install_str_setting((__int64)"ftp", &tunable_ftp_username);
install_str_setting((__int64)"root", &tunable_chown_username);
install_str_setting((__int64)"/var/log/xferlog", &tunable_xferlog_file);
install_str_setting((__int64)"/var/log/flowftpd.log", &tunable_vsftpd_log_file);
install_str_setting((__int64)".message", &tunable_message_file);
install_str_setting((__int64)"nobody", &tunable_nopriv_user);
install_str_setting(0LL, &tunable_ftpd_banner);
install_str_setting((__int64)"/etc/flowftpd.banned_emails", &tunable_banned_email_file);
install_str_setting((__int64)"/etc/flowftpd.chroot_list", &tunable_chroot_list_file);
install_str_setting((__int64)"ftp", &tunable_pam_service_name);
install_str_setting((__int64)"ftp", &tunable_guest_username);
install_str_setting((__int64)"/etc/flowftpd.user_list", &tunable_userlist_file);
install_str_setting(0LL, &tunable_anon_root);
install_str_setting(0LL, &tunable_local_root);
install_str_setting(0LL, &tunable_banner_file);
install_str_setting(0LL, &tunable_pasv_address);
install_str_setting(0LL, &tunable_listen_address);
install_str_setting(0LL, &tunable_user_config_dir);
install_str_setting(0LL, &tunable_listen_address6);
install_str_setting(0LL, &tunable_cmds_allowed);
install_str_setting(0LL, &tunable_cmds_denied);
install_str_setting(0LL, &tunable_hide_file);
install_str_setting(0LL, &tunable_deny_file);
install_str_setting(0LL, &tunable_user_sub_token);
install_str_setting((__int64)"/etc/flowftpd.email_passwords", &tunable_email_password_file);
install_str_setting((__int64)"/usr/share/ssl/certs/flowftpd.pem", &tunable_rsa_cert_file);
install_str_setting(0LL, &tunable_dsa_cert_file);
install_str_setting((__int64)"DES-CBC3-SHA", &tunable_ssl_ciphers);
install_str_setting(0LL, &tunable_rsa_private_key_file);
install_str_setting(0LL, &tunable_dsa_private_key_file);
install_str_setting(0LL, &tunable_ca_certs_file);
install_str_setting(0LL, &tunable_pid_file);
}

canonical_decompiled_code:
void func1()
{
tunable_anonymous_enable = 1;
tunable_local_enable = 0;
tunable_pasv_enable = 1;
tunable_port_enable = 1;
tunable_chroot_local_user = 0;
tunable_write_enable = 0;
tunable_anon_upload_enable = 0;
tunable_anon_mkdir_write_enable = 0;
tunable_anon_other_write_enable = 0;
tunable_chown_uploads = 0;
tunable_connect_from_port_20 = 0;
tunable_xferlog_enable = 0;
tunable_dirmessage_enable = 0;
tunable_anon_world_readable_only = 1;
tunable_async_abor_enable = 0;
tunable_ascii_upload_enable = 0;
tunable_ascii_download_enable = 0;
tunable_one_process_model = 0;
tunable_xferlog_std_format = 0;
tunable_pasv_promiscuous = 0;
tunable_deny_email_enable = 0;
tunable_chroot_list_enable = 0;
tunable_setproctitle_enable = 0;
tunable_text_userdb_names = 0;
tunable_ls_recurse_enable = 0;
tunable_log_ftp_protocol = 0;
tunable_guest_enable = 0;
tunable_userlist_enable = 0;
tunable_userlist_deny = 1;
tunable_use_localtime = 0;
tunable_check_shell = 1;
tunable_hide_ids = 0;
tunable_listen = 0;
tunable_port_promiscuous = 0;
tunable_passwd_chroot_enable = 0;
tunable_no_anon_password = 0;
tunable_tcp_wrappers = 0;
tunable_use_sendfile = 1;
tunable_force_dot_files = 0;
tunable_listen_ipv6 = 0;
tunable_dual_log_enable = 0;
tunable_syslog_enable = 0;
tunable_background = 0;
tunable_virtual_use_local_privs = 0;
tunable_session_support = 0;
tunable_download_enable = 1;
tunable_dirlist_enable = 1;
tunable_chmod_enable = 1;
tunable_secure_email_list_enable = 0;
tunable_run_as_launching_user = 0;
tunable_no_log_lock = 0;
tunable_ssl_enable = 0;
tunable_allow_anon_ssl = 0;
tunable_force_local_logins_ssl = 1;
tunable_force_local_data_ssl = 1;
tunable_sslv2 = 0;
tunable_sslv3 = 0;
tunable_tlsv1 = 1;
tunable_tilde_user_enable = 0;
tunable_force_anon_logins_ssl = 0;
tunable_force_anon_data_ssl = 0;
tunable_mdtm_write = 1;
tunable_lock_upload_files = 1;
tunable_pasv_addr_resolve = 0;
tunable_debug_ssl = 0;
tunable_require_cert = 0;
tunable_validate_cert = 0;
tunable_strict_ssl_read_eof = 0;
tunable_strict_ssl_write_shutdown = 0;
tunable_ssl_request_cert = 1;
tunable_delete_failed_uploads = 0;
tunable_implicit_ssl = 0;
tunable_sandbox = 0;
tunable_require_ssl_reuse = 1;
tunable_isolate = 1;
tunable_isolate_network = 1;
tunable_ftp_enable = 1;
tunable_http_enable = 0;
tunable_calc_crc32 = 0;
tunable_accept_timeout = 60;
tunable_connect_timeout = 60;
tunable_local_umask = 63;
tunable_anon_umask = 63;
tunable_ftp_data_port = 20;
tunable_idle_session_timeout = 300;
tunable_data_connection_timeout = 300;
tunable_pasv_min_port = 5001;
tunable_pasv_max_port = 0;
tunable_anon_max_rate = 0;
tunable_local_max_rate = 0;
tunable_listen_port = 21;
tunable_max_clients = 2000;
tunable_file_open_mode = 438;
tunable_max_per_ip = 50;
tunable_trans_chunk_size = 0;
tunable_delay_failed_login = 1;
tunable_delay_successful_login = 0;
tunable_max_login_fails = 3;
tunable_chown_upload_mode = 384;
func0((__int64)"/usr/share/empty", &tunable_secure_chroot_dir);
func0((__int64)"ftp", &tunable_ftp_username);
func0((__int64)"root", &tunable_chown_username);
func0((__int64)"/var/log/xferlog", &tunable_xferlog_file);
func0((__int64)"/var/log/flowftpd.log", &tunable_vsftpd_log_file);
func0((__int64)".message", &tunable_message_file);
func0((__int64)"nobody", &tunable_nopriv_user);
func0(0LL, &tunable_ftpd_banner);
func0((__int64)"/etc/flowftpd.banned_emails", &tunable_banned_email_file);
func0((__int64)"/etc/flowftpd.chroot_list", &tunable_chroot_list_file);
func0((__int64)"ftp", &tunable_pam_service_name);
func0((__int64)"ftp", &tunable_guest_username);
func0((__int64)"/etc/flowftpd.user_list", &tunable_userlist_file);
func0(0LL, &tunable_anon_root);
func0(0LL, &tunable_local_root);
func0(0LL, &tunable_banner_file);
func0(0LL, &tunable_pasv_address);
func0(0LL, &tunable_listen_address);
func0(0LL, &tunable_user_config_dir);
func0(0LL, &tunable_listen_address6);
func0(0LL, &tunable_cmds_allowed);
func0(0LL, &tunable_cmds_denied);
func0(0LL, &tunable_hide_file);
func0(0LL, &tunable_deny_file);
func0(0LL, &tunable_user_sub_token);
func0((__int64)"/etc/flowftpd.email_passwords", &tunable_email_password_file);
func0((__int64)"/usr/share/ssl/certs/flowftpd.pem", &tunable_rsa_cert_file);
func0(0LL, &tunable_dsa_cert_file);
func0((__int64)"DES-CBC3-SHA", &tunable_ssl_ciphers);
func0(0LL, &tunable_rsa_private_key_file);
func0(0LL, &tunable_dsa_private_key_file);
func0(0LL, &tunable_ca_certs_file);
func0(0LL, &tunable_pid_file);
}

original_code:
void
tunables_load_defaults()
{
  tunable_anonymous_enable = 1;
  tunable_local_enable = 0;
  tunable_pasv_enable = 1;
  tunable_port_enable = 1;
  tunable_chroot_local_user = 0;
  tunable_write_enable = 0;
  tunable_anon_upload_enable = 0;
  tunable_anon_mkdir_write_enable = 0;
  tunable_anon_other_write_enable = 0;
  tunable_chown_uploads = 0;
  tunable_connect_from_port_20 = 0;
  tunable_xferlog_enable = 0;
  tunable_dirmessage_enable = 0;
  tunable_anon_world_readable_only = 1;
  tunable_async_abor_enable = 0;
  tunable_ascii_upload_enable = 0;
  tunable_ascii_download_enable = 0;
  tunable_one_process_model = 0;
  tunable_xferlog_std_format = 0;
  tunable_pasv_promiscuous = 0;
  tunable_deny_email_enable = 0;
  tunable_chroot_list_enable = 0;
  tunable_setproctitle_enable = 0;
  tunable_text_userdb_names = 0;
  tunable_ls_recurse_enable = 0;
  tunable_log_ftp_protocol = 0;
  tunable_guest_enable = 0;
  tunable_userlist_enable = 0;
  tunable_userlist_deny = 1;
  tunable_use_localtime = 0;
  tunable_check_shell = 1;
  tunable_hide_ids = 0;
  tunable_listen = 0;
  tunable_port_promiscuous = 0;
  tunable_passwd_chroot_enable = 0;
  tunable_no_anon_password = 0;
  tunable_tcp_wrappers = 0;
  tunable_use_sendfile = 1;
  tunable_force_dot_files = 0;
  tunable_listen_ipv6 = 0;
  tunable_dual_log_enable = 0;
  tunable_syslog_enable = 0;
  tunable_background = 0;
  tunable_virtual_use_local_privs = 0;
  tunable_session_support = 0;
  tunable_download_enable = 1;
  tunable_dirlist_enable = 1;
  tunable_chmod_enable = 1;
  tunable_secure_email_list_enable = 0;
  tunable_run_as_launching_user = 0;
  tunable_no_log_lock = 0;
  tunable_ssl_enable = 0;
  tunable_allow_anon_ssl = 0;
  tunable_force_local_logins_ssl = 1;
  tunable_force_local_data_ssl = 1;
  tunable_sslv2 = 0;
  tunable_sslv3 = 0;
  tunable_tlsv1 = 1;
  tunable_tilde_user_enable = 0;
  tunable_force_anon_logins_ssl = 0;
  tunable_force_anon_data_ssl = 0;
  tunable_mdtm_write = 1;
  tunable_lock_upload_files = 1;
  tunable_pasv_addr_resolve = 0;
  tunable_debug_ssl = 0;
  tunable_require_cert = 0;
  tunable_validate_cert = 0;
  tunable_strict_ssl_read_eof = 0;
  tunable_strict_ssl_write_shutdown = 0;
  tunable_ssl_request_cert = 1;
  tunable_delete_failed_uploads = 0;
  tunable_implicit_ssl = 0;
  tunable_sandbox = 0;
  tunable_require_ssl_reuse = 1;
  tunable_isolate = 1;
  tunable_isolate_network = 1;
  tunable_ftp_enable = 1;
  tunable_http_enable = 0;
  tunable_calc_crc32 = 0;
  tunable_accept_timeout = 60;
  tunable_connect_timeout = 60;
  tunable_local_umask = 077;
  tunable_anon_umask = 077;
  tunable_ftp_data_port = 20;
  tunable_idle_session_timeout = 300;
  tunable_data_connection_timeout = 300;
  tunable_pasv_min_port = 5001;
  tunable_pasv_max_port = 0;
  tunable_anon_max_rate = 0;
  tunable_local_max_rate = 0;
  tunable_listen_port = 21;
  tunable_max_clients = 2000;
  tunable_file_open_mode = 0666;
  tunable_max_per_ip = 50;
  tunable_trans_chunk_size = 0;
  tunable_delay_failed_login = 1;
  tunable_delay_successful_login = 0;
  tunable_max_login_fails = 3;
  tunable_chown_upload_mode = 0600;
  install_str_setting("/usr/share/empty", &tunable_secure_chroot_dir);
  install_str_setting("ftp", &tunable_ftp_username);
  install_str_setting("root", &tunable_chown_username);
  install_str_setting("/var/log/xferlog", &tunable_xferlog_file);
  install_str_setting("/var/log/" "flowftpd" ".log", &tunable_vsftpd_log_file);
  install_str_setting(".message", &tunable_message_file);
  install_str_setting("nobody", &tunable_nopriv_user);
  install_str_setting(0, &tunable_ftpd_banner);
  install_str_setting("/etc/" "flowftpd" ".banned_emails", &tunable_banned_email_file);
  install_str_setting("/etc/" "flowftpd" ".chroot_list", &tunable_chroot_list_file);
  install_str_setting("ftp", &tunable_pam_service_name);
  install_str_setting("ftp", &tunable_guest_username);
  install_str_setting("/etc/" "flowftpd" ".user_list", &tunable_userlist_file);
  install_str_setting(0, &tunable_anon_root);
  install_str_setting(0, &tunable_local_root);
  install_str_setting(0, &tunable_banner_file);
  install_str_setting(0, &tunable_pasv_address);
  install_str_setting(0, &tunable_listen_address);
  install_str_setting(0, &tunable_user_config_dir);
  install_str_setting(0, &tunable_listen_address6);
  install_str_setting(0, &tunable_cmds_allowed);
  install_str_setting(0, &tunable_cmds_denied);
  install_str_setting(0, &tunable_hide_file);
  install_str_setting(0, &tunable_deny_file);
  install_str_setting(0, &tunable_user_sub_token);
  install_str_setting("/etc/" "flowftpd" ".email_passwords",
                      &tunable_email_password_file);
  install_str_setting("/usr/share/ssl/certs/" "flowftpd" ".pem",
                      &tunable_rsa_cert_file);
  install_str_setting(0, &tunable_dsa_cert_file);
  install_str_setting("DES-CBC3-SHA", &tunable_ssl_ciphers);
  install_str_setting(0, &tunable_rsa_private_key_file);
  install_str_setting(0, &tunable_dsa_private_key_file);
  install_str_setting(0, &tunable_ca_certs_file);
  install_str_setting(0, &tunable_pid_file);
}


main

canonical_name: main

repo: arshadmomen/physics-numaric

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbx
int v5; // eax
__int64 v6; // rbp
double v7; // xmm0_8
double v8; // [rsp+0h] [rbp-38h]
double v9; // [rsp+8h] [rbp-30h]
double v10; // [rsp+18h] [rbp-20h] BYREF

v3 = fopen("eval.dat", "r");
if ( argc != 4 )
{
puts("Usage: gsl-histogram xmin xmax n\nComputes a histogram of the data on stdin using n bins from xmin to xmax");
exit(0);
}
v4 = v3;
v9 = atof(argv[1]);
v8 = atof(argv[2]);
v5 = atoi(argv[3]);
v6 = gsl_histogram_alloc(v5);
v7 = v9;
gsl_histogram_set_ranges_uniform(v6, v9, v8);
while ( (unsigned int)_isoc99_fscanf(v4, "%lg", &v10) == 1 )
{
v7 = v10;
gsl_histogram_increment(v6, v10);
}
gsl_histogram_fprintf(stdout, v6, "%g", v7);
gsl_histogram_free(v6);
exit(0);
}

original_code:
int
main ()
{
  srand (time (((void *)0)));
  gen_mat ();
  print_mat ();
  lapacke_wrapper ();
  return 0;
}

canonical_original_code:
int main()
{
  srand (time (((void *)0)));
  gen_mat ();
  print_mat ();
  lapacke_wrapper ();
  return 0;
}


repo: arthurpessoa/udping-port-forward

decompiled_code:
__int64 __fastcall client_cmp(unsigned __int16 *a1, unsigned __int16 *a2)
{
return *a1 - (unsigned int)*a2;
}

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

original_code:
int client_cmp(client_t *c1, client_t *c2, size_t len)
{
    return c1->id - c2->id;
}

canonical_original_code:
int client_cmp(struct client *c1, struct client *c2, unsigned long len)
{
    return c1->id - c2->id;
}

variable_types: struct client { unsigned short id; struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *tcp_sock; struct socket *udp_sock; int connected; int to_disconnect; struct timeval { long tv_sec; long tv_usec; } keepalive; char udp2tcp[1024]; int udp2tcp_len; int udp2tcp_state; struct list { void **obj_arr; unsigned long obj_sz; int num_objs; int length; int sort; int (*obj_cmp)(void *, void *, unsigned long); void *(*obj_copy)(void *, void *, unsigned long); void (*obj_free)(void *); } *tcp2udp_q; int tcp2udp_state; struct timeval tcp2udp_timeout; int resend_count; } *

variable_types:
len
unsigned long

user_defined_types: struct client { unsigned short id; struct socket *tcp_sock; struct socket *udp_sock; int connected; int to_disconnect; struct timeval keepalive; char udp2tcp[1024]; int udp2tcp_len; int udp2tcp_state; struct list *tcp2udp_q; int tcp2udp_state; struct timeval tcp2udp_timeout; int resend_count; }

user_defined_types: struct socket { int fd; int type; struct sockaddr_storage addr; unsigned int addr_len; }


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

if ( *(_DWORD *)(a1 + 24) )
return 0xFFFFFFFFLL;
result = sock_connect(*(_QWORD *)(a1 + 8), 0LL);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

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

if ( *(_DWORD *)(a1 + 24) )
return 0xFFFFFFFFLL;
result = sock_connect(*(_QWORD *)(a1 + 8), 0LL);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 24) = 1;
return result;
}

original_code:
int client_connect_tcp(client_t *c)
{
    if(!c->connected)
    {
        if(sock_connect(c->tcp_sock, 0) == 0)
        {
            c->connected = 1;
            return 0;
        }
    }
    return -1;
}

canonical_original_code:
int client_connect_tcp(struct client *c)
{
    if(!c->connected)
    {
        if(sock_connect(c->tcp_sock, 0) == 0)
        {
            c->connected = 1;
            return 0;
        }
    }
    return -1;
}

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

user_defined_types: struct list { void **obj_arr; unsigned long obj_sz; int num_objs; int length; int sort; int (*obj_cmp)(void *, void *, unsigned long); void *(*obj_copy)(void *, void *, unsigned long); void (*obj_free)(void *); }

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }


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

result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result )
{
result = sock_close(*(_QWORD *)(a1 + 8));
*(_DWORD *)(a1 + 24) = 0;
}
return result;
}

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

result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result )
{
result = sock_close(*(_QWORD *)(a1 + 8));
*(_DWORD *)(a1 + 24) = 0;
}
return result;
}

original_code:
void client_disconnect_tcp(client_t *c)
{
    if(c->connected)
    {
        sock_close(c->tcp_sock);
        c->connected = 0;
    }
}

canonical_original_code:
void client_disconnect_tcp(struct client *c)
{
    if(c->connected)
    {
        sock_close(c->tcp_sock);
        c->connected = 0;
    }
}


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

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

original_code:
void client_disconnect_udp(client_t *c)
{
    sock_close(c->udp_sock);
}

canonical_original_code:
void client_disconnect_udp(struct client *c)
{
    sock_close(c->udp_sock);
}


decompiled_code:
void __fastcall client_free(void *ptr)
{
if ( ptr )
{
if ( debug_level > 1 )
{
printf("Freeing client id %d\n", *(unsigned __int16 *)ptr);
printf(" q cnt left: %d\n", *(unsigned int *)(*((_QWORD *)ptr + 135) + 16LL));
}
sock_free(*((_QWORD *)ptr + 1));
sock_free(*((_QWORD *)ptr + 2));
list_free(*((_QWORD *)ptr + 135));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
if ( debug_level > 1 )
{
printf("Freeing client id %d\n", *(unsigned __int16 *)ptr);
printf(" q cnt left: %d\n", *(unsigned int *)(*((_QWORD *)ptr + 135) + 16LL));
}
sock_free(*((_QWORD *)ptr + 1));
sock_free(*((_QWORD *)ptr + 2));
list_free(*((_QWORD *)ptr + 135));
free(ptr);
}
}

original_code:
void client_free(client_t *c)
{
    if(c)
    {
        if(debug_level >= 2)
        {
            printf("Freeing client id %d\n", c->id);
            printf("  q cnt left: %d\n", ((c->tcp2udp_q)->num_objs));
        }
        sock_free(c->tcp_sock);
        sock_free(c->udp_sock);
        list_free(c->tcp2udp_q);
        free(c);
    }
}

canonical_original_code:
void client_free(struct client *c)
{
    if(c)
    {
        if(debug_level >= 2)
        {
            printf("Freeing client id %d\n", c->id);
            printf("  q cnt left: %d\n", ((c->tcp2udp_q)->num_objs));
        }
        sock_free(c->tcp_sock);
        sock_free(c->udp_sock);
        list_free(c->tcp2udp_q);
        free(c);
    }
}


decompiled_code:
__int64 __fastcall client_recv_udp_msg(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax
char v7[152]; // [rsp+8h] [rbp-98h] BYREF

result = msg_recv_msg(*(_QWORD *)(a1 + 16), v7, a2, a3, a4, a5, a6);
if ( (int)result >= 0 )
result = (unsigned int)-((unsigned int)sock_addr_equal(*(_QWORD *)(a1 + 16), v7) == 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax
char v7[152]; // [rsp+8h] [rbp-98h] BYREF

result = msg_recv_msg(*(_QWORD *)(a1 + 16), v7, a2, a3, a4, a5, a6);
if ( (int)result >= 0 )
result = (unsigned int)-((unsigned int)sock_addr_equal(*(_QWORD *)(a1 + 16), v7) == 0);
return result;
}

original_code:
int client_recv_udp_msg(client_t *client, char *data, int data_len,
                        uint16_t *id, uint8_t *msg_type, uint16_t *len)
{
    int ret;
    socket_t from;
    ret = msg_recv_msg(client->udp_sock, &from, data, data_len,
                       id, msg_type, len);
    if(ret < 0)
        return ret;
    if(!sock_addr_equal(client->udp_sock, &from))
        return -1;
    return 0;
}

canonical_original_code:
int client_recv_udp_msg(struct client *client, char *data, int data_len, unsigned short *id, unsigned char *msg_type, unsigned short *len)
{
    int ret;
    struct socket from;
    ret = msg_recv_msg(client->udp_sock, &from, data, data_len,
                       id, msg_type, len);
    if(ret < 0)
        return ret;
    if(!sock_addr_equal(client->udp_sock, &from))
        return -1;
    return 0;
}

variable_types:
data
char *

variable_types:
id
unsigned short *

variable_types:
len
unsigned short *

variable_types: ret int

variable_types: struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; }


original_code:
int client_got_udp_data(client_t *client, char *data, int data_len,
                        uint8_t msg_type)
{
    int ret;
    int is_resend = 0;
    if(data_len > 1024)
        return -1;
    if((msg_type == 0x05 &&
        client->udp2tcp_state == 2)
       || (msg_type == 0x06 &&
           client->udp2tcp_state == 3))
    {
        memcpy(client->udp2tcp, data, data_len);
        client->udp2tcp_len = data_len;
    }
    else
        is_resend = 1;
    msg_type = (msg_type == 0x05) ? 0x07 : 0x08;
    ret = msg_send_msg(client->udp_sock, client->id, msg_type, ((void *)0), 0);
    if(ret < 0)
        return ret;
    if(is_resend)
        return 1;
    client->udp2tcp_state = client->udp2tcp_state == 2 ?
        3 : 2;
    return 0;
}

canonical_original_code:
int client_got_udp_data(struct client *client, char *data, int data_len, unsigned char msg_type)
{
    int ret;
    int is_resend = 0;
    if(data_len > 1024)
        return -1;
    if((msg_type == 0x05 &&
        client->udp2tcp_state == 2)
       || (msg_type == 0x06 &&
           client->udp2tcp_state == 3))
    {
        memcpy(client->udp2tcp, data, data_len);
        client->udp2tcp_len = data_len;
    }
    else
        is_resend = 1;
    msg_type = (msg_type == 0x05) ? 0x07 : 0x08;
    ret = msg_send_msg(client->udp_sock, client->id, msg_type, ((void *)0), 0);
    if(ret < 0)
        return ret;
    if(is_resend)
        return 1;
    client->udp2tcp_state = client->udp2tcp_state == 2 ?
        3 : 2;
    return 0;
}


decompiled_code:
__int64 __fastcall client_send_tcp_data(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = sock_send(*(_QWORD *)(a1 + 8), a1 + 48, *(unsigned int *)(a1 + 1072));
if ( v1 < 0 )
result = 0xFFFFFFFFLL;
else
result = v1 == 0 ? 0xFFFFFFFE : 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = sock_send(*(_QWORD *)(a1 + 8), a1 + 48, *(unsigned int *)(a1 + 1072));
if ( v1 < 0 )
result = 0xFFFFFFFFLL;
else
result = v1 == 0 ? 0xFFFFFFFE : 0;
return result;
}

original_code:
int client_send_tcp_data(client_t *client)
{
    int ret;
    ret = sock_send(client->tcp_sock, client->udp2tcp, client->udp2tcp_len);
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    else
        return 0;
}

canonical_original_code:
int client_send_tcp_data(struct client *client)
{
    int ret;
    ret = sock_send(client->tcp_sock, client->udp2tcp, client->udp2tcp_len);
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    else
        return 0;
}


decompiled_code:
__int64 __fastcall client_recv_tcp_data(__int64 a1)
{
int v1; // eax
__int64 v2; // rdi
_DWORD v4[262]; // [rsp+0h] [rbp-418h] BYREF

v1 = sock_recv(*(_QWORD *)(a1 + 8), 0LL, v4, 1024LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( !v1 )
return 4294967294LL;
v2 = *(_QWORD *)(a1 + 1080);
v4[256] = v1;
list_add(v2, v4, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v1; // eax
__int64 v2; // rdi
_DWORD v4[262]; // [rsp+0h] [rbp-418h] BYREF

v1 = sock_recv(*(_QWORD *)(a1 + 8), 0LL, v4, 1024LL);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( !v1 )
return 4294967294LL;
v2 = *(_QWORD *)(a1 + 1080);
v4[256] = v1;
list_add(v2, v4, 1LL);
return 0LL;
}

original_code:
int client_recv_tcp_data(client_t *client)
{
    int ret;
    data_buf_t buf;
    ret = sock_recv(client->tcp_sock, ((void *)0), buf.buf, sizeof(buf.buf));
    if(ret < 0)
        return -1;
    if(ret == 0)
        return -2;
    buf.len = ret;
    list_add(client->tcp2udp_q, &buf, 1);
    return 0;
}

canonical_original_code:
int client_recv_tcp_data(struct client *client)
{
    int ret;
    struct data_buf buf;
    ret = sock_recv(client->tcp_sock, ((void *)0), buf.buf, sizeof(buf.buf));
    if(ret < 0)
        return -1;
    if(ret == 0)
        return -2;
    buf.len = ret;
    list_add(client->tcp2udp_q, &buf, 1);
    return 0;
}

variable_types: struct data_buf { char buf[1024]; int len; }


decompiled_code:
__int64 __fastcall client_send_udp_data(unsigned __int16 *a1)
{
__int64 v2; // rdi
__int64 result; // rax
int v4; // edx
unsigned int v5; // ebp
__int64 v6; // rax
__int64 v7; // r9

v2 = *((_QWORD *)a1 + 135);
result = *(unsigned int *)(v2 + 16);
if ( (_DWORD)result )
{
if ( *((int *)a1 + 278) > 9 )
return 4294967294LL;
v4 = *((_DWORD *)a1 + 272);
result = 1LL;
if ( (unsigned int)(v4 - 4) > 1 )
{
result = *((unsigned int *)a1 + 269);
if ( (_DWORD)result != 1 )
{
if ( v4 == 2 )
{
v5 = 5;
}
else
{
result = 0xFFFFFFFFLL;
v5 = 6;
if ( v4 != 3 )
return result;
}
v6 = list_get_at(v2, 0LL);
result = msg_send_msg(*((_QWORD *)a1 + 2), *a1, v5, v6, *(unsigned int *)(v6 + 1024), v7);
if ( (int)result >= 0 )
{
*((_DWORD *)a1 + 272) = v5 - 1;
gettimeofday((struct timeval *)(a1 + 548), 0LL);
*((_QWORD *)a1 + 137) += *((_DWORD *)a1 + 278) + 1;
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int16 *a1)
{
__int64 v2; // rdi
__int64 result; // rax
int v4; // edx
unsigned int v5; // ebp
__int64 v6; // rax
__int64 v7; // r9

v2 = *((_QWORD *)a1 + 135);
result = *(unsigned int *)(v2 + 16);
if ( (_DWORD)result )
{
if ( *((int *)a1 + 278) > 9 )
return 4294967294LL;
v4 = *((_DWORD *)a1 + 272);
result = 1LL;
if ( (unsigned int)(v4 - 4) > 1 )
{
result = *((unsigned int *)a1 + 269);
if ( (_DWORD)result != 1 )
{
if ( v4 == 2 )
{
v5 = 5;
}
else
{
result = 0xFFFFFFFFLL;
v5 = 6;
if ( v4 != 3 )
return result;
}
v6 = list_get_at(v2, 0LL);
result = msg_send_msg(*((_QWORD *)a1 + 2), *a1, v5, v6, *(unsigned int *)(v6 + 1024), v7);
if ( (int)result >= 0 )
{
*((_DWORD *)a1 + 272) = v5 - 1;
gettimeofday((struct timeval *)(a1 + 548), 0LL);
*((_QWORD *)a1 + 137) += *((_DWORD *)a1 + 278) + 1;
result = 0LL;
}
}
}
}
return result;
}

original_code:
int client_send_udp_data(client_t *client)
{
    data_buf_t *buf;
    uint8_t msg_type;
    int ret;
    if(((client->tcp2udp_q)->num_objs) == 0)
        return 0;
    if(client->resend_count >= 10)
        return -2;
    if(client->tcp2udp_state == 4 ||
       client->tcp2udp_state == 5 ||
       client->udp2tcp_state == 1)
        return 1;
    switch(client->tcp2udp_state)
    {
        case 2:
        case 4:
            msg_type = 0x05;
            break;
        case 3:
        case 5:
            msg_type = 0x06;
            break;
        default:
            return -1;
    }
    buf = list_get_at(client->tcp2udp_q, 0);
    ret = msg_send_msg(client->udp_sock, client->id, msg_type,
                       buf->buf, buf->len);
    if(ret < 0)
        return ret;
    client->tcp2udp_state = (msg_type == 0x05) ?
        4 : 5;
    gettimeofday(&client->tcp2udp_timeout, ((void *)0));
    client->tcp2udp_timeout.tv_sec += (client->resend_count+1)*1;
    return 0;
}

canonical_original_code:
int client_send_udp_data(struct client *client)
{
    struct data_buf *buf;
    unsigned char msg_type;
    int ret;
    if(((client->tcp2udp_q)->num_objs) == 0)
        return 0;
    if(client->resend_count >= 10)
        return -2;
    if(client->tcp2udp_state == 4 ||
       client->tcp2udp_state == 5 ||
       client->udp2tcp_state == 1)
        return 1;
    switch(client->tcp2udp_state)
    {
        case 2:
        case 4:
            msg_type = 0x05;
            break;
        case 3:
        case 5:
            msg_type = 0x06;
            break;
        default:
            return -1;
    }
    buf = list_get_at(client->tcp2udp_q, 0);
    ret = msg_send_msg(client->udp_sock, client->id, msg_type,
                       buf->buf, buf->len);
    if(ret < 0)
        return ret;
    client->tcp2udp_state = (msg_type == 0x05) ?
        4 : 5;
    gettimeofday(&client->tcp2udp_timeout, ((void *)0));
    client->tcp2udp_timeout.tv_sec += (client->resend_count+1)*1;
    return 0;
}

variable_types: struct data_buf { char buf[1024]; int len; } *


original_code:
int client_got_ack(client_t *client, uint8_t ack_type)
{
    if(ack_type == 0x07 && client->tcp2udp_state == 4)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 3;
        client->resend_count = 0;
        return 0;
    }
    if(ack_type == 0x08 && client->tcp2udp_state == 5)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 2;
        client->resend_count = 0;
        return 0;
    }
    return -1;
}

canonical_original_code:
int client_got_ack(struct client *client, unsigned char ack_type)
{
    if(ack_type == 0x07 && client->tcp2udp_state == 4)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 3;
        client->resend_count = 0;
        return 0;
    }
    if(ack_type == 0x08 && client->tcp2udp_state == 5)
    {
        list_delete_at(client->tcp2udp_q, 0);
        client->tcp2udp_state = 2;
        client->resend_count = 0;
        return 0;
    }
    return -1;
}


decompiled_code:
__int64 __fastcall client_send_hello(__int64 a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
return msg_send_hello(*(_QWORD *)(a1 + 16), a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 a3, unsigned __int16 a4)
{
return msg_send_hello(*(_QWORD *)(a1 + 16), a2, a3, a4);
}

original_code:
int client_send_hello(client_t *client, char *host, char *port,
                      uint16_t req_id)
{
    return msg_send_hello(client->udp_sock, host, port, req_id);
}

canonical_original_code:
int client_send_hello(struct client *client, char *host, char *port, unsigned short req_id)
{
    return msg_send_hello(client->udp_sock, host, port, req_id);
}

variable_types:
host
char *

variable_types:
port
char *


decompiled_code:
__int64 __fastcall client_send_helloack(__int64 a1, __int16 a2)
{
__int16 v2; // ax
unsigned __int16 *v3; // rdx
__int64 v4; // rsi
__int64 v5; // rdi
__int64 v6; // r8
__int64 v7; // r9
__int16 v9[6]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = _bswap_16(a2);
v4 = *v3;
v5 = *((_QWORD *)v3 + 2);
v9[0] = v2;
return msg_send_msg(v5, v4, 3LL, v9, v6, v7);
}

original_code:
int client_send_helloack(client_t *client, uint16_t req_id)
{
    req_id = htons(req_id);
    return msg_send_msg(client->udp_sock, client->id, 0x03,
                        (char *)&req_id, sizeof(req_id));
}

canonical_original_code:
int client_send_helloack(struct client *client, unsigned short req_id)
{
    req_id = htons(req_id);
    return msg_send_msg(client->udp_sock, client->id, 0x03,
                        (char *)&req_id, sizeof(req_id));
}


decompiled_code:
__int64 __fastcall client_got_helloack(__int64 a1)
{
if ( *(_DWORD *)(a1 + 1076) == 1 )
*(_DWORD *)(a1 + 1076) = 2;
return 0LL;
}

original_code:
int client_got_helloack(client_t *client)
{
    if(client->udp2tcp_state == 1)
        client->udp2tcp_state = 2;
    return 0;
}

canonical_original_code:
int client_got_helloack(struct client *client)
{
    if(client->udp2tcp_state == 1)
        client->udp2tcp_state = 2;
    return 0;
}


decompiled_code:
__int64 __fastcall client_send_goodbye(unsigned __int16 *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
return msg_send_msg(*((_QWORD *)a1 + 2), *a1, 1LL, 0LL, 0LL, a6);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int16 *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
return msg_send_msg(*((_QWORD *)a1 + 2), *a1, 1LL, 0LL, 0LL, a6);
}

original_code:
int client_send_goodbye(client_t *client)
{
    return msg_send_msg(client->udp_sock, client->id, 0x01,
                        ((void *)0), 0);
}

canonical_original_code:
int client_send_goodbye(struct client *client)
{
    return msg_send_msg(client->udp_sock, client->id, 0x01,
                        ((void *)0), 0);
}


decompiled_code:
__int64 __fastcall client_check_and_resend(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
bool v4; // cc
__int64 v5; // rdx

if ( (unsigned int)(*((_DWORD *)a1 + 272) - 4) > 1 )
return 0LL;
if ( *((_QWORD *)a1 + 137) == a2 )
{
if ( *((_QWORD *)a1 + 138) >= a3 )
return 0LL;
}
else if ( *((_QWORD *)a1 + 137) >= a2 )
{
return 0LL;
}
v4 = debug_level <= 1;
v5 = (unsigned int)(*((_DWORD *)a1 + 278) + 1);
*((_DWORD *)a1 + 278) = v5;
if ( !v4 )
printf("client(%d): resending data, count %d\n", *a1, v5);
return client_send_udp_data(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
bool v4; // cc
__int64 v5; // rdx

if ( (unsigned int)(*((_DWORD *)a1 + 272) - 4) > 1 )
return 0LL;
if ( *((_QWORD *)a1 + 137) == a2 )
{
if ( *((_QWORD *)a1 + 138) >= a3 )
return 0LL;
}
else if ( *((_QWORD *)a1 + 137) >= a2 )
{
return 0LL;
}
v4 = debug_level <= 1;
v5 = (unsigned int)(*((_DWORD *)a1 + 278) + 1);
*((_DWORD *)a1 + 278) = v5;
if ( !v4 )
printf("client(%d): resending data, count %d\n", *a1, v5);
return func10(a1);
}

original_code:
int client_check_and_resend(client_t *client, struct timeval curr_tv)
{
    if((client->tcp2udp_state == 4 ||
        client->tcp2udp_state == 5)
       && (((&curr_tv)->tv_sec == (&client->tcp2udp_timeout)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->tcp2udp_timeout)->tv_usec) : ((&curr_tv)->tv_sec > (&client->tcp2udp_timeout)->tv_sec)))
    {
        client->resend_count++;
        if(debug_level >= 2)
            printf("client(%d): resending data, count %d\n",
                   ((client)->id), client->resend_count);
        return client_send_udp_data(client);
    }
    return 0;
}

canonical_original_code:
int client_check_and_resend(struct client *client, struct timeval curr_tv)
{
    if((client->tcp2udp_state == 4 ||
        client->tcp2udp_state == 5)
       && (((&curr_tv)->tv_sec == (&client->tcp2udp_timeout)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->tcp2udp_timeout)->tv_usec) : ((&curr_tv)->tv_sec > (&client->tcp2udp_timeout)->tv_sec)))
    {
        client->resend_count++;
        if(debug_level >= 2)
            printf("client(%d): resending data, count %d\n",
                   ((client)->id), client->resend_count);
        return client_send_udp_data(client);
    }
    return 0;
}


decompiled_code:
int __fastcall client_reset_keepalive(__m128i *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v2, 0LL);
v2.tv_sec += 421LL;
a1[2] = _mm_loadu_si128((const __m128i *)&v2);
return result;
}

canonical_decompiled_code:
int __fastcall func17(__m128i *a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

result = gettimeofday(&v2, 0LL);
v2.tv_sec += 421LL;
a1[2] = _mm_loadu_si128((const __m128i *)&v2);
return result;
}

original_code:
void client_reset_keepalive(client_t *client)
{
    struct timeval curr;
    gettimeofday(&curr, ((void *)0));
    curr.tv_sec += (7*60+1);
    memcpy(&client->keepalive, &curr, sizeof(struct timeval));
}

canonical_original_code:
void client_reset_keepalive(struct client *client)
{
    struct timeval curr;
    gettimeofday(&curr, ((void *)0));
    curr.tv_sec += (7*60+1);
    memcpy(&client->keepalive, &curr, sizeof(struct timeval));
}

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


decompiled_code:
_BOOL8 __fastcall client_timed_out(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

if ( *(_QWORD *)(a1 + 32) == a2 )
result = *(_QWORD *)(a1 + 40) < a3;
else
result = *(_QWORD *)(a1 + 32) < a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

if ( *(_QWORD *)(a1 + 32) == a2 )
result = *(_QWORD *)(a1 + 40) < a3;
else
result = *(_QWORD *)(a1 + 32) < a2;
return result;
}

original_code:
int client_timed_out(client_t *client, struct timeval curr_tv)
{
    if((((&curr_tv)->tv_sec == (&client->keepalive)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->keepalive)->tv_usec) : ((&curr_tv)->tv_sec > (&client->keepalive)->tv_sec)))
        return 1;
    else
        return 0;
}

canonical_original_code:
int client_timed_out(struct client *client, struct timeval curr_tv)
{
    if((((&curr_tv)->tv_sec == (&client->keepalive)->tv_sec) ? ((&curr_tv)->tv_usec > (&client->keepalive)->tv_usec) : ((&curr_tv)->tv_sec > (&client->keepalive)->tv_sec)))
        return 1;
    else
        return 0;
}


decompiled_code:
__int64 __fastcall client_check_and_send_keepalive(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx
__int64 v4; // r9

if ( !client_timed_out((__int64)a1, a2, a3) )
return 0LL;
a1[5] = v3;
a1[4] = a2 + 60;
return msg_send_msg(a1[2], *(unsigned __int16 *)a1, 4LL, 0LL, 0LL, v4);
}

original_code:
int client_check_and_send_keepalive(client_t *client, struct timeval curr_tv)
{
    if(client_timed_out(client, curr_tv))
    {
        curr_tv.tv_sec += 60;
        memcpy(&client->keepalive, &curr_tv, sizeof(struct timeval));
        return msg_send_msg(client->udp_sock, client->id, 0x04,
                            ((void *)0), 0);
    }
    return 0;
}

canonical_original_code:
int client_check_and_send_keepalive(struct client *client, struct timeval curr_tv)
{
    if(client_timed_out(client, curr_tv))
    {
        curr_tv.tv_sec += 60;
        memcpy(&client->keepalive, &curr_tv, sizeof(struct timeval));
        return msg_send_msg(client->udp_sock, client->id, 0x04,
                            ((void *)0), 0);
    }
    return 0;
}


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

if ( *(_DWORD *)(a1 + 16) <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 16) <= a2 || a2 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
void *list_get_at(list_t *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return ((void *)0);
    return list->obj_arr[i];
}

canonical_original_code:
void *list_get_at(struct list *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return ((void *)0);
    return list->obj_arr[i];
}

variable_types: struct list { void **obj_arr; unsigned long obj_sz; int num_objs; int length; int sort; int (*obj_cmp)(void *, void *, unsigned long); void *(*obj_copy)(void *, void *, unsigned long); void (*obj_free)(void *); } *

variable_types: i int

return_type: void *


decompiled_code:
__int64 __fastcall list_get_index(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( *(int *)(a1 + 16) <= 0 )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1 + 32))(
*(_QWORD *)(*(_QWORD *)a1 + 8 * v2),
a2,
*(_QWORD *)(a1 + 8)) )
{
if ( *(_DWORD *)(a1 + 16) <= (int)++v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( *(int *)(a1 + 16) <= 0 )
return 0xFFFFFFFFLL;
v2 = 0LL;
while ( (*(unsigned int (__fastcall **)(_QWORD, __int64, _QWORD))(a1 + 32))(
*(_QWORD *)(*(_QWORD *)a1 + 8 * v2),
a2,
*(_QWORD *)(a1 + 8)) )
{
if ( *(_DWORD *)(a1 + 16) <= (int)++v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v2;
}

original_code:
int list_get_index(list_t *list, void *obj)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
    {
        if(list->obj_cmp(list->obj_arr[i], obj, list->obj_sz) == 0)
            return i;
    }
    return -1;
}

canonical_original_code:
int list_get_index(struct list *list, void *obj)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
    {
        if(list->obj_cmp(list->obj_arr[i], obj, list->obj_sz) == 0)
            return i;
    }
    return -1;
}

variable_types:
obj
void *


decompiled_code:
__int64 __fastcall list_get(_QWORD *a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = list_get_index((__int64)a1, a2);
if ( v2 == -1 )
result = 0LL;
else
result = *(_QWORD *)(*a1 + 8LL * v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax

v2 = func1((__int64)a1, a2);
if ( v2 == -1 )
result = 0LL;
else
result = *(_QWORD *)(*a1 + 8LL * v2);
return result;
}

original_code:
void *list_get(list_t *list, void *obj)
{
    int i;
    i = list_get_index(list, obj);
    if(i == -1)
        return ((void *)0);
    return list->obj_arr[i];
}

canonical_original_code:
void *list_get(struct list *list, void *obj)
{
    int i;
    i = list_get_index(list, obj);
    if(i == -1)
        return ((void *)0);
    return list->obj_arr[i];
}


original_code:
void *list_add(list_t *list, void *obj, int copy)
{
    void *o;
    void **new_arr;
    void *temp;
    int i;
    o = list_get(list, obj);
    if(o)
        return o;
    if(copy == 1)
    {
        o = malloc(list->obj_sz);
        if(o == ((void *)0))
            return ((void *)0);
        list->obj_copy(o, obj, list->obj_sz);
    }
    else
    {
        o = obj;
    }
    if(list->num_objs == list->length)
    {
        new_arr = realloc(list->obj_arr, list->length * 2 * sizeof(void *));
        if(!new_arr)
        {
            list->obj_free(o);
            return ((void *)0);
        }
        list->obj_arr = new_arr;
        list->length *= 2;
    }
    list->obj_arr[list->num_objs++] = o;
    if(list->sort == 1)
    {
        for(i = list->num_objs-1; i > 0; i--)
        {
            if(list->obj_cmp(list->obj_arr[i-1], list->obj_arr[i],
                             list->obj_sz) > 0)
            {
                temp = list->obj_arr[i-1];
                list->obj_arr[i-1] = list->obj_arr[i];
                list->obj_arr[i] = temp;
            }
            else
                break;
        }
    }
    return o;
}

canonical_original_code:
void *list_add(struct list *list, void *obj, int copy)
{
    void *o;
    void **new_arr;
    void *temp;
    int i;
    o = list_get(list, obj);
    if(o)
        return o;
    if(copy == 1)
    {
        o = malloc(list->obj_sz);
        if(o == ((void *)0))
            return ((void *)0);
        list->obj_copy(o, obj, list->obj_sz);
    }
    else
    {
        o = obj;
    }
    if(list->num_objs == list->length)
    {
        new_arr = realloc(list->obj_arr, list->length * 2 * sizeof(void *));
        if(!new_arr)
        {
            list->obj_free(o);
            return ((void *)0);
        }
        list->obj_arr = new_arr;
        list->length *= 2;
    }
    list->obj_arr[list->num_objs++] = o;
    if(list->sort == 1)
    {
        for(i = list->num_objs-1; i > 0; i--)
        {
            if(list->obj_cmp(list->obj_arr[i-1], list->obj_arr[i],
                             list->obj_sz) > 0)
            {
                temp = list->obj_arr[i-1];
                list->obj_arr[i-1] = list->obj_arr[i];
                list->obj_arr[i] = temp;
            }
            else
                break;
        }
    }
    return o;
}

variable_types: copy int

variable_types:
o
void *

variable_types:
temp
void *


decompiled_code:
__int64 __fastcall list_action(__int64 a1, __int64 (__fastcall *a2)(__int64))
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rdi

result = *(unsigned int *)(a1 + 16);
if ( (int)result > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v4++);
result = a2(v5);
}
while ( *(_DWORD *)(a1 + 16) > (int)v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 (__fastcall *a2)(__int64))
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rdi

result = *(unsigned int *)(a1 + 16);
if ( (int)result > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v4++);
result = a2(v5);
}
while ( *(_DWORD *)(a1 + 16) > (int)v4 );
}
return result;
}

original_code:
void list_action(list_t *list, void (*action)(void *))
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        action(list->obj_arr[i]);
}

canonical_original_code:
void list_action(struct list *list, void (*action)(void *))
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        action(list->obj_arr[i]);
}

variable_types:
action
void (*)(void *)


original_code:
void list_delete_at(list_t *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return;
    list->obj_free(list->obj_arr[i]);
    for(; i < list->num_objs - 1; i++)
        list->obj_arr[i] = list->obj_arr[i+1];
    list->obj_arr[i] = ((void *)0);
    list->num_objs--;
}

canonical_original_code:
void list_delete_at(struct list *list, int i)
{
    if(i >= list->num_objs || i < 0)
        return;
    list->obj_free(list->obj_arr[i]);
    for(; i < list->num_objs - 1; i++)
        list->obj_arr[i] = list->obj_arr[i+1];
    list->obj_arr[i] = ((void *)0);
    list->num_objs--;
}


decompiled_code:
void __fastcall list_delete(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = list_get_index(a1, a2);
list_delete_at(a1, v2);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = func1(a1, a2);
func5(a1, v2);
}

original_code:
void list_delete(list_t *list, void *obj)
{
    list_delete_at(list, list_get_index(list, obj));
}

canonical_original_code:
void list_delete(struct list *list, void *obj)
{
    list_delete_at(list, list_get_index(list, obj));
}


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

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

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

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

original_code:
void list_free(list_t *list)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        list->obj_free(list->obj_arr[i]);
    free(list->obj_arr);
    free(list);
}

canonical_original_code:
void list_free(struct list *list)
{
    int i;
    for(i = 0; i < list->num_objs; i++)
        list->obj_free(list->obj_arr[i]);
    free(list->obj_arr);
    free(list);
}


isnum

decompiled_code:
__int64 __fastcall isnum(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !(_BYTE)v1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x800) != 0 )
{
v1 = *++v2;
if ( !(_BYTE)v1 )
return 1LL;
}
return 0LL;
}

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

v1 = *a1;
if ( !(_BYTE)v1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x800) != 0 )
{
v1 = *++v2;
if ( !(_BYTE)v1 )
return 1LL;
}
return 0LL;
}

original_code:
static inline int isnum(char *s)
{
    for(; *s != '\0'; s++)
    {
        if(!((*__ctype_b_loc ())[(int) (((int)*s))] & (unsigned short int) _ISdigit))
            return 0;
    }
    return 1;
}

canonical_original_code:
static inline int isnum(char *s)
{
    for(; *s != '\0'; s++)
    {
        if(!((*__ctype_b_loc ())[(int) (((int)*s))] & (unsigned short) _ISdigit))
            return 0;
    }
    return 1;
}

variable_types:
s
char *


decompiled_code:
void __fastcall acl_free(void *ptr)
{
if ( *(_QWORD *)ptr )
sock_free();
if ( *((_QWORD *)ptr + 1) )
sock_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( *(_QWORD *)ptr )
sock_free();
if ( *((_QWORD *)ptr + 1) )
sock_free();
free(ptr);
}

original_code:
void acl_free(acl_t *acl)
{
    if(acl->src)
        sock_free(acl->src);
    if(acl->dst)
        sock_free(acl->dst);
    free(acl);
}

canonical_original_code:
void acl_free(struct acl *acl)
{
    if(acl->src)
        sock_free(acl->src);
    if(acl->dst)
        sock_free(acl->dst);
    free(acl);
}

variable_types: struct acl { struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *src; struct socket *dst; int action; } *

user_defined_types: struct acl { struct socket *src; struct socket *dst; int action; }


decompiled_code:
__int64 __fastcall acl_action(unsigned int *a1, __int64 a2, __int16 a3, __int64 a4, __int16 a5)
{
unsigned int v6; // er15
unsigned int v9; // eax
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
__int64 v13; // r10
__int64 v14; // rax
__int64 v15; // rbp
unsigned int v16; // eax
__int64 v17; // rcx
__int64 v18; // r8
__int64 v19; // r9
__int64 v20; // r12
__int16 v21; // ax
__int16 v23; // ax

v6 = 0;
v9 = sock_get_ipver_isra_0(*(_WORD *)(*(_QWORD *)a1 + 8LL));
v14 = sock_create(v13, 0LL, v9, *(unsigned int *)(v10 + 4), v11, v12);
if ( v14 )
{
v15 = v14;
v16 = sock_get_ipver_isra_0(*(_WORD *)(*((_QWORD *)a1 + 1) + 8LL));
v20 = sock_create(a4, 0LL, v16, *(unsigned int *)(v17 + 4), v18, v19);
if ( v20 )
{
v21 = sock_get_port(*(_QWORD *)a1);
if ( (!v21 || v21 == a3)
&& ((v23 = sock_get_port(*((_QWORD *)a1 + 1))) == 0 || v23 == a5)
&& ((unsigned int)sock_isaddrany(*(_QWORD *)a1) || !(unsigned int)sock_ipaddr_cmp(*(_QWORD *)a1, v15))
&& ((unsigned int)sock_isaddrany(*((_QWORD *)a1 + 1)) || !(unsigned int)sock_ipaddr_cmp(
*((_QWORD *)a1 + 1),
v20)) )
{
v6 = a1[4];
}
else
{
v6 = 0;
}
sock_free(v15);
sock_free(v20);
}
else
{
sock_free(v15);
}
}
return v6;
}

original_code:
int acl_action(acl_t *acl, char *src, uint16_t sport, char *dst, uint16_t dport)
{
    socket_t *s = ((void *)0);
    socket_t *d = ((void *)0);
    uint16_t p;
    int ret;
    ret = 0;
    s = sock_create(src, ((void *)0), sock_get_ipver(acl->src),
                    ((acl->src)->type), 0, 0);
    if(s == ((void *)0))
        goto done;
    d = sock_create(dst, ((void *)0), sock_get_ipver(acl->dst),
                    ((acl->dst)->type), 0, 0);
    if(d == ((void *)0))
        goto done;
    p = sock_get_port(acl->src);
    if(p != 0 && p != sport)
        goto done;
    p = sock_get_port(acl->dst);
    if(p != 0 && p != dport)
        goto done;
    if(!sock_isaddrany(acl->src) && sock_ipaddr_cmp(acl->src, s) != 0)
        goto done;
    if(!sock_isaddrany(acl->dst) && sock_ipaddr_cmp(acl->dst, d) != 0)
        goto done;
    ret = acl->action;
  done:
    if(s)
        sock_free(s);
    if(d)
        sock_free(d);
    return ret;
}

canonical_original_code:
int acl_action(struct acl *acl, char *src, unsigned short sport, char *dst, unsigned short dport)
{
    struct socket *s = ((void *)0);
    struct socket *d = ((void *)0);
    unsigned short p;
    int ret;
    ret = 0;
    s = sock_create(src, ((void *)0), sock_get_ipver(acl->src),
                    ((acl->src)->type), 0, 0);
    if(s == ((void *)0))
        goto done;
    d = sock_create(dst, ((void *)0), sock_get_ipver(acl->dst),
                    ((acl->dst)->type), 0, 0);
    if(d == ((void *)0))
        goto done;
    p = sock_get_port(acl->src);
    if(p != 0 && p != sport)
        goto done;
    p = sock_get_port(acl->dst);
    if(p != 0 && p != dport)
        goto done;
    if(!sock_isaddrany(acl->src) && sock_ipaddr_cmp(acl->src, s) != 0)
        goto done;
    if(!sock_isaddrany(acl->dst) && sock_ipaddr_cmp(acl->dst, d) != 0)
        goto done;
    ret = acl->action;
  done:
    if(s)
        sock_free(s);
    if(d)
        sock_free(d);
    return ret;
}

variable_types:
src
char *

variable_types:
sport
unsigned short

variable_types:
dst
char *

variable_types:
dport
unsigned short

variable_types: struct socket { int fd; int type; struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } addr; unsigned int addr_len; } *

variable_types:
p
unsigned short


decompiled_code:
int __fastcall acl_print(_QWORD *a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
int v3; // eax
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

if ( (unsigned int)sock_isaddrany(*a1) )
{
v1 = sock_get_port(*a1);
if ( !v1 )
goto LABEL_3;
LABEL_12:
printf("sp=%hu,", v1);
if ( (unsigned int)sock_isaddrany(a1[1]) )
goto LABEL_4;
goto LABEL_13;
}
sock_get_addrstr(*a1, v5, 55LL);
printf("s=%s,", v5);
v1 = sock_get_port(*a1);
if ( v1 )
goto LABEL_12;
LABEL_3:
if ( (unsigned int)sock_isaddrany(a1[1]) )
goto LABEL_4;
LABEL_13:
sock_get_addrstr(a1[1], v5, 55LL);
printf("d=%s,", v5);
LABEL_4:
v2 = sock_get_port(a1[1]);
if ( v2 )
printf("dp=%hu,", v2);
v3 = *((_DWORD *)a1 + 4);
if ( v3 == 1 )
return puts("a=deny");
if ( v3 == 2 )
return puts("a=allow");
return puts("a=??");
}

canonical_decompiled_code:
int __fastcall func4(_QWORD *a1)
{
unsigned __int16 v1; // ax
unsigned __int16 v2; // ax
int v3; // eax
char v5[72]; // [rsp+0h] [rbp-48h] BYREF

if ( (unsigned int)sock_isaddrany(*a1) )
{
v1 = sock_get_port(*a1);
if ( !v1 )
goto LABEL_3;
LABEL_12:
printf("sp=%hu,", v1);
if ( (unsigned int)sock_isaddrany(a1[1]) )
goto LABEL_4;
goto LABEL_13;
}
sock_get_addrstr(*a1, v5, 55LL);
printf("s=%s,", v5);
v1 = sock_get_port(*a1);
if ( v1 )
goto LABEL_12;
LABEL_3:
if ( (unsigned int)sock_isaddrany(a1[1]) )
goto LABEL_4;
LABEL_13:
sock_get_addrstr(a1[1], v5, 55LL);
printf("d=%s,", v5);
LABEL_4:
v2 = sock_get_port(a1[1]);
if ( v2 )
printf("dp=%hu,", v2);
v3 = *((_DWORD *)a1 + 4);
if ( v3 == 1 )
return puts("a=deny");
if ( v3 == 2 )
return puts("a=allow");
return puts("a=??");
}

original_code:
void acl_print(acl_t *acl)
{
    char addr_str[(46 + 9)];
    int len;
    uint16_t port;
    len = sizeof(addr_str);
    if(!sock_isaddrany(acl->src))
    {
        sock_get_addrstr(acl->src, addr_str, len);
        printf("s=%s,", addr_str);
    }
    if((port = sock_get_port(acl->src)) != 0)
        printf("sp=%hu,", port);
    if(!sock_isaddrany(acl->dst))
    {
        sock_get_addrstr(acl->dst, addr_str, len);
        printf("d=%s,", addr_str);
    }
    if((port = sock_get_port(acl->dst)) != 0)
        printf("dp=%hu,", port);
    switch(acl->action)
    {
        case 2:
            printf("a=allow\n");
            break;
        case 1:
            printf("a=deny\n");
            break;
        default:
            printf("a=??\n");
            break;
    }
}

canonical_original_code:
void acl_print(struct acl *acl)
{
    char addr_str[-1];
    int len;
    unsigned short port;
    len = sizeof(addr_str);
    if(!sock_isaddrany(acl->src))
    {
        sock_get_addrstr(acl->src, addr_str, len);
        printf("s=%s,", addr_str);
    }
    if((port = sock_get_port(acl->src)) != 0)
        printf("sp=%hu,", port);
    if(!sock_isaddrany(acl->dst))
    {
        sock_get_addrstr(acl->dst, addr_str, len);
        printf("d=%s,", addr_str);
    }
    if((port = sock_get_port(acl->dst)) != 0)
        printf("dp=%hu,", port);
    switch(acl->action)
    {
        case 2:
            printf("a=allow\n");
            break;
        case 1:
            printf("a=deny\n");
            break;
        default:
            printf("a=??\n");
            break;
    }
}

variable_types: len int

variable_types:
port
unsigned short


decompiled_code:
__int16 __fastcall msg_init_header(__int64 a1, __int16 a2)
{
__int16 v2; // ax
char v3; // dl
__int64 v4; // r8
__int16 v5; // cx
__int16 result; // ax
__int64 v7; // r8

v2 = _bswap_16(a2);
*(_BYTE *)(v4 + 2) = v3;
*(_WORD *)v4 = v2;
result = _bswap_16(v5);
*(_WORD *)(v7 + 3) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func1(__int64 a1, __int16 a2)
{
__int16 v2; // ax
char v3; // dl
__int64 v4; // r8
__int16 v5; // cx
__int16 result; // ax
__int64 v7; // r8

v2 = func0(a2);
*(_BYTE *)(v4 + 2) = v3;
*(_WORD *)v4 = v2;
result = func0(v5);
*(_WORD *)(v7 + 3) = result;
return result;
}

original_code:
static inline void msg_init_header(msg_hdr_t *hdr, uint16_t client_id,
                                   uint8_t type, uint16_t len)
{
    hdr->client_id = htons(client_id);
    hdr->type = type;
    hdr->length = htons(len);
}

canonical_original_code:
static inline void msg_init_header(struct msg_hdr *hdr, unsigned short client_id, unsigned char type, unsigned short len)
{
    hdr->client_id = htons(client_id);
    hdr->type = type;
    hdr->length = htons(len);
}

variable_types: struct msg_hdr { unsigned short client_id; unsigned char type; unsigned short length; } *

variable_types:
type
unsigned char

variable_types:
len
unsigned short


decompiled_code:
__int16 __fastcall msg_get_client_id(__int16 *a1)
{
return _bswap_16(*a1);
}

canonical_decompiled_code:
__int16 __fastcall func2(__int16 *a1)
{
return func0(*a1);
}

original_code:
static inline uint16_t msg_get_client_id(msg_hdr_t *h)
{
    return ntohs(h->client_id);
}

canonical_original_code:
static inline unsigned short msg_get_client_id(struct msg_hdr *h)
{
    return ntohs(h->client_id);
}

return_type: unsigned short

user_defined_types: struct msg_hdr { unsigned short client_id; unsigned char type; unsigned short length; }


decompiled_code:
__int16 __fastcall msg_get_length(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 3));
}

canonical_decompiled_code:
__int16 __fastcall func3(__int64 a1)
{
return func0(*(_WORD *)(a1 + 3));
}

original_code:
static inline uint16_t msg_get_length(msg_hdr_t *h)
{
    return ntohs(h->length);
}

canonical_original_code:
static inline unsigned short msg_get_length(struct msg_hdr *h)
{
    return ntohs(h->length);
}


decompiled_code:
__int64 __fastcall msg_send_msg(__int64 a1, __int16 a2, char a3, __int64 *a4, int a5)
{
unsigned int v5; // er9
__int64 v6; // r10
int v7; // eax
__int64 result; // rax
__int64 v9; // [rsp+1h] [rbp-41Bh] BYREF
__int64 v10[130]; // [rsp+9h] [rbp-413h] BYREF

if ( a5 > 1024 )
return 0xFFFFFFFFLL;
switch ( a3 )
{
case 0:
goto LABEL_14;
case 1:
case 4:
case 7:
case 8:
goto LABEL_3;
case 2:
case 3:
case 5:
case 6:
if ( (unsigned __int64)a5 >= 8 )
{
v10[0] = *a4;
*(__int64 *)((char *)&v9 + a5) = *(__int64 *)((char *)a4 + a5 - 8);
qmemcpy(
(char *)v10 + 3,
(char *)a4 - ((char *)v10 - ((char *)v10 + 3)),
8 * ((unsigned __int64)((char *)v10 - ((char *)v10 + 3) + a5) >> 3));
}
else if ( (a5 & 4) != 0 )
{
LODWORD(v10[0]) = *(_DWORD *)a4;
*(_DWORD *)((char *)v10 + a5 - 4) = *(_DWORD *)((char *)a4 + a5 - 4);
}
else if ( a5 )
{
LOBYTE(v10[0]) = *(_BYTE *)a4;
if ( (a5 & 2) != 0 )
*(_WORD *)((char *)v10 + a5 - 2) = *(_WORD *)((char *)a4 + a5 - 2);
}
LABEL_3:
msg_init_header((__int64)&v9 + 3, a2);
v7 = sock_send(v6, (char *)&v9 + 3, v5);
if ( v7 < 0 )
LABEL_14:
result = 0xFFFFFFFFLL;
else
result = v7 == 0 ? 0xFFFFFFFE : 0;
break;
default:
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int16 a2, char a3, __int64 *a4, int a5)
{
unsigned int v5; // er9
__int64 v6; // r10
int v7; // eax
__int64 result; // rax
__int64 v9; // [rsp+1h] [rbp-41Bh] BYREF
__int64 v10[130]; // [rsp+9h] [rbp-413h] BYREF

if ( a5 > 1024 )
return 0xFFFFFFFFLL;
switch ( a3 )
{
case 0:
goto LABEL_14;
case 1:
case 4:
case 7:
case 8:
goto LABEL_3;
case 2:
case 3:
case 5:
case 6:
if ( (unsigned __int64)a5 >= 8 )
{
v10[0] = *a4;
*(__int64 *)((char *)&v9 + a5) = *(__int64 *)((char *)a4 + a5 - 8);
qmemcpy(
(char *)v10 + 3,
(char *)a4 - ((char *)v10 - ((char *)v10 + 3)),
8 * ((unsigned __int64)((char *)v10 - ((char *)v10 + 3) + a5) >> 3));
}
else if ( (a5 & 4) != 0 )
{
LODWORD(v10[0]) = *(_DWORD *)a4;
*(_DWORD *)((char *)v10 + a5 - 4) = *(_DWORD *)((char *)a4 + a5 - 4);
}
else if ( a5 )
{
LOBYTE(v10[0]) = *(_BYTE *)a4;
if ( (a5 & 2) != 0 )
*(_WORD *)((char *)v10 + a5 - 2) = *(_WORD *)((char *)a4 + a5 - 2);
}
LABEL_3:
func1((__int64)&v9 + 3, a2);
v7 = sock_send(v6, (char *)&v9 + 3, v5);
if ( v7 < 0 )
LABEL_14:
result = 0xFFFFFFFFLL;
else
result = v7 == 0 ? 0xFFFFFFFE : 0;
break;
default:
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int msg_send_msg(socket_t *to, uint16_t client_id, uint8_t type,
                 char *data, int data_len)
{
    char buf[1024 + sizeof(msg_hdr_t)];
    int len;
    if(data_len > 1024)
        return -1;
    switch(type)
    {
        case 0x02:
        case 0x03:
        case 0x05:
        case 0x06:
            memcpy(buf+sizeof(msg_hdr_t), data, data_len);
            break;
        case 0x01:
        case 0x04:
        case 0x07:
        case 0x08:
            data_len = 0;
            break;
        default:
            return -1;
    }
    len = data_len + sizeof(msg_hdr_t);
    msg_init_header((msg_hdr_t *)buf, client_id, type, data_len);
    len = sock_send(to, buf, len);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

canonical_original_code:
int msg_send_msg(struct socket *to, unsigned short client_id, unsigned char type, char *data, int data_len)
{
    char buf[-1];
    int len;
    if(data_len > 1024)
        return -1;
    switch(type)
    {
        case 0x02:
        case 0x03:
        case 0x05:
        case 0x06:
            memcpy(buf+sizeof(msg_hdr_t), data, data_len);
            break;
        case 0x01:
        case 0x04:
        case 0x07:
        case 0x08:
            data_len = 0;
            break;
        default:
            return -1;
    }
    len = data_len + sizeof(msg_hdr_t);
    msg_init_header((struct msg_hdr *)buf, client_id, type, data_len);
    len = sock_send(to, buf, len);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

variable_types:
data
char *

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall msg_send_hello(__int64 a1, const char *a2, const char *a3, __int16 a4)
{
int v5; // ebx
int v6; // ebx
char *v7; // rax
char *v8; // rbp
const char *v9; // rdx
int v10; // ebx
__int64 result; // rax

v5 = strlen(a2);
v6 = strlen(a3) + v5;
v7 = (char *)malloc(v6 + 4);
if ( v7
&& (v8 = v7,
*(_WORD *)v7 = _bswap_16(a4),
snprintf(v8 + 2, v6 + 2, v9),
v10 = msg_send_msg(a1, 0, 2, (__int64 *)v8, v6 + 3),
free(v8),
v10 >= 0) )
{
result = v10 == 0 ? 0xFFFFFFFE : 0;
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, const char *a3, __int16 a4)
{
int v5; // ebx
int v6; // ebx
char *v7; // rax
char *v8; // rbp
const char *v9; // rdx
int v10; // ebx
__int64 result; // rax

v5 = strlen(a2);
v6 = strlen(a3) + v5;
v7 = (char *)malloc(v6 + 4);
if ( v7
&& (v8 = v7,
*(_WORD *)v7 = func0(a4),
snprintf(v8 + 2, v6 + 2, v9),
v10 = func5(a1, 0, 2, (__int64 *)v8, v6 + 3),
free(v8),
v10 >= 0) )
{
result = v10 == 0 ? 0xFFFFFFFE : 0;
}
else
{
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int msg_send_hello(socket_t *to, char *host, char *port, uint16_t req_id)
{
    char *data;
    int str_len;
    int len;
    str_len = strlen(host) + strlen(port) + 2;
    len = str_len + sizeof(req_id);
    data = malloc(len);
    if(!data)
        return -1;
    *((uint16_t *)data) = htons(req_id);
    snprintf(data + sizeof(req_id), str_len, "%s %s", host, port);
    len = msg_send_msg(to, 0, 0x02, data, len-1);
    free(data);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

canonical_original_code:
int msg_send_hello(struct socket *to, char *host, char *port, unsigned short req_id)
{
    char *data;
    int str_len;
    int len;
    str_len = strlen(host) + strlen(port) + 2;
    len = str_len + sizeof(req_id);
    data = malloc(len);
    if(!data)
        return -1;
    *((unsigned short *)data) = htons(req_id);
    snprintf(data + sizeof(req_id), str_len, "%s %s", host, port);
    len = msg_send_msg(to, 0, 0x02, data, len-1);
    free(data);
    if(len < 0)
        return -1;
    else if(len == 0)
        return -2;
    else
        return 0;
}

variable_types:
host
char *

variable_types:
port
char *


decompiled_code:
__int64 __fastcall msg_recv_msg(__int64 a1, __int64 a2, void *a3, int a4, __int16 *a5, _BYTE *a6, unsigned __int16 *a7)
{
int v11; // eax
__int16 v12; // ax
unsigned int v13; // edi
unsigned __int16 v14; // ax
__int64 v15; // rdx
__int16 v17; // [rsp+0h] [rbp-438h] BYREF
unsigned __int8 v18; // [rsp+2h] [rbp-436h]
char src[1075]; // [rsp+5h] [rbp-433h] BYREF

v11 = sock_recv(a1, a2, &v17, 1029LL);
if ( v11 < 0 )
return 0xFFFFFFFFLL;
if ( !v11 )
return 4294967294LL;
v12 = msg_get_client_id(&v17);
v13 = v18;
*a5 = v12;
*a6 = msg_get_type_isra_0(v13);
v14 = msg_get_length((__int64)&v17);
if ( v15 != v14 )
{
*a7 = v14;
return 0xFFFFFFFFLL;
}
if ( v14 > a4 )
v14 = a4;
*a7 = v14;
memcpy(a3, src, v14);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, void *a3, int a4, __int16 *a5, _BYTE *a6, unsigned __int16 *a7)
{
int v11; // eax
__int16 v12; // ax
unsigned int v13; // edi
unsigned __int16 v14; // ax
__int64 v15; // rdx
__int16 v17; // [rsp+0h] [rbp-438h] BYREF
unsigned __int8 v18; // [rsp+2h] [rbp-436h]
char src[1075]; // [rsp+5h] [rbp-433h] BYREF

v11 = sock_recv(a1, a2, &v17, 1029LL);
if ( v11 < 0 )
return 0xFFFFFFFFLL;
if ( !v11 )
return 4294967294LL;
v12 = func2(&v17);
v13 = v18;
*a5 = v12;
*a6 = func4(v13);
v14 = func3((__int64)&v17);
if ( v15 != v14 )
{
*a7 = v14;
return 0xFFFFFFFFLL;
}
if ( v14 > a4 )
v14 = a4;
*a7 = v14;
memcpy(a3, src, v14);
return 0LL;
}

original_code:
int msg_recv_msg(socket_t *sock, socket_t *from, char *data, int data_len,
                 uint16_t *client_id, uint8_t *type, uint16_t *length)
{
    char buf[1024 + sizeof(msg_hdr_t)];
    msg_hdr_t *hdr_ptr;
    char *msg_ptr;
    int ret;
    hdr_ptr = (msg_hdr_t *)buf;
    msg_ptr = buf + sizeof(msg_hdr_t);
    ret = sock_recv(sock, from, buf, sizeof(buf));
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    *client_id = msg_get_client_id(hdr_ptr);
    *type = msg_get_type(hdr_ptr);
    *length = msg_get_length(hdr_ptr);
    if(ret-sizeof(msg_hdr_t) != *length)
        return -1;
    *length = ((data_len) < (*length) ? (data_len) : (*length));
    memcpy(data, msg_ptr, *length);
    return 0;
}

canonical_original_code:
int msg_recv_msg(struct socket *sock, struct socket *from, char *data, int data_len, unsigned short *client_id, unsigned char *type, unsigned short *length)
{
    char buf[-1];
    struct msg_hdr *hdr_ptr;
    char *msg_ptr;
    int ret;
    hdr_ptr = (struct msg_hdr *)buf;
    msg_ptr = buf + sizeof(msg_hdr_t);
    ret = sock_recv(sock, from, buf, sizeof(buf));
    if(ret < 0)
        return -1;
    else if(ret == 0)
        return -2;
    *client_id = msg_get_client_id(hdr_ptr);
    *type = msg_get_type(hdr_ptr);
    *length = msg_get_length(hdr_ptr);
    if(ret-sizeof(msg_hdr_t) != *length)
        return -1;
    *length = ((data_len) < (*length) ? (data_len) : (*length));
    memcpy(data, msg_ptr, *length);
    return 0;
}

variable_types:
from
struct socket *

variable_types:
type
unsigned char *

variable_types:
length
unsigned short *

variable_types: ret int


repo: arturoc/shift

decompiled_code:
double __fastcall freenect_get_tilt_degs(__int64 a1)
{
return (double)*(char *)(a1 + 6) * 0.5;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1)
{
return (double)*(char *)(a1 + 6) * 0.5;
}

original_code:
double freenect_get_tilt_degs(freenect_raw_tilt_state *state)
{
 return ((double)state->tilt_angle) / 2.;
}

canonical_original_code:
double freenect_get_tilt_degs(struct freenect_raw_tilt_state *state)
{
 return ((double)state->tilt_angle) / 2.;
}

variable_types: struct freenect_raw_tilt_state { short accelerometer_x; short accelerometer_y; short accelerometer_z; char tilt_angle; enum freenect_tilt_status_code { TILT_STATUS_STOPPED=0, TILT_STATUS_LIMIT=1, TILT_STATUS_MOVING=4 } tilt_status; } *

return_type: double

user_defined_types: struct freenect_raw_tilt_state { short accelerometer_x; short accelerometer_y; short accelerometer_z; char tilt_angle; enum freenect_tilt_status_code tilt_status; }


original_code:
void freenect_get_mks_accel(freenect_raw_tilt_state *state, double* x, double* y, double* z)
{
 *x = (double)state->accelerometer_x/819*9.80665;
 *y = (double)state->accelerometer_y/819*9.80665;
 *z = (double)state->accelerometer_z/819*9.80665;
}

canonical_original_code:
void freenect_get_mks_accel(struct freenect_raw_tilt_state *state, double *x, double *y, double *z)
{
 *x = (double)state->accelerometer_x/819*9.80665;
 *y = (double)state->accelerometer_y/819*9.80665;
 *z = (double)state->accelerometer_z/819*9.80665;
}

variable_types:
x
double *

variable_types:
y
double *

variable_types:
z
double *

user_defined_types: enum freenect_tilt_status_code { TILT_STATUS_STOPPED=0, TILT_STATUS_LIMIT=1, TILT_STATUS_MOVING=4 }


decompiled_code:
char *__fastcall new_str(char *src)
{
size_t v1; // r12
char *v2; // rax

v1 = strlen(src) + 1;
v2 = (char *)malloc(v1);
return strncpy(v2, src, v1);
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // r12
char *v2; // rax

v1 = strlen(src) + 1;
v2 = (char *)malloc(v1);
return strncpy(v2, src, v1);
}

original_code:
char *new_str(const char *val) {
    size_t l = strlen(val);
    char *res = (char *)malloc(l + 1);
    strncpy(res, val, l + 1);
    return res;
}

canonical_original_code:
char *new_str(char *val) {
    unsigned long l = strlen(val);
    char *res = (char *)malloc(l + 1);
    strncpy(res, val, l + 1);
    return res;
}

variable_types:
val
char *

variable_types:
l
unsigned long

variable_types:
res
char *

return_type: char *


decompiled_code:
char *__fastcall str_cat(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // r12

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
strncpy(v4, src, v2 + 1);
strncpy(&v4[v2], a2, v3 + 1);
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, char *a2)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // r12

v2 = strlen(src);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 1);
strncpy(v4, src, v2 + 1);
strncpy(&v4[v2], a2, v3 + 1);
return v4;
}

original_code:
char *str_cat(const char *a, const char *b) {
    char *res = (char *)malloc(strlen(a) + strlen(b) + 1);
    strncpy(res, a, strlen(a) + 1);
    strncpy(res + strlen(a), b, strlen(b) + 1);
    return res;
}

canonical_original_code:
char *str_cat(char *a, char *b) {
    char *res = (char *)malloc(strlen(a) + strlen(b) + 1);
    strncpy(res, a, strlen(a) + 1);
    strncpy(res + strlen(a), b, strlen(b) + 1);
    return res;
}

variable_types:
a
char *

variable_types:
b
char *


decompiled_code:
char *__fastcall str_split(char *s, char a2, int *a3)
{
size_t v5; // rbx
int v6; // er15
int v7; // ebx
unsigned __int64 v8; // rax
int v9; // edi
char *v10; // rax
int v12; // ebp
size_t v13; // rdx

v5 = 0LL;
*a3 = 0;
if ( a2 == *s )
{
while ( 1 )
{
v12 = v5;
v6 = v5 + 1;
v13 = strlen(s);
if ( v13 <= v5 )
break;
++v5;
*a3 = v6;
if ( s[v5] != a2 )
{
v12 = v6;
v13 = strlen(s);
break;
}
}
}
else
{
v12 = 0;
v13 = strlen(s);
}
v7 = 0;
v8 = v12 + 1LL;
do
{
v9 = v7++;
if ( v13 <= v8 )
break;
++v8;
}
while ( s[v8 - 1] != a2 );
v10 = (char *)calloc(v9 + 2, 1uLL);
return strncpy(v10, &s[*a3], v7);
}

canonical_decompiled_code:
char *__fastcall func2(char *s, char a2, int *a3)
{
size_t v5; // rbx
int v6; // er15
int v7; // ebx
unsigned __int64 v8; // rax
int v9; // edi
char *v10; // rax
int v12; // ebp
size_t v13; // rdx

v5 = 0LL;
*a3 = 0;
if ( a2 == *s )
{
while ( 1 )
{
v12 = v5;
v6 = v5 + 1;
v13 = strlen(s);
if ( v13 <= v5 )
break;
++v5;
*a3 = v6;
if ( s[v5] != a2 )
{
v12 = v6;
v13 = strlen(s);
break;
}
}
}
else
{
v12 = 0;
v13 = strlen(s);
}
v7 = 0;
v8 = v12 + 1LL;
do
{
v9 = v7++;
if ( v13 <= v8 )
break;
++v8;
}
while ( s[v8 - 1] != a2 );
v10 = (char *)calloc(v9 + 2, 1uLL);
return strncpy(v10, &s[*a3], v7);
}

original_code:
char *str_split(const char *a, const char b, int *start) {
    char *res;
    int size = 0;
    *start = 0;
    while(a[*start] == b && *start < strlen(a)) {
        ++(*start);
    }
    do {
        ++size;
        if(*start + size >= strlen(a)) {
            break;
        }
    } while(a[*start + size] != b);
    res = malloc(size + 1);
    memset(res, 0, size + 1);
    strncpy(res, a + *start, size);
    return res;
}

canonical_original_code:
char *str_split(char *a, char b, int *start) {
    char *res;
    int size = 0;
    *start = 0;
    while(a[*start] == b && *start < strlen(a)) {
        ++(*start);
    }
    do {
        ++size;
        if(*start + size >= strlen(a)) {
            break;
        }
    } while(a[*start + size] != b);
    res = malloc(size + 1);
    memset(res, 0, size + 1);
    strncpy(res, a + *start, size);
    return res;
}

variable_types: b char

variable_types:
start
int *

variable_types: size int


original_code:
char *str_split_rev(const char *a, const char b, int *pos) {
    char *res;
    *pos = strlen(a);
    while(a[--(*pos)] == b && *pos > 0);
    while(a[--(*pos)] != b && *pos >= 0);
    ++(*pos);
    res = (char *)malloc(*pos + 1);
    memset(res, 0, *pos + 1);
    strncpy(res, a, *pos);
    return res;
}

canonical_original_code:
char *str_split_rev(char *a, char b, int *pos) {
    char *res;
    *pos = strlen(a);
    while(a[--(*pos)] == b && *pos > 0);
    while(a[--(*pos)] != b && *pos >= 0);
    ++(*pos);
    res = (char *)malloc(*pos + 1);
    memset(res, 0, *pos + 1);
    strncpy(res, a, *pos);
    return res;
}

variable_types:
pos
int *


decompiled_code:
size_t __fastcall http_buffering(void *src, __int64 a2, __int64 a3, size_t *a4)
{
size_t v4; // r12
size_t v6; // r13
void *v7; // r15
char *v8; // rbp
size_t v10; // [rsp+8h] [rbp-40h]

v4 = a3 * a2;
v6 = *a4;
v7 = (void *)a4[1];
v10 = *a4 + a3 * a2;
v8 = (char *)calloc(v10 + 1, 1uLL);
memcpy(v8, v7, v6);
memcpy(&v8[v6], src, v4);
a4[1] = (size_t)v8;
*a4 = v10;
free(v7);
return v4;
}

canonical_decompiled_code:
size_t __fastcall func1(void *src, __int64 a2, __int64 a3, size_t *a4)
{
size_t v4; // r12
size_t v6; // r13
void *v7; // r15
char *v8; // rbp
size_t v10; // [rsp+8h] [rbp-40h]

v4 = a3 * a2;
v6 = *a4;
v7 = (void *)a4[1];
v10 = *a4 + a3 * a2;
v8 = (char *)calloc(v10 + 1, 1uLL);
memcpy(v8, v7, v6);
memcpy(&v8[v6], src, v4);
a4[1] = (size_t)v8;
*a4 = v10;
free(v7);
return v4;
}

original_code:
size_t http_buffering(char *buf, size_t size, size_t nmemb, void *userdata) {
    int i;
    char *tmp, *old_buf;
    struct http_buf_data *dst = (struct http_buf_data *)userdata;
    old_buf = dst -> buf;
    tmp = malloc(dst -> len + size * nmemb + 1);
    memset(tmp, 0, dst -> len + size * nmemb + 1);
    memcpy(tmp, dst -> buf, dst -> len);
    memcpy(tmp + (dst -> len), buf, size * nmemb);
    dst -> buf = tmp;
    dst -> len += size * nmemb;
    userdata = (void *)dst;
    free(old_buf);
    return size * nmemb;
}

canonical_original_code:
unsigned long http_buffering(char *buf, unsigned long size, unsigned long nmemb, void *userdata) {
    int i;
    char *tmp; char *old_buf;
    struct http_buf_data *dst = (struct http_buf_data *)userdata;
    old_buf = dst -> buf;
    tmp = malloc(dst -> len + size * nmemb + 1);
    memset(tmp, 0, dst -> len + size * nmemb + 1);
    memcpy(tmp, dst -> buf, dst -> len);
    memcpy(tmp + (dst -> len), buf, size * nmemb);
    dst -> buf = tmp;
    dst -> len += size * nmemb;
    userdata = (void *)dst;
    free(old_buf);
    return size * nmemb;
}

variable_types:
buf
char *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types:
userdata
void *

variable_types: i int

variable_types:
tmp
char *

variable_types: struct http_buf_data { unsigned long len; char *buf; } *

return_type: unsigned long