decompiled_code:
__int64 __fastcall send_message(__int64 a1, unsigned int a2)
{
_DWORD *i; // rbp
__int64 result; // rax

for ( i = *(_DWORD **)a1; ; *(_DWORD *)(a1 + 28) = i[6] )
{
puts("Hello");
if ( *(_DWORD *)(a1 + 28) )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 32))(a1 + 16, a2);
if ( (_DWORD)result != 5 )
return result;
list_del((__int64)i);
free(i);
}
if ( list_empty((_QWORD *)a1) )
break;
i = *(_DWORD **)a1;
*(_QWORD *)(a1 + 16) = *(_QWORD *)a1 + 72LL;
}
return 5LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
_DWORD *i; // rbp
__int64 result; // rax

for ( i = *(_DWORD **)a1; ; *(_DWORD *)(a1 + 28) = i[6] )
{
puts("Hello");
if ( *(_DWORD *)(a1 + 28) )
{
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(a1 + 32))(a1 + 16, a2);
if ( (_DWORD)result != 5 )
return result;
func1((__int64)i);
free(i);
}
if ( func2((_QWORD *)a1) )
break;
i = *(_DWORD **)a1;
*(_QWORD *)(a1 + 16) = *(_QWORD *)a1 + 72LL;
}
return 5LL;
}

original_code:
int send_message(struct message_send_queue * queue, int skfd)
{
 int ret;
 struct message_packet * msg;
 msg = (struct message_packet *)((char *)((&queue->msg_list)->next) - ((size_t) &((struct message_packet *)0)->next));
 while (1)
 {
  printf("Hello\n");
  if (queue->status.left)
  {
   ret = queue->put_msg(&queue->status, skfd);
   if (ret == MSG_SEND_FINISH)
   {
    list_del(&msg->next);
    free(msg);
   }
   else
   {
    return ret;
   }
  }
  if (list_empty(&queue->msg_list))
   break;
  msg = (struct message_packet *)((char *)((&queue->msg_list)->next) - ((size_t) &((struct message_packet *)0)->next));
  queue->status.position = msg->content;
  queue->status.left = msg->length;
 }
 return MSG_SEND_FINISH;
}

canonical_original_code:
int send_message(struct message_send_queue *queue, int skfd)
{
 int ret;
 struct message_packet *msg;
 msg = (struct message_packet *)((char *)((&queue->msg_list)->next) - ((unsigned long) &((struct message_packet *)0)->next));
 while (1)
 {
  printf("Hello\n");
  if (queue->status.left)
  {
   ret = queue->put_msg(&queue->status, skfd);
   if (ret == MSG_SEND_FINISH)
   {
    list_del(&msg->next);
    free(msg);
   }
   else
   {
    return ret;
   }
  }
  if (list_empty(&queue->msg_list))
   break;
  msg = (struct message_packet *)((char *)((&queue->msg_list)->next) - ((unsigned long) &((struct message_packet *)0)->next));
  queue->status.position = msg->content;
  queue->status.left = msg->length;
 }
 return MSG_SEND_FINISH;
}

variable_types: struct message_send_queue { struct list_head { struct list_head *next; } msg_list; struct msg_status { char *position; int phase; int left; } status; int (*put_msg)(struct msg_status *status, int skfd); } *

variable_types: skfd int

variable_types: ret int

user_defined_types: struct message_send_queue { struct list_head msg_list; struct msg_status status; int (*put_msg)(struct msg_status *status, int skfd); }


repo: No-name/ball

decompiled_code:
__int64 __fastcall get_message(_DWORD *a1, char **a2, int a3)
{
char *v4; // rbp
int v5; // ebx
signed int v6; // eax
unsigned int v7; // edx
int *v8; // rax

v4 = *a2;
v5 = *((_DWORD *)a2 + 3);
while ( 1 )
{
v6 = read(a3, v4, v5);
v7 = v6;
if ( v6 == -1 )
break;
if ( !v6 )
return v7;
v4 += v6;
v5 -= v6;
if ( !v5 )
{
if ( *((_DWORD *)a2 + 2) )
{
message_parse_body((__int64)a1);
return 2;
}
message_parse_head(a1);
*a2 = v4;
v5 = a1[6] - 12;
*((_DWORD *)a2 + 3) = v5;
*((_DWORD *)a2 + 2) = 1;
}
}
v8 = _errno_location();
v7 = 0;
if ( *v8 == 11 )
{
*a2 = v4;
*((_DWORD *)a2 + 3) = v5;
v7 = 1;
}
return v7;
}

original_code:
int get_message(struct message_packet * msg, struct msg_status * status, int fd)
{
 int rbyte;
 char * p;
 int left;
 p = status->position;
 left = status->left;
 while (1)
 {
  rbyte = read(fd, p, left);
  if (rbyte == -1)
  {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
   {
    break;
   }
   return MSG_GET_FAILED;
  }
  else if (rbyte == 0)
  {
   return MSG_GET_FAILED;
  }
  p += rbyte;
  left -= rbyte;
  if (left == 0)
  {
   if (status->phase == MSG_PHASE_GET_HEAD)
   {
    message_parse_head(msg);
    status->position = p;
    status->left = msg->length - 12;
    status->phase = MSG_PHASE_GET_BODY;
    left = status->left;
   }
   else
   {
    message_parse_body(msg);
    return MSG_GET_FINISH;
   }
  }
 }
 status->position = p;
 status->left = left;
 return MSG_GET_AGAIN;
}

canonical_original_code:
int get_message(struct message_packet *msg, struct msg_status *status, int fd)
{
 int rbyte;
 char *p;
 int left;
 p = status->position;
 left = status->left;
 while (1)
 {
  rbyte = read(fd, p, left);
  if (rbyte == -1)
  {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
   {
    break;
   }
   return MSG_GET_FAILED;
  }
  else if (rbyte == 0)
  {
   return MSG_GET_FAILED;
  }
  p += rbyte;
  left -= rbyte;
  if (left == 0)
  {
   if (status->phase == MSG_PHASE_GET_HEAD)
   {
    message_parse_head(msg);
    status->position = p;
    status->left = msg->length - 12;
    status->phase = MSG_PHASE_GET_BODY;
    left = status->left;
   }
   else
   {
    message_parse_body(msg);
    return MSG_GET_FINISH;
   }
  }
 }
 status->position = p;
 status->left = left;
 return MSG_GET_AGAIN;
}

variable_types: struct message_packet { struct list_head { struct list_head *next; } next; int msg_is_ok; int type; int length; int version; union { struct { int name_len; int passwd_len; char *name; char *passwd; } login_info; struct { int from_len; int to_len; int msg_len; char *from; char *to; char *msg; } chart_info; struct { int more; char *start; char *end; } peer_list; }; char content[1024]; } *

variable_types: struct msg_status { char *position; int phase; int left; } *

variable_types: fd int

variable_types: rbyte int

variable_types:
p
char *

variable_types: left int

return_type: int

user_defined_types: struct message_packet { struct list_head next; int msg_is_ok; int type; int length; int version; union { struct { int name_len; int passwd_len; char *name; char *passwd; } login_info; struct { int from_len; int to_len; int msg_len; char *from; char *to; char *msg; } chart_info; struct { int more; char *start; char *end; } peer_list; }; char content[1024]; }


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

result = (char *)malloc(0x448uLL);
*(_QWORD *)a1 = result + 72;
*(_DWORD *)(a1 + 12) = 12;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

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

result = (char *)malloc(0x448uLL);
*(_QWORD *)a1 = result + 72;
*(_DWORD *)(a1 + 12) = 12;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

original_code:
struct message_packet * initial_new_input_msg(struct msg_status * status)
{
 struct message_packet * packet;
 packet = malloc(sizeof(struct message_packet));
 status->position = packet->content;
 status->left = 12;
 status->phase = MSG_PHASE_GET_HEAD;
 return packet;
}

canonical_original_code:
struct message_packet *initial_new_input_msg(struct msg_status *status)
{
 struct message_packet *packet;
 packet = malloc(sizeof(struct message_packet));
 status->position = packet->content;
 status->left = 12;
 status->phase = MSG_PHASE_GET_HEAD;
 return packet;
}

return_type: struct message_packet { struct list_head { struct list_head *next; } next; int msg_is_ok; int type; int length; int version; union { struct { int name_len; int passwd_len; char *name; char *passwd; } login_info; struct { int from_len; int to_len; int msg_len; char *from; char *to; char *msg; } chart_info; struct { int more; char *start; char *end; } peer_list; }; char content[1024]; } *

user_defined_types: struct msg_status { char *position; int phase; int left; }


repo: No-name/smooth

decompiled_code:
int __fastcall smooth_lib_present_buf(__int64 a1, int a2)
{
__int64 i; // rbx
const char *v3; // rdx

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; printf("%02x%s", (unsigned int)*(char *)(a1 + i++), v3) )
{
v3 = (const char *)&unk_9C;
if ( (int)i % 20 == 19 )
v3 = (const char *)&unk_9A;
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
__int64 i; // rbx
const char *v3; // rdx

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; printf("%02x%s", (unsigned int)*(char *)(a1 + i++), v3) )
{
v3 = (const char *)&unk_9C;
if ( (int)i % 20 == 19 )
v3 = (const char *)&unk_9A;
}
}
return putchar(10);
}

original_code:
void smooth_lib_present_buf(char * buf, int len)
{
 int i;
 for (i = 0; i < len; ++i)
 {
  printf("%02x%s", buf[i], i % 20 == 19 ? "\n" : " ");
 }
 printf("\n");
}

canonical_original_code:
void smooth_lib_present_buf(char *buf, int len)
{
 int i;
 for (i = 0; i < len; ++i)
 {
  printf("%02x%s", buf[i], i % 20 == 19 ? "\n" : " ");
 }
 printf("\n");
}

variable_types:
buf
char *

variable_types: len int

variable_types: i int

return_type: void


echoDataHandler

