decompiled_code:
_BOOL8 __fastcall chiudi_connessione(int a1)
{
return close(a1) == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return close(a1) == -1;
}

original_code:
int chiudi_connessione(int id_connessione) {
 if (close(id_connessione) == -1)
  return 1;
 return 0;
}


repo: fsferrara/legacy-address-book

decompiled_code:
int __fastcall inserisci_record(_BYTE *a1)
{
int result; // eax

fwrite("\tNome: ", 1uLL, 7uLL, stdout);
leggistringa(a1);
fwrite("\tCognome: ", 1uLL, 0xAuLL, stdout);
leggistringa(a1 + 40);
fwrite("\tIndirizzo: ", 1uLL, 0xCuLL, stdout);
leggistringa(a1 + 80);
fwrite("\tTelefono: ", 1uLL, 0xBuLL, stdout);
leggistringa(a1 + 170);
fwrite("\tE-Mail: ", 1uLL, 9uLL, stdout);
result = leggistringa(a1 + 210);
a1[250] = 78;
return result;
}

canonical_decompiled_code:
int __fastcall func1(_BYTE *a1)
{
int result; // eax

fwrite("\tNome: ", 1uLL, 7uLL, stdout);
func0(a1);
fwrite("\tCognome: ", 1uLL, 0xAuLL, stdout);
func0(a1 + 40);
fwrite("\tIndirizzo: ", 1uLL, 0xCuLL, stdout);
func0(a1 + 80);
fwrite("\tTelefono: ", 1uLL, 0xBuLL, stdout);
func0(a1 + 170);
fwrite("\tE-Mail: ", 1uLL, 9uLL, stdout);
result = func0(a1 + 210);
a1[250] = 78;
return result;
}

original_code:
void inserisci_record(struct contatto *new) {
 fprintf(stdout,"\tNome: ");
 leggistringa(new->nome);
 fprintf(stdout,"\tCognome: ");
 leggistringa(new->cognome);
 fprintf(stdout,"\tIndirizzo: ");
 leggistringa(new->indirizzo);
 fprintf(stdout,"\tTelefono: ");
 leggistringa(new->telefono);
 fprintf(stdout,"\tE-Mail: ");
 leggistringa(new->email);
 new->marcatura = 'N';
}

variable_types: struct contatto { char nome[40]; char cognome[40]; char indirizzo[90]; char telefono[40]; char email[40]; char marcatura; } *

return_type: void


connetti

decompiled_code:
__int64 __fastcall connetti(char *cp, __int16 a2)
{
int v2; // edx
int v3; // eax
unsigned int v4; // er12
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v6[0] = 0LL;
if ( inet_pton(2, cp, &v6[0].sa_data[2]) <= 0 )
{
fwrite("connetti(): ip inserito non valido\n", 1uLL, 0x23uLL, stdout);
exit(1);
}
v6[0].sa_family = 2;
*(_WORD *)v6[0].sa_data = _bswap_16(a2);
v3 = socket(2, 1, v2);
v4 = v3;
if ( v3 < 0 )
{
fwrite("connetti(): impossibile creare il socket\n", 1uLL, 0x29uLL, stdout);
exit(1);
}
if ( connect(v3, v6, 0x10u) < 0 )
{
close(v4);
perror("connetti(): impossibile connettersi");
exit(1);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *cp, __int16 a2)
{
int v2; // edx
int v3; // eax
unsigned int v4; // er12
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v6[0] = 0LL;
if ( inet_pton(2, cp, &v6[0].sa_data[2]) <= 0 )
{
fwrite("connetti(): ip inserito non valido\n", 1uLL, 0x23uLL, stdout);
exit(1);
}
v6[0].sa_family = 2;
*(_WORD *)v6[0].sa_data = func0(a2);
v3 = socket(2, 1, v2);
v4 = v3;
if ( v3 < 0 )
{
fwrite("connetti(): impossibile creare il socket\n", 1uLL, 0x29uLL, stdout);
exit(1);
}
if ( connect(v3, v6, 0x10u) < 0 )
{
close(v4);
perror("connetti(): impossibile connettersi");
exit(1);
}
return v4;
}

original_code:
int connetti(char *ip, int portnum) {
 struct sockaddr_in sock_address;
 int id_connessione;
 bzero(&sock_address, sizeof(struct sockaddr_in));
 if (inet_pton(2, ip, &sock_address.sin_addr) <= 0) {
  fprintf(stdout,"connetti(): ip inserito non valido\n");
  exit(1);
 }
 sock_address.sin_family = 2;
 sock_address.sin_port = htons((u_short) portnum);
 id_connessione = socket(2, SOCK_STREAM, 0);
 if (id_connessione < 0) {
  fprintf(stdout,"connetti(): impossibile creare il socket\n");
  exit(1);
 }
 if (connect(id_connessione, (struct sockaddr *) &sock_address, sizeof(struct sockaddr_in)) < 0) {
  close(id_connessione);
  perror("connetti(): impossibile connettersi");
  exit(1);
 }
 return id_connessione;
}

canonical_original_code:
int connetti(char *ip, int portnum) {
 struct sockaddr_in sock_address;
 int id_connessione;
 bzero(&sock_address, sizeof(struct sockaddr_in));
 if (inet_pton(2, ip, &sock_address.sin_addr) <= 0) {
  fprintf(stdout,"connetti(): ip inserito non valido\n");
  exit(1);
 }
 sock_address.sin_family = 2;
 sock_address.sin_port = htons((unsigned short) portnum);
 id_connessione = socket(2, SOCK_STREAM, 0);
 if (id_connessione < 0) {
  fprintf(stdout,"connetti(): impossibile creare il socket\n");
  exit(1);
 }
 if (connect(id_connessione, (struct sockaddr *) &sock_address, sizeof(struct sockaddr_in)) < 0) {
  close(id_connessione);
  perror("connetti(): impossibile connettersi");
  exit(1);
 }
 return id_connessione;
}

variable_types:
ip
char *

variable_types: portnum int

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

return_type: int

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

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


decompiled_code:
int __fastcall chiudi_connessione(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
{
perror("chiudi_connessione()");
exit(1);
}
return result;
}

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

result = close(a1);
if ( result == -1 )
{
perror("chiudi_connessione()");
exit(1);
}
return result;
}

original_code:
void chiudi_connessione(int id_connessione) {
 if (close(id_connessione) == -1)
  perror("chiudi_connessione()"), exit(1);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = 15728640;
v3 = open("mpv955info", 577, 420LL);
if ( v3 < 0 )
{
perror("open()");
exit(1);
}
v4 = v3;
if ( write(v3, buf, 4uLL) == 4 )
{
if ( close(v4) >= 0 )
exit(0);
}
else
{
perror("write()");
if ( close(v4) >= 0 )
goto LABEL_4;
}
perror("close()");
LABEL_4:
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
 int fd;
 ssize_t byte;
 mpv955_info_t info;
 int dr_id, major, nodo;
 info.base_address = 0x00F00000;
 fd = open("mpv955info", 01 | 0100 | 01000, 0644);
 if (fd < 0) {
  perror("open()");
  exit(1);
 }
 byte = write(fd, &info, sizeof(mpv955_info_t));
 if (byte != sizeof(mpv955_info_t)) {
  perror("write()");
  if (close(fd) < 0)
   perror("close()");
  exit(1);
 }
 if (close(fd) < 0) {
  perror("close()");
  exit(1);
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int fd;
 long byte;
 struct mpv955_info info;
 int dr_id; int major; int nodo;
 info.base_address = 0x00F00000;
 fd = open("mpv955info", 01 | 0100 | 01000, 0644);
 if (fd < 0) {
  perror("open()");
  exit(1);
 }
 byte = write(fd, &info, sizeof(mpv955_info_t));
 if (byte != sizeof(mpv955_info_t)) {
  perror("write()");
  if (close(fd) < 0)
   perror("close()");
  exit(1);
 }
 if (close(fd) < 0) {
  perror("close()");
  exit(1);
 }
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fd int

variable_types: byte long

variable_types: struct mpv955_info { unsigned int base_address; }

variable_types: major int

variable_types: nodo int


decompiled_code:
void on_bluetooth_activate()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !g_allowedmodes )
{
puts("the mode: bt(bluetooth) is disabled!");
return;
}
adjust_func_state();
if ( g_iscardin )
{
if ( !g_state )
{
puts("call onbluetoothactive, the last state already is on_bluetooth");
g_isclickinginprogress = 0;
return;
}
if ( (unsigned int)(g_state - 1) <= 1 )
{
if ( !(unsigned int)unplugdevices() )
{
puts("unplugdivice fail ! ");
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(1LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0x7A120u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 0;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
}
}
else
{
g_state = 3;
puts("call on_bluetooth_active, return for the g_iscardin = FALSE");
g_isclickinginprogress = 0;
}
}
}

canonical_decompiled_code:
void func0()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !g_allowedmodes )
{
puts("the mode: bt(bluetooth) is disabled!");
return;
}
adjust_func_state();
if ( g_iscardin )
{
if ( !g_state )
{
puts("call onbluetoothactive, the last state already is on_bluetooth");
g_isclickinginprogress = 0;
return;
}
if ( (unsigned int)(g_state - 1) <= 1 )
{
if ( !(unsigned int)unplugdevices() )
{
puts("unplugdivice fail ! ");
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(1LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0x7A120u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 0;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
}
}
else
{
g_state = 3;
puts("call on_bluetooth_active, return for the g_iscardin = FALSE");
g_isclickinginprogress = 0;
}
}
}

original_code:
void on_bluetooth_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  if (g_allowedmodes[0] == 0)
  {
    printf("the mode: bt(bluetooth) is disabled!\n");
    return;
  }
  adjust_func_state();
  if (!g_iscardin)
  {
    g_state = 3;
    printf("call on_bluetooth_active, return for the g_iscardin = FALSE\n");
    g_isclickinginprogress = 0;
    return;
  }
  if (g_state == 0)
  {
    printf("call onbluetoothactive, the last state already is on_bluetooth\n");
    g_isclickinginprogress = 0;
    return;
  }
  if (g_state == 1
      || g_state == 2)
  {
    if (0 == unplugdevices())
    {
      printf("unplugdivice fail ! \n");
      g_isclickinginprogress = 0;
      return;
    }
    wait_device_unplug_stable();
  }
  write_enum_mode(1);
  if (g_downfromfile == 0)
  {
    tdsp_download_dsp_code(1);
  }
  else
  {
    tdsp_download_dsp_code_from_file(1);
  }
  usleep(500000);
  tdsp_add_device("Tdspbus\\TdspBluetooth\0", sizeof("Tdspbus\\TdspBluetooth\0"), 1);
  usleep(500000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    return;
  }
  g_state = 0;
  g_isclickinginprogress = 0;
  init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
  return;
}


decompiled_code:
void on_wlan_activate()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !*((_DWORD *)&g_allowedmodes + 1) )
{
puts("the mode: wlan is disabled!");
return;
}
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
g_isclickinginprogress = 0;
puts(" call the function on_wlan_active, return for g_iscardin=FALSE");
return;
}
if ( g_state == 1 )
{
puts("\nWLAN menu have been selected already , out !");
g_isclickinginprogress = 0;
return;
}
usleep(0x7A120u);
if ( (g_state & 0xFFFFFFFD) == 0 )
{
if ( !(unsigned int)unplugdevices() )
{
LABEL_12:
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(2LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( !(unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
return;
}
g_state = 1;
goto LABEL_12;
}
}

canonical_decompiled_code:
void func1()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !*((_DWORD *)&g_allowedmodes + 1) )
{
puts("the mode: wlan is disabled!");
return;
}
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
g_isclickinginprogress = 0;
puts(" call the function on_wlan_active, return for g_iscardin=FALSE");
return;
}
if ( g_state == 1 )
{
puts("\nWLAN menu have been selected already , out !");
g_isclickinginprogress = 0;
return;
}
usleep(0x7A120u);
if ( (g_state & 0xFFFFFFFD) == 0 )
{
if ( !(unsigned int)unplugdevices() )
{
LABEL_12:
g_isclickinginprogress = 0;
return;
}
wait_device_unplug_stable();
}
write_enum_mode(2LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x7A120u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( !(unsigned int)tdsp_is_download_dspcode_ok() )
{
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
return;
}
g_state = 1;
goto LABEL_12;
}
}

original_code:
void on_wlan_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  if (g_allowedmodes[1] == 0)
  {
    printf("the mode: wlan is disabled!\n");
    return;
  }
  adjust_func_state();
  if (g_iscardin == 0)
  {
    g_state = 3;
    g_isclickinginprogress = 0;
    printf(" call the function on_wlan_active, return for g_iscardin=FALSE\n");
    return;
  }
  if (g_state == 1)
  {
    printf("\nWLAN menu have been selected already , out !\n");
    g_isclickinginprogress = 0;
    return;
  }
  usleep(500000);
  if (g_state == 0 || g_state == 2)
  {
    if (0 == unplugdevices())
    {
      g_isclickinginprogress = 0;
      return;
    }
    wait_device_unplug_stable();
  }
  write_enum_mode(2);
  if (g_downfromfile == 0)
    tdsp_download_dsp_code(2);
  else
    tdsp_download_dsp_code_from_file(2);
  usleep(500000);
  tdsp_add_device("Tdspbus\\TdspWlan\0", sizeof("Tdspbus\\TdspWlan\0"), 2);
  usleep(1000000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    return;
  }
  g_state = 1;
  g_isclickinginprogress = 0;
  return;
}


