decompiled_code:
__int64 __fastcall remove_info(__int64 a1, _QWORD *a2, const void *a3, unsigned int a4)
{
__int64 v5; // rbx
size_t v6; // rbp
unsigned int v7; // edx
__int64 v8; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a3 )
return (unsigned int)-1;
v5 = *(_QWORD *)(a1 + 24);
if ( !v5 )
return (unsigned int)-1;
v6 = a4;
while ( 1 )
{
v7 = memcmp(*(const void **)v5, a3, v6);
if ( !v7 )
break;
v5 = *(_QWORD *)(v5 + 24);
if ( !v5 )
return (unsigned int)-1;
}
v8 = *(_QWORD *)(v5 + 24);
*(_QWORD *)(*(_QWORD *)(v5 + 32) + 24LL) = v8;
if ( v8 )
*(_QWORD *)(v8 + 32) = *(_QWORD *)(v5 + 32);
else
*a2 = *(_QWORD *)(v5 + 32);
--*(_DWORD *)(a1 + 8);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _QWORD *a2, const void *a3, unsigned int a4)
{
__int64 v5; // rbx
size_t v6; // rbp
unsigned int v7; // edx
__int64 v8; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a3 )
return (unsigned int)-1;
v5 = *(_QWORD *)(a1 + 24);
if ( !v5 )
return (unsigned int)-1;
v6 = a4;
while ( 1 )
{
v7 = memcmp(*(const void **)v5, a3, v6);
if ( !v7 )
break;
v5 = *(_QWORD *)(v5 + 24);
if ( !v5 )
return (unsigned int)-1;
}
v8 = *(_QWORD *)(v5 + 24);
*(_QWORD *)(*(_QWORD *)(v5 + 32) + 24LL) = v8;
if ( v8 )
*(_QWORD *)(v8 + 32) = *(_QWORD *)(v5 + 32);
else
*a2 = *(_QWORD *)(v5 + 32);
--*(_DWORD *)(a1 + 8);
return v7;
}

original_code:
int remove_info(list_head * head, list_tail ** tail, const char * addr,
                unsigned int addr_length){
  server_list * node;
  if(head == ((void *)0) || addr == ((void *)0))
    return -1;
  node = head->next;
  while(node){
    if(memcmp(node->server_addr,addr,addr_length) == 0){
      node->prev->next = node->next;
      if(node->next)
        node->next->prev = node->prev;
      else
        *tail = node->prev;
      head->alength -= 1;
      return 0;
    }
    node = node->next;
  }
  return -1;
}

canonical_original_code:
int remove_info(struct node *head, struct node **tail, char *addr, unsigned int addr_length){
  struct node *node;
  if(head == ((void *)0) || addr == ((void *)0))
    return -1;
  node = head->next;
  while(node){
    if(memcmp(node->server_addr,addr,addr_length) == 0){
      node->prev->next = node->next;
      if(node->next)
        node->next->prev = node->prev;
      else
        *tail = node->prev;
      head->alength -= 1;
      return 0;
    }
    node = node->next;
  }
  return -1;
}


repo: Greeshma/DFS

original_code:
int remove_info_ptr(list_head * head, list_tail ** tail, void *ptr){
  server_list * node;
  if(head == ((void *)0) || ptr == ((void *)0))
    return -1;
  node = head->next;
  while(node){
    if(node->data == ptr){
      node->prev->next = node->next;
      if(node->next)
        node->next->prev = node->prev;
      else
        *tail = node->prev;
      head->alength -= 1;
    }
    node = node->next;
  }
  return -1;
}

canonical_original_code:
int remove_info_ptr(struct node *head, struct node **tail, void *ptr){
  struct node *node;
  if(head == ((void *)0) || ptr == ((void *)0))
    return -1;
  node = head->next;
  while(node){
    if(node->data == ptr){
      node->prev->next = node->next;
      if(node->next)
        node->next->prev = node->prev;
      else
        *tail = node->prev;
      head->alength -= 1;
    }
    node = node->next;
  }
  return -1;
}

variable_types: struct node { char *server_addr; unsigned int alength; void *data; struct node *next; struct node *prev; } *

variable_types:
tail
struct node **

variable_types:
ptr
void *

return_type: int


original_code:
void free_list(list_head * head)
{
  if(head == ((void *)0))
    return;
  server_list * node = head->next;
  while(node){
    head->next = node->next;
    if(node->server_addr) free(node->server_addr);
    if(node->data) free(node->data);
    if(node) free(node);
    node = head->next;
  }
  head->alength = 0;
  head->next = ((void *)0);
  head->prev = ((void *)0);
}

canonical_original_code:
void free_list(struct node *head)
{
  if(head == ((void *)0))
    return;
  struct node *node = head->next;
  while(node){
    head->next = node->next;
    if(node->server_addr) free(node->server_addr);
    if(node->data) free(node->data);
    if(node) free(node);
    node = head->next;
  }
  head->alength = 0;
  head->next = ((void *)0);
  head->prev = ((void *)0);
}

return_type: void

user_defined_types: struct node { char *server_addr; unsigned int alength; void *data; struct node *next; struct node *prev; }


decompiled_code:
__int64 init_mem_serv_list()
{
if ( malloc(0x30uLL) )
return 0LL;
fwrite("\nCould not initialise memory servers list", 1uLL, 0x29uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( malloc(0x30uLL) )
return 0LL;
fwrite("\nCould not initialise memory servers list", 1uLL, 0x29uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int init_mem_serv_list(mem_serv* mem_serv_head) {
  mem_serv_head = (mem_serv*) malloc(sizeof(mem_serv));
  if(mem_serv_head == ((void *)0)) {
    fprintf(stderr, "\nCould not initialise memory servers list");
    return -1;
  }
  strcpy(mem_serv_head->ip, "");
  mem_serv_head->is_assigned = -1;
  mem_serv_head->is_synced = -1;
  mem_serv_head->count = -1;
  mem_serv_head->next = ((void *)0);
  mem_serv_head->prev = ((void *)0);
  return 0;
}

canonical_original_code:
int init_mem_serv_list(struct _mem_serv *mem_serv_head) {
  mem_serv_head = (struct _mem_serv *) malloc(sizeof(mem_serv));
  if(mem_serv_head == ((void *)0)) {
    fprintf(stderr, "\nCould not initialise memory servers list");
    return -1;
  }
  strcpy(mem_serv_head->ip, "");
  mem_serv_head->is_assigned = -1;
  mem_serv_head->is_synced = -1;
  mem_serv_head->count = -1;
  mem_serv_head->next = ((void *)0);
  mem_serv_head->prev = ((void *)0);
  return 0;
}

variable_types: struct _mem_serv { char ip[16]; int is_assigned; int is_synced; int count; struct _mem_serv *next; struct _mem_serv *prev; } *


decompiled_code:
void __fastcall free_mem_serv_list(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 4);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 4);
free(v2);
}
}

original_code:
void free_mem_serv_list(mem_serv *mem_serv_head) {
    mem_serv *temp;
    while(mem_serv_head != ((void *)0)) {
        temp = mem_serv_head;
        mem_serv_head = mem_serv_head->next;
        free(temp);
    }
    return;
}

canonical_original_code:
void free_mem_serv_list(struct _mem_serv *mem_serv_head) {
    struct _mem_serv *temp;
    while(mem_serv_head != ((void *)0)) {
        temp = mem_serv_head;
        mem_serv_head = mem_serv_head->next;
        free(temp);
    }
    return;
}

user_defined_types: struct _mem_serv { char ip[16]; int is_assigned; int is_synced; int count; struct _mem_serv *next; struct _mem_serv *prev; }


