decompiled_code:
__int64 __fastcall bwlc_netlink_init(struct sockaddr **a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
struct sockaddr *v4; // rbp
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax
int *v10; // rbx
char *v11; // rax
int *v12; // rbx
char *v13; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 4096;
v2 = socket(16, 2, a2);
v3 = v2;
if ( v2 == -1 )
{
v6 = __errno_location();
v7 = strerror(*v6);
printf("BWLC_NETLINK:Create socket fail. %d(%s)\n", (unsigned int)*v6, v7);
LABEL_7:
close(v3);
return 0xFFFFFFFFLL;
}
if ( setsockopt(v2, 1, 8, optval, 4u) < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n", (unsigned int)*v8, v9);
}
else
{
v4 = (struct sockaddr *)calloc(1uLL, 0xCuLL);
if ( v4 )
{
v4->sa_family = 16;
*(_DWORD *)&v4->sa_data[2] = getpid();
*(_DWORD *)&v4->sa_data[6] = 1;
if ( !bind(v3, v4, 0xCu) )
{
*a1 = v4;
return v3;
}
v10 = __errno_location();
v11 = strerror(*v10);
printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n", (unsigned int)*v10, v11);
free(v4);
}
else
{
v12 = __errno_location();
v13 = strerror(*v12);
printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n", (unsigned int)*v12, v13);
}
}
if ( v3 )
goto LABEL_7;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(struct sockaddr **a1, int a2)
{
int v2; // eax
unsigned int v3; // er12
struct sockaddr *v4; // rbp
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax
int *v10; // rbx
char *v11; // rax
int *v12; // rbx
char *v13; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 4096;
v2 = socket(16, 2, a2);
v3 = v2;
if ( v2 == -1 )
{
v6 = __errno_location();
v7 = strerror(*v6);
printf("BWLC_NETLINK:Create socket fail. %d(%s)\n", (unsigned int)*v6, v7);
LABEL_7:
close(v3);
return 0xFFFFFFFFLL;
}
if ( setsockopt(v2, 1, 8, optval, 4u) < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n", (unsigned int)*v8, v9);
}
else
{
v4 = (struct sockaddr *)calloc(1uLL, 0xCuLL);
if ( v4 )
{
v4->sa_family = 16;
*(_DWORD *)&v4->sa_data[2] = getpid();
*(_DWORD *)&v4->sa_data[6] = 1;
if ( !bind(v3, v4, 0xCu) )
{
*a1 = v4;
return v3;
}
v10 = __errno_location();
v11 = strerror(*v10);
printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n", (unsigned int)*v10, v11);
free(v4);
}
else
{
v12 = __errno_location();
v13 = strerror(*v12);
printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n", (unsigned int)*v12, v13);
}
}
if ( v3 )
goto LABEL_7;
return 0xFFFFFFFFLL;
}

original_code:
int bwlc_netlink_init(struct sockaddr_nl **nl_saddr, int nl)
{
 int sock = -1, ret;
 int rcvbufsz = 4096;
 struct sockaddr_nl *saddr = ((void *)0);
 sock = socket(16, SOCK_DGRAM, nl);
 if (sock == -1) {
  printf("BWLC_NETLINK:Create socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 ret = setsockopt(sock, 1, 8, &rcvbufsz,
       sizeof(rcvbufsz));
 if (ret < 0) {
  printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr = calloc(1, sizeof(struct sockaddr_nl));
 if (!saddr){
  printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr->nl_family = 16;
 saddr->nl_pid = getpid();
 if (nl == 0)
  saddr->nl_groups = RTNLGRP_LINK;
 else
  saddr->nl_groups = 0x1;
 ret = bind(sock, (struct sockaddr *)saddr, sizeof(struct sockaddr_nl));
 if (ret) {
  printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 *nl_saddr = saddr;
 return sock;
failed:
 if (saddr)
  free(saddr);
 if (sock)
  close(sock);
 return -1;
}

canonical_original_code:
int bwlc_netlink_init(struct sockaddr_nl **nl_saddr, int nl)
{
 int sock = -1; int ret;
 int rcvbufsz = 4096;
 struct sockaddr_nl *saddr = ((void *)0);
 sock = socket(16, SOCK_DGRAM, nl);
 if (sock == -1) {
  printf("BWLC_NETLINK:Create socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 ret = setsockopt(sock, 1, 8, &rcvbufsz,
       sizeof(rcvbufsz));
 if (ret < 0) {
  printf("BWLC_NETLINK:Set socket opt fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr = calloc(1, sizeof(struct sockaddr_nl));
 if (!saddr){
  printf("BWLC_NETLINK:Alloc mem for sockaddr fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 saddr->nl_family = 16;
 saddr->nl_pid = getpid();
 if (nl == 0)
  saddr->nl_groups = RTNLGRP_LINK;
 else
  saddr->nl_groups = 0x1;
 ret = bind(sock, (struct sockaddr *)saddr, sizeof(struct sockaddr_nl));
 if (ret) {
  printf("BWLC_NETLINK:Bind socket fail. %d(%s)\n",
     (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 *nl_saddr = saddr;
 return sock;
failed:
 if (saddr)
  free(saddr);
 if (sock)
  close(sock);
 return -1;
}

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } **

variable_types: nl int

variable_types: sock int

variable_types: rcvbufsz int

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


decompiled_code:
__int64 __fastcall bwlc_netlink_recv(int a1, void *a2, size_t a3)
{
ssize_t v3; // rax
__int64 result; // rax
int *v5; // rbx
char *v6; // rax

v3 = recv(a1, a2, a3, 0);
if ( v3 )
{
if ( v3 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("BWLC_NETLINK:Recv error. %d(%s)\n", (unsigned int)*v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
puts("BWLC_NETLINK:Peer shutdown while recv.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, void *a2, size_t a3)
{
ssize_t v3; // rax
__int64 result; // rax
int *v5; // rbx
char *v6; // rax

v3 = recv(a1, a2, a3, 0);
if ( v3 )
{
if ( v3 < 0 )
{
v5 = __errno_location();
v6 = strerror(*v5);
printf("BWLC_NETLINK:Recv error. %d(%s)\n", (unsigned int)*v5, v6);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
}
else
{
puts("BWLC_NETLINK:Peer shutdown while recv.");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int bwlc_netlink_recv(int sock, char *buf, size_t len)
{
 ssize_t ret;
 ret = recv(sock, buf, len, 0);
 if (ret == 0) {
  printf("BWLC_NETLINK:Peer shutdown while recv.\n");
  goto failed;
 } else if (ret < 0) {
  printf("BWLC_NETLINK:Recv error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 return 0;
failed:
 return -1;
}

canonical_original_code:
int bwlc_netlink_recv(int sock, char *buf, unsigned long len)
{
 long ret;
 ret = recv(sock, buf, len, 0);
 if (ret == 0) {
  printf("BWLC_NETLINK:Peer shutdown while recv.\n");
  goto failed;
 } else if (ret < 0) {
  printf("BWLC_NETLINK:Recv error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 return 0;
failed:
 return -1;
}

variable_types:
buf
char *

variable_types:
len
unsigned long

variable_types: ret long

return_type: int


decompiled_code:
__int64 __fastcall bwlc_uevent_handler(int a1, const char *a2)
{
const char *v2; // rbp
size_t v3; // rax
unsigned int v4; // er13
_DWORD *v5; // rax
_DWORD *v6; // rbp
size_t v7; // rax
char *v8; // rax

v2 = (&bwlc_scan_keyword)[g_scan_set];
v3 = strlen(v2);
if ( !strncmp(a2, v2, v3) )
{
v4 = 0;
v5 = calloc(1uLL, 0x10uLL);
v6 = v5;
if ( v5 )
{
*v5 = a1;
v7 = strlen(a2);
v8 = (char *)calloc(1uLL, v7 + 10);
*((_QWORD *)v6 + 1) = v8;
if ( v8 )
{
sprintf(v8, "/dev/%s", a2);
bwlc_handle_dev_msg((const char **)v6);
}
else
{
v4 = -1;
puts("BWLC_UEVENT:Can not alloc mem for dev_path.");
free(v6);
}
}
else
{
v4 = -1;
puts("BWLC_UEVENT:Can not alloc mem for event msg.");
}
}
else
{
v4 = -1;
printf("BWLC_UEVENT: %s is not in scan set.\n", a2);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, const char *a2)
{
const char *v2; // rbp
size_t v3; // rax
unsigned int v4; // er13
_DWORD *v5; // rax
_DWORD *v6; // rbp
size_t v7; // rax
char *v8; // rax

v2 = (&bwlc_scan_keyword)[g_scan_set];
v3 = strlen(v2);
if ( !strncmp(a2, v2, v3) )
{
v4 = 0;
v5 = calloc(1uLL, 0x10uLL);
v6 = v5;
if ( v5 )
{
*v5 = a1;
v7 = strlen(a2);
v8 = (char *)calloc(1uLL, v7 + 10);
*((_QWORD *)v6 + 1) = v8;
if ( v8 )
{
sprintf(v8, "/dev/%s", a2);
func7((const char **)v6);
}
else
{
v4 = -1;
puts("BWLC_UEVENT:Can not alloc mem for dev_path.");
free(v6);
}
}
else
{
v4 = -1;
puts("BWLC_UEVENT:Can not alloc mem for event msg.");
}
}
else
{
v4 = -1;
printf("BWLC_UEVENT: %s is not in scan set.\n", a2);
}
return v4;
}

original_code:
int32_t bwlc_uevent_handler(bwlc_devent_type_t event_type, char *dev_name)
{
 int32_t ret = 0;
 bwlc_devent_msg_t *devent = ((void *)0);
 if (strncmp(dev_name, bwlc_scan_keyword[g_scan_set],
   strlen(bwlc_scan_keyword[g_scan_set])) != 0) {
  printf("BWLC_UEVENT: %s is not in scan set.\n", dev_name);
  goto failed;
 }
 devent = calloc(1, sizeof(bwlc_devent_msg_t));
 if (!devent) {
  printf("BWLC_UEVENT:Can not alloc mem for event msg.\n");
  goto failed;
 }
 devent->event_type = event_type;
 devent->dev_path = calloc(1, strlen(dev_name)+10);
 if (!devent->dev_path) {
  printf("BWLC_UEVENT:Can not alloc mem for dev_path.\n");
  goto failed;
 }
 sprintf(devent->dev_path, "/dev/%s", dev_name);
 bwlc_handle_dev_msg(devent);
 return ret;
failed:
 if (devent)
  free(devent);
 return -1;
}

canonical_original_code:
int bwlc_uevent_handler(enum _bwlc_devent_type event_type, char *dev_name)
{
 int ret = 0;
 struct _bwlc_devent_msg *devent = ((void *)0);
 if (strncmp(dev_name, bwlc_scan_keyword[g_scan_set],
   strlen(bwlc_scan_keyword[g_scan_set])) != 0) {
  printf("BWLC_UEVENT: %s is not in scan set.\n", dev_name);
  goto failed;
 }
 devent = calloc(1, sizeof(bwlc_devent_msg_t));
 if (!devent) {
  printf("BWLC_UEVENT:Can not alloc mem for event msg.\n");
  goto failed;
 }
 devent->event_type = event_type;
 devent->dev_path = calloc(1, strlen(dev_name)+10);
 if (!devent->dev_path) {
  printf("BWLC_UEVENT:Can not alloc mem for dev_path.\n");
  goto failed;
 }
 sprintf(devent->dev_path, "/dev/%s", dev_name);
 bwlc_handle_dev_msg(devent);
 return ret;
failed:
 if (devent)
  free(devent);
 return -1;
}

variable_types: ret int

variable_types: struct _bwlc_devent_msg { enum _bwlc_devent_type { BWLC_DEV_ARRIVE=1, BWLC_DEV_REMOVE=2 } event_type; char *dev_path; } *

user_defined_types: struct _bwlc_devent_msg { enum _bwlc_devent_type event_type; char *dev_path; }


decompiled_code:
void __fastcall __noreturn bwlc_uevent_reciever(void *a1)
{
int v1; // ebx
void *v2; // rbp
int v3; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr *v4; // [rsp+10h] [rbp-28h] BYREF
char *v5; // [rsp+18h] [rbp-20h] BYREF

v1 = -1;
v2 = calloc(1uLL, 0x1000uLL);
while ( 1 )
{
if ( v1 == -1 )
{
LABEL_7:
while ( 1 )
{
puts("BWLC_UEVENT:Init netlink.");
v1 = bwlc_netlink_init(&v4, 15);
if ( v1 != -1 )
break;
puts("BWLC_UEVENT:Init netlink failed, sleep & retry.");
sleep(1u);
}
}
while ( 1 )
{
memset(v2, 0, 0x1000uLL);
if ( (int)bwlc_netlink_recv(v1, v2, 0x1000uLL) < 0 )
{
puts("BWLC_UEVENT:Recv error reinitial usock.");
goto LABEL_7;
}
if ( !(unsigned int)_bwlc_uevent_parse((char *)v2, &v5, &v3) )
break;
printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", (const char *)v2);
bwlc_uevent_handler(v3, v5);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func12(void *a1)
{
int v1; // ebx
void *v2; // rbp
int v3; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr *v4; // [rsp+10h] [rbp-28h] BYREF
char *v5; // [rsp+18h] [rbp-20h] BYREF

v1 = -1;
v2 = calloc(1uLL, 0x1000uLL);
while ( 1 )
{
if ( v1 == -1 )
{
LABEL_7:
while ( 1 )
{
puts("BWLC_UEVENT:Init netlink.");
v1 = func8(&v4, 15);
if ( v1 != -1 )
break;
puts("BWLC_UEVENT:Init netlink failed, sleep & retry.");
sleep(1u);
}
}
while ( 1 )
{
memset(v2, 0, 0x1000uLL);
if ( (int)func9(v1, v2, 0x1000uLL) < 0 )
{
puts("BWLC_UEVENT:Recv error reinitial usock.");
goto LABEL_7;
}
if ( !(unsigned int)func10((char *)v2, &v5, &v3) )
break;
printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", (const char *)v2);
func11(v3, v5);
}
}
}

original_code:
void *bwlc_uevent_reciever(void *unused)
{
 int usock = -1, ret;
 struct sockaddr_nl *nl_addr;
 bwlc_devent_type_t event_type;
 char *dev_name;
 char *uevent_buf = ((void *)0);
 uevent_buf = calloc(1, 4096);
 while (1) {
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink.\n");
   usock = bwlc_netlink_init(&nl_addr, 15);
  }
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink failed, sleep & retry.\n");
   sleep(1);
   continue;
  }
  memset(uevent_buf, 0, 4096);
  ret = bwlc_netlink_recv(usock, uevent_buf, 4096);
  if (ret < 0) {
   printf("BWLC_UEVENT:Recv error reinitial usock.\n");
   usock = -1;
   continue;
  }
  if (!__bwlc_uevent_parse(uevent_buf, &dev_name, &event_type))
   continue;
  printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", uevent_buf);
  bwlc_uevent_handler(event_type, dev_name);
 }
}

canonical_original_code:
void *bwlc_uevent_reciever(void *unused)
{
 int usock = -1; int ret;
 struct sockaddr_nl *nl_addr;
 enum _bwlc_devent_type event_type;
 char *dev_name;
 char *uevent_buf = ((void *)0);
 uevent_buf = calloc(1, 4096);
 while (1) {
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink.\n");
   usock = bwlc_netlink_init(&nl_addr, 15);
  }
  if (usock == -1) {
   printf("BWLC_UEVENT:Init netlink failed, sleep & retry.\n");
   sleep(1);
   continue;
  }
  memset(uevent_buf, 0, 4096);
  ret = bwlc_netlink_recv(usock, uevent_buf, 4096);
  if (ret < 0) {
   printf("BWLC_UEVENT:Recv error reinitial usock.\n");
   usock = -1;
   continue;
  }
  if (!__bwlc_uevent_parse(uevent_buf, &dev_name, &event_type))
   continue;
  printf("BWLC_UEVENT:DEBUG:uevent msg:%s\n", uevent_buf);
  bwlc_uevent_handler(event_type, dev_name);
 }
}

variable_types:
unused
void *

variable_types: usock int

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } *

variable_types: enum _bwlc_devent_type { BWLC_DEV_ARRIVE=1, BWLC_DEV_REMOVE=2 }

return_type: void *


decompiled_code:
__int64 __fastcall bwlc_uevent_init(unsigned int a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax
char *v4; // rax
__int64 v5; // rsi
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( a1 > 1 )
{
printf("BWLC_UEVENT:Unkown scan set %d\n", a1);
result = 0LL;
}
else
{
g_scan_set = a1;
v1 = pthread_create(newthread, 0LL, (void *(*)(void *))bwlc_uevent_reciever, 0LL);
v2 = v1;
if ( v1 )
{
v4 = strerror(v1);
v5 = v2;
v2 = -1;
printf("BWLC_UEVENT:Create thread error.%d(%s)\n", v5, v4);
}
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1)
{
int v1; // eax
unsigned int v2; // er12
__int64 result; // rax
char *v4; // rax
__int64 v5; // rsi
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

if ( a1 > 1 )
{
printf("BWLC_UEVENT:Unkown scan set %d\n", a1);
result = 0LL;
}
else
{
g_scan_set = a1;
v1 = pthread_create(newthread, 0LL, (void *(*)(void *))bwlc_uevent_reciever, 0LL);
v2 = v1;
if ( v1 )
{
v4 = strerror(v1);
v5 = v2;
v2 = -1;
printf("BWLC_UEVENT:Create thread error.%d(%s)\n", v5, v4);
}
result = v2;
}
return result;
}

original_code:
int32_t bwlc_uevent_init(bwlc_scan_set_t scan_set)
{
 pthread_t pd;
 int32_t bwret = 0;
 int ret;
 if (scan_set < 0 || scan_set >= BWLC_SCAN_MAX) {
  printf("BWLC_UEVENT:Unkown scan set %d\n", scan_set);
  goto failed;
 }
 g_scan_set = scan_set;
 ret = pthread_create(&pd, ((void *)0), bwlc_uevent_reciever, ((void *)0));
 if (ret) {
  printf("BWLC_UEVENT:Create thread error.%d(%s)\n",
    ret, strerror(ret));
  bwret = -1;
  goto failed;
 }
failed:
 return bwret;
}

canonical_original_code:
int bwlc_uevent_init(enum _bwlc_scan_set scan_set)
{
 unsigned long pd;
 int bwret = 0;
 int ret;
 if (scan_set < 0 || scan_set >= BWLC_SCAN_MAX) {
  printf("BWLC_UEVENT:Unkown scan set %d\n", scan_set);
  goto failed;
 }
 g_scan_set = scan_set;
 ret = pthread_create(&pd, ((void *)0), bwlc_uevent_reciever, ((void *)0));
 if (ret) {
  printf("BWLC_UEVENT:Create thread error.%d(%s)\n",
    ret, strerror(ret));
  bwret = -1;
  goto failed;
 }
failed:
 return bwret;
}

variable_types: enum _bwlc_scan_set { BWLC_SCAN_NORMAL=0, BWLC_SCAN_MULTIPATH=1, BWLC_SCAN_MAX=2 }

variable_types:
pd
unsigned long

variable_types: bwret int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( !(unsigned int)bwlc_uevent_init(0LL, argv, envp) )
{
while ( 1 )
sleep(1u);
}
puts("init bwlc_event failed.");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( !(unsigned int)func13(0LL, argv, envp) )
{
while ( 1 )
sleep(1u);
}
puts("init bwlc_event failed.");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int32_t ret;
 ret = bwlc_uevent_init(BWLC_SCAN_NORMAL);
 if (ret) {
  printf("init bwlc_event failed.\n");
  goto failed;
 }
 while (1)
  sleep(1);
failed:
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int ret;
 ret = bwlc_uevent_init(BWLC_SCAN_NORMAL);
 if (ret) {
  printf("init bwlc_event failed.\n");
  goto failed;
 }
 while (1)
  sleep(1);
failed:
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const void *v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = calloc(0xAuLL, 4uLL);
printf("p=%p address of p %p\n", v4[0], v4);
func(v4);
printf("p=%p address of p %p\n", v4[0], v4);
printf("i=%d\n", 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const void *v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = calloc(0xAuLL, 4uLL);
printf("p=%p address of p %p\n", v4[0], v4);
func8(v4);
printf("p=%p address of p %p\n", v4[0], v4);
printf("i=%d\n", 0LL);
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 int *p = ((void *)0);
 int i;
 p = calloc(10, sizeof(int));
 printf("p=%p address of p %p\n", p, &p);
 func(&p);
 printf("p=%p address of p %p\n", p, &p);
 for (i = 0; i != 1; i++)
  printf("i=%d\n", i);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int *p = ((void *)0);
 int i;
 p = calloc(10, sizeof(int));
 printf("p=%p address of p %p\n", p, &p);
 func(&p);
 printf("p=%p address of p %p\n", p, &p);
 for (i = 0; i != 1; i++)
  printf("i=%d\n", i);
 return 0;
}

variable_types:
p
int *

variable_types: i int


func

decompiled_code:
int __fastcall func(const void **a1)
{
return printf("p=%p\n", *a1);
}

canonical_decompiled_code:
int __fastcall func8(const void **a1)
{
return printf("p=%p\n", *a1);
}

original_code:
void func(int **pp)
{
 int *p = *pp;
 printf("p=%p\n", p);
 p++;
}

variable_types:
pp
int **

return_type: void


decompiled_code:
__int64 __fastcall getsockopt_sndbuf(int fd)
{
unsigned int *v1; // rax
unsigned int *v2; // rbp
int *v4; // rbp
char *v5; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)calloc(1uLL, 0x80uLL);
optlen[0] = 128;
if ( v1 )
{
v2 = v1;
if ( getsockopt(fd, 1, 7, v1, optlen) >= 0 )
{
printf("SNDBUF:%d\n", *v2);
free(v2);
return 0LL;
}
printf("can't get sockopt!");
}
else
{
printf("can't alloc sockopt buffer!");
}
v4 = __errno_location();
v5 = strerror(*v4);
printf(" errno:%d(%s)\n", (unsigned int)*v4, v5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd)
{
unsigned int *v1; // rax
unsigned int *v2; // rbp
int *v4; // rbp
char *v5; // rax
socklen_t optlen[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = (unsigned int *)calloc(1uLL, 0x80uLL);
optlen[0] = 128;
if ( v1 )
{
v2 = v1;
if ( getsockopt(fd, 1, 7, v1, optlen) >= 0 )
{
printf("SNDBUF:%d\n", *v2);
free(v2);
return 0LL;
}
printf("can't get sockopt!");
}
else
{
printf("can't alloc sockopt buffer!");
}
v4 = __errno_location();
v5 = strerror(*v4);
printf(" errno:%d(%s)\n", (unsigned int)*v4, v5);
return 0xFFFFFFFFLL;
}

original_code:
int getsockopt_sndbuf(int fd, int package_id)
{
 char *buf;
 int *sockopt_buflen;
 socklen_t buf_len;
 buf = calloc (1, 128);
 buf_len = 128;
 if (!buf)
  do { do { printf("can't alloc sockopt buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if (getsockopt(fd, 1, 7, buf, &buf_len) < 0)
  do { do { printf("can't get sockopt!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 sockopt_buflen = (int *)buf;
 printf("SNDBUF:%d\n", (*sockopt_buflen));
 free(buf);
 return 0;
}

canonical_original_code:
int getsockopt_sndbuf(int fd, int package_id)
{
 char *buf;
 int *sockopt_buflen;
 unsigned int buf_len;
 buf = calloc (1, 128);
 buf_len = 128;
 if (!buf)
  do { do { printf("can't alloc sockopt buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if (getsockopt(fd, 1, 7, buf, &buf_len) < 0)
  do { do { printf("can't get sockopt!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 sockopt_buflen = (int *)buf;
 printf("SNDBUF:%d\n", (*sockopt_buflen));
 free(buf);
 return 0;
}

variable_types: fd int

variable_types:
buf
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // eax
unsigned int v5; // ebp
const char *v6; // rdi
socklen_t v7; // edx
int v8; // ebx
size_t v9; // rax
int *v11; // rbx
char *v12; // rax
char s[8]; // [rsp+6h] [rbp-32h] BYREF
__int16 v14; // [rsp+Eh] [rbp-2Ah]
struct sockaddr v15[2]; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)s = 0x6F6C6C6568LL;
v14 = 0;
if ( argc <= 1 )
{
puts("please input ip ");
exit(1);
}
v3 = calloc(1uLL, 0xA000uLL);
if ( v3 )
{
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 < 0 )
{
printf("socket create error!");
}
else
{
getsockopt_sndbuf(v4);
v6 = argv[1];
v15[0] = 0LL;
inet_aton(v6, (struct in_addr *)&v15[0].sa_data[2]);
v15[0].sa_family = 2;
*(_WORD *)v15[0].sa_data = _bswap_16_constprop_0(v5, v15, 16LL);
if ( connect(v5, v15, v7) < 0 )
{
printf("can't connect to server!");
}
else
{
v8 = 0;
getsockopt_sndbuf(v5);
while ( send(v5, v3, 0xA000uLL, 64) >= 0 )
{
++v8;
getsockopt_sndbuf(v5);
if ( v8 == 10 )
{
v9 = strlen(s);
if ( send(v5, s, v9, 0) >= 0 )
{
getsockopt_sndbuf(v5);
close(v5);
return 0;
}
break;
}
}
printf("can't send msg!");
}
}
}
else
{
printf("can't alloc send buffer!");
}
v11 = __errno_location();
v12 = strerror(*v11);
printf(" errno:%d(%s)\n", (unsigned int)*v11, v12);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // eax
unsigned int v5; // ebp
const char *v6; // rdi
socklen_t v7; // edx
int v8; // ebx
size_t v9; // rax
int *v11; // rbx
char *v12; // rax
char s[8]; // [rsp+6h] [rbp-32h] BYREF
__int16 v14; // [rsp+Eh] [rbp-2Ah]
struct sockaddr v15[2]; // [rsp+10h] [rbp-28h] BYREF

*(_QWORD *)s = 0x6F6C6C6568LL;
v14 = 0;
if ( argc <= 1 )
{
puts("please input ip ");
exit(1);
}
v3 = calloc(1uLL, 0xA000uLL);
if ( v3 )
{
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 < 0 )
{
printf("socket create error!");
}
else
{
func8(v4);
v6 = argv[1];
v15[0] = 0LL;
inet_aton(v6, (struct in_addr *)&v15[0].sa_data[2]);
v15[0].sa_family = 2;
*(_WORD *)v15[0].sa_data = func7(v5, v15, 16LL);
if ( connect(v5, v15, v7) < 0 )
{
printf("can't connect to server!");
}
else
{
v8 = 0;
func8(v5);
while ( send(v5, v3, 0xA000uLL, 64) >= 0 )
{
++v8;
func8(v5);
if ( v8 == 10 )
{
v9 = strlen(s);
if ( send(v5, s, v9, 0) >= 0 )
{
func8(v5);
close(v5);
return 0;
}
break;
}
}
printf("can't send msg!");
}
}
}
else
{
printf("can't alloc send buffer!");
}
v11 = __errno_location();
v12 = strerror(*v11);
printf(" errno:%d(%s)\n", (unsigned int)*v11, v12);
return -1;
}

original_code:
int main(int argc, char **argv)
{
 int servfd,ret = 1;
 struct sockaddr_in servaddr;
 socklen_t socklen = sizeof(servaddr);
 char *buf;
 char hello[10] = "hello";
 int i = -1;
 if (argc < 2)
 {
  printf ("please input ip \n");
  exit(1);
 }
 buf = calloc (1, 40960);
 if (!buf)
  do { do { printf("can't alloc send buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if ((servfd = socket(2,SOCK_STREAM,0)) < 0)
  do { do { printf("socket create error!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 bzero(&servaddr,sizeof(servaddr));
 inet_aton(argv[1],&servaddr.sin_addr);
 servaddr.sin_family = 2;
 servaddr.sin_port = htons(30001);
 if (connect(servfd,(struct sockaddr*)&servaddr, socklen) < 0)
  do { do { printf("can't connect to server!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 for (i = 0; i < 10; i++) {
  if (send(servfd, buf, 40960, MSG_DONTWAIT) < 0)
   do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
  getsockopt_sndbuf(servfd, i);
 }
 if (send(servfd, hello, strlen(hello), 0) < 0)
  do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 close(servfd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int servfd; int ret = 1;
 struct sockaddr_in servaddr;
 unsigned int socklen = sizeof(servaddr);
 char *buf;
 char hello[10] = "hello";
 int i = -1;
 if (argc < 2)
 {
  printf ("please input ip \n");
  exit(1);
 }
 buf = calloc (1, 40960);
 if (!buf)
  do { do { printf("can't alloc send buffer!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 if ((servfd = socket(2,SOCK_STREAM,0)) < 0)
  do { do { printf("socket create error!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 bzero(&servaddr,sizeof(servaddr));
 inet_aton(argv[1],&servaddr.sin_addr);
 servaddr.sin_family = 2;
 servaddr.sin_port = htons(30001);
 if (connect(servfd,(struct sockaddr *)&servaddr, socklen) < 0)
  do { do { printf("can't connect to server!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 for (i = 0; i < 10; i++) {
  if (send(servfd, buf, 40960, MSG_DONTWAIT) < 0)
   do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
  getsockopt_sndbuf(servfd, i);
 }
 if (send(servfd, hello, strlen(hello), 0) < 0)
  do { do { printf("can't send msg!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;} while (0);
 getsockopt_sndbuf(servfd, i);
 close(servfd);
 return 0;
}

variable_types:
argv
char **

variable_types: servfd int

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

variable_types:
socklen
unsigned int

variable_types:
hello
char [10]

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


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

v1 = *(_QWORD *)(a1 + 56);
if ( v1 )
result = 4 * (unsigned int)(*(_BYTE *)(v1 + 12) >> 4);
else
result = 0LL;
return result;
}

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

v1 = *(_QWORD *)(a1 + 56);
if ( v1 )
result = 4 * (unsigned int)(*(_BYTE *)(v1 + 12) >> 4);
else
result = 0LL;
return result;
}

original_code:
int
utcp_header_len(struct usk_buff *uskb)
{
 struct tcphdr *tcph;
 tcph = ((struct tcphdr *)(((uskb))->transport_header));
 if (!tcph)
  return 0;
 return (tcph->doff * 4);
}

variable_types: struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node { struct btqueue_node *next; } q_send; 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]; } sin; struct uprotocol { void (*close)(struct usock { int usk_mode; struct usk_buff_head { struct usk_buff *prev; struct usk_buff *next; unsigned short qlen; 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; } loc; } *usk_write_queue; struct usk_buff_head *usk_receive_queue; } *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head { struct list_head *next; } node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); } *proto; } *

variable_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; } *

user_defined_types: struct usk_buff { struct usk_buff *prev; struct usk_buff *next; unsigned char direct; void *header; void *payload; unsigned short header_len; void *network_header; void *transport_header; struct btqueue_node q_send; struct sockaddr_in sin; struct uprotocol *proto; }

user_defined_types: struct uprotocol { void (*close)(struct usock *sk, long timeout); int (*connect)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); int (*disconnect)(struct usock *sk, int flags); struct usock *(*accept)(struct usock *sk, int flags, int *err); int (*ioctl)(struct usock *sk, int cmd, unsigned long arg); int (*init)(struct usock *sk); void (*destroy)(struct usock *sk); void (*shutdown)(struct usock *sk, int how); int (*setsockopt)(struct usock *sk, int level, int optname, char *optval, int optlen); int (*getsockopt)(struct usock *sk, int level, int optname, char *optval, int *option); int (*bind)(struct usock *sk, struct sockaddr_in *uaddr, int addr_len); char name[32]; int proto_num; struct list_head node; int (*header_len)(struct usk_buff *uskb); int (*handler)(struct usk_buff *uskb); }

user_defined_types: struct usock { int usk_mode; struct usk_buff_head *usk_write_queue; struct usk_buff_head *usk_receive_queue; }

user_defined_types: struct usk_buff_head { struct usk_buff *prev; struct usk_buff *next; unsigned short qlen; union pthread_mutex_t loc; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; 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 utcp_handler(__int64 a1)
{
tcphdr_dump(*(_QWORD *)(a1 + 56));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
tcphdr_dump(*(_QWORD *)(a1 + 56));
return 0LL;
}

original_code:
int
utcp_handler(struct usk_buff *uskb)
{
 struct tcphdr *tcph;
 tcph = ((struct tcphdr *)(((uskb))->transport_header));
 tcphdr_dump(tcph);
 return 0;
}

user_defined_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; }

user_defined_types: struct btqueue_node { struct btqueue_node *next; }

user_defined_types: struct list_head { struct list_head *next; }

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


decompiled_code:
__int64 utcp_init()
{
uprotocol_register(&utcp);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
uprotocol_register(&utcp);
return 0LL;
}

original_code:
int
utcp_init(void)
{
 uprotocol_register(&utcp);
 return 0;
}

canonical_original_code:
int utcp_init()
{
 uprotocol_register(&utcp);
 return 0;
}


decompiled_code:
int __fastcall iphdr_dump(__int64 a1)
{
puts("iphdr dump:");
printf("version:%u\n", *(_BYTE *)a1 >> 4);
printf("ihl:%u\n", *(_BYTE *)a1 & 0xF);
printf("tos:%u\n", *(unsigned __int8 *)(a1 + 1));
printf("tot_len:%u\n", *(unsigned __int16 *)(a1 + 2));
printf("id:%u\n", *(unsigned __int16 *)(a1 + 4));
printf("frag_off:%u\n", *(unsigned __int16 *)(a1 + 6));
printf("ttl:%u\n", *(unsigned __int8 *)(a1 + 8));
printf("protocol:%u\n", *(unsigned __int8 *)(a1 + 9));
printf("check:%u\n", *(unsigned __int16 *)(a1 + 10));
printf("saddr:%x\n", *(unsigned int *)(a1 + 12));
return printf("daddr:%x\n\n", *(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
puts("iphdr dump:");
printf("version:%u\n", *(_BYTE *)a1 >> 4);
printf("ihl:%u\n", *(_BYTE *)a1 & 0xF);
printf("tos:%u\n", *(unsigned __int8 *)(a1 + 1));
printf("tot_len:%u\n", *(unsigned __int16 *)(a1 + 2));
printf("id:%u\n", *(unsigned __int16 *)(a1 + 4));
printf("frag_off:%u\n", *(unsigned __int16 *)(a1 + 6));
printf("ttl:%u\n", *(unsigned __int8 *)(a1 + 8));
printf("protocol:%u\n", *(unsigned __int8 *)(a1 + 9));
printf("check:%u\n", *(unsigned __int16 *)(a1 + 10));
printf("saddr:%x\n", *(unsigned int *)(a1 + 12));
return printf("daddr:%x\n\n", *(unsigned int *)(a1 + 16));
}

original_code:
void
iphdr_dump(struct iphdr *iph)
{
 printf("iphdr dump:\n");
 printf("version:%u\n", iph->version);
 printf("ihl:%u\n", iph->ihl);
 printf("tos:%u\n", iph->tos);
 printf("tot_len:%u\n", iph->tot_len);
 printf("id:%u\n", iph->id);
 printf("frag_off:%u\n", iph->frag_off);
 printf("ttl:%u\n", iph->ttl);
 printf("protocol:%u\n", iph->protocol);
 printf("check:%u\n", iph->check);
 printf("saddr:%x\n", iph->saddr);
 printf("daddr:%x\n\n", iph->daddr);
}

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *


original_code:
void
tcphdr_dump(struct tcphdr *tcph)
{
 printf("tcphdr dump\n");
 printf("source:%u\n", ntohs(tcph->source));
 printf("dest:%u\n", ntohs(tcph->dest));
 printf("seq:%u\n", tcph->seq);
 printf("ack_seq:%u\n", tcph->ack_seq);
 printf("doff:%u\n", tcph->doff);
 printf("fin:%u\n", tcph->fin);
 printf("syn:%u\n", tcph->syn);
 printf("rst:%u\n", tcph->rst);
 printf("psh:%u\n", tcph->psh);
 printf("ack:%u\n", tcph->ack);
 printf("urg:%u\n\n\n\n", tcph->urg);
}


decompiled_code:
_BOOL8 __fastcall is_zero(unsigned int a1)
{
printf("get %d\n", a1);
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(unsigned int a1)
{
printf("get %d\n", a1);
return a1 == 0;
}

original_code:
int is_zero(int i)
{
 printf("get %d\n", i);
 return i == 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("hello");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if (0 == 0 || is_zero(1))
  printf("hello\n");
 return 0;
}


decompiled_code:
int test_long()
{
printf("ul=%lx\n", -1000LL);
return printf("p=%p\n", (const void *)0xFFFFFFFFFFFFFC18LL);
}

canonical_decompiled_code:
int func7()
{
printf("ul=%lx\n", -1000LL);
return printf("p=%p\n", (const void *)0xFFFFFFFFFFFFFC18LL);
}

original_code:
void test_long(void)
{
 long l;
 void *p;
 unsigned long ul;
 l = -1000;
 ul = l;
 printf("ul=%lx\n", ul);
 p = (void *)ul;
 printf("p=%p\n", p);
}

canonical_original_code:
void test_long()
{
 long l;
 void *p;
 unsigned long ul;
 l = -1000;
 ul = l;
 printf("ul=%lx\n", ul);
 p = (void *)ul;
 printf("p=%p\n", p);
}

variable_types: l long

variable_types:
p
void *

variable_types:
ul
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char s[10]; // [rsp+0h] [rbp-28h] BYREF
char v5[8]; // [rsp+Ah] [rbp-1Eh] BYREF

strcpy(s, "123456");
strcpy(v5, "abcdef");
puts(s);
puts(&s[1]);
test_long(&s[1], argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char s[10]; // [rsp+0h] [rbp-28h] BYREF
char v5[8]; // [rsp+Ah] [rbp-1Eh] BYREF

strcpy(s, "123456");
strcpy(v5, "abcdef");
puts(s);
puts(&s[1]);
func7(&s[1], argv);
return 0;
}

original_code:
int
main(void)
{
 char *hello;
 int *i;
 struct node n[2];
 void *p;
 strcpy(n[0].hello, "123456");
 strcpy(n[1].hello, "abcdef");
 p = n;
 printf("%s\n", p);
 p +=1;
 printf("%s\n", p);
 i = p;
 test_long();
 return 0;
}

canonical_original_code:
int main()
{
 char *hello;
 int *i;
 struct node n[2];
 void *p;
 strcpy(n[0].hello, "123456");
 strcpy(n[1].hello, "abcdef");
 p = n;
 printf("%s\n", p);
 p +=1;
 printf("%s\n", p);
 i = p;
 test_long();
 return 0;
}

variable_types:
hello
char *

variable_types:
i
int *

variable_types:
n
struct node { char hello[10]; } [2]


decompiled_code:
int test_snprintf()
{
__int64 v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v2 = 0;
v1 = 0LL;
return printf("snprintf p_len=%d gen=%s\n", 0LL, (const char *)&v1);
}

canonical_decompiled_code:
int func7()
{
__int64 v1; // [rsp+6h] [rbp-12h] BYREF
__int16 v2; // [rsp+Eh] [rbp-Ah]

v2 = 0;
v1 = 0LL;
return printf("snprintf p_len=%d gen=%s\n", 0LL, (const char *)&v1);
}

original_code:
void test_snprintf(void)
{
 char buffer[10] = {0}, *p = ((void *)0);
 int tatal = 10, p_len;
 int i;
 p = buffer;
 p_len = snprintf(buffer, 2, "");
out:
 printf("snprintf p_len=%d gen=%s\n", p_len, buffer);
}

canonical_original_code:
void test_snprintf()
{
 char buffer[10] = {0}; char *p = ((void *)0);
 int tatal = 10; int p_len;
 int i;
 p = buffer;
 p_len = snprintf(buffer, 2, "");
out:
 printf("snprintf p_len=%d gen=%s\n", p_len, buffer);
}

variable_types:
buffer
char [10]

variable_types:
p
char *

variable_types: tatal int

variable_types: i int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx

printf("%u, %u, %u\n", 1LL, 2LL, v3);
printf("%u, %u\n", 4LL, 8LL);
printf("a=%llu\n", 4LL);
printf("%04d\n", 123LL);
test_snprintf();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx

printf("%u, %u, %u\n", 1LL, 2LL, v3);
printf("%u, %u\n", 4LL, 8LL);
printf("a=%llu\n", 4LL);
printf("%04d\n", 123LL);
func7();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 __u64 a = 0x1;
 __u32 b = 2;
 printf("%u, %u, %u\n", a, b);
 printf("%u, %u\n", sizeof(__u32), sizeof(__u64));
 a <<= 2;
 printf("a=%llu\n", a);
 printf("%04d\n", 123);
 test_snprintf();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long long a = 0x1;
 unsigned int b = 2;
 printf("%u, %u, %u\n", a, b);
 printf("%u, %u\n", sizeof(__u32), sizeof(__u64));
 a <<= 2;
 printf("a=%llu\n", a);
 printf("%04d\n", 123);
 test_snprintf();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
a
unsigned long long

variable_types:
b
unsigned int


Abort

decompiled_code:
void __noreturn Abort()
{
abort();
}

canonical_decompiled_code:
void __noreturn func1()
{
abort();
}

original_code:
int Abort()
{
 abort();
}

canonical_original_code:
int Abort()
{
 abort();
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct rlimit v3; // [rsp+0h] [rbp-18h] BYREF

getrlimit(RLIMIT_CORE, &v3);
printf("For core size, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
v3.rlim_cur = -1LL;
setrlimit(RLIMIT_CORE, &v3);
getrlimit(RLIMIT_CORE, &v3);
printf("After setrlimit, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
Abort();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct rlimit v3; // [rsp+0h] [rbp-18h] BYREF

getrlimit(RLIMIT_CORE, &v3);
printf("For core size, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
v3.rlim_cur = -1LL;
setrlimit(RLIMIT_CORE, &v3);
getrlimit(RLIMIT_CORE, &v3);
printf("After setrlimit, cur limit is:%d, hard limit is:%d\n", v3.rlim_cur, v3.rlim_max);
func1();
}

original_code:
int main(int argc, char *argv[])
{
 struct rlimit lim;
 getrlimit(RLIMIT_CORE, &lim);
 printf("For core size, cur limit is:%d, hard limit is:%d\n", lim.rlim_cur, lim.rlim_max);
 lim.rlim_cur = -1;
 setrlimit(RLIMIT_CORE, &lim);
 getrlimit(RLIMIT_CORE, &lim);
 printf("After setrlimit, cur limit is:%d, hard limit is:%d\n", lim.rlim_cur, lim.rlim_max);
 Abort();
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
int __fastcall open_write(const char *a1)
{
int v1; // eax
int result; // eax
int *v3; // rbx
char *v4; // rax
int *v5; // rbx
char *v6; // rax

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("Can not open file:%s, (%d)%s\n", a1, (unsigned int)*v3, v4);
result = 1;
}
else
{
result = close(v1);
if ( result < 0 )
{
printf("can not close file");
v5 = __errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
int v1; // eax
int result; // eax
int *v3; // rbx
char *v4; // rax
int *v5; // rbx
char *v6; // rax

v1 = open(a1, 0);
if ( v1 < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("Can not open file:%s, (%d)%s\n", a1, (unsigned int)*v3, v4);
result = 1;
}
else
{
result = close(v1);
if ( result < 0 )
{
printf("can not close file");
v5 = __errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
result = -1;
}
}
return result;
}

original_code:
int open_write(char *file_path)
{
 int fd, ret;
 fd = open(file_path, (00));
 if (fd < 0) {
  printf("Can not open file:%s, (%d)%s\n", file_path, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 ret = close(fd);
 do {if (ret < 0) { do { printf("can not close file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
 return ret;
}

canonical_original_code:
int open_write(char *file_path)
{
 int fd; int ret;
 fd = open(file_path, (00));
 if (fd < 0) {
  printf("Can not open file:%s, (%d)%s\n", file_path, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 ret = close(fd);
 do {if (ret < 0) { do { printf("can not close file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
 return ret;
}

variable_types: fd int

variable_types: ret int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int result; // eax
__int64 v5; // rbx
struct timezone *v6; // rsi
__int64 v7; // rdi

v3 = parse_args(argc, argv, envp);
result = 1;
if ( v3 )
{
v5 = 0LL;
read_flist(v3);
v6 = *(struct timezone **)(v3 + 16);
printf((const char *)&tv, v6);
gettimeofday((struct timeval *)&tv, v6);
if ( *(__int64 *)(v3 + 16) > 0 )
{
do
{
v7 = *(_QWORD *)(*(_QWORD *)(v3 + 8) + 8 * v5++);
open_write(v7);
}
while ( *(_QWORD *)(v3 + 16) > v5 );
}
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int result; // eax
__int64 v5; // rbx
struct timezone *v6; // rsi
__int64 v7; // rdi

v3 = parse_args(argc, argv, envp);
result = 1;
if ( v3 )
{
v5 = 0LL;
func8(v3);
v6 = *(struct timezone **)(v3 + 16);
printf((const char *)&tv, v6);
gettimeofday((struct timeval *)&tv, v6);
if ( *(__int64 *)(v3 + 16) > 0 )
{
do
{
v7 = *(_QWORD *)(*(_QWORD *)(v3 + 8) + 8 * v5++);
func7(v7);
}
while ( *(_QWORD *)(v3 + 16) > v5 );
}
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 struct options *opts;
 int i;
 opts = parse_args(argc, argv);
 if (opts == ((void *)0))
  goto failed;
 read_flist(opts);
 printf("open %ld files\n", opts->flist_count);
 gettimeofday();
 for (i=0; i<opts->flist_count; i++) {
  open_write(opts->flist[i]);
 }
 return 0;
failed:
 return 1;
}

variable_types: struct options { char *flist_path; char **flist; long flist_count; } *


interval

decompiled_code:
float interval()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start.tv_sec));
}

canonical_decompiled_code:
float func7()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start.tv_usec)) / 1000000.0
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start.tv_sec));
}

original_code:
float interval()
{
 struct timeval curTime;
 gettimeofday(&curTime, ((void *)0));
 float interval = (curTime.tv_sec - start.tv_sec)+((curTime.tv_usec - start.tv_usec)/1000000.0);
 return interval;
}

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

variable_types: interval float

return_type: float


nextQueue

decompiled_code:
__int64 nextQueue()
{
unsigned int v0; // er12

v0 = *(_DWORD *)queue;
if ( size_queue > 0 )
memmove(queue, (char *)queue + 16, 16LL * size_queue);
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // er12

v0 = *(_DWORD *)queue;
if ( size_queue > 0 )
memmove(queue, (char *)queue + 16, 16LL * size_queue);
return v0;
}

original_code:
int nextQueue()
{
 int next = queue[0].id;
 int i = 0;
 while(i<size_queue)
 {
  queue[i]=queue[i+1];
  i++;
 }
 return next;
}

variable_types: next int


yourFlow

decompiled_code:
void __fastcall __noreturn yourFlow(void *a1)
{
unsigned int v1; // ebp
int v2; // ebx
unsigned int v3; // er14
__int64 v4; // r13
__int64 v5; // r12
float v6; // xmm0_4
float v7; // xmm0_4
float v8; // xmm0_4
__int64 v9; // rsi
unsigned int v10; // er12
float v11; // xmm0_4
float v12; // xmm0_4
__int64 v13; // rdx
__int64 v14; // rcx

v1 = *(_DWORD *)a1;
v2 = *((_DWORD *)a1 + 2);
v3 = *((_DWORD *)a1 + 3);
v4 = *(_QWORD *)a1;
v5 = *((_QWORD *)a1 + 1);
usleep((int)(float)((float)*((int *)a1 + 1) * 100000.0));
v6 = interval();
printf(
"Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",
v1,
v6,
(double)v2 / 10.0,
v3);
if ( trans_thread )
{
pthread_mutex_lock(&queue_mutex);
addtoQueue(v4, v5);
pthread_mutex_unlock(&queue_mutex);
printf("Flow %2d waits for the finish of flow %2d. \n", v1, (unsigned int)trans_thread);
v10 = trans_thread;
while ( trans_thread != v1 )
;
pthread_mutex_lock(&transmit);
trans_thread = v10;
pthread_mutex_unlock(&transmit);
v11 = interval();
printf("Flow %2d starts its transmission at time %.2f. \n", v10, v11);
usleep((int)(float)((float)v2 * 100000.0));
v12 = interval();
v9 = v10;
printf("Flow %2d finishes its transmission at time %.2f. \n", v10, v12);
}
else
{
pthread_mutex_lock(&transmit);
trans_thread = v1;
pthread_mutex_unlock(&transmit);
v7 = interval();
printf("Flow %2d starts its transmission at time %.2f. \n", v1, v7);
usleep((int)(float)((float)v2 * 100000.0));
v8 = interval();
v9 = v1;
printf("Flow %2d finishes its transmission at time %.2f. \n", v1, v8);
}
pthread_mutex_lock(&transmit);
if ( size_queue )
{
pthread_mutex_lock(&queue_mutex);
trans_thread = nextQueue(&queue_mutex, v9, v13, v14);
pthread_mutex_unlock(&queue_mutex);
}
else
{
trans_thread = 0;
}
pthread_mutex_unlock(&transmit);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(void *a1)
{
unsigned int v1; // ebp
int v2; // ebx
unsigned int v3; // er14
__int64 v4; // r13
__int64 v5; // r12
float v6; // xmm0_4
float v7; // xmm0_4
float v8; // xmm0_4
__int64 v9; // rsi
unsigned int v10; // er12
float v11; // xmm0_4
float v12; // xmm0_4
__int64 v13; // rdx
__int64 v14; // rcx

v1 = *(_DWORD *)a1;
v2 = *((_DWORD *)a1 + 2);
v3 = *((_DWORD *)a1 + 3);
v4 = *(_QWORD *)a1;
v5 = *((_QWORD *)a1 + 1);
usleep((int)(float)((float)*((int *)a1 + 1) * 100000.0));
v6 = func7();
printf(
"Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",
v1,
v6,
(double)v2 / 10.0,
v3);
if ( trans_thread )
{
pthread_mutex_lock(&queue_mutex);
func9(v4, v5);
pthread_mutex_unlock(&queue_mutex);
printf("Flow %2d waits for the finish of flow %2d. \n", v1, (unsigned int)trans_thread);
v10 = trans_thread;
while ( trans_thread != v1 )
;
pthread_mutex_lock(&transmit);
trans_thread = v10;
pthread_mutex_unlock(&transmit);
v11 = func7();
printf("Flow %2d starts its transmission at time %.2f. \n", v10, v11);
usleep((int)(float)((float)v2 * 100000.0));
v12 = func7();
v9 = v10;
printf("Flow %2d finishes its transmission at time %.2f. \n", v10, v12);
}
else
{
pthread_mutex_lock(&transmit);
trans_thread = v1;
pthread_mutex_unlock(&transmit);
v7 = func7();
printf("Flow %2d starts its transmission at time %.2f. \n", v1, v7);
usleep((int)(float)((float)v2 * 100000.0));
v8 = func7();
v9 = v1;
printf("Flow %2d finishes its transmission at time %.2f. \n", v1, v8);
}
pthread_mutex_lock(&transmit);
if ( size_queue )
{
pthread_mutex_lock(&queue_mutex);
trans_thread = func8(&queue_mutex, v9, v13, v14);
pthread_mutex_unlock(&queue_mutex);
}
else
{
trans_thread = 0;
}
pthread_mutex_unlock(&transmit);
pthread_exit(0LL);
}

original_code:
void *yourFlow(void* arg)
{
 struct flow curFlow = *(struct flow *)arg;
 double arv = (double)curFlow.arrival_time/10;
 double trans = (double)curFlow.trans_time/10;
 usleep(curFlow.arrival_time * 1E5F);
 printf("Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",curFlow.id, interval(), trans, curFlow.priority);
 if(!trans_thread)
 {
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  addtoQueue(curFlow);
  pthread_mutex_unlock(&queue_mutex);
  printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
  int tmp = trans_thread;
  while(trans_thread != curFlow.id)
  {
   if(tmp != trans_thread && trans_thread != curFlow.id)
   {
    tmp = trans_thread;
    printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
   }
  }
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 pthread_mutex_lock(&transmit);
 if(!size_queue)
 {
  trans_thread = 0;
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  trans_thread = nextQueue();
  pthread_mutex_unlock(&queue_mutex);
 }
 pthread_mutex_unlock(&transmit);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *yourFlow(void *arg)
{
 struct flow curFlow = *(struct flow *)arg;
 double arv = (double)curFlow.arrival_time/10;
 double trans = (double)curFlow.trans_time/10;
 usleep(curFlow.arrival_time * 1E5F);
 printf("Flow %2d arrives: arrival time (%.2f), transmission time (%.1f), priority (%2d). \n",curFlow.id, interval(), trans, curFlow.priority);
 if(!trans_thread)
 {
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  addtoQueue(curFlow);
  pthread_mutex_unlock(&queue_mutex);
  printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
  int tmp = trans_thread;
  while(trans_thread != curFlow.id)
  {
   if(tmp != trans_thread && trans_thread != curFlow.id)
   {
    tmp = trans_thread;
    printf("Flow %2d waits for the finish of flow %2d. \n", curFlow.id, trans_thread);
   }
  }
  pthread_mutex_lock(&transmit);
  trans_thread = curFlow.id;
  pthread_mutex_unlock(&transmit);
  printf("Flow %2d starts its transmission at time %.2f. \n", curFlow.id, interval());
  usleep(curFlow.trans_time* 1E5F);
  printf("Flow %2d finishes its transmission at time %.2f. \n", curFlow.id, interval());
 }
 pthread_mutex_lock(&transmit);
 if(!size_queue)
 {
  trans_thread = 0;
 }
 else
 {
  pthread_mutex_lock(&queue_mutex);
  trans_thread = nextQueue();
  pthread_mutex_unlock(&queue_mutex);
 }
 pthread_mutex_unlock(&transmit);
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: struct flow { int id; int arrival_time; int trans_time; int priority; }

variable_types: arv double

variable_types: trans double

variable_types: tmp int


stringtoflow

decompiled_code:
__int64 __fastcall stringtoflow(char *s)
{
char *v1; // rax
char *v2; // rdi
__int64 *v3; // rbx
__int64 v5; // [rsp+0h] [rbp-A8h] BYREF
char dest[152]; // [rsp+10h] [rbp-98h] BYREF

strcpy(dest, s);
v1 = strtok(s, delim);
if ( v1 )
{
v2 = v1;
v3 = &v5;
do
{
v3 = (__int64 *)((char *)v3 + 4);
*((_DWORD *)v3 - 1) = atoi(v2);
v2 = strtok(0LL, &delim[2]);
}
while ( v2 );
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *s)
{
char *v1; // rax
char *v2; // rdi
__int64 *v3; // rbx
__int64 v5; // [rsp+0h] [rbp-A8h] BYREF
char dest[152]; // [rsp+10h] [rbp-98h] BYREF

strcpy(dest, s);
v1 = strtok(s, delim);
if ( v1 )
{
v2 = v1;
v3 = &v5;
do
{
v3 = (__int64 *)((char *)v3 + 4);
*((_DWORD *)v3 - 1) = atoi(v2);
v2 = strtok(0LL, &delim[2]);
}
while ( v2 );
}
return v5;
}

original_code:
struct flow stringtoflow(char* text)
{
 struct flow hold;
 int flow_array[4];
 char buffer[128];
 int i = 0;
 strcpy(buffer, text);
 char* token = strtok(text, ":");
 while (token)
        {
  flow_array[i++] = atoi(token);
             token = strtok(((void *)0), ",");
        }
 hold.id = flow_array[0];
 hold.arrival_time = flow_array[1];
 hold.trans_time = flow_array[2];
 hold.priority = flow_array[3];
 return hold;
}

canonical_original_code:
struct flow stringtoflow(char *text)
{
 struct flow hold;
 int flow_array[4];
 char buffer[128];
 int i = 0;
 strcpy(buffer, text);
 char *token = strtok(text, ":");
 while (token)
        {
  flow_array[i++] = atoi(token);
             token = strtok(((void *)0), ",");
        }
 hold.id = flow_array[0];
 hold.arrival_time = flow_array[1];
 hold.trans_time = flow_array[2];
 hold.priority = flow_array[3];
 return hold;
}

variable_types:
text
char *

variable_types:
buffer
char [128]

variable_types: i int

variable_types:
token
char *

return_type: struct flow { int id; int arrival_time; int trans_time; int priority; }


main

repo: beckharry/loadtune

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
bool v4; // cf
bool v5; // zf
const char **v6; // r12
const char *v7; // rdi
__int64 v8; // rcx
char v9; // bp
const unsigned __int16 *v10; // rcx
char *v11; // rax
float v12; // xmm0_4

nrcpus = sysconf(84);
v3 = nrcpus;
getpid();
v4 = (unsigned int)argc < 2;
v5 = argc == 2;
if ( argc == 2 )
{
v6 = (const char **)argv[1];
v7 = "--help";
v8 = 7LL;
argv = v6;
do
{
if ( !v8 )
break;
v4 = *(_BYTE *)argv < *v7;
v5 = *(_BYTE *)argv == *v7;
argv = (const char **)((char *)argv + 1);
++v7;
--v8;
}
while ( v5 );
if ( (!v4 && !v5) != v4 )
{
argv = (const char **)"-h";
v7 = (const char *)v6;
if ( strcmp((const char *)v6, "-h") )
{
v9 = *(_BYTE *)v6;
if ( !*(_BYTE *)v6 )
{
LABEL_12:
v12 = atof((const char *)v6);
loadtune = LODWORD(v12);
if ( v12 > (float)v3 )
{
puts("Invalid target-value, it MUST be lower than nrcpus.");
print_help("Invalid target-value, it MUST be lower than nrcpus.", "-h");
}
while ( 1 )
{
get_loadavg();
tune_proc_start();
get_loadavg();
tune_proc_start();
}
}
v10 = *__ctype_b_loc();
v11 = (char *)v6 + 1;
while ( (v10[v9] & 0x800) != 0 || v9 == 46 )
{
v9 = *v11++;
if ( !v9 )
goto LABEL_12;
}
}
}
}
else
{
v7 = "Invalid parameter count.";
puts("Invalid parameter count.");
}
return print_help(v7, argv);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
bool v4; // cf
bool v5; // zf
const char **v6; // r12
const char *v7; // rdi
__int64 v8; // rcx
char v9; // bp
const unsigned __int16 *v10; // rcx
char *v11; // rax
float v12; // xmm0_4

nrcpus = sysconf(84);
v3 = nrcpus;
getpid();
v4 = (unsigned int)argc < 2;
v5 = argc == 2;
if ( argc == 2 )
{
v6 = (const char **)argv[1];
v7 = "--help";
v8 = 7LL;
argv = v6;
do
{
if ( !v8 )
break;
v4 = *(_BYTE *)argv < *v7;
v5 = *(_BYTE *)argv == *v7;
argv = (const char **)((char *)argv + 1);
++v7;
--v8;
}
while ( v5 );
if ( (!v4 && !v5) != v4 )
{
argv = (const char **)"-h";
v7 = (const char *)v6;
if ( strcmp((const char *)v6, "-h") )
{
v9 = *(_BYTE *)v6;
if ( !*(_BYTE *)v6 )
{
LABEL_12:
v12 = atof((const char *)v6);
loadtune = LODWORD(v12);
if ( v12 > (float)v3 )
{
puts("Invalid target-value, it MUST be lower than nrcpus.");
func7("Invalid target-value, it MUST be lower than nrcpus.", "-h");
}
while ( 1 )
{
func8();
func9();
func8();
func9();
}
}
v10 = *__ctype_b_loc();
v11 = (char *)v6 + 1;
while ( (v10[v9] & 0x800) != 0 || v9 == 46 )
{
v9 = *v11++;
if ( !v9 )
goto LABEL_12;
}
}
}
}
else
{
v7 = "Invalid parameter count.";
puts("Invalid parameter count.");
}
return func7(v7, argv);
}

original_code:
void main(int argc, char ** argv)
{
 float current_load = 0;
 int proc_index = 0;
 nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
 ("nrcpus: %d.\n", nrcpus);
 ("pid: %d.\n", getpid());
 if (argc == 2) {
  int i = 0;
  if ((strcmp(argv[1], "--help") == 0)
    || ((strcmp(argv[1], "-h") == 0))) {
   print_help();
   return;
  }
  for (; argv[1][i] != '\0'; i++) {
   if (((*__ctype_b_loc ())[(int) ((argv[1][i]))] & (unsigned short int) _ISdigit) || (argv[1][i] == '.')) {
    continue;
   }
   else {
    print_help();
    return;
   }
  }
  loadtune = atof(argv[1]);
 }
 else {
  printf("Invalid parameter count.\n");
  print_help();
  return;
 }
 ("loadtune: %f.\n", loadtune);
 if (loadtune > (float)(nrcpus)) {
  printf("Invalid target-value, it MUST be lower than nrcpus.\n");
  print_help();
 }
 while(1) {
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
  tune_proc_start();
 }
 return;
}

canonical_original_code:
void main(int argc, char **argv)
{
 float current_load = 0;
 int proc_index = 0;
 nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
 ("nrcpus: %d.\n", nrcpus);
 ("pid: %d.\n", getpid());
 if (argc == 2) {
  int i = 0;
  if ((strcmp(argv[1], "--help") == 0)
    || ((strcmp(argv[1], "-h") == 0))) {
   print_help();
   return;
  }
  for (; argv[1][i] != '\0'; i++) {
   if (((*__ctype_b_loc ())[(int) ((argv[1][i]))] & (unsigned short) _ISdigit) || (argv[1][i] == '.')) {
    continue;
   }
   else {
    print_help();
    return;
   }
  }
  loadtune = atof(argv[1]);
 }
 else {
  printf("Invalid parameter count.\n");
  print_help();
  return;
 }
 ("loadtune: %f.\n", loadtune);
 if (loadtune > (float)(nrcpus)) {
  printf("Invalid target-value, it MUST be lower than nrcpus.\n");
  print_help();
 }
 while(1) {
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
  tune_proc_start();
 }
 return;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
int print_help()
{
puts("Usage:");
puts(" loadtune-daemon target-value");
puts("Options:");
puts(" For single core machine, target-value is between 0 and 1;");
puts(" For multiple[N] core machine, target-value is between 0 and N.");
printf(" (N is %d on this machine)\n", (unsigned int)nrcpus);
puts("Example:");
return puts(" loadtune-daemon 0.4");
}

canonical_decompiled_code:
int func7()
{
puts("Usage:");
puts(" loadtune-daemon target-value");
puts("Options:");
puts(" For single core machine, target-value is between 0 and 1;");
puts(" For multiple[N] core machine, target-value is between 0 and N.");
printf(" (N is %d on this machine)\n", (unsigned int)nrcpus);
puts("Example:");
return puts(" loadtune-daemon 0.4");
}

original_code:
static void print_help(void)
{
 printf("Usage:\n");
 printf("    loadtune-daemon target-value\n");
 printf("Options:\n");
 printf("    For single core machine, target-value is between 0 and 1;\n");
 printf("    For multiple[N] core machine, target-value is between 0 and N.\n");
 printf("    (N is %d on this machine)\n", nrcpus);
 printf("Example:\n");
 printf("    loadtune-daemon 0.4\n");
}

canonical_original_code:
static void print_help()
{
 printf("Usage:\n");
 printf("    loadtune-daemon target-value\n");
 printf("Options:\n");
 printf("    For single core machine, target-value is between 0 and 1;\n");
 printf("    For multiple[N] core machine, target-value is between 0 and N.\n");
 printf("    (N is %d on this machine)\n", nrcpus);
 printf("Example:\n");
 printf("    loadtune-daemon 0.4\n");
}


decompiled_code:
int tune_proc_start()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++affinity;
pthread_create(newthread, 0LL, tune_proc, 0LL);
return pthread_join(newthread[0], 0LL);
}

canonical_decompiled_code:
int func9()
{
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

++affinity;
pthread_create(newthread, 0LL, tune_proc, 0LL);
return pthread_join(newthread[0], 0LL);
}

original_code:
static void tune_proc_start(void)
{
 pthread_t thread;
 affinity++;
 pthread_create(&thread, ((void *)0), (void *)tune_proc, ((void *)0));
 pthread_join(thread, ((void *)0));
 return;
}

canonical_original_code:
static void tune_proc_start()
{
 unsigned long thread;
 affinity++;
 pthread_create(&thread, ((void *)0), (void *)tune_proc, ((void *)0));
 pthread_join(thread, ((void *)0));
 return;
}

variable_types:
thread
unsigned long


decompiled_code:
int __fastcall tune_proc(void *a1, float a2)
{
pthread_t v2; // r9
unsigned __int64 v3; // rax
int result; // eax
cpu_set_t v5; // [rsp+0h] [rbp-88h] BYREF

v2 = pthread_self();
memset(&v5, 0, sizeof(v5));
v3 = affinity % nrcpus;
if ( v3 <= 0x3FF )
v5.__bits[v3 >> 6] |= 1LL << (affinity % nrcpus);
pthread_setaffinity_np(v2, 0x80uLL, &v5);
while ( 1 )
{
result = get_loadavg();
if ( *(float *)&loadtune <= a2 )
break;
get_loadavg();
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(void *a1, float a2)
{
pthread_t v2; // r9
unsigned __int64 v3; // rax
int result; // eax
cpu_set_t v5; // [rsp+0h] [rbp-88h] BYREF

v2 = pthread_self();
memset(&v5, 0, sizeof(v5));
v3 = affinity % nrcpus;
if ( v3 <= 0x3FF )
v5.__bits[v3 >> 6] |= 1LL << (affinity % nrcpus);
pthread_setaffinity_np(v2, 0x80uLL, &v5);
while ( 1 )
{
result = func8();
if ( *(float *)&loadtune <= a2 )
break;
func8();
}
return result;
}

original_code:
static void tune_proc(void * arg)
{
 pthread_t thread;
 cpu_set_t cpuset;
 ("affinity: %d.\n", affinity);
 thread = pthread_self();
 ("pthread: %d.\n", thread);
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ size_t __cpu = (affinity % nrcpus); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
 while (get_loadavg() < loadtune){
  ("pthread: %d.\n", thread);
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
 }
 ("end of tune_proc.\n");
 return;
}

canonical_original_code:
static void tune_proc(void *arg)
{
 unsigned long thread;
 struct cpu_set_t cpuset;
 ("affinity: %d.\n", affinity);
 thread = pthread_self();
 ("pthread: %d.\n", thread);
 do __builtin_memset (&cpuset, '\0', sizeof (cpu_set_t)); while (0);
 (__extension__ ({ unsigned long __cpu = (affinity % nrcpus); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((&cpuset)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
 pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
 while (get_loadavg() < loadtune){
  ("pthread: %d.\n", thread);
  ("current load average: %f.\n", get_loadavg());
  ("target load average: %f.\n", loadtune);
 }
 ("end of tune_proc.\n");
 return;
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; }


repo: beckysag/archiver

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r12
char v5; // al
char *v6; // r14
int v7; // eax
const char **v9; // rsi
const char **v10; // rdx
size_t v11; // rax
int v12; // ebp
int *v13; // rax
char *v14; // rax
const char *v15; // rdi
int fd[11]; // [rsp+Ch] [rbp-2Ch] BYREF

while ( 2 )
{
v5 = getopt(argc, (char *const *)argv, "qxtvdAw");
if ( v5 != -1 )
{
switch ( v5 )
{
case 'A':
case 'd':
case 'q':
case 't':
case 'v':
case 'w':
case 'x':
v3 = v5;
continue;
default:
goto LABEL_26;
}
}
break;
}
if ( optind < argc )
{
v11 = strlen(argv[optind]);
v6 = (char *)malloc(v11 + 1);
if ( !v6 )
_assert_fail("ar_name != NULL", "main.c", 0x3Eu, "main");
v12 = optind + 1;
strcpy(v6, argv[optind]);
optind = v12;
}
else
{
v6 = 0LL;
puts("no archive file given.");
usage();
}
fd[0] = open_ar_file(v6, (unsigned int)v3);
do
{
if ( v3 == 65 )
{
append_all((unsigned int)fd[0], v6);
LABEL_10:
v7 = optind;
}
else
{
switch ( v3 )
{
case 'd':
v10 = &argv[optind];
if ( !*v10 )
{
v15 = "no file given to delete.";
goto LABEL_25;
}
delete(fd, v6, v10, (unsigned int)(argc - optind));
v7 = argc;
break;
case 'q':
v9 = &argv[optind];
if ( !*v9 )
{
v15 = "no file given to append.";
LABEL_25:
puts(v15);
LABEL_26:
usage();
exit(1);
}
append((unsigned int)fd[0], v9, (unsigned int)(argc - optind));
v7 = argc;
break;
case 't':
print_concise((unsigned int)fd[0]);
v7 = optind;
break;
case 'v':
print_verbose((unsigned int)fd[0]);
v7 = optind;
break;
case 'x':
extract((unsigned int)fd[0], argv[optind]);
v7 = optind;
break;
default:
goto LABEL_10;
}
}
optind = v7 + 1;
}
while ( v7 + 1 < argc );
if ( close(fd[0]) == -1 )
{
v13 = _errno_location();
v14 = strerror(*v13);
printf("ERROR: %s\n", v14);
}
return 0;
}

original_code:
int main(int argc, char **argv) {
 int fd;
    char c;
    char key;
    char *ar_name = ((void *)0);
    while ((c = getopt (argc, argv, "qxtvdAw")) != -1)
        switch (c) {
            case 'q':
                key = 'q';
                break;
            case 'x':
                key = 'x';
                break;
            case 't':
                key = 't';
                break;
            case 'v':
                key = 'v';
                break;
            case 'd':
                key = 'd';
                break;
            case 'A':
                key = 'A';
                break;
            case 'w':
                key = 'w';
                break;
            default:
                usage();
                exit(1);
                break;
        }
    if (!key){
     printf("No option given\n");
     usage();
     exit(-1);
    }
    if (optind < argc) {
        ar_name = (char*)malloc(sizeof(char) * (strlen(argv[optind]) + 1));
        ((void) sizeof ((ar_name != ((void *)0)) ? 1 : 0), __extension__ ({ if (ar_name != ((void *)0)) ; else __assert_fail ("ar_name != NULL", "main.c", 62, __extension__ __PRETTY_FUNCTION__); }));
        strcpy(ar_name, argv[optind]);
        optind = optind + 1;
    }else {
        printf("no archive file given.\n");
        usage();
    }
    fd = open_ar_file(ar_name, key);
    do {
        switch(key) {
            case 'q':
                if (argv[optind] == ((void *)0)) {
                    printf("no file given to append.\n");
                 usage();
                 exit(1);
                }
             append(fd, &(argv[optind]), (argc-optind));
             optind = argc;
                break;
            case 't':
                print_concise(fd);
                break;
            case 'v':
                print_verbose(fd);
                break;
            case 'x':
                extract(fd, argv[optind] ? argv[optind] : ((void *)0));
                break;
            case 'd':
                if (argv[optind] == ((void *)0)) {
                    printf("no file given to delete.\n");
                 usage();
                 exit(1);
                }
             delete(&fd, ar_name, &(argv[optind]), (argc-optind));
             optind = argc;
                break;
            case 'A':
                append_all(fd, ar_name);
                break;
            case 'w':
                break;
        }
        optind++;
    } while (optind < argc);
    if (close(fd) == -1)
        printf("ERROR: %s\n", strerror((*__errno_location ())));
    return(0);
}

canonical_original_code:
int main(int argc, char **argv) {
 int fd;
    char c;
    char key;
    char *ar_name = ((void *)0);
    while ((c = getopt (argc, argv, "qxtvdAw")) != -1)
        switch (c) {
            case 'q':
                key = 'q';
                break;
            case 'x':
                key = 'x';
                break;
            case 't':
                key = 't';
                break;
            case 'v':
                key = 'v';
                break;
            case 'd':
                key = 'd';
                break;
            case 'A':
                key = 'A';
                break;
            case 'w':
                key = 'w';
                break;
            default:
                usage();
                exit(1);
                break;
        }
    if (!key){
     printf("No option given\n");
     usage();
     exit(-1);
    }
    if (optind < argc) {
        ar_name = (char *)malloc(sizeof(char) * (strlen(argv[optind]) + 1));
        ((void) sizeof ((ar_name != ((void *)0)) ? 1 : 0), __extension__ ({ if (ar_name != ((void *)0)) ; else __assert_fail ("ar_name != NULL", "main.c", 62, __extension__ __PRETTY_FUNCTION__); }));
        strcpy(ar_name, argv[optind]);
        optind = optind + 1;
    }else {
        printf("no archive file given.\n");
        usage();
    }
    fd = open_ar_file(ar_name, key);
    do {
        switch(key) {
            case 'q':
                if (argv[optind] == ((void *)0)) {
                    printf("no file given to append.\n");
                 usage();
                 exit(1);
                }
             append(fd, &(argv[optind]), (argc-optind));
             optind = argc;
                break;
            case 't':
                print_concise(fd);
                break;
            case 'v':
                print_verbose(fd);
                break;
            case 'x':
                extract(fd, argv[optind] ? argv[optind] : ((void *)0));
                break;
            case 'd':
                if (argv[optind] == ((void *)0)) {
                    printf("no file given to delete.\n");
                 usage();
                 exit(1);
                }
             delete(&fd, ar_name, &(argv[optind]), (argc-optind));
             optind = argc;
                break;
            case 'A':
                append_all(fd, ar_name);
                break;
            case 'w':
                break;
        }
        optind++;
    } while (optind < argc);
    if (close(fd) == -1)
        printf("ERROR: %s\n", strerror((*__errno_location ())));
    return(0);
}

variable_types: fd int

variable_types: c char

variable_types: key char


repo: beckysag/prime-finder

decompiled_code:
void __fastcall __noreturn perror_and_exit(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void perror_and_exit(char *msg) {
 perror(msg);
 exit(1);
}

variable_types:
msg
char *


usage

decompiled_code:
int usage()
{
printf("%s %s", "Usage:\n", "primePThread [-qv] [-m max_prime] [-c concurrency]\n\n");
puts("Options:");
printf("%*s%*s\n", 4, "-q", 29, "don't print prime numbers");
printf("%*s%*s\n", 4, "-v", 23, "verbose: print timing and count");
printf("%*s%*s\n", 4, "-m", 36, "maximum size of the prime number");
return printf("%*s%*s\n", 4, "-c", 23, "concurrency to use\n");
}

canonical_decompiled_code:
int func13()
{
printf("%s %s", "Usage:\n", "primePThread [-qv] [-m max_prime] [-c concurrency]\n\n");
puts("Options:");
printf("%*s%*s\n", 4, "-q", 29, "don't print prime numbers");
printf("%*s%*s\n", 4, "-v", 23, "verbose: print timing and count");
printf("%*s%*s\n", 4, "-m", 36, "maximum size of the prime number");
return printf("%*s%*s\n", 4, "-c", 23, "concurrency to use\n");
}

original_code:
void usage() {
 printf("%s  %s", "Usage:\n",
   "primePThread [-qv] [-m max_prime] [-c concurrency]\n\n");
 printf("%s", "Options:\n");
 printf("%*s%*s\n", 4, "-q", 29, "don't print prime numbers");
 printf("%*s%*s\n", 4, "-v", 23, "verbose: print timing and count");
 printf("%*s%*s\n", 4, "-m", 36, "maximum size of the prime number");
 printf("%*s%*s\n", 4, "-c", 23, "concurrency to use\n");
}


decompiled_code:
__int64 __fastcall socket_check_writable(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

memset(&writefds, 0, sizeof(writefds));
v2 = a1 / 64;
v3 = 1LL << (a1 % 64);
writefds.fds_bits[v2] |= v3;
v6.tv_sec = a2 / 1000;
v6.tv_usec = 1000 * (a2 % 1000);
v4 = select(a1 + 1, 0LL, &writefds, 0LL, &v6);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
if ( v4 )
return (unsigned int)-((writefds.fds_bits[v2] & v3) == 0);
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set writefds; // [rsp+10h] [rbp-98h] BYREF

memset(&writefds, 0, sizeof(writefds));
v2 = a1 / 64;
v3 = 1LL << (a1 % 64);
writefds.fds_bits[v2] |= v3;
v6.tv_sec = a2 / 1000;
v6.tv_usec = 1000 * (a2 % 1000);
v4 = select(a1 + 1, 0LL, &writefds, 0LL, &v6);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
if ( v4 )
return (unsigned int)-((writefds.fds_bits[v2] & v3) == 0);
return 4294967294LL;
}

original_code:
static int socket_check_writable(int socket_fd, int ms)
{
        fd_set fdw;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdw)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fdw)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
        struct timeval tv;
        tv.tv_sec = ms / 1000;
        tv.tv_usec = (ms % 1000) * 1000;
        int ret = select(socket_fd + 1, ((void *)0), &fdw, ((void *)0), &tv);
        if (ret < 0) {
                return -1;
        } else if (ret == 0) {
                return -2;
        }
        if (((((&fdw)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                return 0;
        }
        return -1;
}

canonical_original_code:
static int socket_check_writable(int socket_fd, int ms)
{
        struct fd_set fdw;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdw)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fdw)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
        struct timeval tv;
        tv.tv_sec = ms / 1000;
        tv.tv_usec = (ms % 1000) * 1000;
        int ret = select(socket_fd + 1, ((void *)0), &fdw, ((void *)0), &tv);
        if (ret < 0) {
                return -1;
        } else if (ret == 0) {
                return -2;
        }
        if (((((&fdw)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                return 0;
        }
        return -1;
}

variable_types: ms int

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

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

variable_types: ret int


decompiled_code:
__int64 __fastcall socket_check_readable(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
v2 = a1 / 64;
v3 = 1LL << (a1 % 64);
readfds.fds_bits[v2] |= v3;
v6.tv_sec = a2 / 1000;
v6.tv_usec = 1000 * (a2 % 1000);
v4 = select(a1 + 1, &readfds, 0LL, 0LL, &v6);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
if ( v4 )
return (unsigned int)-((readfds.fds_bits[v2] & v3) == 0);
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // eax
struct timeval v6; // [rsp+0h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

memset(&readfds, 0, sizeof(readfds));
v2 = a1 / 64;
v3 = 1LL << (a1 % 64);
readfds.fds_bits[v2] |= v3;
v6.tv_sec = a2 / 1000;
v6.tv_usec = 1000 * (a2 % 1000);
v4 = select(a1 + 1, &readfds, 0LL, 0LL, &v6);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
if ( v4 )
return (unsigned int)-((readfds.fds_bits[v2] & v3) == 0);
return 4294967294LL;
}

original_code:
static int socket_check_readable(int socket_fd, int ms)
{
        fd_set fdr;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdr)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fdr)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
        struct timeval tv;
        tv.tv_sec = ms / 1000;
        tv.tv_usec = (ms % 1000) * 1000;
        int ret = select(socket_fd + 1, &fdr, ((void *)0), ((void *)0), &tv);
        if (ret < 0) {
                return -1;
        } else if (ret == 0) {
                return -2;
        }
        if (((((&fdr)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                return 0;
        }
        return -1;
}

canonical_original_code:
static int socket_check_readable(int socket_fd, int ms)
{
        struct fd_set fdr;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdr)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fdr)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
        struct timeval tv;
        tv.tv_sec = ms / 1000;
        tv.tv_usec = (ms % 1000) * 1000;
        int ret = select(socket_fd + 1, &fdr, ((void *)0), ((void *)0), &tv);
        if (ret < 0) {
                return -1;
        } else if (ret == 0) {
                return -2;
        }
        if (((((&fdr)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                return 0;
        }
        return -1;
}

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

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


decompiled_code:
int socket_create_tcp()
{
return socket(2, 1, 6);
}

canonical_decompiled_code:
int func3()
{
return socket(2, 1, 6);
}

original_code:
int socket_create_tcp(void)
{
        int socket_fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
        return socket_fd;
}

canonical_original_code:
int socket_create_tcp()
{
        int socket_fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
        return socket_fd;
}


decompiled_code:
int __fastcall socket_set_nonblock(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

canonical_decompiled_code:
int __fastcall func4(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

original_code:
void socket_set_nonblock(int socket_fd)
{
        int flags = fcntl(socket_fd, 3);
        flags |= 04000;
        fcntl(socket_fd, 4, flags);
}

variable_types: flags int


decompiled_code:
int __fastcall socket_set_block(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) &= 0xF7u;
return fcntl(fd, 4, v1);
}

canonical_decompiled_code:
int __fastcall func5(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3);
BYTE1(v1) &= 0xF7u;
return fcntl(fd, 4, v1);
}

original_code:
void socket_set_block(int socket_fd)
{
        int flags = fcntl(socket_fd, 3);
        flags &= ~04000;
        fcntl(socket_fd, 4, flags);
}


decompiled_code:
int __fastcall socket_connect(int fd, char *cp, __int16 a3)
{
int result; // eax
int optval; // [rsp+0h] [rbp-20h] BYREF
socklen_t optlen; // [rsp+4h] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+8h] [rbp-18h] BYREF

addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a3);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
result = connect(fd, &addr, 0x10u);
if ( result )
{
if ( (unsigned int)(*_errno_location() - 114) > 1 )
{
usleep(0x186A0u);
result = -1;
}
else
{
usleep(0x186A0u);
if ( (unsigned int)socket_check_writable(fd, 2000) )
{
result = -1;
}
else
{
optval = 0;
optlen = 4;
getsockopt(fd, 1, 4, &optval, &optlen);
result = -(optval != 0);
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int fd, char *cp, __int16 a3)
{
int result; // eax
int optval; // [rsp+0h] [rbp-20h] BYREF
socklen_t optlen; // [rsp+4h] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+8h] [rbp-18h] BYREF

addr = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(a3);
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
result = connect(fd, &addr, 0x10u);
if ( result )
{
if ( (unsigned int)(*_errno_location() - 114) > 1 )
{
usleep(0x186A0u);
result = -1;
}
else
{
usleep(0x186A0u);
if ( (unsigned int)func1(fd, 2000) )
{
result = -1;
}
else
{
optval = 0;
optlen = 4;
getsockopt(fd, 1, 4, &optval, &optlen);
result = -(optval != 0);
}
}
}
return result;
}

original_code:
int socket_connect(int socket_fd, char *dest_addr, int dest_port)
{
        struct sockaddr_in sin;
        bzero(&sin, sizeof(sin));
        sin.sin_family = 2;
        sin.sin_port = htons((u_short)dest_port);
        sin.sin_addr.s_addr = inet_addr(dest_addr);
        if (connect(socket_fd, (struct sockaddr *)&sin, sizeof(sin)) == 0) {
                return 0;
        }
        switch ((*__errno_location ())) {
        case 115:
        case 114:
                usleep(100000);
                break;
        default:
                usleep(100000);
                return -1;
        }
        int connect_timeout = 2000;
        if (socket_check_writable(socket_fd, connect_timeout)) {
                return -1;
        }
        int error = 0;
        socklen_t len = sizeof(error);
        getsockopt(socket_fd, 1, 4, &error, &len);
        if (error == 0) {
                return 0;
        }
        return -1;
}

canonical_original_code:
int socket_connect(int socket_fd, char *dest_addr, int dest_port)
{
        struct sockaddr_in sin;
        bzero(&sin, sizeof(sin));
        sin.sin_family = 2;
        sin.sin_port = htons((unsigned short)dest_port);
        sin.sin_addr.s_addr = inet_addr(dest_addr);
        if (connect(socket_fd, (struct sockaddr *)&sin, sizeof(sin)) == 0) {
                return 0;
        }
        switch ((*__errno_location ())) {
        case 115:
        case 114:
                usleep(100000);
                break;
        default:
                usleep(100000);
                return -1;
        }
        int connect_timeout = 2000;
        if (socket_check_writable(socket_fd, connect_timeout)) {
                return -1;
        }
        int error = 0;
        unsigned int len = sizeof(error);
        getsockopt(socket_fd, 1, 4, &error, &len);
        if (error == 0) {
                return 0;
        }
        return -1;
}

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

variable_types: error int

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall socket_write(int fd, __int64 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // eax

if ( a3 <= 0 )
return 0LL;
v6 = 0;
while ( 1 )
{
result = socket_check_writable(fd, a4);
if ( (_DWORD)result )
break;
v8 = send(fd, (const void *)(a2 + v6), a3 - v6, 0);
if ( (unsigned int)(v8 + 1) <= 1 )
return 0xFFFFFFFFLL;
v6 += v8;
if ( a3 <= v6 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, __int64 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // eax

if ( a3 <= 0 )
return 0LL;
v6 = 0;
while ( 1 )
{
result = func1(fd, a4);
if ( (_DWORD)result )
break;
v8 = send(fd, (const void *)(a2 + v6), a3 - v6, 0);
if ( (unsigned int)(v8 + 1) <= 1 )
return 0xFFFFFFFFLL;
v6 += v8;
if ( a3 <= v6 )
return 0LL;
}
return result;
}

original_code:
int socket_write(int socket_fd, char *buf, int length, int ms)
{
        int sent_len = 0;
        int n = 0;
        int ret = 0;
        while (sent_len < length) {
                ret = socket_check_writable(socket_fd, ms);
                if (ret != 0) {
                        return ret;
                }
                n = send(socket_fd, buf + sent_len,
                                length - sent_len, 0);
                if (n == -1) {
                        return -1;
                } else if (n == 0) {
                        return -1;
                }
                sent_len += n;
        }
        return 0;
}

variable_types:
buf
char *

variable_types: length int

variable_types: n int


decompiled_code:
__int64 __fastcall socket_readn(int fd, void *buf, int a3, int a4)
{
__int64 result; // rax

result = socket_check_readable(fd, a4);
if ( !(_DWORD)result )
result = recv(fd, buf, a3, 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, void *buf, int a3, int a4)
{
__int64 result; // rax

result = func2(fd, a4);
if ( !(_DWORD)result )
result = recv(fd, buf, a3, 0);
return result;
}

original_code:
int socket_readn(int socket_fd, char *buf, int max_length, int ms)
{
        int length = 0;
        int ret = 0;
        ret = socket_check_readable(socket_fd, ms);
        if (ret == 0) {
                length = recv(socket_fd, buf, max_length, 0);
        } else {
                return ret;
        }
        return length;
}


decompiled_code:
__int64 __fastcall socket_read(int fd, __int64 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // eax

if ( a3 <= 0 )
return 0LL;
v6 = 0;
while ( 1 )
{
result = socket_check_readable(fd, a4);
if ( (_DWORD)result )
break;
v8 = recv(fd, (void *)(a2 + v6), a3 - v6, 0);
if ( (unsigned int)(v8 + 1) <= 1 )
return 0xFFFFFFFFLL;
v6 += v8;
if ( a3 <= v6 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, __int64 a2, int a3, int a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // eax

if ( a3 <= 0 )
return 0LL;
v6 = 0;
while ( 1 )
{
result = func2(fd, a4);
if ( (_DWORD)result )
break;
v8 = recv(fd, (void *)(a2 + v6), a3 - v6, 0);
if ( (unsigned int)(v8 + 1) <= 1 )
return 0xFFFFFFFFLL;
v6 += v8;
if ( a3 <= v6 )
return 0LL;
}
return result;
}

original_code:
int socket_read(int socket_fd, char *buf, int req_length, int ms)
{
        char *ptr = (char *)buf;
        int rLen = 0;
        int n = 0;
        int ret = 0;
        while (rLen < req_length) {
                ret = socket_check_readable(socket_fd, ms);
                if (ret == 0) {
                        n = recv(socket_fd, ptr + rLen, req_length - rLen, 0);
                        if (n == -1) {
                                ret = -1;
                                break;
                        } else if (n == 0) {
                                ret = -1;
                                break;
                        }
                        rLen += n;
                } else {
                        break;
                }
        }
        return ret;
}

variable_types:
ptr
char *

variable_types: rLen int


decompiled_code:
__int64 __fastcall socket_clear_recv_buffer(int fd)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF

do
result = socket_read(fd, (__int64)&v2, 256, 0);
while ( (unsigned int)result < 0xFFFFFFFE );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF

do
result = func9(fd, (__int64)&v2, 256, 0);
while ( (unsigned int)result < 0xFFFFFFFE );
return result;
}

original_code:
void socket_clear_recv_buffer(int socket_fd)
{
        int ret = 0;
        int buf_size = 256;
        char buf[buf_size];
        while (1) {
                ret = socket_read(socket_fd, buf, buf_size, 0);
                if ((ret == -2)
                        || (ret == -1)) {
                        break;
                }
        }
}

canonical_original_code:
void socket_clear_recv_buffer(int socket_fd)
{
        int ret = 0;
        int buf_size = 256;
        char buf[-1];
        while (1) {
                ret = socket_read(socket_fd, buf, buf_size, 0);
                if ((ret == -2)
                        || (ret == -1)) {
                        break;
                }
        }
}

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall socket_close(int fd)
{
if ( fd )
{
shutdown(fd, 2);
close(fd);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd)
{
if ( fd )
{
shutdown(fd, 2);
close(fd);
}
return 0LL;
}

original_code:
int socket_close(int socket_fd)
{
        if (socket_fd) {
                shutdown(socket_fd, SHUT_RDWR);
                close(socket_fd);
        }
        return 0;
}


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

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

original_code:
static int ftp_put_file_port()
{
        return 0;
}


decompiled_code:
int __fastcall ftp_get_response(__int64 a1)
{
char dest[4]; // [rsp+Ch] [rbp-Ch] BYREF

memset(response, 0, sizeof(response));
*(_DWORD *)dest = 0;
if ( (int)socket_readn(*(unsigned int *)(a1 + 132), response, 256LL, 2000LL) <= 0 )
return -1;
strncpy(dest, response, 3uLL);
socket_clear_recv_buffer(*(unsigned int *)(a1 + 132));
return atoi(dest);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
char dest[4]; // [rsp+Ch] [rbp-Ch] BYREF

memset(response, 0, sizeof(response));
*(_DWORD *)dest = 0;
if ( (int)socket_readn(*(unsigned int *)(a1 + 132), response, 256LL, 2000LL) <= 0 )
return -1;
strncpy(dest, response, 3uLL);
socket_clear_recv_buffer(*(unsigned int *)(a1 + 132));
return atoi(dest);
}

original_code:
static int ftp_get_response(struct ftp_connect *ftp_client)
{
        char response_code[4] = {0};
        memset(response, 0, sizeof(response));
        int len = socket_readn(ftp_client->control_fd, response,
                                256, kSocketTimeout);
        if (len <= 0) {
                return -1;
        }
        strncpy(response_code, response, 3);
        socket_clear_recv_buffer(ftp_client->control_fd);
        return atoi(response_code);
}

variable_types: struct ftp_connect { char hostname[64]; char username[32]; char password[32]; unsigned short control_port; int control_fd; int data_fd; int mode; } *

variable_types: len int


decompiled_code:
__int64 __fastcall ftp_send_cmd(int a1, const char *a2, __int64 a3)
{
__int64 v4; // rbx
const char *v5; // rdx
size_t v6; // rax
unsigned int v7; // er12
int v8; // eax
char v10[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = 16LL * a1;
v5 = *(const char **)((char *)ftp_cmd + v4);
if ( a2 )
sprintf(v10, "%s %s\r\n", v5, a2);
else
sprintf(v10, "%s\r\n", v5);
v6 = strlen(v10);
v7 = socket_write(*(unsigned int *)(a3 + 132), v10, v6, 2000LL);
if ( v7 || (v8 = ftp_get_response(a3), *(_DWORD *)((char *)ftp_cmd + v4 + 8) != v8) && (v7 = -2, v8 != 421) )
v7 = -1;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const char *a2, __int64 a3)
{
__int64 v4; // rbx
const char *v5; // rdx
size_t v6; // rax
unsigned int v7; // er12
int v8; // eax
char v10[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = 16LL * a1;
v5 = *(const char **)((char *)ftp_cmd + v4);
if ( a2 )
sprintf(v10, "%s %s\r\n", v5, a2);
else
sprintf(v10, "%s\r\n", v5);
v6 = strlen(v10);
v7 = socket_write(*(unsigned int *)(a3 + 132), v10, v6, 2000LL);
if ( v7 || (v8 = func1(a3), *(_DWORD *)((char *)ftp_cmd + v4 + 8) != v8) && (v7 = -2, v8 != 421) )
v7 = -1;
return v7;
}

original_code:
static int ftp_send_cmd(int index,
                        char *append_info,
                        struct ftp_connect *ftp_client)
{
        char cmd[256];
        if (append_info) {
                sprintf(cmd, "%s %s\r\n", ftp_cmd[index].cmd, append_info);
        } else {
                sprintf(cmd, "%s\r\n", ftp_cmd[index].cmd);
        }
        int ret = socket_write(ftp_client->control_fd, cmd,
                                        strlen(cmd), kSocketTimeout);
        if (ret != 0) {
                return -1;
        }
        int response_code = ftp_get_response(ftp_client);
        if (response_code == ftp_cmd[index].response_code) {
                return 0;
        }
        if (response_code == RES_SERVER_DOWN) {
                return -2;
        }
        return -1;
}

variable_types: index int

variable_types:
cmd
char [256]

user_defined_types: struct ftp_connect { char hostname[64]; char username[32]; char password[32]; unsigned short control_port; int control_fd; int data_fd; int mode; }


decompiled_code:
__int64 __fastcall ftp_mkdir(__int64 a1, const char *a2)
{
return ftp_send_cmd(4, a2, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
return func2(4, a2, a1);
}

original_code:
static int ftp_mkdir(struct ftp_connect *client, char *path)
{
        return ftp_send_cmd(Mkdir, path, client);
}

variable_types:
path
char *


decompiled_code:
__int64 __fastcall ftp_cwd(__int64 a1, const char *a2)
{
return ftp_send_cmd(5, a2, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
return func2(5, a2, a1);
}

original_code:
static int ftp_cwd(struct ftp_connect *client, char *path)
{
        return ftp_send_cmd(ChangeDir, path, client);
}


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

result = ftp_cwd(a1, a2);
if ( (((_DWORD)result + 2) & 0xFFFFFFFD) != 0 )
{
result = ftp_mkdir(a1, a2);
if ( (unsigned int)(result + 2) > 1 )
result = ftp_cwd(a1, a2);
}
return result;
}

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

result = func4(a1, a2);
if ( (((_DWORD)result + 2) & 0xFFFFFFFD) != 0 )
{
result = func3(a1, a2);
if ( (unsigned int)(result + 2) > 1 )
result = func4(a1, a2);
}
return result;
}

original_code:
static int ftp_enter_dir(struct ftp_connect *client, char *path)
{
        int ret = 0;
        do {
                ret = ftp_cwd(client, path);
                if (ret == 0 ||
                        ret == -2) {
                        break;
                }
                ret = ftp_mkdir(client, path);
                if (ret == -1 ||
                        ret == -2) {
                        break;
                }
                ret = ftp_cwd(client, path);
                if (ret == 0 ||
                        ret == -2) {
                        break;
                }
        } while(0);
        return ret;
}

variable_types: ret int


original_code:
static int ftp_change_dir(struct ftp_connect *client, char *absolute_path)
{
        int ret = 0;
        char path[32];
        char *p = absolute_path;
        if (*p == '/') {
                ++p;
        }
        ret = ftp_enter_dir(client, "/");
        if (ret != 0) {
                return ret;
        }
        int index = 0;
        while (1) {
                index = 0;
                memset(path, 0, sizeof(path));
                while ((*p != '/') && (*p != '\0')) {
                        path[index] = *p;
                        ++index;
                        ++p;
                }
                path[index] = '\0';
                if (path[0] != '\0') {
                        ret = ftp_enter_dir(client, path);
                        if (ret != 0) {
                                break;
                        }
                }
                if (*p == '\0') {
                        break;
                }
                ++p;
        }
        return ret;
}

variable_types:
path
char [32]

variable_types:
p
char *


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

result = ftp_send_cmd(0, (const char *)(a1 + 64), a1);
if ( !(_DWORD)result )
result = ftp_send_cmd(1, (const char *)(a1 + 96), a1);
return result;
}

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

result = func2(0, (const char *)(a1 + 64), a1);
if ( !(_DWORD)result )
result = func2(1, (const char *)(a1 + 96), a1);
return result;
}

original_code:
static int ftp_login(struct ftp_connect *client)
{
        int ret = ftp_send_cmd(Username, client->username, client);
        if (ret == 0) {
                ret = ftp_send_cmd(Password, client->password, client);
        }
        return ret;
}