decompiled_code:
void on_coexist_activate()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !g_allowedmodes[2] )
{
puts("the mode: combo is disabled!");
return;
}
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
g_isclickinginprogress = 0;
puts("on_coexist_active, return for nocardin");
return;
}
if ( g_state == 2 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for its current state also is COEXIST");
return;
}
usleep(0x7A120u);
if ( g_state <= 1u )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for unplugdevices fail");
return;
}
wait_device_unplug_stable();
}
write_enum_mode(3LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( !(unsigned int)tdsp_is_download_dspcode_ok() )
goto LABEL_20;
while ( 1 )
{
tdsp_query_pnp_state(2LL);
if ( g_dsppnpstate == 1 )
break;
tdsp_query_power_state();
if ( g_buspowerstate != 1 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for power fail");
return;
}
usleep(0x7A120u);
}
tdsp_set_init_flag(2LL);
usleep(0x7A120u);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0xF4240u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
tdsp_set_init_flag(1LL);
g_state = 2;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
LABEL_20:
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
puts("on_coexist_active, return for download_dspcode fail");
}
}
}

canonical_decompiled_code:
void func2()
{
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
if ( !g_allowedmodes[2] )
{
puts("the mode: combo is disabled!");
return;
}
adjust_func_state();
if ( !g_iscardin )
{
g_state = 3;
g_isclickinginprogress = 0;
puts("on_coexist_active, return for nocardin");
return;
}
if ( g_state == 2 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for its current state also is COEXIST");
return;
}
usleep(0x7A120u);
if ( g_state <= 1u )
{
if ( !(unsigned int)unplugdevices() )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for unplugdevices fail");
return;
}
wait_device_unplug_stable();
}
write_enum_mode(3LL);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(2LL);
else
tdsp_download_dsp_code(2LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspWlan", 18LL, 2LL);
usleep(0xF4240u);
if ( !(unsigned int)tdsp_is_download_dspcode_ok() )
goto LABEL_20;
while ( 1 )
{
tdsp_query_pnp_state(2LL);
if ( g_dsppnpstate == 1 )
break;
tdsp_query_power_state();
if ( g_buspowerstate != 1 )
{
g_isclickinginprogress = 0;
puts("on_coexist_active, return for power fail");
return;
}
usleep(0x7A120u);
}
tdsp_set_init_flag(2LL);
usleep(0x7A120u);
if ( g_downfromfile )
tdsp_download_dsp_code_from_file(1LL);
else
tdsp_download_dsp_code(1LL);
usleep(0x30D40u);
tdsp_add_device("Tdspbus\\TdspBluetooth", 23LL, 1LL);
usleep(0xF4240u);
if ( (unsigned int)tdsp_is_download_dspcode_ok() )
{
tdsp_set_init_flag(1LL);
g_state = 2;
g_isclickinginprogress = 0;
init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
}
else
{
LABEL_20:
g_state = 3;
adjust_func_state();
g_isclickinginprogress = 0;
puts("on_coexist_active, return for download_dspcode fail");
}
}
}

original_code:
void on_coexist_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  if (g_allowedmodes[2] == 0)
  {
    printf("the mode: combo is disabled!\n");
    return;
  }
  adjust_func_state();
  if (!g_iscardin)
  {
    g_state = 3;
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for nocardin\n");
    return;
  }
  if (g_state == 2)
  {
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for its current state also is COEXIST\n");
    return;
  }
  usleep(500000);
  if (g_state == 0|| g_state == 1)
  {
    if (0 == unplugdevices())
    {
      g_isclickinginprogress = 0;
      printf("on_coexist_active, return for unplugdevices fail\n");
      return;
    }
    wait_device_unplug_stable();
  }
  write_enum_mode(3);
  if (g_downfromfile == 0)
    tdsp_download_dsp_code(2);
  else
    tdsp_download_dsp_code_from_file(2);
  usleep(200000);
  tdsp_add_device("Tdspbus\\TdspWlan\0", sizeof("Tdspbus\\TdspWlan\0"), 2);
  usleep(1000000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for download_dspcode fail\n");
    return;
  }
  while (1)
  {
    tdsp_query_pnp_state(2);
    if (g_dsppnpstate != Started)
    {
      tdsp_query_power_state();
      if (g_buspowerstate != 1)
      {
        g_isclickinginprogress = 0;
        printf("on_coexist_active, return for power fail\n");
        return;
      }
      usleep(500000);
      continue;
    }
    else
    {
      break;
    }
  }
  tdsp_set_init_flag(2);
  usleep(500000);
  if (g_downfromfile == 0)
    tdsp_download_dsp_code(1);
  else
    tdsp_download_dsp_code_from_file(1);
  usleep(200000);
  tdsp_add_device("Tdspbus\\TdspBluetooth\0", sizeof("Tdspbus\\TdspBluetooth\0"), 1);
  usleep(1000000);
  if (tdsp_is_download_dspcode_ok() == 0)
  {
    g_state = 3;
    adjust_func_state();
    g_isclickinginprogress = 0;
    printf("on_coexist_active, return for download_dspcode fail\n");
    return;
  }
  tdsp_set_init_flag(1);
  g_state = 2;
  g_isclickinginprogress = 0;
  init_tdsp_otherenv("/usr/local/3DSP/usb/btusbcfg.sh");
  return;
}


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

result = g_isclickinginprogress;
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
adjust_func_state();
result = g_state;
if ( g_state != 3 )
{
if ( g_state <= 2u )
{
result = unplugdevices();
if ( !(_DWORD)result )
goto LABEL_5;
result = wait_device_unplug_stable();
}
g_state = 3;
}
LABEL_5:
g_isclickinginprogress = 0;
}
return result;
}

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

result = g_isclickinginprogress;
if ( !g_isclickinginprogress )
{
g_isclickinginprogress = 1;
adjust_func_state();
result = g_state;
if ( g_state != 3 )
{
if ( g_state <= 2u )
{
result = unplugdevices();
if ( !(_DWORD)result )
goto LABEL_5;
result = wait_device_unplug_stable();
}
g_state = 3;
}
LABEL_5:
g_isclickinginprogress = 0;
}
return result;
}

original_code:
void on_unplug_activate()
{
  if (g_isclickinginprogress != 0)
  {
    ;
    return;
  }
  g_isclickinginprogress = 1;
  ;
  adjust_func_state();
  if (g_state == 3)
  {
    g_isclickinginprogress = 0;
    return;
  }
  if (g_state == 0
      || g_state == 1
      || g_state == 2)
  {
    if (0 == unplugdevices())
    {
      ;
      g_isclickinginprogress = 0;
      return;
    }
    wait_device_unplug_stable();
  }
  g_state = 3;
  g_isclickinginprogress = 0;
  return;
}


decompiled_code:
__int64 on_about_activate()
{
return update_ver_string();
}

canonical_decompiled_code:
__int64 func4()
{
return update_ver_string();
}

original_code:
void on_about_activate()
{
  update_ver_string();
}


decompiled_code:
__int64 on_poweron_activate()
{
logging("calling on on_poweron_active ", 457LL);
return tdsp_power_on();
}

canonical_decompiled_code:
__int64 func5()
{
logging("calling on on_poweron_active ", 457LL);
return tdsp_power_on();
}

original_code:
void on_poweron_activate()
{
  logging("calling on on_poweron_active  ", 457);
  tdsp_power_on();
}


decompiled_code:
__int64 on_poweroff_activate()
{
return tdsp_power_off();
}

canonical_decompiled_code:
__int64 func6()
{
return tdsp_power_off();
}

original_code:
void on_poweroff_activate()
{
  ;
  tdsp_power_off();
}


emalloc

repo: fsouza/yatf

decompiled_code:
void *__fastcall emalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("FATAL: can't allocate memory.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("FATAL: can't allocate memory.\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

original_code:
void *
emalloc(size_t size)
{
 void *p;
 p = malloc(size);
 if(p == ((void *)0)) {
  fprintf(stderr, "FATAL: can't allocate memory.\n");
  exit(1);
 }
 return p;
}

canonical_original_code:
void *emalloc(unsigned long size)
{
 void *p;
 p = malloc(size);
 if(p == ((void *)0)) {
  fprintf(stderr, "FATAL: can't allocate memory.\n");
  exit(1);
 }
 return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


original_code:
void
free_test(test_t *t)
{
 failure_t *f;
 while(t->failures != ((void *)0)) {
  f = t->failures;
  t->failures = t->failures->next;
  free(f->reason);
  free(f);
 }
}

canonical_original_code:
void free_test(struct test_t *t)
{
 struct failure_t *f;
 while(t->failures != ((void *)0)) {
  f = t->failures;
  t->failures = t->failures->next;
  free(f->reason);
  free(f);
 }
}

variable_types: struct test_t { char *name; struct failure_t { char *reason; struct failure_t *next; } *failures; int failed; void (*fn)(struct test_t *t); } *

user_defined_types: struct test_t { char *name; struct failure_t *failures; int failed; void (*fn)(struct test_t *t); }


decompiled_code:
void free_suite()
{
void **v0; // rbx
void **v1; // rbp
void *v2; // rdi

v0 = (void **)r;
if ( r )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
v2 = *v1;
r = v0;
free_test((__int64)v2);
free(*v1);
free(v1);
}
while ( v0 );
}
}

original_code:
void
free_suite(void)
{
 registry_t *p;
 while(r != ((void *)0)) {
  p = r;
  r = r->next;
  free_test(p->item);
  free(p->item);
  free(p);
 }
}

canonical_original_code:
void free_suite()
{
 struct test_list_t *p;
 while(r != ((void *)0)) {
  p = r;
  r = r->next;
  free_test(p->item);
  free(p->item);
  free(p);
 }
}

variable_types: struct test_list_t { struct test_t { char *name; struct failure_t { char *reason; struct failure_t *next; } *failures; int failed; void (*fn)(struct test_t *t); } *item; struct test_list_t *next; } *

user_defined_types: struct test_list_t { struct test_t *item; struct test_list_t *next; }


decompiled_code:
__int64 __fastcall test_fail(__int64 a1, const char *a2)
{
_QWORD *v2; // rbp
size_t v3; // rax
char *v4; // rax
__int64 result; // rax

v2 = emalloc(0x10uLL);
v3 = strlen(a2);
v4 = (char *)emalloc(v3 + 1);
*v2 = v4;
strcpy(v4, a2);
result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 8) = v2;
v2[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
_QWORD *v2; // rbp
size_t v3; // rax
char *v4; // rax
__int64 result; // rax

v2 = func0(0x10uLL);
v3 = strlen(a2);
v4 = (char *)func0(v3 + 1);
*v2 = v4;
strcpy(v4, a2);
result = *(_QWORD *)(a1 + 8);
*(_DWORD *)(a1 + 16) = 1;
*(_QWORD *)(a1 + 8) = v2;
v2[1] = result;
return result;
}

original_code:
void
test_fail(test_t *t, char* reason)
{
 failure_t *failure;
 failure = (failure_t *)emalloc(sizeof(failure_t));
 failure->reason = (char *)emalloc((strlen(reason) + 1) * sizeof(char));
 strcpy(failure->reason, reason);
 failure->next = t->failures;
 t->failures = failure;
 t->failed = 1;
}

canonical_original_code:
void test_fail(struct test_t *t, char *reason)
{
 struct failure_t *failure;
 failure = (struct failure_t *)emalloc(sizeof(failure_t));
 failure->reason = (char *)emalloc((strlen(reason) + 1) * sizeof(char));
 strcpy(failure->reason, reason);
 failure->next = t->failures;
 t->failures = failure;
 t->failed = 1;
}

variable_types:
reason
char *

variable_types: struct failure_t { char *reason; struct failure_t *next; } *