decompiled_code:
__int64 __fastcall create_mem_serv_node(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
__int64 result; // rax

v2 = (char *)malloc(0x30uLL);
if ( v2 )
{
v3 = v2;
strcpy(v2, a2);
set_is_assigned(v3, 0LL);
set_is_synced(v3, 0LL);
set_client_count(v3, 0LL);
*((_QWORD *)v3 + 5) = 0LL;
*((_QWORD *)v3 + 4) = 0LL;
result = 1LL;
}
else
{
fwrite("\nError in creating a memory server node", 1uLL, 0x27uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
char *v2; // rax
char *v3; // rbx
__int64 result; // rax

v2 = (char *)malloc(0x30uLL);
if ( v2 )
{
v3 = v2;
strcpy(v2, a2);
set_is_assigned(v3, 0LL);
set_is_synced(v3, 0LL);
set_client_count(v3, 0LL);
*((_QWORD *)v3 + 5) = 0LL;
*((_QWORD *)v3 + 4) = 0LL;
result = 1LL;
}
else
{
fwrite("\nError in creating a memory server node", 1uLL, 0x27uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int create_mem_serv_node(mem_serv *node, const char *ip) {
    node = malloc(sizeof(mem_serv));
    if(node == ((void *)0)) {
        fprintf(stderr, "\nError in creating a memory server node");
        return -1;
    }
    strcpy(node->ip, ip);
    set_is_assigned(node, 0);
    set_is_synced(node, 0);
    set_client_count(node, 0);
    node->prev = ((void *)0);
    node->next = ((void *)0);
    return 1;
}

canonical_original_code:
int create_mem_serv_node(struct _mem_serv *node, char *ip) {
    node = malloc(sizeof(mem_serv));
    if(node == ((void *)0)) {
        fprintf(stderr, "\nError in creating a memory server node");
        return -1;
    }
    strcpy(node->ip, ip);
    set_is_assigned(node, 0);
    set_is_synced(node, 0);
    set_client_count(node, 0);
    node->prev = ((void *)0);
    node->next = ((void *)0);
    return 1;
}

variable_types:
ip
char *


decompiled_code:
__int64 __fastcall mem_serv_list_append(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
char *v4; // rbx
__int64 result; // rax

v2 = a1;
fprintf(stdout, "\nIn mem_serv_list_append with ip %s", a2);
if ( a1 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 32);
}
while ( v2 );
v4 = (char *)malloc(0x30uLL);
strcpy(v4, a2);
set_is_assigned(v4, 0LL);
set_is_synced(v4, 0LL);
set_client_count(v4, 0LL);
*((_QWORD *)v4 + 4) = 0LL;
*((_QWORD *)v4 + 5) = v3;
*(_QWORD *)(v3 + 32) = v4;
result = 1LL;
}
else
{
fwrite("\nseems like the mem serv list is missing!! i cannot proceed further.\n", 1uLL, 0x45uLL, stdout);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
char *v4; // rbx
__int64 result; // rax

v2 = a1;
fprintf(stdout, "\nIn mem_serv_list_append with ip %s", a2);
if ( a1 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 32);
}
while ( v2 );
v4 = (char *)malloc(0x30uLL);
strcpy(v4, a2);
set_is_assigned(v4, 0LL);
set_is_synced(v4, 0LL);
set_client_count(v4, 0LL);
*((_QWORD *)v4 + 4) = 0LL;
*((_QWORD *)v4 + 5) = v3;
*(_QWORD *)(v3 + 32) = v4;
result = 1LL;
}
else
{
fwrite("\nseems like the mem serv list is missing!! i cannot proceed further.\n", 1uLL, 0x45uLL, stdout);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mem_serv_list_append(mem_serv *head, const char *ip) {
    fprintf(stdout, "\nIn mem_serv_list_append with ip %s", ip);
    mem_serv *curr = head;
    mem_serv *prev;
    mem_serv *new;
    if(curr != ((void *)0)){
        while(curr->next != ((void *)0)) {
            curr = curr->next;
        }
    }else{
        fprintf(stdout, "\nseems like the mem serv list is missing!! i cannot proceed further.\n");
        return -1;
    }
    new = (mem_serv *)malloc(sizeof(mem_serv));
    strcpy(new->ip, ip);
    set_is_assigned(new, 0);
    set_is_synced(new, 0);
    set_client_count(new, 0);
    new->next = ((void *)0);
    new->prev = curr;
    curr->next = new;
    return 1;
}

canonical_original_code:
int mem_serv_list_append(struct _mem_serv *head, char *ip) {
    fprintf(stdout, "\nIn mem_serv_list_append with ip %s", ip);
    struct _mem_serv *curr = head;
    struct _mem_serv *prev;
    struct _mem_serv *new;
    if(curr != ((void *)0)){
        while(curr->next != ((void *)0)) {
            curr = curr->next;
        }
    }else{
        fprintf(stdout, "\nseems like the mem serv list is missing!! i cannot proceed further.\n");
        return -1;
    }
    new = (struct _mem_serv *)malloc(sizeof(mem_serv));
    strcpy(new->ip, ip);
    set_is_assigned(new, 0);
    set_is_synced(new, 0);
    set_client_count(new, 0);
    new->next = ((void *)0);
    new->prev = curr;
    curr->next = new;
    return 1;
}


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall remove_mem_serv_node(char *s2, char *s1)
{
__int64 v2; // rbp
int v3; // eax

v2 = *((_QWORD *)s2 + 4);
v3 = strcasecmp(s1, s2);
while ( v3 )
;
*(_QWORD *)((char *)&loc_1D + 3) = v2;
*(_QWORD *)(v2 + 40) = 0LL;
free(s2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2, char *s1)
{
__int64 v2; // rbp
int v3; // eax

v2 = *((_QWORD *)s2 + 4);
v3 = strcasecmp(s1, s2);
while ( v3 )
;
*(_QWORD *)((char *)&loc_1D + 3) = v2;
*(_QWORD *)(v2 + 40) = 0LL;
free(s2);
return 1LL;
}

original_code:
int remove_mem_serv_node(mem_serv *head, const char *ip) {
  mem_serv *curr = head;
  mem_serv *next = curr->next;
  mem_serv *prev;
  while (curr != ((void *)0)) {
    if(strcasecmp(ip, curr->ip) == 0) {
      prev->next = next;
      next->prev = prev;
      free(curr);
      return 1;
    }
  }
  fprintf(stderr, "\nError: Memory server with ip %s not found", ip);
  return -1;
}

canonical_original_code:
int remove_mem_serv_node(struct _mem_serv *head, char *ip) {
  struct _mem_serv *curr = head;
  struct _mem_serv *next = curr->next;
  struct _mem_serv *prev;
  while (curr != ((void *)0)) {
    if(strcasecmp(ip, curr->ip) == 0) {
      prev->next = next;
      next->prev = prev;
      free(curr);
      return 1;
    }
  }
  fprintf(stderr, "\nError: Memory server with ip %s not found", ip);
  return -1;
}


decompiled_code:
__int64 __fastcall my_check_access(__int64 a1, __int64 a2, _DWORD *a3)
{
*a3 = 0;
return 43981LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _DWORD *a3)
{
*a3 = 0;
return 43981LL;
}

original_code:
int my_check_access(COMMCTX * ctx, const user_info * u, int * status, const char * path, const char * path1, int op){
  *status = 0;
  return 0xABCD;
}

canonical_original_code:
int my_check_access(struct _commctx *ctx, struct _user_info_ *u, int *status, char *path, char *path1, int op){
  *status = 0;
  return 0xABCD;
}

variable_types: struct _commctx { struct _sock_ctx { int sock; } *sock_ctx; void *sec_ctx; int (*receive)(struct _commctx *, char *, int); int (*send)(struct _commctx *, char *, int); } *

variable_types: struct _user_info_ { unsigned int uid; unsigned int gid; unsigned int num_sgids; unsigned int sgids[32]; } *

variable_types:
status
int *

variable_types:
path
char *

variable_types: op int

user_defined_types: struct _commctx { struct _sock_ctx *sock_ctx; void *sec_ctx; int (*receive)(struct _commctx *, char *, int); int (*send)(struct _commctx *, char *, int); }


decompiled_code:
void my_goodbye()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void my_goodbye(COMMCTX* ctx) {
  return;
}

canonical_original_code:
void my_goodbye(struct _commctx *ctx) {
  return;
}


decompiled_code:
__int64 my_parse_arguments()
{
return 43981LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 43981LL;
}

original_code:
int my_parse_arguments(char * argstr, int argc, char** argv){
  return 0xABCD;
}

canonical_original_code:
int my_parse_arguments(char *argstr, int argc, char **argv){
  return 0xABCD;
}

variable_types:
argstr
char *

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall my_receive(__int64 a1, _DWORD *a2)
{
void *v2; // rsp
unsigned int v3; // er13
__int64 result; // rax
_BYTE v5[32]; // [rsp+0h] [rbp-20h] BYREF

if ( (int)phy_receive(a1, a2, (unsigned int)header_size) < 0 )
return 0xFFFFFFFFLL;
v2 = alloca(header_size);
memcpy(v5, a2, header_size);
decap_corefs_header(v5, a2);
v3 = a2[3];
if ( (int)phy_receive(a1, (char *)a2 + header_size, v3) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)header_size + v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2)
{
void *v2; // rsp
unsigned int v3; // er13
__int64 result; // rax
_BYTE v5[32]; // [rsp+0h] [rbp-20h] BYREF

if ( (int)phy_receive(a1, a2, (unsigned int)header_size) < 0 )
return 0xFFFFFFFFLL;
v2 = alloca(header_size);
memcpy(v5, a2, header_size);
decap_corefs_header(v5, a2);
v3 = a2[3];
if ( (int)phy_receive(a1, (char *)a2 + header_size, v3) < 0 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)header_size + v3;
return result;
}

original_code:
int my_receive(COMMCTX* ctx, char* buf, int len) {
  corefs_header *header=(corefs_header*)buf;
  int psize;
  if (phy_receive(ctx, buf, header_size) < 0) {
    return -1;
  }
  char temp_buf[header_size];
  memcpy(temp_buf,buf,header_size);
  decap_corefs_header(temp_buf, (corefs_packet*)buf);
   psize=header->payload_size;
  if (phy_receive(ctx, buf+header_size, psize) < 0) {
    return -1;
  }
  return header_size + psize;
}

canonical_original_code:
int my_receive(struct _commctx *ctx, char *buf, int len) {
  struct _corefs_header *header = (corefs_header*)buf;
  int psize;
  if (phy_receive(ctx, buf, header_size) < 0) {
    return -1;
  }
  char temp_buf[-1];
  memcpy(temp_buf,buf,header_size);
  decap_corefs_header(temp_buf, (struct _corefs_packet *)buf);
   psize=header->payload_size;
  if (phy_receive(ctx, buf+header_size, psize) < 0) {
    return -1;
  }
  return header_size + psize;
}

variable_types:
buf
char *

variable_types: len int

variable_types: struct _corefs_header { unsigned int magic; unsigned int type; unsigned int sequence; unsigned int payload_size; } *

variable_types: psize int

user_defined_types: struct _corefs_packet { struct _corefs_header header; union _corefs_payload payload; }

user_defined_types: union _corefs_payload { struct _corefs_request request; struct _corefs_response response; }

user_defined_types: struct _corefs_request { unsigned int type; struct _user_info_ user_ids; union _corefs_operations op; }

user_defined_types: struct _corefs_response { unsigned int type; unsigned int more_offset; union _corefs_response_op rop; }

user_defined_types: struct _user_info_ { unsigned int uid; unsigned int gid; unsigned int num_sgids; unsigned int sgids[32]; }

user_defined_types: union _corefs_operations { struct _corefs_fileop fileop; struct _corefs_simple simple; struct _corefs_xattr xattr; char raw[1]; }

user_defined_types: union _corefs_response_op { struct _corefs_status status; struct _corefs_attr attr; char raw[1]; }

user_defined_types: struct _corefs_fileop { unsigned int type; unsigned int offset; unsigned int size; unsigned int pathlen; char path[4096]; }

user_defined_types: struct _corefs_simple { unsigned int type; unsigned int offset; unsigned int mode1; unsigned int path1len; unsigned int path2len; char path1[4096]; char path2[4096]; }

user_defined_types: struct _corefs_xattr { unsigned int type; int flags; unsigned int sizeofvalue; unsigned int pathlen; unsigned int namelen; char params[1]; }

user_defined_types: struct _corefs_status { unsigned int bits; }

user_defined_types: struct _corefs_attr { unsigned int mode; unsigned int uid; unsigned int gid; unsigned int size; unsigned int mtime; unsigned int atime; unsigned int ctime; unsigned int nlinks; }


decompiled_code:
__int64 my_send()
{
return phy_send();
}

canonical_decompiled_code:
__int64 func5()
{
return phy_send();
}

original_code:
int my_send(COMMCTX* ctx, char* buf, int len) {
 return phy_send(ctx, buf, len);
}

canonical_original_code:
int my_send(struct _commctx *ctx, char *buf, int len) {
 return phy_send(ctx, buf, len);
}


setup

decompiled_code:
__int64 __fastcall setup(__int64 a1)
{
*(_QWORD *)(a1 + 16) = my_receive;
*(_QWORD *)(a1 + 24) = my_send;
return 43981LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
*(_QWORD *)(a1 + 16) = my_receive;
*(_QWORD *)(a1 + 24) = my_send;
return 43981LL;
}

original_code:
int setup(COMMCTX* ctx) {
  ctx->receive = my_receive;
  ctx->send = my_send;
  return 0xABCD;
}

canonical_original_code:
int setup(struct _commctx *ctx) {
  ctx->receive = my_receive;
  ctx->send = my_send;
  return 0xABCD;
}


decompiled_code:
__int64 __fastcall server_hello(__int64 a1, __int64 a2, __int64 a3)
{
return setup(a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
return func6(a3);
}

original_code:
int server_hello(char * client, char * server, COMMCTX * ctx) {
  return setup(ctx);
}

canonical_original_code:
int server_hello(char *client, char *server, struct _commctx *ctx) {
  return setup(ctx);
}

variable_types:
client
char *

variable_types:
server
char *


decompiled_code:
__int64 __fastcall client_hello(__int64 a1, __int64 a2, __int64 a3)
{
return setup(a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
return func6(a3);
}

original_code:
int client_hello(char * client, char * server, COMMCTX * ctx){
  return setup(ctx);
}

canonical_original_code:
int client_hello(char *client, char *server, struct _commctx *ctx){
  return setup(ctx);
}


decompiled_code:
__int64 __fastcall up_client_init(_QWORD *a1)
{
a1[26] = client_hello;
a1[28] = my_goodbye;
a1[25] = my_parse_arguments;
a1[27] = my_get_user_info;
return 43981LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
a1[26] = client_hello;
a1[28] = my_goodbye;
a1[25] = my_parse_arguments;
a1[27] = my_get_user_info;
return 43981LL;
}

original_code:
int up_client_init(corefs_client_operations * op){
  op->up_new_server = client_hello;
  op->up_eof_connection = my_goodbye;
  op->up_parse_arguments = my_parse_arguments;
  op->up_get_user_info = my_get_user_info;
  return 0xABCD;
}

canonical_original_code:
int up_client_init(struct _corefs_client_ops *op){
  op->up_new_server = client_hello;
  op->up_eof_connection = my_goodbye;
  op->up_parse_arguments = my_parse_arguments;
  op->up_get_user_info = my_get_user_info;
  return 0xABCD;
}

variable_types: struct _corefs_client_ops { int (*open)(char *, struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *); int (*release)(char *, struct fuse_file_info *); int (*read)(char *, char *, unsigned long, long, struct fuse_file_info *); int (*readdir)(char *, void *, int (*)(void *buf, char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stbuf, long off), long, struct fuse_file_info *); int (*getattr)(char *, struct stat *); int (*write)(char *, char *, unsigned long, long, struct fuse_file_info *); int (*mknod)(char *, unsigned int, unsigned long); int (*truncate)(char *, long); int (*unlink)(char *); int (*mkdir)(char *, unsigned int); int (*rmdir)(char *); int (*rename)(char *, char *); int (*link)(char *, char *); int (*symlink)(char *, char *); int (*readlink)(char *, char *, unsigned long); int (*chmod)(char *, unsigned int); int (*chown)(char *, unsigned int, unsigned int); int (*utime)(char *, struct utimbuf { long actime; long modtime; } *); int (*flush)(char *, struct fuse_file_info *); int (*access)(char *, int); void (*destroy)(void *); int (*setxattr)(char *, char *, char *, unsigned long, int); int (*getxattr)(char *, char *, char *, unsigned long); int (*listxattr)(char *, char *, unsigned long); int (*removexattr)(char *, char *); int (*up_parse_arguments)(char *argstr, int argc, char **argv); int (*up_new_server)(char *client, char *server, struct _commctx { struct _sock_ctx { int sock; } *sock_ctx; void *sec_ctx; int (*receive)(struct _commctx *, char *, int); int (*send)(struct _commctx *, char *, int); } *ctx); void (*up_get_user_info)(struct _user_info_ { unsigned int uid; unsigned int gid; unsigned int num_sgids; unsigned int sgids[32]; } *u, char *path, char *new_path); void (*up_eof_connection)(struct _commctx *ctx); } *

user_defined_types: struct _corefs_client_ops { int (*open)(char *, struct fuse_file_info *); int (*release)(char *, struct fuse_file_info *); int (*read)(char *, char *, unsigned long, long, struct fuse_file_info *); int (*readdir)(char *, void *, int (*)(void *buf, char *name, struct stat *stbuf, long off), long, struct fuse_file_info *); int (*getattr)(char *, struct stat *); int (*write)(char *, char *, unsigned long, long, struct fuse_file_info *); int (*mknod)(char *, unsigned int, unsigned long); int (*truncate)(char *, long); int (*unlink)(char *); int (*mkdir)(char *, unsigned int); int (*rmdir)(char *); int (*rename)(char *, char *); int (*link)(char *, char *); int (*symlink)(char *, char *); int (*readlink)(char *, char *, unsigned long); int (*chmod)(char *, unsigned int); int (*chown)(char *, unsigned int, unsigned int); int (*utime)(char *, struct utimbuf *); int (*flush)(char *, struct fuse_file_info *); int (*access)(char *, int); void (*destroy)(void *); int (*setxattr)(char *, char *, char *, unsigned long, int); int (*getxattr)(char *, char *, char *, unsigned long); int (*listxattr)(char *, char *, unsigned long); int (*removexattr)(char *, char *); int (*up_parse_arguments)(char *argstr, int argc, char **argv); int (*up_new_server)(char *client, char *server, struct _commctx *ctx); void (*up_get_user_info)(struct _user_info_ *u, char *path, char *new_path); void (*up_eof_connection)(struct _commctx *ctx); }

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


decompiled_code:
__int64 __fastcall up_server_init(_QWORD *a1)
{
a1[24] = server_hello;
a1[25] = my_goodbye;
a1[23] = my_parse_arguments;
a1[26] = my_check_access;
return 43981LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
a1[24] = server_hello;
a1[25] = my_goodbye;
a1[23] = my_parse_arguments;
a1[26] = my_check_access;
return 43981LL;
}

original_code:
int up_server_init(corefs_server_operations * op){
  op->up_new_client = server_hello;
  op->up_eof_connection = my_goodbye;
  op->up_parse_arguments = my_parse_arguments;
  op->up_check_access = my_check_access;
  return 0xABCD;
}

canonical_original_code:
int up_server_init(struct _corefs_server_ops *op){
  op->up_new_client = server_hello;
  op->up_eof_connection = my_goodbye;
  op->up_parse_arguments = my_parse_arguments;
  op->up_check_access = my_check_access;
  return 0xABCD;
}

variable_types: struct _corefs_server_ops { int (*handle_read)(struct _commctx { struct _sock_ctx { int sock; } *sock_ctx; void *sec_ctx; int (*receive)(struct _commctx *, char *, int); int (*send)(struct _commctx *, char *, int); } *ctx, struct _corefs_packet { struct _corefs_header { unsigned int magic; unsigned int type; unsigned int sequence; unsigned int payload_size; } header; union _corefs_payload { struct _corefs_request { unsigned int type; struct _user_info_ { unsigned int uid; unsigned int gid; unsigned int num_sgids; unsigned int sgids[32]; } user_ids; union _corefs_operations { struct _corefs_fileop { unsigned int type; unsigned int offset; unsigned int size; unsigned int pathlen; char path[4096]; } fileop; struct _corefs_simple { unsigned int type; unsigned int offset; unsigned int mode1; unsigned int path1len; unsigned int path2len; char path1[4096]; char path2[4096]; } simple; struct _corefs_xattr { unsigned int type; int flags; unsigned int sizeofvalue; unsigned int pathlen; unsigned int namelen; char params[1]; } xattr; char raw[1]; } op; } request; struct _corefs_response { unsigned int type; unsigned int more_offset; union _corefs_response_op { struct _corefs_status { unsigned int bits; } status; struct _corefs_attr { unsigned int mode; unsigned int uid; unsigned int gid; unsigned int size; unsigned int mtime; unsigned int atime; unsigned int ctime; unsigned int nlinks; } attr; char raw[1]; } rop; } response; } payload; } *cmd); int (*handle_write)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_setxattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_getxattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_listxattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_removexattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_readdir)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_getattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_readlink)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*open)(char *, int flags); int (*release)(char *, int flags); int (*mknod)(char *, unsigned int, unsigned long); int (*truncate)(char *, long); int (*unlink)(char *); int (*mkdir)(char *, unsigned int); int (*rmdir)(char *); int (*rename)(char *, char *); int (*link)(char *, char *); int (*symlink)(char *, char *); int (*chmod)(char *, unsigned int); int (*chown)(char *, unsigned int, unsigned int); int (*utime)(char *, struct utimbuf { long actime; long modtime; } *); int (*access)(char *, int); int (*up_parse_arguments)(char *argstr, int argc, char **argv); int (*up_new_client)(char *client, char *server, struct _commctx *ctx); void (*up_eof_connection)(struct _commctx *ctx); int (*up_check_access)(struct _commctx *ctx, struct _user_info_ *u, int *status, char *path1, char *path2, int op); } *

user_defined_types: struct _corefs_server_ops { int (*handle_read)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_write)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_setxattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_getxattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_listxattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_removexattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_readdir)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_getattr)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*handle_readlink)(struct _commctx *ctx, struct _corefs_packet *cmd); int (*open)(char *, int flags); int (*release)(char *, int flags); int (*mknod)(char *, unsigned int, unsigned long); int (*truncate)(char *, long); int (*unlink)(char *); int (*mkdir)(char *, unsigned int); int (*rmdir)(char *); int (*rename)(char *, char *); int (*link)(char *, char *); int (*symlink)(char *, char *); int (*chmod)(char *, unsigned int); int (*chown)(char *, unsigned int, unsigned int); int (*utime)(char *, struct utimbuf *); int (*access)(char *, int); int (*up_parse_arguments)(char *argstr, int argc, char **argv); int (*up_new_client)(char *client, char *server, struct _commctx *ctx); void (*up_eof_connection)(struct _commctx *ctx); int (*up_check_access)(struct _commctx *ctx, struct _user_info_ *u, int *status, char *path1, char *path2, int op); }