decompiled_code:
ssize_t __fastcall echoDataHandler(int fd)
{
ssize_t result; // rax
char buf[2064]; // [rsp+0h] [rbp-810h] BYREF

while ( 1 )
{
result = read(fd, buf, 0x800uLL);
if ( (int)result <= 0 )
break;
if ( write(fd, buf, (int)result) != (int)result )
fwrite("Write failed\n", 1uLL, 0xDuLL, stderr);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int fd)
{
ssize_t result; // rax
char buf[2064]; // [rsp+0h] [rbp-810h] BYREF

while ( 1 )
{
result = read(fd, buf, 0x800uLL);
if ( (int)result <= 0 )
break;
if ( write(fd, buf, (int)result) != (int)result )
fwrite("Write failed\n", 1uLL, 0xDuLL, stderr);
}
return result;
}

original_code:
static void echoDataHandler(int cfd)
{
 char buf[2048];
 int readed;
 while ((readed = read(cfd, buf, sizeof(buf))) > 0)
 {
  if (write(cfd, buf, readed) != readed)
  {
   fprintf(stderr, "Write failed\n");
  }
 }
}

variable_types: cfd int

variable_types:
buf
char [2048]

variable_types: readed int


discardDataHandler

decompiled_code:
ssize_t __fastcall discardDataHandler(int fd)
{
ssize_t result; // rax
char buf[2056]; // [rsp+0h] [rbp-810h] BYREF

do
result = read(fd, buf, 0x800uLL);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd)
{
ssize_t result; // rax
char buf[2056]; // [rsp+0h] [rbp-810h] BYREF

do
result = read(fd, buf, 0x800uLL);
while ( result > 0 );
return result;
}

original_code:
static void discardDataHandler(int cfd)
{
 char buf[2048];
 while (read(cfd, buf, sizeof(buf)) > 0)
  asm("");
}


tcpServer

decompiled_code:
void __fastcall __noreturn tcpServer(void (__fastcall *a1)(_QWORD))
{
int v1; // eax
int v2; // er12
unsigned int v3; // eax
int v4; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-30h] BYREF

addr_len = 16;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(4242);
v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
if ( bind(v1, &addr, 0x10u) == -1 || listen(v2, 10) == -1 )
{
perror("Socket bind failed");
exit(1);
}
puts("tcpechoServer started !");
while ( 1 )
{
v3 = accept(v2, &addr, &addr_len);
v4 = v3;
if ( v3 == -1 )
break;
a1(v3);
close(v4);
puts("Client disconnected.");
}
fwrite("Accept failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
perror("Socket creation failed");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(void (__fastcall *a1)(_QWORD))
{
int v1; // eax
int v2; // er12
unsigned int v3; // eax
int v4; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-30h] BYREF

addr_len = 16;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func2(4242);
v1 = socket(2, 1, 0);
if ( v1 != -1 )
{
v2 = v1;
if ( bind(v1, &addr, 0x10u) == -1 || listen(v2, 10) == -1 )
{
perror("Socket bind failed");
exit(1);
}
puts("tcpechoServer started !");
while ( 1 )
{
v3 = accept(v2, &addr, &addr_len);
v4 = v3;
if ( v3 == -1 )
break;
a1(v3);
close(v4);
puts("Client disconnected.");
}
fwrite("Accept failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
perror("Socket creation failed");
exit(1);
}

original_code:
static void tcpServer(void (*dataHandler)(int))
{
 struct sockaddr_in sin;
 int sfd;
 int cfd;
        socklen_t sinlen;
        sinlen = sizeof(sin);
 memset(&sin, 0, sizeof(sin));
 sin.sin_family = 2;
 sin.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 sin.sin_port = htons(4242);
 if ((sfd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("Socket creation failed");
  exit(1);
 }
 if (bind(sfd, (const struct sockaddr *)&sin, sizeof(sin)) == -1 ||
  listen(sfd, 10) == -1)
 {
  perror("Socket bind failed");
  exit(1);
 }
 puts("tcpechoServer started !");
 while (42)
 {
  if ((cfd = accept(sfd, (struct sockaddr *)&sin, &sinlen)) == -1)
  {
   fprintf(stderr, "Accept failed\n");
   exit(1);
  }
  dataHandler(cfd);
  close(cfd);
  puts("Client disconnected.");
 }
 close(sfd);
 puts("tcpechoServer shuted down.");
}

canonical_original_code:
static void tcpServer(void (*dataHandler)(int))
{
 struct sockaddr_in sin;
 int sfd;
 int cfd;
        unsigned int sinlen;
        sinlen = sizeof(sin);
 memset(&sin, 0, sizeof(sin));
 sin.sin_family = 2;
 sin.sin_addr.s_addr = ((unsigned int) 0x00000000);
 sin.sin_port = htons(4242);
 if ((sfd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("Socket creation failed");
  exit(1);
 }
 if (bind(sfd, (struct sockaddr *)&sin, sizeof(sin)) == -1 ||
  listen(sfd, 10) == -1)
 {
  perror("Socket bind failed");
  exit(1);
 }
 puts("tcpechoServer started !");
 while (42)
 {
  if ((cfd = accept(sfd, (struct sockaddr *)&sin, &sinlen)) == -1)
  {
   fprintf(stderr, "Accept failed\n");
   exit(1);
  }
  dataHandler(cfd);
  close(cfd);
  puts("Client disconnected.");
 }
 close(sfd);
 puts("tcpechoServer shuted down.");
}

variable_types:
dataHandler
void (*)(int)

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

variable_types: sfd int

variable_types:
sinlen
unsigned int

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

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


initClient

decompiled_code:
__int64 __fastcall initClient(char *name, __int64 a2)
{
__int16 v2; // ax
struct hostent *v3; // rax
__int64 result; // rax
int *v5; // rax
char *v6; // rax

if ( name )
{
v2 = _bswap_16(4242);
*(_WORD *)(a2 + 2) = v2;
if ( v2 )
{
v3 = gethostbyname(name);
if ( v3 )
{
*(_DWORD *)(a2 + 4) = **(_DWORD **)v3->h_addr_list;
*(_WORD *)a2 = 2;
result = 0LL;
}
else
{
v5 = _h_errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Error resolving \"%s\" : %s.\n", name, v6);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("Bad port number.\n", 1uLL, 0x11uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("No remote hostname given.\n", 1uLL, 0x1AuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *name, __int64 a2)
{
__int16 v2; // ax
struct hostent *v3; // rax
__int64 result; // rax
int *v5; // rax
char *v6; // rax

if ( name )
{
v2 = func2(4242);
*(_WORD *)(a2 + 2) = v2;
if ( v2 )
{
v3 = gethostbyname(name);
if ( v3 )
{
*(_DWORD *)(a2 + 4) = **(_DWORD **)v3->h_addr_list;
*(_WORD *)a2 = 2;
result = 0LL;
}
else
{
v5 = _h_errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Error resolving \"%s\" : %s.\n", name, v6);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("Bad port number.\n", 1uLL, 0x11uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("No remote hostname given.\n", 1uLL, 0x1AuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int initClient(char *host, struct sockaddr_in *sin)
{
        struct hostent *h;
 if (!host)
  fprintf(stderr, "No remote hostname given.\n");
        else if (!(sin->sin_port = htons(4242)))
                fputs("Bad port number.\n", stderr);
        else if (!(h = gethostbyname(host)))
                fprintf(stderr, "Error resolving \"%s\" : %s.\n",
                 host, strerror((*__h_errno_location ())));
        else
        {
  memcpy(&(sin->sin_addr), h->h_addr_list[0], sizeof(sin->sin_addr));
                sin->sin_family = 2;
  return (0);
 }
 return (-1);
}

variable_types:
host
char *

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


tcpechoServer

decompiled_code:
void __noreturn tcpechoServer()
{
tcpServer((void (__fastcall *)(_QWORD))echoDataHandler);
}

canonical_decompiled_code:
void __noreturn func5()
{
func3((void (__fastcall *)(_QWORD))echoDataHandler);
}

original_code:
void tcpechoServer(char **arg)
{
 tcpServer(&echoDataHandler);
}

variable_types:
arg
char **


tcpdiscardServer

decompiled_code:
void __noreturn tcpdiscardServer()
{
tcpServer((void (__fastcall *)(_QWORD))discardDataHandler);
}

canonical_decompiled_code:
void __noreturn func6()
{
func3((void (__fastcall *)(_QWORD))discardDataHandler);
}

original_code:
void tcpdiscardServer(char **arg)
{
 tcpServer(&discardDataHandler);
}


tcpechoClient

decompiled_code:
int __fastcall tcpechoClient(char **a1)
{
int v1; // eax
int v2; // er12
unsigned __int64 v3; // r13
int v4; // er9
unsigned int v5; // ebx
__int64 v6; // rsi
double v7; // r13
char buf[2048]; // [rsp+0h] [rbp-830h] BYREF
struct sockaddr addr; // [rsp+800h] [rbp-30h] BYREF

memset(buf, 42, 1460);
if ( (unsigned int)initClient(*a1, (__int64)&addr) == -1 )
exit(1);
v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("Socket creation failed.");
exit(1);
}
if ( connect(v1, &addr, 0x10u) )
{
perror("Socket connect failed");
exit(1);
}
v3 = __rdtsc();
v4 = gl_loopcycle;
if ( gl_loopcycle )
{
v5 = 0;
do
{
if ( write(v2, buf, 0x5B4uLL) != 1460 || read(v2, buf, 0x5B4uLL) != 1460 )
{
perror("Write or read failed");
exit(1);
}
++v5;
v4 = gl_loopcycle;
}
while ( gl_loopcycle > v5 );
}
v6 = __rdtsc() - v3;
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf(
"Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n",
v6,
v7 / (double)v4,
(unsigned int)v4);
gl_lastavgres = v7 / (double)gl_loopcycle;
return close(v2);
}

canonical_decompiled_code:
int __fastcall func7(char **a1)
{
int v1; // eax
int v2; // er12
unsigned __int64 v3; // r13
int v4; // er9
unsigned int v5; // ebx
__int64 v6; // rsi
double v7; // r13
char buf[2048]; // [rsp+0h] [rbp-830h] BYREF
struct sockaddr addr; // [rsp+800h] [rbp-30h] BYREF

memset(buf, 42, 1460);
if ( (unsigned int)func4(*a1, (__int64)&addr) == -1 )
exit(1);
v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("Socket creation failed.");
exit(1);
}
if ( connect(v1, &addr, 0x10u) )
{
perror("Socket connect failed");
exit(1);
}
v3 = __rdtsc();
v4 = gl_loopcycle;
if ( gl_loopcycle )
{
v5 = 0;
do
{
if ( write(v2, buf, 0x5B4uLL) != 1460 || read(v2, buf, 0x5B4uLL) != 1460 )
{
perror("Write or read failed");
exit(1);
}
++v5;
v4 = gl_loopcycle;
}
while ( gl_loopcycle > v5 );
}
v6 = __rdtsc() - v3;
if ( v6 < 0 )
v7 = (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1)) + (double)(int)(v6 & 1 | ((unsigned __int64)v6 >> 1));
else
v7 = (double)(int)v6;
printf(
"Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n",
v6,
v7 / (double)v4,
(unsigned int)v4);
gl_lastavgres = v7 / (double)gl_loopcycle;
return close(v2);
}

original_code:
void tcpechoClient(char **arg)
{
        struct sockaddr_in sin;
        int sfd;
 char buf[2048];
 memset(buf, 42, 1460);
 if (initClient(*arg, &sin) == -1)
  exit(1);
 if ((sfd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("Socket creation failed.");
  exit(1);
 }
 if (connect(sfd, (struct sockaddr *)&sin, sizeof(sin)))
 {
  perror("Socket connect failed");
  exit(1);
 }
 { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (write(sfd, buf, 1460) != 1460 || read(sfd, buf, 1460) != 1460) { perror("Write or read failed"); exit(1); }; } c = rdtsc(); if (1) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
 close(sfd);
}

variable_types:
b
unsigned long long

variable_types:
c
unsigned long long

variable_types:
measureloopcnt
unsigned int


tcpbandwidthClient

decompiled_code:
int __fastcall tcpbandwidthClient(char **a1)
{
int v1; // eax
int v2; // er12
unsigned __int64 v3; // r13
int v4; // er9
__int64 v5; // rsi
double v6; // r14
unsigned int v8; // er15
int i; // ebx
int v10; // eax
char buf[2048]; // [rsp+0h] [rbp-840h] BYREF
struct sockaddr addr; // [rsp+800h] [rbp-40h] BYREF

memset(buf, 42, 1460);
if ( (unsigned int)initClient(*a1, (__int64)&addr) == -1 )
exit(1);
v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("Socket creation failed.");
exit(1);
}
if ( connect(v1, &addr, 0x10u) )
{
perror("Socket connect failed");
exit(1);
}
v3 = __rdtsc();
v4 = gl_loopcycle;
if ( gl_loopcycle )
{
v8 = 0;
do
{
for ( i = 0; i >= 0; i += v10 )
{
v10 = write(v2, buf, 0x5B4uLL);
if ( v10 == -1 )
{
perror("Write failed");
exit(1);
}
}
++v8;
v4 = gl_loopcycle;
}
while ( gl_loopcycle > v8 );
}
v5 = __rdtsc() - v3;
if ( v5 < 0 )
v6 = (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1)) + (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1));
else
v6 = (double)(int)v5;
printf(
"Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n",
v5,
v6 / (double)v4,
(unsigned int)v4);
gl_lastavgres = v6 / (double)gl_loopcycle;
return close(v2);
}

canonical_decompiled_code:
int __fastcall func8(char **a1)
{
int v1; // eax
int v2; // er12
unsigned __int64 v3; // r13
int v4; // er9
__int64 v5; // rsi
double v6; // r14
unsigned int v8; // er15
int i; // ebx
int v10; // eax
char buf[2048]; // [rsp+0h] [rbp-840h] BYREF
struct sockaddr addr; // [rsp+800h] [rbp-40h] BYREF

memset(buf, 42, 1460);
if ( (unsigned int)func4(*a1, (__int64)&addr) == -1 )
exit(1);
v1 = socket(2, 1, 0);
v2 = v1;
if ( v1 == -1 )
{
perror("Socket creation failed.");
exit(1);
}
if ( connect(v1, &addr, 0x10u) )
{
perror("Socket connect failed");
exit(1);
}
v3 = __rdtsc();
v4 = gl_loopcycle;
if ( gl_loopcycle )
{
v8 = 0;
do
{
for ( i = 0; i >= 0; i += v10 )
{
v10 = write(v2, buf, 0x5B4uLL);
if ( v10 == -1 )
{
perror("Write failed");
exit(1);
}
}
++v8;
v4 = gl_loopcycle;
}
while ( gl_loopcycle > v8 );
}
v5 = __rdtsc() - v3;
if ( v5 < 0 )
v6 = (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1)) + (double)(int)(v5 & 1 | ((unsigned __int64)v5 >> 1));
else
v6 = (double)(int)v5;
printf(
"Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n",
v5,
v6 / (double)v4,
(unsigned int)v4);
gl_lastavgres = v6 / (double)gl_loopcycle;
return close(v2);
}

original_code:
void tcpbandwidthClient(char **arg)
{
        struct sockaddr_in sin;
        int sfd;
 char buf[2048];
 int res;
 int written;
 memset(buf, 42, 1460);
 if (initClient(*arg, &sin) == -1)
  exit(1);
 if ((sfd = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("Socket creation failed.");
  exit(1);
 }
 if (connect(sfd, (struct sockaddr *)&sin, sizeof(sin)))
 {
  perror("Socket connect failed");
  exit(1);
 }
 { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ res = 0; while (res < ((unsigned int)(1 << 30) * 2)) { if ((written = write(sfd, buf, 1460)) == -1) { perror("Write failed"); exit(1); } res += written; }; } c = rdtsc(); if (1) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
 close(sfd);
}

variable_types: res int

variable_types: written int


tcpconnectClient

decompiled_code:
int __fastcall tcpconnectClient(char **a1)
{
unsigned int v1; // er9
unsigned int v2; // er12
unsigned __int64 v3; // r13
unsigned __int64 i; // r14
int v5; // er15
unsigned __int64 v6; // rbx
unsigned __int64 v7; // rbx
unsigned __int64 v8; // rax
struct sockaddr addr; // [rsp+0h] [rbp-50h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-40h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 1000000LL;
if ( (unsigned int)initClient(*a1, (__int64)&addr) == -1 )
exit(1);
v1 = gl_loopcycle;
v2 = 0;
v3 = 0LL;
for ( i = 0LL; gl_loopcycle > v2; v1 = gl_loopcycle )
{
v5 = socket(2, 1, 0);
if ( v5 == -1 )
{
perror("Socket creation failed.");
exit(1);
}
v6 = __rdtsc();
if ( connect(v5, &addr, 0x10u) )
{
perror("Socket connect failed");
exit(1);
}
i += __rdtsc() - v6;
v7 = __rdtsc();
close(v5);
v8 = __rdtsc();
v3 += ((unsigned int)v8 | ((unsigned __int64)HIDWORD(v8) << 32)) - v7;
nanosleep(&requested_time, 0LL);
++v2;
}
printf("Connection avg time : %lld\n", i / v1);
return printf("Close avg time : %lld\n", v3 / gl_loopcycle);
}

canonical_decompiled_code:
int __fastcall func9(char **a1)
{
unsigned int v1; // er9
unsigned int v2; // er12
unsigned __int64 v3; // r13
unsigned __int64 i; // r14
int v5; // er15
unsigned __int64 v6; // rbx
unsigned __int64 v7; // rbx
unsigned __int64 v8; // rax
struct sockaddr addr; // [rsp+0h] [rbp-50h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-40h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 1000000LL;
if ( (unsigned int)func4(*a1, (__int64)&addr) == -1 )
exit(1);
v1 = gl_loopcycle;
v2 = 0;
v3 = 0LL;
for ( i = 0LL; gl_loopcycle > v2; v1 = gl_loopcycle )
{
v5 = socket(2, 1, 0);
if ( v5 == -1 )
{
perror("Socket creation failed.");
exit(1);
}
v6 = __rdtsc();
if ( connect(v5, &addr, 0x10u) )
{
perror("Socket connect failed");
exit(1);
}
i += __rdtsc() - v6;
v7 = __rdtsc();
close(v5);
v8 = __rdtsc();
v3 += ((unsigned int)v8 | ((unsigned __int64)HIDWORD(v8) << 32)) - v7;
nanosleep(&requested_time, 0LL);
++v2;
}
printf("Connection avg time : %lld\n", i / v1);
return printf("Close avg time : %lld\n", v3 / gl_loopcycle);
}

original_code:
void tcpconnectClient(char **arg)
{
 struct timespec pauseTime;
        struct sockaddr_in sin;
 unsigned long long b, c, con = 0, clo = 0;
        int sfd, i;
 pauseTime.tv_sec = 0;
 pauseTime.tv_nsec = 1000000;
 if (initClient(*arg, &sin) == -1)
  exit(1);
 for (i = 0; i < gl_loopcycle; i++)
 {
  if ((sfd = socket(2, SOCK_STREAM, 0)) == -1)
  {
   perror("Socket creation failed.");
   exit(1);
  }
  b = rdtsc();
  if (connect(sfd, (struct sockaddr *)&sin, sizeof(sin)))
  {
   perror("Socket connect failed");
   exit(1);
  }
  c = rdtsc();
  con += c - b;
  b = rdtsc();
  close(sfd);
  c = rdtsc();
  clo += c - b;
  nanosleep(&pauseTime, ((void *)0));
 }
 printf("Connection avg time : %lld\n", con / gl_loopcycle);
 printf("Close avg time : %lld\n", clo / gl_loopcycle);
}

canonical_original_code:
void tcpconnectClient(char **arg)
{
 struct timespec pauseTime;
        struct sockaddr_in sin;
 unsigned long long b; unsigned long long c; unsigned long long con = 0; unsigned long long clo = 0;
        int sfd; int i;
 pauseTime.tv_sec = 0;
 pauseTime.tv_nsec = 1000000;
 if (initClient(*arg, &sin) == -1)
  exit(1);
 for (i = 0; i < gl_loopcycle; i++)
 {
  if ((sfd = socket(2, SOCK_STREAM, 0)) == -1)
  {
   perror("Socket creation failed.");
   exit(1);
  }
  b = rdtsc();
  if (connect(sfd, (struct sockaddr *)&sin, sizeof(sin)))
  {
   perror("Socket connect failed");
   exit(1);
  }
  c = rdtsc();
  con += c - b;
  b = rdtsc();
  close(sfd);
  c = rdtsc();
  clo += c - b;
  nanosleep(&pauseTime, ((void *)0));
 }
 printf("Connection avg time : %lld\n", con / gl_loopcycle);
 printf("Close avg time : %lld\n", clo / gl_loopcycle);
}

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

variable_types:
con
unsigned long long

variable_types:
clo
unsigned long long

variable_types: i int


fsCacheSize

original_code:
void fsCacheSize(char **arg)
{
 char filename[] = "./fileCacheBenchXXXXXX";
 unsigned int targetsize = 0;
 unsigned int cursize = 0;
 int fd;
 char buf[2048];
 int res;
 memset(buf, 42, 2048);
 if ((fd = mkstemp(filename)) == -1)
 {
  perror("File creation failed");
  exit(1);
 }
 printf("Temporary file name is %s\n", filename);
 for (targetsize = (1 << 27); targetsize < ((unsigned int)(1 << 30) * 2); targetsize += (1 << 27))
 {
  while (cursize < targetsize)
  {
   if ((res = write(fd, buf, ((targetsize - cursize) % 2048) + 1)) == -1)
   {
    perror("Write error");
    exit(1);
   }
   cursize += res;
  }
  { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (lseek(fd, 0, 0) == -1) { perror("Lseek error"); exit(1); } do { if ((res = read(fd, buf, 2048)) == -1) { perror("Read error"); exit(1); } } while (res); } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
  printf("Average cycles for file of %dMB = %f\n", cursize / (1024 * 1024),
   gl_lastavgres);
 }
 if (unlink(filename) == -1)
  perror("File remove failed");
}

variable_types:
filename
char []

variable_types:
targetsize
unsigned int

variable_types:
cursize
unsigned int

variable_types: fd int

variable_types:
buf
char [2048]


readFile

decompiled_code:
void readFile()
{
int v0; // ebx
__pid_t v1; // eax
int v2; // eax
int v3; // er12
unsigned int v4; // er13
unsigned int v5; // er15
int v6; // eax
unsigned __int64 v7; // rax
int v8; // ecx
unsigned int v9; // ebx
int v10; // eax
int v11; // eax
unsigned __int64 v12; // rdi
double v13; // xmm0_8
int v14; // er10
unsigned int v15; // ebx
int v16; // eax
__int64 v17; // r11
double v18; // xmm0_8
bool v19; // sf
__int64 v20; // [rsp+8h] [rbp-20068h]
unsigned int v21; // [rsp+14h] [rbp-2005Ch]
unsigned int v22; // [rsp+18h] [rbp-20058h]
unsigned __int64 v23; // [rsp+18h] [rbp-20058h]
char buf[131072]; // [rsp+20h] [rbp-20050h] BYREF
char templatea[80]; // [rsp+20020h] [rbp-50h] BYREF

strcpy(templatea, "./fileCacheBenchXXXXXX");
v0 = time(0LL);
v1 = getpid();
srandom(v1 + v0);
memset(buf, 0x2Au, 0x800uLL);
v2 = mkstemp(templatea);
if ( v2 == -1 )
{
perror("File creation failed");
exit(1);
}
v3 = v2;
printf("Temporary file name is %s\n", templatea);
v4 = 0;
v5 = 0x1000000;
do
{
while ( v4 < v5 )
{
v6 = write(v3, buf, ((v5 - v4) & 0x1FFFF) + 1LL);
if ( v6 == -1 )
{
perror("Write error");
exit(1);
}
v4 += v6;
printf("Wrote %d bytes of %d bytes\r", v4, v5);
}
v7 = __rdtsc();
LODWORD(v20) = HIDWORD(v7);
v21 = v7;
v8 = gl_loopcycle;
if ( gl_loopcycle )
{
v22 = 0;
do
{
v9 = 0;
do
{
v10 = random();
if ( lseek(v3, (int)((v10 - v10 % 0x20000) % (v4 - 0x20000)), 0) == -1 )
{
perror("Lseek error");
exit(1);
}
v11 = read(v3, buf, 0x20000uLL);
if ( (unsigned int)(v11 + 1) <= 1 )
{
perror("Read error");
exit(1);
}
v9 += v11;
printf("Readed %d bytes of %d bytes\r", v9, v4);
}
while ( v9 < v4 );
++v22;
v8 = gl_loopcycle;
}
while ( gl_loopcycle > v22 );
}
v12 = __rdtsc() - (v21 | (unsigned __int64)(v20 << 32));
if ( (v12 & 0x8000000000000000LL) != 0LL )
v13 = (double)(int)((v12 >> 1) | v12 & 1) + (double)(int)((v12 >> 1) | v12 & 1);
else
v13 = (double)(int)v12;
gl_lastavgres = v13 / (double)v8;
printf("Random read of %dMB file = %f cycles\n", v4 >> 20, gl_lastavgres);
v23 = __rdtsc();
v14 = gl_loopcycle;
if ( gl_loopcycle )
{
v15 = 0;
do
{
if ( lseek(v3, 0LL, 0) == -1 )
{
perror("Lseek error");
exit(1);
}
do
{
v16 = read(v3, buf, 0x20000uLL);
if ( v16 == -1 )
{
perror("Read error");
exit(1);
}
}
while ( v16 );
++v15;
v14 = gl_loopcycle;
}
while ( gl_loopcycle > v15 );
}
v17 = __rdtsc() - v23;
if ( v17 < 0 )
v18 = (double)(int)(((unsigned __int64)v17 >> 1) | v17 & 1)
+ (double)(int)(((unsigned __int64)v17 >> 1) | v17 & 1);
else
v18 = (double)(int)v17;
gl_lastavgres = v18 / (double)v14;
printf("Sequential read of %dMB file = %f cycles\n", v4 >> 20, gl_lastavgres);
v19 = (v5 & 0x40000000) != 0;
v5 *= 2;
}
while ( !v19 );
if ( unlink(templatea) == -1 )
perror("File remove failed");
}

canonical_decompiled_code:
void func1()
{
int v0; // ebx
__pid_t v1; // eax
int v2; // eax
int v3; // er12
unsigned int v4; // er13
unsigned int v5; // er15
int v6; // eax
unsigned __int64 v7; // rax
int v8; // ecx
unsigned int v9; // ebx
int v10; // eax
int v11; // eax
unsigned __int64 v12; // rdi
double v13; // xmm0_8
int v14; // er10
unsigned int v15; // ebx
int v16; // eax
__int64 v17; // r11
double v18; // xmm0_8
bool v19; // sf
__int64 v20; // [rsp+8h] [rbp-20068h]
unsigned int v21; // [rsp+14h] [rbp-2005Ch]
unsigned int v22; // [rsp+18h] [rbp-20058h]
unsigned __int64 v23; // [rsp+18h] [rbp-20058h]
char buf[131072]; // [rsp+20h] [rbp-20050h] BYREF
char templatea[80]; // [rsp+20020h] [rbp-50h] BYREF

strcpy(templatea, "./fileCacheBenchXXXXXX");
v0 = time(0LL);
v1 = getpid();
srandom(v1 + v0);
memset(buf, 0x2Au, 0x800uLL);
v2 = mkstemp(templatea);
if ( v2 == -1 )
{
perror("File creation failed");
exit(1);
}
v3 = v2;
printf("Temporary file name is %s\n", templatea);
v4 = 0;
v5 = 0x1000000;
do
{
while ( v4 < v5 )
{
v6 = write(v3, buf, ((v5 - v4) & 0x1FFFF) + 1LL);
if ( v6 == -1 )
{
perror("Write error");
exit(1);
}
v4 += v6;
printf("Wrote %d bytes of %d bytes\r", v4, v5);
}
v7 = __rdtsc();
LODWORD(v20) = HIDWORD(v7);
v21 = v7;
v8 = gl_loopcycle;
if ( gl_loopcycle )
{
v22 = 0;
do
{
v9 = 0;
do
{
v10 = random();
if ( lseek(v3, (int)((v10 - v10 % 0x20000) % (v4 - 0x20000)), 0) == -1 )
{
perror("Lseek error");
exit(1);
}
v11 = read(v3, buf, 0x20000uLL);
if ( (unsigned int)(v11 + 1) <= 1 )
{
perror("Read error");
exit(1);
}
v9 += v11;
printf("Readed %d bytes of %d bytes\r", v9, v4);
}
while ( v9 < v4 );
++v22;
v8 = gl_loopcycle;
}
while ( gl_loopcycle > v22 );
}
v12 = __rdtsc() - (v21 | (unsigned __int64)(v20 << 32));
if ( (v12 & 0x8000000000000000LL) != 0LL )
v13 = (double)(int)((v12 >> 1) | v12 & 1) + (double)(int)((v12 >> 1) | v12 & 1);
else
v13 = (double)(int)v12;
gl_lastavgres = v13 / (double)v8;
printf("Random read of %dMB file = %f cycles\n", v4 >> 20, gl_lastavgres);
v23 = __rdtsc();
v14 = gl_loopcycle;
if ( gl_loopcycle )
{
v15 = 0;
do
{
if ( lseek(v3, 0LL, 0) == -1 )
{
perror("Lseek error");
exit(1);
}
do
{
v16 = read(v3, buf, 0x20000uLL);
if ( v16 == -1 )
{
perror("Read error");
exit(1);
}
}
while ( v16 );
++v15;
v14 = gl_loopcycle;
}
while ( gl_loopcycle > v15 );
}
v17 = __rdtsc() - v23;
if ( v17 < 0 )
v18 = (double)(int)(((unsigned __int64)v17 >> 1) | v17 & 1)
+ (double)(int)(((unsigned __int64)v17 >> 1) | v17 & 1);
else
v18 = (double)(int)v17;
gl_lastavgres = v18 / (double)v14;
printf("Sequential read of %dMB file = %f cycles\n", v4 >> 20, gl_lastavgres);
v19 = (v5 & 0x40000000) != 0;
v5 *= 2;
}
while ( !v19 );
if ( unlink(templatea) == -1 )
perror("File remove failed");
}

original_code:
void readFile(char **arg)
{
 char filename[] = "./fileCacheBenchXXXXXX";
 unsigned int targetsize = 0;
 unsigned int cursize = 0;
 int fd;
 char buf[(128 * 1024)];
 int res;
 int readed;
 srandom(time(((void *)0)) + getpid());
 memset(buf, 42, 2048);
 if ((fd = mkstemp(filename)) == -1)
 {
  perror("File creation failed");
  exit(1);
 }
 printf("Temporary file name is %s\n", filename);
 for (targetsize = (1 << 24); targetsize < (1 << 31); targetsize = targetsize << 1)
 {
  while (cursize < targetsize)
  {
   if ((res = write(fd, buf, ((targetsize - cursize) % (128 * 1024)) + 1)) == -1)
   {
    perror("Write error");
    exit(1);
   }
   cursize += res;
   printf("Wrote %d bytes of %d bytes\r", cursize, targetsize);
  }
  { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ readed = 0; do { res = random(); res = (res - (res % (128 * 1024))) % (cursize - (128 * 1024)); if (lseek(fd, res, 0) == -1) { perror("Lseek error"); exit(1); } if ((res = read(fd, buf, (128 * 1024))) == -1 || res == 0) { perror("Read error"); exit(1); } readed += res; printf("Readed %d bytes of %d bytes\r", readed, cursize); } while (readed < cursize);; } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
  printf("Random read of %dMB file = %f cycles\n", cursize / (1024 * 1024),
   gl_lastavgres);
  { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (lseek(fd, 0, 0) == -1) { perror("Lseek error"); exit(1); } do { if ((res = read(fd, buf, (128 * 1024))) == -1) { perror("Read error"); exit(1); } } while (res); } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
  printf("Sequential read of %dMB file = %f cycles\n", cursize / (1024 * 1024),
   gl_lastavgres);
 }
 if (unlink(filename) == -1)
  perror("File remove failed");
}

canonical_original_code:
void readFile(char **arg)
{
 char filename[] = "./fileCacheBenchXXXXXX";
 unsigned int targetsize = 0;
 unsigned int cursize = 0;
 int fd;
 char buf[-1];
 int res;
 int readed;
 srandom(time(((void *)0)) + getpid());
 memset(buf, 42, 2048);
 if ((fd = mkstemp(filename)) == -1)
 {
  perror("File creation failed");
  exit(1);
 }
 printf("Temporary file name is %s\n", filename);
 for (targetsize = (1 << 24); targetsize < (1 << 31); targetsize = targetsize << 1)
 {
  while (cursize < targetsize)
  {
   if ((res = write(fd, buf, ((targetsize - cursize) % (128 * 1024)) + 1)) == -1)
   {
    perror("Write error");
    exit(1);
   }
   cursize += res;
   printf("Wrote %d bytes of %d bytes\r", cursize, targetsize);
  }
  { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ readed = 0; do { res = random(); res = (res - (res % (128 * 1024))) % (cursize - (128 * 1024)); if (lseek(fd, res, 0) == -1) { perror("Lseek error"); exit(1); } if ((res = read(fd, buf, (128 * 1024))) == -1 || res == 0) { perror("Read error"); exit(1); } readed += res; printf("Readed %d bytes of %d bytes\r", readed, cursize); } while (readed < cursize);; } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
  printf("Random read of %dMB file = %f cycles\n", cursize / (1024 * 1024),
   gl_lastavgres);
  { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (lseek(fd, 0, 0) == -1) { perror("Lseek error"); exit(1); } do { if ((res = read(fd, buf, (128 * 1024))) == -1) { perror("Read error"); exit(1); } } while (res); } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
  printf("Sequential read of %dMB file = %f cycles\n", cursize / (1024 * 1024),
   gl_lastavgres);
 }
 if (unlink(filename) == -1)
  perror("File remove failed");
}

variable_types:
buf
char [-1]

variable_types: readed int


readContention

decompiled_code:
void readContention()
{
__int64 i; // r14
char *v1; // r13
int v2; // er12
unsigned int j; // ebx
int v4; // eax
unsigned int k; // ebx
int v6; // er13
int v7; // edx
__pid_t v8; // eax
__pid_t v9; // eax
__pid_t v10; // eax
__pid_t v11; // eax
__pid_t v12; // eax
__pid_t v13; // eax
__pid_t v14; // eax
__pid_t v15; // eax
int v16; // er14
__pid_t v17; // eax
__pid_t v18; // eax
__pid_t v19; // eax
__pid_t v20; // eax
__pid_t v21; // eax
__pid_t v22; // eax
__pid_t v23; // eax
int v24; // er12
int v25; // ecx
int v26; // eax
unsigned __int64 v27; // r14
int v28; // er8
unsigned int v29; // er12
int v30; // ebx
int v31; // eax
__int64 v32; // r9
double v33; // xmm0_8
__int64 v34; // r13
__int64 v35; // r14
int fd[32]; // [rsp+0h] [rbp-201A0h]
char s[131072]; // [rsp+80h] [rbp-20120h] BYREF
void *ptr[36]; // [rsp+20080h] [rbp-120h]

memset(s, 42, sizeof(s));
for ( i = 0LL; i != 32; ++i )
{
v1 = strdup("./tmpReadContentionBenchXXXXXX");
ptr[i] = v1;
v2 = mkstemp(v1);
fd[i] = v2;
if ( v2 == -1 )
{
perror("File creation failed");
exit(1);
}
for ( j = 0; j <= 0x7FFFFFF; j += v4 )
{
v4 = write(v2, s, 0x20000uLL);
if ( v4 == -1 )
{
perror("Write error");
exit(1);
}
}
printf("Temporary file %s created.\n", v1);
}
for ( k = 1; ; k = v26 )
{
printf("Starting %d processes...\n", k);
if ( !k )
{
v26 = 0;
continue;
}
v6 = 0;
v7 = k & 7;
if ( (k & 7) == 0 )
break;
if ( v7 != 1 )
{
if ( v7 != 2 )
{
if ( v7 != 3 )
{
if ( v7 != 4 )
{
if ( v7 != 5 )
{
if ( v7 != 6 )
{
v8 = fork();
if ( !v8 )
goto LABEL_89;
if ( v8 == -1 )
perror("fork");
v6 = 1;
}
v9 = fork();
if ( !v9 )
goto LABEL_89;
if ( v9 == -1 )
perror("fork");
++v6;
}
v10 = fork();
if ( !v10 )
goto LABEL_89;
if ( v10 == -1 )
perror("fork");
++v6;
}
v11 = fork();
if ( !v11 )
goto LABEL_89;
if ( v11 == -1 )
perror("fork");
++v6;
}
v12 = fork();
if ( !v12 )
goto LABEL_89;
if ( v12 == -1 )
perror("fork");
++v6;
}
v13 = fork();
if ( !v13 )
goto LABEL_89;
if ( v13 == -1 )
perror("fork");
++v6;
}
v14 = fork();
if ( !v14 )
goto LABEL_89;
if ( v14 == -1 )
perror("fork");
if ( ++v6 != k )
break;
LABEL_72:
v24 = 0;
v25 = k & 7;
if ( (k & 7) == 0 )
goto LABEL_115;
if ( v25 != 1 )
{
if ( v25 != 2 )
{
if ( v25 != 3 )
{
if ( v25 != 4 )
{
if ( v25 != 5 )
{
if ( v25 != 6 )
{
waitid(P_ALL, 0, 0LL, 4);
v24 = 1;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
if ( ++v24 != k )
{
LABEL_115:
do
{
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
v24 += 8;
}
while ( v24 != k );
}
v26 = 2 * k;
if ( 2 * k > 0x20 )
{
v34 = 0LL;
do
{
close(fd[v34]);
if ( unlink((const char *)ptr[v34]) == -1 )
perror("File remove failed");
free(ptr[k]);
v35 = v34 + 1;
close(fd[v34 + 1]);
if ( unlink((const char *)ptr[v34 + 1]) == -1 )
perror("File remove failed");
free(ptr[k]);
close(fd[v34 + 2]);
if ( unlink((const char *)ptr[v34 + 2]) == -1 )
perror("File remove failed");
free(ptr[k]);
close(fd[v34 + 3]);
if ( unlink((const char *)ptr[v34 + 3]) == -1 )
perror("File remove failed");
free(ptr[k]);
v34 += 4LL;
}
while ( v35 != 29 );
return;
}
}
while ( 1 )
{
v15 = fork();
if ( !v15 )
break;
if ( v15 == -1 )
perror("fork");
v16 = ++v6;
v17 = fork();
if ( !v17 )
break;
if ( v17 == -1 )
perror("fork");
v6 = v16 + 1;
v18 = fork();
if ( !v18 )
break;
if ( v18 == -1 )
perror("fork");
v6 = v16 + 2;
v19 = fork();
if ( !v19 )
break;
if ( v19 == -1 )
perror("fork");
v6 = v16 + 3;
v20 = fork();
if ( !v20 )
break;
if ( v20 == -1 )
perror("fork");
v6 = v16 + 4;
v21 = fork();
if ( !v21 )
break;
if ( v21 == -1 )
perror("fork");
v6 = v16 + 5;
v22 = fork();
if ( !v22 )
break;
if ( v22 == -1 )
perror("fork");
v6 = v16 + 6;
v23 = fork();
if ( !v23 )
break;
if ( v23 == -1 )
perror("fork");
v6 = v16 + 7;
if ( v16 + 7 == k )
goto LABEL_72;
}
LABEL_89:
v27 = __rdtsc();
v28 = gl_loopcycle;
if ( gl_loopcycle )
{
v29 = 0;
do
{
v30 = fd[v6];
if ( lseek(v30, 0LL, 0) == -1 )
{
perror("Lseek error");
exit(1);
}
do
{
v31 = read(v30, s, 0x20000uLL);
if ( v31 == -1 )
{
perror("Read error");
exit(1);
}
}
while ( v31 );
++v29;
v28 = gl_loopcycle;
}
while ( gl_loopcycle > v29 );
}
v32 = __rdtsc() - v27;
if ( v32 < 0 )
v33 = (double)(int)(((unsigned __int64)v32 >> 1) | v32 & 1) + (double)(int)(((unsigned __int64)v32 >> 1) | v32 & 1);
else
v33 = (double)(int)v32;
gl_lastavgres = v33 / (double)v28;
printf("Sequential read of %dMB file = %f cycles\n", 128LL, gl_lastavgres);
free(ptr[v6]);
}

canonical_decompiled_code:
void func2()
{
__int64 i; // r14
char *v1; // r13
int v2; // er12
unsigned int j; // ebx
int v4; // eax
unsigned int k; // ebx
int v6; // er13
int v7; // edx
__pid_t v8; // eax
__pid_t v9; // eax
__pid_t v10; // eax
__pid_t v11; // eax
__pid_t v12; // eax
__pid_t v13; // eax
__pid_t v14; // eax
__pid_t v15; // eax
int v16; // er14
__pid_t v17; // eax
__pid_t v18; // eax
__pid_t v19; // eax
__pid_t v20; // eax
__pid_t v21; // eax
__pid_t v22; // eax
__pid_t v23; // eax
int v24; // er12
int v25; // ecx
int v26; // eax
unsigned __int64 v27; // r14
int v28; // er8
unsigned int v29; // er12
int v30; // ebx
int v31; // eax
__int64 v32; // r9
double v33; // xmm0_8
__int64 v34; // r13
__int64 v35; // r14
int fd[32]; // [rsp+0h] [rbp-201A0h]
char s[131072]; // [rsp+80h] [rbp-20120h] BYREF
void *ptr[36]; // [rsp+20080h] [rbp-120h]

memset(s, 42, sizeof(s));
for ( i = 0LL; i != 32; ++i )
{
v1 = strdup("./tmpReadContentionBenchXXXXXX");
ptr[i] = v1;
v2 = mkstemp(v1);
fd[i] = v2;
if ( v2 == -1 )
{
perror("File creation failed");
exit(1);
}
for ( j = 0; j <= 0x7FFFFFF; j += v4 )
{
v4 = write(v2, s, 0x20000uLL);
if ( v4 == -1 )
{
perror("Write error");
exit(1);
}
}
printf("Temporary file %s created.\n", v1);
}
for ( k = 1; ; k = v26 )
{
printf("Starting %d processes...\n", k);
if ( !k )
{
v26 = 0;
continue;
}
v6 = 0;
v7 = k & 7;
if ( (k & 7) == 0 )
break;
if ( v7 != 1 )
{
if ( v7 != 2 )
{
if ( v7 != 3 )
{
if ( v7 != 4 )
{
if ( v7 != 5 )
{
if ( v7 != 6 )
{
v8 = fork();
if ( !v8 )
goto LABEL_89;
if ( v8 == -1 )
perror("fork");
v6 = 1;
}
v9 = fork();
if ( !v9 )
goto LABEL_89;
if ( v9 == -1 )
perror("fork");
++v6;
}
v10 = fork();
if ( !v10 )
goto LABEL_89;
if ( v10 == -1 )
perror("fork");
++v6;
}
v11 = fork();
if ( !v11 )
goto LABEL_89;
if ( v11 == -1 )
perror("fork");
++v6;
}
v12 = fork();
if ( !v12 )
goto LABEL_89;
if ( v12 == -1 )
perror("fork");
++v6;
}
v13 = fork();
if ( !v13 )
goto LABEL_89;
if ( v13 == -1 )
perror("fork");
++v6;
}
v14 = fork();
if ( !v14 )
goto LABEL_89;
if ( v14 == -1 )
perror("fork");
if ( ++v6 != k )
break;
LABEL_72:
v24 = 0;
v25 = k & 7;
if ( (k & 7) == 0 )
goto LABEL_115;
if ( v25 != 1 )
{
if ( v25 != 2 )
{
if ( v25 != 3 )
{
if ( v25 != 4 )
{
if ( v25 != 5 )
{
if ( v25 != 6 )
{
waitid(P_ALL, 0, 0LL, 4);
v24 = 1;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
++v24;
}
waitid(P_ALL, 0, 0LL, 4);
if ( ++v24 != k )
{
LABEL_115:
do
{
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
waitid(P_ALL, 0, 0LL, 4);
v24 += 8;
}
while ( v24 != k );
}
v26 = 2 * k;
if ( 2 * k > 0x20 )
{
v34 = 0LL;
do
{
close(fd[v34]);
if ( unlink((const char *)ptr[v34]) == -1 )
perror("File remove failed");
free(ptr[k]);
v35 = v34 + 1;
close(fd[v34 + 1]);
if ( unlink((const char *)ptr[v34 + 1]) == -1 )
perror("File remove failed");
free(ptr[k]);
close(fd[v34 + 2]);
if ( unlink((const char *)ptr[v34 + 2]) == -1 )
perror("File remove failed");
free(ptr[k]);
close(fd[v34 + 3]);
if ( unlink((const char *)ptr[v34 + 3]) == -1 )
perror("File remove failed");
free(ptr[k]);
v34 += 4LL;
}
while ( v35 != 29 );
return;
}
}
while ( 1 )
{
v15 = fork();
if ( !v15 )
break;
if ( v15 == -1 )
perror("fork");
v16 = ++v6;
v17 = fork();
if ( !v17 )
break;
if ( v17 == -1 )
perror("fork");
v6 = v16 + 1;
v18 = fork();
if ( !v18 )
break;
if ( v18 == -1 )
perror("fork");
v6 = v16 + 2;
v19 = fork();
if ( !v19 )
break;
if ( v19 == -1 )
perror("fork");
v6 = v16 + 3;
v20 = fork();
if ( !v20 )
break;
if ( v20 == -1 )
perror("fork");
v6 = v16 + 4;
v21 = fork();
if ( !v21 )
break;
if ( v21 == -1 )
perror("fork");
v6 = v16 + 5;
v22 = fork();
if ( !v22 )
break;
if ( v22 == -1 )
perror("fork");
v6 = v16 + 6;
v23 = fork();
if ( !v23 )
break;
if ( v23 == -1 )
perror("fork");
v6 = v16 + 7;
if ( v16 + 7 == k )
goto LABEL_72;
}
LABEL_89:
v27 = __rdtsc();
v28 = gl_loopcycle;
if ( gl_loopcycle )
{
v29 = 0;
do
{
v30 = fd[v6];
if ( lseek(v30, 0LL, 0) == -1 )
{
perror("Lseek error");
exit(1);
}
do
{
v31 = read(v30, s, 0x20000uLL);
if ( v31 == -1 )
{
perror("Read error");
exit(1);
}
}
while ( v31 );
++v29;
v28 = gl_loopcycle;
}
while ( gl_loopcycle > v29 );
}
v32 = __rdtsc() - v27;
if ( v32 < 0 )
v33 = (double)(int)(((unsigned __int64)v32 >> 1) | v32 & 1) + (double)(int)(((unsigned __int64)v32 >> 1) | v32 & 1);
else
v33 = (double)(int)v32;
gl_lastavgres = v33 / (double)v28;
printf("Sequential read of %dMB file = %f cycles\n", 128LL, gl_lastavgres);
free(ptr[v6]);
}

original_code:
void readContention(char **arg)
{
 char *filenametpl = "./tmpReadContentionBenchXXXXXX";
 char *filename[(1 << 5)];
 char buf[(128 * 1024)];
 int fd[(1 << 5)];
 int res;
 unsigned int i;
 unsigned int j;
 unsigned int size;
 memset(buf, 42, (128 * 1024));
 for (i = 0; i < (1 << 5); i++)
 {
  filename[i] = strdup(filenametpl);
  if ((fd[i] = mkstemp(filename[i])) == -1)
  {
   perror("File creation failed");
   exit(1);
  }
  for (size = 0; size < (1 << 27); size += res)
   if ((res = write(fd[i], buf, (128 * 1024))) == -1)
   {
    perror("Write error");
    exit(1);
   }
  printf("Temporary file %s created.\n", filename[i]);
 }
 for (i = 1; i <= (1 << 5); i = i << 1)
 {
  printf("Starting %d processes...\n", i);
  for (j = 0; j < i; j++)
  {
   if (!(res = fork()))
   {
    { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (lseek(fd[j], 0, 0) == -1) { perror("Lseek error"); exit(1); } do { if ((res = read(fd[j], buf, (128 * 1024))) == -1) { perror("Read error"); exit(1); } } while (res); } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
    printf("Sequential read of %dMB file = %f cycles\n", (1 << 27) / (1024 * 1024),
     gl_lastavgres);
    free(filename[j]);
    return;
   }
   else if (res == -1)
    perror("fork");
  }
  for (j = 0; j < i; j++)
   waitid(P_ALL, 0, ((void *)0), 4);
 }
 for (i = 0; i < (1 << 5); i++)
 {
  close(fd[i]);
  if (unlink(filename[i]) == -1)
   perror("File remove failed");
  free(filename[j]);
 }
}

canonical_original_code:
void readContention(char **arg)
{
 char *filenametpl = "./tmpReadContentionBenchXXXXXX";
 char *filename[-1];
 char buf[-1];
 int fd[-1];
 int res;
 unsigned int i;
 unsigned int j;
 unsigned int size;
 memset(buf, 42, (128 * 1024));
 for (i = 0; i < (1 << 5); i++)
 {
  filename[i] = strdup(filenametpl);
  if ((fd[i] = mkstemp(filename[i])) == -1)
  {
   perror("File creation failed");
   exit(1);
  }
  for (size = 0; size < (1 << 27); size += res)
   if ((res = write(fd[i], buf, (128 * 1024))) == -1)
   {
    perror("Write error");
    exit(1);
   }
  printf("Temporary file %s created.\n", filename[i]);
 }
 for (i = 1; i <= (1 << 5); i = i << 1)
 {
  printf("Starting %d processes...\n", i);
  for (j = 0; j < i; j++)
  {
   if (!(res = fork()))
   {
    { unsigned long long b; unsigned long long c; unsigned int measureloopcnt; b = rdtsc(); for (measureloopcnt = 0; measureloopcnt < gl_loopcycle; ++measureloopcnt){ if (lseek(fd[j], 0, 0) == -1) { perror("Lseek error"); exit(1); } do { if ((res = read(fd[j], buf, (128 * 1024))) == -1) { perror("Read error"); exit(1); } } while (res); } c = rdtsc(); if (0) printf("Total execution time is : %llu\nEach execution takes about %f clock cycles (averaging from %d iterations)\n", c - b, (double)(c - b) / (double)gl_loopcycle, gl_loopcycle); gl_lastavgres = (double)(c - b) / (double)gl_loopcycle; }
    printf("Sequential read of %dMB file = %f cycles\n", (1 << 27) / (1024 * 1024),
     gl_lastavgres);
    free(filename[j]);
    return;
   }
   else if (res == -1)
    perror("fork");
  }
  for (j = 0; j < i; j++)
   waitid(P_ALL, 0, ((void *)0), 4);
 }
 for (i = 0; i < (1 << 5); i++)
 {
  close(fd[i]);
  if (unlink(filename[i]) == -1)
   perror("File remove failed");
  free(filename[j]);
 }
}

variable_types:
arg
char **

variable_types:
filenametpl
char *

variable_types:
filename
char *[-1]

variable_types:
fd
int [-1]

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
size
unsigned int


decompiled_code:
int print_help()
{
puts("Le programme \"tartiflette\" permet le stockage de different fichier ou dossier dans une seule et unique archive.");
puts(aUsageTartiflet);
putchar(10);
puts("Options possible:");
puts(aHAfficherLaPr);
puts(" -v Activer le mode verbose.");
puts(aCCr);
puts(" -t Lister le contenu d'une archive existante.");
puts(aRRajouterDesFi);
puts(aUAjouterLesFic);
puts(" -x Extraitre une archive existante.");
puts(aFSp);
puts(" -z Filtrer l'archive au travers de gzip.");
puts(" -d Supprimer une archive existante.");
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
puts("Le programme \"tartiflette\" permet le stockage de different fichier ou dossier dans une seule et unique archive.");
puts(aUsageTartiflet);
putchar(10);
puts("Options possible:");
puts(aHAfficherLaPr);
puts(" -v Activer le mode verbose.");
puts(aCCr);
puts(" -t Lister le contenu d'une archive existante.");
puts(aRRajouterDesFi);
puts(aUAjouterLesFic);
puts(" -x Extraitre une archive existante.");
puts(aFSp);
puts(" -z Filtrer l'archive au travers de gzip.");
puts(" -d Supprimer une archive existante.");
return putchar(10);
}

original_code:
void print_help(){
 printf("Le programme \"tartiflette\" permet le stockage de different fichier ou dossier dans une seule et unique archive.\n");
 printf("Usage : ./tartiflette [-options] [Nom du fichier à créé si option f] [nom des fichiers à inclure dans l'archive]\n");
 printf("\n");
 printf("Options possible:\n");
 printf(" -h Afficher la présente page d'aide.\n");
 printf(" -v Activer le mode verbose.\n");
 printf(" -c Créer une nouvelle archive\n");
 printf(" -t Lister le contenu d'une archive existante.\n");
 printf(" -r Rajouter des fichiers ou dossier à une archive existante.\n");
 printf(" -u Ajouter les fichiers plus récents que leurs copie déjà présente dans une archive existante.\n");
 printf(" -x Extraitre une archive existante.\n");
 printf(" -f Spécifier le nom de l'archive à utiliser, doit être la dernière option appelée.\n");
 printf(" -z Filtrer l'archive au travers de gzip.\n");
 printf(" -d Supprimer une archive existante.\n");
 printf("\n");
}


analyseOption

decompiled_code:
__int64 __fastcall analyseOption(int argc, char **argv)
{
char v2; // r14
char v3; // r15
char *v4; // r13
int v5; // eax
_QWORD *v7; // r12
__int64 v8; // rdx
__int64 v9; // rax
char v10; // [rsp+Ch] [rbp-3Ch]
char v11; // [rsp+Dh] [rbp-3Bh]
unsigned __int8 v12; // [rsp+Eh] [rbp-3Ah]
char v13; // [rsp+Fh] [rbp-39h]

VERBOSE = 0;
v11 = 0;
v2 = 0;
v3 = 0;
v12 = 0;
v10 = 0;
v13 = 0;
v4 = 0LL;
while ( 2 )
{
v5 = getopt(argc, argv, "hvctruxf:zd");
if ( v5 == -1 )
{
v7 = malloc(8LL * (argc - optind));
LODWORD(v9) = optind;
v8 = optind;
*v7 = argv[optind];
LODWORD(v9) = v9 + 1;
if ( argc > (int)v9 )
{
v9 = (int)v9;
do
{
v7[v9 - v8] = argv[v9];
++v9;
}
while ( argc > (int)v9 );
}
if ( v3 )
extract(v4);
if ( v2 )
list(v4);
if ( v13 )
create(v4, v7);
if ( v10 )
add(v4, v7, v12);
if ( v11 )
execlp("gzip", "gzip", v4, 0LL);
}
else
{
switch ( v5 )
{
case 'c':
v13 = 1;
continue;
case 'f':
v4 = optarg;
continue;
case 'h':
print_help();
break;
case 'r':
v10 = 1;
continue;
case 't':
v2 = 1;
continue;
case 'u':
v12 = 1;
continue;
case 'v':
VERBOSE = 1;
continue;
case 'x':
v3 = 1;
continue;
case 'z':
v11 = 1;
continue;
default:
continue;
}
}
break;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv)
{
char v2; // r14
char v3; // r15
char *v4; // r13
int v5; // eax
_QWORD *v7; // r12
__int64 v8; // rdx
__int64 v9; // rax
char v10; // [rsp+Ch] [rbp-3Ch]
char v11; // [rsp+Dh] [rbp-3Bh]
unsigned __int8 v12; // [rsp+Eh] [rbp-3Ah]
char v13; // [rsp+Fh] [rbp-39h]

VERBOSE = 0;
v11 = 0;
v2 = 0;
v3 = 0;
v12 = 0;
v10 = 0;
v13 = 0;
v4 = 0LL;
while ( 2 )
{
v5 = getopt(argc, argv, "hvctruxf:zd");
if ( v5 == -1 )
{
v7 = malloc(8LL * (argc - optind));
LODWORD(v9) = optind;
v8 = optind;
*v7 = argv[optind];
LODWORD(v9) = v9 + 1;
if ( argc > (int)v9 )
{
v9 = (int)v9;
do
{
v7[v9 - v8] = argv[v9];
++v9;
}
while ( argc > (int)v9 );
}
if ( v3 )
extract(v4);
if ( v2 )
list(v4);
if ( v13 )
create(v4, v7);
if ( v10 )
add(v4, v7, v12);
if ( v11 )
execlp("gzip", "gzip", v4, 0LL);
}
else
{
switch ( v5 )
{
case 'c':
v13 = 1;
continue;
case 'f':
v4 = optarg;
continue;
case 'h':
func0();
break;
case 'r':
v10 = 1;
continue;
case 't':
v2 = 1;
continue;
case 'u':
v12 = 1;
continue;
case 'v':
VERBOSE = 1;
continue;
case 'x':
v3 = 1;
continue;
case 'z':
v11 = 1;
continue;
default:
continue;
}
}
break;
}
return 1LL;
}

original_code:
int analyseOption(int argc, char* argv[]){
 char * archive = ((void *)0);
 _Bool o_create = 0 , o_add = 0, o_maj = 0, o_extract = 0, o_list = 0, o_zip = 0;
 int compt;
 char** filename = ((void *)0);
 VERBOSE = 0;
 while(1){
  compt = getopt(argc, argv, "hvctruxf:zd");
  if (compt==-1){
   break;
  }
  switch(compt)
  {
  case 'h':
   print_help();
   return 1;
   break;
  case 'v':
   VERBOSE = 1;
   break;
  case 'c':
   o_create = 1;
   break;
  case 't':
   o_list = 1;
   break;
  case 'r':
   o_add = 1;
   break;
  case 'u':
   o_maj = 1;
   break;
  case 'x':
   o_extract = 1;
   break;
  case 'f':
   archive = optarg;
   break;
  case 'z':
   o_zip = 1;
   break;
  case 'd':
   break;
  }
 }
 filename = malloc(sizeof(char*)*(argc-optind));
 filename[0] = argv[optind];
 for(int i=optind+1; i<argc; i++)
  filename[i-optind]= argv[i];
 if(o_extract)
  extract(archive);
 if(o_list)
  list(archive);
 if(o_create)
  create(archive,filename);
 if(o_add)
  add(archive, filename, o_maj);
 if(o_zip == 1)
  execlp("gzip", "gzip", archive, ((void *)0));
 return 1;
}

canonical_original_code:
int analyseOption(int argc, char *argv[]){
 char *archive = ((void *)0);
 _Bool o_create = 0; _Bool o_add = 0; _Bool o_maj = 0; _Bool o_extract = 0; _Bool o_list = 0; _Bool o_zip = 0;
 int compt;
 char **filename = ((void *)0);
 VERBOSE = 0;
 while(1){
  compt = getopt(argc, argv, "hvctruxf:zd");
  if (compt==-1){
   break;
  }
  switch(compt)
  {
  case 'h':
   print_help();
   return 1;
   break;
  case 'v':
   VERBOSE = 1;
   break;
  case 'c':
   o_create = 1;
   break;
  case 't':
   o_list = 1;
   break;
  case 'r':
   o_add = 1;
   break;
  case 'u':
   o_maj = 1;
   break;
  case 'x':
   o_extract = 1;
   break;
  case 'f':
   archive = optarg;
   break;
  case 'z':
   o_zip = 1;
   break;
  case 'd':
   break;
  }
 }
 filename = malloc(sizeof(char *)*(argc-optind));
 filename[0] = argv[optind];
 for(int i = optind+1; i<argc; i++)
  filename[i-optind]= argv[i];
 if(o_extract)
  extract(archive);
 if(o_list)
  list(archive);
 if(o_create)
  create(archive,filename);
 if(o_add)
  add(archive, filename, o_maj);
 if(o_zip == 1)
  execlp("gzip", "gzip", archive, ((void *)0));
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
archive
char *

variable_types: compt int

variable_types:
filename
char **


main

canonical_name: main

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1(argc, (char **)argv);
return 0;
}

original_code:
int main(int argc, char* argv[]){
 analyseOption(argc, argv);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 analyseOption(argc, argv);
 return 0;
}


decompiled_code:
char *init_header()
{
char *result; // rax

result = (char *)malloc(0x101uLL);
if ( !result )
_assert_fail("header", "src/header.c", 0x28u, "init_header");
memset(result, 0, 0x60uLL);
*((_DWORD *)result + 24) = 0;
strcpy(result + 100, "000000000000000000000000000000000000000000000000");
result[156] = 0;
*(_QWORD *)(result + 157) = 0LL;
*(_QWORD *)(result + 249) = 0LL;
memset(
(void *)((unsigned __int64)(result + 165) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 165) & 0xFFFFFFF8) + 257) >> 3));
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax

result = (char *)malloc(0x101uLL);
if ( !result )
_assert_fail("header", "src/header.c", 0x28u, "init_header");
memset(result, 0, 0x60uLL);
*((_DWORD *)result + 24) = 0;
strcpy(result + 100, "000000000000000000000000000000000000000000000000");
result[156] = 0;
*(_QWORD *)(result + 157) = 0LL;
*(_QWORD *)(result + 249) = 0LL;
memset(
(void *)((unsigned __int64)(result + 165) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 165) & 0xFFFFFFF8) + 257) >> 3));
return result;
}

original_code:
Header init_header(void) {
    Header header = (Header) malloc(sizeof(struct Header));
    ((header) ? (void) (0) : __assert_fail ("header", "src/header.c", 40, __extension__ __PRETTY_FUNCTION__));
    memset(header->file_name, '\0', 100);
    memset(header->file_mode, '0', 8);
    memset(header->owner_id, '0', 8);
    memset(header->owner_group_id, '0', 8);
    memset(header->file_size, '0', 12);
    memset(header->last_modification, '0', 12);
    memset(header->checksum, '\0', 8);
    memset(header->type_flag, '\0', 1);
    memset(header->linked_file_name, '\0', 100);
    return header;
}

canonical_original_code:
struct Header *init_header() {
    struct Header *header = (Header) malloc(sizeof(struct Header));
    ((header) ? (void) (0) : __assert_fail ("header", "src/header.c", 40, __extension__ __PRETTY_FUNCTION__));
    memset(header->file_name, '\0', 100);
    memset(header->file_mode, '0', 8);
    memset(header->owner_id, '0', 8);
    memset(header->owner_group_id, '0', 8);
    memset(header->file_size, '0', 12);
    memset(header->last_modification, '0', 12);
    memset(header->checksum, '\0', 8);
    memset(header->type_flag, '\0', 1);
    memset(header->linked_file_name, '\0', 100);
    return header;
}

variable_types: struct Header { char file_name[100]; char file_mode[8]; char owner_id[8]; char owner_group_id[8]; char file_size[12]; char last_modification[12]; char checksum[8]; char type_flag[1]; char linked_file_name[100]; } *


decompiled_code:
char *__fastcall create_header(char *src, unsigned int a2, __int64 a3, __int64 a4, char a5, const char *a6)
{
char *v9; // rax
char *v10; // rbx

v9 = init_header();
v10 = v9;
if ( src )
strcpy(v9, src);
if ( a2 )
sprintf(v10 + 100, "%o", a2);
if ( a3 )
sprintf(v10 + 124, "%lo", a3);
if ( a4 )
sprintf(v10 + 136, "%lo", a4);
if ( a5 )
v10[156] = a5;
if ( a6 )
strcpy(v10 + 157, a6);
return v10;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, unsigned int a2, __int64 a3, __int64 a4, char a5, const char *a6)
{
char *v9; // rax
char *v10; // rbx

v9 = func0();
v10 = v9;
if ( src )
strcpy(v9, src);
if ( a2 )
sprintf(v10 + 100, "%o", a2);
if ( a3 )
sprintf(v10 + 124, "%lo", a3);
if ( a4 )
sprintf(v10 + 136, "%lo", a4);
if ( a5 )
v10[156] = a5;
if ( a6 )
strcpy(v10 + 157, a6);
return v10;
}

original_code:
Header create_header(char * file_name,
                     mode_t file_mode,
                     off_t file_size,
                     time_t last_modification,
                     char type_flag,
                     char * linked_file_name) {
    Header header = init_header();
    if (file_name) strcpy(header->file_name, file_name);
    if (file_mode) sprintf(header->file_mode, "%o", file_mode);
    if (file_size) sprintf(header->file_size, "%lo", file_size);
    if (last_modification) sprintf(header->last_modification, "%lo", last_modification);
    if (type_flag) *header->type_flag = type_flag;
    if (linked_file_name) strcpy(header->linked_file_name, linked_file_name);
    return header;
}

canonical_original_code:
struct Header *create_header(char *file_name, unsigned int file_mode, long file_size, long last_modification, char type_flag, char *linked_file_name) {
    struct Header *header = init_header();
    if (file_name) strcpy(header->file_name, file_name);
    if (file_mode) sprintf(header->file_mode, "%o", file_mode);
    if (file_size) sprintf(header->file_size, "%lo", file_size);
    if (last_modification) sprintf(header->last_modification, "%lo", last_modification);
    if (type_flag) *header->type_flag = type_flag;
    if (linked_file_name) strcpy(header->linked_file_name, linked_file_name);
    return header;
}

return_type: struct Header { char file_name[100]; char file_mode[8]; char owner_id[8]; char owner_group_id[8]; char file_size[12]; char last_modification[12]; char checksum[8]; char type_flag[1]; char linked_file_name[100]; } *


decompiled_code:
void __fastcall destruct_header(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
free(a1);
}

original_code:
void destruct_header(Header header) {
    free(header);
}

canonical_original_code:
void destruct_header(struct Header *header) {
    free(header);
}

user_defined_types: struct Header { char file_name[100]; char file_mode[8]; char owner_id[8]; char owner_group_id[8]; char file_size[12]; char last_modification[12]; char checksum[8]; char type_flag[1]; char linked_file_name[100]; }


decompiled_code:
__int64 __fastcall header_file_name(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1;
}

original_code:
char * header_file_name(Header header) {
    return header->file_name;
}

canonical_original_code:
char *header_file_name(struct Header *header) {
    return header->file_name;
}

return_type: char *


decompiled_code:
__int64 __fastcall header_file_mode(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1 + 100, "%o", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch] BYREF

_isoc99_sscanf(a1 + 100, "%o", &v2);
return v2;
}

original_code:
mode_t header_file_mode(Header header) {
    mode_t file_mode;
    sscanf(header->file_mode, "%o", &file_mode);
    return file_mode;
}

canonical_original_code:
unsigned int header_file_mode(struct Header *header) {
    unsigned int file_mode;
    sscanf(header->file_mode, "%o", &file_mode);
    return file_mode;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall header_file_size(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 124, "%lo", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 124, "%lo", &v2);
return v2;
}

original_code:
off_t header_file_size(Header header) {
    off_t file_size;
    sscanf(header->file_size, "%lo", &file_size);
    return file_size;
}

canonical_original_code:
long header_file_size(struct Header *header) {
    long file_size;
    sscanf(header->file_size, "%lo", &file_size);
    return file_size;
}

return_type: long


decompiled_code:
__int64 __fastcall header_last_modification(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 136, "%lo", &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

_isoc99_sscanf(a1 + 136, "%lo", &v2);
return v2;
}

original_code:
time_t header_last_modification(Header header) {
    time_t last_modification;
    sscanf(header->last_modification, "%lo", &last_modification);
    return last_modification;
}

canonical_original_code:
long header_last_modification(struct Header *header) {
    long last_modification;
    sscanf(header->last_modification, "%lo", &last_modification);
    return last_modification;
}


decompiled_code:
__int64 __fastcall header_type_flag(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 156);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 156);
}

original_code:
char header_type_flag(Header header) {
    return *header->type_flag;
}

canonical_original_code:
char header_type_flag(struct Header *header) {
    return *header->type_flag;
}

return_type: char


decompiled_code:
__int64 __fastcall header_linked_file_name(__int64 a1)
{
return a1 + 157;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return a1 + 157;
}

original_code:
char * header_linked_file_name(Header header) {
    return header->linked_file_name;
}

canonical_original_code:
char *header_linked_file_name(struct Header *header) {
    return header->linked_file_name;
}


repo: NosicLin/Codger

decompiled_code:
__int64 __fastcall is_in_str(char a1, char *a2)
{
char v2; // al

while ( 1 )
{
v2 = *a2;
if ( !*a2 )
break;
++a2;
if ( v2 == a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char *a2)
{
char v2; // al

while ( 1 )
{
v2 = *a2;
if ( !*a2 )
break;
++a2;
if ( v2 == a1 )
return 1LL;
}
return 0LL;
}

original_code:
static inline int is_in_str(char c,const char* str)
{
 while(*str)
  if(c==*(str++)) return 1 ;
 return 0;
}

canonical_original_code:
static inline int is_in_str(char c, char *str)
{
 while(*str)
  if(c==*(str++)) return 1 ;
 return 0;
}

variable_types: c char

variable_types:
str
char *


decompiled_code:
__int64 __fastcall cal_args_num(char *a1, char *a2)
{
char *v2; // rbx
char v3; // di
_BOOL4 v4; // ebp
unsigned int v5; // er13

v2 = a1;
v3 = *a1;
if ( !v3 )
return 0;
v4 = 0;
v5 = 0;
do
{
if ( v4 )
{
v4 = is_in_str(v3, a2) == 0;
}
else if ( !(unsigned int)is_in_str(v3, a2) )
{
++v5;
v4 = 1;
}
v3 = *++v2;
}
while ( *v2 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2)
{
char *v2; // rbx
char v3; // di
_BOOL4 v4; // ebp
unsigned int v5; // er13

v2 = a1;
v3 = *a1;
if ( !v3 )
return 0;
v4 = 0;
v5 = 0;
do
{
if ( v4 )
{
v4 = func7(v3, a2) == 0;
}
else if ( !(unsigned int)func7(v3, a2) )
{
++v5;
v4 = 1;
}
v3 = *++v2;
}
while ( *v2 );
return v5;
}

original_code:
int cal_args_num(const char* buffer,const char* divide)
{
 int args_num=0;
 int now_word=0;
 while(*buffer)
 {
  if(now_word)
  {
   if(is_in_str(*buffer,divide))
   {
    now_word=0;
   }
  }
  else
  {
   if(!is_in_str(*buffer,divide))
   {
    now_word=1;
    args_num++;
   }
  }
  buffer++;
 }
 return args_num;
}

canonical_original_code:
int cal_args_num(char *buffer, char *divide)
{
 int args_num = 0;
 int now_word = 0;
 while(*buffer)
 {
  if(now_word)
  {
   if(is_in_str(*buffer,divide))
   {
    now_word=0;
   }
  }
  else
  {
   if(!is_in_str(*buffer,divide))
   {
    now_word=1;
    args_num++;
   }
  }
  buffer++;
 }
 return args_num;
}

variable_types:
buffer
char *

variable_types:
divide
char *


decompiled_code:
void __fastcall free_args(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func9(void *a1)
{
free(a1);
}

original_code:
void free_args(struct args* arg)
{
 free(arg);
}

canonical_original_code:
void free_args(struct args *arg)
{
 free(arg);
}

variable_types:
arg
struct args { int num; char **parg; } *


decompiled_code:
__int64 EgBuildin_GcUpdate()
{
s_buildin = GrGc_Update(s_buildin);
return 0LL;
}

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

original_code:
int EgBuildin_GcUpdate()
{
 s_buildin=GrGc_Update(s_buildin);
 return 0;
}


decompiled_code:
__int64 GrModule_BuildinInit()
{
__int64 v0; // rax
__int64 result; // rax

v0 = GrHash_GcNewFlag(4LL);
s_buildin = v0;
if ( v0 )
result = GrUtil_FillWithGrString(v0, &s_buildin_func, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 result; // rax

v0 = GrHash_GcNewFlag(4LL);
s_buildin = v0;
if ( v0 )
result = GrUtil_FillWithGrString(v0, &s_buildin_func, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int GrModule_BuildinInit()
{
 s_buildin=GrHash_GcNewFlag((1ul<<2));
 if(s_buildin==((void *)0))
 {
  return -1;
 }
 return GrUtil_FillWithGrString(s_buildin,s_buildin_func,
   (1ul<<2));
}


decompiled_code:
__int64 GrModule_BuildinExit()
{
s_buildin = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
s_buildin = 0LL;
return 0LL;
}

original_code:
int GrModule_BuildinExit()
{
 s_buildin=0;
 return 0;
}


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

if ( a1 <= 0x20 )
return 32LL;
LODWORD(result) = 32;
do
result = (unsigned int)(2 * result);
while ( a1 > (unsigned int)result );
return result;
}

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

if ( a1 <= 0x20 )
return 32LL;
LODWORD(result) = 32;
do
result = (unsigned int)(2 * result);
while ( a1 > (unsigned int)result );
return result;
}

original_code:
unsigned int round_log(unsigned size)
{
 unsigned int i=32;
 while(i<size)
 {
  i<<=1;
 }
 return i;
}

canonical_original_code:
unsigned int round_log(unsigned int size)
{
 unsigned int i = 32;
 while(i<size)
 {
  i<<=1;
 }
 return i;
}


decompiled_code:
void __fastcall splstr_realloc(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // eax
unsigned int v4; // ebp
void *v5; // r14
void *v6; // r12

v2 = *(_DWORD *)(a1 + 8);
v3 = round_log(a2);
if ( v2 > v3 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_realloc", 35LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Realloc Lose Data,Refuse", 1uLL, 0x18uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
v4 = v3;
v5 = *(void **)a1;
v6 = malloc(v3);
memcpy(v6, v5, v2 + 1);
free(v5);
*(_DWORD *)(a1 + 12) = v4;
*(_QWORD *)a1 = v6;
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // eax
unsigned int v4; // ebp
void *v5; // r14
void *v6; // r12

v2 = *(_DWORD *)(a1 + 8);
v3 = func0(a2);
if ( v2 > v3 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_realloc", 35LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Realloc Lose Data,Refuse", 1uLL, 0x18uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
v4 = v3;
v5 = *(void **)a1;
v6 = malloc(v3);
memcpy(v6, v5, v2 + 1);
free(v5);
*(_DWORD *)(a1 + 12) = v4;
*(_QWORD *)a1 = v6;
}
}

original_code:
void splstr_realloc(splstr* s_str,unsigned int size)
{
 char* new_str;
 char* old_str=s_str->str;
 unsigned int length=s_str->length;
 size=round_log(size);
 if(size<s_str->length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,35); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Realloc Lose Data,Refuse"); fprintf(stderr,")\n"); }while(0);
  return;
 }
 new_str=(char*)malloc(size);
 memcpy(new_str,old_str,length+1);
 free(old_str);
 s_str->max_cap=size;
 s_str->str=new_str;
}

canonical_original_code:
void splstr_realloc(struct tag_splstr *s_str, unsigned int size)
{
 char *new_str;
 char *old_str = s_str->str;
 unsigned int length = s_str->length;
 size=round_log(size);
 if(size<s_str->length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,35); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Realloc Lose Data,Refuse"); fprintf(stderr,")\n"); }while(0);
  return;
 }
 new_str=(char *)malloc(size);
 memcpy(new_str,old_str,length+1);
 free(old_str);
 s_str->max_cap=size;
 s_str->str=new_str;
}

variable_types: struct tag_splstr { char *str; unsigned int length; unsigned int max_cap; } *

variable_types:
length
unsigned int


decompiled_code:
__int64 __fastcall splstr_insert_char(__int64 a1, unsigned int a2, char a3)
{
unsigned int v3; // er12
unsigned int v5; // ebx
int v6; // esi
__int64 v7; // rdx
__int64 result; // rax

v3 = a2;
v5 = *(_DWORD *)(a1 + 8);
if ( v5 < a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_char", 65LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
v3 = v5;
}
v6 = *(_DWORD *)(a1 + 12);
if ( v5 + 1 == v6 )
splstr_realloc(a1, v6 + 1);
v7 = *(_QWORD *)a1;
LODWORD(result) = 0;
do
{
*(_BYTE *)(v7 + v5 + 1 - (unsigned int)result) = *(_BYTE *)(v7 + v5 - (unsigned int)result);
result = (unsigned int)(result + 1);
}
while ( v5 - v3 >= (unsigned int)result );
*(_BYTE *)(v7 + v3) = a3;
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, char a3)
{
unsigned int v3; // er12
unsigned int v5; // ebx
int v6; // esi
__int64 v7; // rdx
__int64 result; // rax

v3 = a2;
v5 = *(_DWORD *)(a1 + 8);
if ( v5 < a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_char", 65LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
v3 = v5;
}
v6 = *(_DWORD *)(a1 + 12);
if ( v5 + 1 == v6 )
func1(a1, v6 + 1);
v7 = *(_QWORD *)a1;
LODWORD(result) = 0;
do
{
*(_BYTE *)(v7 + v5 + 1 - (unsigned int)result) = *(_BYTE *)(v7 + v5 - (unsigned int)result);
result = (unsigned int)(result + 1);
}
while ( v5 - v3 >= (unsigned int)result );
*(_BYTE *)(v7 + v3) = a3;
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void splstr_insert_char(splstr* s_str,unsigned int pos,char c)
{
 char* str;
 unsigned int i;
 unsigned int length=s_str->length;
 int size;
 if(pos>length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,65); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=length;
 }
 if(length+1==s_str->max_cap)
 {
  splstr_realloc(s_str,s_str->max_cap+1);
 }
 str=s_str->str;
 size=length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+1]=str[pos+size-i];
 }
 str[pos]=c;
 s_str->length++;
}

canonical_original_code:
void splstr_insert_char(struct tag_splstr *s_str, unsigned int pos, char c)
{
 char *str;
 unsigned int i;
 unsigned int length = s_str->length;
 int size;
 if(pos>length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,65); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=length;
 }
 if(length+1==s_str->max_cap)
 {
  splstr_realloc(s_str,s_str->max_cap+1);
 }
 str=s_str->str;
 size=length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+1]=str[pos+size-i];
 }
 str[pos]=c;
 s_str->length++;
}

variable_types:
pos
unsigned int

variable_types: size int

user_defined_types: struct tag_splstr { char *str; unsigned int length; unsigned int max_cap; }


decompiled_code:
__int64 __fastcall splstr_push_front(__int64 a1, char a2)
{
return splstr_insert_char(a1, 0, a2);
}

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

original_code:
void splstr_push_front(splstr* s_str,char c)
{
 splstr_insert_char(s_str,0,c);
}

canonical_original_code:
void splstr_push_front(struct tag_splstr *s_str, char c)
{
 splstr_insert_char(s_str,0,c);
}


decompiled_code:
__int64 __fastcall splstr_push_back(__int64 a1, char a2)
{
return splstr_insert_char(a1, *(_DWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
return func2(a1, *(_DWORD *)(a1 + 8), a2);
}

original_code:
void splstr_push_back(splstr* s_str,char c)
{
 splstr_insert_char(s_str,s_str->length,c);
}

canonical_original_code:
void splstr_push_back(struct tag_splstr *s_str, char c)
{
 splstr_insert_char(s_str,s_str->length,c);
}


decompiled_code:
void *__fastcall splstr_insert_str(__int64 a1, unsigned int a2, const char *a3)
{
unsigned int v4; // er13
unsigned int v6; // er14
unsigned int v7; // ebx
unsigned int v8; // esi
__int64 v9; // rdi
unsigned int v10; // eax
void *result; // rax

v4 = a2;
v6 = strlen(a3);
v7 = *(_DWORD *)(a1 + 8);
if ( v7 < a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_str", 92LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
v4 = v7;
}
v8 = v7 + v6 + 1;
if ( v8 > *(_DWORD *)(a1 + 12) )
splstr_realloc(a1, v8);
v9 = *(_QWORD *)a1;
v10 = 0;
do
{
*(_BYTE *)(v9 + v7 + v6 - v10) = *(_BYTE *)(v9 + v7 - v10);
++v10;
}
while ( v7 - v4 >= v10 );
result = memcpy((void *)(v4 + v9), a3, v6);
*(_DWORD *)(a1 + 8) += v6;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, unsigned int a2, const char *a3)
{
unsigned int v4; // er13
unsigned int v6; // er14
unsigned int v7; // ebx
unsigned int v8; // esi
__int64 v9; // rdi
unsigned int v10; // eax
void *result; // rax

v4 = a2;
v6 = strlen(a3);
v7 = *(_DWORD *)(a1 + 8);
if ( v7 < a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_insert_str", 92LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
fwrite(")\n", 1uLL, 2uLL, stderr);
v4 = v7;
}
v8 = v7 + v6 + 1;
if ( v8 > *(_DWORD *)(a1 + 12) )
func1(a1, v8);
v9 = *(_QWORD *)a1;
v10 = 0;
do
{
*(_BYTE *)(v9 + v7 + v6 - v10) = *(_BYTE *)(v9 + v7 - v10);
++v10;
}
while ( v7 - v4 >= v10 );
result = memcpy((void *)(v4 + v9), a3, v6);
*(_DWORD *)(a1 + 8) += v6;
return result;
}

original_code:
void splstr_insert_str(splstr* d_str,unsigned int pos,const char* s_str)
{
 unsigned int s_length=strlen(s_str);
 char* str;
 unsigned int i;
 unsigned int d_length=d_str->length;
 unsigned size;
 if(pos>d_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,92); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=d_length;
 }
 if(d_length+s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,d_length+s_length+1);
 }
 str=d_str->str;
 size=d_length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+s_length]=str[pos+size-i];
 }
 memcpy(str+pos,s_str,s_length);
 d_str->length+=s_length;
}

canonical_original_code:
void splstr_insert_str(struct tag_splstr *d_str, unsigned int pos, char *s_str)
{
 unsigned int s_length = strlen(s_str);
 char *str;
 unsigned int i;
 unsigned int d_length = d_str->length;
 unsigned int size;
 if(pos>d_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,92); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  pos=d_length;
 }
 if(d_length+s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,d_length+s_length+1);
 }
 str=d_str->str;
 size=d_length-pos;
 for(i=0;i<=size;i++)
 {
  str[pos+size-i+s_length]=str[pos+size-i];
 }
 memcpy(str+pos,s_str,s_length);
 d_str->length+=s_length;
}

variable_types:
i
unsigned int


decompiled_code:
void *__fastcall splstr_insert_splstr(__int64 a1, unsigned int a2, const char **a3)
{
return splstr_insert_str(a1, a2, *a3);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, unsigned int a2, const char **a3)
{
return func5(a1, a2, *a3);
}

original_code:
void splstr_insert_splstr(splstr* d_str,unsigned pos,splstr* s_str)
{
 splstr_insert_str(d_str,pos,s_str->str);
}

canonical_original_code:
void splstr_insert_splstr(struct tag_splstr *d_str, unsigned int pos, struct tag_splstr *s_str)
{
 splstr_insert_str(d_str,pos,s_str->str);
}


decompiled_code:
size_t __fastcall splstr_remove(__int64 *a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
int v4; // er10
size_t result; // rax
__int64 v6; // rcx
unsigned int v7; // edx

v3 = *((_DWORD *)a1 + 2);
if ( v3 <= a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove", 135LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
result = fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
v4 = a3;
LODWORD(result) = a2 + a3;
if ( a2 + a3 > v3 )
{
v4 = v3 - a2;
LODWORD(result) = *((_DWORD *)a1 + 2);
}
v6 = *a1;
v7 = result - v4;
do
{
*(_BYTE *)(v6 + v7) = *(_BYTE *)(v6 + (unsigned int)result);
result = (unsigned int)(result + 1);
++v7;
}
while ( v3 >= (unsigned int)result );
*((_DWORD *)a1 + 2) -= v4;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 *a1, unsigned int a2, int a3)
{
unsigned int v3; // er8
int v4; // er10
size_t result; // rax
__int64 v6; // rcx
unsigned int v7; // edx

v3 = *((_DWORD *)a1 + 2);
if ( v3 <= a2 )
{
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove", 135LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Pos Out Of Range", 1uLL, 0x10uLL, stderr);
result = fwrite(")\n", 1uLL, 2uLL, stderr);
}
else
{
v4 = a3;
LODWORD(result) = a2 + a3;
if ( a2 + a3 > v3 )
{
v4 = v3 - a2;
LODWORD(result) = *((_DWORD *)a1 + 2);
}
v6 = *a1;
v7 = result - v4;
do
{
*(_BYTE *)(v6 + v7) = *(_BYTE *)(v6 + (unsigned int)result);
result = (unsigned int)(result + 1);
++v7;
}
while ( v3 >= (unsigned int)result );
*((_DWORD *)a1 + 2) -= v4;
}
return result;
}

original_code:
void splstr_remove(splstr* s_str,unsigned int pos,unsigned int size)
{
 unsigned int s_length=s_str->length;
 char* str=s_str->str;
 unsigned int i;
 if(pos>=s_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,135); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 if(pos+size>s_length)
 {
  size=s_length-pos;
 }
 for(i=pos+size;i<=s_length;i++)
 {
  str[i-size]=str[i];
 }
 s_str->length-=size;
}

canonical_original_code:
void splstr_remove(struct tag_splstr *s_str, unsigned int pos, unsigned int size)
{
 unsigned int s_length = s_str->length;
 char *str = s_str->str;
 unsigned int i;
 if(pos>=s_length)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,135); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Pos Out Of Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 if(pos+size>s_length)
 {
  size=s_length-pos;
 }
 for(i=pos+size;i<=s_length;i++)
 {
  str[i-size]=str[i];
 }
 s_str->length-=size;
}

variable_types:
size
unsigned int


decompiled_code:
size_t __fastcall splstr_remove_range(__int64 *a1, unsigned int a2, unsigned int a3)
{
if ( a3 >= a2 )
return splstr_remove(a1, a2, a3 - a2 + 1);
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove_range", 123LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Error Range", 1uLL, 0xBuLL, stderr);
return fwrite(")\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func8(__int64 *a1, unsigned int a2, unsigned int a3)
{
if ( a3 >= a2 )
return func7(a1, a2, a3 - a2 + 1);
fprintf(stderr, "%s::%s(Line %d):", "splstr.c", "splstr_remove_range", 123LL);
fprintf(stderr, "%s(", "WARN");
fwrite("Error Range", 1uLL, 0xBuLL, stderr);
return fwrite(")\n", 1uLL, 2uLL, stderr);
}

original_code:
void splstr_remove_range(splstr* s_str,unsigned int begin,unsigned int end)
{
 if(end<begin)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,123); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Error Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 return splstr_remove(s_str,begin,end-begin+1);
}

canonical_original_code:
void splstr_remove_range(struct tag_splstr *s_str, unsigned int begin, unsigned int end)
{
 if(end<begin)
 {
  do{ fprintf(stderr,"%s::%s(Line %d):","splstr.c",__func__,123); fprintf(stderr,"%s(","WARN"); fprintf(stderr,"Error Range"); fprintf(stderr,")\n"); }while(0);
  return ;
 }
 return splstr_remove(s_str,begin,end-begin+1);
}

variable_types:
begin
unsigned int

variable_types:
end
unsigned int


decompiled_code:
void *__fastcall splstr_assign(__int64 a1, const char *a2)
{
int v2; // er12
unsigned int v3; // ebp
void *result; // rax

v2 = strlen(a2);
v3 = v2 + 1;
if ( (unsigned int)(v2 + 1) > *(_DWORD *)(a1 + 12) )
splstr_realloc(a1, v3);
result = memcpy(*(void **)a1, a2, v3);
*(_DWORD *)(a1 + 8) = v2;
return result;
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1, const char *a2)
{
int v2; // er12
unsigned int v3; // ebp
void *result; // rax

v2 = strlen(a2);
v3 = v2 + 1;
if ( (unsigned int)(v2 + 1) > *(_DWORD *)(a1 + 12) )
func1(a1, v3);
result = memcpy(*(void **)a1, a2, v3);
*(_DWORD *)(a1 + 8) = v2;
return result;
}

original_code:
void splstr_assign(splstr* d_str,const char* s_str)
{
 unsigned int s_length=strlen(s_str);
 char* str;
 if(s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,s_length+1);
 }
 str=d_str->str;
 memcpy(str,s_str,s_length+1);
 d_str->length=s_length;
}

canonical_original_code:
void splstr_assign(struct tag_splstr *d_str, char *s_str)
{
 unsigned int s_length = strlen(s_str);
 char *str;
 if(s_length+1>d_str->max_cap)
 {
  splstr_realloc(d_str,s_length+1);
 }
 str=d_str->str;
 memcpy(str,s_str,s_length+1);
 d_str->length=s_length;
}


decompiled_code:
void *__fastcall splstr_copy(__int64 a1, const char **a2)
{
return splstr_assign(a1, *a2);
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1, const char **a2)
{
return func11(a1, *a2);
}

original_code:
void splstr_copy(splstr* d_str,splstr* s_str)
{
 splstr_assign(d_str,s_str->str);
}

canonical_original_code:
void splstr_copy(struct tag_splstr *d_str, struct tag_splstr *s_str)
{
 splstr_assign(d_str,s_str->str);
}


decompiled_code:
__int64 __fastcall splstr_length(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int splstr_length(splstr* s_str)
{
 return s_str->length;
}

canonical_original_code:
int splstr_length(struct tag_splstr *s_str)
{
 return s_str->length;
}


decompiled_code:
void *splstr_alloc()
{
return malloc(0x10uLL);
}

canonical_decompiled_code:
void *func14()
{
return malloc(0x10uLL);
}

original_code:
splstr* splstr_alloc()
{
 return (splstr*) malloc(sizeof(splstr));
}

canonical_original_code:
struct tag_splstr *splstr_alloc()
{
 return (struct tag_splstr *) malloc(sizeof(splstr));
}

return_type: struct tag_splstr { char *str; unsigned int length; unsigned int max_cap; } *


decompiled_code:
void *__fastcall splstr_init_str(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
void *v4; // rax

v2 = strlen(a2);
v3 = round_log(v2);
*(_DWORD *)(a1 + 12) = v3;
*(_DWORD *)(a1 + 8) = v2;
v4 = malloc(v3);
*(_QWORD *)a1 = v4;
return memcpy(v4, a2, v2 + 1);
}

canonical_decompiled_code:
void *__fastcall func17(__int64 a1, const char *a2)
{
unsigned int v2; // ebx
unsigned int v3; // eax
void *v4; // rax

v2 = strlen(a2);
v3 = func0(v2);
*(_DWORD *)(a1 + 12) = v3;
*(_DWORD *)(a1 + 8) = v2;
v4 = malloc(v3);
*(_QWORD *)a1 = v4;
return memcpy(v4, a2, v2 + 1);
}

original_code:
void splstr_init_str(splstr* s_str,const char* str)
{
 unsigned length=strlen(str);
 unsigned max_cap=round_log(length);
 s_str->max_cap=max_cap;
 s_str->length=length;
 s_str->str=(char*)malloc(max_cap);
 memcpy(s_str->str,str,length+1);
}

canonical_original_code:
void splstr_init_str(struct tag_splstr *s_str, char *str)
{
 unsigned int length = strlen(str);
 unsigned int max_cap = round_log(length);
 s_str->max_cap=max_cap;
 s_str->length=length;
 s_str->str=(char *)malloc(max_cap);
 memcpy(s_str->str,str,length+1);
}


decompiled_code:
void __fastcall splstr_destory(__int64 a1)
{
free(*(void **)a1);
*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)a1 = 0LL;
}

original_code:
void splstr_destory(splstr* s_str)
{
 free(s_str->str);
 s_str->length=0;
 s_str->max_cap=0;
 s_str->str=((void *)0);
}

canonical_original_code:
void splstr_destory(struct tag_splstr *s_str)
{
 free(s_str->str);
 s_str->length=0;
 s_str->max_cap=0;
 s_str->str=((void *)0);
}


decompiled_code:
void __fastcall splstr_free(void *ptr)
{
splstr_destory((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func19(void *ptr)
{
func18((__int64)ptr);
free(ptr);
}

original_code:
void splstr_free(splstr* s_str)
{
 splstr_destory(s_str);
 free(s_str);
}

canonical_original_code:
void splstr_free(struct tag_splstr *s_str)
{
 splstr_destory(s_str);
 free(s_str);
}


decompiled_code:
void __fastcall list_add(_QWORD *a1, __int64 a2)
{
_list_add(a1, a2, *(_QWORD **)(a2 + 8));
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, __int64 a2)
{
func1(a1, a2, *(_QWORD **)(a2 + 8));
}

original_code:
static inline void list_add(struct list_head *new_list, struct list_head *head)
{
 __list_add(new_list, head, head->next);
}

variable_types: struct list_head { struct list_head *prev; struct list_head *next; } *

variable_types:
head
struct list_head *


decompiled_code:
void __fastcall list_add_tail(_QWORD *a1, __int64 *a2)
{
_list_add(a1, *a2, a2);
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, __int64 *a2)
{
func1(a1, *a2, a2);
}

original_code:
static inline void list_add_tail(struct list_head *new_list, struct list_head *head)
{
 __list_add(new_list, head->prev, head);
}

user_defined_types: struct list_head { struct list_head *prev; struct list_head *next; }


decompiled_code:
_BOOL8 __fastcall list_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

original_code:
static inline int list_empty(const struct list_head *head)
{
 return head->next == head;
}

canonical_original_code:
static inline int list_empty(struct list_head *head)
{
 return head->next == head;
}


decompiled_code:
void *__fastcall Gr_Alloc(size_t a1)
{
if ( !a1 )
a1 = 1LL;
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
if ( !a1 )
a1 = 1LL;
return malloc(a1);
}

original_code:
static inline void* Gr_Alloc(size_t size)
{
 size= size==0?1:size;
 return malloc(size);
}

canonical_original_code:
static inline void *Gr_Alloc(unsigned long size)
{
 size= size==0?1:size;
 return malloc(size);
}

variable_types:
size
unsigned long

return_type: void *


decompiled_code:
void *__fastcall pages_idx_free(int a1)
{
void *result; // rax

if ( pages_idx_free_pos <= a1 )
_assert_fail("pos<pages_idx_free_pos", "memory.c", 0x6Bu, "pages_idx_free");
result = pages_idx_array;
*((_QWORD *)pages_idx_array + a1) = pages_idx_next;
pages_idx_next = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
void *result; // rax

if ( pages_idx_free_pos <= a1 )
_assert_fail("pos<pages_idx_free_pos", "memory.c", 0x6Bu, "pages_idx_free");
result = pages_idx_array;
*((_QWORD *)pages_idx_array + a1) = pages_idx_next;
pages_idx_next = a1;
return result;
}

original_code:
static inline void pages_idx_free(int pos)
{
 ((void) sizeof ((pos<pages_idx_free_pos) ? 1 : 0), __extension__ ({ if (pos<pages_idx_free_pos) ; else __assert_fail ("pos<pages_idx_free_pos", "memory.c", 107, __extension__ __PRETTY_FUNCTION__); }));
 pages_idx_array[pos]=(void*)pages_idx_next;
 pages_idx_next=pos;
}

canonical_original_code:
static inline void pages_idx_free(int pos)
{
 ((void) sizeof ((pos<pages_idx_free_pos) ? 1 : 0), __extension__ ({ if (pos<pages_idx_free_pos) ; else __assert_fail ("pos<pages_idx_free_pos", "memory.c", 107, __extension__ __PRETTY_FUNCTION__); }));
 pages_idx_array[pos]=(void *)pages_idx_next;
 pages_idx_next=pos;
}

variable_types: pos int


decompiled_code:
void __fastcall Gr_Free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func9(void *a1)
{
free(a1);
}

original_code:
static inline void Gr_Free(void* ptr)
{
 free(ptr);
}

canonical_original_code:
static inline void Gr_Free(void *ptr)
{
 free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
__int64 page_idx_enlarge()
{
int v0; // ebx
int v1; // er12
void *v2; // rax
void *v3; // rbp
void *v4; // r13

v0 = pages_idx_cap;
v1 = 2 * pages_idx_cap;
if ( (pages_idx_cap & 0x40000000) != 0 )
return 0xFFFFFFFFLL;
v2 = Gr_Alloc(8LL * v1);
v3 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = pages_idx_array;
memcpy(v2, pages_idx_array, 8LL * v0);
Gr_Free(v4);
pages_idx_array = v3;
pages_idx_cap = v1;
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
int v1; // er12
void *v2; // rax
void *v3; // rbp
void *v4; // r13

v0 = pages_idx_cap;
v1 = 2 * pages_idx_cap;
if ( (pages_idx_cap & 0x40000000) != 0 )
return 0xFFFFFFFFLL;
v2 = func7(8LL * v1);
v3 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = pages_idx_array;
memcpy(v2, pages_idx_array, 8LL * v0);
func9(v4);
pages_idx_array = v3;
pages_idx_cap = v1;
return 0LL;
}

original_code:
static inline int page_idx_enlarge()
{
 int enlarge_size=pages_idx_cap<<1;
 if(enlarge_size<0)
 {
  return -1;
 }
 void** new_idx=(void**)Gr_Alloc(enlarge_size*sizeof(void*));
 if(new_idx==((void *)0))
 {
  return -1;
 }
 memcpy(new_idx,pages_idx_array,sizeof(void*) * pages_idx_cap);
 Gr_Free(pages_idx_array);
 pages_idx_array=new_idx;
 pages_idx_cap=enlarge_size;
 return 0;
}

canonical_original_code:
static inline int page_idx_enlarge()
{
 int enlarge_size = pages_idx_cap<<1;
 if(enlarge_size<0)
 {
  return -1;
 }
 void **new_idx = (void**)Gr_Alloc(enlarge_size*sizeof(void*));
 if(new_idx==((void *)0))
 {
  return -1;
 }
 memcpy(new_idx,pages_idx_array,sizeof(void *) * pages_idx_cap);
 Gr_Free(pages_idx_array);
 pages_idx_array=new_idx;
 pages_idx_cap=enlarge_size;
 return 0;
}


decompiled_code:
__int64 __fastcall pages_idx_alloc(__int64 a1)
{
unsigned int v1; // ebx
_QWORD *v2; // rax
int v4; // ebp

v1 = pages_idx_next;
if ( pages_idx_next == -1 )
{
v4 = pages_idx_free_pos;
if ( pages_idx_free_pos != pages_idx_cap || (int)page_idx_enlarge() >= 0 )
{
pages_idx_free_pos = v4 + 1;
*((_QWORD *)pages_idx_array + v4) = a1;
v1 = v4;
}
}
else
{
v2 = (char *)pages_idx_array + 8 * pages_idx_next;
pages_idx_next = *v2;
*v2 = a1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
unsigned int v1; // ebx
_QWORD *v2; // rax
int v4; // ebp

v1 = pages_idx_next;
if ( pages_idx_next == -1 )
{
v4 = pages_idx_free_pos;
if ( pages_idx_free_pos != pages_idx_cap || (int)func10() >= 0 )
{
pages_idx_free_pos = v4 + 1;
*((_QWORD *)pages_idx_array + v4) = a1;
v1 = v4;
}
}
else
{
v2 = (char *)pages_idx_array + 8 * pages_idx_next;
pages_idx_next = *v2;
*v2 = a1;
}
return v1;
}

original_code:
static inline int pages_idx_alloc(void* ptr)
{
 int ret;
 if(pages_idx_next!=-1)
 {
  ret=pages_idx_next;
  pages_idx_next=(int) pages_idx_array[ret];
  pages_idx_array[ret]=ptr;
  return ret;
 }
 if(pages_idx_free_pos==pages_idx_cap)
 {
  if(page_idx_enlarge()<0)
  {
   return -1;
  }
 }
 ret=pages_idx_free_pos++;
 pages_idx_array[ret]=ptr;
 return ret;
}

canonical_original_code:
static inline int pages_idx_alloc(void *ptr)
{
 int ret;
 if(pages_idx_next!=-1)
 {
  ret=pages_idx_next;
  pages_idx_next=(int) pages_idx_array[ret];
  pages_idx_array[ret]=ptr;
  return ret;
 }
 if(pages_idx_free_pos==pages_idx_cap)
 {
  if(page_idx_enlarge()<0)
  {
   return -1;
  }
 }
 ret=pages_idx_free_pos++;
 pages_idx_array[ret]=ptr;
 return ret;
}

variable_types: ret int