decompiled_code:
_BOOL8 run_tests()
{
unsigned int v0; // er13
unsigned int v1; // er12
const char ***v2; // rbx
const char *i; // rbp
__int64 v4; // rdx
_BOOL8 result; // rax

v0 = 0;
v1 = 0;
v2 = (const char ***)r;
if ( r )
{
do
{
while ( 1 )
{
++v1;
((void (__fastcall *)(const char **))(*v2)[3])(*v2);
if ( *((_DWORD *)*v2 + 4) )
break;
v2 = (const char ***)v2[1];
if ( !v2 )
goto LABEL_8;
}
printf("FAIL: %s\n", **v2);
for ( i = (*v2)[1]; i; i = (const char *)*((_QWORD *)i + 1) )
printf(" %s\n", *(const char **)i);
++v0;
putchar(10);
v2 = (const char ***)v2[1];
}
while ( v2 );
LABEL_8:
free_suite();
v4 = 115LL;
if ( v1 == 1 )
v4 = 0LL;
printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", v1, v4, v1 - v0, v0);
result = (int)v0 > 0;
}
else
{
puts("Warning: no tests to run.");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func4()
{
unsigned int v0; // er13
unsigned int v1; // er12
const char ***v2; // rbx
const char *i; // rbp
__int64 v4; // rdx
_BOOL8 result; // rax

v0 = 0;
v1 = 0;
v2 = (const char ***)r;
if ( r )
{
do
{
while ( 1 )
{
++v1;
((void (__fastcall *)(const char **))(*v2)[3])(*v2);
if ( *((_DWORD *)*v2 + 4) )
break;
v2 = (const char ***)v2[1];
if ( !v2 )
goto LABEL_8;
}
printf("FAIL: %s\n", **v2);
for ( i = (*v2)[1]; i; i = (const char *)*((_QWORD *)i + 1) )
printf(" %s\n", *(const char **)i);
++v0;
putchar(10);
v2 = (const char ***)v2[1];
}
while ( v2 );
LABEL_8:
func2();
v4 = 115LL;
if ( v1 == 1 )
v4 = 0LL;
printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", v1, v4, v1 - v0, v0);
result = (int)v0 > 0;
}
else
{
puts("Warning: no tests to run.");
result = 0LL;
}
return result;
}

original_code:
int
run_tests(void)
{
 registry_t *p = r;
 failure_t *f;
 int ran, failed, plural;
 ran = failed = 0;
 if(r == ((void *)0)) {
  printf("Warning: no tests to run.\n");
  return 0;
 }
 while(p != ((void *)0)) {
  p->item->fn(p->item);
  ran++;
  if(p->item->failed) {
   printf("FAIL: %s\n", p->item->name);
   f = p->item->failures;
   while(f != ((void *)0)) {
    printf("      %s\n", f->reason);
    f = f->next;
   }
   printf("\n");
   failed++;
  }
  p = p->next;
 }
 free_suite();
 plural = ran > 1 ? 's' : '\0';
 printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", ran, plural, ran-failed, failed);
 return failed > 0;
}

canonical_original_code:
int run_tests()
{
 struct test_list_t *p = r;
 struct failure_t *f;
 int ran; int failed; int plural;
 ran = failed = 0;
 if(r == ((void *)0)) {
  printf("Warning: no tests to run.\n");
  return 0;
 }
 while(p != ((void *)0)) {
  p->item->fn(p->item);
  ran++;
  if(p->item->failed) {
   printf("FAIL: %s\n", p->item->name);
   f = p->item->failures;
   while(f != ((void *)0)) {
    printf("      %s\n", f->reason);
    f = f->next;
   }
   printf("\n");
   failed++;
  }
  p = p->next;
 }
 free_suite();
 plural = ran > 1 ? 's' : '\0';
 printf("Ran: %d test%c. Succeeded: %d. Failed: %d.\n", ran, plural, ran-failed, failed);
 return failed > 0;
}

variable_types: ran int

variable_types: failed int

variable_types: plural int

user_defined_types: struct failure_t { char *reason; struct failure_t *next; }


repo: ftnapps/pkg-sbbs

decompiled_code:
int safe_snprintf(char *s, size_t maxlen, const char *a3, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
result = vsnprintf(s, maxlen, a3, arg);
s[maxlen - 1] = 0;
if ( result > 0 && result >= (int)maxlen )
result = maxlen - 1;
return result;
}

canonical_decompiled_code:
int func0(char *s, size_t maxlen, const char *a3, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a3);
result = vsnprintf(s, maxlen, a3, arg);
s[maxlen - 1] = 0;
if ( result > 0 && result >= (int)maxlen )
result = maxlen - 1;
return result;
}

original_code:
int safe_snprintf(char *dst, size_t size, const char *fmt, ...)
{
 va_list argptr;
 int numchars;
 __builtin_va_start(argptr,fmt);
 numchars= vsnprintf(dst,size,fmt,argptr);
 __builtin_va_end(argptr);
 dst[size-1]=0;
 if(numchars>=(int)size && numchars>0)
  numchars=size-1;
 return(numchars);
}

canonical_original_code:
int safe_snprintf(char *dst, unsigned long size, char *fmt, ...)
{
 __builtin_va_list argptr;
 int numchars;
 __builtin_va_start(argptr,fmt);
 numchars= vsnprintf(dst,size,fmt,argptr);
 __builtin_va_end(argptr);
 dst[size-1]=0;
 if(numchars>=(int)size && numchars>0)
  numchars=size-1;
 return(numchars);
}

variable_types:
dst
char *

variable_types:
fmt
char *

variable_types: numchars int


lastchar

decompiled_code:
__int64 __fastcall lastchar(const char *a1)
{
__int64 v1; // r12
size_t v2; // rax

v1 = (__int64)a1;
v2 = strlen(a1);
if ( v2 )
v1 = (__int64)&a1[v2 - 1];
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
__int64 v1; // r12
size_t v2; // rax

v1 = (__int64)a1;
v2 = strlen(a1);
if ( v2 )
v1 = (__int64)&a1[v2 - 1];
return v1;
}

original_code:
char* lastchar(const char* str)
{
 size_t len;
 len = strlen(str);
 if(len)
  return((char*)&str[len-1]);
 return((char*)str);
}

canonical_original_code:
char *lastchar(char *str)
{
 unsigned long len;
 len = strlen(str);
 if(len)
  return((char *)&str[len-1]);
 return((char *)str);
}

variable_types:
str
char *

variable_types:
len
unsigned long

return_type: char *


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

switch ( (char)a1 )
{
case 'a':
result = 7LL;
break;
case 'b':
result = 8LL;
break;
case 'e':
result = 27LL;
break;
case 'f':
result = 12LL;
break;
case 'n':
result = 10LL;
break;
case 'r':
result = 13LL;
break;
case 't':
result = 9LL;
break;
case 'v':
result = 11LL;
break;
default:
result = a1;
break;
}
return result;
}

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

switch ( (char)a1 )
{
case 'a':
result = 7LL;
break;
case 'b':
result = 8LL;
break;
case 'e':
result = 27LL;
break;
case 'f':
result = 12LL;
break;
case 'n':
result = 10LL;
break;
case 'r':
result = 13LL;
break;
case 't':
result = 9LL;
break;
case 'v':
result = 11LL;
break;
default:
result = a1;
break;
}
return result;
}

original_code:
char c_unescape_char(char ch)
{
 switch(ch) {
  case 'e': return(0x1b);
  case 'a': return('\a');
  case 'b': return('\b');
  case 'f': return('\f');
  case 'n': return('\n');
  case 'r': return('\r');
  case 't': return('\t');
  case 'v': return('\v');
 }
 return(ch);
}

variable_types: ch char

return_type: char


decompiled_code:
__int64 __fastcall c_unescape_char_ptr(char *a1, char **a2)
{
const __int32_t **v2; // rax
__int64 v3; // r14
__int64 result; // rax

v2 = _ctype_toupper_loc();
v3 = *a1;
if ( (*v2)[v3] == 88 )
return strtol(a1 + 1, a2, 16);
if ( ((*_ctype_b_loc())[v3] & 0x800) != 0 )
return strtol(a1 + 1, a2, 8);
result = c_unescape_char((char)v3);
if ( a2 )
*a2 = a1 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, char **a2)
{
const __int32_t **v2; // rax
__int64 v3; // r14
__int64 result; // rax

v2 = _ctype_toupper_loc();
v3 = *a1;
if ( (*v2)[v3] == 88 )
return strtol(a1 + 1, a2, 16);
if ( ((*_ctype_b_loc())[v3] & 0x800) != 0 )
return strtol(a1 + 1, a2, 8);
result = func2((char)v3);
if ( a2 )
*a2 = a1 + 1;
return result;
}

original_code:
char c_unescape_char_ptr(const char* str, char** endptr)
{
 char ch;
 if(toupper(*str)=='X')
  ch=(char)strtol(++str,endptr,16);
 else if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISdigit))
  ch=(char)strtol(++str,endptr,8);
 else {
  ch=c_unescape_char(*(str++));
  if(endptr!=((void *)0))
   *endptr=(char*)str;
 }
 return(ch);
}

canonical_original_code:
char c_unescape_char_ptr(char *str, char **endptr)
{
 char ch;
 if(toupper(*str)=='X')
  ch=(char)strtol(++str,endptr,16);
 else if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISdigit))
  ch=(char)strtol(++str,endptr,8);
 else {
  ch=c_unescape_char(*(str++));
  if(endptr!=((void *)0))
   *endptr=(char *)str;
 }
 return(ch);
}

variable_types:
endptr
char **


decompiled_code:
const char *__fastcall c_unescape_str(const char *a1)
{
char *v2; // rax
char *v3; // r12
char *v4; // rdi
char v5; // al
char *v6; // rbx
char *v7; // rax
char *i; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0LL;
v2 = strdup(a1);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = v2 + 1;
v5 = *v2;
v6 = (char *)a1;
for ( i = v4; v5; v5 = *v7 )
{
if ( v5 == 92 )
v5 = c_unescape_char_ptr(v4, &i);
*v6 = v5;
v7 = i;
++v6;
v4 = ++i;
}
*v6 = 0;
free(v3);
return a1;
}

canonical_decompiled_code:
const char *__fastcall func4(const char *a1)
{
char *v2; // rax
char *v3; // r12
char *v4; // rdi
char v5; // al
char *v6; // rbx
char *v7; // rax
char *i; // [rsp+0h] [rbp-20h] BYREF

if ( !a1 )
return 0LL;
v2 = strdup(a1);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = v2 + 1;
v5 = *v2;
v6 = (char *)a1;
for ( i = v4; v5; v5 = *v7 )
{
if ( v5 == 92 )
v5 = func3(v4, &i);
*v6 = v5;
v7 = i;
++v6;
v4 = ++i;
}
*v6 = 0;
free(v3);
return a1;
}

original_code:
char* c_unescape_str(char* str)
{
 char ch;
 char* buf;
 char* src;
 char* dst;
 if(str==((void *)0) || (buf=strdup(str))==((void *)0))
  return(((void *)0));
 src=buf;
 dst=str;
 while((ch=*(src++))!=0) {
  if(ch=='\\')
   ch=c_unescape_char_ptr(src,&src);
  *(dst++)=ch;
 }
 *dst=0;
 free(buf);
 return(str);
}

canonical_original_code:
char *c_unescape_str(char *str)
{
 char ch;
 char *buf;
 char *src;
 char *dst;
 if(str==((void *)0) || (buf=strdup(str))==((void *)0))
  return(((void *)0));
 src=buf;
 dst=str;
 while((ch=*(src++))!=0) {
  if(ch=='\\')
   ch=c_unescape_char_ptr(src,&src);
  *(dst++)=ch;
 }
 *dst=0;
 free(buf);
 return(str);
}

variable_types:
buf
char *

variable_types:
src
char *


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

result = 0LL;
if ( a1 <= 0x5Cu )
result = CSWTCH_21[a1];
return result;
}

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

result = 0LL;
if ( a1 <= 0x5Cu )
result = CSWTCH_21[a1];
return result;
}

original_code:
char* c_escape_char(char ch)
{
 switch(ch) {
  case 0: return("\\x00");
  case 1: return("\\x01");
  case 0x1b: return("\\e");
  case '\a': return("\\a");
  case '\b': return("\\b");
  case '\f': return("\\f");
  case '\n': return("\\n");
  case '\r': return("\\r");
  case '\t': return("\\t");
  case '\v': return("\\v");
  case '\\': return("\\\\");
  case '\"': return("\\\"");
  case '\'': return("\\'");
 }
 return(((void *)0));
}

canonical_original_code:
char *c_escape_char(char ch)
{
 switch(ch) {
  case 0: return("\\x00");
  case 1: return("\\x01");
  case 0x1b: return("\\e");
  case '\a': return("\\a");
  case '\b': return("\\b");
  case '\f': return("\\f");
  case '\n': return("\\n");
  case '\r': return("\\r");
  case '\t': return("\\t");
  case '\v': return("\\v");
  case '\\': return("\\\\");
  case '\"': return("\\\"");
  case '\'': return("\\'");
 }
 return(((void *)0));
}


decompiled_code:
char *__fastcall c_escape_str(unsigned __int8 *a1, char *a2, unsigned __int64 a3, int a4)
{
char *v4; // r14
unsigned __int8 v6; // cl
unsigned __int8 *v8; // rbx
unsigned __int8 *v9; // rdx
char *v10; // rsi
__int64 v11; // r8
unsigned __int8 *v12; // r13
char *result; // rax

v4 = a2;
v6 = *a1;
if ( *a1 && a3 )
{
v8 = a1;
v9 = (unsigned __int8 *)a2;
do
{
if ( a4 && v6 > 0x1Fu || (v10 = c_escape_char(v6)) == 0LL )
{
*v9 = v6;
}
else
{
*v9 = 0;
v12 = v9 + 1;
strncat(v4, v10, a3 - v11);
v9 = v12;
}
v6 = *++v8;
++v9;
}
while ( v6 && v9 - (unsigned __int8 *)v4 < a3 );
*v9 = 0;
result = v4;
}
else
{
result = a2;
*a2 = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned __int8 *a1, char *a2, unsigned __int64 a3, int a4)
{
char *v4; // r14
unsigned __int8 v6; // cl
unsigned __int8 *v8; // rbx
unsigned __int8 *v9; // rdx
char *v10; // rsi
__int64 v11; // r8
unsigned __int8 *v12; // r13
char *result; // rax

v4 = a2;
v6 = *a1;
if ( *a1 && a3 )
{
v8 = a1;
v9 = (unsigned __int8 *)a2;
do
{
if ( a4 && v6 > 0x1Fu || (v10 = func5(v6)) == 0LL )
{
*v9 = v6;
}
else
{
*v9 = 0;
v12 = v9 + 1;
strncat(v4, v10, a3 - v11);
v9 = v12;
}
v6 = *++v8;
++v9;
}
while ( v6 && v9 - (unsigned __int8 *)v4 < a3 );
*v9 = 0;
result = v4;
}
else
{
result = a2;
*a2 = 0;
}
return result;
}

original_code:
char* c_escape_str(const char* src, char* dst, size_t maxlen, int ctrl_only)
{
 const char* s;
 char* d;
 char* e;
 for(s=src,d=dst;*s && (size_t)(d-dst)<maxlen;s++,d++) {
  if((!ctrl_only || (unsigned char)*s < ' ') && (e=c_escape_char(*s))!=((void *)0)) {
   *d=0;
   strncat(dst,e,maxlen-(d-dst));
   d++;
  } else *d=*s;
 }
 *d=0;
 return(dst);
}

canonical_original_code:
char *c_escape_str(char *src, char *dst, unsigned long maxlen, int ctrl_only)
{
 char *s;
 char *d;
 char *e;
 for(s=src,d=dst;*s && (unsigned long)(d-dst)<maxlen;s++,d++) {
  if((!ctrl_only || (unsigned char)*s < ' ') && (e=c_escape_char(*s))!=((void *)0)) {
   *d=0;
   strncat(dst,e,maxlen-(d-dst));
   d++;
  } else *d=*s;
 }
 *d=0;
 return(dst);
}

variable_types:
maxlen
unsigned long

variable_types:
s
char *

variable_types:
d
char *

variable_types:
e
char *


strrev

decompiled_code:
const char *__fastcall strrev(const char *a1)
{
char *v1; // rax
char *v2; // rdx
char v3; // cl
char v4; // si

v1 = (char *)&a1[strlen(a1)];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v2;
v4 = *--v1;
*v2++ = v4;
*v1 = v3;
}
while ( v1 > v2 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func9(const char *a1)
{
char *v1; // rax
char *v2; // rdx
char v3; // cl
char v4; // si

v1 = (char *)&a1[strlen(a1)];
if ( a1 < v1 )
{
v2 = (char *)a1;
do
{
v3 = *v2;
v4 = *--v1;
*v2++ = v4;
*v1 = v3;
}
while ( v1 > v2 );
}
return a1;
}

original_code:
char* strrev(char* str)
{
    char t, *i=str, *j=str+strlen(str);
    while (i<j) {
        t=*i; *(i++)=*(--j); *j=t;
    }
    return str;
}

canonical_original_code:
char *strrev(char *str)
{
    char t; char *i = str; char *j = str+strlen(str);
    while (i<j) {
        t=*i; *(i++)=*(--j); *j=t;
    }
    return str;
}

variable_types: t char

variable_types:
i
char *

variable_types:
j
char *


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

result = 0LL;
if ( a1 > 1 )
result = (unsigned int)(random() % a1);
return result;
}

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

result = 0LL;
if ( a1 > 1 )
result = (unsigned int)(random() % a1);
return result;
}