decompiled_code:
int __fastcall get_mem_serv_ip(const char *a1)
{
printf("\nUsing the load balancer to get ip of the memory server");
get_best_mem_serv_ip(a1);
return printf("\nReturning the ip address of memory server %s", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
printf("\nUsing the load balancer to get ip of the memory server");
get_best_mem_serv_ip(a1);
return printf("\nReturning the ip address of memory server %s", a1);
}

original_code:
void get_mem_serv_ip(char *ip) {
    printf("\nUsing the load balancer to get ip of the memory server");
    get_best_mem_serv_ip(ip);
    printf("\nReturning the ip address of memory server %s", ip);
    return;
}

variable_types:
ip
char *


decompiled_code:
char *__fastcall init_client(char *dest)
{
__int64 v1; // rbx
unsigned int v2; // eax
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

printf("\nInitialising client");
fwrite("\nObtaining mem server ip...\n", 1uLL, 0x1CuLL, stdout);
get_mem_serv_ip(v4);
fprintf(stdout, "Obtained mem server : %s\n", v4);
fprintf(stdout, "Requesting for mem-server with ip: %s\n", v4);
v1 = get_mem_serv_by_ip(v4);
fprintf(stdout, "Received a mem_server count :%d\n", *(unsigned int *)(v1 + 24));
inc_client_count(v1);
v2 = get_client_count(v1);
printf("\nClient count of memory server %s is %d", v4, v2);
return strcpy(dest, v4);
}

canonical_decompiled_code:
char *__fastcall func3(char *dest)
{
__int64 v1; // rbx
unsigned int v2; // eax
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

printf("\nInitialising client");
fwrite("\nObtaining mem server ip...\n", 1uLL, 0x1CuLL, stdout);
func2(v4);
fprintf(stdout, "Obtained mem server : %s\n", v4);
fprintf(stdout, "Requesting for mem-server with ip: %s\n", v4);
v1 = get_mem_serv_by_ip(v4);
fprintf(stdout, "Received a mem_server count :%d\n", *(unsigned int *)(v1 + 24));
inc_client_count(v1);
v2 = get_client_count(v1);
printf("\nClient count of memory server %s is %d", v4, v2);
return strcpy(dest, v4);
}

original_code:
void init_client(char *resp) {
    printf("\nInitialising client");
    char ip[16 + 1];
    fprintf(stdout, "\nObtaining mem server ip...\n");
    get_mem_serv_ip(ip);
    fprintf(stdout, "Obtained mem server : %s\n", ip);
    mem_serv *curr_mem_serv;
    fprintf(stdout, "Requesting for mem-server with ip: %s\n", ip);
    curr_mem_serv = get_mem_serv_by_ip(ip);
    fprintf(stdout, "Received a mem_server count :%d\n", curr_mem_serv->count);
    inc_client_count(curr_mem_serv);
    printf("\nClient count of memory server %s is %d", ip, get_client_count(curr_mem_serv));
    strcpy(resp, ip);
    return;
}

canonical_original_code:
void init_client(char *resp) {
    printf("\nInitialising client");
    char ip[-1];
    fprintf(stdout, "\nObtaining mem server ip...\n");
    get_mem_serv_ip(ip);
    fprintf(stdout, "Obtained mem server : %s\n", ip);
    struct _mem_serv *curr_mem_serv;
    fprintf(stdout, "Requesting for mem-server with ip: %s\n", ip);
    curr_mem_serv = get_mem_serv_by_ip(ip);
    fprintf(stdout, "Received a mem_server count :%d\n", curr_mem_serv->count);
    inc_client_count(curr_mem_serv);
    printf("\nClient count of memory server %s is %d", ip, get_client_count(curr_mem_serv));
    strcpy(resp, ip);
    return;
}

variable_types:
resp
char *

variable_types:
ip
char [-1]

variable_types: struct _mem_serv { char ip[16]; int is_assigned; int is_synced; int count; struct _mem_serv *next; struct _mem_serv *prev; } *


decompiled_code:
int __fastcall close_client(char *a1, const char *a2)
{
__int64 v2; // rbp
unsigned int v3; // eax

fprintf(stdout, "Initiated connection closing for %s\n", a2);
v2 = get_mem_serv_by_ip(a2);
fprintf(stdout, "Found mem server allocated for %s with count %d\n", a2, *(unsigned int *)(v2 + 24));
dec_client_count(v2);
v3 = get_client_count(v2);
printf("\nCLosing client. Ip address of the attached server: %s and number of clients attached is %d ", a2, v3);
strcpy(a1, "\nBye bye!! ^_^\n");
return puts("\n____________________________________________________________________________");
}

canonical_decompiled_code:
int __fastcall func5(char *a1, const char *a2)
{
__int64 v2; // rbp
unsigned int v3; // eax

fprintf(stdout, "Initiated connection closing for %s\n", a2);
v2 = get_mem_serv_by_ip(a2);
fprintf(stdout, "Found mem server allocated for %s with count %d\n", a2, *(unsigned int *)(v2 + 24));
dec_client_count(v2);
v3 = get_client_count(v2);
printf("\nCLosing client. Ip address of the attached server: %s and number of clients attached is %d ", a2, v3);
strcpy(a1, "\nBye bye!! ^_^\n");
return puts("\n____________________________________________________________________________");
}

original_code:
void close_client(char *resp, char *ip) {
    mem_serv *curr_mem_serv;
    fprintf(stdout, "Initiated connection closing for %s\n", ip);
    curr_mem_serv = get_mem_serv_by_ip(ip);
    fprintf(stdout, "Found mem server allocated for %s with count %d\n", ip, curr_mem_serv->count);
    dec_client_count(curr_mem_serv);
    printf("\nCLosing client. Ip address of the attached server: %s and number of clients attached is %d ", ip, get_client_count(curr_mem_serv));
    strcpy(resp, "\nBye bye!! ^_^\n");
    printf("\n____________________________________________________________________________\n");
    return;
}

canonical_original_code:
void close_client(char *resp, char *ip) {
    struct _mem_serv *curr_mem_serv;
    fprintf(stdout, "Initiated connection closing for %s\n", ip);
    curr_mem_serv = get_mem_serv_by_ip(ip);
    fprintf(stdout, "Found mem server allocated for %s with count %d\n", ip, curr_mem_serv->count);
    dec_client_count(curr_mem_serv);
    printf("\nCLosing client. Ip address of the attached server: %s and number of clients attached is %d ", ip, get_client_count(curr_mem_serv));
    strcpy(resp, "\nBye bye!! ^_^\n");
    printf("\n____________________________________________________________________________\n");
    return;
}

user_defined_types: struct _mem_serv { char ip[16]; int is_assigned; int is_synced; int count; struct _mem_serv *next; struct _mem_serv *prev; }


decompiled_code:
unsigned int __fastcall process_command(char *dest, __int64 a2)
{
__int64 v2; // rbp
const char *v3; // rbx
char nptr[25]; // [rsp+Fh] [rbp-19h] BYREF

nptr[0] = *(_BYTE *)a2;
v2 = (unsigned int)atoi(nptr);
v3 = (const char *)(a2 + 1);
printf("\nProcess command function: cmd: %d, ip: %s", v2, (const char *)(a2 + 1));
switch ( (_DWORD)v2 )
{
case 1:
return sync_mem_serv(dest, v3);
case 2:
return close_client(dest, v3);
case 0:
return (unsigned int)init_client(dest);
}
strcpy(dest, "Error: Unknown command");
return fprintf(stderr, "Unknown command recieved: %d\n", (unsigned int)v2);
}

canonical_decompiled_code:
unsigned int __fastcall func6(char *dest, __int64 a2)
{
__int64 v2; // rbp
const char *v3; // rbx
char nptr[25]; // [rsp+Fh] [rbp-19h] BYREF

nptr[0] = *(_BYTE *)a2;
v2 = (unsigned int)atoi(nptr);
v3 = (const char *)(a2 + 1);
printf("\nProcess command function: cmd: %d, ip: %s", v2, (const char *)(a2 + 1));
switch ( (_DWORD)v2 )
{
case 1:
return func4(dest, v3);
case 2:
return func5(dest, v3);
case 0:
return (unsigned int)func3(dest);
}
strcpy(dest, "Error: Unknown command");
return fprintf(stderr, "Unknown command recieved: %d\n", (unsigned int)v2);
}

original_code:
void process_command(char *resp, char *req) {
    char ch = req[0];
    int cmd = atoi(&ch);
    char *ip = req+1;
    printf("\nProcess command function: cmd: %d, ip: %s", cmd, ip);
    switch (cmd) {
        case 0:
            init_client(resp);
            break;
        case 1:
            sync_mem_serv(resp, ip);
            break;
        case 2:
            close_client(resp, ip);
            break;
        default:
            strcpy(resp, "Error: Unknown command");
            fprintf(stderr, "Unknown command recieved: %d\n", cmd);
    }
}

variable_types:
req
char *

variable_types: ch char

variable_types: cmd int


decompiled_code:
int __fastcall handle_client(void *a1)
{
int v1; // ebp
size_t v2; // rax
char v4[100000]; // [rsp+0h] [rbp-30D58h] BYREF
char s[100024]; // [rsp+186A0h] [rbp-186B8h] BYREF

v1 = *(_DWORD *)a1;
printf("\nClient accepted. Now to handle the client request and respond. ");
memset(v4, 0, 0x400uLL);
v4[1024] = 0;
read(v1, v4, 0x1869FuLL);
printf("\nReceived request: %s\n", v4);
memset(s, 0, 0x186A0uLL);
process_command(s, (__int64)v4);
v2 = strlen(s);
write(v1, s, v2);
printf("\nWriting response: %s", s);
return close(v1);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
int v1; // ebp
size_t v2; // rax
char v4[100000]; // [rsp+0h] [rbp-30D58h] BYREF
char s[100024]; // [rsp+186A0h] [rbp-186B8h] BYREF

v1 = *(_DWORD *)a1;
printf("\nClient accepted. Now to handle the client request and respond. ");
memset(v4, 0, 0x400uLL);
v4[1024] = 0;
read(v1, v4, 0x1869FuLL);
printf("\nReceived request: %s\n", v4);
memset(s, 0, 0x186A0uLL);
func6(s, (__int64)v4);
v2 = strlen(s);
write(v1, s, v2);
printf("\nWriting response: %s", s);
return close(v1);
}

original_code:
void *handle_client(void *arg)
{
  char sendBuff[100000];
  char recvBuff[100000];
  time_t ticks;
  int n = 0;
  int connfd;
  connfd = *((int *) arg);
  printf("\nClient accepted. Now to handle the client request and respond. ");
  bzero(recvBuff, 1025);
  n = read(connfd, recvBuff, sizeof(recvBuff)-1);
  printf("\nReceived request: %s\n", recvBuff, n);
  memset(sendBuff, 0, sizeof(sendBuff));
  process_command(sendBuff, recvBuff);
  n = write(connfd, sendBuff, strlen(sendBuff));
  printf("\nWriting response: %s", sendBuff);
  close(connfd);
}

canonical_original_code:
void *handle_client(void *arg)
{
  char sendBuff[100000];
  char recvBuff[100000];
  long ticks;
  int n = 0;
  int connfd;
  connfd = *((int *) arg);
  printf("\nClient accepted. Now to handle the client request and respond. ");
  bzero(recvBuff, 1025);
  n = read(connfd, recvBuff, sizeof(recvBuff)-1);
  printf("\nReceived request: %s\n", recvBuff, n);
  memset(sendBuff, 0, sizeof(sendBuff));
  process_command(sendBuff, recvBuff);
  n = write(connfd, sendBuff, strlen(sendBuff));
  printf("\nWriting response: %s", sendBuff);
  close(connfd);
}

variable_types:
arg
void *

variable_types:
sendBuff
char [100000]

variable_types:
recvBuff
char [100000]

variable_types: ticks long

variable_types: n int

variable_types: connfd int

return_type: void *


main

canonical_name: main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF
int arg[3]; // [rsp+2Ch] [rbp-Ch] BYREF

arg[0] = 0;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
port = atoi(*(const char **)&argc);
}
if ( (int)init_mem_serv(*(_QWORD *)&argc, argv, envp) >= 0 )
{
printf("\nCreating a socket for listening to clients on port %d ", (unsigned int)port);
v3 = socket(2, 1, 0);
*(_QWORD *)&addr.sa_data[6] = 0x3030303030303030LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(port);
bind(v3, &addr, 0x10u);
listen(v3, 10);
printf("\nListening on port %d", (unsigned int)port);
while ( 1 )
{
arg[0] = accept(v3, 0LL, 0LL);
puts("\nAccepted client. Spawning a new thread for the client... ");
pthread_create(&newthread, 0LL, (void *(*)(void *))handle_client, arg);
sleep(1u);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF
int arg[3]; // [rsp+2Ch] [rbp-Ch] BYREF

arg[0] = 0;
if ( argc > 1 )
{
*(_QWORD *)&argc = argv[1];
port = atoi(*(const char **)&argc);
}
if ( (int)init_mem_serv(*(_QWORD *)&argc, argv, envp) >= 0 )
{
printf("\nCreating a socket for listening to clients on port %d ", (unsigned int)port);
v3 = socket(2, 1, 0);
*(_QWORD *)&addr.sa_data[6] = 0x3030303030303030LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = func0(0);
*(_WORD *)addr.sa_data = func1(port);
bind(v3, &addr, 0x10u);
listen(v3, 10);
printf("\nListening on port %d", (unsigned int)port);
while ( 1 )
{
arg[0] = accept(v3, 0LL, 0LL);
puts("\nAccepted client. Spawning a new thread for the client... ");
pthread_create(&newthread, 0LL, (void *(*)(void *))handle_client, arg);
sleep(1u);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int listenfd = 0, connfd = 0;
  struct sockaddr_in serv_addr;
  pthread_t thread;
  if(argc > 1)
    port = atoi(argv[1]);
  if(init_mem_serv() < 0 ) {
    return 0;
  }
  printf("\nCreating a socket for listening to clients on port %d ", port);
  listenfd = socket(2, SOCK_STREAM, 0);
  memset(&serv_addr, '0', sizeof(serv_addr));
  serv_addr.sin_family = 2;
  serv_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  serv_addr.sin_port = htons(port);
  bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
  listen(listenfd, 10);
  printf("\nListening on port %d", port);
  while(1)
  {
    connfd = accept(listenfd, (struct sockaddr*)((void *)0), ((void *)0));
    printf("\nAccepted client. Spawning a new thread for the client... \n");
    pthread_create(&thread, ((void *)0), handle_client, (void *)&connfd);
    sleep(1);
   }
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int listenfd = 0; int connfd = 0;
  struct sockaddr_in serv_addr;
  unsigned long thread;
  if(argc > 1)
    port = atoi(argv[1]);
  if(init_mem_serv() < 0 ) {
    return 0;
  }
  printf("\nCreating a socket for listening to clients on port %d ", port);
  listenfd = socket(2, SOCK_STREAM, 0);
  memset(&serv_addr, '0', sizeof(serv_addr));
  serv_addr.sin_family = 2;
  serv_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  serv_addr.sin_port = htons(port);
  bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  listen(listenfd, 10);
  printf("\nListening on port %d", port);
  while(1)
  {
    connfd = accept(listenfd, (struct sockaddr *)((void *)0), ((void *)0));
    printf("\nAccepted client. Spawning a new thread for the client... \n");
    pthread_create(&thread, ((void *)0), handle_client, (void *)&connfd);
    sleep(1);
   }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: listenfd int

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

variable_types:
thread
unsigned long

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

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


decompiled_code:
void __fastcall parse_response(int a1, const char *a2)
{
char *v2; // rbx
int v3; // eax
char v4; // [rsp+Fh] [rbp-186B9h]
char dest[100024]; // [rsp+10h] [rbp-186B8h] BYREF

switch ( a1 )
{
case 1:
printf("\n %s \n", a2);
is_synced = 1;
break;
case 2:
if ( !is_synced )
{
printf("\nThe data has been changed locally. Are you sure you don't want to sync the server? (Y/N) ");
__isoc99_scanf();
printf("\nReceived char %c \n", (unsigned int)v4);
v3 = tolower(v4);
if ( v3 == 110 )
{
printf("\nReceived no");
send_command(1LL);
}
else if ( v3 != 121 )
{
fwrite("\nInvalid input", 1uLL, 0xEuLL, stderr);
}
}
printf("\nUnmounting the file system from %s", (const char *)mount_path);
sprintf(0LL, "fusermount -u %s", (const char *)mount_path);
system(0LL);
break;
case 0:
is_synced = 0;
mem_server_ip = 0;
strcpy(dest, a2);
printf("\n\nEnter the path to mount the server partition: ");
mount_path = (__int64)malloc(0x1000uLL);
v2 = (char *)malloc(0x1000uLL);
__isoc99_scanf();
printf("\nMounting the file system from %s on %s", dest, (const char *)mount_path);
sprintf(v2, "corefs/bin/dclient -S %s %s", dest, (const char *)mount_path);
system(v2);
strcpy(&mem_server_ip, dest);
break;
}
}

canonical_decompiled_code:
void __fastcall func8(int a1, const char *a2)
{
char *v2; // rbx
int v3; // eax
char v4; // [rsp+Fh] [rbp-186B9h]
char dest[100024]; // [rsp+10h] [rbp-186B8h] BYREF

switch ( a1 )
{
case 1:
printf("\n %s \n", a2);
is_synced = 1;
break;
case 2:
if ( !is_synced )
{
printf("\nThe data has been changed locally. Are you sure you don't want to sync the server? (Y/N) ");
__isoc99_scanf();
printf("\nReceived char %c \n", (unsigned int)v4);
v3 = tolower(v4);
if ( v3 == 110 )
{
printf("\nReceived no");
func9(1LL);
}
else if ( v3 != 121 )
{
fwrite("\nInvalid input", 1uLL, 0xEuLL, stderr);
}
}
printf("\nUnmounting the file system from %s", (const char *)mount_path);
sprintf(0LL, "fusermount -u %s", (const char *)mount_path);
system(0LL);
break;
case 0:
is_synced = 0;
mem_server_ip = 0;
strcpy(dest, a2);
printf("\n\nEnter the path to mount the server partition: ");
mount_path = (__int64)malloc(0x1000uLL);
v2 = (char *)malloc(0x1000uLL);
__isoc99_scanf();
printf("\nMounting the file system from %s on %s", dest, (const char *)mount_path);
sprintf(v2, "corefs/bin/dclient -S %s %s", dest, (const char *)mount_path);
system(v2);
strcpy(&mem_server_ip, dest);
break;
}
}

original_code:
int parse_response(int cmd, char *resp) {
  char ip[100000], *buf, ch;
  switch(cmd) {
    case 0:
      is_synced = 0;
      strcpy(mem_server_ip, "");
      strcpy(ip, resp);
      printf("\n\nEnter the path to mount the server partition: ");
      mount_path = (char *)malloc(sizeof(char) * 4096);
      buf = (char *)malloc(sizeof(char) * 4096);
      scanf("%s", mount_path);
      printf("\nMounting the file system from %s on %s", ip, mount_path);
      sprintf(buf, "corefs/bin/dclient -S %s %s", ip, mount_path);
      system(buf);
      strcpy(mem_server_ip, ip);
      break;
    case 1:
      printf("\n %s \n", resp);
      is_synced = 1;
      break;
    case 2:
      if(! is_synced) {
        printf("\nThe data has been changed locally. Are you sure you don't want to sync the server? (Y/N) ");
        scanf(" %c", &ch);
        printf("\nReceived char %c \n", ch);
        switch(tolower(ch)) {
          case 'y':
            break;
          case 'n':
            printf("\nReceived no");
            send_command(1);
            break;
          default:
            fprintf(stderr, "\nInvalid input");
        }
      }
      printf("\nUnmounting the file system from %s", mount_path);
      sprintf(buf, "fusermount -u %s", mount_path);
      system(buf);
      break;
  }
}

canonical_original_code:
int parse_response(int cmd, char *resp) {
  char ip[100000]; char *buf; char ch;
  switch(cmd) {
    case 0:
      is_synced = 0;
      strcpy(mem_server_ip, "");
      strcpy(ip, resp);
      printf("\n\nEnter the path to mount the server partition: ");
      mount_path = (char *)malloc(sizeof(char) * 4096);
      buf = (char *)malloc(sizeof(char) * 4096);
      scanf("%s", mount_path);
      printf("\nMounting the file system from %s on %s", ip, mount_path);
      sprintf(buf, "corefs/bin/dclient -S %s %s", ip, mount_path);
      system(buf);
      strcpy(mem_server_ip, ip);
      break;
    case 1:
      printf("\n %s \n", resp);
      is_synced = 1;
      break;
    case 2:
      if(! is_synced) {
        printf("\nThe data has been changed locally. Are you sure you don't want to sync the server? (Y/N) ");
        scanf(" %c", &ch);
        printf("\nReceived char %c \n", ch);
        switch(tolower(ch)) {
          case 'y':
            break;
          case 'n':
            printf("\nReceived no");
            send_command(1);
            break;
          default:
            fprintf(stderr, "\nInvalid input");
        }
      }
      printf("\nUnmounting the file system from %s", mount_path);
      sprintf(buf, "fusermount -u %s", mount_path);
      system(buf);
      break;
  }
}

variable_types:
resp
char *

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall send_command(unsigned int a1)
{
size_t v1; // rax
__int64 result; // rax
struct sockaddr v3; // [rsp+0h] [rbp-848h] BYREF
char s[1040]; // [rsp+10h] [rbp-838h] BYREF
char buf[1064]; // [rsp+420h] [rbp-428h] BYREF

if ( sockfd >= 0 )
goto LABEL_2;
sockfd = socket(2, 1, 0);
if ( sockfd < 0 )
{
fwrite("\nError : Could not create socket \n", 1uLL, 0x22uLL, stderr);
result = 1LL;
}
else
{
*(_QWORD *)&v3.sa_family = 0x3030303030300002LL;
*(_QWORD *)&v3.sa_data[6] = 0x3030303030303030LL;
*(_WORD *)v3.sa_data = _bswap_16(port);
if ( inet_pton(2, server, &v3.sa_data[2]) <= 0 )
{
fwrite("\nError: inet_pton error occured\n", 1uLL, 0x20uLL, stderr);
result = 1LL;
}
else
{
if ( connect(sockfd, &v3, 0x10u) >= 0 )
{
LABEL_2:
memset(s, 0, 0x400uLL);
s[1024] = 0;
sprintf(s, "%d%s", a1, &mem_server_ip);
printf("\nSending command: %s", s);
v1 = strlen(s);
write(sockfd, s, v1);
memset(buf, 0, 0x400uLL);
buf[1024] = 0;
read(sockfd, buf, 0x400uLL);
printf("\nReceived response: %s", buf);
parse_response(a1, buf);
close(sockfd);
sockfd = -1;
return 0LL;
}
fwrite("\nError : Connect Failed \n", 1uLL, 0x19uLL, stderr);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
size_t v1; // rax
__int64 result; // rax
struct sockaddr v3; // [rsp+0h] [rbp-848h] BYREF
char s[1040]; // [rsp+10h] [rbp-838h] BYREF
char buf[1064]; // [rsp+420h] [rbp-428h] BYREF

if ( sockfd >= 0 )
goto LABEL_2;
sockfd = socket(2, 1, 0);
if ( sockfd < 0 )
{
fwrite("\nError : Could not create socket \n", 1uLL, 0x22uLL, stderr);
result = 1LL;
}
else
{
*(_QWORD *)&v3.sa_family = 0x3030303030300002LL;
*(_QWORD *)&v3.sa_data[6] = 0x3030303030303030LL;
*(_WORD *)v3.sa_data = func7(port);
if ( inet_pton(2, server, &v3.sa_data[2]) <= 0 )
{
fwrite("\nError: inet_pton error occured\n", 1uLL, 0x20uLL, stderr);
result = 1LL;
}
else
{
if ( connect(sockfd, &v3, 0x10u) >= 0 )
{
LABEL_2:
memset(s, 0, 0x400uLL);
s[1024] = 0;
sprintf(s, "%d%s", a1, &mem_server_ip);
printf("\nSending command: %s", s);
v1 = strlen(s);
write(sockfd, s, v1);
memset(buf, 0, 0x400uLL);
buf[1024] = 0;
read(sockfd, buf, 0x400uLL);
printf("\nReceived response: %s", buf);
func8(a1, buf);
close(sockfd);
sockfd = -1;
return 0LL;
}
fwrite("\nError : Connect Failed \n", 1uLL, 0x19uLL, stderr);
result = 1LL;
}
}
return result;
}

original_code:
int send_command(int cmd) {
    int n = 0;
    char recvBuff[1025];
    char sendBuff[1025];
    struct sockaddr_in serv_addr;
    if(sockfd < 0) {
        if((sockfd = socket(2, SOCK_STREAM, 0)) < 0)
        {
            fprintf(stderr, "\nError : Could not create socket \n");
            return 1;
        }
        memset(&serv_addr, '0', sizeof(serv_addr));
        serv_addr.sin_family = 2;
        serv_addr.sin_port = htons(port);
        if(inet_pton(2, server, &serv_addr.sin_addr)<=0)
        {
            fprintf(stderr, "\nError: inet_pton error occured\n");
            return 1;
        }
        if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
        {
           fprintf(stderr, "\nError : Connect Failed \n");
           return 1;
        }
    }
    memset(sendBuff, 0, 1025);
    sprintf(sendBuff, "%d%s", cmd, mem_server_ip);
    printf("\nSending command: %s", sendBuff);
    n = write(sockfd, sendBuff, strlen(sendBuff));
    memset(recvBuff, 0, 1025);
    n = read(sockfd, recvBuff, sizeof(recvBuff)-1);
    printf("\nReceived response: %s", recvBuff);
    parse_response(cmd, recvBuff);
    close(sockfd);
    sockfd = -1;
    return 0;
}

variable_types:
recvBuff
char [1025]

variable_types:
sendBuff
char [1025]


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

if ( argc == 2 )
{
server = (char *)argv[1];
send_command(0);
printf("\nClient init done. Enter any key to continue: ");
__isoc99_scanf();
send_command(1u);
printf("\nSync memeory servers done. Enter any key to continue: ");
__isoc99_scanf();
send_command(2u);
printf("\nClient close done.");
result = 0;
}
else
{
printf("\n Usage: %s <ip of server> \n", *argv);
result = 1;
}
return result;
}

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

if ( argc == 2 )
{
server = (char *)argv[1];
func9(0);
printf("\nClient init done. Enter any key to continue: ");
__isoc99_scanf();
func9(1u);
printf("\nSync memeory servers done. Enter any key to continue: ");
__isoc99_scanf();
func9(2u);
printf("\nClient close done.");
result = 0;
}
else
{
printf("\n Usage: %s <ip of server> \n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv) {
    char ch;
    if(argc != 2)
    {
        printf("\n Usage: %s <ip of server> \n",argv[0]);
        return 1;
    }
    server = argv[1];
    if(argc == 3)
    {
        port = atoi(argv[2]);
    }
    send_command(0);
    printf("\nClient init done. Enter any key to continue: ");
    scanf(" %c", &ch);
    send_command(1);
    printf("\nSync memeory servers done. Enter any key to continue: ");
    scanf(" %c", &ch);
    send_command(2);
    printf("\nClient close done.");
    return 0;
}

variable_types:
argv
char **

variable_types: ch char


galoisTest

repo: GregoireDelannoy/TCPeP

decompiled_code:
__int64 galoisTest()
{
unsigned int v0; // ebx

v0 = 1;
if ( (unsigned __int8)gadd(1LL, 10LL) != 11 )
{
puts("Galois addition failed");
v0 = 0;
}
if ( (unsigned __int8)gmul(1LL, 10LL) != 10 || (unsigned __int8)gmul(2LL, 2LL) != 4 )
{
puts("Galois multiplication failed");
v0 = 0;
}
if ( (unsigned __int8)gdiv(10LL, 1LL) != 10 || (unsigned __int8)gdiv(2LL, 2LL) != 1 )
{
puts("Galois division failed");
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx

v0 = 1;
if ( (unsigned __int8)gadd(1LL, 10LL) != 11 )
{
puts("Galois addition failed");
v0 = 0;
}
if ( (unsigned __int8)gmul(1LL, 10LL) != 10 || (unsigned __int8)gmul(2LL, 2LL) != 4 )
{
puts("Galois multiplication failed");
v0 = 0;
}
if ( (unsigned __int8)gdiv(10LL, 1LL) != 10 || (unsigned __int8)gdiv(2LL, 2LL) != 1 )
{
puts("Galois division failed");
v0 = 0;
}
return v0;
}

original_code:
int galoisTest(){
    uint8_t a,b,c;
    int isOk = 1==1;
    a = 0x01; b = 0x0A; c = 0x0B;
    if((gadd(a,b) != c)){
        printf("Galois addition failed\n");
        isOk = 1==0;
    }
    if((gmul(a,b) != b) || (gmul(0x02, 0x02)!=0x04) ){
        printf("Galois multiplication failed\n");
        isOk = 1==0;
    }
    if((gdiv(b,a) != b) || (gdiv(0x02, 0x02)!=0x01)){
        printf("Galois division failed\n");
        isOk = 1==0;
    }
    return isOk;
}

canonical_original_code:
int galoisTest(){
    unsigned char a; unsigned char b; unsigned char c;
    int isOk = 1==1;
    a = 0x01; b = 0x0A; c = 0x0B;
    if((gadd(a,b) != c)){
        printf("Galois addition failed\n");
        isOk = 1==0;
    }
    if((gmul(a,b) != b) || (gmul(0x02, 0x02)!=0x04) ){
        printf("Galois multiplication failed\n");
        isOk = 1==0;
    }
    if((gdiv(b,a) != b) || (gdiv(0x02, 0x02)!=0x01)){
        printf("Galois division failed\n");
        isOk = 1==0;
    }
    return isOk;
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
c
unsigned char

variable_types: isOk int


matrixTest

decompiled_code:
__int64 matrixTest()
{
_QWORD *v0; // rbx
_QWORD *v1; // rbp
__int64 v2; // r12
__int64 v3; // rax

v0 = (_QWORD *)getRandomMatrix(1000LL, 1000LL);
v1 = (_QWORD *)getRandomMatrix(1000LL, 1000LL);
v2 = mMul(*v0, v0[1], *v1, v1[1]);
mFree(v0);
mFree(v1);
mFree(v2);
v3 = mCreate(0LL, 0LL);
mFree(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rbx
_QWORD *v1; // rbp
__int64 v2; // r12
__int64 v3; // rax

v0 = (_QWORD *)getRandomMatrix(1000LL, 1000LL);
v1 = (_QWORD *)getRandomMatrix(1000LL, 1000LL);
v2 = mMul(*v0, v0[1], *v1, v1[1]);
mFree(v0);
mFree(v1);
mFree(v2);
v3 = mCreate(0LL, 0LL);
mFree(v3);
return 1LL;
}

original_code:
int matrixTest(){
    matrix* a, *b, *c;
    a = getRandomMatrix(1000,1000);
    b = getRandomMatrix(1000,1000);
    c = mMul(*a, *b);
    mFree(a);
    mFree(b);
    mFree(c);
    mFree(mCreate(0,0));
    return 1==1;
}

canonical_original_code:
int matrixTest(){
    struct matrix_t *a; struct matrix_t *b; struct matrix_t *c;
    a = getRandomMatrix(1000,1000);
    b = getRandomMatrix(1000,1000);
    c = mMul(*a, *b);
    mFree(a);
    mFree(b);
    mFree(c);
    mFree(mCreate(0,0));
    return 1==1;
}

variable_types: struct matrix_t { unsigned char **data; int nRows; int nColumns; } *


maxMinTest

decompiled_code:
__int64 maxMinTest()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}


codingTest

decompiled_code:
__int64 codingTest()
{
__int64 v0; // rbp
__int64 v1; // rbx
const void ***v2; // rax
unsigned int v3; // er13
__int64 v4; // r14
int v5; // eax
__int64 v6; // r12
unsigned int v7; // er15
unsigned int v8; // er13
__int64 v9; // r12
__int64 v10; // r12
int v11; // er14
int v12; // ebx
int v13; // eax
int v14; // er15
__int64 v15; // r12
int v16; // eax
float v17; // xmm5_4
int v19; // [rsp+0h] [rbp-2258h]
__int64 v20; // [rsp+0h] [rbp-2258h]
unsigned int v21; // [rsp+Ch] [rbp-224Ch]
float v22; // [rsp+Ch] [rbp-224Ch]
unsigned int v23; // [rsp+10h] [rbp-2248h]
int v24; // [rsp+14h] [rbp-2244h]
unsigned int v25; // [rsp+18h] [rbp-2240h]
unsigned int v26; // [rsp+18h] [rbp-2240h]
int v27; // [rsp+1Ch] [rbp-223Ch]
__int64 v28; // [rsp+20h] [rbp-2238h] BYREF
__int64 v29; // [rsp+28h] [rbp-2230h]
unsigned int v30; // [rsp+94h] [rbp-21C4h] BYREF
unsigned int v31; // [rsp+98h] [rbp-21C0h] BYREF
char v32; // [rsp+9Fh] [rbp-21B9h] BYREF
char v33[2768]; // [rsp+A0h] [rbp-21B8h] BYREF
char v34[2768]; // [rsp+B70h] [rbp-16E8h] BYREF
char v35[3008]; // [rsp+1640h] [rbp-C18h] BYREF
struct timeval v36; // [rsp+2200h] [rbp-58h] BYREF
struct timeval tv; // [rsp+2210h] [rbp-48h] BYREF

v0 = encoderStateInit();
v1 = decoderStateInit();
HIDWORD(v28) = 655370;
LODWORD(v29) = 10;
v2 = (const void ***)getRandomMatrix(1LL, 3000LL);
qmemcpy(v35, **v2, 0xBB8uLL);
mFree(v2);
gettimeofday(&tv, 0LL);
v21 = 0;
v19 = 0;
v3 = 0;
v24 = 0;
v23 = 0;
v4 = 0LL;
v27 = 0;
do
{
handleInClear(v0, v35, 1360LL);
if ( *(int *)(v1 + 80) > 0 )
{
v6 = 0LL;
v26 = v3;
v8 = v23;
do
{
bufferToMuxed(
*(_QWORD *)(*(_QWORD *)(v1 + 64) + 8 * v6),
v34,
*(unsigned int *)(*(_QWORD *)(v1 + 72) + 4 * v6),
&v31,
1LL);
muxedToBuffer(v34, v33, v31, &v30, &v28, &v32);
v7 = v4 + v6 + 1;
if ( (double)(int)random() / 2147483647.0 > 0.1 )
{
onAck(v0, v33, v30);
++v8;
}
v5 = *(_DWORD *)(v1 + 80);
++v6;
}
while ( v5 > (int)v6 );
v23 = v8;
v3 = v26;
if ( v5 <= 0 )
{
v4 = v7;
}
else
{
v9 = 0LL;
do
free(*(void **)(*(_QWORD *)(v1 + 64) + 8 * v9++));
while ( *(_DWORD *)(v1 + 80) > (int)v9 );
v4 = v7;
}
}
free(*(void **)(v1 + 64));
*(_QWORD *)(v1 + 64) = 0LL;
free(*(void **)(v1 + 72));
*(_QWORD *)(v1 + 72) = 0LL;
*(_DWORD *)(v1 + 80) = 0;
if ( *(int *)(v0 + 136) > 0 )
{
v10 = 0LL;
v25 = v4;
v11 = v19;
v20 = v1;
v12 = v24;
do
{
bufferToMuxed(
*(_QWORD *)(*(_QWORD *)(v0 + 120) + 8 * v10),
v34,
*(unsigned int *)(*(_QWORD *)(v0 + 128) + 4 * v10),
&v31,
0LL);
muxedToBuffer(v34, v33, v31, &v30, &v28, &v32);
v3 += v30;
v14 = v11 + v10 + 1;
if ( (double)(int)random() / 2147483647.0 > 0.1 )
{
handleInCoded(v20, v33, v30);
v12 += v30;
}
v13 = *(_DWORD *)(v0 + 136);
++v10;
}
while ( v13 > (int)v10 );
v4 = v25;
v24 = v12;
v1 = v20;
if ( v13 <= 0 )
{
v19 = v14;
}
else
{
v15 = 0LL;
do
free(*(void **)(*(_QWORD *)(v0 + 120) + 8 * v15++));
while ( *(_DWORD *)(v0 + 136) > (int)v15 );
v19 = v14;
}
}
free(*(void **)(v0 + 120));
*(_QWORD *)(v0 + 120) = 0LL;
free(*(void **)(v0 + 128));
*(_QWORD *)(v0 + 128) = 0LL;
*(_DWORD *)(v0 + 136) = 0;
v16 = *(_DWORD *)(v1 + 56);
if ( v16 > 0 )
{
v27 += v16;
free(*(void **)(v1 + 48));
*(_QWORD *)(v1 + 48) = 0LL;
*(_DWORD *)(v1 + 56) = 0;
}
if ( (unsigned int)regulator() )
{
printf("\n~~~~End of round %d~~~~~\n", v21);
encoderStatePrint("\n~~~~End of round %d~~~~~\n", v21);
decoderStatePrint("\n~~~~End of round %d~~~~~\n", v21);
puts("~~~~~~~~~");
}
++v21;
}
while ( v21 != 1000 );
gettimeofday(&v36, 0LL);
v17 = (double)(LODWORD(v36.tv_usec) - LODWORD(tv.tv_usec)) / 1000000.0
+ (double)(LODWORD(v36.tv_sec) - LODWORD(tv.tv_sec));
v22 = v17;
encoderStatePrint((const char *)&v36);
decoderStatePrint((const char *)&v36);
printf(
"During the %d rounds and %f s, %d bytes has been received by the encoder ; %d has been sent to the application.\n"
"%d bytes of Data Packets has been sent, %d received.\n"
"%d Ack has been sent, %d received.\n"
" Simulated loss rate = %f %%. Transmission efficiency = %f %%. Transmission speed = %f MB/s. Data packet per Rounds = %f\n",
1000LL,
v22,
1360000LL,
(unsigned int)v27,
v3,
(unsigned int)v24,
v4,
v23,
*(double *)&LC4,
(double)v27 / (double)v24,
(float)((float)v27 / (float)(v22 * 1048576.0)),
(double)v19 / 1000.0);
encoderStateFree(v0);
decoderStateFree(v1);
return 1LL;
}

original_code:
int codingTest(){
    struct timeval startTime, endTime;
    encoderstate* encState = encoderStateInit();
    decoderstate* decState = decoderStateInit();
    uint8_t inputBuffer[3000], buf1[2 * 1380], buf2[2 * 1380], type;
    int totalBytesSent = 0, totalBytesReceived = 0, totalAckSent = 0, totalAckReceived = 0, totalDataPacketReceived = 0, totalDataPacketSent = 0, nDataPacketSent = 0;
    int i, j, buf1Len, buf2Len;
    muxstate mState;
    mState.sport = 10; mState.dport = 10; mState.remote_ip = 10;
    int nRounds = 1000, sendSize;
    float timeElapsed;
    matrix* randomMatrix = getRandomMatrix(1, 3000);
    memcpy(inputBuffer, randomMatrix->data[0], 3000);
    mFree(randomMatrix);
    gettimeofday(&startTime, ((void *)0));
    for(i = 0; i<nRounds; i++){
        sendSize = 1380 - 20;
        handleInClear(encState, inputBuffer, sendSize);
        totalBytesReceived += sendSize;
        for(j = 0; j < decState->nAckToSend; j++){
            bufferToMuxed(decState->ackToSend[j], buf1, decState->ackToSendSize[j], &buf1Len, mState, 0x01);
            muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type);
            totalAckSent++;
            if(((1.0 * random())/2147483647) > 0.1){
                onAck(encState, buf2, buf2Len);
                totalAckReceived++;
            } else {
            }
        }
        for(j = 0; j< decState->nAckToSend;j++){
            free(decState->ackToSend[j]);
        }
        free(decState->ackToSend);
        decState->ackToSend = 0;
        free(decState->ackToSendSize);
        decState->ackToSendSize = 0;
        decState->nAckToSend = 0;
        for(j = 0; j < encState->nDataToSend; j++){
            bufferToMuxed(encState->dataToSend[j], buf1, encState->dataToSendSize[j], &buf1Len, mState, 0x00);
            muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type);
            totalDataPacketSent += buf2Len;
            nDataPacketSent++;
            if(((1.0 * random())/2147483647) > 0.1){
                handleInCoded(decState, buf2, buf2Len);
                totalDataPacketReceived += buf2Len;
            } else {
            }
        }
        for(j = 0; j< encState->nDataToSend;j++){
            free(encState->dataToSend[j]);
        }
        free(encState->dataToSend);
        encState->dataToSend=0;
        free(encState->dataToSendSize);
        encState->dataToSendSize = 0;
        encState->nDataToSend = 0;
        if(decState->nDataToSend > 0){
            totalBytesSent += decState->nDataToSend;
            free(decState->dataToSend);
            decState->dataToSend = 0;
            decState->nDataToSend = 0;
        }
        if(regulator()){
            printf("\n~~~~End of round %d~~~~~\n", i);
            encoderStatePrint(*encState);
            decoderStatePrint(*decState);
            printf("~~~~~~~~~\n");
        }
    }
    gettimeofday(&endTime, ((void *)0));
    timeElapsed = 1.0 * (endTime.tv_sec - startTime.tv_sec) + ((endTime.tv_usec - startTime.tv_usec) / 1000000.0);
    encoderStatePrint(*encState);
    decoderStatePrint(*decState);
    printf("During the %d rounds and %f s, %d bytes has been received by the encoder ; %d has been sent to the application.\n%d bytes of Data Packets has been sent, %d received.\n%d Ack has been sent, %d received.\n Simulated loss rate = %f %%. Transmission efficiency = %f %%. Transmission speed = %f MB/s. Data packet per Rounds = %f\n", nRounds, timeElapsed, totalBytesReceived, totalBytesSent, totalDataPacketSent, totalDataPacketReceived, totalAckSent, totalAckReceived, 0.1, 1.0 * totalBytesSent / totalDataPacketReceived, totalBytesSent / (1024 * 1024 * timeElapsed), 1.0 * nDataPacketSent / nRounds);
    encoderStateFree(encState);
    decoderStateFree(decState);
    return 1==1;
}

canonical_original_code:
int codingTest(){
    struct timeval startTime; struct timeval endTime;
    struct encoderstate_t *encState = encoderStateInit();
    struct decoderstate_t *decState = decoderStateInit();
    unsigned char inputBuffer[3000]; unsigned char buf1[-1]; unsigned char buf2[-1]; unsigned char type;
    int totalBytesSent = 0; int totalBytesReceived = 0; int totalAckSent = 0; int totalAckReceived = 0; int totalDataPacketReceived = 0; int totalDataPacketSent = 0; int nDataPacketSent = 0;
    int i; int j; int buf1Len; int buf2Len;
    struct muxstate_t mState;
    mState.sport = 10; mState.dport = 10; mState.remote_ip = 10;
    int nRounds = 1000; int sendSize;
    float timeElapsed;
    struct matrix_t *randomMatrix = getRandomMatrix(1, 3000);
    memcpy(inputBuffer, randomMatrix->data[0], 3000);
    mFree(randomMatrix);
    gettimeofday(&startTime, ((void *)0));
    for(i = 0; i<nRounds; i++){
        sendSize = 1380 - 20;
        handleInClear(encState, inputBuffer, sendSize);
        totalBytesReceived += sendSize;
        for(j = 0; j < decState->nAckToSend; j++){
            bufferToMuxed(decState->ackToSend[j], buf1, decState->ackToSendSize[j], &buf1Len, mState, 0x01);
            muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type);
            totalAckSent++;
            if(((1.0 * random())/2147483647) > 0.1){
                onAck(encState, buf2, buf2Len);
                totalAckReceived++;
            } else {
            }
        }
        for(j = 0; j< decState->nAckToSend;j++){
            free(decState->ackToSend[j]);
        }
        free(decState->ackToSend);
        decState->ackToSend = 0;
        free(decState->ackToSendSize);
        decState->ackToSendSize = 0;
        decState->nAckToSend = 0;
        for(j = 0; j < encState->nDataToSend; j++){
            bufferToMuxed(encState->dataToSend[j], buf1, encState->dataToSendSize[j], &buf1Len, mState, 0x00);
            muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type);
            totalDataPacketSent += buf2Len;
            nDataPacketSent++;
            if(((1.0 * random())/2147483647) > 0.1){
                handleInCoded(decState, buf2, buf2Len);
                totalDataPacketReceived += buf2Len;
            } else {
            }
        }
        for(j = 0; j< encState->nDataToSend;j++){
            free(encState->dataToSend[j]);
        }
        free(encState->dataToSend);
        encState->dataToSend=0;
        free(encState->dataToSendSize);
        encState->dataToSendSize = 0;
        encState->nDataToSend = 0;
        if(decState->nDataToSend > 0){
            totalBytesSent += decState->nDataToSend;
            free(decState->dataToSend);
            decState->dataToSend = 0;
            decState->nDataToSend = 0;
        }
        if(regulator()){
            printf("\n~~~~End of round %d~~~~~\n", i);
            encoderStatePrint(*encState);
            decoderStatePrint(*decState);
            printf("~~~~~~~~~\n");
        }
    }
    gettimeofday(&endTime, ((void *)0));
    timeElapsed = 1.0 * (endTime.tv_sec - startTime.tv_sec) + ((endTime.tv_usec - startTime.tv_usec) / 1000000.0);
    encoderStatePrint(*encState);
    decoderStatePrint(*decState);
    printf("During the %d rounds and %f s, %d bytes has been received by the encoder ; %d has been sent to the application.\n%d bytes of Data Packets has been sent, %d received.\n%d Ack has been sent, %d received.\n Simulated loss rate = %f %%. Transmission efficiency = %f %%. Transmission speed = %f MB/s. Data packet per Rounds = %f\n", nRounds, timeElapsed, totalBytesReceived, totalBytesSent, totalDataPacketSent, totalDataPacketReceived, totalAckSent, totalAckReceived, 0.1, 1.0 * totalBytesSent / totalDataPacketReceived, totalBytesSent / (1024 * 1024 * timeElapsed), 1.0 * nDataPacketSent / nRounds);
    encoderStateFree(encState);
    decoderStateFree(decState);
    return 1==1;
}

variable_types: struct decoderstate_t { struct matrix_t { unsigned char **data; int nRows; int nColumns; } **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t { int isReceived[512]; int currentIndex; } *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; } *

variable_types:
inputBuffer
unsigned char [3000]

variable_types:
type
unsigned char

variable_types: totalBytesSent int

variable_types: totalBytesReceived int

variable_types: totalAckSent int

variable_types: totalAckReceived int

variable_types: totalDataPacketReceived int

variable_types: totalDataPacketSent int

variable_types: nDataPacketSent int

variable_types: i int

variable_types: j int

variable_types: struct muxstate_t { int sock_fd; unsigned short sport; unsigned short dport; unsigned int remote_ip; 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]; } udpRemote; unsigned short randomId; struct encoderstate_t { struct block_t { struct matrix_t { unsigned char **data; int nRows; int nColumns; } *dataMatrix; int nPackets; int isSentPacket[127]; unsigned char dofs; } *blocks; int numBlock; struct timeval { long tv_sec; long tv_usec; } nextTimeout; struct packetsentinfo_t { unsigned int seqNo; unsigned short blockNo; struct timeval sentAt; } **packetSentInfos; int *nPacketSent; float p; double shortTermRttAverage; double longTermRttAverage; unsigned int seqNo_Next; unsigned int seqNo_Una; struct timeval time_lastAck; float congestionWindow; unsigned short currBlock; int slowStartMode; int timeOutCounter; int isOutstandingData; unsigned char **dataToSend; int *dataToSendSize; int nDataToSend; } *encoderState; struct decoderstate_t { struct matrix_t **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t { int isReceived[512]; int currentIndex; } *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; } *decoderState; int state; int localSocketReadState; int localSocketWriteState; int remoteSocketReadState; int remoteSocketWriteState; struct timeval lastWriteSent; int remoteOutstandingData; int localOutstandingData; struct timeval lastOutstandingSent; }

variable_types: nRounds int

variable_types: sendSize int

variable_types: timeElapsed float

user_defined_types: struct muxstate_t { int sock_fd; unsigned short sport; unsigned short dport; unsigned int remote_ip; struct sockaddr_in udpRemote; unsigned short randomId; struct encoderstate_t *encoderState; struct decoderstate_t *decoderState; int state; int localSocketReadState; int localSocketWriteState; int remoteSocketReadState; int remoteSocketWriteState; struct timeval lastWriteSent; int remoteOutstandingData; int localOutstandingData; struct timeval lastOutstandingSent; }

user_defined_types: struct encoderstate_t { struct block_t *blocks; int numBlock; struct timeval nextTimeout; struct packetsentinfo_t **packetSentInfos; int *nPacketSent; float p; double shortTermRttAverage; double longTermRttAverage; unsigned int seqNo_Next; unsigned int seqNo_Una; struct timeval time_lastAck; float congestionWindow; unsigned short currBlock; int slowStartMode; int timeOutCounter; int isOutstandingData; unsigned char **dataToSend; int *dataToSendSize; int nDataToSend; }

user_defined_types: struct decoderstate_t { struct matrix_t **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; }

user_defined_types: struct block_t { struct matrix_t *dataMatrix; int nPackets; int isSentPacket[127]; unsigned char dofs; }


statesTest

original_code:
int statesTest(){
    muxstate** muxTable = malloc(sizeof(muxstate*));
    *muxTable = 0;
    int tableLength = 0;
    struct sockaddr_in udpRemoteAddr;
    memset(&udpRemoteAddr, 0, sizeof(udpRemoteAddr));
    assignMux((uint16_t)random(), (uint16_t)random(), (uint32_t)random(), (uint16_t)random(), 0, muxTable, &tableLength, udpRemoteAddr);
    printMux((*muxTable)[0]);
    removeMux(0, muxTable, &tableLength);
    free(muxTable);
    return 1==1;
}

canonical_original_code:
int statesTest(){
    struct muxstate_t **muxTable = malloc(sizeof(muxstate*));
    *muxTable = 0;
    int tableLength = 0;
    struct sockaddr_in udpRemoteAddr;
    memset(&udpRemoteAddr, 0, sizeof(udpRemoteAddr));
    assignMux((unsigned short)random(), (unsigned short)random(), (unsigned int)random(), (unsigned short)random(), 0, muxTable, &tableLength, udpRemoteAddr);
    printMux((*muxTable)[0]);
    removeMux(0, muxTable, &tableLength);
    free(muxTable);
    return 1==1;
}

variable_types: struct muxstate_t { int sock_fd; unsigned short sport; unsigned short dport; unsigned int remote_ip; 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]; } udpRemote; unsigned short randomId; struct encoderstate_t { struct block_t { struct matrix_t { unsigned char **data; int nRows; int nColumns; } *dataMatrix; int nPackets; int isSentPacket[127]; unsigned char dofs; } *blocks; int numBlock; struct timeval { long tv_sec; long tv_usec; } nextTimeout; struct packetsentinfo_t { unsigned int seqNo; unsigned short blockNo; struct timeval sentAt; } **packetSentInfos; int *nPacketSent; float p; double shortTermRttAverage; double longTermRttAverage; unsigned int seqNo_Next; unsigned int seqNo_Una; struct timeval time_lastAck; float congestionWindow; unsigned short currBlock; int slowStartMode; int timeOutCounter; int isOutstandingData; unsigned char **dataToSend; int *dataToSendSize; int nDataToSend; } *encoderState; struct decoderstate_t { struct matrix_t **blocks; struct matrix_t **coefficients; struct lossInformationBuffer_t { int isReceived[512]; int currentIndex; } *lossBuffer; unsigned short currBlock; int numBlock; int *nPacketsInBlock; int **isSentPacketInBlock; unsigned char *dataToSend; int nDataToSend; unsigned char **ackToSend; int *ackToSendSize; int nAckToSend; unsigned int lastSeqReceived; unsigned long stats_nAppendedNotInnovativeGaloisFirstBlock; unsigned long stats_nAppendedNotInnovativeGaloisOtherBlock; unsigned long stats_nOutdated; unsigned long stats_nAppendedNotInnovativeCounter; unsigned long stats_nInnovative; } *decoderState; int state; int localSocketReadState; int localSocketWriteState; int remoteSocketReadState; int remoteSocketWriteState; struct timeval lastWriteSent; int remoteOutstandingData; int localOutstandingData; struct timeval lastOutstandingSent; } **

