decompiled_code:
__int64 __fastcall free_pools(__int64 a1)
{
void **v1; // rbx

v1 = (void **)(a1 + 16);
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != (void **)(a1 + 176) );
return init_pools(a1);
}

original_code:
void
free_pools (pools_t *pools)
{
    int i;
    for (i = 0; i < 20; ++i)
 if (pools->pools[i] != 0)
     free(pools->pools[i]);
    init_pools(pools);
}

canonical_original_code:
void free_pools(struct pools_t *pools)
{
    int i;
    for (i = 0; i < 20; ++i)
 if (pools->pools[i] != 0)
     free(pools->pools[i]);
    init_pools(pools);
}


repo: mnemonikk/emacs-otr

original_code:
static inline void*
pools_alloc (pools_t *pools, size_t size)
{
    void *p;
    size_t padded_size = (size + sizeof(long) - 1) / sizeof(long);
    if (pools->fill_ptr + padded_size >= (((size_t)2048) << pools->active_pool))
 return _pools_alloc(pools, size);
    p = pools->pools[pools->active_pool] + pools->fill_ptr;
    pools->fill_ptr += padded_size;
    return p;
}

canonical_original_code:
static inline void *pools_alloc(struct pools_t *pools, unsigned long size)
{
    void *p;
    unsigned long padded_size = (size + sizeof(long) - 1) / sizeof(long);
    if (pools->fill_ptr + padded_size >= (((unsigned long)2048) << pools->active_pool))
 return _pools_alloc(pools, size);
    p = pools->pools[pools->active_pool] + pools->fill_ptr;
    pools->fill_ptr += padded_size;
    return p;
}

variable_types: struct pools_t { int active_pool; unsigned long fill_ptr; long *pools[20]; } *

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


filename

