original_code:
int test_fuse_mount ()
{
 int fd, ret;
 char source[100] = "/tmp/image_mount";
 char mountpoint[100] = "/mnt/test2";
 char fstype[30] = "fuse.glusterfs";
 char mnt_param_mnt[1024];
 fd = open ("/dev/fuse", 02);
 if (fd == -1) {
  printf ("cannot open /dev/fuse errno:%d, errstr:%s\n", (*__errno_location ()), strerror ((*__errno_location ())));
  return -1;
 }
 sprintf (mnt_param_mnt,
   "allow_other,default_permissions,max_read=131072,fd=%i,rootmode=%o,user_id=%i,group_id=%i",
   fd, 0040000, getuid (), getgid ());
 ret = mount (source, mountpoint, fstype, 0, mnt_param_mnt);
 if (ret) {
  printf ("cannot mount errno:%d, errstr:%s\n", (*__errno_location ()), strerror ((*__errno_location ())));
  close (fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int test_fuse_mount()
{
 int fd; int ret;
 char source[100] = "/tmp/image_mount";
 char mountpoint[100] = "/mnt/test2";
 char fstype[30] = "fuse.glusterfs";
 char mnt_param_mnt[1024];
 fd = open ("/dev/fuse", 02);
 if (fd == -1) {
  printf ("cannot open /dev/fuse errno:%d, errstr:%s\n", (*__errno_location ()), strerror ((*__errno_location ())));
  return -1;
 }
 sprintf (mnt_param_mnt,
   "allow_other,default_permissions,max_read=131072,fd=%i,rootmode=%o,user_id=%i,group_id=%i",
   fd, 0040000, getuid (), getgid ());
 ret = mount (source, mountpoint, fstype, 0, mnt_param_mnt);
 if (ret) {
  printf ("cannot mount errno:%d, errstr:%s\n", (*__errno_location ()), strerror ((*__errno_location ())));
  close (fd);
  return -1;
 }
 return fd;
}

variable_types:
source
char [100]

variable_types:
mountpoint
char [100]

variable_types:
fstype
char [30]


decompiled_code:
__int64 __fastcall test_fuse_cntl(int fd)
{
int v1; // er12
int v2; // eax
_DWORD *v3; // rbx
unsigned int *v4; // rbp
struct iovec v6; // [rsp+0h] [rbp-48h] BYREF
unsigned int *v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]

v6.iov_len = 40LL;
v6.iov_base = calloc(1uLL, 0x28uLL);
v8 = 1024LL;
v7 = (unsigned int *)calloc(1uLL, 0x400uLL);
v1 = 100;
do
{
v2 = readv(fd, &v6, 2);
if ( v2 <= 0 )
{
puts("read nothing");
}
else
{
printf("readv recieve %d bytes\n", (unsigned int)v2);
v3 = v6.iov_base;
v4 = v7;
printf(
"len:%d,opcode:%d,unique:%d,nodeid:%d,uid:%d,gid:%d,pid:%d,padding:%d\n",
*(unsigned int *)v6.iov_base,
*((unsigned int *)v6.iov_base + 1),
*((_QWORD *)v6.iov_base + 1),
*((_QWORD *)v6.iov_base + 2),
*((unsigned int *)v6.iov_base + 6),
*((unsigned int *)v6.iov_base + 7),
*((unsigned int *)v6.iov_base + 8),
*((unsigned int *)v6.iov_base + 9));
printf("major:%d,minor:%d,max_readahead:%d,flags:%d\n", *v4, v4[1], v4[2], v4[3]);
if ( v3[1] == 26 )
test_fuse_init(fd, (__int64)v3, (int *)v4);
else
puts("can not recogonise thie op");
}
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd)
{
int v1; // er12
int v2; // eax
_DWORD *v3; // rbx
unsigned int *v4; // rbp
struct iovec v6; // [rsp+0h] [rbp-48h] BYREF
unsigned int *v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]

v6.iov_len = 40LL;
v6.iov_base = calloc(1uLL, 0x28uLL);
v8 = 1024LL;
v7 = (unsigned int *)calloc(1uLL, 0x400uLL);
v1 = 100;
do
{
v2 = readv(fd, &v6, 2);
if ( v2 <= 0 )
{
puts("read nothing");
}
else
{
printf("readv recieve %d bytes\n", (unsigned int)v2);
v3 = v6.iov_base;
v4 = v7;
printf(
"len:%d,opcode:%d,unique:%d,nodeid:%d,uid:%d,gid:%d,pid:%d,padding:%d\n",
*(unsigned int *)v6.iov_base,
*((unsigned int *)v6.iov_base + 1),
*((_QWORD *)v6.iov_base + 1),
*((_QWORD *)v6.iov_base + 2),
*((unsigned int *)v6.iov_base + 6),
*((unsigned int *)v6.iov_base + 7),
*((unsigned int *)v6.iov_base + 8),
*((unsigned int *)v6.iov_base + 9));
printf("major:%d,minor:%d,max_readahead:%d,flags:%d\n", *v4, v4[1], v4[2], v4[3]);
if ( v3[1] == 26 )
func7(fd, (__int64)v3, (int *)v4);
else
puts("can not recogonise thie op");
}
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
int test_fuse_cntl (int fd)
{
 int i, ret;
 struct iovec iov[2];
 struct fuse_in_header *finh;
 struct fuse_init_in *fini;
 iov[0].iov_len = sizeof(*finh);
 iov[0].iov_base = calloc(1, sizeof(*finh));
 iov[1].iov_len = 1024;
 iov[1].iov_base = calloc(1, 1024);
 i = 100;
 while (i) {
  ret = readv (fd, iov, 2);
  if (ret > 0) {
   printf("readv recieve %d bytes\n", ret);
   finh = (struct fuse_in_header *) iov[0].iov_base;
   fini = (struct fuse_init_in *) iov[1].iov_base;
   printf("len:%d,opcode:%d,unique:%d,nodeid:%d,uid:%d,gid:%d,pid:%d,padding:%d\n",
    finh->len,
    finh->opcode,
    finh->unique,
    finh->nodeid,
    finh->uid,
    finh->gid,
    finh->pid,
    finh->padding);
   printf("major:%d,minor:%d,max_readahead:%d,flags:%d\n",
    fini->major,
    fini->minor,
    fini->max_readahead,
    fini->flags);
   if (finh->opcode == 26)
    fuse_ops[0] (fd, finh, fini);
   else
    printf("can not recogonise thie op\n");
  }
  else
   printf("read nothing\n");
  i--;
 }
 return 0;
}

canonical_original_code:
int test_fuse_cntl(int fd)
{
 int i; int ret;
 struct iovec iov[2];
 struct fuse_in_header *finh;
 struct fuse_init_in *fini;
 iov[0].iov_len = sizeof(*finh);
 iov[0].iov_base = calloc(1, sizeof(*finh));
 iov[1].iov_len = 1024;
 iov[1].iov_base = calloc(1, 1024);
 i = 100;
 while (i) {
  ret = readv (fd, iov, 2);
  if (ret > 0) {
   printf("readv recieve %d bytes\n", ret);
   finh = (struct fuse_in_header *) iov[0].iov_base;
   fini = (struct fuse_init_in *) iov[1].iov_base;
   printf("len:%d,opcode:%d,unique:%d,nodeid:%d,uid:%d,gid:%d,pid:%d,padding:%d\n",
    finh->len,
    finh->opcode,
    finh->unique,
    finh->nodeid,
    finh->uid,
    finh->gid,
    finh->pid,
    finh->padding);
   printf("major:%d,minor:%d,max_readahead:%d,flags:%d\n",
    fini->major,
    fini->minor,
    fini->max_readahead,
    fini->flags);
   if (finh->opcode == 26)
    fuse_ops[0] (fd, finh, fini);
   else
    printf("can not recogonise thie op\n");
  }
  else
   printf("read nothing\n");
  i--;
 }
 return 0;
}

variable_types: fd int

variable_types: i int

variable_types: ret int

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [2]

variable_types: struct fuse_in_header { unsigned int len; unsigned int opcode; unsigned long unique; unsigned long nodeid; unsigned int uid; unsigned int gid; unsigned int pid; unsigned int padding; } *

variable_types: struct fuse_init_in { unsigned int major; unsigned int minor; unsigned int max_readahead; unsigned int flags; } *

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int result; // eax
int *v6; // rax

v3 = test_fuse_mount(argc, argv, envp);
if ( v3 < 0 )
{
v6 = __errno_location();
printf("error ocoured. %d\n", (unsigned int)*v6);
result = -1;
}
else
{
v4 = v3;
test_fuse_cntl(v3);
close(v4);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int result; // eax
int *v6; // rax

v3 = func8(argc, argv, envp);
if ( v3 < 0 )
{
v6 = __errno_location();
printf("error ocoured. %d\n", (unsigned int)*v6);
result = -1;
}
else
{
v4 = v3;
func9(v3);
close(v4);
result = 0;
}
return result;
}

original_code:
int main (int argc, char *argv[])
{
 int fd;
 fd = test_fuse_mount ();
 if (fd < 0) {
  printf ("error ocoured. %d\n", (*__errno_location ()));
  return -1;
 }
 test_fuse_cntl (fd);
 close (fd);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd;
 fd = test_fuse_mount ();
 if (fd < 0) {
  printf ("error ocoured. %d\n", (*__errno_location ()));
  return -1;
 }
 test_fuse_cntl (fd);
 close (fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


original_code:
void *
mempool_alloc(struct mempool *pool)
{
 int i;
 while(1) {
  if ((((struct mem_status *)((pool->mempod[pool->cursor])-sizeof(struct mem_status)))->status) == MEM_IDLE) {
   i = pool->cursor;
   pool->cursor++;
   pool->cursor %= pool->count;
   break;
  }
  pool->cursor++;
  pool->cursor %= pool->count;
 }
 (((struct mem_status *)((pool->mempod[i])-sizeof(struct mem_status)))->status = MEM_USED);
 return pool->mempod[i];
}

canonical_original_code:
void *mempool_alloc(struct mempool *pool)
{
 int i;
 while(1) {
  if ((((struct mem_status *)((pool->mempod[pool->cursor])-sizeof(struct mem_status)))->status) == MEM_IDLE) {
   i = pool->cursor;
   pool->cursor++;
   pool->cursor %= pool->count;
   break;
  }
  pool->cursor++;
  pool->cursor %= pool->count;
 }
 (((struct mem_status *)((pool->mempod[i])-sizeof(struct mem_status)))->status = MEM_USED);
 return pool->mempod[i];
}

variable_types: struct mempool { char *name; int size; int count; int cursor; void **mempod; } *

return_type: void *


decompiled_code:
void __fastcall mempool_free(__int64 a1)
{
*(_DWORD *)(a1 - 4) = 1;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
*(_DWORD *)(a1 - 4) = 1;
}

original_code:
void
mempool_free(void *ptr)
{
 (((struct mem_status *)((ptr)-sizeof(struct mem_status)))->status = MEM_IDLE);
}

variable_types:
ptr
void *

return_type: void


decompiled_code:
int __fastcall show_parent(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
result = printf("son[%d] score=%d\n", (unsigned int)v1, *(unsigned int *)(*(_QWORD *)a1 + 4 * v1));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
result = printf("son[%d] score=%d\n", (unsigned int)v1, *(unsigned int *)(*(_QWORD *)a1 + 4 * v1));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return result;
}

original_code:
void show_parent(struct parent *p)
{
 int i;
 for (i=0; i<p->count; i++) {
  printf("son[%d] score=%d\n", i, p->son[i].score);
 }
}

variable_types: struct parent { struct son { int score; } *son; int count; } *

user_defined_types: struct parent { struct son *son; int count; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = 0LL;
v4[1] = 10LL;
init_parent((__int64)v4);
show_parent((__int64)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = 0LL;
v4[1] = 10LL;
init_parent((__int64)v4);
func7((__int64)v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 struct parent p = {.count=10};
 init_parent(&p);
 show_parent(&p);
 return 0;
}

variable_types: struct parent { struct son { int score; } *son; int count; }


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

result = *(_QWORD *)(a1 + 24) + *(unsigned __int16 *)(a1 + 40);
*(_QWORD *)(a1 + 48) = result;
return result;
}

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

result = *(_QWORD *)(a1 + 24) + *(unsigned __int16 *)(a1 + 40);
*(_QWORD *)(a1 + 48) = result;
return result;
}

original_code:
static inline void
uskb_set_network_header(struct usk_buff *uskb)
{
 uskb->network_header = uskb->header + uskb->header_len;
}

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

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 sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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 uskb_set_transport_header(__int64 a1)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 48) + *(unsigned __int16 *)(a1 + 40);
*(_QWORD *)(a1 + 56) = result;
return result;
}

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

result = *(_QWORD *)(a1 + 48) + *(unsigned __int16 *)(a1 + 40);
*(_QWORD *)(a1 + 56) = result;
return result;
}

original_code:
static inline void
uskb_set_transport_header(struct usk_buff *uskb)
{
 uskb->transport_header = uskb->network_header + uskb->header_len;
}

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 __fastcall uskb_header_grow(__int64 a1, int a2)
{
unsigned __int16 v2; // ax

v2 = *(_WORD *)(a1 + 40);
if ( a2 + v2 > *(unsigned __int16 *)(a1 + 44) )
return 0xFFFFFFFFLL;
*(_WORD *)(a1 + 40) = v2 + a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned __int16 v2; // ax

v2 = *(_WORD *)(a1 + 40);
if ( a2 + v2 > *(unsigned __int16 *)(a1 + 44) )
return 0xFFFFFFFFLL;
*(_WORD *)(a1 + 40) = v2 + a2;
return 0LL;
}

original_code:
static inline int
uskb_header_grow(struct usk_buff *uskb, const int len)
{
 if ((uskb->header_len + len) > uskb->header_max)
  return -1;
 uskb->header_len += len;
 return 0;
}

canonical_original_code:
static inline int uskb_header_grow(struct usk_buff *uskb, int len)
{
 if ((uskb->header_len + len) > uskb->header_max)
  return -1;
 uskb->header_len += len;
 return 0;
}

variable_types: len int


ureceiver

decompiled_code:
__int64 __fastcall ureceiver(__int64 a1)
{
_DWORD *v1; // rbx
int v2; // eax
int v3; // er13
int v4; // er12
int *v5; // r12
char *v6; // rax
int *v7; // r12
char *v8; // rax
int *v10; // rbx
char *v11; // rax
__int64 v12; // rbx
void *v13; // rbp
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = malloc(4uLL);
v2 = socket(2, 3, 6);
if ( v2 < 0 )
{
printf("Can not create socket!");
v7 = _errno_location();
v8 = strerror(*v7);
printf(" errno:%d(%s)\n", (unsigned int)*v7, v8);
*v1 = -1;
}
else
{
v3 = v2;
optval[0] = 1;
v4 = 0;
if ( setsockopt(v2, 0, 3, optval, 4u) >= 0 )
{
while ( 1 )
{
printf("rcv %d package\n", (unsigned int)++v4);
v13 = (void *)mempool_alloc(rcv_mempool);
if ( recv(v3, v13, 0x2000uLL, 0) < 0 )
{
printf("Receive error!");
v10 = _errno_location();
v11 = strerror(*v10);
printf(" errno:%d(%s)\n", (unsigned int)*v10, v11);
}
v12 = uskb_alloc_in();
uskb_set_header(v12, (__int64)v13, 0x2000);
_do_rcv(v12);
}
}
printf("Can not set HDRINCL!");
v5 = _errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
*v1 = -1;
}
*(_QWORD *)(a1 + 32) = v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_DWORD *v1; // rbx
int v2; // eax
int v3; // er13
int v4; // er12
int *v5; // r12
char *v6; // rax
int *v7; // r12
char *v8; // rax
int *v10; // rbx
char *v11; // rax
__int64 v12; // rbx
void *v13; // rbp
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = malloc(4uLL);
v2 = socket(2, 3, 6);
if ( v2 < 0 )
{
printf("Can not create socket!");
v7 = _errno_location();
v8 = strerror(*v7);
printf(" errno:%d(%s)\n", (unsigned int)*v7, v8);
*v1 = -1;
}
else
{
v3 = v2;
optval[0] = 1;
v4 = 0;
if ( setsockopt(v2, 0, 3, optval, 4u) >= 0 )
{
while ( 1 )
{
printf("rcv %d package\n", (unsigned int)++v4);
v13 = (void *)mempool_alloc(rcv_mempool);
if ( recv(v3, v13, 0x2000uLL, 0) < 0 )
{
printf("Receive error!");
v10 = _errno_location();
v11 = strerror(*v10);
printf(" errno:%d(%s)\n", (unsigned int)*v10, v11);
}
v12 = uskb_alloc_in();
func3(v12, (__int64)v13, 0x2000);
func4(v12);
}
}
printf("Can not set HDRINCL!");
v5 = _errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
*v1 = -1;
}
*(_QWORD *)(a1 + 32) = v1;
return 0LL;
}

original_code:
void *
ureceiver(void *t)
{
 struct task *rcv_task;
 struct usk_buff *uskb;
 void *buffer;
 int sock_opt;
 int fd;
 int *ret;
 int count = 0;
 rcv_task = ((struct task *)(t));
 ret = malloc(sizeof(int));
 fd = socket (2, SOCK_RAW, IPPROTO_TCP);
 if (fd < 0) {
  do { printf("Can not create socket!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  *ret = -1;
  goto out;
 }
 sock_opt = 1;
 if(setsockopt (fd, IPPROTO_IP, 3, &sock_opt, sizeof (sock_opt)) < 0){
  do { printf("Can not set HDRINCL!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  *ret = -1;
  goto out;
 }
 while (1) {
  count++;
  printf("rcv %d package\n", count);
  buffer = mempool_alloc(rcv_mempool);
  if (recv(fd, buffer, 8192, 0) < 0)
   do { printf("Receive error!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  uskb = uskb_alloc_in();
  uskb_set_header(uskb, buffer, 8192);
  __do_rcv(uskb);
 }
 close(fd);
 *ret = 0;
out:
 ((rcv_task)->ret = (ret));
 return ((void *)0);
}

canonical_original_code:
void *ureceiver(void *t)
{
 struct task *rcv_task;
 struct usk_buff *uskb;
 void *buffer;
 int sock_opt;
 int fd;
 int *ret;
 int count = 0;
 rcv_task = ((struct task *)(t));
 ret = malloc(sizeof(int));
 fd = socket (2, SOCK_RAW, IPPROTO_TCP);
 if (fd < 0) {
  do { printf("Can not create socket!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  *ret = -1;
  goto out;
 }
 sock_opt = 1;
 if(setsockopt (fd, IPPROTO_IP, 3, &sock_opt, sizeof (sock_opt)) < 0){
  do { printf("Can not set HDRINCL!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  *ret = -1;
  goto out;
 }
 while (1) {
  count++;
  printf("rcv %d package\n", count);
  buffer = mempool_alloc(rcv_mempool);
  if (recv(fd, buffer, 8192, 0) < 0)
   do { printf("Receive error!"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0);
  uskb = uskb_alloc_in();
  uskb_set_header(uskb, buffer, 8192);
  __do_rcv(uskb);
 }
 close(fd);
 *ret = 0;
out:
 ((rcv_task)->ret = (ret));
 return ((void *)0);
}

variable_types:
t
void *

variable_types: struct task { unsigned long tid; void *(*rt)(void *t); int status; void *arg; void *ret; } *

variable_types:
buffer
void *

variable_types:
ret
int *

variable_types: count int


decompiled_code:
__int64 ureceiver_start()
{
__int64 v0; // rbx

v0 = task_create(ureceiver);
task_start(v0);
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx

v0 = task_create(ureceiver);
task_start(v0);
return v0;
}

original_code:
struct task *
ureceiver_start(void)
{
 struct task *rcv_task;
 rcv_task = task_create(ureceiver);
 task_start(rcv_task);
 return rcv_task;
}

canonical_original_code:
struct task *ureceiver_start()
{
 struct task *rcv_task;
 rcv_task = task_create(ureceiver);
 task_start(rcv_task);
 return rcv_task;
}

return_type: struct task { unsigned long tid; void *(*rt)(void *t); int status; void *arg; void *ret; } *


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

result = mempool_create("rcv_mempool", 0x2000LL, 12LL);
rcv_mempool = result;
return result;
}

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

result = mempool_create("rcv_mempool", 0x2000LL, 12LL);
rcv_mempool = result;
return result;
}

original_code:
void
ureceiver_init(void)
{
 rcv_mempool = mempool_create("rcv_mempool", 8192, 12);
}

canonical_original_code:
void ureceiver_init()
{
 rcv_mempool = mempool_create("rcv_mempool", 8192, 12);
}


decompiled_code:
void sigchld_handler()
{
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

LODWORD(stat_loc.__uptr) = 99;
wait((__WAIT_STATUS)&stat_loc);
printf("child returned with status %d\n", LODWORD(stat_loc.__uptr));
}

canonical_decompiled_code:
void func7()
{
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

LODWORD(stat_loc.__uptr) = 99;
wait((__WAIT_STATUS)&stat_loc);
printf("child returned with status %d\n", LODWORD(stat_loc.__uptr));
}

original_code:
void sigchld_handler (int signum)
{
 int status = 99;
 wait (&status);
 printf ("child returned with status %d\n", status);
}

canonical_original_code:
void sigchld_handler(int signum)
{
 int status = 99;
 wait (&status);
 printf ("child returned with status %d\n", status);
}

variable_types: signum int

variable_types: status int


main

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

signal(17, (__sighandler_t)sigchld_handler);
v3 = fork();
if ( v3 >= 0 )
{
if ( !v3 )
execv("/usr/bin/gedit", 0LL);
while ( 1 )
sleep(3u);
}
return 1;
}

original_code:
int main (int argc, char *argv[])
{
 pid_t pid;
 signal (17, sigchld_handler);
 pid = fork();
 if (pid < 0)
  return 1;
 else if (pid == 0) {
  execv ("/usr/bin/gedit", ((void *)0));
 }
 while (1)
  sleep (3);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int pid;
 signal (17, sigchld_handler);
 pid = fork();
 if (pid < 0)
  return 1;
 else if (pid == 0) {
  execv ("/usr/bin/gedit", ((void *)0));
 }
 while (1)
  sleep (3);
 return 0;
}

variable_types: pid int


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

v1 = *(_DWORD *)(a1 + 120);
if ( proto_list[v1] )
return 0xFFFFFFFFLL;
proto_list[v1] = a1;
return 0LL;
}

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

v1 = *(_DWORD *)(a1 + 120);
if ( proto_list[v1] )
return 0xFFFFFFFFLL;
proto_list[v1] = a1;
return 0LL;
}

original_code:
int
uprotocol_register(struct uprotocol *proto)
{
 if (proto_list[proto->proto_num])
  return -1;
 proto_list[proto->proto_num] = proto;
 return 0;
}

variable_types: struct uprotocol { void (*close)(struct usock { int usk_mode; struct usk_buff_head { 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 *proto; } *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); } *


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

if ( a1 > 0xA )
result = 0LL;
else
result = proto_list[a1];
return result;
}

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

if ( a1 > 0xA )
result = 0LL;
else
result = proto_list[a1];
return result;
}

original_code:
struct uprotocol *
uprotocol_find(int proto_num)
{
 if (proto_num < 0 || proto_num > 10)
  return ((void *)0);
 return proto_list[proto_num];
}

canonical_original_code:
struct uprotocol *uprotocol_find(int proto_num)
{
 if (proto_num < 0 || proto_num > 10)
  return ((void *)0);
 return proto_list[proto_num];
}

return_type: struct uprotocol { void (*close)(struct usock { int usk_mode; struct usk_buff_head { 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 *proto; } *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); } *


original_code:
int request_analysis(int client_fd,char* buffer,char func[],char arguments[][100]){
 int n=0;
 int i=0;
 int j=0;
 int sock_stat = 0;
 char request[10];
 char tm[20];
 sock_stat = recv(client_fd,buffer,4096,0);
 if(sock_stat<0){
  printf("request_analysis recv package error! \n");
  return -1;
 }
 else if(sock_stat==0){
  return 0;
 }
 while(buffer[n]!=';'){
  request[n] = buffer[n];
  n++;
 }
 request[n+1] = '\0';
 if(strncmp(request,"request",7)==0){
  n++;
  i=0;
  while(buffer[n]!=';'){
   func[i] = buffer[n];
   n++;
   i++;
  }
  func[i] = '\0';
  n++;
  i=0;
  j=0;
  while(buffer[n]!='|'){
   if(buffer[n]==';'){
    arguments[j][i] = '\0';
    i=0;
    j++;
    n++;
   }
   else{
    arguments[j][i] = buffer[n];
    n++;
    i++;
   }
  }
  arguments[j][i] = '\0';
 }
 return sock_stat;
}

canonical_original_code:
int request_analysis(int client_fd, char *buffer, char func[], char arguments[][100]){
 int n = 0;
 int i = 0;
 int j = 0;
 int sock_stat = 0;
 char request[10];
 char tm[20];
 sock_stat = recv(client_fd,buffer,4096,0);
 if(sock_stat<0){
  printf("request_analysis recv package error! \n");
  return -1;
 }
 else if(sock_stat==0){
  return 0;
 }
 while(buffer[n]!=';'){
  request[n] = buffer[n];
  n++;
 }
 request[n+1] = '\0';
 if(strncmp(request,"request",7)==0){
  n++;
  i=0;
  while(buffer[n]!=';'){
   func[i] = buffer[n];
   n++;
   i++;
  }
  func[i] = '\0';
  n++;
  i=0;
  j=0;
  while(buffer[n]!='|'){
   if(buffer[n]==';'){
    arguments[j][i] = '\0';
    i=0;
    j++;
    n++;
   }
   else{
    arguments[j][i] = buffer[n];
    n++;
    i++;
   }
  }
  arguments[j][i] = '\0';
 }
 return sock_stat;
}

variable_types:
buffer
char *

variable_types:
func
char []

variable_types:
arguments
char [][100]

variable_types: n int

variable_types: i int

variable_types: j int

variable_types:
request
char [10]

variable_types:
tm
char [20]


decompiled_code:
__int64 __fastcall init_data_connection(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // eax
struct sockaddr in[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&in[0].sa_family = a1;
*(_QWORD *)&in[0].sa_data[6] = a2;
v2 = socket(2, 1, 0);
*(_WORD *)in[0].sa_data = _bswap_16(30667);
v3 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
printf("%s require data connection at port: %d\n", (const char *)v3, *(unsigned __int16 *)in[0].sa_data);
sleep(1u);
if ( connect(v2, in, 0x10u) == -1 )
{
puts("can not connect to the client ");
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // eax
struct sockaddr in[2]; // [rsp+0h] [rbp-28h] BYREF

*(_QWORD *)&in[0].sa_family = a1;
*(_QWORD *)&in[0].sa_data[6] = a2;
v2 = socket(2, 1, 0);
*(_WORD *)in[0].sa_data = func0(30667);
v3 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&a1 + 4));
printf("%s require data connection at port: %d\n", (const char *)v3, *(unsigned __int16 *)in[0].sa_data);
sleep(1u);
if ( connect(v2, in, 0x10u) == -1 )
{
puts("can not connect to the client ");
v2 = -1;
}
return v2;
}

original_code:
int init_data_connection(struct sockaddr_in client_addr)
{
 int client_recv_fd;
 client_recv_fd = socket(2,SOCK_STREAM,0);
 client_addr.sin_port=htons(30667);
 printf("%s require data connection at port: %d\n",inet_ntoa(client_addr.sin_addr.s_addr),client_addr.sin_port);
 sleep(1);
 if(connect(client_recv_fd,(struct sockaddr *) &client_addr,sizeof(client_addr))==-1){
  printf("can not connect to the client \n");
  return -1;
 }
 return client_recv_fd;
}

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

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


SendFileNames

decompiled_code:
__int64 __fastcall SendFileNames(int fd, void *buf, __int64 a3)
{
size_t v4; // rax
_QWORD *v5; // rbx
unsigned int v6; // er12
size_t v7; // rax
size_t v8; // rax
size_t v10; // rax
size_t v11; // rax
char v12[248]; // [rsp+0h] [rbp-F8h] BYREF

v4 = strlen((const char *)buf);
memset(buf, 0, v4);
v5 = *(_QWORD **)(a3 + 16);
if ( v5 )
{
v6 = 0;
while ( 1 )
{
sprintf(
v12,
"%d<%s<%d/",
(*(_DWORD *)(v5[1] + 24LL) & 0xF000) == 0x4000,
(const char *)(*v5 + 19LL),
*(_QWORD *)(v5[1] + 48LL));
strcat((char *)buf, v12);
v7 = strlen((const char *)buf);
if ( v7 > 0xBFF )
{
v6 += send(fd, buf, v7, 0);
if ( v6 == -1 )
goto LABEL_3;
v8 = strlen((const char *)buf);
memset(buf, 0, v8);
}
v5 = (_QWORD *)v5[2];
if ( !v5 )
goto LABEL_9;
}
}
v6 = 0;
LABEL_9:
if ( *(_BYTE *)buf )
{
v10 = strlen((const char *)buf);
v6 += send(fd, buf, v10, 0);
if ( v6 == -1 )
{
LABEL_3:
puts("send error ");
}
else
{
v11 = strlen((const char *)buf);
memset(buf, 0, v11);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, void *buf, __int64 a3)
{
size_t v4; // rax
_QWORD *v5; // rbx
unsigned int v6; // er12
size_t v7; // rax
size_t v8; // rax
size_t v10; // rax
size_t v11; // rax
char v12[248]; // [rsp+0h] [rbp-F8h] BYREF

v4 = strlen((const char *)buf);
memset(buf, 0, v4);
v5 = *(_QWORD **)(a3 + 16);
if ( v5 )
{
v6 = 0;
while ( 1 )
{
sprintf(
v12,
"%d<%s<%d/",
(*(_DWORD *)(v5[1] + 24LL) & 0xF000) == 0x4000,
(const char *)(*v5 + 19LL),
*(_QWORD *)(v5[1] + 48LL));
strcat((char *)buf, v12);
v7 = strlen((const char *)buf);
if ( v7 > 0xBFF )
{
v6 += send(fd, buf, v7, 0);
if ( v6 == -1 )
goto LABEL_3;
v8 = strlen((const char *)buf);
memset(buf, 0, v8);
}
v5 = (_QWORD *)v5[2];
if ( !v5 )
goto LABEL_9;
}
}
v6 = 0;
LABEL_9:
if ( *(_BYTE *)buf )
{
v10 = strlen((const char *)buf);
v6 += send(fd, buf, v10, 0);
if ( v6 == -1 )
{
LABEL_3:
puts("send error ");
}
else
{
v11 = strlen((const char *)buf);
memset(buf, 0, v11);
}
}
return v6;
}

original_code:
int SendFileNames(int client_data_channel_fd,char * buffer,struct file_list * pfile)
{
 int bytes_send = 0;
 char tem_str[200];
 memset(buffer,'\0',strlen(buffer));
 while(pfile->next_file != ((void *)0)){
  pfile = pfile->next_file;
  sprintf(tem_str,"%d<%s<%d/",((((pfile->file_stat->st_mode)) & 0170000) == (0040000)),pfile->file->d_name,pfile->file_stat->st_size);
  strcat(buffer,tem_str);
  if(strlen(buffer) >= 3072){
   if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
   {
    printf("send error \n");
    return -1;
      }
   memset(buffer,'\0',strlen(buffer));
  }
 }
 if(strlen(buffer)>0){
  if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
  {
   printf("send error \n");
   return -1;
     }
  memset(buffer,'\0',strlen(buffer));
 }
 return bytes_send;
}

canonical_original_code:
int SendFileNames(int client_data_channel_fd, char *buffer, struct file_list *pfile)
{
 int bytes_send = 0;
 char tem_str[200];
 memset(buffer,'\0',strlen(buffer));
 while(pfile->next_file != ((void *)0)){
  pfile = pfile->next_file;
  sprintf(tem_str,"%d<%s<%d/",((((pfile->file_stat->st_mode)) & 0170000) == (0040000)),pfile->file->d_name,pfile->file_stat->st_size);
  strcat(buffer,tem_str);
  if(strlen(buffer) >= 3072){
   if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
   {
    printf("send error \n");
    return -1;
      }
   memset(buffer,'\0',strlen(buffer));
  }
 }
 if(strlen(buffer)>0){
  if((bytes_send += send(client_data_channel_fd,buffer,strlen(buffer),0)) == -1)
  {
   printf("send error \n");
   return -1;
     }
  memset(buffer,'\0',strlen(buffer));
 }
 return bytes_send;
}

variable_types: struct file_list { struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *file; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *file_stat; struct file_list *next_file; } *

user_defined_types: struct file_list { struct dirent *file; struct stat *file_stat; struct file_list *next_file; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


GetDirContent

decompiled_code:
__int64 __fastcall GetDirContent(int fd, void *buf, const char *a3, __int64 a4, __int64 a5)
{
_QWORD *v7; // rax
void *v8; // rbp
int v9; // er12
unsigned int v10; // eax
unsigned int v11; // ebx
char v13[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v13, "%s%s", root_directory, a3);
v7 = get_file_list(v13);
if ( v7 )
{
v8 = v7;
strcpy((char *)buf, "ack;rcvdircontent|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
v9 = init_data_connection(a4, a5);
v10 = SendFileNames(v9, buf, (__int64)v8);
v11 = v10;
if ( v10 == -1 )
{
puts("SendFileNames send package failed!");
free_file_list(v8);
}
else
{
printf("%d bytes sended \n", v10);
close(v9);
free_file_list(v8);
v11 = 1;
}
}
else
{
strcpy((char *)buf, "error;1001|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
v11 = -1;
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, const char *a3, __int64 a4, __int64 a5)
{
_QWORD *v7; // rax
void *v8; // rbp
int v9; // er12
unsigned int v10; // eax
unsigned int v11; // ebx
char v13[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v13, "%s%s", root_directory, a3);
v7 = get_file_list(v13);
if ( v7 )
{
v8 = v7;
strcpy((char *)buf, "ack;rcvdircontent|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
v9 = func2(a4, a5);
v10 = func4(v9, buf, (__int64)v8);
v11 = v10;
if ( v10 == -1 )
{
puts("SendFileNames send package failed!");
func3(v8);
}
else
{
printf("%d bytes sended \n", v10);
close(v9);
func3(v8);
v11 = 1;
}
}
else
{
strcpy((char *)buf, "error;1001|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
v11 = -1;
}
return v11;
}

original_code:
int GetDirContent(int client_fd,char* buffer,char* directory,struct sockaddr_in client_addr)
{
 int bytes_send = 0;
 char abs_dir[100];
 int client_data_channel_fd;
 struct file_list * files_head = ((void *)0);
 sprintf(abs_dir,"%s%s",root_directory,directory);
 files_head = get_file_list(abs_dir);
 if(files_head != ((void *)0)){
  sprintf(buffer,"ack;rcvdircontent|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
   printf("send error\n");
   exit(1);
  }
 }
 else{
  sprintf(buffer,"error;1001|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
     printf("send error\n");
     exit(1);
  }
  return -1;
 }
 client_data_channel_fd = init_data_connection(client_addr);
 if((bytes_send = SendFileNames(client_data_channel_fd,buffer,files_head)) == -1){
  printf("SendFileNames send package failed!\n");
  free_file_list(files_head);
  return -1;
 }
 printf("%d bytes sended \n",bytes_send);
 close(client_data_channel_fd);
  free_file_list(files_head);
 return 1;
}

canonical_original_code:
int GetDirContent(int client_fd, char *buffer, char *directory, struct sockaddr_in client_addr)
{
 int bytes_send = 0;
 char abs_dir[100];
 int client_data_channel_fd;
 struct file_list *files_head = ((void *)0);
 sprintf(abs_dir,"%s%s",root_directory,directory);
 files_head = get_file_list(abs_dir);
 if(files_head != ((void *)0)){
  sprintf(buffer,"ack;rcvdircontent|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
   printf("send error\n");
   exit(1);
  }
 }
 else{
  sprintf(buffer,"error;1001|");
  if(send(client_fd,buffer,4096,0)==-1)
  {
     printf("send error\n");
     exit(1);
  }
  return -1;
 }
 client_data_channel_fd = init_data_connection(client_addr);
 if((bytes_send = SendFileNames(client_data_channel_fd,buffer,files_head)) == -1){
  printf("SendFileNames send package failed!\n");
  free_file_list(files_head);
  return -1;
 }
 printf("%d bytes sended \n",bytes_send);
 close(client_data_channel_fd);
  free_file_list(files_head);
 return 1;
}

variable_types:
directory
char *

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


ChangeDirectory

decompiled_code:
__int64 __fastcall ChangeDirectory(int fd, void *buf, const char *a3, const char *a4)
{
__int64 result; // rax
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v5, "%s%s%s", root_directory, a3, a4);
if ( opendir(v5) )
{
strcpy((char *)buf, "ack;directorychanged|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
result = 1LL;
}
else
{
strcpy((char *)buf, "error;1002|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
closedir(0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd, void *buf, const char *a3, const char *a4)
{
__int64 result; // rax
char v5[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v5, "%s%s%s", root_directory, a3, a4);
if ( opendir(v5) )
{
strcpy((char *)buf, "ack;directorychanged|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
result = 1LL;
}
else
{
strcpy((char *)buf, "error;1002|");
if ( send(fd, buf, 0x1000uLL, 0) == -1 )
{
puts("send error");
exit(1);
}
closedir(0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int ChangeDirectory(int server_fd,char new_dir[])
{
 char response_type[20];
 char response_argu[20];
 memset(buffer,1048576,'\0');
 sprintf(buffer,"request;changedirectory;%s;%s|",current_directory,new_dir);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
  return -1;
 }
 memset(buffer,1048576,'\0');
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
  printf("the directory don't exist\n");
  return -1;
 }
 strcat(current_directory,new_dir);
 current_directory[strlen(current_directory)] = '/';
 current_directory[strlen(current_directory)+1] = '\0';
 printf("directory changed\n");
 return 1;
}

canonical_original_code:
int ChangeDirectory(int server_fd, char new_dir[])
{
 char response_type[20];
 char response_argu[20];
 memset(buffer,1048576,'\0');
 sprintf(buffer,"request;changedirectory;%s;%s|",current_directory,new_dir);
 if(send(server_fd,buffer,strlen(buffer),0)==-1)
 {
  printf("send error\n");
  return -1;
 }
 memset(buffer,1048576,'\0');
 recv(server_fd,buffer,1048576,0);
 response_analysis(buffer,response_type,response_argu);
 if(strcmp(response_type,"error") == 0)
 {
  printf("the directory don't exist\n");
  return -1;
 }
 strcat(current_directory,new_dir);
 current_directory[strlen(current_directory)] = '/';
 current_directory[strlen(current_directory)+1] = '\0';
 printf("directory changed\n");
 return 1;
}


session

decompiled_code:
int __fastcall session(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 v3; // r13
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
_BYTE v8[4096]; // [rsp+0h] [rbp-1258h] BYREF
char v9[100]; // [rsp+1000h] [rbp-258h] BYREF
char v10[100]; // [rsp+1064h] [rbp-1F4h] BYREF
char v11[312]; // [rsp+10C8h] [rbp-190h] BYREF
char v12[88]; // [rsp+1200h] [rbp-58h] BYREF

v1 = *(_DWORD *)a1;
v2 = *(_QWORD *)(a1 + 4);
v3 = *(_QWORD *)(a1 + 12);
v4 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&v2 + 4));
printf("get connection with:%s at port: %d\n", (const char *)v4, WORD1(v2));
while ( (int)request_analysis(v1, v8, (__int64)v12, (__int64)v9) > 0 )
{
v5 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&v2 + 4));
printf("%s execute command:%s\targu[0]:%s\targu[1]:%s\taru[2]:%s \n", (const char *)v5, v12, v9, v10, v11);
if ( !strcmp(v12, "downloadfile") )
{
DownloadFile(v1, (__int64)v8, v9, v10, v2, v3);
}
else if ( !strcmp(v12, "uploadfile") )
{
UploadFile(v1, (__int64)v8, v9, v10, v2, v3);
}
else if ( !strcmp(v12, "querydircontent") )
{
GetDirContent(v1, v8, v9, v2, v3);
}
else if ( strcmp(v12, "rename") && strcmp(v12, "deletefile") && !strcmp(v12, "changedirectory") )
{
ChangeDirectory(v1, v8, v9, v10);
}
}
v6 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&v2 + 4));
printf("%s disconnected \n", (const char *)v6);
return close(v1);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int v1; // ebx
__int64 v2; // r12
__int64 v3; // r13
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
_BYTE v8[4096]; // [rsp+0h] [rbp-1258h] BYREF
char v9[100]; // [rsp+1000h] [rbp-258h] BYREF
char v10[100]; // [rsp+1064h] [rbp-1F4h] BYREF
char v11[312]; // [rsp+10C8h] [rbp-190h] BYREF
char v12[88]; // [rsp+1200h] [rbp-58h] BYREF

v1 = *(_DWORD *)a1;
v2 = *(_QWORD *)(a1 + 4);
v3 = *(_QWORD *)(a1 + 12);
v4 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&v2 + 4));
printf("get connection with:%s at port: %d\n", (const char *)v4, WORD1(v2));
while ( (int)func1(v1, v8, (__int64)v12, (__int64)v9) > 0 )
{
v5 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&v2 + 4));
printf("%s execute command:%s\targu[0]:%s\targu[1]:%s\taru[2]:%s \n", (const char *)v5, v12, v9, v10, v11);
if ( !strcmp(v12, "downloadfile") )
{
func8(v1, (__int64)v8, v9, v10, v2, v3);
}
else if ( !strcmp(v12, "uploadfile") )
{
func10(v1, (__int64)v8, v9, v10, v2, v3);
}
else if ( !strcmp(v12, "querydircontent") )
{
func5(v1, v8, v9, v2, v3);
}
else if ( strcmp(v12, "rename") && strcmp(v12, "deletefile") && !strcmp(v12, "changedirectory") )
{
func6(v1, v8, v9, v10);
}
}
v6 = (unsigned int)inet_ntoa(*(struct in_addr *)((char *)&v2 + 4));
printf("%s disconnected \n", (const char *)v6);
return close(v1);
}

original_code:
void session(struct sockaddr_sockfd* client_addr_fd)
{
 int n = 1;
 char func[20];
 int client_fd = 0 ;
 char arguments[5][100];
 char buffer[4096];
 client_fd = client_addr_fd->socket_fd;
 struct sockaddr_in client_addr;
 memcpy(&client_addr,&(client_addr_fd->socket_addr),sizeof(client_addr_fd->socket_addr));
 printf("get connection with:%s at port: %d\n",inet_ntoa(client_addr.sin_addr.s_addr),client_addr.sin_port);
 while(request_analysis(client_fd,buffer,func,arguments)>0){
  printf("%s execute command:%s\targu[0]:%s\targu[1]:%s\taru[2]:%s \n",inet_ntoa(client_addr.sin_addr.s_addr),func,arguments[0],arguments[1],arguments[2]);
  if(strcmp(func,"downloadfile")==0){
   DownloadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"uploadfile")==0){
   UploadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"querydircontent")==0){
   GetDirContent(client_fd,buffer,arguments[0],client_addr);
  }
  else if(strcmp(func,"rename")==0){
  }
  else if(strcmp(func,"deletefile")==0){
  }
  else if(strcmp(func,"changedirectory")==0){
   ChangeDirectory(client_fd,buffer,arguments[0],arguments[1]);
  }
 }
 printf("%s disconnected \n",inet_ntoa(client_addr.sin_addr.s_addr));
 close(client_fd);
 return;
}

canonical_original_code:
void session(struct sockaddr_sockfd *client_addr_fd)
{
 int n = 1;
 char func[20];
 int client_fd = 0;
 char arguments[5][100];
 char buffer[4096];
 client_fd = client_addr_fd->socket_fd;
 struct sockaddr_in client_addr;
 memcpy(&client_addr,&(client_addr_fd->socket_addr),sizeof(client_addr_fd->socket_addr));
 printf("get connection with:%s at port: %d\n",inet_ntoa(client_addr.sin_addr.s_addr),client_addr.sin_port);
 while(request_analysis(client_fd,buffer,func,arguments)>0){
  printf("%s execute command:%s\targu[0]:%s\targu[1]:%s\taru[2]:%s \n",inet_ntoa(client_addr.sin_addr.s_addr),func,arguments[0],arguments[1],arguments[2]);
  if(strcmp(func,"downloadfile")==0){
   DownloadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"uploadfile")==0){
   UploadFile(client_fd,buffer,arguments[0],arguments[1],client_addr);
  }
  else if(strcmp(func,"querydircontent")==0){
   GetDirContent(client_fd,buffer,arguments[0],client_addr);
  }
  else if(strcmp(func,"rename")==0){
  }
  else if(strcmp(func,"deletefile")==0){
  }
  else if(strcmp(func,"changedirectory")==0){
   ChangeDirectory(client_fd,buffer,arguments[0],arguments[1]);
  }
 }
 printf("%s disconnected \n",inet_ntoa(client_addr.sin_addr.s_addr));
 close(client_fd);
 return;
}

variable_types: struct sockaddr_sockfd { int socket_fd; 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]; } socket_addr; } *

variable_types:
func
char [20]

variable_types:
arguments
char [5][100]

variable_types:
buffer
char [4096]

user_defined_types: struct sockaddr_sockfd { int socket_fd; struct sockaddr_in socket_addr; }


decompiled_code:
void test_glob()
{
glob_t v0; // [rsp+0h] [rbp-58h] BYREF

v0.gl_pathc = 0LL;
v0.gl_pathv = 0LL;
v0.gl_offs = 0LL;
*(_QWORD *)&v0.gl_flags = 0LL;
v0.gl_closedir = 0LL;
v0.gl_readdir = 0LL;
v0.gl_opendir = 0LL;
v0.gl_lstat = 0LL;
v0.gl_stat = 0LL;
glob("/dev/sd*", 0, 0LL, &v0);
globfree(&v0);
}

canonical_decompiled_code:
void func7()
{
glob_t v0; // [rsp+0h] [rbp-58h] BYREF

v0.gl_pathc = 0LL;
v0.gl_pathv = 0LL;
v0.gl_offs = 0LL;
*(_QWORD *)&v0.gl_flags = 0LL;
v0.gl_closedir = 0LL;
v0.gl_readdir = 0LL;
v0.gl_opendir = 0LL;
v0.gl_lstat = 0LL;
v0.gl_stat = 0LL;
glob("/dev/sd*", 0, 0LL, &v0);
globfree(&v0);
}

original_code:
void test_glob(void)
{
 glob_t globbuf = {
  .gl_pathc = 0,
  .gl_pathv = ((void *)0),
  .gl_offs = 0};
 glob("/dev/sd*", 0, ((void *)0), &globbuf);
 globfree(&globbuf);
}

canonical_original_code:
void test_glob()
{
 struct glob_t globbuf = {
  .gl_pathc = 0,
  .gl_pathv = ((void *)0),
  .gl_offs = 0};
 glob("/dev/sd*", 0, ((void *)0), &globbuf);
 globfree(&globbuf);
}

variable_types: struct glob_t { unsigned long gl_pathc; char **gl_pathv; unsigned long gl_offs; int gl_flags; void (*gl_closedir)(void *); void *(*gl_readdir)(void *); void *(*gl_opendir)(char *); int (*gl_lstat)(char *, void *); int (*gl_stat)(char *, void *); }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
char *v4; // rbp

v3 = calloc(0xAuLL, 8uLL);
v4 = strdup("hello0");
*(_QWORD *)v3 = v4;
*((_QWORD *)v3 + 1) = strdup("hello1");
*((_QWORD *)v3 + 2) = strdup("hello2");
puts(v4);
puts(*((const char **)v3 + 1));
puts(*((const char **)v3 + 2));
test_glob();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
char *v4; // rbp

v3 = calloc(0xAuLL, 8uLL);
v4 = strdup("hello0");
*(_QWORD *)v3 = v4;
*((_QWORD *)v3 + 1) = strdup("hello1");
*((_QWORD *)v3 + 2) = strdup("hello2");
puts(v4);
puts(*((const char **)v3 + 1));
puts(*((const char **)v3 + 2));
func7();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int i;
 struct test_s ttt = {0};
 ttt.list = calloc(10, sizeof(char **));
 ttt.count = 3;
 ttt.list[0] = strdup("hello0");
 ttt.list[1] = strdup("hello1");
 ttt.list[2] = strdup("hello2");
 for (i=0; i<ttt.count; i++) {
  printf("%s\n", ttt.list[i]);
 }
 test_glob();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct test_s { char **list; int count; }


memalign

decompiled_code:
__int64 __fastcall memalign(__int64 a1, __int64 a2)
{
return (-a2 & a1) + a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
return (-a2 & a1) + a2;
}

original_code:
static void *memalign(void *p, unsigned long align_size)
{
 return (void *)(((unsigned long)p & ~(align_size-1)) + align_size);
}

variable_types:
p
void *


routine

decompiled_code:
void *__fastcall routine(void *a1)
{
unsigned int *v1; // rbp
int v2; // er13
unsigned int v3; // ebx
void *v4; // rax
void *v5; // r12
int v6; // ebx
int *v7; // rbx
char *v8; // rax
int *v10; // rbx
char *v11; // rax

v1 = *(unsigned int **)a1;
v2 = *((_DWORD *)a1 + 2);
v3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
v4 = malloc(2 * v3);
if ( v4 )
{
v5 = (void *)memalign((__int64)v4, v3);
memset(v5, 97, v3);
lseek(v2, v1[3], 0);
if ( (int)v1[2] > 0 )
{
v6 = 0;
while ( (int)write(v2, v5, v1[1]) >= 0 )
{
if ( (int)v1[2] <= ++v6 )
goto LABEL_8;
}
v10 = __errno_location();
v11 = strerror(*v10);
printf("Can not write to file.(%d)%s\n", (unsigned int)*v10, v11);
}
}
else
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v7, v8);
}
LABEL_8:
puts("thread exit.");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
unsigned int *v1; // rbp
int v2; // er13
unsigned int v3; // ebx
void *v4; // rax
void *v5; // r12
int v6; // ebx
int *v7; // rbx
char *v8; // rax
int *v10; // rbx
char *v11; // rax

v1 = *(unsigned int **)a1;
v2 = *((_DWORD *)a1 + 2);
v3 = *(_DWORD *)(*(_QWORD *)a1 + 4LL);
v4 = malloc(2 * v3);
if ( v4 )
{
v5 = (void *)func7((__int64)v4, v3);
memset(v5, 97, v3);
lseek(v2, v1[3], 0);
if ( (int)v1[2] > 0 )
{
v6 = 0;
while ( (int)write(v2, v5, v1[1]) >= 0 )
{
if ( (int)v1[2] <= ++v6 )
goto LABEL_8;
}
v10 = __errno_location();
v11 = strerror(*v10);
printf("Can not write to file.(%d)%s\n", (unsigned int)*v10, v11);
}
}
else
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v7, v8);
}
LABEL_8:
puts("thread exit.");
return 0LL;
}

original_code:
void *routine(void *arg)
{
 struct thread_info *th_info = (struct thread_info *)arg;
 struct options *opts = th_info->opts;
 int fd = th_info->fd;
 char *buf = ((void *)0);
 int i, ret;
 off_t cur_size = 0;
 buf = malloc(opts->block_size*2);
 if (buf == ((void *)0) || th_info == ((void *)0)) {
  printf("Can not alloc mem.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 buf = (char *)memalign((void *)buf, opts->block_size);
 memset(buf, 'a', opts->block_size);
 lseek(fd, opts->file_pos, 0);
 for (i=0; i<opts->block_count; i++){
  ret = write(fd, buf, opts->block_size);
  if (ret < 0) {
   printf("Can not write to file.(%d)%s\n",
    (*__errno_location ()), strerror((*__errno_location ())));
   goto out;
  }
  cur_size+=ret;
 }
out:
 printf("thread exit.\n");
 return ((void *)0);
}

canonical_original_code:
void *routine(void *arg)
{
 struct thread_info *th_info = (struct thread_info *)arg;
 struct options *opts = th_info->opts;
 int fd = th_info->fd;
 char *buf = ((void *)0);
 int i; int ret;
 long cur_size = 0;
 buf = malloc(opts->block_size*2);
 if (buf == ((void *)0) || th_info == ((void *)0)) {
  printf("Can not alloc mem.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
 buf = (char *)memalign((void *)buf, opts->block_size);
 memset(buf, 'a', opts->block_size);
 lseek(fd, opts->file_pos, 0);
 for (i=0; i<opts->block_count; i++){
  ret = write(fd, buf, opts->block_size);
  if (ret < 0) {
   printf("Can not write to file.(%d)%s\n",
    (*__errno_location ()), strerror((*__errno_location ())));
   goto out;
  }
  cur_size+=ret;
 }
out:
 printf("thread exit.\n");
 return ((void *)0);
}

variable_types:
arg
void *

variable_types: struct thread_info { struct options { int mode; unsigned int block_size; int block_count; unsigned int file_pos; char *filepath; } *opts; int fd; } *

variable_types: fd int

variable_types:
buf
char *

variable_types: ret int

user_defined_types: struct thread_info { struct options *opts; int fd; }


controler

decompiled_code:
__int64 controler()
{
int *v1; // rbx
char *v2; // rax

if ( calloc(1uLL, 0x200uLL) )
return 0LL;
v1 = __errno_location();
v2 = strerror(*v1);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func9()
{
int *v1; // rbx
char *v2; // rax

if ( calloc(1uLL, 0x200uLL) )
return 0LL;
v1 = __errno_location();
v2 = strerror(*v1);
printf("Can not alloc mem.(%d)%s\n", (unsigned int)*v1, v2);
return 0xFFFFFFFFLL;
}

original_code:
int controler(int fd)
{
 char *buf = ((void *)0);
 int ret;
 int i;
 buf = calloc(1, 512);
 if (buf == ((void *)0)) {
  printf("Can not alloc mem.(%d)%s\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto failed;
 }
 memset(buf, 'b', 512);
 for (i=0; i<0; i++) {
  printf("input to continue:");
  getchar();
  ret = write(fd, buf, 512);
  if (ret < 0) {
   printf("Can not write to file.(%d)%s\n",
    (*__errno_location ()), strerror((*__errno_location ())));
   goto failed;
  }
  printf("write finished.\n");
 }
 return 0;
failed:
 return -1;
}

variable_types: i int


getfd

decompiled_code:
int __fastcall getfd(__int64 a1)
{
return open(*(const char **)(a1 + 16), 16450, 420LL);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
return open(*(const char **)(a1 + 16), 16450, 420LL);
}

original_code:
int getfd(struct options *opts)
{
 return open(opts->filepath, (02|0100|040000), 0644);
}

variable_types: struct options { int mode; unsigned int block_size; int block_count; unsigned int file_pos; char *filepath; } *


original_code:
int parse_args(int argc, char *argv[], struct options *opts)
{
 int i;
 memset(opts, '\0', sizeof(*opts));
 opts->block_size = 4096;
 opts->block_count = 1024;
 opts->file_pos = 512;
 for (i=1; i<argc; i++) {
  if (strcmp(argv[i], "-d") == 0) {
   opts->mode |= 040000;
  } else if (strcmp(argv[i], "-a") == 0) {
   opts->mode |= 02000;
  } else if (strcmp(argv[i], "-b") == 0) {
   if (i == argc-1) {
    printf("missing args for -b\n");
    goto failed;
   }
   i++;
   opts->block_size = atol(argv[i]);
  } else if(strcmp(argv[i], "-c") == 0) {
   if (i == argc-1) {
    printf("missing args for -c\n");
    goto failed;
   }
   i++;
   opts->block_count = atol(argv[i]);
  } else {
   if (!opts->filepath)
    opts->filepath = strdup(argv[i]);
  }
 }
 if (!opts->filepath) {
  printf("provide a file path\n");
  goto failed;
 }
 return 0;
failed:
 return 1;
}

user_defined_types: struct options { int mode; unsigned int block_size; int block_count; unsigned int file_pos; char *filepath; }


decompiled_code:
__off_t __fastcall file_size(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (int)fstat(a1, &v2) < 0 )
result = -1LL;
else
result = v2.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func7(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (int)func15(a1, &v2) < 0 )
result = -1LL;
else
result = v2.st_size;
return result;
}

original_code:
off_t file_size(int fd)
{
 struct stat stbuff;
 if (fstat(fd, &stbuff) < 0)
  return -1;
 return stbuff.st_size;
}

canonical_original_code:
long file_size(int fd)
{
 struct stat stbuff;
 if (fstat(fd, &stbuff) < 0)
  return -1;
 return stbuff.st_size;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: long


decompiled_code:
__int64 __fastcall file_check(int fd, __off_t a2, __off_t a3, __int64 a4, __int64 a5)
{
int v8; // edx
__int64 result; // rax

if ( a3 <= a2 || (v8 = _file_check_gap(fd, a2, a3 - a2), result = 1LL, !v8) )
result = _file_check_data(fd, a3, a4 - a3, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, __off_t a2, __off_t a3, __int64 a4, __int64 a5)
{
int v8; // edx
__int64 result; // rax

if ( a3 <= a2 || (v8 = func8(fd, a2, a3 - a2), result = 1LL, !v8) )
result = func9(fd, a3, a4 - a3, a5);
return result;
}

original_code:
int file_check(int fd, off_t pos1, off_t pos2, off_t pos3, char *data)
{
 int ret = 1;
 if (pos2 > pos1)
  if (__file_check_gap(fd, pos1, pos2-pos1))
   goto out;
 ret = __file_check_data(fd, pos2, pos3-pos2, data);
out:
 return ret;
}

canonical_original_code:
int file_check(int fd, long pos1, long pos2, long pos3, char *data)
{
 int ret = 1;
 if (pos2 > pos1)
  if (__file_check_gap(fd, pos1, pos2-pos1))
   goto out;
 ret = __file_check_data(fd, pos2, pos3-pos2, data);
out:
 return ret;
}

variable_types:
data
char *


decompiled_code:
__int64 __fastcall grow_file(int fd, int a2)
{
__off_t v2; // r12
__off_t v3; // rax
__off_t v4; // rbp
__int64 v5; // r14
__off_t v6; // rax
__off_t v7; // r13
unsigned int v8; // ecx
ssize_t v9; // rax
ssize_t v10; // r12
size_t v11; // r14
__int64 v13; // r15
__off_t v14; // rax
signed int v15; // ebp
int v16; // er13
__off_t v17; // rax
__off_t v18; // r14
__off_t v19; // r14
int v20; // eax
__off_t v21; // [rsp+8h] [rbp-40h]

v2 = file_size(fd);
v3 = lseek(fd, 0LL, 2);
if ( v3 < 0 || (v4 = v3, v2 != v3) )
{
puts("file end & file size mismatch or operation failed");
return 1;
}
v5 = qword_4040C8;
if ( qword_4040C8 )
{
v6 = lseek(fd, qword_4040C8 + v2, 0);
v7 = v6;
if ( v6 < 0 || v5 != v6 - v4 )
{
puts("lseek do not reach require size or operation failed");
return 1;
}
}
else
{
v7 = v3;
}
v9 = write(fd, buf, size);
v10 = v9;
if ( v9 >= 0 && (v11 = size, size == v9) )
{
v13 = lseek(fd, 0LL, 1);
v14 = file_size(fd);
v21 = v14;
if ( v13 >= 0 && v13 == v14 && v13 - v7 == v11 )
{
v8 = file_check(fd, v4, v7, v13, (__int64)buf);
if ( v8 )
{
v8 = 1;
}
else
{
v15 = a2 + 1;
v16 = (a2 + 1) % dword_4040F8;
if ( !v16 )
{
v17 = lseek(fd, 0LL, 1);
v18 = v17;
if ( v17 >= 0 && v13 == v17 )
{
printf("truncate file to %jd trunk_pos=%jd\n", v17 - qword_4040F0, v17);
printf(
"refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
v15 / dword_4040F8 * (size * dword_4040F8 - qword_4040F0),
(unsigned int)v15,
v13,
v21,
v10);
v19 = v18 - qword_4040F0;
if ( (size * dword_4040F8 - qword_4040F0) * (v15 / dword_4040F8) == v19 )
{
v20 = ftruncate(fd, v19);
v8 = v16;
if ( v20 < 0 )
{
puts("can not truncate file");
v8 = 1;
}
}
else
{
puts("wrong truncate position");
v8 = 1;
}
}
else
{
puts("trunk_pos does't match");
v8 = 1;
}
}
}
}
else
{
puts("write data len mismatch or operation failed");
v8 = 1;
}
}
else
{
puts("write len does't not match or operation failed");
v8 = 1;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, int a2)
{
__off_t v2; // r12
__off_t v3; // rax
__off_t v4; // rbp
__int64 v5; // r14
__off_t v6; // rax
__off_t v7; // r13
unsigned int v8; // ecx
ssize_t v9; // rax
ssize_t v10; // r12
size_t v11; // r14
__int64 v13; // r15
__off_t v14; // rax
signed int v15; // ebp
int v16; // er13
__off_t v17; // rax
__off_t v18; // r14
__off_t v19; // r14
int v20; // eax
__off_t v21; // [rsp+8h] [rbp-40h]

v2 = func7(fd);
v3 = lseek(fd, 0LL, 2);
if ( v3 < 0 || (v4 = v3, v2 != v3) )
{
puts("file end & file size mismatch or operation failed");
return 1;
}
v5 = qword_4040C8;
if ( qword_4040C8 )
{
v6 = lseek(fd, qword_4040C8 + v2, 0);
v7 = v6;
if ( v6 < 0 || v5 != v6 - v4 )
{
puts("lseek do not reach require size or operation failed");
return 1;
}
}
else
{
v7 = v3;
}
v9 = write(fd, buf, size);
v10 = v9;
if ( v9 >= 0 && (v11 = size, size == v9) )
{
v13 = lseek(fd, 0LL, 1);
v14 = func7(fd);
v21 = v14;
if ( v13 >= 0 && v13 == v14 && v13 - v7 == v11 )
{
v8 = func10(fd, v4, v7, v13, (__int64)buf);
if ( v8 )
{
v8 = 1;
}
else
{
v15 = a2 + 1;
v16 = (a2 + 1) % dword_4040F8;
if ( !v16 )
{
v17 = lseek(fd, 0LL, 1);
v18 = v17;
if ( v17 >= 0 && v13 == v17 )
{
printf("truncate file to %jd trunk_pos=%jd\n", v17 - qword_4040F0, v17);
printf(
"refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
v15 / dword_4040F8 * (size * dword_4040F8 - qword_4040F0),
(unsigned int)v15,
v13,
v21,
v10);
v19 = v18 - qword_4040F0;
if ( (size * dword_4040F8 - qword_4040F0) * (v15 / dword_4040F8) == v19 )
{
v20 = ftruncate(fd, v19);
v8 = v16;
if ( v20 < 0 )
{
puts("can not truncate file");
v8 = 1;
}
}
else
{
puts("wrong truncate position");
v8 = 1;
}
}
else
{
puts("trunk_pos does't match");
v8 = 1;
}
}
}
}
else
{
puts("write data len mismatch or operation failed");
v8 = 1;
}
}
else
{
puts("write len does't not match or operation failed");
v8 = 1;
}
return v8;
}

original_code:
int grow_file(int fd, int iter)
{
 off_t fsize;
 ssize_t write_len;
 off_t pos1, pos2, pos3;
 off_t trunk_pos;
 fsize = file_size(fd);
 pos1 = pos2 = lseek(fd, 0, 2);
 if (pos1 < 0 || fsize != pos1) {
  printf("file end & file size mismatch or operation failed\n");
  goto failed;
 }
 if (opt.gap_size) {
  pos2 = lseek(fd, fsize + opt.gap_size, 0);
  if (pos2 < 0 || (pos2 - pos1) != opt.gap_size) {
   printf("lseek do not reach require size or operation failed\n");
   goto failed;
  }
 }
 write_len = write(fd, opt.data, opt.data_size);
 if (write_len < 0 || write_len != opt.data_size) {
  printf("write len does't not match or operation failed\n");
  goto failed;
 }
 pos3 = lseek(fd, 0, 1);
 fsize = file_size(fd);
 if (pos3 < 0 || fsize != pos3 || (pos3 - pos2) != opt.data_size) {
  printf("write data len mismatch or operation failed\n");
  goto failed;
 }
 if (file_check(fd, pos1, pos2, pos3, opt.data))
  goto failed;
 if (((iter+1)%opt.trunc_iter) == 0) {
  trunk_pos = lseek(fd, 0, 1);
  if (trunk_pos < 0 || trunk_pos != pos3) {
   printf("trunk_pos does't match\n");
   goto failed;
  }
  printf("truncate file to  %jd trunk_pos=%jd\n", trunk_pos-opt.trunc_size, trunk_pos);
  printf("refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
    ((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size),
    iter+1,
    pos3,
    fsize,
    write_len);
  if (((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size)
    != trunk_pos-opt.trunc_size) {
   printf("wrong truncate position\n");
   goto failed;
  }
  if (ftruncate(fd, trunk_pos - opt.trunc_size) < 0) {
   printf("can not truncate file\n");
   goto failed;
  }
 }
 return 0;
failed:
 return 1;
}

canonical_original_code:
int grow_file(int fd, int iter)
{
 long fsize;
 long write_len;
 long pos1; long pos2; long pos3;
 long trunk_pos;
 fsize = file_size(fd);
 pos1 = pos2 = lseek(fd, 0, 2);
 if (pos1 < 0 || fsize != pos1) {
  printf("file end & file size mismatch or operation failed\n");
  goto failed;
 }
 if (opt.gap_size) {
  pos2 = lseek(fd, fsize + opt.gap_size, 0);
  if (pos2 < 0 || (pos2 - pos1) != opt.gap_size) {
   printf("lseek do not reach require size or operation failed\n");
   goto failed;
  }
 }
 write_len = write(fd, opt.data, opt.data_size);
 if (write_len < 0 || write_len != opt.data_size) {
  printf("write len does't not match or operation failed\n");
  goto failed;
 }
 pos3 = lseek(fd, 0, 1);
 fsize = file_size(fd);
 if (pos3 < 0 || fsize != pos3 || (pos3 - pos2) != opt.data_size) {
  printf("write data len mismatch or operation failed\n");
  goto failed;
 }
 if (file_check(fd, pos1, pos2, pos3, opt.data))
  goto failed;
 if (((iter+1)%opt.trunc_iter) == 0) {
  trunk_pos = lseek(fd, 0, 1);
  if (trunk_pos < 0 || trunk_pos != pos3) {
   printf("trunk_pos does't match\n");
   goto failed;
  }
  printf("truncate file to  %jd trunk_pos=%jd\n", trunk_pos-opt.trunc_size, trunk_pos);
  printf("refrence position %lu, iter=%d, pos3=%jd, fsize=%jd, write_len=%jd\n",
    ((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size),
    iter+1,
    pos3,
    fsize,
    write_len);
  if (((iter+1)/opt.trunc_iter)*(opt.data_size*opt.trunc_iter-opt.trunc_size)
    != trunk_pos-opt.trunc_size) {
   printf("wrong truncate position\n");
   goto failed;
  }
  if (ftruncate(fd, trunk_pos - opt.trunc_size) < 0) {
   printf("can not truncate file\n");
   goto failed;
  }
 }
 return 0;
failed:
 return 1;
}

variable_types: iter int

variable_types: fsize long


decompiled_code:
__int64 __fastcall get_opt(int a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // r8

if ( a1 > 1 )
{
v2 = 1;
while ( 1 )
{
v3 = 8LL * v2;
if ( !strcmp(*(const char **)(a2 + v3), "-s") )
{
if ( a1 == ++v2 )
goto LABEL_18;
opt = atoi(*(const char **)(a2 + v3 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v2), "-g") )
{
if ( a1 == ++v2 )
goto LABEL_18;
qword_4040C8 = atoi(*(const char **)(a2 + v3 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v2), "-d") )
{
if ( a1 == ++v2 )
goto LABEL_18;
size = atoi(*(const char **)(a2 + v3 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v2), "-i") )
{
if ( a1 == ++v2 )
{
LABEL_18:
puts("options parse failed!");
return 1LL;
}
dword_4040D8 = atoi(*(const char **)(a2 + v3 + 8));
}
else
{
file = strdup(*(const char **)(a2 + 8LL * v2));
}
if ( a1 <= ++v2 )
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, __int64 a2)
{
int v2; // ebx
__int64 v3; // r8

if ( a1 > 1 )
{
v2 = 1;
while ( 1 )
{
v3 = 8LL * v2;
if ( !strcmp(*(const char **)(a2 + v3), "-s") )
{
if ( a1 == ++v2 )
goto LABEL_18;
opt = atoi(*(const char **)(a2 + v3 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v2), "-g") )
{
if ( a1 == ++v2 )
goto LABEL_18;
qword_4040C8 = atoi(*(const char **)(a2 + v3 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v2), "-d") )
{
if ( a1 == ++v2 )
goto LABEL_18;
size = atoi(*(const char **)(a2 + v3 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8LL * v2), "-i") )
{
if ( a1 == ++v2 )
{
LABEL_18:
puts("options parse failed!");
return 1LL;
}
dword_4040D8 = atoi(*(const char **)(a2 + v3 + 8));
}
else
{
file = strdup(*(const char **)(a2 + 8LL * v2));
}
if ( a1 <= ++v2 )
return 0LL;
}
}
return 0LL;
}

original_code:
int get_opt(int argc, char *argv[])
{
 int i;
 for (i=1; i< argc; i++) {
  if (strcmp(argv[i], "-s") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.get_size_way = atoi(argv[i]);
  } else if (strcmp(argv[i], "-g") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.gap_size = atoi(argv[i]);
  } else if (strcmp(argv[i], "-d") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.data_size = atoi(argv[i]);
  } else if (strcmp(argv[i], "-i") == 0) {
   i++;
   if (i == argc)
    goto failed;
   opt.iter = atoi(argv[i]);
  } else {
   opt.file_path = strdup(argv[i]);
  }
 }
 return 0;
failed:
 printf("options parse failed!\n");
 return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
int v5; // ebx
int v6; // er12
int *v7; // rbx
char *v8; // rax

if ( (unsigned int)get_opt(argc, (__int64)argv) )
goto LABEL_11;
v3 = 0;
if ( !file )
goto LABEL_11;
buf = prepare_data(size);
if ( !buf )
{
puts("memory alloc failed!");
LABEL_11:
v7 = __errno_location();
v8 = strerror(*v7);
printf("Got error(%d):%s\n", (unsigned int)*v7, v8);
return 1;
}
if ( dword_4040D8 > 0 )
{
while ( 1 )
{
v4 = open(file, 66, 511LL);
v5 = v4;
if ( v4 < 0 )
break;
v6 = grow_file(v4, v3);
if ( v6 )
goto LABEL_11;
close(v5);
if ( dword_4040D8 <= ++v3 )
return v6;
}
puts("can not open file");
goto LABEL_11;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
int v5; // ebx
int v6; // er12
int *v7; // rbx
char *v8; // rax

if ( (unsigned int)func12(argc, (__int64)argv) )
goto LABEL_11;
v3 = 0;
if ( !file )
goto LABEL_11;
buf = prepare_data(size);
if ( !buf )
{
puts("memory alloc failed!");
LABEL_11:
v7 = __errno_location();
v8 = strerror(*v7);
printf("Got error(%d):%s\n", (unsigned int)*v7, v8);
return 1;
}
if ( dword_4040D8 > 0 )
{
while ( 1 )
{
v4 = open(file, 66, 511LL);
v5 = v4;
if ( v4 < 0 )
break;
v6 = func11(v4, v3);
if ( v6 )
goto LABEL_11;
close(v5);
if ( dword_4040D8 <= ++v3 )
return v6;
}
puts("can not open file");
goto LABEL_11;
}
return v3;
}

original_code:
int main(int argc, char *argv[])
{
 int fd, i;
 if (get_opt(argc, argv) || !opt.file_path)
  goto failed;
 opt.data = prepare_data(opt.data_size);
 if (!opt.data) {
  printf("memory alloc failed!\n");
  goto failed;
 }
 for (i=0; i<opt.iter; i++) {
  fd = open(opt.file_path, 02|0100, 0777);
  if (fd < 0) {
   printf("can not open file\n");
   goto failed;
  }
  if (grow_file(fd, i))
   goto failed;
  close(fd);
 }
 return 0;
failed:
 printf("Got error(%d):%s\n", (*__errno_location ()), strerror((*__errno_location ())));
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd; int i;
 if (get_opt(argc, argv) || !opt.file_path)
  goto failed;
 opt.data = prepare_data(opt.data_size);
 if (!opt.data) {
  printf("memory alloc failed!\n");
  goto failed;
 }
 for (i=0; i<opt.iter; i++) {
  fd = open(opt.file_path, 02|0100, 0777);
  if (fd < 0) {
   printf("can not open file\n");
   goto failed;
  }
  if (grow_file(fd, i))
   goto failed;
  close(fd);
 }
 return 0;
failed:
 printf("Got error(%d):%s\n", (*__errno_location ()), strerror((*__errno_location ())));
 return 1;
}


debuger

decompiled_code:
int __fastcall debuger(unsigned int a1)
{
return printf("test write for %d times\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
return printf("test write for %d times\n", a1);
}

original_code:
void debuger(int counter)
{
 printf("test write for %d times\n", counter);
}

variable_types: counter int


decompiled_code:
int __fastcall sys_open(const char *a1, int a2)
{
return open(a1, a2 | 0x800);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1, int a2)
{
return open(a1, a2 | 0x800);
}

original_code:
int
sys_open(const char *file_path, int flags, mode_t mode)
{
 int ret;
 flags |= 04000;
 ret = open(file_path, flags, mode);
 return ret;
}

canonical_original_code:
int sys_open(char *file_path, int flags, unsigned int mode)
{
 int ret;
 flags |= 04000;
 ret = open(file_path, flags, mode);
 return ret;
}

variable_types: flags int

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall sys_write(int a1, const void *a2, size_t a3)
{
int v3; // eax
__int64 v4; // rdx

v3 = write(a1, a2, a3);
v4 = v3;
if ( v3 == 11 )
{
puts("debug_ding:non block mode continue to write");
v4 = 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, const void *a2, size_t a3)
{
int v3; // eax
__int64 v4; // rdx

v3 = write(a1, a2, a3);
v4 = v3;
if ( v3 == 11 )
{
puts("debug_ding:non block mode continue to write");
v4 = 0LL;
}
return v4;
}

original_code:
ssize_t
sys_write(int fd, const void *buf, size_t count)
{
 ssize_t ret;
 ret = write(fd, buf, count);
 if (ret == 11) {
  ret = 0;
  printf("debug_ding:non block mode continue to write\n");
 }
 return ret;
}

canonical_original_code:
long sys_write(int fd, void *buf, unsigned long count)
{
 long ret;
 ret = write(fd, buf, count);
 if (ret == 11) {
  ret = 0;
  printf("debug_ding:non block mode continue to write\n");
 }
 return ret;
}

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: ret long


decompiled_code:
int __fastcall sys_close(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func10(int a1)
{
return close(a1);
}

original_code:
int
sys_close(int fd)
{
 return close(fd);
}


decompiled_code:
__int64 __fastcall test_thread(void *a1)
{
signed int v1; // ebx
int *v2; // rbx
char *v3; // rax
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int v9; // eax
int v10; // ebp
char v11[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v11, "%s%d", (const char *)file_prefix, *(unsigned int *)a1);
printf("file_path:%s\n", v11);
v1 = 0;
do
{
v9 = sys_open(v11, 1090);
v10 = v9;
if ( v9 < 0 )
{
printf("can not open file");
v2 = __errno_location();
v3 = strerror(*v2);
printf(" errno:%d(%s)\n", (unsigned int)*v2, v3);
return -1LL;
}
if ( (int)sys_write(v9, (const void *)buf, 0x100000uLL) < 0
|| (int)sys_write(v10, (const void *)buf, 0x100000uLL) < 0 )
{
printf("write error");
v5 = __errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
return -1LL;
}
if ( sys_close(v10) )
{
printf("can not close file");
v7 = __errno_location();
v8 = strerror(*v7);
printf(" errno:%d(%s)\n", (unsigned int)*v7, v8);
return -1LL;
}
++v1;
if ( v1 == 30 * (v1 / 30) )
debuger(v1);
}
while ( v1 != 40960 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(void *a1)
{
signed int v1; // ebx
int *v2; // rbx
char *v3; // rax
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int v9; // eax
int v10; // ebp
char v11[136]; // [rsp+0h] [rbp-88h] BYREF

sprintf(v11, "%s%d", (const char *)file_prefix, *(unsigned int *)a1);
printf("file_path:%s\n", v11);
v1 = 0;
do
{
v9 = func8(v11, 1090);
v10 = v9;
if ( v9 < 0 )
{
printf("can not open file");
v2 = __errno_location();
v3 = strerror(*v2);
printf(" errno:%d(%s)\n", (unsigned int)*v2, v3);
return -1LL;
}
if ( (int)func9(v9, (const void *)buf, 0x100000uLL) < 0
|| (int)func9(v10, (const void *)buf, 0x100000uLL) < 0 )
{
printf("write error");
v5 = __errno_location();
v6 = strerror(*v5);
printf(" errno:%d(%s)\n", (unsigned int)*v5, v6);
return -1LL;
}
if ( func10(v10) )
{
printf("can not close file");
v7 = __errno_location();
v8 = strerror(*v7);
printf(" errno:%d(%s)\n", (unsigned int)*v7, v8);
return -1LL;
}
++v1;
if ( v1 == 30 * (v1 / 30) )
func7(v1);
}
while ( v1 != 40960 );
return 0LL;
}

original_code:
void *
test_thread (void *arg)
{
 int fd;
 int ret;
 int i;
 int loop_counter = 0;
 int *thread_num = (int *)arg;
 char file_path[100];
 sprintf(file_path, "%s%d", file_prefix, *thread_num);
 printf("file_path:%s\n", file_path);
 i = 40960;
 while (i-->0) {
  fd = sys_open(file_path, 02|0100|02000, 0400|0200);
  do {if (fd < 0) { do { printf("can not open file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_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);
  loop_counter++;
  if ((loop_counter%30)==0) {
   debuger(loop_counter);
  }
 }
 return 0;
}

canonical_original_code:
void *test_thread(void *arg)
{
 int fd;
 int ret;
 int i;
 int loop_counter = 0;
 int *thread_num = (int *)arg;
 char file_path[100];
 sprintf(file_path, "%s%d", file_prefix, *thread_num);
 printf("file_path:%s\n", file_path);
 i = 40960;
 while (i-->0) {
  fd = sys_open(file_path, 02|0100|02000, 0400|0200);
  do {if (fd < 0) { do { printf("can not open file"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_write (fd, buf, 1048576);
  do {if (ret < 0) { do { printf("write error"); printf(" errno:%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ()))); } while(0); return -1;}} while (0);
  ret = sys_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);
  loop_counter++;
  if ((loop_counter%30)==0) {
   debuger(loop_counter);
  }
 }
 return 0;
}

variable_types:
arg
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
int arg[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( argc <= 1 )
{
file_prefix = (__int64)"/cluster2/test1/test_file";
printf("use default file location:%s\n", "/cluster2/test1/test_file");
}
else
{
file_prefix = (__int64)argv[1];
printf("use user specified file location:%s\n", (const char *)file_prefix);
}
buf = (__int64)malloc(0x100000uLL);
arg[0] = 0;
pthread_create(&th, 0LL, (void *(*)(void *))test_thread, arg);
printf("waiting for thread %d\n", 0LL);
pthread_join(th, 0LL);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 int i;
 int args[1];
 void * ptr;
 pthread_t th_id[1];
 if (argc > 1) {
  file_prefix = argv[1];
  printf("use user specified file location:%s\n", file_prefix);
 }
 else {
  file_prefix = "/cluster2/test1/test_file";
  printf("use default file location:%s\n", file_prefix);
 }
 buf = malloc(1048576);
 if(buf < 0){
  printf("can not alloc memory");
  return -1;
 }
 memset(buf, 1048576, '\0');
 for (i=0; i<1; i++){
  args[i] = i;
  pthread_create (&th_id[i], ((void *)0), test_thread, (void *)&args[i]);
 }
 for (i=0; i<1; i++) {
  printf ("waiting for thread %d\n", i);
  pthread_join (th_id[i], ((void *)0));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i;
 int args[1];
 void *ptr;
 unsigned long th_id[1];
 if (argc > 1) {
  file_prefix = argv[1];
  printf("use user specified file location:%s\n", file_prefix);
 }
 else {
  file_prefix = "/cluster2/test1/test_file";
  printf("use default file location:%s\n", file_prefix);
 }
 buf = malloc(1048576);
 if(buf < 0){
  printf("can not alloc memory");
  return -1;
 }
 memset(buf, 1048576, '\0');
 for (i=0; i<1; i++){
  args[i] = i;
  pthread_create (&th_id[i], ((void *)0), test_thread, (void *)&args[i]);
 }
 for (i=0; i<1; i++) {
  printf ("waiting for thread %d\n", i);
  pthread_join (th_id[i], ((void *)0));
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
args
int [1]

variable_types:
ptr
void *


decompiled_code:
void *__fastcall my_thread(void *a1)
{
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
printf("i=%d\n", (unsigned int)MEMORY[0]);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
sleep(1u);
printf("i=%d\n", (unsigned int)MEMORY[0]);
return 0LL;
}

original_code:
void *my_thread(void *args)
{
 int i = 0;
 char *p = ((void *)0);
 while (i++ < 5) {
  sleep(1);
 }
 i = (int)p[0];
 printf("i=%d\n", i);
 return ((void *)0);
}

variable_types:
args
void *

variable_types: i int

variable_types:
p
char *


decompiled_code:
void __fastcall my_sig_handler(unsigned int a1)
{
int v1; // eax

puts("enter signal handler");
if ( a1 == signal_name_map )
{
v1 = 0;
}
else if ( a1 == dword_404070 )
{
v1 = 1;
}
else
{
v1 = 2;
if ( dword_404080 != a1 )
{
printf("no match signal for %d\n", a1);
return;
}
}
printf("recieve signal %s\n", (&off_404068)[2 * v1]);
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1)
{
int v1; // eax

puts("enter signal handler");
if ( a1 == signal_name_map )
{
v1 = 0;
}
else if ( a1 == dword_404070 )
{
v1 = 1;
}
else
{
v1 = 2;
if ( dword_404080 != a1 )
{
printf("no match signal for %d\n", a1);
return;
}
}
printf("recieve signal %s\n", (&off_404068)[2 * v1]);
}

original_code:
void my_sig_handler (int signum)
{
 int i;
 printf("enter signal handler\n");
 for (i=0; i<3; i++) {
  if (signum == signal_name_map[i].signal_num) {
   printf ("recieve signal %s\n", signal_name_map[i].signal_name);
   return;
  }
 }
 printf("no match signal for %d\n", signum);
}

canonical_original_code:
void my_sig_handler(int signum)
{
 int i;
 printf("enter signal handler\n");
 for (i=0; i<3; i++) {
  if (signum == signal_name_map[i].signal_num) {
   printf ("recieve signal %s\n", signal_name_map[i].signal_name);
   return;
  }
 }
 printf("no match signal for %d\n", signum);
}

variable_types: signum int


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

pthread_create(newthread, 0LL, my_thread, 0LL);
signal(9, (__sighandler_t)my_sig_handler);
signal(15, (__sighandler_t)my_sig_handler);
signal(11, (__sighandler_t)my_sig_handler);
while ( 1 )
{
sleep(1u);
puts("sleeping ");
}
}

original_code:
int main ()
{
 pthread_t tid;
 pthread_create(&tid, ((void *)0), my_thread, ((void *)0));
 signal(9, my_sig_handler);
 signal(15, my_sig_handler);
 signal(11, my_sig_handler);
 while (1) {
  sleep(1);
  printf ("sleeping \n");
 }
 return 0;
}

canonical_original_code:
int main()
{
 unsigned long tid;
 pthread_create(&tid, ((void *)0), my_thread, ((void *)0));
 signal(9, my_sig_handler);
 signal(15, my_sig_handler);
 signal(11, my_sig_handler);
 while (1) {
  sleep(1);
  printf ("sleeping \n");
 }
 return 0;
}

variable_types:
tid
unsigned long


decompiled_code:
int __fastcall follow_link(char *src)
{
char *v1; // rbp
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
int v5; // eax
ssize_t v6; // rax
size_t v7; // rax
int *v8; // r13
char *v9; // rax
int result; // eax
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v1 = (char *)calloc(1uLL, 0x1000uLL);
v2 = (char *)calloc(1uLL, 0x1000uLL);
v3 = v2;
if ( *src != 47 )
{
if ( !getcwd(v2, 0xFFFuLL) )
{
v8 = __errno_location();
v9 = strerror(*v8);
printf("BW_VMDIO:Get cwd error. %d(%s)\n", (unsigned int)*v8, v9);
}
*(_WORD *)&v3[strlen(v3)] = 47;
}
v4 = strlen(v3);
strncat(v3, src, 4095 - v4);
while ( 1 )
{
if ( (unsigned int)lstat(v3, &v11) )
return printf("BW_VMDIO:stat %s failed.\n", v3);
v5 = v11.st_mode & 0xF000;
if ( v5 != 40960 )
break;
v6 = readlink(v3, v1, 0xFFFuLL);
if ( v6 < 0 )
return printf("BW_VMDIO:read link %s failed\n", v3);
v1[v6] = 0;
if ( *v1 == 47 )
{
strcpy(v3, v1);
}
else
{
dirname(v3);
*(_WORD *)&v3[strlen(v3)] = 47;
v7 = strlen(v3);
strncat(v3, v1, 4095 - v7);
}
}
if ( v5 == 24576 )
result = printf("BW_VMDIO: final path = %s\n", v3);
else
result = printf("BW_VMDIO:%s unkown file mode %o\n", v3, v11.st_mode);
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *src)
{
char *v1; // rbp
char *v2; // rax
char *v3; // rbx
size_t v4; // rax
int v5; // eax
ssize_t v6; // rax
size_t v7; // rax
int *v8; // r13
char *v9; // rax
int result; // eax
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v1 = (char *)calloc(1uLL, 0x1000uLL);
v2 = (char *)calloc(1uLL, 0x1000uLL);
v3 = v2;
if ( *src != 47 )
{
if ( !getcwd(v2, 0xFFFuLL) )
{
v8 = __errno_location();
v9 = strerror(*v8);
printf("BW_VMDIO:Get cwd error. %d(%s)\n", (unsigned int)*v8, v9);
}
*(_WORD *)&v3[strlen(v3)] = 47;
}
v4 = strlen(v3);
strncat(v3, src, 4095 - v4);
while ( 1 )
{
if ( (unsigned int)func10(v3, &v11) )
return printf("BW_VMDIO:stat %s failed.\n", v3);
v5 = v11.st_mode & 0xF000;
if ( v5 != 40960 )
break;
v6 = readlink(v3, v1, 0xFFFuLL);
if ( v6 < 0 )
return printf("BW_VMDIO:read link %s failed\n", v3);
v1[v6] = 0;
if ( *v1 == 47 )
{
strcpy(v3, v1);
}
else
{
dirname(v3);
*(_WORD *)&v3[strlen(v3)] = 47;
v7 = strlen(v3);
strncat(v3, v1, 4095 - v7);
}
}
if ( v5 == 24576 )
result = printf("BW_VMDIO: final path = %s\n", v3);
else
result = printf("BW_VMDIO:%s unkown file mode %o\n", v3, v11.st_mode);
return result;
}

original_code:
void follow_link(const char *src_path)
{
 struct stat st;
 int ret;
 ssize_t sym_len;
 char *dev_path = ((void *)0);
 char *sym_path = ((void *)0);
 sym_path = calloc(1, 4096);
 dev_path = calloc(1, 4096);
 if (src_path[0] != '/') {
  if (getcwd(dev_path, 4096 -1) == ((void *)0)) {
   printf("BW_VMDIO:Get cwd error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  }
  strcat(dev_path, "/");
 }
 strncat(dev_path, src_path, 4096 -strlen(dev_path)-1);
 while (1) {
  ret = lstat(dev_path, &st);
  if (ret) {
   printf("BW_VMDIO:stat %s failed.\n", dev_path);
   goto failed;
  }
  if (((((st.st_mode)) & 0170000) == (0120000))) {
   sym_len = readlink(dev_path, sym_path, 4096 -1);
   if (sym_len < 0) {
    printf("BW_VMDIO:read link %s failed\n", dev_path);
    goto failed;
   }
   sym_path[sym_len] = '\0';
   if (sym_path[0] == '/') {
    strcpy(dev_path, sym_path);
   } else {
    dirname(dev_path);
    strcat(dev_path, "/");
    strncat(dev_path, sym_path, 4096 -strlen(dev_path)-1);
   }
   continue;
  } else if (((((st.st_mode)) & 0170000) == (0060000))) {
   break;
  } else {
   printf("BW_VMDIO:%s unkown file mode %o\n", dev_path, st.st_mode);
   goto failed;
  }
 }
 printf("BW_VMDIO: final path = %s\n", dev_path);
 return ;
failed:
 return ;
}

canonical_original_code:
void follow_link(char *src_path)
{
 struct stat st;
 int ret;
 long sym_len;
 char *dev_path = ((void *)0);
 char *sym_path = ((void *)0);
 sym_path = calloc(1, 4096);
 dev_path = calloc(1, 4096);
 if (src_path[0] != '/') {
  if (getcwd(dev_path, 4096 -1) == ((void *)0)) {
   printf("BW_VMDIO:Get cwd error. %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  }
  strcat(dev_path, "/");
 }
 strncat(dev_path, src_path, 4096 -strlen(dev_path)-1);
 while (1) {
  ret = lstat(dev_path, &st);
  if (ret) {
   printf("BW_VMDIO:stat %s failed.\n", dev_path);
   goto failed;
  }
  if (((((st.st_mode)) & 0170000) == (0120000))) {
   sym_len = readlink(dev_path, sym_path, 4096 -1);
   if (sym_len < 0) {
    printf("BW_VMDIO:read link %s failed\n", dev_path);
    goto failed;
   }
   sym_path[sym_len] = '\0';
   if (sym_path[0] == '/') {
    strcpy(dev_path, sym_path);
   } else {
    dirname(dev_path);
    strcat(dev_path, "/");
    strncat(dev_path, sym_path, 4096 -strlen(dev_path)-1);
   }
   continue;
  } else if (((((st.st_mode)) & 0170000) == (0060000))) {
   break;
  } else {
   printf("BW_VMDIO:%s unkown file mode %o\n", dev_path, st.st_mode);
   goto failed;
  }
 }
 printf("BW_VMDIO: final path = %s\n", dev_path);
 return ;
failed:
 return ;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: ret int


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

if ( argc <= 1 )
{
puts("Provide a path.");
}
else
{
v3 = strdup(argv[1]);
follow_link(v3);
}
return 0;
}

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

if ( argc <= 1 )
{
puts("Provide a path.");
}
else
{
v3 = strdup(argv[1]);
func7(v3);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 char *file_path;
 if (argc < 2) {
  printf("Provide a path.\n");
  goto out;
 }
 file_path = strdup(argv[1]);
 follow_link(file_path);
out:
 return 0;
}


decompiled_code:
__int64 __fastcall gen_dir(const char *a1)
{
unsigned int v1; // ebx
int *v2; // rbp
char *v3; // rax

v1 = mkdir(a1, 0x1EDu);
if ( v1 )
{
v2 = __errno_location();
if ( *v2 == 17 )
{
v1 = 0;
}
else
{
v3 = strerror(*v2);
printf("ret=%d,errno=%d(%s)\n", v1, (unsigned int)*v2, v3);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned int v1; // ebx
int *v2; // rbp
char *v3; // rax

v1 = mkdir(a1, 0x1EDu);
if ( v1 )
{
v2 = __errno_location();
if ( *v2 == 17 )
{
v1 = 0;
}
else
{
v3 = strerror(*v2);
printf("ret=%d,errno=%d(%s)\n", v1, (unsigned int)*v2, v3);
}
}
return v1;
}

original_code:
int gen_dir(char *path)
{
 int ret = 0;
 ret = mkdir(path, 0755);
 if (ret && (*__errno_location ())==17) {
  ret = 0;
 } else if (ret) {
  printf("ret=%d,errno=%d(%s)\n", ret, (*__errno_location ()), strerror((*__errno_location ())));
 }
 return ret;
}

variable_types:
path
char *


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

v1 = strdup(a1);
v2 = dirname(v1);
return gen_dir(v2);
}

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

v1 = strdup(a1);
v2 = dirname(v1);
return func7(v2);
}

original_code:
int gen_parent(char *path)
{
 char *dirpath;
 dirpath = dirname(strdup(path));
 return gen_dir(dirpath);
}

variable_types:
dirpath
char *


decompiled_code:
__int64 __fastcall lock_pidfile(int fd, int a2)
{
int i; // ebp
unsigned int v3; // ebx

for ( i = a2; ; --i )
{
v3 = flock(fd, a2 == 0 ? 2 : 6);
if ( !v3 || *__errno_location() != 11 || !i )
break;
sleep(1u);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, int a2)
{
int i; // ebp
unsigned int v3; // ebx

for ( i = a2; ; --i )
{
v3 = flock(fd, a2 == 0 ? 2 : 6);
if ( !v3 || *__errno_location() != 11 || !i )
break;
sleep(1u);
}
return v3;
}

original_code:
int lock_pidfile(int fd, uint32_t timeo)
{
 int ret = -1;
 int lock_mode = 2;
 if (timeo != 0)
  lock_mode |= 4;
 while (ret) {
  ret = flock(fd, lock_mode);
  if (ret == 0)
   break;
  if ((*__errno_location ()) != 11)
   break;
  if (timeo == 0)
   break;
  sleep(1);
  timeo--;
 }
 return ret;
}

canonical_original_code:
int lock_pidfile(int fd, unsigned int timeo)
{
 int ret = -1;
 int lock_mode = 2;
 if (timeo != 0)
  lock_mode |= 4;
 while (ret) {
  ret = flock(fd, lock_mode);
  if (ret == 0)
   break;
  if ((*__errno_location ()) != 11)
   break;
  if (timeo == 0)
   break;
  sleep(1);
  timeo--;
 }
 return ret;
}

variable_types: fd int

variable_types:
timeo
unsigned int


decompiled_code:
__int64 __fastcall unlock_pidfile(int a1)
{
unsigned int v1; // ebx
int *v3; // rbp
char *v4; // rax

v1 = flock(a1, 8);
if ( v1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("unlock error.%d(%s)\n", (unsigned int)*v3, v4);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
unsigned int v1; // ebx
int *v3; // rbp
char *v4; // rax

v1 = flock(a1, 8);
if ( v1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("unlock error.%d(%s)\n", (unsigned int)*v3, v4);
}
return v1;
}

original_code:
int unlock_pidfile(int fd)
{
 int ret = 0;
 ret = flock(fd, 8);
 if (ret) {
  printf("unlock error.%d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  goto out;
 }
out:
 return ret;
}


decompiled_code:
__int64 __fastcall get_right(char *file)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rbx
char *v5; // rax

if ( (unsigned int)gen_parent(file) )
{
puts("gen_parent error");
v2 = -1;
}
else
{
v1 = open(file, 66, 420LL);
v2 = v1;
if ( v1 < 0 )
{
v4 = __errno_location();
v5 = strerror(*v4);
printf("open error, %d(%s)\n", (unsigned int)*v4, v5);
v2 = -1;
}
else if ( (unsigned int)lock_pidfile(v1, 10) )
{
puts("lock_pidfile error");
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *file)
{
int v1; // eax
unsigned int v2; // ebx
int *v4; // rbx
char *v5; // rax

if ( (unsigned int)func8(file) )
{
puts("gen_parent error");
v2 = -1;
}
else
{
v1 = open(file, 66, 420LL);
v2 = v1;
if ( v1 < 0 )
{
v4 = __errno_location();
v5 = strerror(*v4);
printf("open error, %d(%s)\n", (unsigned int)*v4, v5);
v2 = -1;
}
else if ( (unsigned int)func9(v1, 10) )
{
puts("lock_pidfile error");
v2 = -1;
}
}
return v2;
}

original_code:
int get_right(char *pid_path)
{
 int ret, fd;
 ret = gen_parent(pid_path);
 if (ret) {
  printf("gen_parent error\n");
  goto fail;
 }
 fd = open(pid_path, 02|0100, 0644);
 if (fd < 0) {
  printf("open error, %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  ret = (*__errno_location ());
  goto fail;
 }
 ret = lock_pidfile(fd, 10);
 if (ret) {
  printf("lock_pidfile error\n");
  goto fail;
 }
 return fd;
fail:
 return -1;
}

canonical_original_code:
int get_right(char *pid_path)
{
 int ret; int fd;
 ret = gen_parent(pid_path);
 if (ret) {
  printf("gen_parent error\n");
  goto fail;
 }
 fd = open(pid_path, 02|0100, 0644);
 if (fd < 0) {
  printf("open error, %d(%s)\n", (*__errno_location ()), strerror((*__errno_location ())));
  ret = (*__errno_location ());
  goto fail;
 }
 ret = lock_pidfile(fd, 10);
 if (ret) {
  printf("lock_pidfile error\n");
  goto fail;
 }
 return fd;
fail:
 return -1;
}


decompiled_code:
__int64 __fastcall put_right(int a1)
{
return unlock_pidfile(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return func10(a1);
}

original_code:
int put_right(int fd)
{
 return unlock_pidfile(fd);
}


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

v3 = get_right("/var/log/test.pid");
if ( v3 < 0 )
puts("get right fail");
sleep(0xAu);
put_right(v3);
return 0;
}

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

v3 = func11("/var/log/test.pid");
if ( v3 < 0 )
puts("get right fail");
sleep(0xAu);
func12(v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int fd;
 fd = get_right("/var/log/test.pid");
 if (fd < 0)
  printf("get right fail\n");
 sleep(10);
 put_right(fd);
 return 0;
}


decompiled_code:
void __fastcall sig_handler(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
printf("recieve msg:%d, at:%d\n", a1, tv.tv_sec);
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1)
{
struct timezone tz; // [rsp+8h] [rbp-20h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, &tz);
printf("recieve msg:%d, at:%d\n", a1, tv.tv_sec);
}

original_code:
void sig_handler(int signum)
{
 struct timeval tv;
 struct timezone tz;
 gettimeofday(&tv, &tz);
 printf("recieve msg:%d, at:%d\n", signum, tv.tv_sec);
}

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


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

gettimeofday(&v1, 0LL);
printf("tm1:interval=%u.%u\n", v1.tv_sec - tm1_last.tv_sec, v1.tv_usec - tm1_last.tv_usec);
tm1_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return 0LL;
}

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

gettimeofday(&v1, 0LL);
printf("tm1:interval=%u.%u\n", v1.tv_sec - tm1_last.tv_sec, v1.tv_usec - tm1_last.tv_usec);
tm1_last = (struct timeval)_mm_loadu_si128((const __m128i *)&v1);
return 0LL;
}

original_code:
int32_t tm1_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm1:interval=%u.%u\n",
   tm_now.tv_sec-tm1_last.tv_sec, tm_now.tv_usec-tm1_last.tv_usec);
 tm1_last = tm_now;
 return 0;
}

canonical_original_code:
int tm1_handler(void *args)
{
 struct timeval tm_now;
 gettimeofday(&tm_now, ((void *)0));
 printf("tm1:interval=%u.%u\n",
   tm_now.tv_sec-tm1_last.tv_sec, tm_now.tv_usec-tm1_last.tv_usec);
 tm1_last = tm_now;
 return 0;
}

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