variable_types: tableLength int


main

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

if ( (unsigned int)codingTest(argc, argv, envp) )
{
puts("All test passed.");
result = 0;
}
else
{
puts("Testing failed.");
result = -1;
}
return result;
}

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

if ( (unsigned int)func3(argc, argv, envp) )
{
puts("All test passed.");
result = 0;
}
else
{
puts("Testing failed.");
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv){
    if(codingTest()){
        printf("All test passed.\n");
        return 0;
    } else {
        printf("Testing failed.\n");
        return -1;
    }
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void do_debug()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void do_debug(char *msg, ...){
    va_list argp;
    if(1==0) {
        __builtin_va_start(argp,msg);
        vfprintf(stdout, msg, argp);
        __builtin_va_end(argp);
    }
}

canonical_original_code:
void do_debug(char *msg, ...){
    __builtin_va_list argp;
    if(1==0) {
        __builtin_va_start(argp,msg);
        vfprintf(stdout, msg, argp);
        __builtin_va_end(argp);
    }
}

variable_types:
msg
char *


decompiled_code:
int my_err(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stderr, format, arg);
}

original_code:
void my_err(char *msg, ...) {
    va_list argp;
    __builtin_va_start(argp,msg);
    vfprintf(stderr, msg, argp);
    __builtin_va_end(argp);
}

