decompiled_code:
__int64 read_from_kb()
{
int v0; // eax
__int64 result; // rax

v0 = wgetch(stdscr);
if ( v0 != 259 )
{
if ( v0 == 258 && *(_QWORD *)(curr + 16LL) )
{
curr = *(_QWORD *)(curr + 16LL);
while ( 1 )
{
result = filter_i(*curr);
if ( !(_DWORD)result )
break;
curr = *(_QWORD *)(curr + 16LL);
if ( curr == tail )
return 0LL;
}
return result;
}
return (unsigned int)-(v0 == 113);
}
if ( !*(_QWORD *)(curr + 8LL) )
return (unsigned int)-(v0 == 113);
curr = *(_QWORD *)(curr + 8LL);
while ( 1 )
{
result = filter_i(*curr);
if ( !(_DWORD)result )
break;
curr = *(_QWORD *)(curr + 8LL);
if ( curr == head )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
__int64 result; // rax

v0 = wgetch(stdscr);
if ( v0 != 259 )
{
if ( v0 == 258 && *(_QWORD *)(curr + 16LL) )
{
curr = *(_QWORD *)(curr + 16LL);
while ( 1 )
{
result = func5(*curr);
if ( !(_DWORD)result )
break;
curr = *(_QWORD *)(curr + 16LL);
if ( curr == tail )
return 0LL;
}
return result;
}
return (unsigned int)-(v0 == 113);
}
if ( !*(_QWORD *)(curr + 8LL) )
return (unsigned int)-(v0 == 113);
curr = *(_QWORD *)(curr + 8LL);
while ( 1 )
{
result = func5(*curr);
if ( !(_DWORD)result )
break;
curr = *(_QWORD *)(curr + 8LL);
if ( curr == head )
return 0LL;
}
return result;
}

original_code:
int read_from_kb(void){
 int ch = wgetch(stdscr);
 if(ch == 0403 && curr->prev){
  curr = curr->prev;
  while(filter_i(curr->i)){
   curr = curr->prev;
   if(curr == head){
    break;
   }
  }
 }else if(ch == 0402 && curr->next){
  curr = curr->next;
  while(filter_i(curr->i)){
   curr = curr->next;
   if(curr == tail){
    break;
   }
  }
 }else if(ch == 'q'){
  return -1;
 }
 return 0;
}

canonical_original_code:
int read_from_kb(){
 int ch = wgetch(stdscr);
 if(ch == 0403 && curr->prev){
  curr = curr->prev;
  while(filter_i(curr->i)){
   curr = curr->prev;
   if(curr == head){
    break;
   }
  }
 }else if(ch == 0402 && curr->next){
  curr = curr->next;
  while(filter_i(curr->i)){
   curr = curr->next;
   if(curr == tail){
    break;
   }
  }
 }else if(ch == 'q'){
  return -1;
 }
 return 0;
}


repo: alexandernst/monks

decompiled_code:
__int64 __fastcall net_init(_QWORD *a1, _QWORD *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // ebx
_QWORD *v5; // rax
unsigned int *v6; // rax
struct sockaddr addr; // [rsp+4h] [rbp-24h] BYREF

v2 = get_netlink_id();
v3 = socket(16, 2, v2);
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
*(_DWORD *)&addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[6] = 0;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v4, &addr, 0xCu) )
return (unsigned int)-1;
v5 = (_QWORD *)new(1040LL);
*a1 = v5;
*v5 = 0LL;
v5[129] = 0LL;
memset(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 1040) >> 3));
*(_DWORD *)*a1 = 1040;
v6 = (unsigned int *)*a1;
*a2 = *a1;
a2[1] = *v6;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // ebx
_QWORD *v5; // rax
unsigned int *v6; // rax
struct sockaddr addr; // [rsp+4h] [rbp-24h] BYREF

v2 = get_netlink_id();
v3 = socket(16, 2, v2);
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
*(_DWORD *)&addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[6] = 0;
*(_DWORD *)&addr.sa_data[2] = getpid();
if ( bind(v4, &addr, 0xCu) )
return (unsigned int)-1;
v5 = (_QWORD *)new(1040LL);
*a1 = v5;
*v5 = 0LL;
v5[129] = 0LL;
memset(
(void *)((unsigned __int64)(v5 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + 1040) >> 3));
*(_DWORD *)*a1 = 1040;
v6 = (unsigned int *)*a1;
*a2 = *a1;
a2[1] = *v6;
return v4;
}