original_code:
int xp_random(int n)
{
 if(n<2)
  return(0);
 return(random()%n);
}

variable_types: n int


ultoa

decompiled_code:
char *__fastcall ultoa(__int64 a1, char *a2, __int64 a3)
{
char *result; // rax

if ( (_DWORD)a3 == 10 )
{
sprintf(a2, "%lu", a1);
result = a2;
}
else if ( (_DWORD)a3 == 16 )
{
sprintf(a2, "%lx", a1);
result = a2;
}
else
{
if ( (_DWORD)a3 == 8 )
sprintf(a2, "%lo", a1);
else
sprintf(a2, "bad radix: %d", a3);
result = a2;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1, char *a2, __int64 a3)
{
char *result; // rax

if ( (_DWORD)a3 == 10 )
{
sprintf(a2, "%lu", a1);
result = a2;
}
else if ( (_DWORD)a3 == 16 )
{
sprintf(a2, "%lx", a1);
result = a2;
}
else
{
if ( (_DWORD)a3 == 8 )
sprintf(a2, "%lo", a1);
else
sprintf(a2, "bad radix: %d", a3);
result = a2;
}
return result;
}

original_code:
char* ultoa(ulong val, char* str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%lo",val);
   break;
  case 10:
   sprintf(str,"%lu",val);
   break;
  case 16:
   sprintf(str,"%lx",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

canonical_original_code:
char *ultoa(unsigned long val, char *str, int radix)
{
 switch(radix) {
  case 8:
   sprintf(str,"%lo",val);
   break;
  case 10:
   sprintf(str,"%lu",val);
   break;
  case 16:
   sprintf(str,"%lx",val);
   break;
  default:
   sprintf(str,"bad radix: %d",radix);
   break;
 }
 return(str);
}

variable_types:
val
unsigned long

variable_types: radix int


decompiled_code:
char *__fastcall os_version(char *s)
{
int *v2; // rax
struct utsname v3; // [rsp+0h] [rbp-198h] BYREF

if ( uname(&v3) < 0 )
{
v2 = _errno_location();
sprintf(s, "Unix (uname errno: %d)", (unsigned int)*v2);
}
else
{
sprintf(s, "%s %s %s", v3.sysname, v3.release, v3.machine);
}
return s;
}

canonical_decompiled_code:
char *__fastcall func13(char *s)
{
int *v2; // rax
struct utsname v3; // [rsp+0h] [rbp-198h] BYREF

if ( uname(&v3) < 0 )
{
v2 = _errno_location();
sprintf(s, "Unix (uname errno: %d)", (unsigned int)*v2);
}
else
{
sprintf(s, "%s %s %s", v3.sysname, v3.release, v3.machine);
}
return s;
}

original_code:
char* os_version(char *str)
{
 struct utsname unixver;
 if(uname(&unixver)<0)
  sprintf(str,"Unix (uname errno: %d)",(*__errno_location ()));
 else
  sprintf(str,"%s %s %s"
   ,unixver.sysname
   ,unixver.release
   ,unixver.machine
   );
 return(str);
}

canonical_original_code:
char *os_version(char *str)
{
 struct utsname unixver;
 if(uname(&unixver)<0)
  sprintf(str,"Unix (uname errno: %d)",(*__errno_location ()));
 else
  sprintf(str,"%s %s %s"
   ,unixver.sysname
   ,unixver.release
   ,unixver.machine
   );
 return(str);
}

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }


decompiled_code:
char *os_cmdshell()
{
return getenv("SHELL");
}

canonical_decompiled_code:
char *func14()
{
return getenv("SHELL");
}

original_code:
char* os_cmdshell(void)
{
 char* shell=getenv("SHELL");
 return(shell);
}

canonical_original_code:
char *os_cmdshell()
{
 char *shell = getenv("SHELL");
 return(shell);
}

variable_types:
shell
char *


msclock

decompiled_code:
__suseconds_t msclock()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1LL;
else
result = (v1.tv_usec + 1000000 * v1.tv_sec) / 1000;
return result;
}

canonical_decompiled_code:
__suseconds_t func15()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1LL;
else
result = (v1.tv_usec + 1000000 * v1.tv_sec) / 1000;
return result;
}

original_code:
clock_t msclock(void)
{
 long long int usecs;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 usecs=tv.tv_sec*1000000+tv.tv_usec;
 return((clock_t)(usecs/(1000000/1000)));
}

canonical_original_code:
long msclock()
{
 long long usecs;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 usecs=tv.tv_sec*1000000+tv.tv_usec;
 return((clock_t)(usecs/(1000000/1000)));
}

variable_types:
usecs
long long

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

return_type: long


decompiled_code:
const char *__fastcall truncsp_lines(const char *a1)
{
const char *v1; // r12
char *v2; // rax
char v3; // cl
char *v4; // r8
const char *v5; // rax
char *v6; // rdi
char *v7; // rdx
char v8; // dl

v1 = a1;
v2 = strdup(a1);
if ( v2 )
{
v3 = *v2;
v4 = v2;
v5 = a1;
if ( v3 )
{
v6 = v4;
do
{
if ( v3 == 10 )
{
if ( v1 == v5 )
{
v7 = (char *)v1;
v5 = v1 + 1;
goto LABEL_5;
}
while ( 1 )
{
v8 = *(v5 - 1);
if ( (v8 & 0xFB) != 9 && v8 != 32 )
break;
if ( v8 == 10 )
break;
v7 = (char *)(v5 - 1);
if ( v1 == v5 - 1 )
goto LABEL_5;
--v5;
}
}
v7 = (char *)v5++;
LABEL_5:
++v6;
*v7 = v3;
v3 = *v6;
}
while ( *v6 );
}
*v5 = 0;
free(v4);
}
return v1;
}

original_code:
char* truncsp_lines(char* dst)
{
 char* sp;
 char* dp;
 char* src;
 if((src=strdup(dst))==((void *)0))
  return(dst);
 for(sp=src, dp=dst; *sp!=0; sp++) {
  if(*sp=='\n')
   while(dp!=dst
    && (*(dp-1)==' ' || *(dp-1)=='\t' || *(dp-1)=='\r') && *(dp-1)!='\n')
     dp--;
  *(dp++)=*sp;
 }
 *dp=0;
 free(src);
 return(dst);
}

canonical_original_code:
char *truncsp_lines(char *dst)
{
 char *sp;
 char *dp;
 char *src;
 if((src=strdup(dst))==((void *)0))
  return(dst);
 for(sp=src, dp=dst; *sp!=0; sp++) {
  if(*sp=='\n')
   while(dp!=dst
    && (*(dp-1)==' ' || *(dp-1)=='\t' || *(dp-1)=='\r') && *(dp-1)!='\n')
     dp--;
  *(dp++)=*sp;
 }
 *dp=0;
 free(src);
 return(dst);
}

variable_types:
dst
char *

variable_types:
sp
char *

variable_types:
dp
char *


truncnl

decompiled_code:
const char *__fastcall truncnl(const char *a1)
{
size_t v1; // rax
size_t v2; // rsi
char v3; // dl

v1 = strlen(a1);
v2 = v1;
while ( v1 )
{
v3 = a1[v1 - 1];
if ( v3 != 13 && v3 != 10 )
break;
--v1;
}
if ( v2 != v1 )
a1[v1] = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func18(const char *a1)
{
size_t v1; // rax
size_t v2; // rsi
char v3; // dl

v1 = strlen(a1);
v2 = v1;
while ( v1 )
{
v3 = a1[v1 - 1];
if ( v3 != 13 && v3 != 10 )
break;
--v1;
}
if ( v2 != v1 )
a1[v1] = 0;
return a1;
}

original_code:
char* truncnl(char* str)
{
 size_t i,len;
 i=len=strlen(str);
 while(i && (str[i-1]=='\r' || str[i-1]=='\n'))
  i--;
 if(i!=len)
  str[i]=0;
 return(str);
}

canonical_original_code:
char *truncnl(char *str)
{
 unsigned long i; unsigned long len;
 i=len=strlen(str);
 while(i && (str[i-1]=='\r' || str[i-1]=='\n'))
  i--;
 if(i!=len)
  str[i]=0;
 return(str);
}

variable_types:
str
char *

variable_types:
i
unsigned long

variable_types:
len
unsigned long


decompiled_code:
__int64 get_errno()
{
return (unsigned int)*_errno_location();
}

canonical_decompiled_code:
__int64 func19()
{
return (unsigned int)*_errno_location();
}

original_code:
int get_errno(void)
{
 return((*__errno_location ()));
}

canonical_original_code:
int get_errno()
{
 return((*__errno_location ()));
}


decompiled_code:
long double xp_timer()
{
long double result; // fst7
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1.0;
else
result = (long double)v1.tv_usec / 1000000.0 + (long double)v1.tv_sec;
return result;
}

canonical_decompiled_code:
long double func20()
{
long double result; // fst7
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) == 1 )
result = -1.0;
else
result = (long double)v1.tv_usec / 1000000.0 + (long double)v1.tv_sec;
return result;
}

original_code:
long double xp_timer(void)
{
 long double ret;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 ret=tv.tv_usec;
 ret /= 1000000;
 ret += tv.tv_sec;
 return(ret);
}

canonical_original_code:
long double xp_timer()
{
 long double ret;
 struct timeval tv;
 if(gettimeofday(&tv,((void *)0))==1)
  return(-1);
 ret=tv.tv_usec;
 ret /= 1000000;
 ret += tv.tv_sec;
 return(ret);
}

variable_types:
ret
long double

return_type: long double

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


ydecode

decompiled_code:
__int64 __fastcall ydecode(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v7; // r8
unsigned __int64 v8; // rdx
size_t v9; // rcx
bool v10; // si
size_t v11; // rdi
char v12; // al

if ( a4 )
{
v7 = a4;
}
else
{
v7 = strlen(a3);
if ( !v7 )
return 0LL;
}
v8 = 0LL;
v9 = 0LL;
if ( a2 )
{
while ( 1 )
{
v11 = v9 + 1;
v12 = a3[v9];
v10 = v9 + 1 < v7;
if ( v12 == 61 && v9 + 1 < v7 )
{
v9 += 2LL;
v10 = v9 < v7;
++v8;
*(_BYTE *)(a1 + v8 - 1) = a3[v11] - 106;
if ( a2 <= v8 )
return (unsigned int)v8;
}
else
{
++v8;
++v9;
*(_BYTE *)(a1 + v8 - 1) = v12 - 42;
if ( a2 <= v8 )
return (unsigned int)v8;
}
if ( !v10 )
return (unsigned int)v8;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v7; // r8
unsigned __int64 v8; // rdx
size_t v9; // rcx
bool v10; // si
size_t v11; // rdi
char v12; // al

if ( a4 )
{
v7 = a4;
}
else
{
v7 = strlen(a3);
if ( !v7 )
return 0LL;
}
v8 = 0LL;
v9 = 0LL;
if ( a2 )
{
while ( 1 )
{
v11 = v9 + 1;
v12 = a3[v9];
v10 = v9 + 1 < v7;
if ( v12 == 61 && v9 + 1 < v7 )
{
v9 += 2LL;
v10 = v9 < v7;
++v8;
*(_BYTE *)(a1 + v8 - 1) = a3[v11] - 106;
if ( a2 <= v8 )
return (unsigned int)v8;
}
else
{
++v8;
++v9;
*(_BYTE *)(a1 + v8 - 1) = v12 - 42;
if ( a2 <= v8 )
return (unsigned int)v8;
}
if ( !v10 )
return (unsigned int)v8;
}
}
return 0LL;
}

original_code:
int ydecode(char *target, size_t tlen, const char *source, size_t slen)
{
 char ch;
 size_t rd=0;
 size_t wr=0;
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch=='=' && rd<slen)
   ch=source[rd++]-64;
  ch-=42;
  target[wr++]=ch;
 }
 return(wr);
}

canonical_original_code:
int ydecode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 char ch;
 unsigned long rd = 0;
 unsigned long wr = 0;
 if(slen==0)
  slen=strlen(source);
 while(rd<slen && wr<tlen) {
  ch=source[rd++];
  if(ch=='=' && rd<slen)
   ch=source[rd++]-64;
  ch-=42;
  target[wr++]=ch;
 }
 return(wr);
}

variable_types:
target
char *

variable_types:
tlen
unsigned long

variable_types:
source
char *