canonical_original_code:
void my_err(char *msg, ...) {
    __builtin_va_list argp;
    __builtin_va_start(argp,msg);
    vfprintf(stderr, msg, argp);
    __builtin_va_end(argp);
}


cread

decompiled_code:
__int64 __fastcall cread(int a1, void *a2, int a3)
{
int v3; // edx

v3 = read(a1, a2, a3);
if ( v3 < 0 )
{
perror("in utils.c : Reading data");
v3 = -1;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, void *a2, int a3)
{
int v3; // edx

v3 = read(a1, a2, a3);
if ( v3 < 0 )
{
perror("in utils.c : Reading data");
v3 = -1;
}
return (unsigned int)v3;
}

original_code:
int cread(int fd, uint8_t *buf, int n){
    int nread;
    if((nread=read(fd, buf, n)) < 0){
        perror("in utils.c : Reading data");
        return -1;
    }
    return nread;
}

canonical_original_code:
int cread(int fd, unsigned char *buf, int n){
    int nread;
    if((nread=read(fd, buf, n)) < 0){
        perror("in utils.c : Reading data");
        return -1;
    }
    return nread;
}

variable_types: fd int

variable_types:
buf
unsigned char *

variable_types: n int

variable_types: nread int


udpSend

decompiled_code:
__int64 __fastcall udpSend(int a1, const void *a2, int a3, const struct sockaddr *a4)
{
unsigned int v5; // edx

v5 = sendto(a1, a2, a3, 0, a4, 0x10u);
if ( a3 != v5 )
{
perror("in udpSend() : sent != n");
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const void *a2, int a3, const struct sockaddr *a4)
{
unsigned int v5; // edx

v5 = sendto(a1, a2, a3, 0, a4, 0x10u);
if ( a3 != v5 )
{
perror("in udpSend() : sent != n");
v5 = -1;
}
return v5;
}

original_code:
int udpSend(int fd, uint8_t *buf, int n, struct sockaddr* remote){
    int ret = sendto(fd, buf, n, 0, remote, 16);
    if( n != ret){
        perror("in udpSend() : sent != n");
        return -1;
    }
    return ret;
}

canonical_original_code:
int udpSend(int fd, unsigned char *buf, int n, struct sockaddr *remote){
    int ret = sendto(fd, buf, n, 0, remote, 16);
    if( n != ret){
        perror("in udpSend() : sent != n");
        return -1;
    }
    return ret;
}

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

variable_types: ret int


cwrite

decompiled_code:
__int64 __fastcall cwrite(int fd, void *buf, int a3)
{
unsigned int v4; // ebx
size_t v5; // r14
int v6; // eax

if ( a3 <= 0 )
return 0;
v4 = 0;
v5 = a3;
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 < 0 )
break;
v4 += v6;
if ( a3 <= (int)v4 )
return v4;
}
perror("In utils.c: Writing data");
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, void *buf, int a3)
{
unsigned int v4; // ebx
size_t v5; // r14
int v6; // eax

if ( a3 <= 0 )
return 0;
v4 = 0;
v5 = a3;
while ( 1 )
{
v6 = write(fd, buf, v5);
if ( v6 < 0 )
break;
v4 += v6;
if ( a3 <= (int)v4 )
return v4;
}
perror("In utils.c: Writing data");
return (unsigned int)-1;
}