original_code:
int net_init(struct nlmsghdr **nlh, struct iovec *iov){
 int sock_fd, ret;
 struct sockaddr_nl src_addr;
 sock_fd = socket(16, SOCK_DGRAM, get_netlink_id());
 if(sock_fd < 0){
  return -1;
 }
 memset(&src_addr, 0, sizeof(src_addr));
 src_addr.nl_family = 16;
 src_addr.nl_pid = getpid();
 ret = bind(sock_fd, (struct sockaddr *)&src_addr, sizeof(src_addr));
 if(ret != 0){
  return -1;
 }
 *nlh = (struct nlmsghdr *)new(( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 memset(*nlh, 0, ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 (*nlh)->nlmsg_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 iov->iov_base = (void *)*nlh;
 iov->iov_len = (*nlh)->nlmsg_len;
 return sock_fd;
}

canonical_original_code:
int net_init(struct nlmsghdr **nlh, struct iovec *iov){
 int sock_fd; int ret;
 struct sockaddr_nl src_addr;
 sock_fd = socket(16, SOCK_DGRAM, get_netlink_id());
 if(sock_fd < 0){
  return -1;
 }
 memset(&src_addr, 0, sizeof(src_addr));
 src_addr.nl_family = 16;
 src_addr.nl_pid = getpid();
 ret = bind(sock_fd, (struct sockaddr *)&src_addr, sizeof(src_addr));
 if(ret != 0){
  return -1;
 }
 *nlh = (struct nlmsghdr *)new(( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 memset(*nlh, 0, ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
 (*nlh)->nlmsg_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 iov->iov_base = (void *)*nlh;
 iov->iov_len = (*nlh)->nlmsg_len;
 return sock_fd;
}

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } **

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

variable_types: ret int

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

return_type: int

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


decompiled_code:
__int64 __fastcall read_from_socket(int a1, _DWORD *a2)
{
__int64 v2; // rbx
size_t *v3; // rbp
size_t v4; // rdi
void *v5; // rax
struct msghdr v7; // [rsp+0h] [rbp-68h] BYREF
__int64 v8[5]; // [rsp+40h] [rbp-28h] BYREF

v8[0] = (__int64)a2;
v8[1] = 1040LL;
v7.msg_name = 0LL;
v7.msg_namelen = 0;
v7.msg_iov = (struct iovec *)v8;
v7.msg_iovlen = 1LL;
v7.msg_control = 0LL;
v7.msg_controllen = 0LL;
v7.msg_flags = 0;
v2 = 0LL;
if ( recvmsg(a1, &v7, 64) > 0 )
{
v3 = (size_t *)new(16LL);
if ( v3 )
{
v4 = (unsigned int)(*a2 - 16);
*v3 = v4;
v5 = (void *)new(v4);
v2 = (__int64)v5;
v3[1] = (size_t)v5;
if ( v5 )
{
memcpy(v5, a2 + 4, *v3);
v2 = deserialize_syscall_info(v3);
del(v3[1]);
del(v3);
}
}
else
{
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _DWORD *a2)
{
__int64 v2; // rbx
size_t *v3; // rbp
size_t v4; // rdi
void *v5; // rax
struct msghdr v7; // [rsp+0h] [rbp-68h] BYREF
__int64 v8[5]; // [rsp+40h] [rbp-28h] BYREF

v8[0] = (__int64)a2;
v8[1] = 1040LL;
v7.msg_name = 0LL;
v7.msg_namelen = 0;
v7.msg_iov = (struct iovec *)v8;
v7.msg_iovlen = 1LL;
v7.msg_control = 0LL;
v7.msg_controllen = 0LL;
v7.msg_flags = 0;
v2 = 0LL;
if ( recvmsg(a1, &v7, 64) > 0 )
{
v3 = (size_t *)new(16LL);
if ( v3 )
{
v4 = (unsigned int)(*a2 - 16);
*v3 = v4;
v5 = (void *)new(v4);
v2 = (__int64)v5;
v3[1] = (size_t)v5;
if ( v5 )
{
memcpy(v5, a2 + 4, *v3);
v2 = deserialize_syscall_info(v3);
del(v3[1]);
del(v3);
}
}
else
{
v2 = 0LL;
}
}
return v2;
}

original_code:
syscall_intercept_info *read_from_socket(int sock_fd, struct nlmsghdr *nlh){
 membuffer *x;
 syscall_intercept_info *i;
 struct iovec iov;
 struct msghdr msg;
 iov.iov_base = nlh;
 iov.iov_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 msg.msg_name = ((void *)0);
 msg.msg_namelen = 0;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = ((void *)0);
 msg.msg_controllen = 0;
 msg.msg_flags = 0;
 if (recvmsg(sock_fd, &msg, MSG_DONTWAIT) <= 0)
  return ((void *)0);
 x = new(sizeof(membuffer));
 if(!x){
  return ((void *)0);
 }
 x->len = nlh->nlmsg_len - ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ));
 x->data = new(x->len);
 if(!x->data){
  return ((void *)0);
 }
 memcpy(x->data, ((void*)(((char*)nlh) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))), x->len);
 i = deserialize_syscall_info(x);
 del(x->data);
 del(x);
 if(!i){
  return ((void *)0);
 }
 return i;
}

canonical_original_code:
struct syscall_intercept_info *read_from_socket(int sock_fd, struct nlmsghdr *nlh){
 struct membuffer *x;
 struct syscall_intercept_info *i;
 struct iovec iov;
 struct msghdr msg;
 iov.iov_base = nlh;
 iov.iov_len = ( ((((1024) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) );
 msg.msg_name = ((void *)0);
 msg.msg_namelen = 0;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = ((void *)0);
 msg.msg_controllen = 0;
 msg.msg_flags = 0;
 if (recvmsg(sock_fd, &msg, MSG_DONTWAIT) <= 0)
  return ((void *)0);
 x = new(sizeof(membuffer));
 if(!x){
  return ((void *)0);
 }
 x->len = nlh->nlmsg_len - ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ));
 x->data = new(x->len);
 if(!x->data){
  return ((void *)0);
 }
 memcpy(x->data, ((void *)(((char *)nlh) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))), x->len);
 i = deserialize_syscall_info(x);
 del(x->data);
 del(x);
 if(!i){
  return ((void *)0);
 }
 return i;
}

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types: struct membuffer { unsigned long len; unsigned char *data; } *

variable_types: struct syscall_intercept_info { char *pname; int pid; char *operation; char *path; char *result; char *details; } *

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


original_code:
void *get_chunk(membuffer *buffer){
 size_t size;
 void *chunk;
 membuffer *tmp;
 memcpy(&size, buffer->data, sizeof(size_t));
 chunk = new(size);
 memcpy(chunk, buffer->data + sizeof(size_t), size);
 tmp = new(sizeof(membuffer));
 tmp->len = buffer->len - sizeof(size_t) - size;
 tmp->data = new(tmp->len);
 memcpy(tmp->data, buffer->data + sizeof(size_t) + size, tmp->len);
 del(buffer->data);
 buffer->data = tmp->data;
 buffer->len = tmp->len;
 del(tmp);
 return chunk;
}

canonical_original_code:
void *get_chunk(struct membuffer *buffer){
 unsigned long size;
 void *chunk;
 struct membuffer *tmp;
 memcpy(&size, buffer->data, sizeof(unsigned long));
 chunk = new(size);
 memcpy(chunk, buffer->data + sizeof(unsigned long), size);
 tmp = new(sizeof(membuffer));
 tmp->len = buffer->len - sizeof(unsigned long) - size;
 tmp->data = new(tmp->len);
 memcpy(tmp->data, buffer->data + sizeof(unsigned long) + size, tmp->len);
 del(buffer->data);
 buffer->data = tmp->data;
 buffer->len = tmp->len;
 del(tmp);
 return chunk;
}

variable_types:
size
unsigned long

variable_types:
chunk
void *

return_type: void *

user_defined_types: struct membuffer { unsigned long len; unsigned char *data; }


decompiled_code:
__int64 __fastcall deserialize_syscall_info(__int64 a1)
{
__int64 v1; // rbx
_DWORD *v2; // rax

v1 = new(48LL);
if ( v1 )
{
*(_QWORD *)v1 = get_chunk(a1);
v2 = get_chunk(a1);
*(_DWORD *)(v1 + 8) = *v2;
del(v2);
*(_QWORD *)(v1 + 16) = get_chunk(a1);
*(_QWORD *)(v1 + 24) = get_chunk(a1);
*(_QWORD *)(v1 + 32) = get_chunk(a1);
*(_QWORD *)(v1 + 40) = get_chunk(a1);
}
return v1;
}

original_code:
syscall_intercept_info *deserialize_syscall_info(membuffer *buffer){
 void *tmp;
 syscall_intercept_info *i = new(sizeof(struct syscall_intercept_info));
 if(!i){
  return ((void *)0);
 }
 i->pname = (char *)get_chunk(buffer);
 tmp = get_chunk(buffer);
 i->pid = *(pid_t *)tmp;
 del(tmp);
 i->operation = (char *)get_chunk(buffer);
 i->path = (char *)get_chunk(buffer);
 i->result = (char *)get_chunk(buffer);
 i->details = (char *)get_chunk(buffer);
 return i;
}

canonical_original_code:
struct syscall_intercept_info *deserialize_syscall_info(struct membuffer *buffer){
 void *tmp;
 struct syscall_intercept_info *i = new(sizeof(struct syscall_intercept_info));
 if(!i){
  return ((void *)0);
 }
 i->pname = (char *)get_chunk(buffer);
 tmp = get_chunk(buffer);
 i->pid = *(int *)tmp;
 del(tmp);
 i->operation = (char *)get_chunk(buffer);
 i->path = (char *)get_chunk(buffer);
 i->result = (char *)get_chunk(buffer);
 i->details = (char *)get_chunk(buffer);
 return i;
}

variable_types:
tmp
void *

return_type: struct syscall_intercept_info { char *pname; int pid; char *operation; char *path; char *result; char *details; } *


rstrip

decompiled_code:
void __fastcall rstrip(const char *a1)
{
int v1; // ebx
const unsigned __int16 **v2; // rsi
__int64 i; // rax

if ( a1 )
{
v1 = strlen(a1);
v2 = _ctype_b_loc();
for ( i = v1 - 1; ((*v2)[a1[i]] & 0x2000) != 0 && (int)i >= 0; --i )
a1[i] = 0;
}
}

canonical_decompiled_code:
void __fastcall func1(const char *a1)
{
int v1; // ebx
const unsigned __int16 **v2; // rsi
__int64 i; // rax

if ( a1 )
{
v1 = strlen(a1);
v2 = _ctype_b_loc();
for ( i = v1 - 1; ((*v2)[a1[i]] & 0x2000) != 0 && (int)i >= 0; --i )
a1[i] = 0;
}
}

original_code:
void rstrip(char *string){
 int l;
 if(!string){
  return;
 }
 l = strlen(string) - 1;
 while(((*__ctype_b_loc ())[(int) ((string[l]))] & (unsigned short int) _ISspace) && l >= 0){
  string[l--] = 0;
 }
}

canonical_original_code:
void rstrip(char *string){
 int l;
 if(!string){
  return;
 }
 l = strlen(string) - 1;
 while(((*__ctype_b_loc ())[(int) ((string[l]))] & (unsigned short) _ISspace) && l >= 0){
  string[l--] = 0;
 }
}

variable_types:
string
char *

variable_types: l int

return_type: void


original_code:
char *get_str_info(syscall_intercept_info *i){
 int err;
 int max_len = 2048;
 char *tmp = new(max_len);
 if(!tmp){
  return ((void *)0);
 }
 err = snprintf(tmp,
  max_len,
  "%-15.20s"
  "%10u"
  " %-15.10s"
  "%-50.45s"
  "%-10.10s"
  " %-200.200s\n",
  i->pname,
  i->pid,
  i->operation,
  i->path,
  i->result,
  i->details
 );
 if(err < 0){
  del(tmp);
  return ((void *)0);
 }
 rstrip(tmp);
 return tmp;
}

canonical_original_code:
char *get_str_info(struct syscall_intercept_info *i){
 int err;
 int max_len = 2048;
 char *tmp = new(max_len);
 if(!tmp){
  return ((void *)0);
 }
 err = snprintf(tmp,
  max_len,
  "%-15.20s"
  "%10u"
  " %-15.10s"
  "%-50.45s"
  "%-10.10s"
  " %-200.200s\n",
  i->pname,
  i->pid,
  i->operation,
  i->path,
  i->result,
  i->details
 );
 if(err < 0){
  del(tmp);
  return ((void *)0);
 }
 rstrip(tmp);
 return tmp;
}

variable_types: err int

variable_types:
tmp
char *

return_type: char *

user_defined_types: struct syscall_intercept_info { char *pname; int pid; char *operation; char *path; char *result; char *details; }


lstrip

decompiled_code:
void __fastcall lstrip(const char *a1)
{
int v1; // ebp
const unsigned __int16 **v2; // rsi
char *v3; // rax

if ( a1 )
{
v1 = strlen(a1);
v2 = _ctype_b_loc();
while ( ((*v2)[*a1] & 0x2000) != 0 )
{
v3 = (char *)a1;
if ( v1 > 0 )
{
do
{
*v3 = v3[1];
++v3;
}
while ( v3 != &a1[v1 - 1 + 1] );
}
}
}
}

original_code:
void lstrip(char *string){
 int i, l;
 if(!string){
  return;
 }
 l = strlen(string);
 while(((*__ctype_b_loc ())[(int) ((string[(i = 0)]))] & (unsigned short int) _ISspace)){
  while(i++ < l){
   string[i-1] = string[i];
  }
 }
}

canonical_original_code:
void lstrip(char *string){
 int i; int l;
 if(!string){
  return;
 }
 l = strlen(string);
 while(((*__ctype_b_loc ())[(int) ((string[(i = 0)]))] & (unsigned short) _ISspace)){
  while(i++ < l){
   string[i-1] = string[i];
  }
 }
}

variable_types: i int


repo: alexandream/atest

decompiled_code:
const char *__fastcall read_line(const char **a1)
{
const char *v1; // rbp
char *v2; // rax

v1 = *a1;
v2 = strchr(*a1, 10);
if ( v2 )
{
*v2 = 0;
*a1 = v2 + 1;
}
else
{
*a1 = &v1[strlen(v1)];
}
return v1;
}

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

v1 = *a1;
v2 = strchr(*a1, 10);
if ( v2 )
{
*v2 = 0;
*a1 = v2 + 1;
}
else
{
*a1 = &v1[strlen(v1)];
}
return v1;
}

original_code:
char* read_line(char** buffer) {
    char *result = *buffer;
    char* eol = strchr(*buffer, '\n');
    if (eol) {
        *eol = '\0';
        *buffer = eol+1;
    }
    else {
        size_t len = strlen(*buffer);
        *buffer = *buffer + len;
    }
    return result;
}

canonical_original_code:
char *read_line(char **buffer) {
    char *result = *buffer;
    char *eol = strchr(*buffer, '\n');
    if (eol) {
        *eol = '\0';
        *buffer = eol+1;
    }
    else {
        unsigned long len = strlen(*buffer);
        *buffer = *buffer + len;
    }
    return result;
}

variable_types:
buffer
char **

variable_types:
result
char *

variable_types:
eol
char *

variable_types:
len
unsigned long


decompiled_code:
int __fastcall process_footer(char *a1, _DWORD *a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
int result; // eax

strtok(a1, "\t");
v2 = strtok(0LL, "\t");
a2[2] = atoi(v2);
v3 = strtok(0LL, "\t");
a2[3] = atoi(v3);
v4 = strtok(0LL, "\t");
result = atoi(v4);
a2[4] = result;
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *a1, _DWORD *a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
int result; // eax

strtok(a1, "\t");
v2 = strtok(0LL, "\t");
a2[2] = atoi(v2);
v3 = strtok(0LL, "\t");
a2[3] = atoi(v3);
v4 = strtok(0LL, "\t");
result = atoi(v4);
a2[4] = result;
return result;
}

original_code:
void process_footer(char* line, SuiteSummary* summary) {
    strtok(line, "\t");
    summary->tests = atoi(strtok(((void *)0), "\t"));
    summary->errors = atoi(strtok(((void *)0), "\t"));
    summary->failures = atoi(strtok(((void *)0), "\t"));
}

canonical_original_code:
void process_footer(char *line, struct SuiteSummary *summary) {
    strtok(line, "\t");
    summary->tests = atoi(strtok(((void *)0), "\t"));
    summary->errors = atoi(strtok(((void *)0), "\t"));
    summary->failures = atoi(strtok(((void *)0), "\t"));
}

variable_types:
line
char *

variable_types: struct SuiteSummary { char *name; int tests; int errors; int failures; } *


original_code:
char*
decode_crlf(const char* input) {
 char* result;
 size_t length = strlen(input);
 size_t i;
 size_t j;
 result = malloc(sizeof(char) * (length + 1));
 if (result == ((void *)0)) {
  return ((void *)0);
 }
 for (i = 0, j = 0; i < length; i++, j++) {
  if (input[i] == '\\') {
   char c = input[i+1];
   if (c != '\\' && c != 'n' && c != 'r') {
    free(result);
    (*__errno_location ()) = 33;
    return ((void *)0);
   }
   result[j] = (c == '\\') ? '\\'
             : (c == 'r') ? '\r'
             : '\n';
   i++;
  }
  else {
   result[j] = input[i];
  }
 }
 result[j] = '\0';
 return result;
}

canonical_original_code:
char *decode_crlf(char *input) {
 char *result;
 unsigned long length = strlen(input);
 unsigned long i;
 unsigned long j;
 result = malloc(sizeof(char) * (length + 1));
 if (result == ((void *)0)) {
  return ((void *)0);
 }
 for (i = 0, j = 0; i < length; i++, j++) {
  if (input[i] == '\\') {
   char c = input[i+1];
   if (c != '\\' && c != 'n' && c != 'r') {
    free(result);
    (*__errno_location ()) = 33;
    return ((void *)0);
   }
   result[j] = (c == '\\') ? '\\'
             : (c == 'r') ? '\r'
             : '\n';
   i++;
  }
  else {
   result[j] = input[i];
  }
 }
 result[j] = '\0';
 return result;
}

variable_types:
input
char *

variable_types:
length
unsigned long

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types: c char


decompiled_code:
__int64 __fastcall process_output_file(const char *a1, const char **a2)
{
const char *v2; // rax
const char *v3; // rbx
char *v4; // rax
char *v5; // rax
const char *v7[4]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = (const char *)read_file_to_memory(a1);
if ( !v7[0] )
return 0xFFFFFFFFLL;
v2 = read_line(v7);
process_header((__int64)v2, a2);
while ( *v7[0] && *v7[0] != 35 )
{
v3 = *a2;
v4 = (char *)read_line(v7);
process_result(v4, v3);
}
v5 = (char *)read_line(v7);
process_footer(v5, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char *a1, const char **a2)
{
const char *v2; // rax
const char *v3; // rbx
char *v4; // rax
char *v5; // rax
const char *v7[4]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = (const char *)read_file_to_memory(a1);
if ( !v7[0] )
return 0xFFFFFFFFLL;
v2 = func8(v7);
func9((__int64)v2, a2);
while ( *v7[0] && *v7[0] != 35 )
{
v3 = *a2;
v4 = (char *)func8(v7);
func12(v4, v3);
}
v5 = (char *)func8(v7);
func10(v5, a2);
return 0LL;
}

original_code:
int process_output_file(const char* file_name, SuiteSummary *summary) {
    char* buffer = read_file_to_memory(file_name);
    char* p = buffer;
    if (buffer == ((void *)0)) {
        return -1;
    }
    process_header(read_line(&p), summary);
    while(*p && *p != '#') {
        process_result(read_line(&p), summary->name);
    }
    process_footer(read_line(&p), summary);
    return 0;
}

canonical_original_code:
int process_output_file(char *file_name, struct SuiteSummary *summary) {
    char *buffer = read_file_to_memory(file_name);
    char *p = buffer;
    if (buffer == ((void *)0)) {
        return -1;
    }
    process_header(read_line(&p), summary);
    while(*p && *p != '#') {
        process_result(read_line(&p), summary->name);
    }
    process_footer(read_line(&p), summary);
    return 0;
}

variable_types:
buffer
char *

variable_types:
p
char *

user_defined_types: struct SuiteSummary { char *name; int tests; int errors; int failures; }


main

canonical_name: main

original_code:
int main(int argc, char** argv) {
    SuiteSummary* summary_pool;
    int num_summaries = 0;
    int max_summaries = argc -1;
    int error = 0;
    int i;
    if (argc < 2) {
        fprintf(stderr, "Wrong number of arguments.\n");
        exit(1);
    }
    summary_pool = malloc(sizeof(SuiteSummary)*max_summaries);
    if (summary_pool == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(2);
    }
    for (i = 0; i < max_summaries; i++) {
        SuiteSummary *summary = summary_pool + i;
        const char* file_name = argv[i+1];
        error = process_output_file(file_name, summary);
        if (error) {
            fprintf(stderr, "Got error %d while processing file %s.\n",
                    error, file_name);
            exit(3);
        }
        num_summaries++;
    }
    printf ("%s\n", ("========================================" "========================================"));
    printf("| %-46s| %s | %s | %s | %s |\n",
           "Suite Name", "Tests", "Errors", "Fails", "  %");
    printf("|%s|%s|%s|%s|%s|\n",
           "-----------------------------------------------",
           "-------","--------","-------","-----");
    for (i = 0; i < num_summaries; i++) {
        SuiteSummary *summary = summary_pool +i;
        int percent;
  if (summary->tests > 0) {
   percent = 100 - 100 * (summary->errors + summary->failures)
                                / summary->tests;
  }
  else {
   percent = 0;
  }
        printf("| %-46s|   %3d |    %3d |   %3d | %3d |\n",
               summary->name, summary->tests, summary->errors,
               summary->failures, percent);
    }
    printf(" %s \n",
           "---------------------------------------"
           "---------------------------------------");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    struct SuiteSummary *summary_pool;
    int num_summaries = 0;
    int max_summaries = argc -1;
    int error = 0;
    int i;
    if (argc < 2) {
        fprintf(stderr, "Wrong number of arguments.\n");
        exit(1);
    }
    summary_pool = malloc(sizeof(SuiteSummary)*max_summaries);
    if (summary_pool == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(2);
    }
    for (i = 0; i < max_summaries; i++) {
        struct SuiteSummary *summary = summary_pool + i;
        char *file_name = argv[i+1];
        error = process_output_file(file_name, summary);
        if (error) {
            fprintf(stderr, "Got error %d while processing file %s.\n",
                    error, file_name);
            exit(3);
        }
        num_summaries++;
    }
    printf ("%s\n", ("========================================" "========================================"));
    printf("| %-46s| %s | %s | %s | %s |\n",
           "Suite Name", "Tests", "Errors", "Fails", "  %");
    printf("|%s|%s|%s|%s|%s|\n",
           "-----------------------------------------------",
           "-------","--------","-------","-----");
    for (i = 0; i < num_summaries; i++) {
        struct SuiteSummary *summary = summary_pool +i;
        int percent;
  if (summary->tests > 0) {
   percent = 100 - 100 * (summary->errors + summary->failures)
                                / summary->tests;
  }
  else {
   percent = 0;
  }
        printf("| %-46s|   %3d |    %3d |   %3d | %3d |\n",
               summary->name, summary->tests, summary->errors,
               summary->failures, percent);
    }
    printf(" %s \n",
           "---------------------------------------"
           "---------------------------------------");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: error int

variable_types: percent int


original_code:
void process_result(char* line, const char* suite) {
    char extra_info[81];
    char dash_line[81];
    const char* type = strtok(line, "\t");
    const char* name = strtok(((void *)0), "\t");
    const char* file = strtok(((void *)0), "\t");
    char* line_num = strtok(((void *)0), "\t");
    char* check = strtok(((void *)0), "\t");
    char* n_checks = strtok(((void *)0), "\t");
    char* msg = decode_crlf(strtok(((void *)0), "\t"));
    int extra_info_len = strlen(file) + strlen(line_num) + strlen(check) +
                         strlen(n_checks) + 7;
    if (msg == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(19);
    }
    printf("%s\n", ("========================================" "========================================"));
    printf("%-5s: %s.%s\n",
           *type == 'E' ? "ERROR" : "FAIL",
           suite, name);
    strcpy(dash_line, ("----------------------------------------" "----------------------------------------"));
    sprintf(extra_info, " %s, %s, %s/%s ",
            file, line_num, check, n_checks);
    memcpy(dash_line+(80 - extra_info_len ), extra_info, extra_info_len);
    printf("%s\n\n", dash_line);
    printf("%s\n\n", msg);
    free(msg);
}

canonical_original_code:
void process_result(char *line, char *suite) {
    char extra_info[81];
    char dash_line[81];
    char *type = strtok(line, "\t");
    char *name = strtok(((void *)0), "\t");
    char *file = strtok(((void *)0), "\t");
    char *line_num = strtok(((void *)0), "\t");
    char *check = strtok(((void *)0), "\t");
    char *n_checks = strtok(((void *)0), "\t");
    char *msg = decode_crlf(strtok(((void *)0), "\t"));
    int extra_info_len = strlen(file) + strlen(line_num) + strlen(check) +
                         strlen(n_checks) + 7;
    if (msg == ((void *)0)) {
        fprintf(stderr, "Allocation error.\n");
        exit(19);
    }
    printf("%s\n", ("========================================" "========================================"));
    printf("%-5s: %s.%s\n",
           *type == 'E' ? "ERROR" : "FAIL",
           suite, name);
    strcpy(dash_line, ("----------------------------------------" "----------------------------------------"));
    sprintf(extra_info, " %s, %s, %s/%s ",
            file, line_num, check, n_checks);
    memcpy(dash_line+(80 - extra_info_len ), extra_info, extra_info_len);
    printf("%s\n\n", dash_line);
    printf("%s\n\n", msg);
    free(msg);
}

variable_types:
suite
char *

variable_types:
type
char *

variable_types:
name
char *

variable_types:
file
char *

variable_types:
check
char *

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall at_eq_long(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi

if ( a3 == a4 )
{
at_make_success();
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %ld but found to have value %ld.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi

if ( a3 == a4 )
{
at_make_success();
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %ld but found to have value %ld.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

original_code:
AtCheckResult at_eq_long(const char* expr, long value, long expected) {
 do { if (! ((value == expected)) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "%ld" " but found to have value " "%ld" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_long(char *expr, long value, long expected) {
 do { if (! ((value == expected)) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "%ld" " but found to have value " "%ld" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
expr
char *

variable_types: value long

variable_types: expected long

return_type: struct AtCheckResult { int status; int check_number; char *message; char *file_name; int line_number; void (*clean_up)(char *); }


decompiled_code:
__int64 __fastcall at_eq_ulong(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi

if ( a3 == a4 )
{
at_make_success();
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %lu but found to have value %lu.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rsi

if ( a3 == a4 )
{
at_make_success();
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %lu but found to have value %lu.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

original_code:
AtCheckResult at_eq_ulong(const char* expr, unsigned long value,
                          unsigned long expected) {
 do { if (! ((value == expected)) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "%lu" " but found to have value " "%lu" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_ulong(char *expr, unsigned long value, unsigned long expected) {
 do { if (! ((value == expected)) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "%lu" " but found to have value " "%lu" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
value
unsigned long

variable_types:
expected
unsigned long

user_defined_types: struct AtCheckResult { int status; int check_number; char *message; char *file_name; int line_number; void (*clean_up)(char *); }


decompiled_code:
__int64 __fastcall at_eq_ptr(__int64 a1, const char *a2, const void *a3, const void *a4)
{
__int64 v4; // rsi

if ( a3 == a4 )
{
at_make_success();
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %p but found to have value %p.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, const void *a3, const void *a4)
{
__int64 v4; // rsi

if ( a3 == a4 )
{
at_make_success();
}
else
{
v4 = at_allocf("Expression (%s) expected to have value %p but found to have value %p.", a2, a4, a3);
if ( v4 )
at_make_failure(a1, v4, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

original_code:
AtCheckResult at_eq_ptr(const char* expr, const void* value,
                        const void* expected ) {
 do { if (! ((value == expected)) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "%p" " but found to have value " "%p" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_ptr(char *expr, void *value, void *expected) {
 do { if (! ((value == expected)) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "%p" " but found to have value " "%p" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
value
void *

variable_types:
expected
void *


decompiled_code:
__int64 __fastcall at_eq_str(__int64 a1, const char *a2, const char *a3, const char *a4)
{
__int64 v6; // rsi

if ( !strcmp(a3, a4) )
{
at_make_success(a1);
}
else
{
v6 = at_allocf(
"Expression (%s) expected to have value \n \"%s\"\n but found to have value \n \"%s\"\n.",
a2,
a4,
a3);
if ( v6 )
at_make_failure(a1, v6, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, const char *a3, const char *a4)
{
__int64 v6; // rsi

if ( !strcmp(a3, a4) )
{
at_make_success(a1);
}
else
{
v6 = at_allocf(
"Expression (%s) expected to have value \n \"%s\"\n but found to have value \n \"%s\"\n.",
a2,
a4,
a3);
if ( v6 )
at_make_failure(a1, v6, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

original_code:
AtCheckResult at_eq_str(const char* expr, const char* value,
                        const char* expected) {
 do { if (! ((!strcmp(value, expected))) ) { const char* _at_msg = at_allocf("Expression (%s) expected to have value " "\n    \"%s\"\n" " but found to have value " "\n    \"%s\"\n" ".", expr, expected, value); if (_at_msg == ((void *)0)) { const char* _at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

canonical_original_code:
struct AtCheckResult at_eq_str(char *expr, char *value, char *expected) {
 do { if (! ((!strcmp(value, expected))) ) { char *_at_msg = at_allocf("Expression (%s) expected to have value " "\n    \"%s\"\n" " but found to have value " "\n    \"%s\"\n" ".", expr, expected, value); if (_at_msg == ((void *)0)) { char *_at_error_msg = "Allocation error during failed check"; return at_make_error(_at_error_msg, ((void *)0)); } return at_make_failure(_at_msg, at_freef); } return at_make_success(); } while (0);
}

variable_types:
value
char *

variable_types:
expected
char *


decompiled_code:
__int64 __fastcall at_is_true(__int64 a1, const char *a2, int a3)
{
__int64 v3; // rsi

if ( a3 )
{
at_make_success(a1);
}
else
{
v3 = at_allocf("Expression (%s) expected to be true, but found to be false.", a2);
if ( v3 )
at_make_failure(a1, v3, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, int a3)
{
__int64 v3; // rsi

if ( a3 )
{
at_make_success(a1);
}
else
{
v3 = at_allocf("Expression (%s) expected to be true, but found to be false.", a2);
if ( v3 )
at_make_failure(a1, v3, &at_freef);
else
at_make_error(a1, "Allocation error during failed check", 0LL);
}
return a1;
}

original_code:
AtCheckResult at_is_true(const char* expr, int value) {
 if (! value ) {
  const char* _at_msg =
   at_allocf("Expression (%s) expected to be true, but found "
          "to be false.",
       expr);
  if (_at_msg == ((void *)0)) {
   const char* _at_error_msg =
    "Allocation error during failed check";
   return
    at_make_error(_at_error_msg, ((void *)0));
  }
  return at_make_failure(_at_msg, at_freef);
 }
 return at_make_success();
}

canonical_original_code:
struct AtCheckResult at_is_true(char *expr, int value) {
 if (! value ) {
  char *_at_msg = at_allocf("Expression (%s) expected to be true, but found "
          "to be false.",
       expr);
  if (_at_msg == ((void *)0)) {
   char *_at_error_msg = "Allocation error during failed check";
   return
    at_make_error(_at_error_msg, ((void *)0));
  }
  return at_make_failure(_at_msg, at_freef);
 }
 return at_make_success();
}

variable_types: value int


decompiled_code:
__int64 __fastcall compute_format_length(char *a1, void *a2)
{
unsigned int v2; // ebx
int v3; // eax
char *v5; // [rsp+8h] [rbp-20h] BYREF

if ( !*a1 )
return 0;
v2 = 0;
while ( 1 )
{
v5 = 0LL;
v3 = get_part_length(a1, a2, &v5);
if ( v3 < 0 )
break;
v2 += v3;
a1 = v5;
if ( !*v5 )
return v2;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, void *a2)
{
unsigned int v2; // ebx
int v3; // eax
char *v5; // [rsp+8h] [rbp-20h] BYREF

if ( !*a1 )
return 0;
v2 = 0;
while ( 1 )
{
v5 = 0LL;
v3 = func0(a1, a2, &v5);
if ( v3 < 0 )
break;
v2 += v3;
a1 = v5;
if ( !*v5 )
return v2;
}
return (unsigned int)-1;
}

original_code:
static
int compute_format_length(const char* format, va_list ap) {
 int result = 0;
 const char* part = format;
 while(*part) {
  const char* next_part = ((void *)0);
  int part_len;
  part_len = get_part_length(part, ap, &next_part);
  if (part_len < 0) {
   return -1;
  }
  result += part_len;
  part = next_part;
 }
 return result;
}

canonical_original_code:
static int compute_format_length(char *format, __builtin_va_list ap) {
 int result = 0;
 char *part = format;
 while(*part) {
  char *next_part = ((void *)0);
  int part_len;
  part_len = get_part_length(part, ap, &next_part);
  if (part_len < 0) {
   return -1;
  }
  result += part_len;
  part = next_part;
 }
 return result;
}

variable_types:
format
char *

variable_types: result int

variable_types:
part
char *


decompiled_code:
int __fastcall do_vasprintf(char **a1, char *a2, void *a3, void *a4)
{
int result; // eax
char *v6; // rax
char *v7; // r13

result = compute_format_length(a2, a3);
if ( result >= 0 )
{
v6 = (char *)malloc(result + 1);
v7 = v6;
if ( v6 )
{
result = vsprintf(v6, a2, a4);
if ( result < 0 )
{
free(v7);
result = -12;
}
else
{
*a1 = v7;
}
}
else
{
result = -11;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char **a1, char *a2, void *a3, void *a4)
{
int result; // eax
char *v6; // rax
char *v7; // r13

result = func1(a2, a3);
if ( result >= 0 )
{
v6 = (char *)malloc(result + 1);
v7 = v6;
if ( v6 )
{
result = vsprintf(v6, a2, a4);
if ( result < 0 )
{
free(v7);
result = -12;
}
else
{
*a1 = v7;
}
}
else
{
result = -11;
}
}
return result;
}

original_code:
static
int do_vasprintf(char** dest, const char* fmt, va_list ap1, va_list ap2) {
 int length;
 char* buf;
 int expected_length;
 expected_length = compute_format_length(fmt, ap1);
 if (expected_length < 0) {
  return expected_length;
 }
 buf = malloc(sizeof(char) * (expected_length + 1));
 if (buf == ((void *)0)) {
  return -11;
 }
 length = vsprintf(buf, fmt, ap2);
 if (length < 0) {
  free(buf);
  return -12;
 }
 *dest = buf;
 return length;
}

canonical_original_code:
static int do_vasprintf(char **dest, char *fmt, __builtin_va_list ap1, __builtin_va_list ap2) {
 int length;
 char *buf;
 int expected_length;
 expected_length = compute_format_length(fmt, ap1);
 if (expected_length < 0) {
  return expected_length;
 }
 buf = malloc(sizeof(char) * (expected_length + 1));
 if (buf == ((void *)0)) {
  return -11;
 }
 length = vsprintf(buf, fmt, ap2);
 if (length < 0) {
  free(buf);
  return -12;
 }
 *dest = buf;
 return length;
}

variable_types:
dest
char **

variable_types:
fmt
char *

variable_types: length int

variable_types:
buf
char *


decompiled_code:
int at_asprintf(char **a1, char *a2, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list va1; // [rsp+18h] [rbp-D0h] BYREF

va_start(va, a2);
va_start(va1, a2);
return do_vasprintf(a1, a2, va1, va);
}

canonical_decompiled_code:
int func3(char **a1, char *a2, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list va1; // [rsp+18h] [rbp-D0h] BYREF

va_start(va, a2);
va_start(va1, a2);
return func2(a1, a2, va1, va);
}

original_code:
int at_asprintf(char** dest, const char* fmt, ...) {
 int length;
 va_list ap1;
 va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(dest, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return length;
}

canonical_original_code:
int at_asprintf(char **dest, char *fmt, ...) {
 int length;
 __builtin_va_list ap1;
 __builtin_va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(dest, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return length;
}


decompiled_code:
char *at_allocf(char *a1, ...)
{
bool v1; // sf
char *result; // rax
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF
gcc_va_list va1; // [rsp+20h] [rbp-D8h] BYREF
char *v5; // [rsp+38h] [rbp-C0h] BYREF

va_start(va, a1);
va_start(va1, a1);
v5 = 0LL;
v1 = do_vasprintf(&v5, a1, va1, va) < 0;
result = 0LL;
if ( !v1 )
result = v5;
return result;
}

canonical_decompiled_code:
char *func4(char *a1, ...)
{
bool v1; // sf
char *result; // rax
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF
gcc_va_list va1; // [rsp+20h] [rbp-D8h] BYREF
char *v5; // [rsp+38h] [rbp-C0h] BYREF

va_start(va, a1);
va_start(va1, a1);
v5 = 0LL;
v1 = func2(&v5, a1, va1, va) < 0;
result = 0LL;
if ( !v1 )
result = v5;
return result;
}

original_code:
char* at_allocf(const char* fmt, ...) {
 char* result = ((void *)0);
 int length;
 va_list ap1;
 va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(&result, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return (length >= 0) ? result : ((void *)0);
}

canonical_original_code:
char *at_allocf(char *fmt, ...) {
 char *result = ((void *)0);
 int length;
 __builtin_va_list ap1;
 __builtin_va_list ap2;
 __builtin_va_start(ap1,fmt);
 __builtin_va_start(ap2,fmt);
 length = do_vasprintf(&result, fmt, ap1, ap2);
 __builtin_va_end(ap2);
 __builtin_va_end(ap1);
 return (length >= 0) ? result : ((void *)0);
}

variable_types:
result
char *


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

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

original_code:
void at_freef(const char* msg) {
 free((void*) msg);
}

canonical_original_code:
void at_freef(char *msg) {
 free((void *) msg);
}

variable_types:
msg
char *


repo: alexisduque/prs

decompiled_code:
_BOOL8 __fastcall test_delim(char a1)
{
return a1 == 58;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return a1 == 58;
}

original_code:
int test_delim(char c) {
    return (c == ':');
}

variable_types: c char


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

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

original_code:
void p2p_addr_delete(p2p_addr addr) {
    free(addr);
}

canonical_original_code:
void p2p_addr_delete(struct p2p_addr_struct *addr) {
    free(addr);
}

variable_types: struct p2p_addr_struct { struct in_addr { unsigned int s_addr; } ip; unsigned short tcp_port; unsigned short udp_port; } *

user_defined_types: struct p2p_addr_struct { struct in_addr ip; unsigned short tcp_port; unsigned short udp_port; }


decompiled_code:
_BOOL8 __fastcall p2p_addr_is_equal(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

original_code:
int p2p_addr_is_equal(const p2p_addr addr1, const p2p_addr addr2) {
    return ((addr1->ip.s_addr == addr2->ip.s_addr) &&
            (addr1->tcp_port == addr2->tcp_port) &&
            (addr1->udp_port == addr2->udp_port));
}

canonical_original_code:
int p2p_addr_is_equal(struct p2p_addr_struct *addr1, struct p2p_addr_struct *addr2) {
    return ((addr1->ip.s_addr == addr2->ip.s_addr) &&
            (addr1->tcp_port == addr2->tcp_port) &&
            (addr1->udp_port == addr2->udp_port));
}


decompiled_code:
__int64 __fastcall p2p_addr_set(struct in_addr *inp, char *cp, __int16 a3, __int16 a4)
{
if ( !inet_aton(cp, inp) )
return 0xFFFFFFFFLL;
LOWORD(inp[1].s_addr) = _bswap_16(a3);
HIWORD(inp[1].s_addr) = _bswap_16(a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(struct in_addr *inp, char *cp, __int16 a3, __int16 a4)
{
if ( !inet_aton(cp, inp) )
return 0xFFFFFFFFLL;
LOWORD(inp[1].s_addr) = func1(a3);
HIWORD(inp[1].s_addr) = func1(a4);
return 0LL;
}

original_code:
int p2p_addr_set(p2p_addr dst, const char* ip_str,
        unsigned short tcp, unsigned short udp) {
    if (inet_aton(ip_str, & dst->ip) == 0) {
        return -1;
    }
    dst->tcp_port = htons(tcp);
    dst->udp_port = htons(udp);
    return 0;
}

canonical_original_code:
int p2p_addr_set(struct p2p_addr_struct *dst, char *ip_str, unsigned short tcp, unsigned short udp) {
    if (inet_aton(ip_str, & dst->ip) == 0) {
        return -1;
    }
    dst->tcp_port = htons(tcp);
    dst->udp_port = htons(udp);
    return 0;
}

variable_types:
tcp
unsigned short

variable_types:
udp
unsigned short


decompiled_code:
__int64 __fastcall p2p_addr_setstr(struct in_addr *inp, __int64 a2)
{
__int16 v2; // bx
__int16 v3; // ax
char v5[30]; // [rsp+0h] [rbp-78h] BYREF
char v6[30]; // [rsp+1Eh] [rbp-5Ah] BYREF
char nptr[60]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( (unsigned int)get_tokens(a2, v5, test_delim) != 3 )
return 0xFFFFFFFFLL;
v2 = atoi(nptr);
v3 = atoi(v6);
return p2p_addr_set(inp, v5, v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(struct in_addr *inp, __int64 a2)
{
__int16 v2; // bx
__int16 v3; // ax
char v5[30]; // [rsp+0h] [rbp-78h] BYREF
char v6[30]; // [rsp+1Eh] [rbp-5Ah] BYREF
char nptr[60]; // [rsp+3Ch] [rbp-3Ch] BYREF

if ( (unsigned int)get_tokens(a2, v5, test_delim) != 3 )
return 0xFFFFFFFFLL;
v2 = atoi(nptr);
v3 = atoi(v6);
return func5(inp, v5, v3, v2);
}

original_code:
int p2p_addr_setstr(p2p_addr dst, const char* p2p_str) {
    char tokens[3][30];
    if (get_tokens(p2p_str, tokens, test_delim) == 3) {
        return p2p_addr_set(dst, tokens[0], atoi(tokens[1]), atoi(tokens[2]));
    } else {
        return -1;
    }
}

canonical_original_code:
int p2p_addr_setstr(struct p2p_addr_struct *dst, char *p2p_str) {
    char tokens[3][30];
    if (get_tokens(p2p_str, tokens, test_delim) == 3) {
        return p2p_addr_set(dst, tokens[0], atoi(tokens[1]), atoi(tokens[2]));
    } else {
        return -1;
    }
}

variable_types:
tokens
char [3][30]


decompiled_code:
__int64 __fastcall p2p_addr_set_undefined(struct in_addr *a1)
{
return p2p_addr_set(a1, "0.0.0.0", 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func7(struct in_addr *a1)
{
return func5(a1, "0.0.0.0", 0, 0);
}

original_code:
void p2p_addr_set_undefined(p2p_addr addr) {
    p2p_addr_set(addr, "0.0.0.0", 0, 0);
}

canonical_original_code:
void p2p_addr_set_undefined(struct p2p_addr_struct *addr) {
    p2p_addr_set(addr, "0.0.0.0", 0, 0);
}


decompiled_code:
struct in_addr *p2p_addr_create()
{
struct in_addr *v0; // rbx

v0 = (struct in_addr *)malloc(8uLL);
p2p_addr_set_undefined(v0);
return v0;
}

canonical_decompiled_code:
struct in_addr *func8()
{
struct in_addr *v0; // rbx

v0 = (struct in_addr *)malloc(8uLL);
func7(v0);
return v0;
}

original_code:
p2p_addr p2p_addr_create() {
    p2p_addr a;
    a = (p2p_addr) malloc(sizeof (struct p2p_addr_struct));
    p2p_addr_set_undefined(a);
    return a;
}

canonical_original_code:
struct p2p_addr_struct *p2p_addr_create() {
    struct p2p_addr_struct *a;
    a = (struct p2p_addr_struct *) malloc(sizeof (struct p2p_addr_struct));
    p2p_addr_set_undefined(a);
    return a;
}

return_type: struct p2p_addr_struct { struct in_addr { unsigned int s_addr; } ip; unsigned short tcp_port; unsigned short udp_port; } *


decompiled_code:
_BOOL8 __fastcall p2p_addr_is_undefined(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

p2p_addr_set_undefined(v2);
return p2p_addr_is_equal(a1, v2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

func7(v2);
return func4(a1, v2);
}

original_code:
int p2p_addr_is_undefined(const p2p_addr addr) {
    struct p2p_addr_struct u;
    p2p_addr_set_undefined(&u);
    return p2p_addr_is_equal(addr, &u);
}

canonical_original_code:
int p2p_addr_is_undefined(struct p2p_addr_struct *addr) {
    struct p2p_addr_struct u;
    p2p_addr_set_undefined(&u);
    return p2p_addr_is_equal(addr, &u);
}

variable_types: struct p2p_addr_struct { struct in_addr { unsigned int s_addr; } ip; unsigned short tcp_port; unsigned short udp_port; }


decompiled_code:
void *p2p_addr_undefined()
{
p2p_addr_set_undefined((struct in_addr *)&a_1);
return &a_1;
}

canonical_decompiled_code:
void *func10()
{
func7((struct in_addr *)&a_1);
return &a_1;
}

original_code:
p2p_addr p2p_addr_undefined() {
    static struct p2p_addr_struct a;
    p2p_addr_set_undefined(&a);
    return &a;
}

canonical_original_code:
struct p2p_addr_struct *p2p_addr_undefined() {
    static struct p2p_addr_struct a;
    p2p_addr_set_undefined(&a);
    return &a;
}


decompiled_code:
__int64 __fastcall p2p_addr_set_broadcast(struct in_addr *a1)
{
return p2p_addr_set(a1, "255.255.255.255", 0, 0);
}

original_code:
void p2p_addr_set_broadcast(p2p_addr addr) {
    p2p_addr_set(addr, "255.255.255.255", 0, 0);
}

canonical_original_code:
void p2p_addr_set_broadcast(struct p2p_addr_struct *addr) {
    p2p_addr_set(addr, "255.255.255.255", 0, 0);
}


decompiled_code:
_BOOL8 __fastcall p2p_addr_is_broadcast(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

p2p_addr_set_broadcast(v2);
return p2p_addr_is_equal(a1, v2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_DWORD *a1)
{
struct in_addr v2[4]; // [rsp+8h] [rbp-10h] BYREF

func11(v2);
return func4(a1, v2);
}

original_code:
int p2p_addr_is_broadcast(const p2p_addr addr) {
    struct p2p_addr_struct b;
    p2p_addr_set_broadcast(&b);
    return p2p_addr_is_equal(addr, &b);
}

canonical_original_code:
int p2p_addr_is_broadcast(struct p2p_addr_struct *addr) {
    struct p2p_addr_struct b;
    p2p_addr_set_broadcast(&b);
    return p2p_addr_is_equal(addr, &b);
}


decompiled_code:
void *p2p_addr_broadcast()
{
p2p_addr_set_broadcast((struct in_addr *)&a_2);
return &a_2;
}

canonical_decompiled_code:
void *func13()
{
func11((struct in_addr *)&a_2);
return &a_2;
}

original_code:
p2p_addr p2p_addr_broadcast() {
    static struct p2p_addr_struct a;
    p2p_addr_set_broadcast(&a);
    return &a;
}

canonical_original_code:
struct p2p_addr_struct *p2p_addr_broadcast() {
    static struct p2p_addr_struct a;
    p2p_addr_set_broadcast(&a);
    return &a;
}


decompiled_code:
char *__fastcall p2p_addr_get_ip_str(struct in_addr *a1)
{
return inet_ntoa((struct in_addr)a1->s_addr);
}

canonical_decompiled_code:
char *__fastcall func14(struct in_addr *a1)
{
return inet_ntoa((struct in_addr)a1->s_addr);
}

original_code:
char* p2p_addr_get_ip_str(p2p_addr addr) {
    return inet_ntoa(addr->ip);
}

canonical_original_code:
char *p2p_addr_get_ip_str(struct p2p_addr_struct *addr) {
    return inet_ntoa(addr->ip);
}


decompiled_code:
__int16 __fastcall p2p_addr_get_tcp_port(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 4));
}

canonical_decompiled_code:
__int16 __fastcall func15(__int64 a1)
{
return func1(*(_WORD *)(a1 + 4));
}

original_code:
unsigned short p2p_addr_get_tcp_port(p2p_addr addr) {
    return ntohs(addr->tcp_port);
}

canonical_original_code:
unsigned short p2p_addr_get_tcp_port(struct p2p_addr_struct *addr) {
    return ntohs(addr->tcp_port);
}

return_type: unsigned short


decompiled_code:
__int16 __fastcall p2p_addr_get_udp_port(__int64 a1)
{
return _bswap_16(*(_WORD *)(a1 + 6));
}

canonical_decompiled_code:
__int16 __fastcall func16(__int64 a1)
{
return func1(*(_WORD *)(a1 + 6));
}

original_code:
unsigned short p2p_addr_get_udp_port(p2p_addr addr) {
    return ntohs(addr->udp_port);
}

canonical_original_code:
unsigned short p2p_addr_get_udp_port(struct p2p_addr_struct *addr) {
    return ntohs(addr->udp_port);
}


decompiled_code:
char *__fastcall p2p_addr_get_str(struct in_addr *a1)
{
unsigned __int16 v1; // r12
unsigned __int16 v2; // bx
char *v3; // rax

v1 = p2p_addr_get_udp_port((__int64)a1);
v2 = p2p_addr_get_tcp_port((__int64)a1);
v3 = p2p_addr_get_ip_str(a1);
sprintf(str_0, "%s:%d:%d", v3, v2, v1);
return str_0;
}

canonical_decompiled_code:
char *__fastcall func17(struct in_addr *a1)
{
unsigned __int16 v1; // r12
unsigned __int16 v2; // bx
char *v3; // rax

v1 = func16((__int64)a1);
v2 = func15((__int64)a1);
v3 = func14(a1);
sprintf(str_0, "%s:%d:%d", v3, v2, v1);
return str_0;
}

original_code:
char* p2p_addr_get_str(p2p_addr addr) {
    static char str[15 + 1 + 5 + 1 + 5 + 1];
    sprintf(str, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    return str;
}

canonical_original_code:
char *p2p_addr_get_str(struct p2p_addr_struct *addr) {
    static char str[-1];
    sprintf(str, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    return str;
}

variable_types:
str
char [-1]


decompiled_code:
ssize_t __fastcall p2p_addr_dump(struct in_addr *a1, int a2)
{
unsigned __int16 v2; // r13
unsigned __int16 v3; // bx
char *v4; // rax
int v5; // eax
char v7[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = p2p_addr_get_udp_port((__int64)a1);
v3 = p2p_addr_get_tcp_port((__int64)a1);
v4 = p2p_addr_get_ip_str(a1);
v5 = sprintf(v7, "%s:%d:%d", v4, v3, v2);
return write(a2, v7, v5);
}

canonical_decompiled_code:
ssize_t __fastcall func18(struct in_addr *a1, int a2)
{
unsigned __int16 v2; // r13
unsigned __int16 v3; // bx
char *v4; // rax
int v5; // eax
char v7[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = func16((__int64)a1);
v3 = func15((__int64)a1);
v4 = func14(a1);
v5 = sprintf(v7, "%s:%d:%d", v4, v3, v2);
return write(a2, v7, v5);
}

original_code:
void p2p_addr_dump(const p2p_addr addr, int fd) {
    char buf[1024];
    int length;
    length = sprintf(buf, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    write(fd, buf, length);
}

canonical_original_code:
void p2p_addr_dump(struct p2p_addr_struct *addr, int fd) {
    char buf[1024];
    int length;
    length = sprintf(buf, "%s:%d:%d",
            p2p_addr_get_ip_str(addr),
            p2p_addr_get_tcp_port(addr),
            p2p_addr_get_udp_port(addr));
    write(fd, buf, length);
}

variable_types: fd int

variable_types:
buf
char [1024]


original_code:
int
get_tokens(const char *str, char tok[3][30], int (*test_delim)(char)) {
    int i = 0;
    int token = 0;
    int index = 0;
    while (str[i] && token < 3) {
        while (str[i] && test_delim(str[i])) {
            i++;
        }
        index = 0;
        while (str[i] && !test_delim(str[i]) && index < 30) {
            tok[token][index++] = str[i++];
        }
        tok[token++][index] = '\0';
    }
    return token;
}

canonical_original_code:
int get_tokens(char *str, char tok[3][30], int (*test_delim)(char)) {
    int i = 0;
    int token = 0;
    int index = 0;
    while (str[i] && token < 3) {
        while (str[i] && test_delim(str[i])) {
            i++;
        }
        index = 0;
        while (str[i] && !test_delim(str[i]) && index < 30) {
            tok[token][index++] = str[i++];
        }
        tok[token++][index] = '\0';
    }
    return token;
}

variable_types:
str
char *

variable_types:
tok
char [3][30]

variable_types: i int

variable_types: token int

variable_types: index int


decompiled_code:
int __fastcall raw_print(unsigned __int8 *a1, int a2)
{
unsigned __int8 *i; // rbp
int v3; // ebx

if ( a2 > 0 )
{
printf("%02x ", *a1);
for ( i = a1 + 1; ; ++i )
{
v3 = (_DWORD)i - (_DWORD)a1;
if ( &a1[a2] == i )
break;
printf("%02x ", *i);
if ( v3 % 16 == 15 )
putchar(10);
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int8 *a1, int a2)
{
unsigned __int8 *i; // rbp
int v3; // ebx

if ( a2 > 0 )
{
printf("%02x ", *a1);
for ( i = a1 + 1; ; ++i )
{
v3 = (_DWORD)i - (_DWORD)a1;
if ( &a1[a2] == i )
break;
printf("%02x ", *i);
if ( v3 % 16 == 15 )
putchar(10);
}
}
return putchar(10);
}

original_code:
void raw_print(char *buf, int size) {
    int i;
    char *visitor;
    visitor = buf;
    for (i = 0; i < size; i++) {
        printf("%02x ", *visitor & 0xff);
        visitor++;
        if (i % 16 == 15) printf("\n");
    }
    printf("\n");
}

variable_types:
buf
char *

variable_types: size int

variable_types:
visitor
char *


decompiled_code:
__int64 __fastcall creer_socket(int type, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = socket(2, type, 0);
v3 = v2;
if ( v2 == -1 )
{
perror("Impossible to create the socket");
}
else
{
optval[0] = 1;
if ( setsockopt(v2, 1, 2, optval, 4u) < 0 )
{
perror("Could'nt setsockopt");
close(v3);
v3 = -1;
}
else
{
v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = _bswap_32(0);
*(_WORD *)v5.sa_data = _bswap_16(a2);
if ( bind(v3, &v5, 0x10u) == -1 )
{
perror(" Socket attachement failed");
close(v3);
v3 = -1;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int type, __int16 a2)
{
int v2; // eax
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v2 = socket(2, type, 0);
v3 = v2;
if ( v2 == -1 )
{
perror("Impossible to create the socket");
}
else
{
optval[0] = 1;
if ( setsockopt(v2, 1, 2, optval, 4u) < 0 )
{
perror("Could'nt setsockopt");
close(v3);
v3 = -1;
}
else
{
v5.sa_family = 2;
*(_DWORD *)&v5.sa_data[2] = func0(0);
*(_WORD *)v5.sa_data = func1(a2);
if ( bind(v3, &v5, 0x10u) == -1 )
{
perror(" Socket attachement failed");
close(v3);
v3 = -1;
}
}
}
return v3;
}

original_code:
int creer_socket(int type, int port) {
    int desc;
    int valid;
    int longueur = sizeof (struct sockaddr_in);
    struct sockaddr_in adresse;
    if ((desc = socket(2, type, 0)) == -1) {
        perror("Impossible to create the socket");
        return -1;
    }
    valid = 1;
    if (setsockopt(desc, 1, 2, (void*) &valid, sizeof (valid)) < 0) {
        perror("Could'nt setsockopt");
        close(desc);
        return -1;
    }
    adresse.sin_family = 2;
    adresse.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    adresse.sin_port = htons(port);
    if (bind(desc, (struct sockaddr*) &adresse, longueur) == -1) {
        perror(" Socket attachement failed");
        close(desc);
        return -1;
    }
    return desc;
}

canonical_original_code:
int creer_socket(int type, int port) {
    int desc;
    int valid;
    int longueur = sizeof (struct sockaddr_in);
    struct sockaddr_in adresse;
    if ((desc = socket(2, type, 0)) == -1) {
        perror("Impossible to create the socket");
        return -1;
    }
    valid = 1;
    if (setsockopt(desc, 1, 2, (void *) &valid, sizeof (valid)) < 0) {
        perror("Could'nt setsockopt");
        close(desc);
        return -1;
    }
    adresse.sin_family = 2;
    adresse.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    adresse.sin_port = htons(port);
    if (bind(desc, (struct sockaddr *) &adresse, longueur) == -1) {
        perror(" Socket attachement failed");
        close(desc);
        return -1;
    }
    return desc;
}

variable_types: type int

variable_types: port int

variable_types: desc int

variable_types: valid int

variable_types: longueur 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]; }

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


max

decompiled_code:
__int64 __fastcall max(signed int a1, signed int a2)
{
__int64 result; // rax

result = (unsigned int)a1;
if ( a1 < a2 )
return (unsigned int)a2;
if ( a1 <= a2 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(signed int a1, signed int a2)
{
__int64 result; // rax

result = (unsigned int)a1;
if ( a1 < a2 )
return (unsigned int)a2;
if ( a1 <= a2 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int max(int a, int b) {
    if (a < b) {
        return b;
    } else if (a > b) {
        return a;
    } else return -1;
}

variable_types: a int

variable_types: b int


usage

decompiled_code:
int __fastcall usage(__int64 a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

strcpy(
v2,
"%s: a p2p node \n"
" -c, --connect=[p2paddr] : connect to node after init \n"
" -d, --dir=[path] : directory for download files \n"
" -s, --server-name=[string] : server name \n"
" -i, --listening-ip=[ip] : listening ip address \n"
" -U, --ui-tcp-port=[port] : listening port for user interface \n"
" -t, --p2p-tcp-port=[port] : listening port for tcp p2p traffic \n"
" -u, --p2p-udp-port=[port] : listening port for udp p2p traffic \n"
" -v, --verbose=[int] : debug verbosity level \n"
" 0 - print nothing \n"
" 1 - print protocol errors \n"
" 2 - trace received msg \n"
" 3 - trace msg actions and content \n"
" 4 - trace server syscalls \n"
" -h, --help : this message \n");
return fprintf(stdout, v2, a1);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
char v2[1016]; // [rsp+0h] [rbp-3F8h] BYREF

strcpy(
v2,
"%s: a p2p node \n"
" -c, --connect=[p2paddr] : connect to node after init \n"
" -d, --dir=[path] : directory for download files \n"
" -s, --server-name=[string] : server name \n"
" -i, --listening-ip=[ip] : listening ip address \n"
" -U, --ui-tcp-port=[port] : listening port for user interface \n"
" -t, --p2p-tcp-port=[port] : listening port for tcp p2p traffic \n"
" -u, --p2p-udp-port=[port] : listening port for udp p2p traffic \n"
" -v, --verbose=[int] : debug verbosity level \n"
" 0 - print nothing \n"
" 1 - print protocol errors \n"
" 2 - trace received msg \n"
" 3 - trace msg actions and content \n"
" 4 - trace server syscalls \n"
" -h, --help : this message \n");
return fprintf(stdout, v2, a1);
}

original_code:
void
usage(char* progname) {
    char msg[] = "%s: a p2p node                                                    \n  -c, --connect=[p2paddr]    : connect to node after init         \n  -d, --dir=[path]           : directory for download files       \n  -s, --server-name=[string] : server name                        \n  -i, --listening-ip=[ip]    : listening ip address               \n  -U, --ui-tcp-port=[port]   : listening port for user interface  \n  -t, --p2p-tcp-port=[port]  : listening port for tcp p2p traffic \n  -u, --p2p-udp-port=[port]  : listening port for udp p2p traffic \n  -v, --verbose=[int]        : debug verbosity level              \n                               0 - print nothing                  \n                               1 - print protocol errors          \n                               2 - trace received msg             \n                               3 - trace msg actions and content  \n                               4 - trace server syscalls          \n  -h, --help                 : this message                       \n";
    fprintf(stdout, msg, progname);
}

canonical_original_code:
void usage(char *progname) {
    char msg[] = "%s: a p2p node                                                    \n  -c, --connect=[p2paddr]    : connect to node after init         \n  -d, --dir=[path]           : directory for download files       \n  -s, --server-name=[string] : server name                        \n  -i, --listening-ip=[ip]    : listening ip address               \n  -U, --ui-tcp-port=[port]   : listening port for user interface  \n  -t, --p2p-tcp-port=[port]  : listening port for tcp p2p traffic \n  -u, --p2p-udp-port=[port]  : listening port for udp p2p traffic \n  -v, --verbose=[int]        : debug verbosity level              \n                               0 - print nothing                  \n                               1 - print protocol errors          \n                               2 - trace received msg             \n                               3 - trace msg actions and content  \n                               4 - trace server syscalls          \n  -h, --help                 : this message                       \n";
    fprintf(stdout, msg, progname);
}

variable_types:
progname
char *

variable_types:
msg
char []


decompiled_code:
__int64 __fastcall test_ui_delim(unsigned __int8 a1)
{
char v1; // al

v1 = 1;
if ( a1 <= 0x20u )
v1 = ((0x100002600uLL >> a1) ^ 1) & 1;
return (unsigned __int8)v1 ^ 1u;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
char v1; // al

v1 = 1;
if ( a1 <= 0x20u )
v1 = ((0x100002600uLL >> a1) ^ 1) & 1;
return (unsigned __int8)v1 ^ 1u;
}

variable_types: c char


fileTypeToString

repo: alexpogue/soundutils

decompiled_code:
void __fastcall fileTypeToString(char *a1, int a2)
{
if ( a2 == 1 )
{
strcpy(a1, "WAVE");
}
else if ( !a2 )
{
strcpy(a1, "CS229");
}
}

canonical_decompiled_code:
void __fastcall func2(char *a1, int a2)
{
if ( a2 == 1 )
{
strcpy(a1, "WAVE");
}
else if ( !a2 )
{
strcpy(a1, "CS229");
}
}

original_code:
void fileTypeToString(char* str, fileType_t type) {
  if(type == WAVE) {
    strcpy(str, "WAVE");
  }
  else if(type == CS229) {
    strcpy(str, "CS229");
  }
}

canonical_original_code:
void fileTypeToString(char *str, enum fileType_t type) {
  if(type == WAVE) {
    strcpy(str, "WAVE");
  }
  else if(type == CS229) {
    strcpy(str, "CS229");
  }
}

variable_types:
str
char *

variable_types:
type
enum fileType_t { CS229=0, WAVE=1 }


printSoundDetails

decompiled_code:
int __fastcall printSoundDetails(__int64 a1)
{
unsigned int v1; // eax
float v2; // xmm0_4
char v4[14]; // [rsp+Ah] [rbp-Eh] BYREF

fileTypeToString(v4, *(_DWORD *)(a1 + 8));
printf("File name: %s\n", *(const char **)(a1 + 16));
printf("File type: %s\n", v4);
printf("Sample rate: %ld\n", *(_QWORD *)a1);
printf("Bit depth: %d\n", *(unsigned __int16 *)(a1 + 42));
printf("Number of channels: %d\n", *(unsigned __int16 *)(a1 + 40));
v1 = calculateNumSamples(a1);
printf("Number of samples: %d\n", v1);
v2 = calculateSoundLength(a1);
return printf("Sound length (seconds): %.3f\n", v2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
unsigned int v1; // eax
float v2; // xmm0_4
char v4[14]; // [rsp+Ah] [rbp-Eh] BYREF

func2(v4, *(_DWORD *)(a1 + 8));
printf("File name: %s\n", *(const char **)(a1 + 16));
printf("File type: %s\n", v4);
printf("Sample rate: %ld\n", *(_QWORD *)a1);
printf("Bit depth: %d\n", *(unsigned __int16 *)(a1 + 42));
printf("Number of channels: %d\n", *(unsigned __int16 *)(a1 + 40));
v1 = calculateNumSamples(a1);
printf("Number of samples: %d\n", v1);
v2 = calculateSoundLength(a1);
return printf("Sound length (seconds): %.3f\n", v2);
}

original_code:
void printSoundDetails(sound_t* sound) {
  char typeStr[6];
  fileTypeToString(typeStr, sound->fileType);
  printf("File name: %s\n", sound->fileName);
  printf("File type: %s\n", typeStr);
  printf("Sample rate: %ld\n", sound->sampleRate);
  printf("Bit depth: %d\n", sound->bitDepth);
  printf("Number of channels: %d\n", sound->numChannels);
  printf("Number of samples: %d\n", calculateNumSamples(sound));
  printf("Sound length (seconds): %.3f\n", calculateSoundLength(sound));
}

canonical_original_code:
void printSoundDetails(struct sound_t *sound) {
  char typeStr[6];
  fileTypeToString(typeStr, sound->fileType);
  printf("File name: %s\n", sound->fileName);
  printf("File type: %s\n", typeStr);
  printf("Sample rate: %ld\n", sound->sampleRate);
  printf("Bit depth: %d\n", sound->bitDepth);
  printf("Number of channels: %d\n", sound->numChannels);
  printf("Number of samples: %d\n", calculateNumSamples(sound));
  printf("Sound length (seconds): %.3f\n", calculateSoundLength(sound));
}

variable_types: struct sound_t { unsigned long sampleRate; enum fileType_t { CS229=0, WAVE=1 } fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 } error; unsigned short numChannels; unsigned short bitDepth; } *

variable_types:
typeStr
char [6]

user_defined_types: struct sound_t { unsigned long sampleRate; enum fileType_t fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t error; unsigned short numChannels; unsigned short bitDepth; }


printUsage

decompiled_code:
int __fastcall printUsage(const char *a1)
{
return printf("Usage: %s file1 [file2 ...]\n\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("Usage: %s file1 [file2 ...]\n\n", a1);
}

original_code:
void printUsage(char* exeName) {
  printf("Usage: %s file1 [file2 ...]\n\n", exeName);
}

canonical_original_code:
void printUsage(char *exeName) {
  printf("Usage: %s file1 [file2 ...]\n\n", exeName);
}

variable_types:
exeName
char *


printHelp

decompiled_code:
int __fastcall printHelp(const char *a1)
{
puts("Sndinfo Help:");
printUsage(a1);
puts("Utility:");
puts("This program reads each wav and CS229 sound file passed as");
puts("arguments and outputs their information.\n");
puts("Options: ");
return puts("-h\tdisplays this help page");
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
puts("Sndinfo Help:");
func0(a1);
puts("Utility:");
puts("This program reads each wav and CS229 sound file passed as");
puts("arguments and outputs their information.\n");
puts("Options: ");
return puts("-h\tdisplays this help page");
}

original_code:
void printHelp(char* exeName) {
  printf("Sndinfo Help:\n");
  printUsage(exeName);
  printf("Utility:\n");
  printf("This program reads each wav and CS229 sound file passed as\n");
  printf("arguments and outputs their information.\n\n");
  printf("Options: \n");
  printf("-h\tdisplays this help page\n");
}

canonical_original_code:
void printHelp(char *exeName) {
  printf("Sndinfo Help:\n");
  printUsage(exeName);
  printf("Utility:\n");
  printf("This program reads each wav and CS229 sound file passed as\n");
  printf("arguments and outputs their information.\n\n");
  printf("Options: \n");
  printf("-h\tdisplays this help page\n");
}


printMemoryError

decompiled_code:
size_t printMemoryError()
{
return fwrite("Could not allocate memory\n", 1uLL, 0x1AuLL, stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite("Could not allocate memory\n", 1uLL, 0x1AuLL, stderr);
}

original_code:
void printMemoryError() {
  fprintf(stderr, "Could not allocate memory\n");
}


printFileTypeError

decompiled_code:
size_t printFileTypeError()
{
return fwrite("Unknown file type\n", 1uLL, 0x12uLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite("Unknown file type\n", 1uLL, 0x12uLL, stderr);
}

original_code:
void printFileTypeError() {
  fprintf(stderr, "Unknown file type\n");
}


printFileOpenError

decompiled_code:
int __fastcall printFileOpenError(const char *a1)
{
return fprintf(stderr, "Could not open file: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return fprintf(stderr, "Could not open file: %s\n", a1);
}

original_code:
void printFileOpenError(char* filePath) {
  fprintf(stderr, "Could not open file: %s\n", filePath);
}

canonical_original_code:
void printFileOpenError(char *filePath) {
  fprintf(stderr, "Could not open file: %s\n", filePath);
}

variable_types:
filePath
char *


printSoundLoadError

decompiled_code:
size_t printSoundLoadError()
{
return fwrite("Could not load sound\n", 1uLL, 0x15uLL, stderr);
}

canonical_decompiled_code:
size_t func3()
{
return fwrite("Could not load sound\n", 1uLL, 0x15uLL, stderr);
}

original_code:
void printSoundLoadError() {
  fprintf(stderr, "Could not load sound\n");
}


printEofError

decompiled_code:
size_t printEofError()
{
return fwrite("Unexpected end of file\n", 1uLL, 0x17uLL, stderr);
}

canonical_decompiled_code:
size_t func4()
{
return fwrite("Unexpected end of file\n", 1uLL, 0x17uLL, stderr);
}

original_code:
void printEofError() {
  fprintf(stderr, "Unexpected end of file\n");
}


printFileReadError

decompiled_code:
size_t printFileReadError()
{
return fwrite("Could not read file\n", 1uLL, 0x14uLL, stderr);
}

canonical_decompiled_code:
size_t func5()
{
return fwrite("Could not read file\n", 1uLL, 0x14uLL, stderr);
}

original_code:
void printFileReadError() {
  fprintf(stderr, "Could not read file\n");
}


printInvalidOptionError

decompiled_code:
int __fastcall printInvalidOptionError(char a1)
{
return fprintf(stderr, "Unknown option -%c. Use -h for help.\n", (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func6(char a1)
{
return fprintf(stderr, "Unknown option -%c. Use -h for help.\n", (unsigned int)a1);
}

original_code:
void printInvalidOptionError(char optionChar) {
  fprintf(stderr, "Unknown option -%c. Use -h for help.\n", optionChar);
}

variable_types: optionChar char


printBitDepthError

decompiled_code:
size_t printBitDepthError()
{
return fwrite("Unsupported bit depth encountered\n", 1uLL, 0x22uLL, stderr);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite("Unsupported bit depth encountered\n", 1uLL, 0x22uLL, stderr);
}

original_code:
void printBitDepthError() {
  fprintf(stderr, "Unsupported bit depth encountered\n");
}


printInvalidKeywordError

decompiled_code:
size_t printInvalidKeywordError()
{
return fwrite("Invalid keyword found in file\n", 1uLL, 0x1EuLL, stderr);
}

canonical_decompiled_code:
size_t func8()
{
return fwrite("Invalid keyword found in file\n", 1uLL, 0x1EuLL, stderr);
}

original_code:
void printInvalidKeywordError() {
  fprintf(stderr, "Invalid keyword found in file\n");
}


printNoValueError

decompiled_code:
size_t printNoValueError()
{
return fwrite("No value given for a keyword in the file\n", 1uLL, 0x29uLL, stderr);
}

canonical_decompiled_code:
size_t func9()
{
return fwrite("No value given for a keyword in the file\n", 1uLL, 0x29uLL, stderr);
}

original_code:
void printNoValueError() {
  fprintf(stderr, "No value given for a keyword in the file\n");
}


printSampleDataError

decompiled_code:
size_t printSampleDataError()
{
return fwrite("Corrupted sample data in the file\n", 1uLL, 0x22uLL, stderr);
}

canonical_decompiled_code:
size_t func10()
{
return fwrite("Corrupted sample data in the file\n", 1uLL, 0x22uLL, stderr);
}

original_code:
void printSampleDataError() {
  fprintf(stderr, "Corrupted sample data in the file\n");
}


printSampleRateError

decompiled_code:
size_t printSampleRateError()
{
return fwrite("Incompatible sample rates in sounds\n", 1uLL, 0x24uLL, stderr);
}

canonical_decompiled_code:
size_t func11()
{
return fwrite("Incompatible sample rates in sounds\n", 1uLL, 0x24uLL, stderr);
}

original_code:
void printSampleRateError() {
  fprintf(stderr, "Incompatible sample rates in sounds\n");
}


printZeroChannelsError

decompiled_code:
size_t printZeroChannelsError()
{
return fwrite("Sound is either empty or incorrectly zero channels\n", 1uLL, 0x33uLL, stderr);
}

canonical_decompiled_code:
size_t func12()
{
return fwrite("Sound is either empty or incorrectly zero channels\n", 1uLL, 0x33uLL, stderr);
}

original_code:
void printZeroChannelsError() {
  fprintf(stderr, "Sound is either empty or incorrectly zero channels\n");
}


printErrorsInSound

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

if ( *(_DWORD *)(a1 + 36) )
{
fprintf(stderr, "Error in file: %s\n", *(const char **)(a1 + 16));
v1 = *(_DWORD *)(a1 + 36);
switch ( v1 )
{
case 1:
printEofError();
break;
case 2:
printFileReadError();
break;
case 3:
printMemoryError();
break;
case 4:
printFileTypeError();
break;
case 5:
printBitDepthError();
break;
case 6:
printInvalidKeywordError();
break;
case 7:
printNoValueError();
break;
case 8:
printSampleDataError();
break;
case 9:
printZeroChannelsError();
break;
default:
puts("Unforeseen error occurred!");
break;
}
}
}

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

if ( *(_DWORD *)(a1 + 36) )
{
fprintf(stderr, "Error in file: %s\n", *(const char **)(a1 + 16));
v1 = *(_DWORD *)(a1 + 36);
switch ( v1 )
{
case 1:
func4();
break;
case 2:
func5();
break;
case 3:
func0();
break;
case 4:
func1();
break;
case 5:
func7();
break;
case 6:
func8();
break;
case 7:
func9();
break;
case 8:
func10();
break;
case 9:
func12();
break;
default:
puts("Unforeseen error occurred!");
break;
}
}
}

original_code:
void printErrorsInSound(sound_t* sound) {
  if(sound->error == NO_ERROR) {
    return;
  }
  fprintf(stderr, "Error in file: %s\n", sound->fileName);
  if(sound->error == ERROR_EOF) {
    printEofError();
  }
  else if(sound->error == ERROR_READING) {
    printFileReadError();
  }
  else if(sound->error == ERROR_MEMORY) {
    printMemoryError();
  }
  else if(sound->error == ERROR_FILETYPE) {
    printFileTypeError();
  }
  else if(sound->error == ERROR_BIT_DEPTH) {
    printBitDepthError();
  }
  else if(sound->error == ERROR_INVALID_KEYWORD) {
    printInvalidKeywordError();
  }
  else if(sound->error == ERROR_NO_VALUE) {
    printNoValueError();
  }
  else if(sound->error == ERROR_SAMPLE_DATA) {
    printSampleDataError();
  }
  else if(sound->error == ERROR_ZERO_CHANNELS) {
    printZeroChannelsError();
  }
  else {
    printf("Unforeseen error occurred!\n");
  }
}

canonical_original_code:
void printErrorsInSound(struct sound_t *sound) {
  if(sound->error == NO_ERROR) {
    return;
  }
  fprintf(stderr, "Error in file: %s\n", sound->fileName);
  if(sound->error == ERROR_EOF) {
    printEofError();
  }
  else if(sound->error == ERROR_READING) {
    printFileReadError();
  }
  else if(sound->error == ERROR_MEMORY) {
    printMemoryError();
  }
  else if(sound->error == ERROR_FILETYPE) {
    printFileTypeError();
  }
  else if(sound->error == ERROR_BIT_DEPTH) {
    printBitDepthError();
  }
  else if(sound->error == ERROR_INVALID_KEYWORD) {
    printInvalidKeywordError();
  }
  else if(sound->error == ERROR_NO_VALUE) {
    printNoValueError();
  }
  else if(sound->error == ERROR_SAMPLE_DATA) {
    printSampleDataError();
  }
  else if(sound->error == ERROR_ZERO_CHANNELS) {
    printZeroChannelsError();
  }
  else {
    printf("Unforeseen error occurred!\n");
  }
}

user_defined_types: enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 }


distributeIntoChannels

decompiled_code:
unsigned __int64 __fastcall distributeIntoChannels(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
int v5; // er11
int v6; // edx
int v7; // er10
int v8; // er12
int v9; // edi
__int64 v10; // rsi
int v11; // er9
int v12; // er8

result = (unsigned __int64)realloc(*(void **)(a1 + 24), *(unsigned int *)(a1 + 32));
if ( result )
{
*(_QWORD *)(a1 + 24) = result;
v3 = *(_QWORD *)(a2 + 24);
addZeroedChannels(*(unsigned __int16 *)(a2 + 40), a1);
v4 = *(_QWORD *)(a1 + 24);
v5 = calculateNumSamples(a1);
v6 = *(unsigned __int16 *)(a2 + 42);
result = v6 * (unsigned int)*(unsigned __int16 *)(a1 + 40);
v7 = (int)result / 8;
v8 = v6 * *(unsigned __int16 *)(a2 + 40);
v9 = v8 / 8;
if ( v5 > 0 )
{
result = v9;
v10 = v4 + v7 - (__int64)v9;
v11 = 0;
v12 = 0;
do
{
++v12;
if ( v8 > 7 )
{
result = 0LL;
do
{
*(_BYTE *)(v10 + result) = *(_BYTE *)(v3 + v11 + result);
++result;
}
while ( v9 > (int)result );
}
v11 += v9;
v10 += v7;
}
while ( v12 != v5 );
}
}
else
{
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
int v5; // er11
int v6; // edx
int v7; // er10
int v8; // er12
int v9; // edi
__int64 v10; // rsi
int v11; // er9
int v12; // er8

result = (unsigned __int64)realloc(*(void **)(a1 + 24), *(unsigned int *)(a1 + 32));
if ( result )
{
*(_QWORD *)(a1 + 24) = result;
v3 = *(_QWORD *)(a2 + 24);
addZeroedChannels(*(unsigned __int16 *)(a2 + 40), a1);
v4 = *(_QWORD *)(a1 + 24);
v5 = calculateNumSamples(a1);
v6 = *(unsigned __int16 *)(a2 + 42);
result = v6 * (unsigned int)*(unsigned __int16 *)(a1 + 40);
v7 = (int)result / 8;
v8 = v6 * *(unsigned __int16 *)(a2 + 40);
v9 = v8 / 8;
if ( v5 > 0 )
{
result = v9;
v10 = v4 + v7 - (__int64)v9;
v11 = 0;
v12 = 0;
do
{
++v12;
if ( v8 > 7 )
{
result = 0LL;
do
{
*(_BYTE *)(v10 + result) = *(_BYTE *)(v3 + v11 + result);
++result;
}
while ( v9 > (int)result );
}
v11 += v9;
v10 += v7;
}
while ( v12 != v5 );
}
}
else
{
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

original_code:
void distributeIntoChannels(sound_t* dest, sound_t* append) {
  int i, j, numSamples, bytesPerDestSample, bytesPerAppendSample;
  void* newData = realloc(dest->rawData, dest->dataSize);
  char *destCharData, *appendCharData;
  if(!newData) {
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  appendCharData = (char*)append->rawData;
  addZeroedChannels(append->numChannels, dest);
  destCharData = (char*)dest->rawData;
  numSamples = calculateNumSamples(dest);
  bytesPerDestSample = dest->numChannels * append->bitDepth / 8;
  bytesPerAppendSample = append->numChannels * append->bitDepth / 8;
  for(i = 0; i < numSamples; i++) {
    int firstNewData = bytesPerDestSample * (i + 1) - bytesPerAppendSample;
    for(j = 0; j < bytesPerAppendSample; j++) {
      destCharData[firstNewData + j] = appendCharData[i * bytesPerAppendSample + j];
    }
  }
}

canonical_original_code:
void distributeIntoChannels(struct sound_t *dest, struct sound_t *append) {
  int i; int j; int numSamples; int bytesPerDestSample; int bytesPerAppendSample;
  void *newData = realloc(dest->rawData, dest->dataSize);
  char *destCharData; char *appendCharData;
  if(!newData) {
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  appendCharData = (char *)append->rawData;
  addZeroedChannels(append->numChannels, dest);
  destCharData = (char *)dest->rawData;
  numSamples = calculateNumSamples(dest);
  bytesPerDestSample = dest->numChannels * append->bitDepth / 8;
  bytesPerAppendSample = append->numChannels * append->bitDepth / 8;
  for(i = 0; i < numSamples; i++) {
    int firstNewData = bytesPerDestSample * (i + 1) - bytesPerAppendSample;
    for(j = 0; j < bytesPerAppendSample; j++) {
      destCharData[firstNewData + j] = appendCharData[i * bytesPerAppendSample + j];
    }
  }
}

variable_types:
append
struct sound_t *

variable_types: i int

variable_types: j int

variable_types: numSamples int

variable_types: bytesPerDestSample int

variable_types: bytesPerAppendSample int

variable_types:
newData
void *

variable_types:
destCharData
char *

variable_types:
appendCharData
char *

variable_types: firstNewData int


combineChannels

decompiled_code:
unsigned __int64 __fastcall combineChannels(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax

if ( (unsigned int)ensureSoundChannelsCombinable() == -1 )
result = printSampleRateError();
else
result = distributeIntoChannels(a1, a2);
return result;
}

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

if ( (unsigned int)ensureSoundChannelsCombinable() == -1 )
result = printSampleRateError();
else
result = func0(a1, a2);
return result;
}

original_code:
void combineChannels(sound_t* s1, sound_t* s2, fileType_t resultType) {
  if(ensureSoundChannelsCombinable(s1, s2, resultType) == -1) {
    printSampleRateError();
    return;
  }
  distributeIntoChannels(s1, s2);
}

canonical_original_code:
void combineChannels(struct sound_t *s1, struct sound_t *s2, enum fileType_t resultType) {
  if(ensureSoundChannelsCombinable(s1, s2, resultType) == -1) {
    printSampleRateError();
    return;
  }
  distributeIntoChannels(s1, s2);
}

variable_types:
resultType
enum fileType_t { CS229=0, WAVE=1 }


combineChannelsSoundArray

decompiled_code:
unsigned __int64 __fastcall combineChannelsSoundArray(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v4; // rbx
__int64 v5; // r12
unsigned __int64 result; // rax
__int64 *v7; // rbx

if ( a3 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
convertToFileType(*(unsigned int *)(a1 + 8), *v4++);
while ( v4 != (_QWORD *)v5 );
}
result = deepCopySound(a1, *a2);
if ( a3 > 1 )
{
v7 = a2 + 1;
do
result = combineChannels(a1, *v7++);
while ( v7 != &a2[(unsigned int)(a3 - 2) + 2] );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v4; // rbx
__int64 v5; // r12
unsigned __int64 result; // rax
__int64 *v7; // rbx

if ( a3 > 0 )
{
v4 = a2;
v5 = (__int64)&a2[(unsigned int)(a3 - 1) + 1];
do
convertToFileType(*(unsigned int *)(a1 + 8), *v4++);
while ( v4 != (_QWORD *)v5 );
}
result = deepCopySound(a1, *a2);
if ( a3 > 1 )
{
v7 = a2 + 1;
do
result = func1(a1, *v7++);
while ( v7 != &a2[(unsigned int)(a3 - 2) + 2] );
}
return result;
}

original_code:
void combineChannelsSoundArray(sound_t* dest, sound_t** sounds, int numSounds) {
  int i;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  deepCopySound(dest, sounds[0]);
  for(i = 1; i < numSounds; i++) {
    combineChannels(dest, sounds[i], dest->fileType);
  }
}

canonical_original_code:
void combineChannelsSoundArray(struct sound_t *dest, struct sound_t **sounds, int numSounds) {
  int i;
  for(i = 0; i < numSounds; i++) {
    convertToFileType(dest->fileType, sounds[i]);
  }
  deepCopySound(dest, sounds[0]);
  for(i = 1; i < numSounds; i++) {
    combineChannels(dest, sounds[i], dest->fileType);
  }
}

variable_types:
sounds
struct sound_t **

variable_types: numSounds int


printHelp

decompiled_code:
int __fastcall printHelp(const char *a1)
{
puts("Sndchan Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the files passed as arguments and combines the channels of");
puts("them into a single sound. The resulting sound will be the \"overlay\" of the");
puts("source sounds. \n");
puts("Defaults:");
puts("Default output is in CS229 format (see -w option to change). ");
puts("Default output is to stdout unless another file is given (with -o)");
puts("If no source files are given, tries to read file from stdin\n");
puts("Options:");
puts("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)");
puts("-h\t\tPrint this screen");
puts("-o [fileName]\tOutput file to fileName");
return puts("-w\t\tOutput in WAVE format");
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
puts("Sndchan Help:");
printf("Usage: %s file1 [file2 ...] [options]\n\n", a1);
puts("Utility:");
puts("This program reads the files passed as arguments and combines the channels of");
puts("them into a single sound. The resulting sound will be the \"overlay\" of the");
puts("source sounds. \n");
puts("Defaults:");
puts("Default output is in CS229 format (see -w option to change). ");
puts("Default output is to stdout unless another file is given (with -o)");
puts("If no source files are given, tries to read file from stdin\n");
puts("Options:");
puts("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)");
puts("-h\t\tPrint this screen");
puts("-o [fileName]\tOutput file to fileName");
return puts("-w\t\tOutput in WAVE format");
}

original_code:
void printHelp(char* cmd) {
  printf("Sndchan Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the files passed as arguments and combines the channels of\n");
  printf("them into a single sound. The resulting sound will be the \"overlay\" of the\n");
  printf("source sounds. \n\n");
  printf("Defaults:\n");
  printf("Default output is in CS229 format (see -w option to change). \n");
  printf("Default output is to stdout unless another file is given (with -o)\n");
  printf("If no source files are given, tries to read file from stdin\n\n");
  printf("Options:\n");
  printf("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)\n");
  printf("-h\t\tPrint this screen\n");
  printf("-o [fileName]\tOutput file to fileName\n");
  printf("-w\t\tOutput in WAVE format\n");
}

canonical_original_code:
void printHelp(char *cmd) {
  printf("Sndchan Help:\n");
  printf("Usage: %s file1 [file2 ...] [options]\n\n", cmd);
  printf("Utility:\n");
  printf("This program reads the files passed as arguments and combines the channels of\n");
  printf("them into a single sound. The resulting sound will be the \"overlay\" of the\n");
  printf("source sounds. \n\n");
  printf("Defaults:\n");
  printf("Default output is in CS229 format (see -w option to change). \n");
  printf("Default output is to stdout unless another file is given (with -o)\n");
  printf("If no source files are given, tries to read file from stdin\n\n");
  printf("Options:\n");
  printf("-c [n]\t\tOnly include channel n in output (1st channel = 0, etc.)\n");
  printf("-h\t\tPrint this screen\n");
  printf("-o [fileName]\tOutput file to fileName\n");
  printf("-w\t\tOutput in WAVE format\n");
}

variable_types:
cmd
char *


handleCommandLineArgs

original_code:
fileType_t handleCommandLineArgs(int argc, char** argv, char** fileNames, int capacity, int* numFilesRead, int* outputChannel, char** outputFileName) {
  int i;
  fileType_t outputType = CS229;
  *outputChannel = -1;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else if(argv[i][1] == 'c') {
        *outputChannel = strtol(argv[i+1], ((void *)0), 10);
        ++i;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

canonical_original_code:
enum fileType_t handleCommandLineArgs(int argc, char **argv, char **fileNames, int capacity, int *numFilesRead, int *outputChannel, char **outputFileName) {
  int i;
  enum fileType_t outputType = CS229;
  *outputChannel = -1;
  for(i = 1; i < argc; i++) {
    if(argv[i][0] == '-') {
      if(argv[i][1] == 'h') {
        printHelp(argv[0]);
        *numFilesRead = -1;
        return outputType;
      }
      else if(argv[i][1] == 'o') {
        *outputFileName = argv[i+1];
        ++i;
      }
      else if(argv[i][1] == 'w') {
        outputType = WAVE;
      }
      else if(argv[i][1] == 'c') {
        *outputChannel = strtol(argv[i+1], ((void *)0), 10);
        ++i;
      }
      else {
        printInvalidOptionError(argv[i][1]);
        *numFilesRead = -1;
        return outputType;
      }
    }
    else {
      fileNames[(*numFilesRead)++] = argv[i];
    }
  }
  return outputType;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
fileNames
char **

variable_types: capacity int

variable_types:
numFilesRead
int *

variable_types:
outputChannel
int *

variable_types:
outputFileName
char **

variable_types:
outputType
enum fileType_t { CS229=0, WAVE=1 }

return_type: enum fileType_t { CS229=0, WAVE=1 }


concatenateData

decompiled_code:
__int64 __fastcall concatenateData(__int64 a1, __int64 a2)
{
int v4; // er12
__int64 result; // rax
char *v6; // rsi
__int64 v7; // rdi

v4 = *(_DWORD *)(a1 + 32) + *(_DWORD *)(a2 + 32);
result = (__int64)realloc(*(void **)(a1 + 24), v4);
if ( result )
{
v6 = (char *)result;
*(_QWORD *)(a1 + 24) = result;
v7 = *(_QWORD *)(a2 + 24);
if ( *(_DWORD *)(a2 + 32) )
{
result = 0LL;
do
{
v6[(unsigned int)(*(_DWORD *)(a1 + 32) + result)] = *(_BYTE *)(v7 + result);
++result;
}
while ( *(_DWORD *)(a2 + 32) > (unsigned int)result );
}
*(_DWORD *)(a1 + 32) = v4;
}
else
{
result = printMemoryError();
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v4; // er12
__int64 result; // rax
char *v6; // rsi
__int64 v7; // rdi

v4 = *(_DWORD *)(a1 + 32) + *(_DWORD *)(a2 + 32);
result = (__int64)realloc(*(void **)(a1 + 24), v4);
if ( result )
{
v6 = (char *)result;
*(_QWORD *)(a1 + 24) = result;
v7 = *(_QWORD *)(a2 + 24);
if ( *(_DWORD *)(a2 + 32) )
{
result = 0LL;
do
{
v6[(unsigned int)(*(_DWORD *)(a1 + 32) + result)] = *(_BYTE *)(v7 + result);
++result;
}
while ( *(_DWORD *)(a2 + 32) > (unsigned int)result );
}
*(_DWORD *)(a1 + 32) = v4;
}
else
{
result = printMemoryError();
*(_DWORD *)(a1 + 36) = 3;
}
return result;
}

original_code:
void concatenateData(sound_t* dest, sound_t* append) {
  int i;
  char *destCharData, *appendCharData;
  int newDataSize = dest->dataSize + append->dataSize;
  char* newData = (char*)realloc(dest->rawData, newDataSize);
  if(!newData) {
    printMemoryError();
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  destCharData = (char*)dest->rawData;
  appendCharData = (char*)append->rawData;
  for(i = 0; i < append->dataSize; i++) {
    destCharData[dest->dataSize + i] = appendCharData[i];
  }
  dest->dataSize = newDataSize;
}

canonical_original_code:
void concatenateData(struct sound_t *dest, struct sound_t *append) {
  int i;
  char *destCharData; char *appendCharData;
  int newDataSize = dest->dataSize + append->dataSize;
  char *newData = (char*)realloc(dest->rawData, newDataSize);
  if(!newData) {
    printMemoryError();
    dest->error = ERROR_MEMORY;
    return;
  }
  dest->rawData = newData;
  destCharData = (char *)dest->rawData;
  appendCharData = (char *)append->rawData;
  for(i = 0; i < append->dataSize; i++) {
    destCharData[dest->dataSize + i] = appendCharData[i];
  }
  dest->dataSize = newDataSize;
}

variable_types: struct sound_t { unsigned long sampleRate; enum fileType_t { CS229=0, WAVE=1 } fileType; char *fileName; void *rawData; unsigned int dataSize; enum readError_t { NO_ERROR=0, ERROR_EOF=1, ERROR_READING=2, ERROR_MEMORY=3, ERROR_FILETYPE=4, ERROR_BIT_DEPTH=5, ERROR_INVALID_KEYWORD=6, ERROR_NO_VALUE=7, ERROR_SAMPLE_DATA=8, ERROR_ZERO_CHANNELS=9 } error; unsigned short numChannels; unsigned short bitDepth; } *

variable_types:
append
struct sound_t *

variable_types: i int

variable_types: newDataSize int

variable_types:
newData
char *


concatenateSounds

decompiled_code:
__int64 __fastcall concatenateSounds(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned int)ensureSoundsCanConcatenate() == -1 )
result = printSampleRateError();
else
result = concatenateData(a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( (unsigned int)ensureSoundsCanConcatenate() == -1 )
result = printSampleRateError();
else
result = func2(a1, a2);
return result;
}

original_code:
void concatenateSounds(sound_t* dest, sound_t* src, fileType_t resultType) {
  if(ensureSoundsCanConcatenate(dest, src, resultType) == -1) {
    printSampleRateError();
    return;
  }
  concatenateData(dest, src);
}

canonical_original_code:
void concatenateSounds(struct sound_t *dest, struct sound_t *src, enum fileType_t resultType) {
  if(ensureSoundsCanConcatenate(dest, src, resultType) == -1) {
    printSampleRateError();
    return;
  }
  concatenateData(dest, src);
}

variable_types:
src
struct sound_t *

variable_types:
resultType
enum fileType_t { CS229=0, WAVE=1 }