variable_types:
slen
unsigned long

variable_types: ch char

variable_types:
rd
unsigned long

variable_types:
wr
unsigned long


yencode

decompiled_code:
size_t __fastcall yencode(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v4; // r8
unsigned __int64 v8; // rdx
size_t result; // rax
char v10; // di
char v11; // cl
unsigned __int64 v12; // rsi

v4 = a4;
if ( !a4 )
v4 = strlen(a3);
v8 = 0LL;
result = 0LL;
if ( !a2 )
return result;
while ( 1 )
{
v10 = a3[result++];
v11 = v10 + 42;
if ( (unsigned __int8)(v10 + 42) > 0x3Du || ((1LL << v11) & 0x2000000000002401LL) == 0 )
{
*(_BYTE *)(a1 + v8++) = v11;
if ( result > v4 )
break;
goto LABEL_7;
}
v12 = v8 + 1;
if ( a2 <= v8 + 1 )
break;
*(_BYTE *)(a1 + v8) = 61;
v8 += 2LL;
*(_BYTE *)(a1 + v12) = v10 + 106;
if ( result > v4 )
break;
LABEL_7:
if ( a2 <= v8 )
return (unsigned int)v8;
}
if ( a2 <= v8 )
return (unsigned int)v8;
*(_BYTE *)(a1 + v8) = 0;
return (unsigned int)(v8 + 1);
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1, unsigned __int64 a2, const char *a3, size_t a4)
{
size_t v4; // r8
unsigned __int64 v8; // rdx
size_t result; // rax
char v10; // di
char v11; // cl
unsigned __int64 v12; // rsi

v4 = a4;
if ( !a4 )
v4 = strlen(a3);
v8 = 0LL;
result = 0LL;
if ( !a2 )
return result;
while ( 1 )
{
v10 = a3[result++];
v11 = v10 + 42;
if ( (unsigned __int8)(v10 + 42) > 0x3Du || ((1LL << v11) & 0x2000000000002401LL) == 0 )
{
*(_BYTE *)(a1 + v8++) = v11;
if ( result > v4 )
break;
goto LABEL_7;
}
v12 = v8 + 1;
if ( a2 <= v8 + 1 )
break;
*(_BYTE *)(a1 + v8) = 61;
v8 += 2LL;
*(_BYTE *)(a1 + v12) = v10 + 106;
if ( result > v4 )
break;
LABEL_7:
if ( a2 <= v8 )
return (unsigned int)v8;
}
if ( a2 <= v8 )
return (unsigned int)v8;
*(_BYTE *)(a1 + v8) = 0;
return (unsigned int)(v8 + 1);
}