original_code:
int cwrite(int fd, uint8_t *buf, int n){
    int nwrite, totalWrite = 0;
    while(totalWrite<n){
        if((nwrite=write(fd, buf, n)) < 0){
            perror("In utils.c: Writing data");
            return(-1);
        } else {
            totalWrite += nwrite;
        }
    }
    return totalWrite;
}

canonical_original_code:
int cwrite(int fd, unsigned char *buf, int n){
    int nwrite; int totalWrite = 0;
    while(totalWrite<n){
        if((nwrite=write(fd, buf, n)) < 0){
            perror("In utils.c: Writing data");
            return(-1);
        } else {
            totalWrite += nwrite;
        }
    }
    return totalWrite;
}

variable_types: nwrite int

variable_types: totalWrite int


isSooner

decompiled_code:
_BOOL8 __fastcall isSooner(__int128 a1, __int64 a2, signed __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 != 0 )
{
result = 1LL;
if ( __PAIR128__(a3, a2) != 0 )
{
result = 0LL;
if ( a2 >= (__int64)a1 )
result = a2 != (_QWORD)a1 || *((_QWORD *)&a1 + 1) <= a3;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int128 a1, __int64 a2, signed __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 != 0 )
{
result = 1LL;
if ( __PAIR128__(a3, a2) != 0 )
{
result = 0LL;
if ( a2 >= (__int64)a1 )
result = a2 != (_QWORD)a1 || *((_QWORD *)&a1 + 1) <= a3;
}
}
return result;
}