decompiled_code:
__int64 __fastcall filename(void *src, unsigned int a2, unsigned int a3, const char *a4)
{
int v6; // ebx
int v7; // edx
__int64 result; // rax
int v9; // edx
int v10; // [rsp+8h] [rbp-BF0h] BYREF
char v11; // [rsp+Fh] [rbp-BE9h] BYREF
int v12[2]; // [rsp+10h] [rbp-BE8h] BYREF
char dest[1496]; // [rsp+18h] [rbp-BE0h] BYREF
char v14[1544]; // [rsp+5F0h] [rbp-608h] BYREF

v11 = 0;
v10 = 0;
v6 = strlen((const char *)src);
v12[0] = _bswap_32(a2);
v12[1] = _bswap_32(a3);
memcpy(dest, src, v6 + 1);
send_buf(v12, (unsigned int)(v6 + 9), &server, 6LL, 0LL, v14);
v7 = select_call((unsigned int)server, 1LL, 0LL, 1LL);
result = 1LL;
if ( v7 == 1 )
{
v9 = recv_buf(v14, 1500LL, (unsigned int)server, &server, &v11, &v10);
result = 1LL;
if ( v9 != 5 )
{
result = 3LL;
if ( v11 == 8 )
{
printf("Error %s does not exist on %s\n", (const char *)src, a4);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, unsigned int a2, unsigned int a3, const char *a4)
{
int v6; // ebx
int v7; // edx
__int64 result; // rax
int v9; // edx
int v10; // [rsp+8h] [rbp-BF0h] BYREF
char v11; // [rsp+Fh] [rbp-BE9h] BYREF
int v12[2]; // [rsp+10h] [rbp-BE8h] BYREF
char dest[1496]; // [rsp+18h] [rbp-BE0h] BYREF
char v14[1544]; // [rsp+5F0h] [rbp-608h] BYREF

v11 = 0;
v10 = 0;
v6 = strlen((const char *)src);
v12[0] = func0(a2);
v12[1] = func0(a3);
memcpy(dest, src, v6 + 1);
send_buf(v12, (unsigned int)(v6 + 9), &server, 6LL, 0LL, v14);
v7 = select_call((unsigned int)server, 1LL, 0LL, 1LL);
result = 1LL;
if ( v7 == 1 )
{
v9 = recv_buf(v14, 1500LL, (unsigned int)server, &server, &v11, &v10);
result = 1LL;
if ( v9 != 5 )
{
result = 3LL;
if ( v11 == 8 )
{
printf("Error %s does not exist on %s\n", (const char *)src, a4);
result = 0LL;
}
}
}
return result;
}

original_code:
STATE filename(char *fname, int32_t buf_size, int32_t window_size,
     char *server_machine) {
   uint8_t packet[1500];
   uint8_t buf[1500];
   uint8_t flag = 0;
   int32_t seq_num = 0;
   int32_t fname_len = strlen(fname) + 1;
   int32_t recv_check = 0;
 buf_size = htonl(buf_size);
 window_size = htonl(window_size);
   memcpy(buf, &buf_size, 4);
 memcpy(&buf[4], &window_size, 4);
   memcpy(&buf[8], fname, fname_len);
   send_buf(buf, fname_len + 8, &server, FNAME, 0, packet);
   if (select_call(server.sk_num, 1, 0, NOT_NULL) == 1) {
      recv_check = recv_buf(packet, 1500, server.sk_num, &server, &flag, &seq_num);
      if (recv_check == CRC_ERROR) {
         return FILENAME;
      }
      if (flag == FNAME_BAD) {
         printf("Error %s does not exist on %s\n", fname, server_machine);
         return (DONE);
      }
      return (FILE_OK);
   }
   return (FILENAME);
}

canonical_original_code:
enum State filename(char *fname, int buf_size, int window_size, char *server_machine) {
   unsigned char packet[1500];
   unsigned char buf[1500];
   unsigned char flag = 0;
   int seq_num = 0;
   int fname_len = strlen(fname) + 1;
   int recv_check = 0;
 buf_size = htonl(buf_size);
 window_size = htonl(window_size);
   memcpy(buf, &buf_size, 4);
 memcpy(&buf[4], &window_size, 4);
   memcpy(&buf[8], fname, fname_len);
   send_buf(buf, fname_len + 8, &server, FNAME, 0, packet);
   if (select_call(server.sk_num, 1, 0, NOT_NULL) == 1) {
      recv_check = recv_buf(packet, 1500, server.sk_num, &server, &flag, &seq_num);
      if (recv_check == CRC_ERROR) {
         return FILENAME;
      }
      if (flag == FNAME_BAD) {
         printf("Error %s does not exist on %s\n", fname, server_machine);
         return (DONE);
      }
      return (FILE_OK);
   }
   return (FILENAME);
}

variable_types:
fname
char *

variable_types:
packet
unsigned char [1500]

variable_types:
buf
unsigned char [1500]

variable_types:
flag
unsigned char

return_type: enum State { DONE=0, FILENAME=1, RECV_DATA=2, FILE_OK=3, SELREJ=4 }


decompiled_code:
__int64 __fastcall buffer_data(int a1, int a2, int a3, const void *a4, __int64 a5)
{
__int64 v7; // rbx
__int64 result; // rax

v7 = 1512LL * a2;
memcpy((void *)(*(_QWORD *)(a5 + 8) + v7 + 9), a4, a3);
*(_DWORD *)(*(_QWORD *)(a5 + 8) + v7 + 4) = a3;
*(_DWORD *)(*(_QWORD *)(a5 + 8) + v7) = a1;
result = *(_QWORD *)(a5 + 8);
*(_BYTE *)(result + v7 + 8) = 0;
return result;
}

original_code:
void buffer_data(int32_t seq_num, int32_t seq_num_ndx, int32_t data_len,
       uint8_t *data_buf, Window *window ) {
 memcpy(window->window[seq_num_ndx].data, data_buf, data_len);
 window->window[seq_num_ndx].length = data_len;
 window->window[seq_num_ndx].seq_num = seq_num;
 window->window[seq_num_ndx].written = 0;
}

canonical_original_code:
void buffer_data(int seq_num, int seq_num_ndx, int data_len, unsigned char *data_buf, struct window *window) {
 memcpy(window->window[seq_num_ndx].data, data_buf, data_len);
 window->window[seq_num_ndx].length = data_len;
 window->window[seq_num_ndx].seq_num = seq_num;
 window->window[seq_num_ndx].written = 0;
}

variable_types: struct window { unsigned int window_size; struct packet { int seq_num; unsigned int length; unsigned char written; unsigned char data[1500]; } *window; unsigned int head; } *

return_type: void

user_defined_types: struct window { unsigned int window_size; struct packet *window; unsigned int head; }


decompiled_code:
unsigned int __fastcall check_args(int a1, const char **a2)
{
size_t v2; // rax
size_t v3; // rax
unsigned int v4; // eax
unsigned int result; // eax

if ( a1 != 8 )
{
printf("Usage %s fromFile toFile buffer_size error_rate window_size hostname port\n", *a2);
exit(-1);
}
v2 = strlen(a2[1]);
if ( v2 > 0x3E8 )
{
printf("FROM filename to long needs to be less than 1000 and is: %d\n", v2);
exit(-1);
}
v3 = strlen(a2[2]);
if ( v3 > 0x3E8 )
{
printf("TO filename to long needs to be less than 1000 and is: %d\n", v3);
exit(-1);
}
v4 = atoi(a2[3]);
if ( v4 - 400 > 0x3E8 )
{
printf("Buffer size needs to be between 400 and 1400 and is: %d\n", v4);
exit(-1);
}
result = atoi(a2[4]);
if ( result )
{
printf("Error rate needs to be between 0 and less than 1 and is: %d\n", result);
exit(-1);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func6(int a1, const char **a2)
{
size_t v2; // rax
size_t v3; // rax
unsigned int v4; // eax
unsigned int result; // eax

if ( a1 != 8 )
{
printf("Usage %s fromFile toFile buffer_size error_rate window_size hostname port\n", *a2);
exit(-1);
}
v2 = strlen(a2[1]);
if ( v2 > 0x3E8 )
{
printf("FROM filename to long needs to be less than 1000 and is: %d\n", v2);
exit(-1);
}
v3 = strlen(a2[2]);
if ( v3 > 0x3E8 )
{
printf("TO filename to long needs to be less than 1000 and is: %d\n", v3);
exit(-1);
}
v4 = atoi(a2[3]);
if ( v4 - 400 > 0x3E8 )
{
printf("Buffer size needs to be between 400 and 1400 and is: %d\n", v4);
exit(-1);
}
result = atoi(a2[4]);
if ( result )
{
printf("Error rate needs to be between 0 and less than 1 and is: %d\n", result);
exit(-1);
}
return result;
}

original_code:
void check_args(int argc, char **argv) {
   if (argc != 8) {
      printf("Usage %s fromFile toFile buffer_size error_rate window_size hostname port\n", argv[0]);
      exit(-1);
   }
   if (strlen(argv[1]) > 1000) {
      printf("FROM filename to long needs to be less than 1000 and is: %d\n", strlen(argv[1]));
      exit(-1);
   }
   if (strlen(argv[2]) > 1000) {
      printf("TO filename to long needs to be less than 1000 and is: %d\n", strlen(argv[2]));
      exit(-1);
   }
   if (atoi(argv[3]) < 400 || atoi(argv[3]) > 1400) {
      printf("Buffer size needs to be between 400 and 1400 and is: %d\n", atoi(argv[3]));
      exit(-1);
   }
   if (atoi(argv[4]) < 0 || atoi(argv[4]) >= 1) {
      printf("Error rate needs to be between 0 and less than 1 and is: %d\n", atoi(argv[4]));
      exit(-1);
   }
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 udp_server()
{
int v0; // eax
unsigned int v1; // ebx
unsigned __int16 v2; // ax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
v0 = socket(2, 2, 0);
if ( v0 < 0 )
{
perror("socket");
exit(-1);
}
v1 = v0;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = _bswap_16(0);
if ( (int)bindMod(v1, &addr, 16LL) < 0 )
{
perror("udp_server, bind");
exit(-1);
}
getsockname(v1, &addr, &len);
v2 = _bswap_16(*(__int16 *)addr.sa_data);
printf("Using Port #: %d\n", v2);
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
unsigned int v1; // ebx
unsigned __int16 v2; // ax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
v0 = socket(2, 2, 0);
if ( v0 < 0 )
{
perror("socket");
exit(-1);
}
v1 = v0;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = func0(0);
if ( (int)bindMod(v1, &addr, 16LL) < 0 )
{
perror("udp_server, bind");
exit(-1);
}
getsockname(v1, &addr, &len);
v2 = func0(*(__int16 *)addr.sa_data);
printf("Using Port #: %d\n", v2);
return v1;
}

original_code:
int32_t udp_server() {
   int sk = 0;
   struct sockaddr_in local;
   uint32_t len = sizeof(local);
   if ((sk = socket(2, SOCK_DGRAM, 0)) < 0) {
      perror("socket");
      exit(-1);
   }
   local.sin_family = 2;
   local.sin_addr.s_addr = ((in_addr_t) 0x00000000);
   local.sin_port = htons(0);
   if (bindMod(sk, (struct sockaddr *)&local, sizeof(local)) < 0) {
      perror("udp_server, bind");
      exit(-1);
   }
   getsockname(sk, (struct sockaddr *)&local, &len);
   printf("Using Port #: %d\n", ntohs(local.sin_port));
   return (sk);
}

canonical_original_code:
int udp_server() {
   int sk = 0;
   struct sockaddr_in local;
   unsigned int len = sizeof(local);
   if ((sk = socket(2, SOCK_DGRAM, 0)) < 0) {
      perror("socket");
      exit(-1);
   }
   local.sin_family = 2;
   local.sin_addr.s_addr = ((unsigned int) 0x00000000);
   local.sin_port = htons(0);
   if (bindMod(sk, (struct sockaddr *)&local, sizeof(local)) < 0) {
      perror("udp_server, bind");
      exit(-1);
   }
   getsockname(sk, (struct sockaddr *)&local, &len);
   printf("Using Port #: %d\n", ntohs(local.sin_port));
   return (sk);
}

variable_types: sk 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:
len
unsigned int

return_type: int

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

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


decompiled_code:
__int64 __fastcall udp_client_setup(char *name, __int16 a2, __int64 a3)
{
int v4; // eax
struct hostent *v5; // rax
__int64 result; // rax

*(_DWORD *)a3 = 0;
*(_DWORD *)(a3 + 20) = 16;
v4 = socket(2, 2, 0);
*(_DWORD *)a3 = v4;
if ( v4 < 0 )
{
perror("udp_client_setup, socket");
exit(-1);
}
*(_WORD *)(a3 + 4) = 2;
v5 = gethostbyname(name);
if ( v5 )
{
memcpy((void *)(a3 + 8), *(const void **)v5->h_addr_list, v5->h_length);
*(_WORD *)(a3 + 6) = _bswap_16(a2);
result = 0LL;
}
else
{
printf("Host not found: %s\n", name);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *name, __int16 a2, __int64 a3)
{
int v4; // eax
struct hostent *v5; // rax
__int64 result; // rax

*(_DWORD *)a3 = 0;
*(_DWORD *)(a3 + 20) = 16;
v4 = socket(2, 2, 0);
*(_DWORD *)a3 = v4;
if ( v4 < 0 )
{
perror("udp_client_setup, socket");
exit(-1);
}
*(_WORD *)(a3 + 4) = 2;
v5 = gethostbyname(name);
if ( v5 )
{
memcpy((void *)(a3 + 8), *(const void **)v5->h_addr_list, v5->h_length);
*(_WORD *)(a3 + 6) = func0(a2);
result = 0LL;
}
else
{
printf("Host not found: %s\n", name);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int32_t udp_client_setup(char *hostname, uint16_t port_num, Connection *connection) {
   struct hostent *hp = ((void *)0);
   connection->sk_num = 0;
   connection->len = sizeof(struct sockaddr_in);
   if((connection->sk_num = socket(2, SOCK_DGRAM, 0)) < 0) {
      perror("udp_client_setup, socket");
      exit(-1);
   }
   connection->remote.sin_family = 2;
   hp = gethostbyname(hostname);
   if (hp == ((void *)0)) {
      printf("Host not found: %s\n", hostname);
      return -1;
   }
   memcpy(&(connection->remote.sin_addr), hp->h_addr_list[0], hp->h_length);
   connection->remote.sin_port = htons(port_num);
   return 0;
}

canonical_original_code:
int udp_client_setup(char *hostname, unsigned short port_num, struct connection *connection) {
   struct hostent *hp = ((void *)0);
   connection->sk_num = 0;
   connection->len = sizeof(struct sockaddr_in);
   if((connection->sk_num = socket(2, SOCK_DGRAM, 0)) < 0) {
      perror("udp_client_setup, socket");
      exit(-1);
   }
   connection->remote.sin_family = 2;
   hp = gethostbyname(hostname);
   if (hp == ((void *)0)) {
      printf("Host not found: %s\n", hostname);
      return -1;
   }
   memcpy(&(connection->remote.sin_addr), hp->h_addr_list[0], hp->h_length);
   connection->remote.sin_port = htons(port_num);
   return 0;
}

variable_types:
hostname
char *

variable_types: struct connection { int sk_num; 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]; } remote; unsigned int len; } *

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

user_defined_types: struct connection { int sk_num; struct sockaddr_in remote; unsigned int len; }


original_code:
int32_t select_call(int32_t socket_num, int32_t seconds, int32_t microseconds,
        int32_t set_null) {
   fd_set fdvar;
   struct timeval *timeout = ((void *)0);
   if (set_null == NOT_NULL) {
      timeout = (struct timeval *)malloc(sizeof(struct timeval));
      timeout->tv_sec = seconds;
      timeout->tv_usec = microseconds;
   }
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdvar)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&fdvar)->__fds_bits)[((socket_num) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_num) % (8 * (int) sizeof (__fd_mask)))))));
   if(selectMod(socket_num + 1, (fd_set *)&fdvar, (fd_set *)0, (fd_set *)0, timeout) < 0) {
      perror("select");
      exit(-1);
   }
   if(((((&fdvar)->__fds_bits)[((socket_num) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_num) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      return 1;
   }
   else {
      return 0;
   }
}

canonical_original_code:
int select_call(int socket_num, int seconds, int microseconds, int set_null) {
   struct fd_set fdvar;
   struct timeval *timeout = ((void *)0);
   if (set_null == NOT_NULL) {
      timeout = (struct timeval *)malloc(sizeof(struct timeval));
      timeout->tv_sec = seconds;
      timeout->tv_usec = microseconds;
   }
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdvar)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&fdvar)->__fds_bits)[((socket_num) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_num) % (8 * (int) sizeof (__fd_mask)))))));
   if(selectMod(socket_num + 1, (struct fd_set *)&fdvar, (struct fd_set *)0, (struct fd_set *)0, timeout) < 0) {
      perror("select");
      exit(-1);
   }
   if(((((&fdvar)->__fds_bits)[((socket_num) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_num) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
      return 1;
   }
   else {
      return 0;
   }
}

variable_types: seconds int

variable_types: microseconds int

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

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


decompiled_code:
__int64 __fastcall send_buf(void *src, size_t n, unsigned int *a3, char a4, unsigned int a5, __int64 a6)
{
__int64 result; // rax

if ( (_DWORD)n )
memcpy((void *)(a6 + 7), src, (unsigned int)n);
*(_DWORD *)a6 = _bswap_32(a5);
*(_BYTE *)(a6 + 6) = a4;
*(_WORD *)(a6 + 4) = 0;
*(_WORD *)(a6 + 4) = in_cksum(a6, (unsigned int)(n + 8));
result = sendtoErr(*a3, a6, (unsigned int)(n + 8), 0LL, a3 + 1, a3[5]);
if ( (int)result < 0 )
{
perror("send_buf, sendto");
exit(-1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *src, size_t n, unsigned int *a3, char a4, unsigned int a5, __int64 a6)
{
__int64 result; // rax

if ( (_DWORD)n )
memcpy((void *)(a6 + 7), src, (unsigned int)n);
*(_DWORD *)a6 = func1(a5);
*(_BYTE *)(a6 + 6) = a4;
*(_WORD *)(a6 + 4) = 0;
*(_WORD *)(a6 + 4) = in_cksum(a6, (unsigned int)(n + 8));
result = sendtoErr(*a3, a6, (unsigned int)(n + 8), 0LL, a3 + 1, a3[5]);
if ( (int)result < 0 )
{
perror("send_buf, sendto");
exit(-1);
}
return result;
}

original_code:
int32_t send_buf(uint8_t *buf, uint32_t len, Connection *connection, uint8_t flag,
                 uint32_t seq_num, uint8_t *packet) {
   int32_t send_len = 0;
   uint16_t checksum = 0;
   if (len > 0) {
      memcpy(&packet[7], buf, len);
   }
   seq_num = htonl(seq_num);
   memcpy(&packet[0], &seq_num, 4);
   packet[6] = flag;
   memset(&packet[4], 0, 2);
   checksum = in_cksum((unsigned short *)packet, len + 8);
   memcpy(&packet[4], &checksum, 2);
   if((send_len = sendtoErr(connection->sk_num, packet, len + 8, 0,
                            (struct sockaddr *)&(connection->remote), connection->len)) < 0) {
      perror("send_buf, sendto");
      exit(-1);
   }
   return send_len;
}

canonical_original_code:
int send_buf(unsigned char *buf, unsigned int len, struct connection *connection, unsigned char flag, unsigned int seq_num, unsigned char *packet) {
   int send_len = 0;
   unsigned short checksum = 0;
   if (len > 0) {
      memcpy(&packet[7], buf, len);
   }
   seq_num = htonl(seq_num);
   memcpy(&packet[0], &seq_num, 4);
   packet[6] = flag;
   memset(&packet[4], 0, 2);
   checksum = in_cksum((unsigned short *)packet, len + 8);
   memcpy(&packet[4], &checksum, 2);
   if((send_len = sendtoErr(connection->sk_num, packet, len + 8, 0,
                            (struct sockaddr *)&(connection->remote), connection->len)) < 0) {
      perror("send_buf, sendto");
      exit(-1);
   }
   return send_len;
}

variable_types:
buf
unsigned char *

variable_types:
packet
unsigned char *

variable_types:
checksum
unsigned short


decompiled_code:
__int64 __fastcall recv_buf(void *dest, int a2, unsigned int a3, __int64 a4, _BYTE *a5, _DWORD *a6)
{
int v9; // eax
int v10; // ebx
__int16 v11; // dx
__int64 result; // rax
int v13; // [rsp+Ch] [rbp-60Ch] BYREF
unsigned int v14; // [rsp+10h] [rbp-608h] BYREF
char v15; // [rsp+16h] [rbp-602h]
char src[1537]; // [rsp+17h] [rbp-601h] BYREF

v13 = 16;
v9 = recvfromErr(a3, &v14, a2, 0LL, a4 + 4, &v13);
if ( v9 < 0 )
{
perror("recv_buf, recvfrom");
exit(-1);
}
v10 = v9;
v11 = in_cksum(&v14, (unsigned int)v9);
result = 5LL;
if ( !v11 )
{
*a5 = v15;
*a6 = _bswap_32(v14);
if ( v10 > 7 )
memcpy(dest, src, v10 - 8);
*(_DWORD *)(a4 + 20) = v13;
result = (unsigned int)(v10 - 8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *dest, int a2, unsigned int a3, __int64 a4, _BYTE *a5, _DWORD *a6)
{
int v9; // eax
int v10; // ebx
__int16 v11; // dx
__int64 result; // rax
int v13; // [rsp+Ch] [rbp-60Ch] BYREF
unsigned int v14; // [rsp+10h] [rbp-608h] BYREF
char v15; // [rsp+16h] [rbp-602h]
char src[1537]; // [rsp+17h] [rbp-601h] BYREF

v13 = 16;
v9 = recvfromErr(a3, &v14, a2, 0LL, a4 + 4, &v13);
if ( v9 < 0 )
{
perror("recv_buf, recvfrom");
exit(-1);
}
v10 = v9;
v11 = in_cksum(&v14, (unsigned int)v9);
result = 5LL;
if ( !v11 )
{
*a5 = v15;
*a6 = func1(v14);
if ( v10 > 7 )
memcpy(dest, src, v10 - 8);
*(_DWORD *)(a4 + 20) = v13;
result = (unsigned int)(v10 - 8);
}
return result;
}

original_code:
int32_t recv_buf(uint8_t *buf, int32_t len, int32_t recv_sk_num,
                 Connection *connection, uint8_t *flag, int32_t *seq_num) {
   char data_buf[1500];
   int32_t recv_len = 0;
   uint32_t remote_len = sizeof(struct sockaddr_in);
   if((recv_len = recvfromErr(recv_sk_num, data_buf, len, 0, (struct sockaddr *) &(connection->remote), &remote_len)) < 0) {
      perror("recv_buf, recvfrom");
      exit(-1);
   }
   if(in_cksum((unsigned short*)data_buf, recv_len) != 0) {
      return CRC_ERROR;
   }
   *flag = data_buf[6];
   memcpy(seq_num, data_buf, 4);
   *seq_num = ntohl(*seq_num);
   if (recv_len > 7) {
      memcpy(buf, &data_buf[7], recv_len - 8);
   }
   connection->len = remote_len;
   return (recv_len - 8);
}

canonical_original_code:
int recv_buf(unsigned char *buf, int len, int recv_sk_num, struct connection *connection, unsigned char *flag, int *seq_num) {
   char data_buf[1500];
   int recv_len = 0;
   unsigned int remote_len = sizeof(struct sockaddr_in);
   if((recv_len = recvfromErr(recv_sk_num, data_buf, len, 0, (struct sockaddr *) &(connection->remote), &remote_len)) < 0) {
      perror("recv_buf, recvfrom");
      exit(-1);
   }
   if(in_cksum((unsigned short *)data_buf, recv_len) != 0) {
      return CRC_ERROR;
   }
   *flag = data_buf[6];
   memcpy(seq_num, data_buf, 4);
   *seq_num = ntohl(*seq_num);
   if (recv_len > 7) {
      memcpy(buf, &data_buf[7], recv_len - 8);
   }
   connection->len = remote_len;
   return (recv_len - 8);
}

variable_types: len int

variable_types:
flag
unsigned char *


freemem

repo: mnhrdt/iio

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

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

original_code:
void freemem(void *ptr){
   free(ptr);
}

canonical_original_code:
void freemem(void *ptr){
   free(ptr);
}

variable_types:
ptr
void *


minmax

original_code:
void minmax(float *p, int N, float *vmin, float *vmax) {
   float imin = +(__builtin_inff ());
   float imax = -(__builtin_inff ());
   for ( int i=0;i<N;i++ ) {
      float pp = p[i];
      if ( __builtin_isfinite (pp) ) {
         imin = fmin(imin, pp);
         imax = fmax(imax, pp);
      }
   }
   *vmin = imin;
   *vmax = imax;
}

canonical_original_code:
void minmax(float *p, int N, float *vmin, float *vmax) {
   float imin = +(__builtin_inff ());
   float imax = -(__builtin_inff ());
   for ( int i = 0;i<N;i++ ) {
      float pp = p[i];
      if ( __builtin_isfinite (pp) ) {
         imin = fmin(imin, pp);
         imax = fmax(imax, pp);
      }
   }
   *vmin = imin;
   *vmax = imax;
}

variable_types:
p
float *

variable_types: N int

variable_types:
vmin
float *

variable_types:
vmax
float *

variable_types: imin float

variable_types: imax float

variable_types: i int

variable_types: pp float


original_code:
void copy_tile(float *src, int nc, int nr, int nch, float *dst, int x0, int y0, int w, int h, int dst_nch) {
   for (int j=0;j<h;j++) {
   for (int i=0;i<w;i++) {
   for (int c=0;c<dst_nch;c++) {
      float v=0;
      int ii = x0+i;
      int jj = y0+j;
      if(ii>=0 && jj>=0 && ii < nc && jj < nr && c < nch) {
         v = src[ nch*(ii + jj*nc)+c ];
      }
      dst[ dst_nch*(i + j*w)+c ] = v;
   }
   }
   }
}

canonical_original_code:
void copy_tile(float *src, int nc, int nr, int nch, float *dst, int x0, int y0, int w, int h, int dst_nch) {
   for (int j = 0;j<h;j++) {
   for (int i = 0;i<w;i++) {
   for (int c = 0;c<dst_nch;c++) {
      float v = 0;
      int ii = x0+i;
      int jj = y0+j;
      if(ii>=0 && jj>=0 && ii < nc && jj < nr && c < nch) {
         v = src[ nch*(ii + jj*nc)+c ];
      }
      dst[ dst_nch*(i + j*w)+c ] = v;
   }
   }
   }
}

variable_types:
src
float *

variable_types: nc int

variable_types: nr int

variable_types: nch int

variable_types:
dst
float *

variable_types: w int

variable_types: h int

variable_types: j int

variable_types: c int

variable_types: v float

variable_types: ii int

variable_types: jj int


decompiled_code:
unsigned __int64 __fastcall reverse_vertically_uint8_buffer_inplace(__int64 a1, int a2, int a3, int a4)
{
unsigned __int64 result; // rax
int v7; // er15
int v8; // ebx
int v9; // er14
__int64 v10; // r13
__int64 v11; // rcx
char v12; // si
int v13; // er10
int v14; // er9
int v15; // [rsp+4h] [rbp-3Ch]
int v16; // [rsp+8h] [rbp-38h]

result = (unsigned int)a3;
if ( a3 > 1 )
{
v15 = a4 * a2;
v7 = (a3 - 1) * a4 * a2;
v16 = 2 * a4 * a2;
v8 = -(a4 * a2 * (a3 - 1));
v9 = 0;
result = (unsigned int)(a4 - 1);
v10 = a1 + result + 1;
do
{
v14 = v7;
v13 = 0;
if ( a2 > 0 )
{
do
{
if ( a4 > 0 )
{
result = a1 + v14;
v11 = v14 + v8;
do
{
v12 = *(_BYTE *)result;
*(_BYTE *)result = *(_BYTE *)(result - v14 + v11);
*(_BYTE *)(result - v14 + v11) = v12;
++result;
}
while ( result != v10 + v14 );
}
++v13;
v14 += a4;
}
while ( a2 != v13 );
}
++v9;
v7 -= v15;
v8 += v16;
}
while ( v9 < a3 / 2 );
}
return result;
}

original_code:
void reverse_vertically_uint8_buffer_inplace(uint8_t *buff, int w, int h, int nch) {
   for (int j=0;j<h/2;j++)
   for (int i=0;i<w;i++)
   for (int c=0;c<nch;c++) {
      {uint8_t t = buff[nch*(i + (h-j-1)*w)+c]; buff[nch*(i + (h-j-1)*w)+c] = buff[nch*(i + j*w)+c]; buff[nch*(i + j*w)+c] = t;};
   }
}

canonical_original_code:
void reverse_vertically_uint8_buffer_inplace(unsigned char *buff, int w, int h, int nch) {
   for (int j = 0;j<h/2;j++)
   for (int i = 0;i<w;i++)
   for (int c = 0;c<nch;c++) {
      {unsigned char t = buff[nch*(i + (h-j-1)*w)+c]; buff[nch*(i + (h-j-1)*w)+c] = buff[nch*(i + j*w)+c]; buff[nch*(i + j*w)+c] = t;};
   }
}

variable_types:
buff
unsigned char *

variable_types:
t
unsigned char


repo: mnicolae/parallel-sort

decompiled_code:
__int64 __fastcall get_file_size(char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)stat(a1, &v2) == -1 )
{
perror("stat");
exit(1);
}
return LODWORD(v2.st_size);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func13(a1, &v2) == -1 )
{
perror("stat");
exit(1);
}
return LODWORD(v2.st_size);
}

original_code:
int get_file_size(char *filename) {
    struct stat sbuf;
    if((stat(filename, &sbuf)) == -1) {
       perror("stat");
       exit(1);
    }
    return sbuf.st_size;
}

variable_types:
filename
char *

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

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


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

result = 0LL;
if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
result = 2 * (unsigned int)(*(_DWORD *)a1 > *(_DWORD *)a2) - 1;
return result;
}

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

result = 0LL;
if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
result = 2 * (unsigned int)(*(_DWORD *)a1 > *(_DWORD *)a2) - 1;
return result;
}

original_code:
int compare_freq(const void *rec1, const void *rec2) {
    struct rec *r1 = (struct rec *)rec1;
    struct rec *r2 = (struct rec *)rec2;
    if(r1->freq == r2->freq) {
        return 0;
    } else if (r1->freq > r2->freq) {
        return 1;
    } else {
        return -1;
    }
}

canonical_original_code:
int compare_freq(void *rec1, void *rec2) {
    struct rec *r1 = (struct rec *)rec1;
    struct rec *r2 = (struct rec *)rec2;
    if(r1->freq == r2->freq) {
        return 0;
    } else if (r1->freq > r2->freq) {
        return 1;
    } else {
        return -1;
    }
}

variable_types: struct rec { int freq; char word[44]; } *


decompiled_code:
__int64 __fastcall get_smallest(int *a1, int a2)
{
unsigned int v3; // esi
int v4; // ecx
unsigned int i; // eax
int v6; // edx

if ( a2 <= 0 )
return (unsigned int)-1;
v3 = -1;
v4 = 0x7FFFFFFF;
for ( i = 0; i != a2; ++i )
{
v6 = *a1;
if ( *a1 < v4 )
{
if ( v6 != -1 )
v3 = i;
if ( v6 != -1 )
v4 = *a1;
}
a1 += 12;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, int a2)
{
unsigned int v3; // esi
int v4; // ecx
unsigned int i; // eax
int v6; // edx

if ( a2 <= 0 )
return (unsigned int)-1;
v3 = -1;
v4 = 0x7FFFFFFF;
for ( i = 0; i != a2; ++i )
{
v6 = *a1;
if ( *a1 < v4 )
{
if ( v6 != -1 )
v3 = i;
if ( v6 != -1 )
v4 = *a1;
}
a1 += 12;
}
return v3;
}

original_code:
int get_smallest(struct rec *p, int n) {
    int i;
    int smallest_freq = 0x7fffffff, smallest_index = -1;
    for (i = 0; i < n; i++) {
     if ((p + i)->freq != -1 && (p + i)->freq < smallest_freq) {
  smallest_freq = (p + i)->freq;
  smallest_index = i;
        }
    }
    return smallest_index;
}

canonical_original_code:
int get_smallest(struct rec *p, int n) {
    int i;
    int smallest_freq = 0x7fffffff; int smallest_index = -1;
    for (i = 0; i < n; i++) {
     if ((p + i)->freq != -1 && (p + i)->freq < smallest_freq) {
  smallest_freq = (p + i)->freq;
  smallest_index = i;
        }
    }
    return smallest_index;
}

variable_types: n int

variable_types: i int


Close

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

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

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

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

original_code:
void
Close (int fd) {
    if (close(fd) == -1) {
 perror("close");
 exit(1);
    }
}

canonical_original_code:
void Close(int fd) {
    if (close(fd) == -1) {
 perror("close");
 exit(1);
    }
}

variable_types: fd int


repo: mnicolae/search-index

decompiled_code:
char *__fastcall find_word_node(char *s1, char *s2)
{
int v3; // eax

while ( 1 )
{
v3 = strcmp(s1, s2);
if ( v3 >= 0 )
break;
s1 = (char *)*((_QWORD *)s1 + 20);
if ( !s1 )
return s1;
}
if ( v3 )
s1 = 0LL;
return s1;
}

canonical_decompiled_code:
char *__fastcall func7(char *s1, char *s2)
{
int v3; // eax

while ( 1 )
{
v3 = strcmp(s1, s2);
if ( v3 >= 0 )
break;
s1 = (char *)*((_QWORD *)s1 + 20);
if ( !s1 )
return s1;
}
if ( v3 )
s1 = 0LL;
return s1;
}

original_code:
Node *find_word_node(Node *head, char *word) {
    Node *nextNode = head;
    while (strcmp(nextNode->word, word) < 0 && nextNode->next != ((void *)0)) {
     nextNode = nextNode->next;
    }
    if (strcmp(nextNode->word, word) == 0) {
     return nextNode;
    }
    else {
        return ((void *)0);
    }
}

canonical_original_code:
struct node *find_word_node(struct node *head, char *word) {
    struct node *nextNode = head;
    while (strcmp(nextNode->word, word) < 0 && nextNode->next != ((void *)0)) {
     nextNode = nextNode->next;
    }
    if (strcmp(nextNode->word, word) == 0) {
     return nextNode;
    }
    else {
        return ((void *)0);
    }
}

variable_types:
head
struct node *

variable_types:
word
char *

variable_types: struct node { char word[40]; int freq[30]; struct node *next; } *


decompiled_code:
void __fastcall init_indexes(__int64 a1, int a2)
{
__int64 i; // rax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
*(_DWORD *)(a1 + 4 * i) = i;
}
}

original_code:
void init_indexes(int indexes[], int array_size) {
    int i;
    for (i = 0; i < array_size; i++) {
        indexes[i] = i;
    }
}

variable_types:
indexes
int []


original_code:
void bubble_sort(int numbers[], int indexes[], int array_size) {
    int i, j, temp;
    for (i = (array_size - 1); i > 0; i--) {
        for (j = 1; j <= i; j++) {
            if (numbers[indexes[j-1]] < numbers[indexes[j]]) {
                temp = indexes[j-1];
         indexes[j-1] = indexes[j];
         indexes[j] = temp;
            }
        }
    }
}

canonical_original_code:
void bubble_sort(int numbers[], int indexes[], int array_size) {
    int i; int j; int temp;
    for (i = (array_size - 1); i > 0; i--) {
        for (j = 1; j <= i; j++) {
            if (numbers[indexes[j-1]] < numbers[indexes[j]]) {
                temp = indexes[j-1];
         indexes[j-1] = indexes[j];
         indexes[j] = temp;
            }
        }
    }
}

variable_types:
numbers
int []

variable_types: j int

variable_types: temp int


decompiled_code:
int __fastcall print_query(__int64 a1, __int64 a2)
{
char *v3; // rbx
int result; // eax
__int64 v5; // rsi
int v6[30]; // [rsp+0h] [rbp-A8h] BYREF
char v7; // [rsp+78h] [rbp-30h] BYREF

init_indexes((__int64)v6, 30);
bubble_sort(a1 + 40, v6, 30);
v3 = (char *)v6;
do
{
result = *(_DWORD *)v3;
v5 = *(unsigned int *)(a1 + 4LL * *(int *)v3 + 40);
if ( !(_DWORD)v5 )
break;
result = printf("%d %s\n", v5, *(const char **)(a2 + 8LL * result));
v3 += 4;
}
while ( v3 != &v7 );
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2)
{
char *v3; // rbx
int result; // eax
__int64 v5; // rsi
int v6[30]; // [rsp+0h] [rbp-A8h] BYREF
char v7; // [rsp+78h] [rbp-30h] BYREF

func8((__int64)v6, 30);
func9(a1 + 40, v6, 30);
v3 = (char *)v6;
do
{
result = *(_DWORD *)v3;
v5 = *(unsigned int *)(a1 + 4LL * *(int *)v3 + 40);
if ( !(_DWORD)v5 )
break;
result = printf("%d %s\n", v5, *(const char **)(a2 + 8LL * result));
v3 += 4;
}
while ( v3 != &v7 );
return result;
}

original_code:
void print_query(Node *node, char **filenames) {
    int i;
    int indexes[30];
    init_indexes(indexes, 30);
    bubble_sort(node->freq, indexes, 30);
    for (i = 0; i < 30; i++) {
     if (node->freq[indexes[i]] == 0) {
  break;
        }
 else {
  printf("%d %s\n", node->freq[indexes[i]], filenames[indexes[i]]);
        }
    }
}

canonical_original_code:
void print_query(struct node *node, char **filenames) {
    int i;
    int indexes[30];
    init_indexes(indexes, 30);
    bubble_sort(node->freq, indexes, 30);
    for (i = 0; i < 30; i++) {
     if (node->freq[indexes[i]] == 0) {
  break;
        }
 else {
  printf("%d %s\n", node->freq[indexes[i]], filenames[indexes[i]]);
        }
    }
}

variable_types:
filenames
char **

variable_types:
indexes
int [30]

user_defined_types: struct node { char word[40]; int freq[30]; struct node *next; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // r14
__int64 v4; // r15
char *v5; // r12
char *v6; // r13
char v7; // al
char *v8; // rbp
char *v9; // rdi

v3 = (char **)malloc(8uLL);
v4 = init_filenames();
v5 = "filenames";
v6 = "index";
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "i:n:");
if ( v7 == -1 )
break;
if ( v7 == 105 )
{
v6 = (char *)optarg;
}
else
{
if ( v7 != 110 )
{
fwrite("Usage: indexfile [-i FILE] [-n FILE ] FILE...\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
v5 = (char *)optarg;
}
}
v8 = (char *)argv[_bss_start];
if ( !v8 )
{
fwrite("Usage: indexfile [-u FILE] [-n FILE] FILE...\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
read_list(v5, v6);
v9 = find_word_node(*v3, v8);
if ( v9 )
print_query((__int64)v9, v4);
else
printf("indexfile %s: word not found\n", argv[_bss_start]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // r14
__int64 v4; // r15
char *v5; // r12
char *v6; // r13
char v7; // al
char *v8; // rbp
char *v9; // rdi

v3 = (char **)malloc(8uLL);
v4 = func16();
v5 = "filenames";
v6 = "index";
while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "i:n:");
if ( v7 == -1 )
break;
if ( v7 == 105 )
{
v6 = (char *)optarg;
}
else
{
if ( v7 != 110 )
{
fwrite("Usage: indexfile [-i FILE] [-n FILE ] FILE...\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
v5 = (char *)optarg;
}
}
v8 = (char *)argv[_bss_start];
if ( !v8 )
{
fwrite("Usage: indexfile [-u FILE] [-n FILE] FILE...\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
func15(v5, v6);
v9 = func7(*v3, v8);
if ( v9 )
func10((__int64)v9, v4);
else
printf("indexfile %s: word not found\n", argv[_bss_start]);
return 0;
}

original_code:
int main(int argc, char **argv) {
    Node **head = malloc(sizeof(Node *));
    Node *word_node;
    char **filenames = init_filenames();
    char ch;
    char *indexfile = "index";
    char *namefile = "filenames";
    char *word;
    while((ch = getopt(argc, argv, "i:n:")) != -1) {
     switch (ch) {
            case 'i':
             indexfile = optarg;
             break;
            case 'n':
                namefile = optarg;
                break;
            default:
                fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n");
                exit(1);
        }
    }
    if (argv[optind] == ((void *)0)) {
 fprintf(stderr, "Usage: indexfile [-u FILE] [-n FILE] FILE...\n");
 exit(1);
    }
    word = argv[optind];
    read_list(namefile, indexfile, head, filenames);
    word_node = find_word_node(*head, word);
    if (word_node != ((void *)0)) {
     print_query(word_node, filenames);
    }
    else {
 printf("indexfile %s: word not found\n", argv[optind]);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    struct node **head = malloc(sizeof(Node *));
    struct node *word_node;
    char **filenames = init_filenames();
    char ch;
    char *indexfile = "index";
    char *namefile = "filenames";
    char *word;
    while((ch = getopt(argc, argv, "i:n:")) != -1) {
     switch (ch) {
            case 'i':
             indexfile = optarg;
             break;
            case 'n':
                namefile = optarg;
                break;
            default:
                fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n");
                exit(1);
        }
    }
    if (argv[optind] == ((void *)0)) {
 fprintf(stderr, "Usage: indexfile [-u FILE] [-n FILE] FILE...\n");
 exit(1);
    }
    word = argv[optind];
    read_list(namefile, indexfile, head, filenames);
    word_node = find_word_node(*head, word);
    if (word_node != ((void *)0)) {
     print_query(word_node, filenames);
    }
    else {
 printf("indexfile %s: word not found\n", argv[optind]);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct node { char word[40]; int freq[30]; struct node *next; } **

variable_types: ch char

variable_types:
indexfile
char *

variable_types:
namefile
char *


decompiled_code:
char *__fastcall convert_to_lower(char *s)
{
size_t v1; // rax
char v2; // bl
const unsigned __int16 **v3; // r12
char *v4; // rbp

v1 = strlen(s);
strncpy(word_lower, s, v1);
word_lower[strlen(s)] = 0;
v2 = word_lower[0];
if ( word_lower[0] )
{
v3 = __ctype_b_loc();
v4 = word_lower;
do
{
if ( ((*v3)[v2] & 0x100) != 0 )
*v4 = (*__ctype_tolower_loc())[v2];
v2 = *++v4;
}
while ( *v4 );
}
return word_lower;
}

canonical_decompiled_code:
char *__fastcall func7(char *s)
{
size_t v1; // rax
char v2; // bl
const unsigned __int16 **v3; // r12
char *v4; // rbp

v1 = strlen(s);
strncpy(word_lower, s, v1);
word_lower[strlen(s)] = 0;
v2 = word_lower[0];
if ( word_lower[0] )
{
v3 = __ctype_b_loc();
v4 = word_lower;
do
{
if ( ((*v3)[v2] & 0x100) != 0 )
*v4 = (*__ctype_tolower_loc())[v2];
v2 = *++v4;
}
while ( *v4 );
}
return word_lower;
}

original_code:
char *convert_to_lower(char *word) {
    int i;
    char *p = word_lower;
    strncpy(p, word, strlen(word));
    word_lower[strlen(word)] = '\0';
    for (i = 0; word_lower[i] != '\0'; i++) {
        if (((*__ctype_b_loc ())[(int) ((word_lower[i]))] & (unsigned short int) _ISupper)) {
            word_lower[i] = tolower(word_lower[i]);
        }
    }
    return p;
}

canonical_original_code:
char *convert_to_lower(char *word) {
    int i;
    char *p = word_lower;
    strncpy(p, word, strlen(word));
    word_lower[strlen(word)] = '\0';
    for (i = 0; word_lower[i] != '\0'; i++) {
        if (((*__ctype_b_loc ())[(int) ((word_lower[i]))] & (unsigned short) _ISupper)) {
            word_lower[i] = tolower(word_lower[i]);
        }
    }
    return p;
}

variable_types: i int

variable_types:
p
char *

return_type: char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // r12
char v5; // al
int i; // eax
FILE *v8; // r14
char *j; // rdi
char *v10; // [rsp+0h] [rbp-448h]
char *filename; // [rsp+8h] [rbp-440h]
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

v4 = (char *)create_node((char *)"");
init_filenames("", 0LL);
filename = "filenames";
v10 = "index";
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "i:n:");
if ( v5 == -1 )
break;
if ( v5 == 105 )
{
v10 = (char *)optarg;
}
else
{
if ( v5 != 110 )
{
fwrite("Usage: indexfile [-i FILE] [-n FILE ] FILE...\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
filename = (char *)optarg;
}
}
for ( i = optind; i < argc; optind = i )
{
v8 = fopen(argv[i], "r");
if ( v8 )
{
while ( fgets(s, 1024, v8) )
{
for ( j = strtok(s, delim); j; j = strtok(0LL, delim) )
{
convert_to_lower(j);
add_word(v4);
}
}
fclose(v8);
}
else
{
fprintf(stderr, "Cannot open file %s.\n", argv[optind]);
}
i = optind + 1;
}
write_list(filename, v10, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // r12
char v5; // al
int i; // eax
FILE *v8; // r14
char *j; // rdi
char *v10; // [rsp+0h] [rbp-448h]
char *filename; // [rsp+8h] [rbp-440h]
char s[1080]; // [rsp+10h] [rbp-438h] BYREF

v4 = (char *)func8((char *)"");
func13("", 0LL);
filename = "filenames";
v10 = "index";
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "i:n:");
if ( v5 == -1 )
break;
if ( v5 == 105 )
{
v10 = (char *)optarg;
}
else
{
if ( v5 != 110 )
{
fwrite("Usage: indexfile [-i FILE] [-n FILE ] FILE...\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
filename = (char *)optarg;
}
}
for ( i = optind; i < argc; optind = i )
{
v8 = fopen(argv[i], "r");
if ( v8 )
{
while ( fgets(s, 1024, v8) )
{
for ( j = strtok(s, delim); j; j = strtok(0LL, delim) )
{
func7(j);
func15(v4);
}
}
fclose(v8);
}
else
{
fprintf(stderr, "Cannot open file %s.\n", argv[optind]);
}
i = optind + 1;
}
func11(filename, v10, v4);
return 0;
}


decompiled_code:
char *__fastcall create_node(char *src, int a2, int a3)
{
char *v4; // rax
char *v5; // rbx

v4 = (char *)malloc(0xA8uLL);
if ( !v4 )
{
perror("create_node:");
exit(1);
}
v5 = v4;
strncpy(v4, src, 0x27uLL);
v5[39] = 0;
memset(v5 + 40, 0, 0x78uLL);
*(_DWORD *)&v5[4 * a3 + 40] = a2;
*((_QWORD *)v5 + 20) = 0LL;
return v5;
}

canonical_decompiled_code:
char *__fastcall func8(char *src, int a2, int a3)
{
char *v4; // rax
char *v5; // rbx

v4 = (char *)malloc(0xA8uLL);
if ( !v4 )
{
perror("create_node:");
exit(1);
}
v5 = v4;
strncpy(v4, src, 0x27uLL);
v5[39] = 0;
memset(v5 + 40, 0, 0x78uLL);
*(_DWORD *)&v5[4 * a3 + 40] = a2;
*((_QWORD *)v5 + 20) = 0LL;
return v5;
}

original_code:
Node *create_node(char *word, int count, int filenum) {
    Node *newnode;
    if((newnode= (Node *)malloc(sizeof(Node))) == ((void *)0)) {
 perror("create_node:");
 exit(1);
    }
    strncpy(newnode->word, word, 40);
    newnode->word[40 -1] = '\0';
    memset(newnode->freq, 0, 30 * sizeof(int));
    newnode->freq[filenum] = count;
    newnode->next = ((void *)0);
    return newnode;
}

canonical_original_code:
struct node *create_node(char *word, int count, int filenum) {
    struct node *newnode;
    if((newnode= (struct node *)malloc(sizeof(Node))) == ((void *)0)) {
 perror("create_node:");
 exit(1);
    }
    strncpy(newnode->word, word, 40);
    newnode->word[40 -1] = '\0';
    memset(newnode->freq, 0, 30 * sizeof(int));
    newnode->freq[filenum] = count;
    newnode->next = ((void *)0);
    return newnode;
}

variable_types: count int

variable_types: filenum int

return_type: struct node { char word[40]; int freq[30]; struct node *next; } *


decompiled_code:
char *__fastcall get_node(char *s1, char *src)
{
char *v2; // rbp
char *v3; // rbx

v2 = s1;
if ( !s1 )
return create_node(src, 0, 0);
while ( strcmp(v2, src) < 0 )
{
v3 = (char *)*((_QWORD *)v2 + 20);
if ( !v3 || strcmp(*((const char **)v2 + 20), src) > 0 )
break;
v2 = v3;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func9(char *s1, char *src)
{
char *v2; // rbp
char *v3; // rbx

v2 = s1;
if ( !s1 )
return func8(src, 0, 0);
while ( strcmp(v2, src) < 0 )
{
v3 = (char *)*((_QWORD *)v2 + 20);
if ( !v3 || strcmp(*((const char **)v2 + 20), src) > 0 )
break;
v2 = v3;
}
return v2;
}

original_code:
Node *get_node(Node *head, char *word) {
    Node *nextNode = head;
    if (nextNode == ((void *)0)) {
 nextNode = create_node(word, 0, 0);
 return nextNode;
    }
    while (strcmp(nextNode->word, word) < 0 && nextNode->next != ((void *)0)) {
 if (strcmp(nextNode->next->word, word) > 0) {
   break;
        }
     nextNode = nextNode->next;
    }
    return nextNode;
}

canonical_original_code:
struct node *get_node(struct node *head, char *word) {
    struct node *nextNode = head;
    if (nextNode == ((void *)0)) {
 nextNode = create_node(word, 0, 0);
 return nextNode;
    }
    while (strcmp(nextNode->word, word) < 0 && nextNode->next != ((void *)0)) {
 if (strcmp(nextNode->next->word, word) > 0) {
   break;
        }
     nextNode = nextNode->next;
    }
    return nextNode;
}

variable_types:
head
struct node *

variable_types:
word
char *

variable_types: struct node { char word[40]; int freq[30]; struct node *next; } *


decompiled_code:
int __fastcall display_list(__int64 a1, __int64 a2)
{
__int64 i; // rbp
int result; // eax
__int64 v4; // rbx
const char *v5; // rdx

for ( i = a1; i; i = *(_QWORD *)(i + 160) )
{
printf("%s:\n", (const char *)i);
v4 = 0LL;
while ( 1 )
{
v5 = *(const char **)(a2 + 2 * v4);
if ( !v5 )
break;
result = printf(" %d %s ", *(unsigned int *)(i + v4 + 40), v5);
v4 += 4LL;
if ( v4 == 120 )
goto LABEL_4;
}
result = putchar(10);
LABEL_4:
;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2)
{
__int64 i; // rbp
int result; // eax
__int64 v4; // rbx
const char *v5; // rdx

for ( i = a1; i; i = *(_QWORD *)(i + 160) )
{
printf("%s:\n", (const char *)i);
v4 = 0LL;
while ( 1 )
{
v5 = *(const char **)(a2 + 2 * v4);
if ( !v5 )
break;
result = printf(" %d %s ", *(unsigned int *)(i + v4 + 40), v5);
v4 += 4LL;
if ( v4 == 120 )
goto LABEL_4;
}
result = putchar(10);
LABEL_4:
;
}
return result;
}

original_code:
void display_list(Node *head, char **filenames) {
    Node *cur = head;
    int i;
    while(cur != ((void *)0)) {
 printf("%s:\n", cur->word);
 for(i = 0; i < 30; i++) {
     if(filenames[i] != ((void *)0)) {
  printf("    %d %s ", cur->freq[i], filenames[i]);
     }
            else {
  printf("\n");
  break;
     }
 }
 cur = cur->next;
    }
}

canonical_original_code:
void display_list(struct node *head, char **filenames) {
    struct node *cur = head;
    int i;
    while(cur != ((void *)0)) {
 printf("%s:\n", cur->word);
 for(i = 0; i < 30; i++) {
     if(filenames[i] != ((void *)0)) {
  printf("    %d %s ", cur->freq[i], filenames[i]);
     }
            else {
  printf("\n");
  break;
     }
 }
 cur = cur->next;
    }
}


decompiled_code:
_QWORD *init_filenames()
{
_QWORD *v0; // rax
_QWORD *v1; // rcx
_QWORD *v2; // rdx

v0 = malloc(0xF0uLL);
v1 = v0;
v2 = v0 + 30;
do
*v0++ = 0LL;
while ( v0 != v2 );
return v1;
}

canonical_decompiled_code:
_QWORD *func13()
{
_QWORD *v0; // rax
_QWORD *v1; // rcx
_QWORD *v2; // rdx

v0 = malloc(0xF0uLL);
v1 = v0;
v2 = v0 + 30;
do
*v0++ = 0LL;
while ( v0 != v2 );
return v1;
}

original_code:
char **init_filenames() {
    int i;
    char **fnames = (char **)malloc(30 * sizeof(char *));
    for(i = 0; i < 30; i++) {
 fnames[i] = ((void *)0);
    }
    return fnames;
}

variable_types:
fnames
char **

return_type: char **


decompiled_code:
__int64 __fastcall get_filenum(char *s1, const char **a2)
{
unsigned int v3; // ebp

v3 = 0;
while ( *a2 )
{
if ( !strcmp(s1, *a2) )
return v3;
++v3;
++a2;
if ( v3 == 30 )
{
fwrite("Too many files\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
}
*a2 = s1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *s1, const char **a2)
{
unsigned int v3; // ebp

v3 = 0;
while ( *a2 )
{
if ( !strcmp(s1, *a2) )
return v3;
++v3;
++a2;
if ( v3 == 30 )
{
fwrite("Too many files\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
}
*a2 = s1;
return v3;
}

original_code:
int get_filenum(char *fname, char **filenames) {
    int i;
    for(i = 0; i < 30; i++) {
 if(filenames[i] == ((void *)0)) {
     filenames[i] = fname;
     return i;
 }
 if((strcmp(fname, filenames[i])) == 0) {
     return i;
 }
    }
    fprintf(stderr, "Too many files\n");
    exit(1);
}

variable_types:
fname
char *


decompiled_code:
char *__fastcall add_word(char *s1, const char **a2, char *a3, char *a4)
{
int v5; // ebp
char *v6; // rbx
char *v8; // rax

v5 = get_filenum(a4, a2);
v6 = get_node(s1, a3);
if ( !strcmp(v6, a3) )
{
++*(_DWORD *)&v6[4 * v5 + 40];
}
else
{
v8 = create_node(a3, 1, v5);
*((_QWORD *)v8 + 20) = *((_QWORD *)v6 + 20);
*((_QWORD *)v6 + 20) = v8;
v6 = v8;
}
return v6;
}

original_code:
Node *add_word(Node *head, char **filenames, char *word, char *fname) {
    int i = get_filenum(fname, filenames);
    Node *nextNode = get_node(head, word);
    if (strcmp(nextNode->word, word) == 0) {
    nextNode->freq[i] += 1;
 return nextNode;
    }
    else {
    Node *wordNode;
 wordNode = create_node(word, 1, i);
 wordNode->next = nextNode->next;
 nextNode->next = wordNode;
 return wordNode;
    }
}

canonical_original_code:
struct node *add_word(struct node *head, char **filenames, char *word, char *fname) {
    int i = get_filenum(fname, filenames);
    struct node *nextNode = get_node(head, word);
    if (strcmp(nextNode->word, word) == 0) {
    nextNode->freq[i] += 1;
 return nextNode;
    }
    else {
    struct node *wordNode;
 wordNode = create_node(word, 1, i);
 wordNode->next = nextNode->next;
 nextNode->next = wordNode;
 return wordNode;
    }
}

variable_types:
filenames
char **


repo: mniip/vcsaclockd

decompiled_code:
__off_t __fastcall vcsa_seek(int a1, __int16 a2, int a3, int a4)
{
return lseek(a1, 2 * (a3 + a4 * HIBYTE(a2)) + 5LL, 0);
}

canonical_decompiled_code:
__off_t __fastcall func7(int a1, __int16 a2, int a3, int a4)
{
return lseek(a1, 2 * (a3 + a4 * HIBYTE(a2)) + 5LL, 0);
}

original_code:
void vcsa_seek(int vcsa, vcsainfo info, int x, int y)
{
 lseek(vcsa, sizeof(vcsainfo) + (info.xres*y+x) * 2 + 1, 0);
}

canonical_original_code:
void vcsa_seek(int vcsa, struct vcsainfo info, int x, int y)
{
 lseek(vcsa, sizeof(vcsainfo) + (info.xres*y+x) * 2 + 1, 0);
}

variable_types: vcsa int

variable_types:
info
struct vcsainfo { unsigned char yres; }

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall blit_digit(int a1, __int16 a2, int a3, int a4, int a5)
{
__int64 v6; // r15
__int64 i; // rbx
__int64 result; // rax
int v10; // [rsp+Ch] [rbp-3Ch]

v6 = 7LL * a5;
v10 = 0;
do
{
for ( i = 0LL; i != 7; ++i )
{
vcsa_seek(a1, a2, a3, a4 + i);
if ( ((1 << v10) & map_0[i + v6]) != 0 )
write(a1, &unk_402004, 1uLL);
else
write(a1, &unk_402006, 1uLL);
}
result = (unsigned int)++v10;
++a3;
}
while ( v10 != 5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int16 a2, int a3, int a4, int a5)
{
__int64 v6; // r15
__int64 i; // rbx
__int64 result; // rax
int v10; // [rsp+Ch] [rbp-3Ch]

v6 = 7LL * a5;
v10 = 0;
do
{
for ( i = 0LL; i != 7; ++i )
{
func7(a1, a2, a3, a4 + i);
if ( ((1 << v10) & map_0[i + v6]) != 0 )
write(a1, &unk_402004, 1uLL);
else
write(a1, &unk_402006, 1uLL);
}
result = (unsigned int)++v10;
++a3;
}
while ( v10 != 5 );
return result;
}

variable_types: d int

variable_types:
map
char [11][7]

variable_types: j int


decompiled_code:
__int64 __fastcall blit_clock(int a1, __int16 a2, int a3, int a4, int a5)
{
int v7; // er13

v7 = a3 / 10;
blit_digit(a1, a2, HIBYTE(a2) - 33, 0, a3 / 10);
blit_digit(a1, a2, HIBYTE(a2) - 29, 0, a3 - 10 * v7);
blit_digit(a1, a2, HIBYTE(a2) - 25, 0, 10);
blit_digit(a1, a2, HIBYTE(a2) - 21, 0, a4 / 10);
blit_digit(a1, a2, HIBYTE(a2) - 17, 0, a4 % 10);
blit_digit(a1, a2, HIBYTE(a2) - 13, 0, 10);
blit_digit(a1, a2, HIBYTE(a2) - 9, 0, a5 / 10);
return blit_digit(a1, a2, (unsigned int)HIBYTE(a2) - 5, 0, a5 % 10);
}

original_code:
void blit_clock(int vcsa, vcsainfo info, int h, int m, int s)
{
 blit_digit(vcsa, info, info.xres-33, 0, h/10);
 blit_digit(vcsa, info, info.xres-29, 0, h%10);
 blit_digit(vcsa, info, info.xres-25, 0, 10);
 blit_digit(vcsa, info, info.xres-21, 0, m/10);
 blit_digit(vcsa, info, info.xres-17, 0, m%10);
 blit_digit(vcsa, info, info.xres-13, 0, 10);
 blit_digit(vcsa, info, info.xres-9 , 0, s/10);
 blit_digit(vcsa, info, info.xres-5 , 0, s%10);
}

canonical_original_code:
void blit_clock(int vcsa, struct vcsainfo info, int h, int m, int s)
{
 blit_digit(vcsa, info, info.xres-33, 0, h/10);
 blit_digit(vcsa, info, info.xres-29, 0, h%10);
 blit_digit(vcsa, info, info.xres-25, 0, 10);
 blit_digit(vcsa, info, info.xres-21, 0, m/10);
 blit_digit(vcsa, info, info.xres-17, 0, m%10);
 blit_digit(vcsa, info, info.xres-13, 0, 10);
 blit_digit(vcsa, info, info.xres-9 , 0, s/10);
 blit_digit(vcsa, info, info.xres-5 , 0, s%10);
}

variable_types: h int

variable_types: m int

variable_types: s int


decompiled_code:
void *__fastcall thread_vcsa(void *a1)
{
int v1; // eax
int v2; // ebx
__int64 v3; // rbp
int v4; // eax
int v5; // eax
struct tm *v6; // rax
int *v7; // rax
char *v8; // rax
char *v9; // rax
char *v11; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char s[28]; // [rsp+10h] [rbp-38h] BYREF
int buf[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

sprintf(s, "/dev/vcsa%d", (unsigned int)a1);
v1 = open(s, 2);
if ( v1 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("[%d]open %s: %s\n", (unsigned int)a1, s, v8);
}
else
{
v2 = v1;
v3 = 40LL * (int)a1;
while ( 1 )
{
v4 = pthread_mutex_lock((pthread_mutex_t *)(mutexes + v3));
if ( v4 )
{
v9 = strerror(v4);
printf("[%d]pthread_mutex_lock: %s\n", (unsigned int)a1, v9);
return 0LL;
}
v5 = pthread_mutex_unlock((pthread_mutex_t *)(mutexes + v3));
if ( v5 )
break;
lseek(v2, 0LL, 0);
read(v2, buf, 4uLL);
timer = time(0LL);
v6 = localtime(&timer);
blit_clock(v2, buf[0], v6->tm_hour, v6->tm_min, v6->tm_sec);
usleep(0xF4240u);
}
v11 = strerror(v5);
printf("[%d]pthread_mutex_unlock: %s\n", (unsigned int)a1, v11);
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
int v1; // eax
int v2; // ebx
__int64 v3; // rbp
int v4; // eax
int v5; // eax
struct tm *v6; // rax
int *v7; // rax
char *v8; // rax
char *v9; // rax
char *v11; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF
char s[28]; // [rsp+10h] [rbp-38h] BYREF
int buf[7]; // [rsp+2Ch] [rbp-1Ch] BYREF

sprintf(s, "/dev/vcsa%d", (unsigned int)a1);
v1 = open(s, 2);
if ( v1 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf("[%d]open %s: %s\n", (unsigned int)a1, s, v8);
}
else
{
v2 = v1;
v3 = 40LL * (int)a1;
while ( 1 )
{
v4 = pthread_mutex_lock((pthread_mutex_t *)(mutexes + v3));
if ( v4 )
{
v9 = strerror(v4);
printf("[%d]pthread_mutex_lock: %s\n", (unsigned int)a1, v9);
return 0LL;
}
v5 = pthread_mutex_unlock((pthread_mutex_t *)(mutexes + v3));
if ( v5 )
break;
lseek(v2, 0LL, 0);
read(v2, buf, 4uLL);
timer = time(0LL);
v6 = localtime(&timer);
func9(v2, buf[0], v6->tm_hour, v6->tm_min, v6->tm_sec);
usleep(0xF4240u);
}
v11 = strerror(v5);
printf("[%d]pthread_mutex_unlock: %s\n", (unsigned int)a1, v11);
}
return 0LL;
}

original_code:
void* thread_vcsa(void* m)
{
 int s;
 int id = (intptr_t)m;
 vcsainfo info;
 int vcsa;
 char filename[20];
 sprintf(filename, "/dev/vcsa%d", id);
 if(-1 == (vcsa = open(filename, 02)))
 {
  printf("[%d]open %s: %s\n", id, filename, strerror((*__errno_location ())));
  return ((void *)0);
 }
 while(!time_to_die)
 {
  time_t epoch_time;
  struct tm *tstruct;
  if(s = pthread_mutex_lock(mutexes+id))
  {
   printf("[%d]pthread_mutex_lock: %s\n", id, strerror(s));
   return ((void *)0);
  }
  if(s = pthread_mutex_unlock(mutexes+id))
  {
   printf("[%d]pthread_mutex_unlock: %s\n", id, strerror(s));
   return ((void *)0);
  }
  lseek(vcsa, 0, 0);
  read(vcsa, &info, sizeof(info));
  epoch_time = time(((void *)0));
  tstruct = localtime(&epoch_time);
  blit_clock(vcsa, info, tstruct->tm_hour, tstruct->tm_min, tstruct->tm_sec);
  usleep(1000000);
 }
 close(vcsa);
}

canonical_original_code:
void *thread_vcsa(void *m)
{
 int s;
 int id = (intptr_t)m;
 struct vcsainfo info;
 int vcsa;
 char filename[20];
 sprintf(filename, "/dev/vcsa%d", id);
 if(-1 == (vcsa = open(filename, 02)))
 {
  printf("[%d]open %s: %s\n", id, filename, strerror((*__errno_location ())));
  return ((void *)0);
 }
 while(!time_to_die)
 {
  long epoch_time;
  struct tm *tstruct;
  if(s = pthread_mutex_lock(mutexes+id))
  {
   printf("[%d]pthread_mutex_lock: %s\n", id, strerror(s));
   return ((void *)0);
  }
  if(s = pthread_mutex_unlock(mutexes+id))
  {
   printf("[%d]pthread_mutex_unlock: %s\n", id, strerror(s));
   return ((void *)0);
  }
  lseek(vcsa, 0, 0);
  read(vcsa, &info, sizeof(info));
  epoch_time = time(((void *)0));
  tstruct = localtime(&epoch_time);
  blit_clock(vcsa, info, tstruct->tm_hour, tstruct->tm_min, tstruct->tm_sec);
  usleep(1000000);
 }
 close(vcsa);
}

variable_types:
m
void *

variable_types: id int

variable_types:
filename
char [20]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
__int64 v5; // r12
__int64 i; // rbp
int v7; // eax
int v8; // eax
int *v9; // rax
char *v10; // rax
char *v11; // rax
char *v12; // rax
int v13; // eax
__int64 v14; // rsi
int v15; // eax
char *v16; // rax
int v18; // eax
char *v19; // rax
__int16 v20[20]; // [rsp+0h] [rbp-1E8h] BYREF
char v21; // [rsp+28h] [rbp-1C0h]
char v22; // [rsp+29h] [rbp-1BFh]
char v23[7]; // [rsp+189h] [rbp-5Fh]
pthread_t newthread[11]; // [rsp+190h] [rbp-58h] BYREF

v3 = open("/var/run/utmp", 0, envp);
if ( v3 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("open /var/run/utmp: %s\n", v10);
exit(1);
}
v4 = v3;
mutexes = (__int64)calloc(7uLL, 0x28uLL);
v5 = 40LL;
for ( i = 1LL; i != 7; ++i )
{
v7 = pthread_mutex_init((pthread_mutex_t *)(mutexes + v5), 0LL);
if ( v7 )
{
v11 = strerror(v7);
printf("pthread_mutex_init: %s\n", v11);
exit(1);
}
v8 = pthread_create(&newthread[i], 0LL, thread_vcsa, (void *)i);
if ( v8 )
{
v12 = strerror(v8);
printf("pthread_create: %s\n", v12);
exit(1);
}
v23[i] = 0;
v5 += 40LL;
}
while ( 1 )
{
while ( 1 )
{
do
{
while ( 1 )
{
v13 = read(v4, v20, 0x180uLL);
if ( v13 == 384 )
break;
if ( v13 )
puts("Incomplete record in utmp, ignoring");
lseek(v4, 0LL, 0);
usleep(0x186A0u);
}
}
while ( v21 != 99 || (unsigned int)(v22 - 49) > 5 );
v14 = (unsigned int)(v22 - 48);
if ( !v23[(int)v14] )
break;
if ( v20[0] != 7 )
{
v23[(int)v14] = 0;
printf("Logout on %d, unlocking clock\n", v14);
v15 = pthread_mutex_unlock((pthread_mutex_t *)(mutexes + 40LL * (int)v14));
if ( v15 )
{
v16 = strerror(v15);
return printf("pthread_mutex_unlock: %s\n", v16);
}
}
}
if ( v20[0] == 7 )
{
v23[(int)v14] = 1;
printf("Login on %d, locking clock\n", v14);
v18 = pthread_mutex_lock((pthread_mutex_t *)(mutexes + 40LL * (int)v14));
if ( v18 )
break;
}
}
v19 = strerror(v18);
return printf("pthread_mutex_lock: %s\n", v19);
}

original_code:
int main(int argc, char* argv[])
{
 int s,i;
 pthread_t threads[6 +1];
 char states[6 +1];
 int utmp;
 if(-1 == (utmp = open("/var/run/utmp", 00)))
 {
  printf("open /var/run/utmp: %s\n", strerror((*__errno_location ())));
  exit(1);
 }
 mutexes = calloc(6 +1, sizeof(pthread_mutex_t));
 for(i = 1; i < 6 +1; i++)
 {
  if(s = pthread_mutex_init(mutexes+i, ((void *)0)))
  {
   printf("pthread_mutex_init: %s\n", strerror(s));
   exit(1);
  }
  if(s = pthread_create(threads+i, ((void *)0), &thread_vcsa, (void*)(intptr_t)i))
  {
   printf("pthread_create: %s\n", strerror(s));
   exit(1);
  }
  states[i]=0;
 }
 while(!time_to_die)
 {
  struct utmp record;
  while(sizeof(struct utmp) == (s = read(utmp, &record, sizeof(struct utmp))))
  {
   if(record.ut_id[0] == 'c')
   {
    int ttyn=record.ut_id[1]-'0';
    if((ttyn > 0) && (ttyn < 6 +1))
     if(states[ttyn] && (record.ut_type != 7))
     {
      states[ttyn] = 0;
      printf("Logout on %d, unlocking clock\n", ttyn);
      if(s = pthread_mutex_unlock(mutexes+ttyn))
      {
       printf("pthread_mutex_unlock: %s\n", strerror(s));
       return;
      }
     }
     else if(!states[ttyn] && (record.ut_type == 7))
     {
      states[ttyn] = 1;
      printf("Login on %d, locking clock\n", ttyn);
      if(s = pthread_mutex_lock(mutexes+ttyn))
      {
       printf("pthread_mutex_lock: %s\n", strerror(s));
       return;
      }
     }
   }
  }
  if(s)
  {
   printf("Incomplete record in utmp, ignoring\n");
  }
  lseek(utmp, 0, 0);
  usleep(100000);
 }
 for(i = 1; i < 6 +1; i++)
 {
  if(s = pthread_join(threads[i], ((void *)0)))
  {
   printf("pthread_join: %s\n", strerror(s));
   exit(1);
  }
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int s; int i;
 unsigned long threads[-1];
 char states[-1];
 int utmp;
 if(-1 == (utmp = open("/var/run/utmp", 00)))
 {
  printf("open /var/run/utmp: %s\n", strerror((*__errno_location ())));
  exit(1);
 }
 mutexes = calloc(6 +1, sizeof(pthread_mutex_t));
 for(i = 1; i < 6 +1; i++)
 {
  if(s = pthread_mutex_init(mutexes+i, ((void *)0)))
  {
   printf("pthread_mutex_init: %s\n", strerror(s));
   exit(1);
  }
  if(s = pthread_create(threads+i, ((void *)0), &thread_vcsa, (void *)(long)i))
  {
   printf("pthread_create: %s\n", strerror(s));
   exit(1);
  }
  states[i]=0;
 }
 while(!time_to_die)
 {
  struct utmp record;
  while(sizeof(struct utmp) == (s = read(utmp, &record, sizeof(struct utmp))))
  {
   if(record.ut_id[0] == 'c')
   {
    int ttyn = record.ut_id[1]-'0';
    if((ttyn > 0) && (ttyn < 6 +1))
     if(states[ttyn] && (record.ut_type != 7))
     {
      states[ttyn] = 0;
      printf("Logout on %d, unlocking clock\n", ttyn);
      if(s = pthread_mutex_unlock(mutexes+ttyn))
      {
       printf("pthread_mutex_unlock: %s\n", strerror(s));
       return;
      }
     }
     else if(!states[ttyn] && (record.ut_type == 7))
     {
      states[ttyn] = 1;
      printf("Login on %d, locking clock\n", ttyn);
      if(s = pthread_mutex_lock(mutexes+ttyn))
      {
       printf("pthread_mutex_lock: %s\n", strerror(s));
       return;
      }
     }
   }
  }
  if(s)
  {
   printf("Incomplete record in utmp, ignoring\n");
  }
  lseek(utmp, 0, 0);
  usleep(100000);
 }
 for(i = 1; i < 6 +1; i++)
 {
  if(s = pthread_join(threads[i], ((void *)0)))
  {
   printf("pthread_join: %s\n", strerror(s));
   exit(1);
  }
 }
 exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types:
threads
unsigned long [-1]

variable_types:
states
char [-1]

variable_types: utmp int

variable_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status { short e_termination; short e_exit; } ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; }

variable_types: ttyn int

user_defined_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; }


repo: mnothic/mdbuilder

decompiled_code:
char *__fastcall mdb_sql(char *format, char *s)
{
int v2; // er12
size_t v3; // r13
char *v4; // rax
char *v5; // r12

if ( !format || !s )
return 0LL;
v2 = strlen(format);
v3 = (int)(v2 + strlen(s) + 1);
v4 = (char *)malloc(v3);
v5 = v4;
if ( v4 )
snprintf(v4, v3, format, s);
else
perror("mdb_strcat no memory");
return v5;
}

canonical_decompiled_code:
char *__fastcall func2(char *format, char *s)
{
int v2; // er12
size_t v3; // r13
char *v4; // rax
char *v5; // r12

if ( !format || !s )
return 0LL;
v2 = strlen(format);
v3 = (int)(v2 + strlen(s) + 1);
v4 = (char *)malloc(v3);
v5 = v4;
if ( v4 )
snprintf(v4, v3, format, s);
else
perror("mdb_strcat no memory");
return v5;
}

original_code:
char *mdb_sql(char *sql,char *val)
{
    char *buff = ((void *)0);
    int len;
    if (sql != ((void *)0) && val != ((void *)0)) {
        len = strlen(sql)+strlen(val)+sizeof(char);
        buff = (char *)malloc(len);
    } else
        return ((void *)0);
    if ( buff != ((void *)0) )
        snprintf(buff,len,sql,val);
    else
        perror("mdb_strcat no memory");
    if ( buff )
        return buff;
    else
        return ((void *)0);
}

canonical_original_code:
char *mdb_sql(char *sql, char *val)
{
    char *buff = ((void *)0);
    int len;
    if (sql != ((void *)0) && val != ((void *)0)) {
        len = strlen(sql)+strlen(val)+sizeof(char);
        buff = (char *)malloc(len);
    } else
        return ((void *)0);
    if ( buff != ((void *)0) )
        snprintf(buff,len,sql,val);
    else
        perror("mdb_strcat no memory");
    if ( buff )
        return buff;
    else
        return ((void *)0);
}

variable_types:
sql
char *

variable_types:
val
char *

variable_types:
buff
char *

variable_types: len int


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

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

original_code:
void mdb_free(char *p)
{
    if (p != ((void *)0)) {
        free(p);
        p = ((void *)0);
    }
}

variable_types:
p
char *


decompiled_code:
char *__fastcall mdb_alloc_str(char *src)
{
void *v1; // rax
void *v2; // r12
size_t v3; // rbx
char *v4; // rax
char *v5; // r12

v1 = malloc(1uLL);
if ( !src )
return 0LL;
v2 = v1;
v3 = (int)(strlen(src) + 1);
v4 = (char *)realloc(v2, v3);
v5 = v4;
if ( v4 )
strncpy(v4, src, v3);
return v5;
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
void *v1; // rax
void *v2; // r12
size_t v3; // rbx
char *v4; // rax
char *v5; // r12

v1 = malloc(1uLL);
if ( !src )
return 0LL;
v2 = v1;
v3 = (int)(strlen(src) + 1);
v4 = (char *)realloc(v2, v3);
v5 = v4;
if ( v4 )
strncpy(v4, src, v3);
return v5;
}

original_code:
char *mdb_alloc_str(char *str)
{
    int len;
    char *sp = (char *)malloc(sizeof(char));
    if (str == ((void *)0))
        return ((void *)0);
    len = strlen(str)+sizeof(char);
    sp = realloc((char *)sp,len);
    if (sp != ((void *)0))
        strncpy(sp,str,len);
    else {
        free(sp);
        return ((void *)0);
    }
    return (char *)sp;
}

variable_types:
str
char *

variable_types:
sp
char *


rm

decompiled_code:
__int64 __fastcall rm(char *s)
{
void *v1; // rbx
int v2; // er12
size_t v3; // r12
char *v4; // rax
char *v5; // rbx
__int64 result; // rax
char sa[8]; // [rsp+8h] [rbp-20h] BYREF

v1 = malloc(1uLL);
strcpy(sa, "rm -rf ");
v2 = strlen(sa);
v3 = (int)(v2 + strlen(s) + 1);
v4 = (char *)realloc(v1, v3);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
snprintf(v4, v3, "%s%s", sa, s);
system(v5);
free(v5);
result = dir_exist(s);
if ( (_DWORD)result )
{
openlog("mdbuilder", 1, 24);
syslog(1, "Can't delete directory %s", s);
closelog();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s)
{
void *v1; // rbx
int v2; // er12
size_t v3; // r12
char *v4; // rax
char *v5; // rbx
__int64 result; // rax
char sa[8]; // [rsp+8h] [rbp-20h] BYREF

v1 = malloc(1uLL);
strcpy(sa, "rm -rf ");
v2 = strlen(sa);
v3 = (int)(v2 + strlen(s) + 1);
v4 = (char *)realloc(v1, v3);
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
snprintf(v4, v3, "%s%s", sa, s);
system(v5);
free(v5);
result = func5(s);
if ( (_DWORD)result )
{
openlog("mdbuilder", 1, 24);
syslog(1, "Can't delete directory %s", s);
closelog();
result = 1LL;
}
return result;
}

original_code:
int rm(char *path)
{
    char * cmd = (char *)malloc(sizeof(char));
    char rm[] = "rm -rf ";
    int len,r;
    len = strlen(rm)+strlen(path)+sizeof(char);
    cmd = realloc(cmd,len);
    if (cmd == ((void *)0))
        return -1;
    snprintf(cmd,len,"%s%s",rm,path);
    r = system(cmd);
    free(cmd);
    if (dir_exist(path)) {
        openlog("mdbuilder",0x01,(3<<3));
        syslog(1,"Can't delete directory %s",path);
        closelog();
        return 1;
    }
    return 0;
}

canonical_original_code:
int rm(char *path)
{
    char *cmd = (char *)malloc(sizeof(char));
    char rm[] = "rm -rf ";
    int len; int r;
    len = strlen(rm)+strlen(path)+sizeof(char);
    cmd = realloc(cmd,len);
    if (cmd == ((void *)0))
        return -1;
    snprintf(cmd,len,"%s%s",rm,path);
    r = system(cmd);
    free(cmd);
    if (dir_exist(path)) {
        openlog("mdbuilder",0x01,(3<<3));
        syslog(1,"Can't delete directory %s",path);
        closelog();
        return 1;
    }
    return 0;
}

variable_types:
path
char *

variable_types:
cmd
char *

variable_types:
rm
char []

variable_types: r int


build

decompiled_code:
__int64 __fastcall build(char *file, __mode_t a2)
{
char *v3; // rbx
_BOOL4 v4; // er15
__mode_t v5; // er13
_BOOL4 v6; // ebp
int *v8; // r15
char v9; // al
int v10; // eax
__mode_t v11; // edi
struct stat v12; // [rsp+10h] [rbp-C8h] BYREF

v3 = &file[(*file == 47) + 1];
v4 = 1;
v5 = 0;
while ( 1 )
{
v9 = *(v3 - 1);
if ( !v9 )
{
if ( v4 )
goto LABEL_29;
goto LABEL_3;
}
if ( v9 == 47 )
break;
LABEL_12:
++v3;
}
*(v3 - 1) = 0;
v6 = *v3 == 0;
if ( !v4 )
goto LABEL_16;
v4 = *v3 == 0;
LABEL_29:
v5 = umask(0);
v11 = v5;
LOBYTE(v11) = v5 & 0x3F;
umask(v11);
v6 = v4;
LABEL_16:
if ( !v6 )
{
if ( mkdir(file, 0x1FFu) < 0 )
goto LABEL_7;
LABEL_11:
*(v3 - 1) = 47;
v4 = 0;
goto LABEL_12;
}
LABEL_3:
umask(v5);
if ( mkdir(file, a2) >= 0 )
return 1;
v6 = 1;
LABEL_7:
v8 = _errno_location();
if ( (*v8 & 0xFFFFFFFB) != 17 || stat(file, &v12) < 0 )
{
warn("%s", file);
goto LABEL_24;
}
if ( (v12.st_mode & 0xF000) == 0x4000 )
{
if ( v6 )
return 2;
goto LABEL_11;
}
v10 = 20;
if ( v6 )
v10 = 17;
*v8 = v10;
warn("%s", file);
LABEL_24:
if ( v6 )
return 0;
umask(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *file, __mode_t a2)
{
char *v3; // rbx
_BOOL4 v4; // er15
__mode_t v5; // er13
_BOOL4 v6; // ebp
int *v8; // r15
char v9; // al
int v10; // eax
__mode_t v11; // edi
struct stat v12; // [rsp+10h] [rbp-C8h] BYREF

v3 = &file[(*file == 47) + 1];
v4 = 1;
v5 = 0;
while ( 1 )
{
v9 = *(v3 - 1);
if ( !v9 )
{
if ( v4 )
goto LABEL_29;
goto LABEL_3;
}
if ( v9 == 47 )
break;
LABEL_12:
++v3;
}
*(v3 - 1) = 0;
v6 = *v3 == 0;
if ( !v4 )
goto LABEL_16;
v4 = *v3 == 0;
LABEL_29:
v5 = umask(0);
v11 = v5;
LOBYTE(v11) = v5 & 0x3F;
umask(v11);
v6 = v4;
LABEL_16:
if ( !v6 )
{
if ( mkdir(file, 0x1FFu) < 0 )
goto LABEL_7;
LABEL_11:
*(v3 - 1) = 47;
v4 = 0;
goto LABEL_12;
}
LABEL_3:
umask(v5);
if ( mkdir(file, a2) >= 0 )
return 1;
v6 = 1;
LABEL_7:
v8 = _errno_location();
if ( (*v8 & 0xFFFFFFFB) != 17 || stat(file, &v12) < 0 )
{
warn("%s", file);
goto LABEL_24;
}
if ( (v12.st_mode & 0xF000) == 0x4000 )
{
if ( v6 )
return 2;
goto LABEL_11;
}
v10 = 20;
if ( v6 )
v10 = 17;
*v8 = v10;
warn("%s", file);
LABEL_24:
if ( v6 )
return 0;
umask(v5);
return v6;
}

original_code:
int build(char *path, mode_t omode)
{
        struct stat sb;
        mode_t numask, oumask;
        int first, last, retval;
        char *p;
        p = path;
        oumask = 0;
        retval = 1;
        if (p[0] == '/')
                ++p;
        for (first = 1, last = 0; !last ; ++p) {
                if (p[0] == '\0')
                        last = 1;
                else if (p[0] != '/')
                        continue;
                *p = '\0';
                if (!last && p[1] == '\0')
                        last = 1;
                if (first) {
                        oumask = umask(0);
                        numask = oumask & ~(0200 | 0100);
                        (void)umask(numask);
                        first = 0;
                }
                if (last)
                        (void)umask(oumask);
                if (mkdir(path, last ? omode : (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3)) < 0) {
                        if ((*__errno_location ()) == 17 || (*__errno_location ()) == 21) {
                                if (stat(path, &sb) < 0) {
                                        warn("%s", path);
                                        retval = 0;
                                        break;
                                } else if (!((((sb.st_mode)) & 0170000) == (0040000))) {
                                        if (last)
                                                (*__errno_location ()) = 17;
                                        else
                                                (*__errno_location ()) = 20;
                                        warn("%s", path);
                                        retval = 0;
                                        break;
                                }
                                if (last)
                                        retval = 2;
                        } else {
                                warn("%s", path);
                                retval = 0;
                                break;
                        }
                }
                if (!last)
                    *p = '/';
        }
        if (!first && !last)
                (void)umask(oumask);
        return (retval);
}

canonical_original_code:
int build(char *path, unsigned int omode)
{
        struct stat sb;
        unsigned int numask; unsigned int oumask;
        int first; int last; int retval;
        char *p;
        p = path;
        oumask = 0;
        retval = 1;
        if (p[0] == '/')
                ++p;
        for (first = 1, last = 0; !last ; ++p) {
                if (p[0] == '\0')
                        last = 1;
                else if (p[0] != '/')
                        continue;
                *p = '\0';
                if (!last && p[1] == '\0')
                        last = 1;
                if (first) {
                        oumask = umask(0);
                        numask = oumask & ~(0200 | 0100);
                        (void)umask(numask);
                        first = 0;
                }
                if (last)
                        (void)umask(oumask);
                if (mkdir(path, last ? omode : (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3)) < 0) {
                        if ((*__errno_location ()) == 17 || (*__errno_location ()) == 21) {
                                if (stat(path, &sb) < 0) {
                                        warn("%s", path);
                                        retval = 0;
                                        break;
                                } else if (!((((sb.st_mode)) & 0170000) == (0040000))) {
                                        if (last)
                                                (*__errno_location ()) = 17;
                                        else
                                                (*__errno_location ()) = 20;
                                        warn("%s", path);
                                        retval = 0;
                                        break;
                                }
                                if (last)
                                        retval = 2;
                        } else {
                                warn("%s", path);
                                retval = 0;
                                break;
                        }
                }
                if (!last)
                    *p = '/';
        }
        if (!first && !last)
                (void)umask(oumask);
        return (retval);
}

variable_types:
omode
unsigned int

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

variable_types:
numask
unsigned int

variable_types:
oumask
unsigned int

variable_types: first int

variable_types: last int

variable_types: retval int


decompiled_code:
__int64 __fastcall parse_file(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
__int64 result; // rax
__int64 v10; // r12
__int64 v11; // rbp
__int64 v12; // rbx
char *v13; // rax
double v14; // xmm4_8
double v15; // xmm5_8
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rax
__int64 v23; // rax

cfg = cfg_init(&options, 0LL);
result = cfg_parse(cfg, a1);
if ( (_DWORD)result != 1 )
{
v10 = cfg_getstr(cfg, "password");
v11 = cfg_getstr(cfg, "user");
v12 = cfg_getstr(cfg, "database");
v13 = (char *)cfg_getstr(cfg, "hostname");
dsn_h = (__int64)create_dsn(v13, a2, a3, a4, a5, v14, v15, a8, a9, v12, v11, v10);
v16 = cfg_getstr(cfg, "table");
table_h = mdb_alloc_str(v16);
v17 = cfg_getstr(cfg, "rmquery");
rmquery_h = mdb_alloc_str(v17);
v18 = cfg_getstr(cfg, "getquery");
getquery_h = mdb_alloc_str(v18);
v19 = cfg_getstr(cfg, "basehome");
basehome_h = mdb_alloc_str(v19);
v20 = cfg_getstr(cfg, "update_a");
update_a_h = mdb_alloc_str(v20);
v21 = cfg_getstr(cfg, "update_b");
update_b_h = mdb_alloc_str(v21);
v22 = cfg_getstr(cfg, "delsql");
delsql_h = mdb_alloc_str(v22);
v23 = cfg_getstr(cfg, "pidfile");
pidfile_h = mdb_alloc_str(v23);
cfg_free(cfg);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
__int64 result; // rax
__int64 v10; // r12
__int64 v11; // rbp
__int64 v12; // rbx
char *v13; // rax
double v14; // xmm4_8
double v15; // xmm5_8
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
__int64 v20; // rax
__int64 v21; // rax
__int64 v22; // rax
__int64 v23; // rax

cfg = cfg_init(&options, 0LL);
result = cfg_parse(cfg, a1);
if ( (_DWORD)result != 1 )
{
v10 = cfg_getstr(cfg, "password");
v11 = cfg_getstr(cfg, "user");
v12 = cfg_getstr(cfg, "database");
v13 = (char *)cfg_getstr(cfg, "hostname");
dsn_h = (__int64)func0(v13, a2, a3, a4, a5, v14, v15, a8, a9, v12, v11, v10);
v16 = cfg_getstr(cfg, "table");
table_h = mdb_alloc_str(v16);
v17 = cfg_getstr(cfg, "rmquery");
rmquery_h = mdb_alloc_str(v17);
v18 = cfg_getstr(cfg, "getquery");
getquery_h = mdb_alloc_str(v18);
v19 = cfg_getstr(cfg, "basehome");
basehome_h = mdb_alloc_str(v19);
v20 = cfg_getstr(cfg, "update_a");
update_a_h = mdb_alloc_str(v20);
v21 = cfg_getstr(cfg, "update_b");
update_b_h = mdb_alloc_str(v21);
v22 = cfg_getstr(cfg, "delsql");
delsql_h = mdb_alloc_str(v22);
v23 = cfg_getstr(cfg, "pidfile");
pidfile_h = mdb_alloc_str(v23);
cfg_free(cfg);
result = 0LL;
}
return result;
}

original_code:
int parse_file(char *ptrcfg)
{
    cfg = cfg_init(options, 0);
    if (cfg_parse(cfg, ptrcfg) == 1)
        return 1;
    dsn_h = create_dsn(cfg_getstr(cfg,"hostname"),
                      cfg_getstr(cfg,"database"),
                      cfg_getstr(cfg,"user"),
                      cfg_getstr(cfg,"password"));
    table_h = mdb_alloc_str(cfg_getstr(cfg,"table"));
    rmquery_h = mdb_alloc_str(cfg_getstr(cfg,"rmquery"));
    getquery_h = mdb_alloc_str(cfg_getstr(cfg,"getquery"));
    basehome_h = mdb_alloc_str(cfg_getstr(cfg,"basehome"));
    update_a_h = mdb_alloc_str(cfg_getstr(cfg,"update_a"));
    update_b_h = mdb_alloc_str(cfg_getstr(cfg,"update_b"));
    delsql_h = mdb_alloc_str(cfg_getstr(cfg,"delsql"));
    pidfile_h = mdb_alloc_str(cfg_getstr(cfg,"pidfile"));
    cfg_free(cfg);
    return 0;
}

variable_types:
ptrcfg
char *


usage

repo: modiziri/helloworld

decompiled_code:
__int64 __fastcall usage(unsigned int a1)
{
char *v1; // rax

v1 = dcgettext(
0LL,
"Hello world example %s\n"
"Copyright Jiang Xin <jiangxin AT ossxp DOT com>, 2009.\n"
"\n"
"Usage:\n"
" hello\n"
" say hello to the world.\n"
"\n"
" hello -v, --version\n"
" show version.\n"
"\n"
" hello -h, --help\n"
" this help screen.\n"
"\n",
5);
printf(v1, "7fd0f24");
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
char *v1; // rax

v1 = dcgettext(
0LL,
"Hello world example %s\n"
"Copyright Jiang Xin <jiangxin AT ossxp DOT com>, 2009.\n"
"\n"
"Usage:\n"
" hello\n"
" say hello to the world.\n"
"\n"
" hello -v, --version\n"
" show version.\n"
"\n"
" hello -h, --help\n"
" this help screen.\n"
"\n",
5);
printf(v1, "7fd0f24");
return a1;
}

original_code:
int usage(int code)
{
    printf(gettext ("Hello world example %s\n" "Copyright Jiang Xin <jiangxin AT ossxp DOT com>, 2009.\n" "\n" "Usage:\n" "    hello\n" "            say hello to the world.\n\n" "    hello -v, --version\n" "            show version.\n\n" "    hello -h, --help\n" "            this help screen.\n\n"), "7fd0f24");
    return code;
}

variable_types: code int


decompiled_code:
int show_version()
{
char *v0; // rax

v0 = dcgettext(0LL, "hello version %s\n", 5);
return printf(v0, "7fd0f24");
}

canonical_decompiled_code:
int func1()
{
char *v0; // rax

v0 = dcgettext(0LL, "hello version %s\n", 5);
return printf(v0, "7fd0f24");
}

original_code:
void show_version(void)
{
    printf(gettext ("hello version %s\n"), "7fd0f24" );
}

canonical_original_code:
void show_version()
{
    printf(gettext ("hello version %s\n"), "7fd0f24" );
}


main

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

setlocale(6, &locale);
bindtextdomain("helloworld", "locale");
textdomain("helloworld");
v3 = getopt_long(argc, (char *const *)argv, "hv", &longopts_0, 0LL);
switch ( v3 )
{
case -1:
if ( argc - optind <= 0 )
{
v7 = dcgettext(0LL, "Hello world.\n", 5);
printf(v7);
}
else
{
v5 = argv[optind];
v6 = dcgettext(0LL, "Hi, %s.\n", 5);
printf(v6, v5);
}
result = 0;
break;
case 104:
result = usage(0);
break;
case 118:
show_version();
result = 0;
break;
default:
result = usage(1u);
break;
}
return result;
}

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

setlocale(6, &locale);
bindtextdomain("helloworld", "locale");
textdomain("helloworld");
v3 = getopt_long(argc, (char *const *)argv, "hv", &longopts_0, 0LL);
switch ( v3 )
{
case -1:
if ( argc - optind <= 0 )
{
v7 = dcgettext(0LL, "Hello world.\n", 5);
printf(v7);
}
else
{
v5 = argv[optind];
v6 = dcgettext(0LL, "Hi, %s.\n", 5);
printf(v6, v5);
}
result = 0;
break;
case 104:
result = func0(0);
break;
case 118:
func1();
result = 0;
break;
default:
result = func0(1u);
break;
}
return result;
}

original_code:
int
main(int argc, char **argv)
{
    int ch;
    setlocale( 6, "" );
    bindtextdomain("helloworld","locale");
    textdomain("helloworld");
    static struct option longopts[] = {
            { "help", 0, ((void *)0), 'h' },
            { "version", 0, ((void *)0), 'v' },
            { ((void *)0), 0, ((void *)0), 0 }
    };
    while ((ch = getopt_long(argc, argv, "hv", longopts, ((void *)0))) != -1)
            switch (ch) {
            case 'v':
                    show_version();
                    return 0;
            case 'h':
                    return usage(0);
            default:
                    return usage(1);
    }
    argc -= optind;
    argv += optind;
    if (argc > 0) {
        printf (gettext ("Hi, %s.\n"), argv[0]);
    } else {
        printf (gettext ("Hello world.\n"));
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ch int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


repo: mogeb/utils

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

printf("Allocating and touching %d bytes\n", 209715200LL);
v3 = malloc(0xC800000uLL);
memset(v3, 0, 0xC800000uLL);
puts("Enter to continue");
__isoc99_scanf();
return 0;
}

original_code:
int main()
{
 int i;
 char *buf;
 for(i = 0; i < 1; i++) {
  printf("Allocating and touching %d bytes\n", (200 * (1024 * 1024)));
  buf = (char*) malloc((200 * (1024 * 1024)));
  memset(buf, 0, (200 * (1024 * 1024)));
 }
 printf("Enter to continue\n");
 scanf("%s", buf);
 return 0;
}

canonical_original_code:
int main()
{
 int i;
 char *buf;
 for(i = 0; i < 1; i++) {
  printf("Allocating and touching %d bytes\n", (200 * (1024 * 1024)));
  buf = (char *) malloc((200 * (1024 * 1024)));
  memset(buf, 0, (200 * (1024 * 1024)));
 }
 printf("Enter to continue\n");
 scanf("%s", buf);
 return 0;
}

variable_types: i int

variable_types:
buf
char *


repo: mogest/pcp

decompiled_code:
__int64 __fastcall load_config(int a1, __int64 a2)
{
__int64 v2; // rax
char v3; // al
int v4; // eax
__int64 result; // rax
__int64 v6; // rbp
int v7; // eax
const char *v8; // rbx
char *v9; // rax
const char *v10; // rbp
char *v11; // rax
int argc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

argc[0] = a1;
v2 = ssh_new();
config = v2;
if ( a1 > 1 && strcmp(*(const char **)(a2 + 8), "-$") )
ssh_options_getopt(v2, argc, a2);
*((_DWORD *)&config + 3) = 4;
while ( 1 )
{
v3 = getopt(argc[0], (char *const *)a2, "$t:");
if ( v3 == -1 )
break;
if ( v3 == 36 )
{
*((_DWORD *)&config + 2) = 1;
}
else if ( v3 == 116 )
{
v4 = atoi(optarg);
*((_DWORD *)&config + 3) = v4;
if ( (unsigned int)(v4 - 1) > 0xFE )
{
fprintf(stderr, "threads must be between 1 and %d\n", 255LL);
return 0xFFFFFFFFLL;
}
}
}
if ( *((_DWORD *)&config + 2) )
{
if ( argc[0] - 3 == optind )
{
v6 = 8LL * optind;
*(&config + 2) = *(_QWORD *)(a2 + v6);
*(&config + 5) = atol(*(const char **)(a2 + v6 + 8));
*(&config + 6) = atol(*(const char **)(a2 + v6 + 16));
LABEL_14:
printf(
"server_mode=%d, threads=%d, filename=%s\n",
*((unsigned int *)&config + 2),
*((unsigned int *)&config + 3),
(const char *)*(&config + 2));
return 0LL;
}
fwrite("expected three arguments: local filename, offset and length\n", 1uLL, 0x3CuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v7 = optind;
if ( argc[0] - 2 == optind )
{
*(&config + 2) = *(_QWORD *)(a2 + 8LL * optind);
v8 = *(const char **)(a2 + 8LL * v7 + 8);
v9 = strchr(v8, 58);
if ( v9 )
{
*v9 = 0;
*(&config + 4) = (__int64)v8;
if ( v9[1] )
{
*(&config + 3) = (__int64)(v9 + 1);
}
else
{
v10 = (const char *)*(&config + 2);
v11 = strrchr(v10, 47);
if ( v11 )
v10 = v11 + 1;
*(&config + 3) = (__int64)v10;
}
ssh_options_set(config, 0LL, v8);
goto LABEL_14;
}
fwrite("destination must be in the form host:[filename]\n", 1uLL, 0x30uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
fwrite("expected two arguments, local filename and ssh host\n", 1uLL, 0x34uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
__int64 v2; // rax
char v3; // al
int v4; // eax
__int64 result; // rax
__int64 v6; // rbp
int v7; // eax
const char *v8; // rbx
char *v9; // rax
const char *v10; // rbp
char *v11; // rax
int argc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

argc[0] = a1;
v2 = ssh_new();
config = v2;
if ( a1 > 1 && strcmp(*(const char **)(a2 + 8), "-$") )
ssh_options_getopt(v2, argc, a2);
*((_DWORD *)&config + 3) = 4;
while ( 1 )
{
v3 = getopt(argc[0], (char *const *)a2, "$t:");
if ( v3 == -1 )
break;
if ( v3 == 36 )
{
*((_DWORD *)&config + 2) = 1;
}
else if ( v3 == 116 )
{
v4 = atoi(optarg);
*((_DWORD *)&config + 3) = v4;
if ( (unsigned int)(v4 - 1) > 0xFE )
{
fprintf(stderr, "threads must be between 1 and %d\n", 255LL);
return 0xFFFFFFFFLL;
}
}
}
if ( *((_DWORD *)&config + 2) )
{
if ( argc[0] - 3 == optind )
{
v6 = 8LL * optind;
*(&config + 2) = *(_QWORD *)(a2 + v6);
*(&config + 5) = atol(*(const char **)(a2 + v6 + 8));
*(&config + 6) = atol(*(const char **)(a2 + v6 + 16));
LABEL_14:
printf(
"server_mode=%d, threads=%d, filename=%s\n",
*((unsigned int *)&config + 2),
*((unsigned int *)&config + 3),
(const char *)*(&config + 2));
return 0LL;
}
fwrite("expected three arguments: local filename, offset and length\n", 1uLL, 0x3CuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v7 = optind;
if ( argc[0] - 2 == optind )
{
*(&config + 2) = *(_QWORD *)(a2 + 8LL * optind);
v8 = *(const char **)(a2 + 8LL * v7 + 8);
v9 = strchr(v8, 58);
if ( v9 )
{
*v9 = 0;
*(&config + 4) = (__int64)v8;
if ( v9[1] )
{
*(&config + 3) = (__int64)(v9 + 1);
}
else
{
v10 = (const char *)*(&config + 2);
v11 = strrchr(v10, 47);
if ( v11 )
v10 = v11 + 1;
*(&config + 3) = (__int64)v10;
}
ssh_options_set(config, 0LL, v8);
goto LABEL_14;
}
fwrite("destination must be in the form host:[filename]\n", 1uLL, 0x30uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
fwrite("expected two arguments, local filename and ssh host\n", 1uLL, 0x34uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int load_config(int argc, char *argv[]) {
    char c;
    config.ssh_opts = ssh_new();
    if (argc > 1 && strcmp(argv[1], "-$")) {
        ssh_options_getopt(config.ssh_opts, &argc, argv);
    }
    config.threads = 4;
    while ((c = getopt(argc, argv, "$t:")) != -1) {
        switch (c) {
            case '$':
                config.server_mode = 1;
                break;
            case 't':
                config.threads = atoi(optarg);
                if (config.threads < 1 || config.threads > 255) {
                    fprintf(stderr, "threads must be between 1 and %d\n", 255);
                    return -1;
                }
                break;
        }
    }
    if (config.server_mode) {
        if (optind != argc - 3) {
            fprintf(stderr, "expected three arguments: local filename, offset and length\n");
            return -1;
        }
        config.input_filename = argv[optind];
        config.file_offset = atol(argv[optind + 1]);
        config.file_size = atol(argv[optind + 2]);
    }
    else {
        if (optind != argc - 2) {
            fprintf(stderr, "expected two arguments, local filename and ssh host\n");
            return -1;
        }
        config.input_filename = argv[optind];
        char *dest = argv[optind + 1];
        char *colon = strchr(dest, ':');
        if (colon == ((void *)0)) {
            fprintf(stderr, "destination must be in the form host:[filename]\n");
            return -1;
        }
        *colon = 0;
        config.hostname = dest;
        colon++;
        if (*colon) {
            config.output_filename = colon;
        }
        else {
            char *filename_only = strrchr(config.input_filename, '/');
            config.output_filename = filename_only ? filename_only + 1 : config.input_filename;
        }
        ssh_options_set(config.ssh_opts, SSH_OPTIONS_HOST, config.hostname);
    }
    printf("server_mode=%d, threads=%d, filename=%s\n", config.server_mode, config.threads, config.input_filename);
    return 0;
}

variable_types:
argv
char *[]

variable_types: c char

variable_types:
dest
char *

variable_types:
colon
char *


decompiled_code:
__int64 server_mode()
{
unsigned __int64 v0; // rbx
int v1; // eax
int v2; // er14
char *v3; // r13
unsigned __int64 v4; // rbp
size_t v5; // r12
size_t v7; // rdx
ssize_t v8; // rax

v0 = *(&config + 6);
v1 = open((const char *)*(&config + 2), 65, 420LL);
if ( v1 == -1 )
{
perror("open");
LODWORD(v0) = 1;
}
else
{
v2 = v1;
if ( lseek(v1, *(&config + 5), 0) == -1 )
{
perror("lseek");
LODWORD(v0) = 1;
}
else
{
v3 = (char *)malloc(0x100000uLL);
if ( !v3 )
abort();
v4 = 0x100000LL;
v5 = 0LL;
if ( v0 )
{
while ( 1 )
{
do
{
v7 = v4;
if ( v0 <= v4 )
v7 = v0;
v8 = read(0, &v3[v5], v7);
if ( !v8 )
{
fwrite("got EOF before we received all the data\n", 1uLL, 0x28uLL, stderr);
LODWORD(v0) = 1;
goto LABEL_10;
}
if ( v8 == -1 )
{
perror("read");
LODWORD(v0) = 1;
goto LABEL_10;
}
v5 += v8;
v4 -= v8;
v0 -= v8;
}
while ( v0 && v4 > 0xFFFF );
if ( v5 != write(v2, v3, v5) )
{
perror("write");
LODWORD(v0) = 1;
goto LABEL_10;
}
if ( !v0 )
break;
v4 = 0x100000LL;
v5 = 0LL;
}
LODWORD(v0) = 0;
}
LABEL_10:
free(v3);
close(v2);
}
}
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int64 v0; // rbx
int v1; // eax
int v2; // er14
char *v3; // r13
unsigned __int64 v4; // rbp
size_t v5; // r12
size_t v7; // rdx
ssize_t v8; // rax

v0 = *(&config + 6);
v1 = open((const char *)*(&config + 2), 65, 420LL);
if ( v1 == -1 )
{
perror("open");
LODWORD(v0) = 1;
}
else
{
v2 = v1;
if ( lseek(v1, *(&config + 5), 0) == -1 )
{
perror("lseek");
LODWORD(v0) = 1;
}
else
{
v3 = (char *)malloc(0x100000uLL);
if ( !v3 )
abort();
v4 = 0x100000LL;
v5 = 0LL;
if ( v0 )
{
while ( 1 )
{
do
{
v7 = v4;
if ( v0 <= v4 )
v7 = v0;
v8 = read(0, &v3[v5], v7);
if ( !v8 )
{
fwrite("got EOF before we received all the data\n", 1uLL, 0x28uLL, stderr);
LODWORD(v0) = 1;
goto LABEL_10;
}
if ( v8 == -1 )
{
perror("read");
LODWORD(v0) = 1;
goto LABEL_10;
}
v5 += v8;
v4 -= v8;
v0 -= v8;
}
while ( v0 && v4 > 0xFFFF );
if ( v5 != write(v2, v3, v5) )
{
perror("write");
LODWORD(v0) = 1;
goto LABEL_10;
}
if ( !v0 )
break;
v4 = 0x100000LL;
v5 = 0LL;
}
LODWORD(v0) = 0;
}
LABEL_10:
free(v3);
close(v2);
}
}
return (unsigned int)v0;
}

original_code:
int server_mode(void) {
    size_t size = config.file_size;
    int fd = open(config.input_filename, 01|0100, 0644);
    if (fd == -1) {
        perror("open");
        return 1;
    }
    if (lseek(fd, config.file_offset, 0) == -1) {
        perror("lseek");
        return 1;
    }
    char *buffer = (char *)malloc(1048576);
    if (buffer == ((void *)0)) abort();
    size_t read_position = 0, read_size = 1048576;
    ssize_t n;
    int retval = 0;
    while (size > 0) {
        n = read(0, buffer + read_position, size < read_size ? size : read_size);
        if (n == 0) {
            fprintf(stderr, "got EOF before we received all the data\n");
            retval = 1;
            break;
        }
        if (n == -1) {
            perror("read");
            retval = 1;
            break;
        }
        size -= n;
        read_position += n;
        read_size -= n;
        if (size == 0 || read_size < 65536) {
            n = write(fd, buffer, read_position);
            if (n != read_position) {
                perror("write");
                retval = 1;
                break;
            }
            read_position = 0;
            read_size = 1048576;
        }
    }
    free(buffer);
    close(fd);
    return retval;
}

canonical_original_code:
int server_mode() {
    unsigned long size = config.file_size;
    int fd = open(config.input_filename, 01|0100, 0644);
    if (fd == -1) {
        perror("open");
        return 1;
    }
    if (lseek(fd, config.file_offset, 0) == -1) {
        perror("lseek");
        return 1;
    }
    char *buffer = (char *)malloc(1048576);
    if (buffer == ((void *)0)) abort();
    unsigned long read_position = 0; unsigned long read_size = 1048576;
    long n;
    int retval = 0;
    while (size > 0) {
        n = read(0, buffer + read_position, size < read_size ? size : read_size);
        if (n == 0) {
            fprintf(stderr, "got EOF before we received all the data\n");
            retval = 1;
            break;
        }
        if (n == -1) {
            perror("read");
            retval = 1;
            break;
        }
        size -= n;
        read_position += n;
        read_size -= n;
        if (size == 0 || read_size < 65536) {
            n = write(fd, buffer, read_position);
            if (n != read_position) {
                perror("write");
                retval = 1;
                break;
            }
            read_position = 0;
            read_size = 1048576;
        }
    }
    free(buffer);
    close(fd);
    return retval;
}

variable_types:
size
unsigned long

variable_types: fd int

variable_types:
buffer
char *

variable_types: n long


decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

v3 = 1;
if ( (unsigned int)load_config(argc, (__int64)argv) != -1 )
{
if ( *((_DWORD *)&config + 2) )
v3 = server_mode();
else
v3 = client_mode(*(__int64 *)&argc);
ssh_free(config);
}
return v3;
}

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

v3 = 1;
if ( (unsigned int)func0(argc, (__int64)argv) != -1 )
{
if ( *((_DWORD *)&config + 2) )
v3 = func7();
else
v3 = func6(*(__int64 *)&argc);
ssh_free(config);
}
return v3;
}

original_code:
int main(int argc, char *argv[]) {
    ((void) sizeof ((1024 > 255) ? 1 : 0), __extension__ ({ if (1024 > 255) ; else __assert_fail ("MIN_THREADED_COPY_SIZE > MAX_THREADS", "pcp.c", 358, __extension__ __PRETTY_FUNCTION__); }));
    int result;
    result = load_config(argc, argv);
    if (result == -1) return 1;
    result = config.server_mode ? server_mode() : client_mode();
    ssh_free(config.ssh_opts);
    return result;
}

variable_types: result int


createSemaphore

repo: mohic/streams

decompiled_code:
__int64 __fastcall createSemaphore(key_t a1, int a2)
{
unsigned int v2; // ebx

v2 = semget(a1, 1, a2);
semctl(v2, 0, 16, 1LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(key_t a1, int a2)
{
unsigned int v2; // ebx

v2 = semget(a1, 1, a2);
semctl(v2, 0, 16, 1LL);
return v2;
}

original_code:
int createSemaphore(key_t key, int flags)
{
 int semid = semget(key, 1, flags);
 semctl(semid, 0, 16, 1);
 return semid;
}

canonical_original_code:
int createSemaphore(int key, int flags)
{
 int semid = semget(key, 1, flags);
 semctl(semid, 0, 16, 1);
 return semid;
}

variable_types: key int

variable_types: flags int

variable_types: semid int


deleteSemaphore

decompiled_code:
int __fastcall deleteSemaphore(int a1)
{
return semctl(a1, 0, 0, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
return semctl(a1, 0, 0, 0LL);
}

original_code:
int deleteSemaphore(int semid)
{
 return semctl(semid, 0, 0, 0);
}