original_code:
int yencode(char *target, size_t tlen, const char *source, size_t slen)
{
 char ch;
 size_t rd=0;
 size_t wr=0;
 int done=0;
 if(slen==0)
  slen=strlen(source);
 while(rd<=slen && wr<tlen && !done) {
  ch=source[rd++];
  ch+=42;
  switch(ch) {
   case 0:
   case '\r':
   case '\n':
   case '=':
    if(wr+1>=tlen) {
     done=1;
     continue;
    }
    ch+=64;
    target[wr++]='=';
    break;
  }
  target[wr++]=ch;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}

canonical_original_code:
int yencode(char *target, unsigned long tlen, char *source, unsigned long slen)
{
 char ch;
 unsigned long rd = 0;
 unsigned long wr = 0;
 int done = 0;
 if(slen==0)
  slen=strlen(source);
 while(rd<=slen && wr<tlen && !done) {
  ch=source[rd++];
  ch+=42;
  switch(ch) {
   case 0:
   case '\r':
   case '\n':
   case '=':
    if(wr+1>=tlen) {
     done=1;
     continue;
    }
    ch+=64;
    target[wr++]='=';
    break;
  }
  target[wr++]=ch;
 }
 if(wr<tlen)
  target[wr++]=0;
 return(wr);
}

variable_types: done int


decompiled_code:
const char *__fastcall smb_hfieldtype(unsigned __int16 a1)
{
const char *result; // rax

switch ( a1 )
{
case 0u:
result = "Sender";
break;
case 1u:
result = "SenderAgent";
break;
case 2u:
result = "SenderNetType";
break;
case 3u:
result = "SenderNetAddr";
break;
case 4u:
result = "SenderExt";
break;
case 6u:
result = "SenderOrg";
break;
case 7u:
result = "SenderIpAddr";
break;
case 8u:
result = "SenderHostName";
break;
case 9u:
result = "SenderProtocol";
break;
case 0xAu:
result = "SenderPort";
break;
case 0x20u:
result = "ReplyTo";
break;
case 0x21u:
result = "ReplyToAgent";
break;
case 0x22u:
result = "ReplyToNetType";
break;
case 0x23u:
result = "ReplyToNetAddr";
break;
case 0x24u:
result = "ReplyToExt";
break;
case 0x30u:
result = "Recipient";
break;
case 0x31u:
result = "RecipientAgent";
break;
case 0x32u:
result = "RecipientNetType";
break;
case 0x33u:
result = "RecipientNetAddr";
break;
case 0x34u:
result = "RecipientExt";
break;
case 0x60u:
result = "Subject";
break;
case 0x61u:
result = "Summary";
break;
case 0x62u:
result = "Comment";
break;
case 0x63u:
result = "CarbonCopy";
break;
case 0x64u:
result = "Group";
break;
case 0x65u:
result = "Expiration";
break;
case 0x66u:
result = "Priority";
break;
case 0x67u:
result = "Cost";
break;
case 0xA0u:
result = "FidoCtrl";
break;
case 0xA1u:
result = "FidoArea";
break;
case 0xA2u:
result = "FidoSeenBy";
break;
case 0xA3u:
result = "FidoPath";
break;
case 0xA4u:
result = "FidoMsgID";
break;
case 0xA5u:
result = "FidoReplyID";
break;
case 0xA6u:
result = "FidoPID";
break;
case 0xA7u:
result = "FidoFlags";
break;
case 0xA8u:
result = "FidoTID";
break;
case 0xB0u:
result = "RFC822Header";
break;
case 0xB1u:
result = "RFC822MsgID";
break;
case 0xB2u:
result = "RFC822ReplyID";
break;
case 0xB3u:
result = "RFC822To";
break;
case 0xB4u:
result = "RFC822From";
break;
case 0xB5u:
result = "RFC822ReplyTo";
break;
case 0xC0u:
result = "UsenetPath";
break;
case 0xC1u:
result = "UsenetNewsgroups";
break;
case 0xD0u:
result = "SMTPCommand";
break;
case 0xD1u:
result = "SMTPReversePath";
break;
case 0xD2u:
result = "SMTPForwardPath";
break;
case 0xD8u:
result = "SMTPSysMsg";
break;
case 0xF1u:
result = "UNKNOWN";
break;
case 0xF2u:
result = "UNKNOWNASCII";
break;
case 0xFFu:
result = "UNUSED";
break;
default:
sprintf(str_4, "%02Xh", a1);
result = str_4;
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned __int16 a1)
{
const char *result; // rax

switch ( a1 )
{
case 0u:
result = "Sender";
break;
case 1u:
result = "SenderAgent";
break;
case 2u:
result = "SenderNetType";
break;
case 3u:
result = "SenderNetAddr";
break;
case 4u:
result = "SenderExt";
break;
case 6u:
result = "SenderOrg";
break;
case 7u:
result = "SenderIpAddr";
break;
case 8u:
result = "SenderHostName";
break;
case 9u:
result = "SenderProtocol";
break;
case 0xAu:
result = "SenderPort";
break;
case 0x20u:
result = "ReplyTo";
break;
case 0x21u:
result = "ReplyToAgent";
break;
case 0x22u:
result = "ReplyToNetType";
break;
case 0x23u:
result = "ReplyToNetAddr";
break;
case 0x24u:
result = "ReplyToExt";
break;
case 0x30u:
result = "Recipient";
break;
case 0x31u:
result = "RecipientAgent";
break;
case 0x32u:
result = "RecipientNetType";
break;
case 0x33u:
result = "RecipientNetAddr";
break;
case 0x34u:
result = "RecipientExt";
break;
case 0x60u:
result = "Subject";
break;
case 0x61u:
result = "Summary";
break;
case 0x62u:
result = "Comment";
break;
case 0x63u:
result = "CarbonCopy";
break;
case 0x64u:
result = "Group";
break;
case 0x65u:
result = "Expiration";
break;
case 0x66u:
result = "Priority";
break;
case 0x67u:
result = "Cost";
break;
case 0xA0u:
result = "FidoCtrl";
break;
case 0xA1u:
result = "FidoArea";
break;
case 0xA2u:
result = "FidoSeenBy";
break;
case 0xA3u:
result = "FidoPath";
break;
case 0xA4u:
result = "FidoMsgID";
break;
case 0xA5u:
result = "FidoReplyID";
break;
case 0xA6u:
result = "FidoPID";
break;
case 0xA7u:
result = "FidoFlags";
break;
case 0xA8u:
result = "FidoTID";
break;
case 0xB0u:
result = "RFC822Header";
break;
case 0xB1u:
result = "RFC822MsgID";
break;
case 0xB2u:
result = "RFC822ReplyID";
break;
case 0xB3u:
result = "RFC822To";
break;
case 0xB4u:
result = "RFC822From";
break;
case 0xB5u:
result = "RFC822ReplyTo";
break;
case 0xC0u:
result = "UsenetPath";
break;
case 0xC1u:
result = "UsenetNewsgroups";
break;
case 0xD0u:
result = "SMTPCommand";
break;
case 0xD1u:
result = "SMTPReversePath";
break;
case 0xD2u:
result = "SMTPForwardPath";
break;
case 0xD8u:
result = "SMTPSysMsg";
break;
case 0xF1u:
result = "UNKNOWN";
break;
case 0xF2u:
result = "UNKNOWNASCII";
break;
case 0xFFu:
result = "UNUSED";
break;
default:
sprintf(str_4, "%02Xh", a1);
result = str_4;
break;
}
return result;
}

original_code:
char* smb_hfieldtype(ushort type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("Sender");
  case 0x01: return("SenderAgent");
  case 0x02: return("SenderNetType");
  case 0x03: return("SenderNetAddr");
  case 0x04: return("SenderExt");
  case 0x06: return("SenderOrg");
  case 0x07: return("SenderIpAddr");
  case 0x08: return("SenderHostName");
  case 0x09: return("SenderProtocol");
  case 0x0a: return("SenderPort");
  case 0x20: return("ReplyTo");
  case 0x21: return("ReplyToAgent");
  case 0x22: return("ReplyToNetType");
  case 0x23: return("ReplyToNetAddr");
  case 0x24: return("ReplyToExt");
  case 0x30: return("Recipient");
  case 0x31: return("RecipientAgent");
  case 0x32: return("RecipientNetType");
  case 0x33: return("RecipientNetAddr");
  case 0x34: return("RecipientExt");
  case 0x60: return("Subject");
  case 0x61: return("Summary");
  case 0x62: return("Comment");
  case 0x63: return("CarbonCopy");
  case 0x64: return("Group");
  case 0x65: return("Expiration");
  case 0x66: return("Priority");
  case 0x67: return("Cost");
  case 0xa0: return("FidoCtrl");
  case 0xa1: return("FidoArea");
  case 0xa2: return("FidoSeenBy");
  case 0xa3: return("FidoPath");
  case 0xa4: return("FidoMsgID");
  case 0xa5: return("FidoReplyID");
  case 0xa6: return("FidoPID");
  case 0xa7: return("FidoFlags");
  case 0xa8: return("FidoTID");
  case 0xb0: return("RFC822Header");
  case 0xb1: return("RFC822MsgID");
  case 0xb2: return("RFC822ReplyID");
  case 0xb3: return("RFC822To");
  case 0xb4: return("RFC822From");
  case 0xb5: return("RFC822ReplyTo");
  case 0xc0: return("UsenetPath");
  case 0xc1: return("UsenetNewsgroups");
  case 0xd0: return("SMTPCommand");
  case 0xd1: return("SMTPReversePath");
  case 0xd2: return("SMTPForwardPath");
  case 0xd8: return("SMTPSysMsg");
  case 0xf1: return("UNKNOWN");
  case 0xf2: return("UNKNOWNASCII");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

canonical_original_code:
char *smb_hfieldtype(unsigned short type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("Sender");
  case 0x01: return("SenderAgent");
  case 0x02: return("SenderNetType");
  case 0x03: return("SenderNetAddr");
  case 0x04: return("SenderExt");
  case 0x06: return("SenderOrg");
  case 0x07: return("SenderIpAddr");
  case 0x08: return("SenderHostName");
  case 0x09: return("SenderProtocol");
  case 0x0a: return("SenderPort");
  case 0x20: return("ReplyTo");
  case 0x21: return("ReplyToAgent");
  case 0x22: return("ReplyToNetType");
  case 0x23: return("ReplyToNetAddr");
  case 0x24: return("ReplyToExt");
  case 0x30: return("Recipient");
  case 0x31: return("RecipientAgent");
  case 0x32: return("RecipientNetType");
  case 0x33: return("RecipientNetAddr");
  case 0x34: return("RecipientExt");
  case 0x60: return("Subject");
  case 0x61: return("Summary");
  case 0x62: return("Comment");
  case 0x63: return("CarbonCopy");
  case 0x64: return("Group");
  case 0x65: return("Expiration");
  case 0x66: return("Priority");
  case 0x67: return("Cost");
  case 0xa0: return("FidoCtrl");
  case 0xa1: return("FidoArea");
  case 0xa2: return("FidoSeenBy");
  case 0xa3: return("FidoPath");
  case 0xa4: return("FidoMsgID");
  case 0xa5: return("FidoReplyID");
  case 0xa6: return("FidoPID");
  case 0xa7: return("FidoFlags");
  case 0xa8: return("FidoTID");
  case 0xb0: return("RFC822Header");
  case 0xb1: return("RFC822MsgID");
  case 0xb2: return("RFC822ReplyID");
  case 0xb3: return("RFC822To");
  case 0xb4: return("RFC822From");
  case 0xb5: return("RFC822ReplyTo");
  case 0xc0: return("UsenetPath");
  case 0xc1: return("UsenetNewsgroups");
  case 0xd0: return("SMTPCommand");
  case 0xd1: return("SMTPReversePath");
  case 0xd2: return("SMTPForwardPath");
  case 0xd8: return("SMTPSysMsg");
  case 0xf1: return("UNKNOWN");
  case 0xf2: return("UNKNOWNASCII");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

variable_types:
type
unsigned short

variable_types:
str
char [8]


decompiled_code:
__int64 __fastcall smb_hfieldtypelookup(char *nptr)
{
unsigned int v1; // ebx
const char *v2; // rax

v1 = 0;
if ( ((*_ctype_b_loc())[*nptr] & 0x800) != 0 )
return (unsigned int)strtol(nptr, 0LL, 0);
do
{
v2 = smb_hfieldtype(v1);
if ( !strcasecmp(nptr, v2) )
return v1;
++v1;
}
while ( v1 != 256 );
return 241LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr)
{
unsigned int v1; // ebx
const char *v2; // rax

v1 = 0;
if ( ((*_ctype_b_loc())[*nptr] & 0x800) != 0 )
return (unsigned int)strtol(nptr, 0LL, 0);
do
{
v2 = func0(v1);
if ( !strcasecmp(nptr, v2) )
return v1;
++v1;
}
while ( v1 != 256 );
return 241LL;
}

original_code:
ushort smb_hfieldtypelookup(const char* str)
{
 ushort type;
 if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISdigit))
  return((ushort)strtol(str,((void *)0),0));
 for(type=0;type<=0xff;type++)
  if(strcasecmp(str,smb_hfieldtype(type))==0)
   return(type);
 return(0xf1);
}

canonical_original_code:
unsigned short smb_hfieldtypelookup(char *str)
{
 unsigned short type;
 if(((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISdigit))
  return((unsigned short)strtol(str,((void *)0),0));
 for(type=0;type<=0xff;type++)
  if(strcasecmp(str,smb_hfieldtype(type))==0)
   return(type);
 return(0xf1);
}

return_type: unsigned short


decompiled_code:
const char *__fastcall smb_dfieldtype(unsigned __int16 a1)
{
const char *result; // rax

result = "TEXT_TAIL";
if ( a1 != 2 )
{
result = "UNUSED";
if ( a1 != 255 )
{
result = "TEXT_BODY";
if ( a1 )
{
sprintf(str_3, "%02Xh", a1);
result = str_3;
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned __int16 a1)
{
const char *result; // rax

result = "TEXT_TAIL";
if ( a1 != 2 )
{
result = "UNUSED";
if ( a1 != 255 )
{
result = "TEXT_BODY";
if ( a1 )
{
sprintf(str_3, "%02Xh", a1);
result = str_3;
}
}
}
return result;
}

original_code:
char* smb_dfieldtype(ushort type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("TEXT_BODY");
  case 0x02: return("TEXT_TAIL");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

canonical_original_code:
char *smb_dfieldtype(unsigned short type)
{
 static char str[8];
 switch(type) {
  case 0x00: return("TEXT_BODY");
  case 0x02: return("TEXT_TAIL");
  case 0xff: return("UNUSED");
 }
 sprintf(str,"%02Xh",type);
 return(str);
}


decompiled_code:
char *__fastcall smb_hashsourcetype(unsigned __int8 a1)
{
switch ( a1 )
{
case 1u:
return (char *)smb_hfieldtype(0xB1u);
case 2u:
return (char *)smb_hfieldtype(0xA4u);
case 0u:
return (char *)smb_dfieldtype(0);
}
sprintf(str_2, "%02Xh", a1);
return str_2;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned __int8 a1)
{
switch ( a1 )
{
case 1u:
return (char *)func0(0xB1u);
case 2u:
return (char *)func0(0xA4u);
case 0u:
return (char *)func2(0);
}
sprintf(str_2, "%02Xh", a1);
return str_2;
}

original_code:
char* smb_hashsourcetype(unsigned char type)
{
 static char str[8];
 switch(type) {
  case SMB_HASH_SOURCE_BODY: return(smb_dfieldtype(0x00));
  case SMB_HASH_SOURCE_MSG_ID: return(smb_hfieldtype(0xb1));
  case SMB_HASH_SOURCE_FTN_ID: return(smb_hfieldtype(0xa4));
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

canonical_original_code:
char *smb_hashsourcetype(unsigned char type)
{
 static char str[8];
 switch(type) {
  case SMB_HASH_SOURCE_BODY: return(smb_dfieldtype(0x00));
  case SMB_HASH_SOURCE_MSG_ID: return(smb_hfieldtype(0xb1));
  case SMB_HASH_SOURCE_FTN_ID: return(smb_hfieldtype(0xa4));
 }
 sprintf(str,"%02Xh",type);
 return(str);
}

variable_types:
type
unsigned char


decompiled_code:
const char *__fastcall smb_hashsource(__int64 a1, int a2)
{
if ( a2 == 1 )
return *(const char **)(a1 + 208);
if ( a2 == 2 )
return *(const char **)(a1 + 288);
return "hash";
}

canonical_decompiled_code:
const char *__fastcall func4(__int64 a1, int a2)
{
if ( a2 == 1 )
return *(const char **)(a1 + 208);
if ( a2 == 2 )
return *(const char **)(a1 + 288);
return "hash";
}

original_code:
char* smb_hashsource(smbmsg_t* msg, int source)
{
 switch(source) {
  case SMB_HASH_SOURCE_MSG_ID:
   return(msg->id);
  case SMB_HASH_SOURCE_FTN_ID:
   return(msg->ftn_msgid);
 }
 return("hash");
}

canonical_original_code:
char *smb_hashsource(struct smbmsg_t *msg, int source)
{
 switch(source) {
  case SMB_HASH_SOURCE_MSG_ID:
   return(msg->id);
  case SMB_HASH_SOURCE_FTN_ID:
   return(msg->ftn_msgid);
 }
 return("hash");
}

variable_types: struct smbmsg_t { struct idxrec_t { unsigned short to; unsigned short from; unsigned short subj; unsigned short attr; unsigned long offset; unsigned long number; unsigned long time; } idx; struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t { unsigned long time; short zone; } when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; } hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t { unsigned short type; void *addr; } to_net; unsigned short total_hfields; struct hfield_t { unsigned short type; unsigned short length; } *hfield; void **hfield_dat; struct dfield_t { unsigned short type; unsigned long offset; unsigned long length; } *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; } *

variable_types: source int

user_defined_types: struct smbmsg_t { struct idxrec_t idx; struct msghdr_t hdr; char *to; char *summary; char *subj; unsigned short to_agent; struct net_t to_net; unsigned short total_hfields; struct hfield_t *hfield; void **hfield_dat; struct dfield_t *dfield; long offset; int forwarded; unsigned long expiration; unsigned long priority; unsigned long cost; unsigned long flags; }

user_defined_types: struct msghdr_t { unsigned char id[4]; unsigned short type; unsigned short version; unsigned short length; unsigned short attr; unsigned long auxattr; unsigned long netattr; struct when_t when_written; struct when_t when_imported; unsigned long number; unsigned long thread_back; unsigned long thread_next; unsigned long thread_first; unsigned short delivery_attempts; unsigned long times_downloaded; unsigned long last_downloaded; unsigned char reserved[6]; unsigned long offset; unsigned short total_dfields; }


decompiled_code:
char *__fastcall smb_zonestr(int a1, char *a2)
{
int v2; // edx
char *result; // rax
int v4; // eax
const char *v5; // r9
__int64 v6; // r8

if ( (_WORD)a1 == 8492 )
return "BOG";
LOWORD(v2) = a1;
if ( (unsigned __int16)a1 <= 0x212Cu )
{
if ( (_WORD)a1 == 4456 )
return "DHA";
if ( (unsigned __int16)a1 > 0x1168u )
{
if ( (_WORD)a1 == 4816 )
return "WEL";
if ( (unsigned __int16)a1 <= 0x12D0u )
{
if ( (_WORD)a1 == 4636 )
return "TOK";
if ( (unsigned __int16)a1 <= 0x121Cu )
{
result = "BAN";
if ( (_WORD)a1 == 4516 )
return result;
if ( (_WORD)a1 == 4576 )
return "HON";
}
else
{
result = "SYD";
if ( (_WORD)a1 == 4696 )
return result;
if ( (_WORD)a1 == 4756 )
return "NOU";
}
}
else
{
result = "RIO";
if ( (_WORD)a1 == 8372 )
return result;
if ( (unsigned __int16)a1 <= 0x20B4u )
{
result = "AZO";
if ( (_WORD)a1 == 8252 )
return result;
if ( (_WORD)a1 == 8312 )
return "FER";
}
else
{
result = "CAR";
if ( (_WORD)a1 == 8432 )
return result;
}
}
goto LABEL_21;
}
if ( (_WORD)a1 == 4336 )
return "DUB";
if ( (unsigned __int16)a1 > 0x10F0u )
{
result = "BOM";
if ( (_WORD)a1 == 4426 )
return result;
if ( (unsigned __int16)a1 <= 0x114Au )
{
result = "KAB";
if ( (_WORD)a1 == 4366 )
return result;
if ( (_WORD)a1 == 4396 )
return "KAR";
}
else
{
result = "KAT";
if ( (_WORD)a1 == 4441 )
return result;
}
goto LABEL_21;
}
if ( (_WORD)a1 == 4156 )
return "BER";
if ( (unsigned __int16)a1 > 0x103Cu )
{
result = "ATH";
if ( (_WORD)a1 == 4216 )
return result;
if ( (_WORD)a1 == 4276 )
return "MOS";
goto LABEL_21;
}
result = "UTC";
if ( !(_WORD)a1 )
return result;
if ( (_WORD)a1 == 4096 )
return "LON";
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
goto LABEL_92;
LABEL_44:
v5 = "+";
if ( (__int16)v2 > 0 )
goto LABEL_45;
goto LABEL_23;
}
if ( (_WORD)a1 == 16984 )
return "HST";
if ( (unsigned __int16)a1 <= 0x4258u )
{
if ( (_WORD)a1 == 16684 )
return "EST";
if ( (unsigned __int16)a1 <= 0x412Cu )
{
if ( (_WORD)a1 == 8672 )
return "VAN";
if ( (unsigned __int16)a1 <= 0x21E0u )
{
result = "WIN";
if ( (_WORD)a1 == 8552 )
return result;
if ( (_WORD)a1 == 8612 )
return "EDM";
}
else
{
result = "MID";
if ( (_WORD)a1 == 8852 )
return result;
if ( (_WORD)a1 == 16624 )
return "AST";
}
}
else
{
result = "PST";
if ( (_WORD)a1 == 16864 )
return result;
if ( (unsigned __int16)a1 <= 0x41E0u )
{
result = "CST";
if ( (_WORD)a1 == 16744 )
return result;
if ( (_WORD)a1 == 16804 )
return "MST";
}
else
{
result = "YST";
if ( (_WORD)a1 == 16924 )
return result;
}
}
}
else
{
if ( (_WORD)a1 == 0xC1A4 )
return "MDT";
if ( (unsigned __int16)a1 <= 0xC1A4u )
{
result = "EDT";
if ( (_WORD)a1 == 0xC12C )
return result;
if ( (unsigned __int16)a1 <= 0xC12Cu )
{
result = "BST";
if ( (_WORD)a1 == 17044 )
return result;
if ( (_WORD)a1 == 0xC0F0 )
return "ADT";
}
else
{
result = "CDT";
if ( (_WORD)a1 == 0xC168 )
return result;
}
}
else
{
result = "HDT";
if ( (_WORD)a1 == 0xC258 )
return result;
if ( (unsigned __int16)a1 > 0xC258u )
{
result = "BDT";
if ( (_WORD)a1 == 0xC294 )
return result;
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
goto LABEL_22;
goto LABEL_44;
}
result = "PDT";
if ( (_WORD)a1 == 0xC1E0 )
return result;
if ( (_WORD)a1 == 0xC21C )
return "YDT";
}
}
LABEL_21:
if ( (a1 & 0x6000) == 0 )
{
LABEL_92:
LOWORD(v2) = a1 & 0xFFF;
goto LABEL_44;
}
LABEL_22:
LOWORD(a1) = a1 & 0xFFF;
v2 = -a1;
LABEL_23:
if ( (_WORD)v2 )
{
v4 = (__int16)v2;
v5 = (const char *)&unk_D08;
v6 = -(__int16)v2 % 0x3Cu;
goto LABEL_46;
}
v5 = (const char *)&unk_D08;
LABEL_45:
v4 = (__int16)v2;
v6 = (unsigned __int16)v2 % 0x3Cu;
LABEL_46:
sprintf(
str_1,
"UTC%s%d:%02u",
v5,
(unsigned int)(__int16)(((__int16)(v2 + ((unsigned int)(-30583 * v4) >> 16)) >> 5) - ((__int16)v2 >> 15)),
v6);
result = str_1;
if ( a2 )
result = strcpy(a2, str_1);
return result;
}

canonical_decompiled_code:
char *__fastcall func5(int a1, char *a2)
{
int v2; // edx
char *result; // rax
int v4; // eax
const char *v5; // r9
__int64 v6; // r8

if ( (_WORD)a1 == 8492 )
return "BOG";
LOWORD(v2) = a1;
if ( (unsigned __int16)a1 <= 0x212Cu )
{
if ( (_WORD)a1 == 4456 )
return "DHA";
if ( (unsigned __int16)a1 > 0x1168u )
{
if ( (_WORD)a1 == 4816 )
return "WEL";
if ( (unsigned __int16)a1 <= 0x12D0u )
{
if ( (_WORD)a1 == 4636 )
return "TOK";
if ( (unsigned __int16)a1 <= 0x121Cu )
{
result = "BAN";
if ( (_WORD)a1 == 4516 )
return result;
if ( (_WORD)a1 == 4576 )
return "HON";
}
else
{
result = "SYD";
if ( (_WORD)a1 == 4696 )
return result;
if ( (_WORD)a1 == 4756 )
return "NOU";
}
}
else
{
result = "RIO";
if ( (_WORD)a1 == 8372 )
return result;
if ( (unsigned __int16)a1 <= 0x20B4u )
{
result = "AZO";
if ( (_WORD)a1 == 8252 )
return result;
if ( (_WORD)a1 == 8312 )
return "FER";
}
else
{
result = "CAR";
if ( (_WORD)a1 == 8432 )
return result;
}
}
goto LABEL_21;
}
if ( (_WORD)a1 == 4336 )
return "DUB";
if ( (unsigned __int16)a1 > 0x10F0u )
{
result = "BOM";
if ( (_WORD)a1 == 4426 )
return result;
if ( (unsigned __int16)a1 <= 0x114Au )
{
result = "KAB";
if ( (_WORD)a1 == 4366 )
return result;
if ( (_WORD)a1 == 4396 )
return "KAR";
}
else
{
result = "KAT";
if ( (_WORD)a1 == 4441 )
return result;
}
goto LABEL_21;
}
if ( (_WORD)a1 == 4156 )
return "BER";
if ( (unsigned __int16)a1 > 0x103Cu )
{
result = "ATH";
if ( (_WORD)a1 == 4216 )
return result;
if ( (_WORD)a1 == 4276 )
return "MOS";
goto LABEL_21;
}
result = "UTC";
if ( !(_WORD)a1 )
return result;
if ( (_WORD)a1 == 4096 )
return "LON";
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
goto LABEL_92;
LABEL_44:
v5 = "+";
if ( (__int16)v2 > 0 )
goto LABEL_45;
goto LABEL_23;
}
if ( (_WORD)a1 == 16984 )
return "HST";
if ( (unsigned __int16)a1 <= 0x4258u )
{
if ( (_WORD)a1 == 16684 )
return "EST";
if ( (unsigned __int16)a1 <= 0x412Cu )
{
if ( (_WORD)a1 == 8672 )
return "VAN";
if ( (unsigned __int16)a1 <= 0x21E0u )
{
result = "WIN";
if ( (_WORD)a1 == 8552 )
return result;
if ( (_WORD)a1 == 8612 )
return "EDM";
}
else
{
result = "MID";
if ( (_WORD)a1 == 8852 )
return result;
if ( (_WORD)a1 == 16624 )
return "AST";
}
}
else
{
result = "PST";
if ( (_WORD)a1 == 16864 )
return result;
if ( (unsigned __int16)a1 <= 0x41E0u )
{
result = "CST";
if ( (_WORD)a1 == 16744 )
return result;
if ( (_WORD)a1 == 16804 )
return "MST";
}
else
{
result = "YST";
if ( (_WORD)a1 == 16924 )
return result;
}
}
}
else
{
if ( (_WORD)a1 == 0xC1A4 )
return "MDT";
if ( (unsigned __int16)a1 <= 0xC1A4u )
{
result = "EDT";
if ( (_WORD)a1 == 0xC12C )
return result;
if ( (unsigned __int16)a1 <= 0xC12Cu )
{
result = "BST";
if ( (_WORD)a1 == 17044 )
return result;
if ( (_WORD)a1 == 0xC0F0 )
return "ADT";
}
else
{
result = "CDT";
if ( (_WORD)a1 == 0xC168 )
return result;
}
}
else
{
result = "HDT";
if ( (_WORD)a1 == 0xC258 )
return result;
if ( (unsigned __int16)a1 > 0xC258u )
{
result = "BDT";
if ( (_WORD)a1 == 0xC294 )
return result;
if ( (unsigned __int16)(a1 + 1000) > 0x7D0u )
goto LABEL_22;
goto LABEL_44;
}
result = "PDT";
if ( (_WORD)a1 == 0xC1E0 )
return result;
if ( (_WORD)a1 == 0xC21C )
return "YDT";
}
}
LABEL_21:
if ( (a1 & 0x6000) == 0 )
{
LABEL_92:
LOWORD(v2) = a1 & 0xFFF;
goto LABEL_44;
}
LABEL_22:
LOWORD(a1) = a1 & 0xFFF;
v2 = -a1;
LABEL_23:
if ( (_WORD)v2 )
{
v4 = (__int16)v2;
v5 = (const char *)&unk_D08;
v6 = -(__int16)v2 % 0x3Cu;
goto LABEL_46;
}
v5 = (const char *)&unk_D08;
LABEL_45:
v4 = (__int16)v2;
v6 = (unsigned __int16)v2 % 0x3Cu;
LABEL_46:
sprintf(
str_1,
"UTC%s%d:%02u",
v5,
(unsigned int)(__int16)(((__int16)(v2 + ((unsigned int)(-30583 * v4) >> 16)) >> 5) - ((__int16)v2 >> 15)),
v6);
result = str_1;
if ( a2 )
result = strcpy(a2, str_1);
return result;
}

original_code:
char* smb_zonestr(short zone, char* outstr)
{
 char* plus;
    static char str[32];
 switch((ushort)zone) {
  case 0: return("UTC");
  case 0x40F0: return("AST");
  case 0x412C: return("EST");
  case 0x4168: return("CST");
  case 0x41A4: return("MST");
  case 0x41E0: return("PST");
  case 0x421C: return("YST");
  case 0x4258: return("HST");
  case 0x4294: return("BST");
  case 0xC0F0: return("ADT");
  case 0xC12C: return("EDT");
  case 0xC168: return("CDT");
  case 0xC1A4: return("MDT");
  case 0xC1E0: return("PDT");
  case 0xC21C: return("YDT");
  case 0xC258: return("HDT");
  case 0xC294: return("BDT");
  case 0x2294: return("MID");
  case 0x21E0: return("VAN");
  case 0x21A4: return("EDM");
  case 0x2168: return("WIN");
  case 0x212C: return("BOG");
  case 0x20F0: return("CAR");
  case 0x20B4: return("RIO");
  case 0x2078: return("FER");
  case 0x203C: return("AZO");
  case 0x1000: return("LON");
  case 0x103C: return("BER");
  case 0x1078: return("ATH");
  case 0x10B4: return("MOS");
  case 0x10F0: return("DUB");
  case 0x110E: return("KAB");
  case 0x112C: return("KAR");
  case 0x114A: return("BOM");
  case 0x1159: return("KAT");
  case 0x1168: return("DHA");
  case 0x11A4: return("BAN");
  case 0x11E0: return("HON");
  case 0x121C: return("TOK");
  case 0x1258: return("SYD");
  case 0x1294: return("NOU");
  case 0x12D0: return("WEL");
  }
 if(!(zone<=1000 && zone>=-1000)) {
  if(zone&(0x2000|0x4000))
   zone=-(zone&0xfff);
  else
   zone&=0xfff;
 }
 if(zone>0)
  plus="+";
 else
  plus="";
 sprintf(str,"UTC%s%d:%02u", plus, zone/60, zone<0 ? (-zone)%60 : zone%60);
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

canonical_original_code:
char *smb_zonestr(short zone, char *outstr)
{
 char *plus;
    static char str[32];
 switch((unsigned short)zone) {
  case 0: return("UTC");
  case 0x40F0: return("AST");
  case 0x412C: return("EST");
  case 0x4168: return("CST");
  case 0x41A4: return("MST");
  case 0x41E0: return("PST");
  case 0x421C: return("YST");
  case 0x4258: return("HST");
  case 0x4294: return("BST");
  case 0xC0F0: return("ADT");
  case 0xC12C: return("EDT");
  case 0xC168: return("CDT");
  case 0xC1A4: return("MDT");
  case 0xC1E0: return("PDT");
  case 0xC21C: return("YDT");
  case 0xC258: return("HDT");
  case 0xC294: return("BDT");
  case 0x2294: return("MID");
  case 0x21E0: return("VAN");
  case 0x21A4: return("EDM");
  case 0x2168: return("WIN");
  case 0x212C: return("BOG");
  case 0x20F0: return("CAR");
  case 0x20B4: return("RIO");
  case 0x2078: return("FER");
  case 0x203C: return("AZO");
  case 0x1000: return("LON");
  case 0x103C: return("BER");
  case 0x1078: return("ATH");
  case 0x10B4: return("MOS");
  case 0x10F0: return("DUB");
  case 0x110E: return("KAB");
  case 0x112C: return("KAR");
  case 0x114A: return("BOM");
  case 0x1159: return("KAT");
  case 0x1168: return("DHA");
  case 0x11A4: return("BAN");
  case 0x11E0: return("HON");
  case 0x121C: return("TOK");
  case 0x1258: return("SYD");
  case 0x1294: return("NOU");
  case 0x12D0: return("WEL");
  }
 if(!(zone<=1000 && zone>=-1000)) {
  if(zone&(0x2000|0x4000))
   zone=-(zone&0xfff);
  else
   zone&=0xfff;
 }
 if(zone>0)
  plus="+";
 else
  plus="";
 sprintf(str,"UTC%s%d:%02u", plus, zone/60, zone<0 ? (-zone)%60 : zone%60);
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

variable_types: zone short

variable_types:
outstr
char *

variable_types:
plus
char *

variable_types:
str
char [32]


decompiled_code:
char *__fastcall smb_faddrtoa(unsigned __int16 *a1, char *a2)
{
char *result; // rax
__int64 v3; // rdx
char v4[56]; // [rsp-38h] [rbp-38h] BYREF

result = "0:0/0";
if ( a1 )
{
sprintf(str_0, "%hu:%hu/%hu", *a1, a1[1], a1[2]);
v3 = a1[3];
if ( (_WORD)v3 )
{
sprintf(v4, ".%hu", v3);
strcat(str_0, v4);
result = str_0;
if ( !a2 )
return result;
}
else
{
result = str_0;
if ( !a2 )
return result;
}
result = strcpy(a2, str_0);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned __int16 *a1, char *a2)
{
char *result; // rax
__int64 v3; // rdx
char v4[56]; // [rsp-38h] [rbp-38h] BYREF

result = "0:0/0";
if ( a1 )
{
sprintf(str_0, "%hu:%hu/%hu", *a1, a1[1], a1[2]);
v3 = a1[3];
if ( (_WORD)v3 )
{
sprintf(v4, ".%hu", v3);
strcat(str_0, v4);
result = str_0;
if ( !a2 )
return result;
}
else
{
result = str_0;
if ( !a2 )
return result;
}
result = strcpy(a2, str_0);
}
return result;
}

original_code:
char* smb_faddrtoa(fidoaddr_t* addr, char* outstr)
{
 static char str[64];
    char point[25];
 if(addr==((void *)0))
  return("0:0/0");
 sprintf(str,"%hu:%hu/%hu",addr->zone,addr->net,addr->node);
 if(addr->point) {
  sprintf(point,".%hu",addr->point);
  strcat(str,point);
 }
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

canonical_original_code:
char *smb_faddrtoa(struct fidoaddr_t *addr, char *outstr)
{
 static char str[64];
    char point[25];
 if(addr==((void *)0))
  return("0:0/0");
 sprintf(str,"%hu:%hu/%hu",addr->zone,addr->net,addr->node);
 if(addr->point) {
  sprintf(point,".%hu",addr->point);
  strcat(str,point);
 }
 if(outstr==((void *)0))
  return(str);
 strcpy(outstr,str);
 return(outstr);
}

variable_types: struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; } *

variable_types:
str
char [64]

variable_types:
point
char [25]


original_code:
fidoaddr_t smb_atofaddr(const fidoaddr_t* sys_addr, const char *str)
{
 char *p;
 fidoaddr_t addr;
 fidoaddr_t tmp_addr={1,1,1,0};
 if(sys_addr==((void *)0))
  sys_addr=&tmp_addr;
 memset(&(addr),0,sizeof(addr));
 if((p=strchr(str,':'))!=((void *)0)) {
  addr.zone=atoi(str);
  addr.net=atoi(p+1);
 } else {
  addr.zone=sys_addr->zone;
  addr.net=atoi(str);
 }
 if(addr.zone==0)
  addr.zone=1;
 if((p=strchr(str,'/'))!=((void *)0))
  addr.node=atoi(p+1);
 else {
  if(addr.zone==sys_addr->zone)
   addr.net=sys_addr->net;
  addr.node=atoi(str);
 }
 if((p=strchr(str,'.'))!=((void *)0))
  addr.point=atoi(p+1);
 return(addr);
}

canonical_original_code:
struct fidoaddr_t smb_atofaddr(struct fidoaddr_t *sys_addr, char *str)
{
 char *p;
 struct fidoaddr_t addr;
 struct fidoaddr_t tmp_addr = {1,1,1,0};
 if(sys_addr==((void *)0))
  sys_addr=&tmp_addr;
 memset(&(addr),0,sizeof(addr));
 if((p=strchr(str,':'))!=((void *)0)) {
  addr.zone=atoi(str);
  addr.net=atoi(p+1);
 } else {
  addr.zone=sys_addr->zone;
  addr.net=atoi(str);
 }
 if(addr.zone==0)
  addr.zone=1;
 if((p=strchr(str,'/'))!=((void *)0))
  addr.node=atoi(p+1);
 else {
  if(addr.zone==sys_addr->zone)
   addr.net=sys_addr->net;
  addr.node=atoi(str);
 }
 if((p=strchr(str,'.'))!=((void *)0))
  addr.point=atoi(p+1);
 return(addr);
}

variable_types:
str
char *

variable_types:
p
char *

variable_types: struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; }


decompiled_code:
char *__fastcall smb_netaddr(__int64 a1)
{
char *result; // rax

result = *(char **)(a1 + 8);
if ( *(_WORD *)a1 == 2 )
result = smb_faddrtoa(*(unsigned __int16 **)(a1 + 8), 0LL);
return result;
}

canonical_decompiled_code:
char *__fastcall func8(__int64 a1)
{
char *result; // rax

result = *(char **)(a1 + 8);
if ( *(_WORD *)a1 == 2 )
result = func6(*(unsigned __int16 **)(a1 + 8), 0LL);
return result;
}

original_code:
char* smb_netaddr(net_t* net)
{
 if(net->type==NET_FIDO)
  return(smb_faddrtoa((fidoaddr_t*)net->addr,((void *)0)));
 return(net->addr);
}

canonical_original_code:
char *smb_netaddr(struct net_t *net)
{
 if(net->type==NET_FIDO)
  return(smb_faddrtoa((struct fidoaddr_t *)net->addr,((void *)0)));
 return(net->addr);
}

variable_types: struct net_t { unsigned short type; void *addr; } *

user_defined_types: struct fidoaddr_t { unsigned short zone; unsigned short net; unsigned short node; unsigned short point; }


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

v1 = strchr(a1, 64);
if ( !v1 )
return 0LL;
v2 = v1[1];
v3 = v1 + 1;
if ( !(_BYTE)v2 )
return 1LL;
v4 = *_ctype_b_loc();
while ( 1 )
{
v5 = v4[v2];
if ( (v5 & 0x2000) == 0 )
break;
v2 = *++v3;
if ( !(_BYTE)v2 )
return 1LL;
}
if ( (v5 & 0x400) != 0 && !strchr(v3, 46) )
return 4LL;
while ( 1 )
{
v7 = *v3;
if ( !*v3 )
return (v5 & 8) == 0 ? 1 : 5;
if ( (v4[v7] & 0x800) == 0 && v7 != 58 && (unsigned __int8)(v7 - 46) > 1u )
break;
++v3;
}
result = 2LL;
if ( (v5 & 0x800) == 0 )
return (v5 & 8) == 0 ? 1 : 5;
return result;
}

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

v1 = strchr(a1, 64);
if ( !v1 )
return 0LL;
v2 = v1[1];
v3 = v1 + 1;
if ( !(_BYTE)v2 )
return 1LL;
v4 = *_ctype_b_loc();
while ( 1 )
{
v5 = v4[v2];
if ( (v5 & 0x2000) == 0 )
break;
v2 = *++v3;
if ( !(_BYTE)v2 )
return 1LL;
}
if ( (v5 & 0x400) != 0 && !strchr(v3, 46) )
return 4LL;
while ( 1 )
{
v7 = *v3;
if ( !*v3 )
return (v5 & 8) == 0 ? 1 : 5;
if ( (v4[v7] & 0x800) == 0 && v7 != 58 && (unsigned __int8)(v7 - 46) > 1u )
break;
++v3;
}
result = 2LL;
if ( (v5 & 0x800) == 0 )
return (v5 & 8) == 0 ? 1 : 5;
return result;
}

original_code:
ushort smb_netaddr_type(const char* str)
{
 char* p;
 char* tp;
 if((p=strchr(str,'@'))==((void *)0))
  return(NET_NONE);
 p++;
 while(*(p) && ((*__ctype_b_loc ())[(int) ((*(p)))] & (unsigned short int) _ISspace)) (p)++;;
 if(*p==0)
  return(NET_UNKNOWN);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalpha) && strchr(p,'.')==((void *)0))
  return(NET_QWK);
 for(tp=p;*tp;tp++) {
  if(!((*__ctype_b_loc ())[(int) ((*tp))] & (unsigned short int) _ISdigit) && *tp!=':' && *tp!='/' && *tp!='.')
   break;
 }
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit) && *tp)
  return(NET_FIDO);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalnum))
  return(NET_INTERNET);
 return(NET_UNKNOWN);
}

canonical_original_code:
unsigned short smb_netaddr_type(char *str)
{
 char *p;
 char *tp;
 if((p=strchr(str,'@'))==((void *)0))
  return(NET_NONE);
 p++;
 while(*(p) && ((*__ctype_b_loc ())[(int) ((*(p)))] & (unsigned short) _ISspace)) (p)++;;
 if(*p==0)
  return(NET_UNKNOWN);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalpha) && strchr(p,'.')==((void *)0))
  return(NET_QWK);
 for(tp=p;*tp;tp++) {
  if(!((*__ctype_b_loc ())[(int) ((*tp))] & (unsigned short) _ISdigit) && *tp!=':' && *tp!='/' && *tp!='.')
   break;
 }
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit) && *tp)
  return(NET_FIDO);
 if(((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalnum))
  return(NET_INTERNET);
 return(NET_UNKNOWN);
}