original_code:
int isSooner(struct timeval a, struct timeval b){
    int ret;
    if(a.tv_sec == 0 && a.tv_usec == 0){
        ret = 1==0;
    } else if(b.tv_sec == 0 && b.tv_usec == 0){
        ret = 1==1;
    }else if(a.tv_sec > b.tv_sec){
        ret = 1==0;
    } else if(a.tv_sec < b.tv_sec){
        ret = 1==1;
    } else if(a.tv_usec > b.tv_usec){
        ret = 1==0;
    } else {
        ret = 1==1;
    }
    return ret;
}

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

variable_types:
b
struct timeval


addUSec

original_code:
void addUSec(struct timeval *a, long t){
    a->tv_usec += t;
    while(a->tv_usec > 1000000){
        a->tv_sec ++;
        a->tv_usec -= 1000000;
    }
}

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

variable_types: t long


regulator

decompiled_code:
_BOOL8 regulator()
{
struct timeval *v0; // rbx
_BOOL8 result; // rax
__int128 v2; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
if ( !last_0 )
{
last_0 = (__int64)malloc(0x10uLL);
gettimeofday((struct timeval *)last_0, 0LL);
}
v0 = (struct timeval *)last_0;
v2 = *(_OWORD *)last_0;
addUSec((__int64 *)&v2, 5000000LL);
result = isSooner(v2, tv.tv_sec, tv.tv_usec);
if ( result )
{
*v0 = tv;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func7()
{
struct timeval *v0; // rbx
_BOOL8 result; // rax
__int128 v2; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
if ( !last_0 )
{
last_0 = (__int64)malloc(0x10uLL);
gettimeofday((struct timeval *)last_0, 0LL);
}
v0 = (struct timeval *)last_0;
v2 = *(_OWORD *)last_0;
func6((__int64 *)&v2, 5000000LL);
result = func5(v2, tv.tv_sec, tv.tv_usec);
if ( result )
{
*v0 = tv;
result = 1LL;
}
return result;
}

original_code:
int regulator(){
    static struct timeval *last = 0;
    struct timeval current, tmp;
    int ret;
    gettimeofday(&current, ((void *)0));
    if(last == 0){
        last = malloc(sizeof(struct timeval));
        gettimeofday(last, ((void *)0));
    }
    tmp.tv_sec = last->tv_sec;
    tmp.tv_usec = last->tv_usec;
    addUSec(&tmp, 1000 * 5000);
    if(isSooner(tmp, current)){
        ret = 1==1;
        last->tv_sec = current.tv_sec;
        last->tv_usec = current.tv_usec;
    } else {
        ret = 1==0;
    }
    return ret;
}

canonical_original_code:
int regulator(){
    static struct timeval *last = 0;
    struct timeval current; struct timeval tmp;
    int ret;
    gettimeofday(&current, ((void *)0));
    if(last == 0){
        last = malloc(sizeof(struct timeval));
        gettimeofday(last, ((void *)0));
    }
    tmp.tv_sec = last->tv_sec;
    tmp.tv_usec = last->tv_usec;
    addUSec(&tmp, 1000 * 5000);
    if(isSooner(tmp, current)){
        ret = 1==1;
        last->tv_sec = current.tv_sec;
        last->tv_usec = current.tv_usec;
    } else {
        ret = 1==0;
    }
    return ret;
}

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


mPrint

decompiled_code:
int __fastcall mPrint(__int64 a1, __int64 a2)
{
int result; // eax
__int64 v3; // r13
__int64 v4; // rbx

result = printf("rows = %d, columns = %d\n", a2, HIDWORD(a2));
if ( SHIDWORD(a2) > 20 )
return puts("Yo Matrix so fat I not ev' gonna print it.");
v3 = 0LL;
if ( (int)a2 > 0 )
{
do
{
putchar(124);
if ( SHIDWORD(a2) > 0 )
{
v4 = 0LL;
do
printf(" %2x ", *(unsigned __int8 *)(*(_QWORD *)(v3 + a1) + v4++));
while ( v4 != HIDWORD(a2) );
}
result = puts("|");
v3 += 8LL;
}
while ( v3 != 8LL * (unsigned int)a2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
int result; // eax
__int64 v3; // r13
__int64 v4; // rbx

result = printf("rows = %d, columns = %d\n", a2, HIDWORD(a2));
if ( SHIDWORD(a2) > 20 )
return puts("Yo Matrix so fat I not ev' gonna print it.");
v3 = 0LL;
if ( (int)a2 > 0 )
{
do
{
putchar(124);
if ( SHIDWORD(a2) > 0 )
{
v4 = 0LL;
do
printf(" %2x ", *(unsigned __int8 *)(*(_QWORD *)(v3 + a1) + v4++));
while ( v4 != HIDWORD(a2) );
}
result = puts("|");
v3 += 8LL;
}
while ( v3 != 8LL * (unsigned int)a2 );
}
return result;
}

original_code:
void mPrint(matrix m){
    int i, j;
    printf("rows = %d, columns = %d\n", m.nRows, m.nColumns);
    if(m.nColumns > 20){
        printf("Yo Matrix so fat I not ev' gonna print it.\n");
        return;
    }
    for(i = 0; i < m.nRows; i++){
        printf("|");
        for(j = 0; j < m.nColumns; j++){
            printf(" %2x ", m.data[i][j]);
        }
        printf("|\n");
    }
}

canonical_original_code:
void mPrint(struct matrix_t m){
    int i; int j;
    printf("rows = %d, columns = %d\n", m.nRows, m.nColumns);
    if(m.nColumns > 20){
        printf("Yo Matrix so fat I not ev' gonna print it.\n");
        return;
    }
    for(i = 0; i < m.nRows; i++){
        printf("|");
        for(j = 0; j < m.nColumns; j++){
            printf(" %2x ", m.data[i][j]);
        }
        printf("|\n");
    }
}

variable_types: struct matrix_t { unsigned char **data; int nRows; int nColumns; }

variable_types: i int

variable_types: j int


mFree

decompiled_code:
void __fastcall mFree(void *ptr)
{
__int64 v1; // rbx
int v2; // eax

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
{
free(*(void **)(*(_QWORD *)ptr + 8 * v1));
v2 = *((_DWORD *)ptr + 2);
++v1;
}
while ( v2 > (int)v1 );
if ( v2 > 0 )
free(*(void **)ptr);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v1; // rbx
int v2; // eax

if ( *((int *)ptr + 2) > 0 )
{
v1 = 0LL;
do
{
free(*(void **)(*(_QWORD *)ptr + 8 * v1));
v2 = *((_DWORD *)ptr + 2);
++v1;
}
while ( v2 > (int)v1 );
if ( v2 > 0 )
free(*(void **)ptr);
}
free(ptr);
}

original_code:
void mFree(matrix* m){
    int i;
    for(i = 0; i < m->nRows; i++){
        free(m->data[i]);
    }
    if(m->nRows > 0){
        free(m->data);
    }
    free(m);
}

canonical_original_code:
void mFree(struct matrix_t *m){
    int i;
    for(i = 0; i < m->nRows; i++){
        free(m->data[i]);
    }
    if(m->nRows > 0){
        free(m->data);
    }
    free(m);
}

variable_types: struct matrix_t { unsigned char **data; int nRows; int nColumns; } *


mEqual

decompiled_code:
__int64 __fastcall mEqual(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
unsigned __int64 v6; // r11
__int64 v7; // rdi
__int64 v8; // r10
__int64 v9; // rsi
__int64 v10; // rax

result = 0LL;
if ( a2 == a4 )
{
if ( (int)a2 <= 0 )
{
result = 1LL;
}
else
{
v6 = HIDWORD(a2);
v7 = (unsigned int)a2;
v8 = 0LL;
v9 = HIDWORD(a2);
while ( (int)v6 <= 0 )
{
if ( ++v8 == v7 )
return 1LL;
}
while ( 2 )
{
v10 = 0LL;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 8 * v8) + v10) != *(_BYTE *)(*(_QWORD *)(a3 + 8 * v8) + v10) )
return 0LL;
++v10;
}
while ( v9 != v10 );
if ( ++v8 != v7 )
continue;
break;
}
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
unsigned __int64 v6; // r11
__int64 v7; // rdi
__int64 v8; // r10
__int64 v9; // rsi
__int64 v10; // rax

result = 0LL;
if ( a2 == a4 )
{
if ( (int)a2 <= 0 )
{
result = 1LL;
}
else
{
v6 = HIDWORD(a2);
v7 = (unsigned int)a2;
v8 = 0LL;
v9 = HIDWORD(a2);
while ( (int)v6 <= 0 )
{
if ( ++v8 == v7 )
return 1LL;
}
while ( 2 )
{
v10 = 0LL;
do
{
if ( *(_BYTE *)(*(_QWORD *)(a1 + 8 * v8) + v10) != *(_BYTE *)(*(_QWORD *)(a3 + 8 * v8) + v10) )
return 0LL;
++v10;
}
while ( v9 != v10 );
if ( ++v8 != v7 )
continue;
break;
}
result = 1LL;
}
}
return result;
}

original_code:
int mEqual(matrix a, matrix b){
    int i,j;
    if((a.nRows != b.nRows) || (a.nColumns != b.nColumns)){
    return 1==0;
    }
    for(i = 0; i < a.nRows; i++){
        for(j = 0; j < a.nColumns; j++){
            if(a.data[i][j] != b.data[i][j]){
                return 1==0;
            }
        }
    }
    return 1==1;
}

canonical_original_code:
int mEqual(struct matrix_t a, struct matrix_t b){
    int i; int j;
    if((a.nRows != b.nRows) || (a.nColumns != b.nColumns)){
    return 1==0;
    }
    for(i = 0; i < a.nRows; i++){
        for(j = 0; j < a.nColumns; j++){
            if(a.data[i][j] != b.data[i][j]){
                return 1==0;
            }
        }
    }
    return 1==1;
}

variable_types:
b
struct matrix_t

user_defined_types: struct matrix_t { unsigned char **data; int nRows; int nColumns; }


rowReduce

decompiled_code:
void __fastcall rowReduce(_BYTE *a1, unsigned __int8 a2, int a3)
{
_BYTE *v3; // rbx
__int64 v4; // r12

if ( a2 != 1 && a3 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[a3 - 1 + 1];
do
{
*v3 = gdiv((unsigned __int8)*v3, a2);
++v3;
}
while ( v3 != (_BYTE *)v4 );
}
}

original_code:
void rowReduce(uint8_t* row, uint8_t factor, int size){
    if(factor != 0x01){
        int i;
        for(i = 0; i < size ; i++){
            row[i] = gdiv(row[i], factor);
        }
    }
}

canonical_original_code:
void rowReduce(unsigned char *row, unsigned char factor, int size){
    if(factor != 0x01){
        int i;
        for(i = 0; i < size ; i++){
            row[i] = gdiv(row[i], factor);
        }
    }
}

variable_types:
row
unsigned char *

variable_types:
factor
unsigned char

variable_types: size int


rowMulSub

decompiled_code:
void __fastcall rowMulSub(_BYTE *a1, unsigned __int8 *a2, unsigned __int8 a3, int a4)
{
unsigned __int8 *v4; // rbp
__int64 v6; // r13
unsigned int v7; // er12
unsigned __int8 v8; // al

if ( a3 && a4 > 0 )
{
v4 = a2;
v6 = (__int64)&a2[a4 - 1 + 1];
v7 = a3;
do
{
v8 = gmul(v7, *v4);
*a1 = gsub((unsigned __int8)*a1, v8);
++v4;
++a1;
}
while ( v4 != (unsigned __int8 *)v6 );
}
}

canonical_decompiled_code:
void __fastcall func4(_BYTE *a1, unsigned __int8 *a2, unsigned __int8 a3, int a4)
{
unsigned __int8 *v4; // rbp
__int64 v6; // r13
unsigned int v7; // er12
unsigned __int8 v8; // al

if ( a3 && a4 > 0 )
{
v4 = a2;
v6 = (__int64)&a2[a4 - 1 + 1];
v7 = a3;
do
{
v8 = gmul(v7, *v4);
*a1 = gsub((unsigned __int8)*a1, v8);
++v4;
++a1;
}
while ( v4 != (unsigned __int8 *)v6 );
}
}

original_code:
void rowMulSub(uint8_t* a, uint8_t* b, uint8_t coeff, int size){
    if(coeff != 0x00){
        int i;
        for(i = 0; i < size ; i++){
            a[i] = gsub(a[i], gmul(coeff, b[i]));
        }
    }
}

canonical_original_code:
void rowMulSub(unsigned char *a, unsigned char *b, unsigned char coeff, int size){
    if(coeff != 0x00){
        int i;
        for(i = 0; i < size ; i++){
            a[i] = gsub(a[i], gmul(coeff, b[i]));
        }
    }
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
coeff
unsigned char


dataPacketPrint

decompiled_code:
int __fastcall dataPacketPrint(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, int a9)
{
int v9; // ebp
__int64 v10; // rbx

puts("DataPacket :");
printf("\tBlock No = %u\n", (unsigned __int16)a7);
if ( (a7 & 0x800000) != 0 )
puts("\tCoded Packet");
else
puts("\tClear Packet");
printf("\tPacket No = %u\n", BYTE2(a7) & 0x7F);
printf("\tSeq No = %u\n", HIDWORD(a7));
printf("\tSize = %d\n", (unsigned int)a9);
printf("\tPayload start : ");
v9 = 10;
if ( a9 <= 10 )
v9 = a9;
if ( a9 > 0 )
{
v10 = 0LL;
do
printf("%2x ", *(unsigned __int8 *)(a8 + v10++));
while ( v9 > (int)v10 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, int a9)
{
int v9; // ebp
__int64 v10; // rbx

puts("DataPacket :");
printf("\tBlock No = %u\n", (unsigned __int16)a7);
if ( (a7 & 0x800000) != 0 )
puts("\tCoded Packet");
else
puts("\tClear Packet");
printf("\tPacket No = %u\n", BYTE2(a7) & 0x7F);
printf("\tSeq No = %u\n", HIDWORD(a7));
printf("\tSize = %d\n", (unsigned int)a9);
printf("\tPayload start : ");
v9 = 10;
if ( a9 <= 10 )
v9 = a9;
if ( a9 > 0 )
{
v10 = 0LL;
do
printf("%2x ", *(unsigned __int8 *)(a8 + v10++));
while ( v9 > (int)v10 );
}
return putchar(10);
}

original_code:
void dataPacketPrint(datapacket p){
    printf("DataPacket :\n");
    printf("\tBlock No = %u\n", p.blockNo);
    if((p.packetNumber & 0b10000000) == 0b00000000){
        printf("\tClear Packet\n");
    } else if((p.packetNumber & 0b10000000) == 0b10000000){
        printf("\tCoded Packet\n");
    } else {
        printf("\tIs neither clear or coded... ?!?\n");
    }
    printf("\tPacket No = %u\n", (p.packetNumber & 0b01111111));
    printf("\tSeq No = %u\n", p.seqNo);
    printf("\tSize = %d\n", p.size);
    printf("\tPayload start : ");
    int i;
    for(i=0;i<(p.size<10?p.size:10);i++){
        printf("%2x ", p.payloadAndSize[i]);
    }
    printf("\n");
}

canonical_original_code:
void dataPacketPrint(struct datapacket_t p){
    printf("DataPacket :\n");
    printf("\tBlock No = %u\n", p.blockNo);
    if((p.packetNumber & 0b10000000) == 0b00000000){
        printf("\tClear Packet\n");
    } else if((p.packetNumber & 0b10000000) == 0b10000000){
        printf("\tCoded Packet\n");
    } else {
        printf("\tIs neither clear or coded... ?!?\n");
    }
    printf("\tPacket No = %u\n", (p.packetNumber & 0b01111111));
    printf("\tSeq No = %u\n", p.seqNo);
    printf("\tSize = %d\n", p.size);
    printf("\tPayload start : ");
    int i;
    for(i=0;i<(p.size<10?p.size:10);i++){
        printf("%2x ", p.payloadAndSize[i]);
    }
    printf("\n");
}

variable_types: struct datapacket_t { unsigned short blockNo; unsigned char packetNumber; unsigned int seqNo; unsigned char *payloadAndSize; int size; }