variable_types:
tp
char *


decompiled_code:
int __fastcall xp_sem_init(pthread_cond_t **a1, int a2, int a3)
{
char *v4; // rax
int result; // eax
pthread_cond_t *v6; // rdx
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF

if ( a2 )
{
*_errno_location() = 1;
result = -1;
}
else
{
v4 = (char *)malloc(0x68uLL);
*a1 = (pthread_cond_t *)v4;
if ( v4 )
{
if ( !pthread_mutex_init((pthread_mutex_t *)(v4 + 8), 0LL) )
{
result = pthread_cond_init(*a1 + 1, 0LL);
if ( !result )
{
v6 = *a1;
v6[2].__lock = a3;
v6[2].__futex = 0;
v6->__lock = 167395346;
return result;
}
while ( pthread_mutex_destroy((pthread_mutex_t *)(&(*a1)->__align + 1)) == 16 )
{
v7.tv_sec = 0LL;
v7.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v7);
}
}
free(*a1);
}
*_errno_location() = 28;
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(pthread_cond_t **a1, int a2, int a3)
{
char *v4; // rax
int result; // eax
pthread_cond_t *v6; // rdx
struct timeval v7; // [rsp+0h] [rbp-28h] BYREF

if ( a2 )
{
*_errno_location() = 1;
result = -1;
}
else
{
v4 = (char *)malloc(0x68uLL);
*a1 = (pthread_cond_t *)v4;
if ( v4 )
{
if ( !pthread_mutex_init((pthread_mutex_t *)(v4 + 8), 0LL) )
{
result = pthread_cond_init(*a1 + 1, 0LL);
if ( !result )
{
v6 = *a1;
v6[2].__lock = a3;
v6[2].__futex = 0;
v6->__lock = 167395346;
return result;
}
while ( pthread_mutex_destroy((pthread_mutex_t *)(&(*a1)->__align + 1)) == 16 )
{
v7.tv_sec = 0LL;
v7.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v7);
}
}
free(*a1);
}
*_errno_location() = 28;
result = -1;
}
return result;
}

original_code:
int
xp_sem_init(xp_sem_t *sem, int pshared, unsigned int value)
{
 int retval;
 if (pshared != 0) {
  (*__errno_location ()) = 1;
  retval = -1;
  goto RETURN;
 }
 if (value > (0x7fffffff * 2U + 1U)) {
  (*__errno_location ()) = 22;
  retval = -1;
  goto RETURN;
 }
 *sem = (xp_sem_t)malloc(sizeof(struct xp_sem));
 if (*sem == ((void *)0)) {
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_mutex_init(&(*sem)->lock, ((void *)0)) != 0) {
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_cond_init(&(*sem)->gtzero, ((void *)0)) != 0) {
  while(pthread_mutex_destroy(&(*sem)->lock)==16)
   ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 (*sem)->count = (u_int32_t)value;
 (*sem)->nwaiters = 0;
 (*sem)->magic = ((u_int32_t) 0x09fa4012);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_init(struct xp_sem **sem, int pshared, unsigned int value)
{
 int retval;
 if (pshared != 0) {
  (*__errno_location ()) = 1;
  retval = -1;
  goto RETURN;
 }
 if (value > (0x7fffffff * 2U + 1U)) {
  (*__errno_location ()) = 22;
  retval = -1;
  goto RETURN;
 }
 *sem = (struct xp_sem *)malloc(sizeof(struct xp_sem));
 if (*sem == ((void *)0)) {
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_mutex_init(&(*sem)->lock, ((void *)0)) != 0) {
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 if (pthread_cond_init(&(*sem)->gtzero, ((void *)0)) != 0) {
  while(pthread_mutex_destroy(&(*sem)->lock)==16)
   ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
  free(*sem);
  (*__errno_location ()) = 28;
  retval = -1;
  goto RETURN;
 }
 (*sem)->count = (unsigned int)value;
 (*sem)->nwaiters = 0;
 (*sem)->magic = ((unsigned int) 0x09fa4012);
 retval = 0;
  RETURN:
 return retval;
}

variable_types: struct xp_sem { unsigned int magic; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } **

variable_types: pshared int

variable_types:
value
unsigned int

variable_types: retval int

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

user_defined_types: struct xp_sem { unsigned int magic; union pthread_mutex_t lock; union pthread_cond_t gtzero; unsigned int count; unsigned int nwaiters; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall xp_sem_destroy(void **a1)
{
char *v2; // rdi
char *v3; // rdi
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( a1 && (v2 = (char *)*a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = (char *)*a1;
if ( *((_DWORD *)*a1 + 25) )
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
*_errno_location() = 16;
result = 0xFFFFFFFFLL;
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
while ( pthread_mutex_destroy((pthread_mutex_t *)((char *)*a1 + 8)) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
while ( pthread_cond_destroy((pthread_cond_t *)*a1 + 1) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
free(*a1);
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1)
{
char *v2; // rdi
char *v3; // rdi
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( a1 && (v2 = (char *)*a1, *(_DWORD *)v2 == 167395346) )
{
pthread_mutex_lock((pthread_mutex_t *)(v2 + 8));
v3 = (char *)*a1;
if ( *((_DWORD *)*a1 + 25) )
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
*_errno_location() = 16;
result = 0xFFFFFFFFLL;
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(v3 + 8));
while ( pthread_mutex_destroy((pthread_mutex_t *)((char *)*a1 + 8)) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
while ( pthread_cond_destroy((pthread_cond_t *)*a1 + 1) == 16 )
{
v5.tv_sec = 0LL;
v5.tv_usec = 1000LL;
select(0, 0LL, 0LL, 0LL, &v5);
}
free(*a1);
result = 0LL;
}
}
else
{
*_errno_location() = 22;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
xp_sem_destroy(xp_sem_t *sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((u_int32_t) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->nwaiters > 0) {
  pthread_mutex_unlock(&(*sem)->lock);
  (*__errno_location ()) = 16;
  retval = -1;
  goto RETURN;
 }
 pthread_mutex_unlock(&(*sem)->lock);
 while(pthread_mutex_destroy(&(*sem)->lock)==16)
  ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 while(pthread_cond_destroy(&(*sem)->gtzero)==16)
  ({ int sleep_msecs=1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 (*sem)->magic = 0;
 free(*sem);
 retval = 0;
  RETURN:
 return retval;
}

canonical_original_code:
int xp_sem_destroy(struct xp_sem **sem)
{
 int retval;
 if (sem==((void *)0) || (*(sem))->magic != ((unsigned int) 0x09fa4012)) { (*__errno_location ()) = 22; retval = -1; goto RETURN; };
 pthread_mutex_lock(&(*sem)->lock);
 if ((*sem)->nwaiters > 0) {
  pthread_mutex_unlock(&(*sem)->lock);
  (*__errno_location ()) = 16;
  retval = -1;
  goto RETURN;
 }
 pthread_mutex_unlock(&(*sem)->lock);
 while(pthread_mutex_destroy(&(*sem)->lock)==16)
  ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 while(pthread_cond_destroy(&(*sem)->gtzero)==16)
  ({ int sleep_msecs = 1; struct timeval tv; tv.tv_sec=(sleep_msecs/1000); tv.tv_usec=((sleep_msecs%1000)*1000); select(0,((void *)0),((void *)0),((void *)0),&tv); });
 (*sem)->magic = 0;
 free(*sem);
 retval = 0;
  RETURN:
 return retval;
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 xp_sem_open()
{
*_errno_location() = 38;
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
*_errno_location() = 38;
return 0LL;
}

original_code:
xp_sem_t *
xp_sem_open(const char *name, int oflag, ...)
{
 (*__errno_location ()) = 38;
 return ((xp_sem_t *)0);
}

canonical_original_code:
struct xp_sem **xp_sem_open(char *name, int oflag, ...)
{
 (*__errno_location ()) = 38;
 return ((struct xp_sem **)0);
}

variable_types:
name
char *

variable_types: oflag int

return_type: struct xp_sem { unsigned int magic; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } gtzero; unsigned int count; unsigned int nwaiters; } **


decompiled_code:
__int64 xp_sem_close()
{
*_errno_location() = 38;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func3()
{
*_errno_location() = 38;
return 0xFFFFFFFFLL;
}

original_code:
int
xp_sem_close(xp_sem_t *sem)
{
 (*__errno_location ()) = 38;
 return -1;
}

canonical_original_code:
int xp_sem_close(struct xp_sem **sem)
{
 (*__errno_location ()) = 38;
 return -1;
}


decompiled_code:
// attributes: thunk
__int64 xp_sem_unlink()
{
return xp_sem_close();
}

canonical_decompiled_code:
__int64 func4()
{
return func3();
}

original_code:
int
xp_sem_unlink(const char *name)
{
 (*__errno_location ()) = 38;
 return -1;
}

canonical_original_code:
int xp_sem_unlink(char *name)
{
 (*__errno_location ()) = 38;
 return -1;
}