decompiled_code:
char *__fastcall get_domain_in_question(__int64 a1, int a2)
{
char *v2; // r15
const char *v3; // r13
char v4; // r12
int v5; // ebp
int v6; // er14
const char *v7; // r13
char *v8; // rax
char *v9; // rbx
int v10; // ebp

v2 = 0LL;
if ( a2 > 12 )
{
v3 = (const char *)(a1 + 12);
v4 = *(_BYTE *)(a1 + 12);
v5 = v4;
if ( v4 <= 0 )
{
v2 = 0LL;
}
else
{
v6 = 0;
while ( a2 - 12 >= v5 )
{
v7 = v3 + 1;
v8 = (char *)realloc(v2, v5 + v6 + 2);
v9 = v8;
if ( !v8 )
{
if ( v2 )
free(v2);
perror("Realloc Failure");
return 0LL;
}
v10 = v5 + 2;
memset(&v8[v6], 0, v10);
strncat(v9, v7, v4);
*(_WORD *)&v9[strlen(v9)] = 46;
v6 += v10;
v3 = &v7[v4];
v4 = *v3;
v5 = *v3;
if ( v5 <= 0 )
{
v2 = v9;
break;
}
v2 = v9;
}
}
puts("Ignoring : invalid name_part_len ");
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, int a2)
{
char *v2; // r15
const char *v3; // r13
char v4; // r12
int v5; // ebp
int v6; // er14
const char *v7; // r13
char *v8; // rax
char *v9; // rbx
int v10; // ebp

v2 = 0LL;
if ( a2 > 12 )
{
v3 = (const char *)(a1 + 12);
v4 = *(_BYTE *)(a1 + 12);
v5 = v4;
if ( v4 <= 0 )
{
v2 = 0LL;
}
else
{
v6 = 0;
while ( a2 - 12 >= v5 )
{
v7 = v3 + 1;
v8 = (char *)realloc(v2, v5 + v6 + 2);
v9 = v8;
if ( !v8 )
{
if ( v2 )
free(v2);
perror("Realloc Failure");
return 0LL;
}
v10 = v5 + 2;
memset(&v8[v6], 0, v10);
strncat(v9, v7, v4);
*(_WORD *)&v9[strlen(v9)] = 46;
v6 += v10;
v3 = &v7[v4];
v4 = *v3;
v5 = *v3;
if ( v5 <= 0 )
{
v2 = v9;
break;
}
v2 = v9;
}
}
puts("Ignoring : invalid name_part_len ");
}
return v2;
}

original_code:
char *get_domain_in_question(char *dns_packet, int packet_size)
{
 char *domain_name_pointer = ((void *)0);
 char *domain_name = ((void *)0);
 char *tmp_ptr = ((void *)0);
 int dns_header_len = sizeof(struct dns_header);
 int name_part_len = 0;
 int dn_len = 0;
 if(packet_size > dns_header_len){
  domain_name_pointer = (dns_packet + dns_header_len);
  do {
   name_part_len = (int) domain_name_pointer[0];
   if((name_part_len <= 0) || (name_part_len > (packet_size-dns_header_len))){
    printf("Ignoring : invalid name_part_len \n");
    break;
   }
   domain_name_pointer++;
   tmp_ptr = domain_name;
   domain_name = realloc(domain_name,(dn_len+name_part_len+1 +1));
   if(domain_name == ((void *)0)){
    if(tmp_ptr) free(tmp_ptr);
    perror("Realloc Failure");
    return ((void *)0);
   }
   memset(domain_name+dn_len,0,name_part_len+1 +1);
   strncat(domain_name,domain_name_pointer,name_part_len);
   strncat(domain_name,".",1);
   dn_len += name_part_len + 1 + 1;
   domain_name_pointer += name_part_len;
  } while(name_part_len > 0);
 }
 return domain_name;
}

return_type: char *


decompiled_code:
__int64 __fastcall create_socket(__int64 a1, __int64 a2, int a3)
{
int v4; // edx
int v5; // eax
unsigned int v6; // ebx
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

optval[0] = 1;
v4 = 6;
if ( a3 != 1 )
v4 = (unsigned int)(a3 - 2) < 2 ? 0x11 : 0;
v5 = socket(2, a3, v4);
v6 = v5;
if ( v5 < 0 )
{
puts("Socklib: Failed to create socket");
v6 = -1;
}
else if ( setsockopt(v5, 1, 2, optval, 4u) < 0 )
{
puts("Socklib: Failed to set socket option SO_REUSEADDR");
v6 = -1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
int v4; // edx
int v5; // eax
unsigned int v6; // ebx
int optval[3]; // [rsp+1Ch] [rbp-Ch] BYREF

optval[0] = 1;
v4 = 6;
if ( a3 != 1 )
v4 = (unsigned int)(a3 - 2) < 2 ? 0x11 : 0;
v5 = socket(2, a3, v4);
v6 = v5;
if ( v5 < 0 )
{
puts("Socklib: Failed to create socket");
v6 = -1;
}
else if ( setsockopt(v5, 1, 2, optval, 4u) < 0 )
{
puts("Socklib: Failed to set socket option SO_REUSEADDR");
v6 = -1;
}
return v6;
}

original_code:
int create_socket(char *ip, int port, int sock_type)
{
 int on = 1;
 int sock = 0;
 int proto = 0;
 int addrlen = sizeof(struct sockaddr_in);
 struct sockaddr_in serveraddr;
 memset((void *) &serveraddr,0,sizeof(struct sockaddr_in));
 if(sock_type == SOCK_STREAM){
  proto = IPPROTO_TCP;
 } else if(sock_type == SOCK_DGRAM){
  proto = IPPROTO_UDP;
 } else if(sock_type == SOCK_RAW) {
  proto = IPPROTO_UDP;
 }
    if((sock = socket(2,sock_type,proto)) < 0){
            printf("Socklib: Failed to create socket\n");
            return -1;
    }
    if(setsockopt(sock,1,2,&on,sizeof(int)) < 0){
        printf("Socklib: Failed to set socket option SO_REUSEADDR\n");
        return -1;
    }
 return sock;
}

variable_types:
ip
char *

variable_types: port int

variable_types: on int

variable_types: sock int

variable_types: proto int

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

return_type: int

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


receive

decompiled_code:
void *__fastcall receive(int fd, int a2, int *a3, __int64 a4, struct sockaddr *a5)
{
void *v5; // rbx
void *v9; // rax
int v10; // eax
socklen_t addr_len[11]; // [rsp+Ch] [rbp-2Ch] BYREF

addr_len[0] = 16;
*a3 = 0;
v5 = 0LL;
if ( (unsigned int)(a2 - 2) <= 1 )
{
v9 = malloc(0x10001uLL);
v5 = v9;
if ( v9 )
{
memset(v9, 0, 0x10001uLL);
v10 = recvfrom(fd, v5, 0x10000uLL, 0, a5, addr_len);
*a3 = v10;
if ( v10 < 0 )
{
puts("Socklib: Failed to read data from UDP socket");
free(v5);
v5 = 0LL;
}
}
else
{
perror("Malloc failed");
}
}
return v5;
}

canonical_decompiled_code:
void *__fastcall func4(int fd, int a2, int *a3, __int64 a4, struct sockaddr *a5)
{
void *v5; // rbx
void *v9; // rax
int v10; // eax
socklen_t addr_len[11]; // [rsp+Ch] [rbp-2Ch] BYREF

addr_len[0] = 16;
*a3 = 0;
v5 = 0LL;
if ( (unsigned int)(a2 - 2) <= 1 )
{
v9 = malloc(0x10001uLL);
v5 = v9;
if ( v9 )
{
memset(v9, 0, 0x10001uLL);
v10 = recvfrom(fd, v5, 0x10000uLL, 0, a5, addr_len);
*a3 = v10;
if ( v10 < 0 )
{
puts("Socklib: Failed to read data from UDP socket");
free(v5);
v5 = 0LL;
}
}
else
{
perror("Malloc failed");
}
}
return v5;
}

original_code:
char *receive(int lsock, int sock_type, int *rx_bytes, int csock, struct sockaddr_in *clientaddr)
{
 int recv_size = 0;
 int clen = 0, header_offset = 0;
 int addrlen = sizeof(struct sockaddr_in);
 char *buffer = ((void *)0), *tmp_ptr = ((void *)0), *data_ptr = ((void *)0);
 char *clen_ptr = ((void *)0), *line_end_ptr = ((void *)0);
 *rx_bytes = 0;
 if(sock_type == SOCK_DGRAM || sock_type == SOCK_RAW) {
  if((buffer = malloc(65536 +1)) == ((void *)0)){
                 perror("Malloc failed");
                 return ((void *)0);
         }
         memset(buffer,0,65536 +1);
  if((*rx_bytes = recvfrom(lsock,buffer,65536,0,(struct sockaddr *) clientaddr, (socklen_t *) &addrlen)) < 0){
   printf("Socklib: Failed to read data from UDP socket\n");
   if(buffer) free(buffer);
   return ((void *)0);
  }
 }
 return buffer;
}

canonical_original_code:
char *receive(int lsock, int sock_type, int *rx_bytes, int csock, struct sockaddr_in *clientaddr)
{
 int recv_size = 0;
 int clen = 0; int header_offset = 0;
 int addrlen = sizeof(struct sockaddr_in);
 char *buffer = ((void *)0); char *tmp_ptr = ((void *)0); char *data_ptr = ((void *)0);
 char *clen_ptr = ((void *)0); char *line_end_ptr = ((void *)0);
 *rx_bytes = 0;
 if(sock_type == SOCK_DGRAM || sock_type == SOCK_RAW) {
  if((buffer = malloc(65536 +1)) == ((void *)0)){
                 perror("Malloc failed");
                 return ((void *)0);
         }
         memset(buffer,0,65536 +1);
  if((*rx_bytes = recvfrom(lsock,buffer,65536,0,(struct sockaddr *) clientaddr, (unsigned int *) &addrlen)) < 0){
   printf("Socklib: Failed to read data from UDP socket\n");
   if(buffer) free(buffer);
   return ((void *)0);
  }
 }
 return buffer;
}

variable_types: lsock int

variable_types: csock 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: clen int

variable_types:
buffer
char *

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int16 *v5; // rbx
unsigned __int16 v6; // ax
__int64 v7; // r12
unsigned __int16 v8; // ax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
unsigned __int16 v11; // ax
char *v12; // rbx
unsigned __int16 *v13; // r13
__int16 v14; // ax
__int16 v15; // r14
struct sockaddr v16; // [rsp+0h] [rbp-48h] BYREF
int v17[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v17[0] = 0;
*(_QWORD *)&v16.sa_family = 0LL;
*(_QWORD *)&v16.sa_data[6] = 0LL;
v3 = create_socket((__int64)"mani", 2222LL, 3);
if ( v3 == -1 )
{
puts("Failed to create UDP socket for DNS server");
}
else
{
while ( 1 )
{
v5 = (__int16 *)receive(v3, 3, v17, 0LL, &v16);
if ( !v5 )
break;
printf("Packet size is %d\n", (unsigned int)v17[0]);
if ( v17[0] <= 16 )
{
printf("Received invalid DNS packet; packet size too small");
}
else if ( v17[0] > 44 )
{
v6 = _bswap_16(v5[16]);
if ( v6 == 1 )
{
v7 = (__int64)(v5 + 14);
printf("------------ DNS QUERY -----------------");
v8 = _bswap_16(v5[16]);
printf("\n [%d QUS]", v8);
v9 = _bswap_16(v5[17]);
printf(" [%d ANW]", v9);
v10 = _bswap_16(v5[18]);
printf(" [%d AUT]", v10);
v11 = _bswap_16(v5[19]);
printf(" [%d ADD]\n\n", v11);
v12 = get_domain_in_question((__int64)(v5 + 14), v17[0]);
printf("\x1B[1;34mDomain Name is %s\x1B[0m\n", v12);
if ( v12 && *v12 )
{
v13 = (unsigned __int16 *)(v7 + strlen(v12) + 13);
v14 = _bswap_16(1);
if ( v13[1] == v14 && (v14 == *v13 || (v15 = *v13, v15 == _bswap_16(2))) )
{
puts("\x1B[33mDNS CLASS IN , TYPE A | NS\x1B[0m");
if ( !(unsigned int)send_dns_reply(v12, v3, (__int64)&v16, *v13, v7, v17[0]) )
puts("Failed to send DNS response packet");
}
else
{
puts(
"\x1B[1;31mReceived unsupported DNS query type or class. Only type A, NS and class IN queries are supported.\x1B[0m");
}
}
}
else
{
printf("DNS packet contained the wrong number of questions %d\n", v6);
}
}
}
puts("Failed to receive DNS request from client");
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int16 *v5; // rbx
unsigned __int16 v6; // ax
__int64 v7; // r12
unsigned __int16 v8; // ax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
unsigned __int16 v11; // ax
char *v12; // rbx
unsigned __int16 *v13; // r13
__int16 v14; // ax
__int16 v15; // r14
struct sockaddr v16; // [rsp+0h] [rbp-48h] BYREF
int v17[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v17[0] = 0;
*(_QWORD *)&v16.sa_family = 0LL;
*(_QWORD *)&v16.sa_data[6] = 0LL;
v3 = func3((__int64)"mani", 2222LL, 3);
if ( v3 == -1 )
{
puts("Failed to create UDP socket for DNS server");
}
else
{
while ( 1 )
{
v5 = (__int16 *)func4(v3, 3, v17, 0LL, &v16);
if ( !v5 )
break;
printf("Packet size is %d\n", (unsigned int)v17[0]);
if ( v17[0] <= 16 )
{
printf("Received invalid DNS packet; packet size too small");
}
else if ( v17[0] > 44 )
{
v6 = func0(v5[16]);
if ( v6 == 1 )
{
v7 = (__int64)(v5 + 14);
printf("------------ DNS QUERY -----------------");
v8 = func0(v5[16]);
printf("\n [%d QUS]", v8);
v9 = func0(v5[17]);
printf(" [%d ANW]", v9);
v10 = func0(v5[18]);
printf(" [%d AUT]", v10);
v11 = func0(v5[19]);
printf(" [%d ADD]\n\n", v11);
v12 = func2((__int64)(v5 + 14), v17[0]);
printf("\x1B[1;34mDomain Name is %s\x1B[0m\n", v12);
if ( v12 && *v12 )
{
v13 = (unsigned __int16 *)(v7 + strlen(v12) + 13);
v14 = func0(1);
if ( v13[1] == v14 && (v14 == *v13 || (v15 = *v13, v15 == func0(2))) )
{
puts("\x1B[33mDNS CLASS IN , TYPE A | NS\x1B[0m");
if ( !(unsigned int)func1(v12, v3, (__int64)&v16, *v13, v7, v17[0]) )
puts("Failed to send DNS response packet");
}
else
{
puts(
"\x1B[1;31mReceived unsupported DNS query type or class. Only type A, NS and class IN queries are supported.\x1B[0m");
}
}
}
else
{
printf("DNS packet contained the wrong number of questions %d\n", v6);
}
}
}
puts("Failed to receive DNS request from client");
}
return 1;
}

original_code:
int main(int agrc, char *argv[]) {
 int sock = 0, csock = 0, packet_size = 0;
 struct sockaddr_in clientaddr;
 struct dns_header *header = ((void *)0);
 struct dns_question_section *query_info = ((void *)0);
 char *dns_packet = ((void *)0);
 char *question_domain = ((void *)0);
 char *message = ((void *)0);
 char *fqdn = ((void *)0);
 char *server_ip = ((void *)0);
 memset((void *) &clientaddr,0,sizeof(struct sockaddr_in));
 if((sock = create_socket("mani",2222,SOCK_RAW)) == -1){
  printf("Failed to create UDP socket for DNS server\n");
  return 1;
 }
 int count = 0;
 while(1){
  dns_packet = ((void *)0);
  if((dns_packet = receive(sock,SOCK_RAW,&packet_size,csock,&clientaddr)) == ((void *)0)){
   printf("Failed to receive DNS request from client\n");
   return 1;
  }
  printf("Packet size is %d\n", packet_size);
  if(packet_size <= (int) (sizeof(struct dns_header) + sizeof(struct dns_question_section))){
   printf("Received invalid DNS packet; packet size too small");
   continue;
  }
  if (packet_size <= (int) (sizeof(struct iphdr) + sizeof(struct udphdr) + sizeof(struct dns_header)+ sizeof(struct dns_question_section))) {
   continue;
  }
  dns_packet += sizeof(struct iphdr);
  dns_packet += sizeof(struct udphdr);
  header = (struct dns_header *) dns_packet;
  if(ntohs(header->num_questions) != 1){
   printf("DNS packet contained the wrong number of questions %d\n",ntohs(header->num_questions));
   continue;
  }
  printf("------------ DNS QUERY -----------------");
     printf("\n [%d QUS]",ntohs(header->num_questions));
     printf(" [%d ANW]",ntohs(header->num_answers));
     printf(" [%d AUT]",ntohs(header->num_authority));
     printf(" [%d ADD]\n\n",ntohs(header->num_additional));
  question_domain = get_domain_in_question(dns_packet,packet_size);
  printf("\x1b[1;34m""Domain Name is %s""\x1b[0m""\n", question_domain);
  if(question_domain != ((void *)0) && strlen(question_domain) > 0){
   query_info = (struct dns_question_section *) ((dns_packet) + sizeof(struct dns_header) + strlen(question_domain) + 1);
   if((query_info->class == htons(0x0001)) && ((query_info->type == htons(0x0001)) || (query_info->type == htons(0x0002)))){
     printf("\x1b[33m""DNS CLASS IN , TYPE A | NS""\x1b[0m""\n");
     if(!send_dns_reply(question_domain,sock,&clientaddr,query_info->type,dns_packet,packet_size)){
      printf("Failed to send DNS response packet\n");
     }
   } else {
    printf("\x1b[1;31m""Received unsupported DNS query type or class. Only type A, NS and class IN queries are supported.""\x1b[0m""\n");
   }
  }
 }
 return 0;
}

canonical_original_code:
int main(int agrc, char *argv[]) {
 int sock = 0; int csock = 0; int packet_size = 0;
 struct sockaddr_in clientaddr;
 struct dns_header *header = ((void *)0);
 struct dns_question_section *query_info = ((void *)0);
 char *dns_packet = ((void *)0);
 char *question_domain = ((void *)0);
 char *message = ((void *)0);
 char *fqdn = ((void *)0);
 char *server_ip = ((void *)0);
 memset((void *) &clientaddr,0,sizeof(struct sockaddr_in));
 if((sock = create_socket("mani",2222,SOCK_RAW)) == -1){
  printf("Failed to create UDP socket for DNS server\n");
  return 1;
 }
 int count = 0;
 while(1){
  dns_packet = ((void *)0);
  if((dns_packet = receive(sock,SOCK_RAW,&packet_size,csock,&clientaddr)) == ((void *)0)){
   printf("Failed to receive DNS request from client\n");
   return 1;
  }
  printf("Packet size is %d\n", packet_size);
  if(packet_size <= (int) (sizeof(struct dns_header) + sizeof(struct dns_question_section))){
   printf("Received invalid DNS packet; packet size too small");
   continue;
  }
  if (packet_size <= (int) (sizeof(struct iphdr) + sizeof(struct udphdr) + sizeof(struct dns_header)+ sizeof(struct dns_question_section))) {
   continue;
  }
  dns_packet += sizeof(struct iphdr);
  dns_packet += sizeof(struct udphdr);
  header = (struct dns_header *) dns_packet;
  if(ntohs(header->num_questions) != 1){
   printf("DNS packet contained the wrong number of questions %d\n",ntohs(header->num_questions));
   continue;
  }
  printf("------------ DNS QUERY -----------------");
     printf("\n [%d QUS]",ntohs(header->num_questions));
     printf(" [%d ANW]",ntohs(header->num_answers));
     printf(" [%d AUT]",ntohs(header->num_authority));
     printf(" [%d ADD]\n\n",ntohs(header->num_additional));
  question_domain = get_domain_in_question(dns_packet,packet_size);
  printf("\x1b[1;34m""Domain Name is %s""\x1b[0m""\n", question_domain);
  if(question_domain != ((void *)0) && strlen(question_domain) > 0){
   query_info = (struct dns_question_section *) ((dns_packet) + sizeof(struct dns_header) + strlen(question_domain) + 1);
   if((query_info->class == htons(0x0001)) && ((query_info->type == htons(0x0001)) || (query_info->type == htons(0x0002)))){
     printf("\x1b[33m""DNS CLASS IN , TYPE A | NS""\x1b[0m""\n");
     if(!send_dns_reply(question_domain,sock,&clientaddr,query_info->type,dns_packet,packet_size)){
      printf("Failed to send DNS response packet\n");
     }
   } else {
    printf("\x1b[1;31m""Received unsupported DNS query type or class. Only type A, NS and class IN queries are supported.""\x1b[0m""\n");
   }
  }
 }
 return 0;
}

variable_types: agrc int

variable_types:
argv
char *[]

variable_types: struct dns_header { unsigned short xid; unsigned short flags; unsigned short num_questions; unsigned short num_answers; unsigned short num_authority; unsigned short num_additional; } *

variable_types: struct dns_question_section { unsigned short type; unsigned short class; } *

variable_types:
message
char *

variable_types:
fqdn
char *

variable_types: count int

user_defined_types: struct iphdr { unsigned char ihl; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; }

user_defined_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; }


repo: prajakta-pathak/digit-recognition

decompiled_code:
__int64 __fastcall largest_count(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 0LL;
v2 = 0;
do
{
if ( *(_DWORD *)(a1 + 4 * v1) > *(_DWORD *)(a1 + 4LL * (int)v2) )
v2 = v1;
++v1;
}
while ( v1 != 10 );
return v2;
}

original_code:
int largest_count(int num[])
{
 int i,res=0;
 for(i=0;i<10;i++)
 {
  if(num[i]>num[res])
  {
   res=i;
  }
 }
 return res;
}

canonical_original_code:
int largest_count(int num[])
{
 int i; int res = 0;
 for(i=0;i<10;i++)
 {
  if(num[i]>num[res])
  {
   res=i;
  }
 }
 return res;
}

variable_types:
num
int []

variable_types: i int

variable_types: res int


digitrec

decompiled_code:
__int64 __fastcall digitrec(const char *a1)
{
unsigned int v1; // ebp

v1 = 0;
if ( (unsigned int)ispresent("data/zero.txt", a1, 91) != 1 )
{
v1 = ispresent("data/one.txt", a1, 97);
if ( v1 != 1 )
{
if ( (unsigned int)ispresent("data/two.txt", a1, 94) == 1 )
{
v1 = 2;
}
else if ( (unsigned int)ispresent("data/three.txt", a1, 88) == 1 )
{
v1 = 3;
}
else if ( (unsigned int)ispresent("data/four.txt", a1, 98) == 1 )
{
v1 = 4;
}
else if ( (unsigned int)ispresent("data/five.txt", a1, 92) == 1 )
{
v1 = 5;
}
else if ( (unsigned int)ispresent("data/six.txt", a1, 98) == 1 )
{
v1 = 6;
}
else if ( (unsigned int)ispresent("data/seven.txt", a1, 98) == 1 )
{
v1 = 7;
}
else if ( (unsigned int)ispresent("data/eight.txt", a1, 89) == 1 )
{
v1 = 8;
}
else if ( (unsigned int)ispresent("data/nine.txt", a1, 96) == 1 )
{
v1 = 9;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // ebp

v1 = 0;
if ( (unsigned int)func1("data/zero.txt", a1, 91) != 1 )
{
v1 = func1("data/one.txt", a1, 97);
if ( v1 != 1 )
{
if ( (unsigned int)func1("data/two.txt", a1, 94) == 1 )
{
v1 = 2;
}
else if ( (unsigned int)func1("data/three.txt", a1, 88) == 1 )
{
v1 = 3;
}
else if ( (unsigned int)func1("data/four.txt", a1, 98) == 1 )
{
v1 = 4;
}
else if ( (unsigned int)func1("data/five.txt", a1, 92) == 1 )
{
v1 = 5;
}
else if ( (unsigned int)func1("data/six.txt", a1, 98) == 1 )
{
v1 = 6;
}
else if ( (unsigned int)func1("data/seven.txt", a1, 98) == 1 )
{
v1 = 7;
}
else if ( (unsigned int)func1("data/eight.txt", a1, 89) == 1 )
{
v1 = 8;
}
else if ( (unsigned int)func1("data/nine.txt", a1, 96) == 1 )
{
v1 = 9;
}
}
}
return v1;
}

original_code:
int digitrec(char input[])
{
  int n;
  if(ispresent("data/zero.txt",input,91)==1)
  {
   n=0;
  }
  else if(ispresent("data/one.txt",input,97)==1)
  {
   n=1;
  }
  else if(ispresent("data/two.txt",input,94)==1)
  {
   n=2;
  }
  else if(ispresent("data/three.txt",input,88)==1)
  {
   n=3;
  }
  else if(ispresent("data/four.txt",input,98)==1)
  {
   n=4;
  }
  else if(ispresent("data/five.txt",input,92)==1)
  {
   n=5;
  }
  else if(ispresent("data/six.txt",input,98)==1)
  {
   n=6;
  }
  else if(ispresent("data/seven.txt",input,98)==1)
  {
   n=7;
  }
  else if(ispresent("data/eight.txt",input,89)==1)
  {
   n=8;
  }
  else if(ispresent("data/nine.txt",input,96)==1)
  {
   n=9;
  }
  return n;
 }

variable_types:
input
char []

variable_types: n int


predict

decompiled_code:
__int64 __fastcall predict(const char *a1)
{
char *v1; // rax
unsigned int i; // ebx
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int v7; // eax
char v9[16]; // [rsp+0h] [rbp-58h] BYREF
int v10[10]; // [rsp+10h] [rbp-48h] BYREF
char v11; // [rsp+38h] [rbp-20h] BYREF

v1 = (char *)v10;
do
{
*(_DWORD *)v1 = 0;
v1 += 4;
}
while ( v1 != &v11 );
for ( i = 0; i != 750; ++i )
{
sprintf(v9, "data/%d.txt", i);
if ( COERCE_FLOAT(distancesq(a1, v9, v3, v4, v5, v6)) < 130.0 )
{
v7 = digitrec(v9);
++v10[v7];
}
}
return largest_count((__int64)v10);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char *v1; // rax
unsigned int i; // ebx
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int v7; // eax
char v9[16]; // [rsp+0h] [rbp-58h] BYREF
int v10[10]; // [rsp+10h] [rbp-48h] BYREF
char v11; // [rsp+38h] [rbp-20h] BYREF

v1 = (char *)v10;
do
{
*(_DWORD *)v1 = 0;
v1 += 4;
}
while ( v1 != &v11 );
for ( i = 0; i != 750; ++i )
{
sprintf(v9, "data/%d.txt", i);
if ( COERCE_FLOAT(distancesq(a1, v9, v3, v4, v5, v6)) < 130.0 )
{
v7 = func2(v9);
++v10[v7];
}
}
return func0((__int64)v10);
}

original_code:
int predict(char name[])
{
 int n=0,res;
 float dist;
 int i;
 int count[10];
 char fname[16];
 for(i=0;i<10;i++)
 count[i]=0;
 for(i=0;i<750;i++)
 {
  sprintf(fname,"data/%d.txt",i);
  dist=distancesq(name,fname);
  if(dist<130)
  {
   n=digitrec(fname);
   count[n]++;
  }
 }
 res=largest_count(count);
 return res;
}

canonical_original_code:
int predict(char name[])
{
 int n = 0; int res;
 float dist;
 int i;
 int count[10];
 char fname[16];
 for(i=0;i<10;i++)
 count[i]=0;
 for(i=0;i<750;i++)
 {
  sprintf(fname,"data/%d.txt",i);
  dist=distancesq(name,fname);
  if(dist<130)
  {
   n=digitrec(fname);
   count[n]++;
  }
 }
 res=largest_count(count);
 return res;
}

variable_types:
name
char []

variable_types: dist float

variable_types:
count
int [10]

variable_types:
fname
char [16]


decompiled_code:
__int64 accuracy_two()
{
unsigned int v0; // ebx
unsigned int v1; // er12
int v2; // ebp
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
v1 = 0;
do
{
sprintf(v4, "data/%d.txt", v0);
v2 = predict(v4);
v1 += v2 == digitrec(v4);
printf("%d\n", v1);
++v0;
}
while ( v0 != 1500 );
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
unsigned int v1; // er12
int v2; // ebp
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
v1 = 0;
do
{
sprintf(v4, "data/%d.txt", v0);
v2 = func3(v4);
v1 += v2 == func2(v4);
printf("%d\n", v1);
++v0;
}
while ( v0 != 1500 );
return v1;
}

original_code:
int accuracy_two()
{
 int count=0,i;
 float acc;
 int n1,n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=predict(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
   printf("%d\n",count);
  }
 return count;
}

canonical_original_code:
int accuracy_two()
{
 int count = 0; int i;
 float acc;
 int n1; int n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=predict(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
   printf("%d\n",count);
  }
 return count;
}

variable_types: acc float


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
unsigned int v4; // ebx
int v5; // ebp
const char *v6; // r12
unsigned int v7; // eax
const char *v8; // rbx
unsigned int v9; // eax
unsigned int v10; // ebx
int v11; // ebp
const char *v12; // r12
unsigned int v13; // eax
unsigned int v14; // eax
char v16[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc != 2 )
{
if ( argc != 3 )
{
printf("check the number of arguments");
return 0;
}
v3 = argv[1];
v4 = strcmp(v3, "m1");
if ( v4 )
{
v10 = strcmp(v3, "m2");
if ( v10 )
{
puts("Check the name of method you wrote!!! ");
return 0;
}
printf("%s", argv[2]);
v11 = 0;
if ( !strcmp(argv[2], "acc") )
{
v14 = accuracy_two();
printf("accuracy for this method is %d/1500 \n", v14);
return 0;
}
do
{
sprintf(v16, "data/%d.txt", v10);
v12 = argv[2];
v11 += strcmp(v16, v12) == 0;
++v10;
}
while ( v10 != 1499 );
if ( v11 )
{
v13 = predict(v12);
printf("the predicted value by this method is %d \n", v13);
return 0;
}
}
else
{
v5 = 0;
if ( !strcmp(argv[2], "acc") )
{
v9 = accuracy_one();
printf("accuracy for this method is %d/1500 \n", v9);
return 0;
}
do
{
sprintf(v16, "data/%d.txt", v4);
v6 = argv[2];
v5 += strcmp(v16, v6) == 0;
++v4;
}
while ( v4 != 1499 );
if ( v5 )
{
v7 = prediction(v6);
printf("the predicted value by this method is %d \n", v7);
return 0;
}
}
puts("Such file does not exist ");
return 0;
}
v8 = argv[1];
if ( !strcmp(v8, "create_tr_data") )
{
create_training_data();
}
else if ( !strcmp(v8, "break_digitwise") )
{
data_set_divide();
}
else if ( !strcmp(v8, "break_samplewise") )
{
training_data_divide();
}
else if ( !strcmp(v8, "ave_construct") )
{
ave_construct();
}
else
{
printf("Read the instructions and write again :(");
}
return 0;
}

original_code:
int main(int argc,char *argv[])
{
 int n1=0,n2=0;
 int a1=0,a2=0;
 int i,chk=0;
 char fname[16];
 if(argc==2)
 {
  if(strcmp(argv[1],"create_tr_data")==0)
  create_training_data();
  else if(strcmp(argv[1],"break_digitwise")==0)
  data_set_divide();
  else if(strcmp(argv[1],"break_samplewise")==0)
  training_data_divide();
  else if(strcmp(argv[1],"ave_construct")==0)
  ave_construct();
  else
  printf("Read the instructions and write again :(");
 }
 else if(argc==3)
 {
  if(strcmp(argv[1],"m1")==0)
  {
   if(strcmp(argv[2],"acc")==0)
   {
    n1=accuracy_one();
    printf("accuracy for this method is %d/1500 \n",n1);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n1=prediction(argv[2]);
    printf("the predicted value by this method is %d \n",n1);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else if(strcmp(argv[1],"m2")==0)
  {
   printf("%s",argv[2]);
   if(strcmp(argv[2],"acc")==0)
   {
    a2=accuracy_two();
    printf("accuracy for this method is %d/1500  \n",a2);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n2=predict(argv[2]);
    printf("the predicted value by this method is %d \n",n2);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else
  {
   printf("Check the name of method you wrote!!! \n");
  }
 }
 else
 {
  printf("check the number of arguments");
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int n1 = 0; int n2 = 0;
 int a1 = 0; int a2 = 0;
 int i; int chk = 0;
 char fname[16];
 if(argc==2)
 {
  if(strcmp(argv[1],"create_tr_data")==0)
  create_training_data();
  else if(strcmp(argv[1],"break_digitwise")==0)
  data_set_divide();
  else if(strcmp(argv[1],"break_samplewise")==0)
  training_data_divide();
  else if(strcmp(argv[1],"ave_construct")==0)
  ave_construct();
  else
  printf("Read the instructions and write again :(");
 }
 else if(argc==3)
 {
  if(strcmp(argv[1],"m1")==0)
  {
   if(strcmp(argv[2],"acc")==0)
   {
    n1=accuracy_one();
    printf("accuracy for this method is %d/1500 \n",n1);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n1=prediction(argv[2]);
    printf("the predicted value by this method is %d \n",n1);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else if(strcmp(argv[1],"m2")==0)
  {
   printf("%s",argv[2]);
   if(strcmp(argv[2],"acc")==0)
   {
    a2=accuracy_two();
    printf("accuracy for this method is %d/1500  \n",a2);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n2=predict(argv[2]);
    printf("the predicted value by this method is %d \n",n2);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else
  {
   printf("Check the name of method you wrote!!! \n");
  }
 }
 else
 {
  printf("check the number of arguments");
 }
}

variable_types: argc int

variable_types: chk int


smallest

decompiled_code:
__int64 __fastcall smallest(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 0LL;
v2 = 0;
do
{
if ( *(float *)(a1 + 4LL * (int)v2) > *(float *)(a1 + 4 * v1) )
v2 = v1;
++v1;
}
while ( v1 != 10 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 0LL;
v2 = 0;
do
{
if ( *(float *)(a1 + 4LL * (int)v2) > *(float *)(a1 + 4 * v1) )
v2 = v1;
++v1;
}
while ( v1 != 10 );
return v2;
}

original_code:
int smallest(float num[])
{
 int i,res=0;
 for(i=0;i<10;i++)
 {
  if(num[i]<num[res])
  {
   res=i;
  }
 }
 return res;
}

canonical_original_code:
int smallest(float num[])
{
 int i; int res = 0;
 for(i=0;i<10;i++)
 {
  if(num[i]<num[res])
  {
   res=i;
  }
 }
 return res;
}

variable_types:
num
float []


prediction

original_code:
int prediction(char name[])
{
 int n,i;
 float dist[10];
 dist[0]=distancesq1(name,"data/ave0.txt");
 dist[1]=distancesq1(name,"data/ave1.txt");
 dist[2]=distancesq1(name,"data/ave2.txt");
 dist[3]=distancesq1(name,"data/ave3.txt");
 dist[4]=distancesq1(name,"data/ave4.txt");
 dist[5]=distancesq1(name,"data/ave5.txt");
 dist[6]=distancesq1(name,"data/ave6.txt");
 dist[7]=distancesq1(name,"data/ave7.txt");
 dist[8]=distancesq1(name,"data/ave8.txt");
 dist[9]=distancesq1(name,"data/ave9.txt");
 n=smallest(dist);
 return n;
}

canonical_original_code:
int prediction(char name[])
{
 int n; int i;
 float dist[10];
 dist[0]=distancesq1(name,"data/ave0.txt");
 dist[1]=distancesq1(name,"data/ave1.txt");
 dist[2]=distancesq1(name,"data/ave2.txt");
 dist[3]=distancesq1(name,"data/ave3.txt");
 dist[4]=distancesq1(name,"data/ave4.txt");
 dist[5]=distancesq1(name,"data/ave5.txt");
 dist[6]=distancesq1(name,"data/ave6.txt");
 dist[7]=distancesq1(name,"data/ave7.txt");
 dist[8]=distancesq1(name,"data/ave8.txt");
 dist[9]=distancesq1(name,"data/ave9.txt");
 n=smallest(dist);
 return n;
}

variable_types:
dist
float [10]


decompiled_code:
__int64 accuracy_one()
{
unsigned int v0; // ebx
unsigned int v1; // er12
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
int v6; // ebp
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
v1 = 0;
do
{
sprintf(v8, "data/%d.txt", v0);
v6 = prediction(v8, (__int64)"data/%d.txt", v2, v3, v4, v5);
v1 += v6 == digitrec(v8);
++v0;
}
while ( v0 != 1500 );
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
unsigned int v1; // er12
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
int v6; // ebp
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
v1 = 0;
do
{
sprintf(v8, "data/%d.txt", v0);
v6 = func1(v8, (__int64)"data/%d.txt", v2, v3, v4, v5);
v1 += v6 == digitrec(v8);
++v0;
}
while ( v0 != 1500 );
return v1;
}

original_code:
int accuracy_one()
{
 int count=0,i;
 float acc;
 int n1,n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=prediction(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
  }
 return count;
}

canonical_original_code:
int accuracy_one()
{
 int count = 0; int i;
 float acc;
 int n1; int n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=prediction(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
  }
 return count;
}


fail

repo: prasad-joshi/logfsprogs

decompiled_code:
void __fastcall __noreturn fail(const char *a1)
{
printf("mklogfs: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
printf("mklogfs: %s\n", a1);
exit(1);
}

original_code:
void fail(const char *s)
{
 printf("mklogfs: %s\n", s);
 exit(1);
}

canonical_original_code:
void fail(char *s)
{
 printf("mklogfs: %s\n", s);
 exit(1);
}

variable_types:
s
char *

return_type: void


decompiled_code:
__int64 check_crc32()
{
int v0; // ebx
__int64 result; // rax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
v0 = logfs_crc32((__int64)v2, 4, 0LL);
result = _bswap_32(0xDEBB20E3);
if ( v0 != (_DWORD)result )
fail("crc32 returns bad results");
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebx
__int64 result; // rax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
v0 = func1((__int64)v2, 4, 0LL);
result = func0(0xDEBB20E3);
if ( v0 != (_DWORD)result )
func2("crc32 returns bad results");
return result;
}

original_code:
void check_crc32(void)
{
 u32 c=0;
 if (logfs_crc32(&c, 4, 0) != (( __be32)(u32)(__bswap_32 (0xdebb20e3))))
  fail("crc32 returns bad results");
}

canonical_original_code:
void check_crc32()
{
 unsigned int c = 0;
 if (logfs_crc32(&c, 4, 0) != (( __be32)(u32)(__bswap_32 (0xdebb20e3))))
  fail("crc32 returns bad results");
}

variable_types:
c
unsigned int


maxbix

decompiled_code:
__int64 __fastcall maxbix(char a1)
{
return 1LL << (9 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
return 1LL << (9 * a1);
}

original_code:
static inline u64 maxbix(u8 height)
{
 return 1ULL << ((9) * height);
}

canonical_original_code:
static inline unsigned long long maxbix(unsigned char height)
{
 return 1ULL << ((9) * height);
}

variable_types:
height
unsigned char

return_type: unsigned long long


decompiled_code:
void __fastcall grow_inode(__int64 a1, unsigned __int64 a2, char a3)
{
char v3; // bl

if ( !a3 )
{
while ( 1 )
{
v3 = *(_BYTE *)(a1 + 98);
if ( maxbix(v3) >= a2 )
break;
*(_BYTE *)(a1 + 98) = v3 + 1;
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, unsigned __int64 a2, char a3)
{
char v3; // bl

if ( !a3 )
{
while ( 1 )
{
v3 = *(_BYTE *)(a1 + 98);
if ( func3(v3) >= a2 )
break;
*(_BYTE *)(a1 + 98) = v3 + 1;
}
}
}

original_code:
static void grow_inode(struct inode *inode, u64 bix, u8 level)
{
 if (level != 0)
  return;
 while (bix > maxbix(inode->di.di_height))
  inode->di.di_height++;
}

canonical_original_code:
static void grow_inode(struct inode *inode, unsigned long long bix, unsigned char level)
{
 if (level != 0)
  return;
 while (bix > maxbix(inode->di.di_height))
  inode->di.di_height++;
}

variable_types: struct inode { struct btree_head64 { struct btree_head { unsigned long *node; int height; } h; } block_tree[-1]; struct logfs_disk_inode { unsigned short di_mode; unsigned char di_height; unsigned char di_pad; unsigned int di_flags; unsigned int di_uid; unsigned int di_gid; unsigned long long di_ctime; unsigned long long di_mtime; unsigned long long di_atime; unsigned int di_refcount; unsigned int di_generation; unsigned long long di_used_bytes; unsigned long long di_size; unsigned long long di_data[-1]; } di; } *

variable_types:
bix
unsigned long long

variable_types:
level
unsigned char

user_defined_types: struct inode { struct btree_head64 block_tree[-1]; struct logfs_disk_inode di; }

user_defined_types: struct btree_head64 { struct btree_head h; }


decompiled_code:
__int64 __fastcall btree_lookup64(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return btree_lookup(a1, &btree_geo64, &v3);
}

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

v3 = a2;
return btree_lookup(a1, &btree_geo64, &v3);
}

original_code:
static inline void *btree_lookup64(struct btree_head64 *head, u64 key)
{
 return btree_lookup(&head->h, &btree_geo64, (unsigned long *)&key);
}

canonical_original_code:
static inline void *btree_lookup64(struct btree_head64 *head, unsigned long long key)
{
 return btree_lookup(&head->h, &btree_geo64, (unsigned long *)&key);
}

variable_types: struct btree_head64 { struct btree_head { unsigned long *node; int height; } h; } *

variable_types:
key
unsigned long long

return_type: void *


zalloc

decompiled_code:
void *__fastcall zalloc(size_t n)
{
void *v1; // rax

v1 = malloc(n);
return memset(v1, 0, n);
}

canonical_decompiled_code:
void *__fastcall func6(size_t n)
{
void *v1; // rax

v1 = malloc(n);
return memset(v1, 0, n);
}

original_code:
static inline void *zalloc(size_t bytes)
{
 void *p = malloc(bytes);
 memset(p, 0, bytes);
 return p;
}

canonical_original_code:
static inline void *zalloc(unsigned long bytes)
{
 void *p = malloc(bytes);
 memset(p, 0, bytes);
 return p;
}

variable_types:
bytes
unsigned long

variable_types:
p
void *


decompiled_code:
__int64 __fastcall btree_insert64(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
return btree_insert(a1, &btree_geo64, &v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
return btree_insert(a1, &btree_geo64, &v4, a3);
}

original_code:
static inline int btree_insert64(struct btree_head64 *head, u64 key,
  void *val)
{
 return btree_insert(&head->h, &btree_geo64, (unsigned long *)&key, val);
}

canonical_original_code:
static inline int btree_insert64(struct btree_head64 *head, unsigned long long key, void *val)
{
 return btree_insert(&head->h, &btree_geo64, (unsigned long *)&key, val);
}

variable_types:
val
void *

user_defined_types: struct btree_head { unsigned long *node; int height; }


decompiled_code:
__int64 __fastcall btree_last64(__int64 a1)
{
__int64 *v1; // rax
__int64 v2; // rdx

v1 = (__int64 *)btree_last(a1, &btree_geo64);
v2 = 0LL;
if ( v1 )
v2 = *v1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 *v1; // rax
__int64 v2; // rdx

v1 = (__int64 *)btree_last(a1, &btree_geo64);
v2 = 0LL;
if ( v1 )
v2 = *v1;
return v2;
}

original_code:
static inline u64 btree_last64(struct btree_head64 *head)
{
 u64 *key;
 key = (u64 *)btree_last(&head->h, &btree_geo64);
 if (key)
  return *key;
 else
  return 0;
}

canonical_original_code:
static inline unsigned long long btree_last64(struct btree_head64 *head)
{
 unsigned long long *key;
 key = (unsigned long long *)btree_last(&head->h, &btree_geo64);
 if (key)
  return *key;
 else
  return 0;
}

variable_types:
key
unsigned long long *


decompiled_code:
__int64 __fastcall btree_remove64(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return btree_remove(a1, &btree_geo64, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return btree_remove(a1, &btree_geo64, &v3);
}

original_code:
static inline void *btree_remove64(struct btree_head64 *head, u64 key)
{
 return btree_remove(&head->h, &btree_geo64, (unsigned long *)&key);
}

canonical_original_code:
static inline void *btree_remove64(struct btree_head64 *head, unsigned long long key)
{
 return btree_remove(&head->h, &btree_geo64, (unsigned long *)&key);
}


decompiled_code:
__int64 __fastcall logfs_crc32(__int64 a1, int a2, __int64 a3)
{
int v3; // eax

v3 = crc32(0LL, a1 + a3, (unsigned int)(a2 - a3));
return _bswap_32(~v3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, __int64 a3)
{
int v3; // eax

v3 = crc32(0LL, a1 + a3, (unsigned int)(a2 - a3));
return func0(~v3);
}

original_code:
static inline __be32 logfs_crc32(void *data, size_t len, size_t skip)
{
 return (( __be32)(u32)(__bswap_32 (~crc32(0, data+skip, len-skip))));
}

canonical_original_code:
static inline unsigned int logfs_crc32(void *data, unsigned long len, unsigned long skip)
{
 return (( __be32)(u32)(__bswap_32 (~crc32(0, data+skip, len-skip))));
}

variable_types:
data
void *

variable_types:
len
unsigned long

variable_types:
skip
unsigned long

return_type: unsigned int


copybuf

decompiled_code:
void *__fastcall copybuf(__int64 a1, const void *a2, size_t a3)
{
int v3; // ebp
void *result; // rax

v3 = a3;
result = memcpy((void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 4)), a2, a3);
*(_DWORD *)(a1 + 4) += v3;
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, const void *a2, size_t a3)
{
int v3; // ebp
void *result; // rax

v3 = a3;
result = memcpy((void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 4)), a2, a3);
*(_DWORD *)(a1 + 4) += v3;
return result;
}

original_code:
static void copybuf(struct logfs_area *area, void *buf, size_t len)
{
 memcpy(area->buf + area->used_bytes, buf, len);
 area->used_bytes += len;
}

canonical_original_code:
static void copybuf(struct logfs_area *area, void *buf, unsigned long len)
{
 memcpy(area->buf + area->used_bytes, buf, len);
 area->used_bytes += len;
}

variable_types: struct logfs_area { unsigned int segno; unsigned int used_bytes; void *buf; } *

variable_types:
buf
void *


user_defined_types: struct logfs_disk_inode { unsigned short di_mode; unsigned char di_height; unsigned char di_pad; unsigned int di_flags; unsigned int di_uid; unsigned int di_gid; unsigned long long di_ctime; unsigned long long di_mtime; unsigned long long di_atime; unsigned int di_refcount; unsigned int di_generation; unsigned long long di_used_bytes; unsigned long long di_size; unsigned long long di_data[-1]; }


usage

repo: prasad-joshi/skiena

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "\nUsage:\n\t %s <#rows> <#cols>\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(stderr, "\nUsage:\n\t %s <#rows> <#cols>\n", a1);
}

original_code:
void usage(char *s)
{
 fprintf(stderr, "\nUsage:\n\t %s <#rows> <#cols>\n", s);
}

variable_types:
s
char *


decompiled_code:
void __fastcall free_board(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_board(unsigned long **board, int nrows, int ncols)
{
 free(board[0]);
 free(board);
}

variable_types:
board
unsigned long **

variable_types: nrows int

variable_types: ncols int


decompiled_code:
int __fastcall print_board_ulong(_QWORD *a1)
{
int v2; // er12
__int64 i; // rbx

puts("START");
if ( nrows > 0 )
{
v2 = 0;
do
{
for ( i = 0LL; ncols > (int)i; ++i )
printf(" %lu ", *(_QWORD *)(*a1 + 8 * i));
putchar(10);
++v2;
++a1;
}
while ( nrows > v2 );
}
return puts("END");
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1)
{
int v2; // er12
__int64 i; // rbx

puts("START");
if ( nrows > 0 )
{
v2 = 0;
do
{
for ( i = 0LL; ncols > (int)i; ++i )
printf(" %lu ", *(_QWORD *)(*a1 + 8 * i));
putchar(10);
++v2;
++a1;
}
while ( nrows > v2 );
}
return puts("END");
}

original_code:
void print_board_ulong(unsigned long **b)
{
 int i;
 int j;
 printf("START\n");
 for (i = 0; i < nrows; i++) {
  for (j = 0; j < ncols; j++) {
   printf(" %lu ", b[i][j]);
  }
  printf("\n");
 }
 printf("END\n");
}

variable_types:
b
unsigned long **

variable_types: i int

variable_types: j int


decompiled_code:
int __fastcall print_board(_QWORD *a1)
{
int v2; // ebx
int v3; // er13
__int64 i; // rbx
__int64 v5; // rsi
int v6; // ebx

if ( ncols >= -1 )
{
v2 = 0;
do
{
putchar(61);
++v2;
}
while ( 3 * ncols + 3 >= v2 );
}
putchar(10);
if ( nrows > 0 )
{
v3 = 0;
do
{
for ( i = 0LL; ncols > (int)i; ++i )
{
if ( !(_DWORD)i )
printf("| ");
v5 = *(_QWORD *)(*a1 + 8 * i);
if ( v5 )
printf(" %c ", v5);
else
printf(" %lu ", 0LL);
if ( ncols - 1 == (_DWORD)i )
printf(" |");
}
putchar(10);
++v3;
++a1;
}
while ( nrows > v3 );
}
if ( ncols >= -1 )
{
v6 = 0;
do
{
putchar(61);
++v6;
}
while ( 3 * ncols + 3 >= v6 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(_QWORD *a1)
{
int v2; // ebx
int v3; // er13
__int64 i; // rbx
__int64 v5; // rsi
int v6; // ebx

if ( ncols >= -1 )
{
v2 = 0;
do
{
putchar(61);
++v2;
}
while ( 3 * ncols + 3 >= v2 );
}
putchar(10);
if ( nrows > 0 )
{
v3 = 0;
do
{
for ( i = 0LL; ncols > (int)i; ++i )
{
if ( !(_DWORD)i )
printf("| ");
v5 = *(_QWORD *)(*a1 + 8 * i);
if ( v5 )
printf(" %c ", v5);
else
printf(" %lu ", 0LL);
if ( ncols - 1 == (_DWORD)i )
printf(" |");
}
putchar(10);
++v3;
++a1;
}
while ( nrows > v3 );
}
if ( ncols >= -1 )
{
v6 = 0;
do
{
putchar(61);
++v6;
}
while ( 3 * ncols + 3 >= v6 );
}
return putchar(10);
}

original_code:
void print_board(unsigned long **board)
{
 int i;
 int j;
 for (i = 0; i < ncols * 3 + 4; i++) {
  printf("=");
 }
 printf("\n");
 for (i = 0; i < nrows; i++) {
  for (j = 0; j < ncols; j++) {
   if (j == 0) {
    printf("| ");
   }
   if (board[i][j] != 0) {
    printf(" %c ", (int) board[i][j]);
   } else {
    printf(" %lu ", board[i][j]);
   }
   if (j == ncols - 1) {
    printf(" |");
   }
  }
  printf("\n");
 }
 for (i = 0; i < ncols * 3 + 4; i++) {
  printf("=");
 }
 printf("\n");
}


decompiled_code:
__int64 __fastcall next_direction(int a1)
{
return a1 + (unsigned int)(a1 != 9);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return a1 + (unsigned int)(a1 != 9);
}

original_code:
DIRECTION next_direction(DIRECTION d)
{
 return ((d == INVAL) ? INVAL : ++d);
}

canonical_original_code:
enum DIRECTION next_direction(enum DIRECTION d)
{
 return ((d == INVAL) ? INVAL : ++d);
}

variable_types: enum DIRECTION { START=0, ULD=1, ULU=2, URU=3, URD=4, DLU=5, DLD=6, DRD=7, DRU=8, INVAL=9 }


decompiled_code:
__int64 __fastcall traverse_done(_QWORD **a1)
{
_QWORD **v1; // rcx
_QWORD *v2; // rax

if ( nrows <= 0 )
return 1LL;
v1 = a1;
while ( ncols <= 0 )
{
LABEL_7:
if ( ++v1 == &a1[(unsigned int)(nrows - 1) + 1] )
return 1LL;
}
v2 = *v1;
while ( *v2 )
{
if ( ++v2 == &(*v1)[(unsigned int)(ncols - 1) + 1] )
goto LABEL_7;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD **a1)
{
_QWORD **v1; // rcx
_QWORD *v2; // rax

if ( nrows <= 0 )
return 1LL;
v1 = a1;
while ( ncols <= 0 )
{
LABEL_7:
if ( ++v1 == &a1[(unsigned int)(nrows - 1) + 1] )
return 1LL;
}
v2 = *v1;
while ( *v2 )
{
if ( ++v2 == &(*v1)[(unsigned int)(ncols - 1) + 1] )
goto LABEL_7;
}
return 0LL;
}

original_code:
int traverse_done(unsigned long **board)
{
 int i;
 int j;
 for (i = 0; i < nrows; i++) {
  for (j = 0; j < ncols; j++) {
   if (board[i][j] == 0) {
    return (0);
   }
  }
 }
 return (1);
}


decompiled_code:
__int64 __fastcall set_board_position(__int64 a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8LL * a2);
*(_QWORD *)(result + 8LL * a3) = (a5 << 8) | (a4 << 16) | 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8LL * a2);
*(_QWORD *)(result + 8LL * a3) = (a5 << 8) | (a4 << 16) | 1;
return result;
}

original_code:
void set_board_position(unsigned long **board, int row, int col, int nr, int nc)
{
 board[row][col] = (nr << 16 | nc << 8 | 1);
}

variable_types: row int

variable_types: col int

variable_types: nr int

variable_types: nc int


decompiled_code:
__int64 __fastcall traverse_board(_QWORD **a1, int a2, int a3, int a4)
{
_QWORD *v6; // r15
__int64 v7; // r14
__int64 result; // rax
int v9; // eax
__int64 v10; // [rsp+8h] [rbp-50h]
int v11; // [rsp+18h] [rbp-40h] BYREF
int v12[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v6 = &a1[a2];
v7 = a3;
v10 = 8LL * a3;
*(_QWORD *)(*v6 + v10) = 1LL;
result = traverse_done(a1);
if ( (_DWORD)result == 1 )
{
++count;
}
else
{
*(_QWORD *)(*v6 + 8 * v7) = 0LL;
while ( 1 )
{
v9 = next_direction(a4);
a4 = v9;
if ( v9 == 9 )
break;
v12[0] = a2;
v11 = a3;
next_index(v9, v12, &v11);
if ( v12[0] >= 0 && v12[0] < nrows && v11 >= 0 && v11 < ncols && !a1[v12[0]][v11] )
{
set_board_position((__int64)a1, a2, a3, v12[0], v11);
result = traverse_board(a1, (unsigned int)v12[0], (unsigned int)v11, 0LL);
if ( (_DWORD)result == 1 )
return result;
*(_QWORD *)(*v6 + v10) = 0LL;
}
}
result = 0LL;
}
return result;
}

original_code:
int traverse_board(unsigned long **board, int row, int col, DIRECTION dir)
{
 int r;
 int c;
 board[row][col] = 1;
 if (traverse_done(board) == 1) {
  count++;
  return (1);
 }
 board[row][col] = 0;
 while ((dir = next_direction(dir)) != INVAL) {
  r = row;
  c = col;
  next_index(dir, &r, &c);
  if ((((r) >= 0 && (r) < (nrows) && (c) >= 0 && (c) < (ncols)) ? 1 : 0) == 0) {
   continue;
  }
  if (board[r][c] != 0) {
   continue;
  }
  set_board_position(board, row, col, r, c);
  if (traverse_board(board, r, c, START) == 1) {
   return (1);
  }
  board[row][col] = 0;
 }
 return (0);
}

canonical_original_code:
int traverse_board(unsigned long **board, int row, int col, enum DIRECTION dir)
{
 int r;
 int c;
 board[row][col] = 1;
 if (traverse_done(board) == 1) {
  count++;
  return (1);
 }
 board[row][col] = 0;
 while ((dir = next_direction(dir)) != INVAL) {
  r = row;
  c = col;
  next_index(dir, &r, &c);
  if ((((r) >= 0 && (r) < (nrows) && (c) >= 0 && (c) < (ncols)) ? 1 : 0) == 0) {
   continue;
  }
  if (board[r][c] != 0) {
   continue;
  }
  set_board_position(board, row, col, r, c);
  if (traverse_board(board, r, c, START) == 1) {
   return (1);
  }
  board[row][col] = 0;
 }
 return (0);
}

variable_types: r int

variable_types: c int

user_defined_types: enum DIRECTION { START=0, ULD=1, ULU=2, URU=3, URD=4, DLU=5, DLD=6, DRD=7, DRU=8, INVAL=9 }


decompiled_code:
void __fastcall knight_tour(__int64 a1, int a2, int a3)
{
int v3; // er12
_QWORD *v5; // rax
_QWORD *v6; // rbp
int v7; // ebx
int v8; // [rsp+8h] [rbp-30h] BYREF
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = a2;
v5 = allocate_board(nrows, ncols);
if ( !v5 )
__assert_fail("b != NULL", "knight_tour.c", 0xEFu, "knight_tour");
v6 = v5;
*(_QWORD *)(v5[a2] + 8LL * a3) = 75LL;
print_board(v5);
if ( ncols * nrows > 1 )
{
v7 = 1;
do
{
get_board_position(a1, v3, a3, v9, &v8);
*(_QWORD *)(v6[v9[0]] + 8LL * v8) = 75LL;
print_board(v6);
v3 = v9[0];
a3 = v8;
++v7;
}
while ( ncols * nrows > v7 );
}
free_board(v6);
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, int a2, int a3)
{
int v3; // er12
_QWORD *v5; // rax
_QWORD *v6; // rbp
int v7; // ebx
int v8; // [rsp+8h] [rbp-30h] BYREF
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = a2;
v5 = allocate_board(nrows, ncols);
if ( !v5 )
__assert_fail("b != NULL", "knight_tour.c", 0xEFu, "knight_tour");
v6 = v5;
*(_QWORD *)(v5[a2] + 8LL * a3) = 75LL;
func10(v5);
if ( ncols * nrows > 1 )
{
v7 = 1;
do
{
func15(a1, v3, a3, v9, &v8);
*(_QWORD *)(v6[v9[0]] + 8LL * v8) = 75LL;
func10(v6);
v3 = v9[0];
a3 = v8;
++v7;
}
while ( ncols * nrows > v7 );
}
func8(v6);
}

original_code:
void knight_tour(unsigned long **board, int r, int c)
{
 unsigned long **b;
 int n;
 int nr;
 int nc;
 b = allocate_board(nrows, ncols);
 ((void) sizeof ((b != ((void *)0)) ? 1 : 0), __extension__ ({ if (b != ((void *)0)) ; else __assert_fail ("b != NULL", "knight_tour.c", 239, __extension__ __PRETTY_FUNCTION__); }));
 b[r][c] = 'K';
 print_board(b);
 for (n = 1; n < nrows * ncols; n++) {
  get_board_position(board, r, c, &nr, &nc);
  b[nr][nc] = 'K';
  print_board(b);
  r = nr;
  c = nc;
 }
 free_board(b, nrows, ncols);
}

variable_types: n int


decompiled_code:
_BOOL8 __fastcall sll_is_empty(_QWORD *a1)
{
if ( !a1 )
__assert_fail("headp", "sll.c", 0xEu, "sll_is_empty");
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_QWORD *a1)
{
if ( !a1 )
__assert_fail("headp", "sll.c", 0xEu, "sll_is_empty");
return *a1 == 0LL;
}

original_code:
int sll_is_empty(sll_t *headp)
{
 ((void) sizeof ((headp) ? 1 : 0), __extension__ ({ if (headp) ; else __assert_fail ("headp", "sll.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 return headp->next == ((void *)0);
}

canonical_original_code:
int sll_is_empty(struct sll *headp)
{
 ((void) sizeof ((headp) ? 1 : 0), __extension__ ({ if (headp) ; else __assert_fail ("headp", "sll.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 return headp->next == ((void *)0);
}

variable_types:
headp
struct sll { struct sll *next; } *


decompiled_code:
__int64 __fastcall sll_next(__int64 a1)
{
if ( !a1 )
__assert_fail("nodep", "sll.c", 0x2Cu, "sll_next");
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( !a1 )
__assert_fail("nodep", "sll.c", 0x2Cu, "sll_next");
return *(_QWORD *)a1;
}

original_code:
sll_t *sll_next(sll_t *nodep)
{
 ((void) sizeof ((nodep) ? 1 : 0), __extension__ ({ if (nodep) ; else __assert_fail ("nodep", "sll.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 return nodep->next;
}

canonical_original_code:
struct sll *sll_next(struct sll *nodep)
{
 ((void) sizeof ((nodep) ? 1 : 0), __extension__ ({ if (nodep) ; else __assert_fail ("nodep", "sll.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 return nodep->next;
}

variable_types:
nodep
struct sll *

return_type: struct sll { struct sll *next; } *


decompiled_code:
_BOOL8 basic_test()
{
unsigned int i; // ebx
__int64 *v1; // rsi
int v2; // ebx
_DWORD *v3; // rdi
int v4; // ebp
_DWORD *v5; // rdi
int v6; // ebp
int v7; // ebp
_DWORD *v8; // rdi
int v9; // er12
_DWORD *v10; // rdi
int v11; // er12
_BOOL8 result; // rax
__int64 v13; // [rsp+8h] [rbp-30h] BYREF
void *ptr; // [rsp+10h] [rbp-28h] BYREF
__int64 v15[4]; // [rsp+18h] [rbp-20h] BYREF

sll_init(v15);
if ( !sll_is_empty(v15) )
__assert_fail("rc != 0", "test-sll.c", 0x2Au, "basic_test");
for ( i = 0; i != 50000; ++i )
{
v1 = (__int64 *)tst_basic_new(i);
if ( !v1 )
__assert_fail("np != NULL", "test-sll.c", 0x2Eu, "basic_test");
sll_insert_head(v15, v1);
if ( sll_is_empty(v15) )
__assert_fail("rc == 0", "test-sll.c", 0x33u, "basic_test");
v13 = 0LL;
sll_get_mid((_QWORD **)v15, &v13);
if ( !v13 )
__assert_fail("midp != NULL", "test-sll.c", 0x37u, "basic_test");
if ( *(_DWORD *)(v13 + 8) != i >> 1 )
__assert_fail("np->number == (i >> 1)", "test-sll.c", 0x39u, "basic_test");
}
v2 = 10;
do
{
v3 = (_DWORD *)sll_next((__int64)v15);
ptr = v3;
if ( v3 )
{
v4 = 49999;
do
{
if ( v3[2] != v4 )
__assert_fail("np->number == i", "test-sll.c", 0x42u, "basic_test");
--v4;
v3 = (_DWORD *)sll_next((__int64)v3);
ptr = v3;
}
while ( v3 );
}
sll_reverse((_QWORD **)v15);
v5 = (_DWORD *)sll_next((__int64)v15);
ptr = v5;
if ( v5 )
{
v6 = 0;
do
{
if ( v5[2] != v6 )
__assert_fail("np->number == i", "test-sll.c", 0x4Du, "basic_test");
++v6;
v5 = (_DWORD *)sll_next((__int64)v5);
ptr = v5;
}
while ( v5 );
}
sll_reverse_recursive(v15);
--v2;
}
while ( v2 );
v7 = 10;
do
{
v8 = (_DWORD *)sll_next((__int64)v15);
ptr = v8;
if ( v8 )
{
v9 = 49999;
do
{
if ( v8[2] != v9 )
__assert_fail("np->number == i", "test-sll.c", 0x5Bu, "basic_test");
--v9;
v8 = (_DWORD *)sll_next((__int64)v8);
ptr = v8;
}
while ( v8 );
}
sll_reverse_recursive(v15);
v10 = (_DWORD *)sll_next((__int64)v15);
ptr = v10;
if ( v10 )
{
v11 = 0;
do
{
if ( v10[2] != v11 )
__assert_fail("np->number == i", "test-sll.c", 0x66u, "basic_test");
++v11;
v10 = (_DWORD *)sll_next((__int64)v10);
ptr = v10;
}
while ( v10 );
}
sll_reverse((_QWORD **)v15);
--v7;
}
while ( v7 );
while ( 1 )
{
result = sll_is_empty(v15);
if ( result )
break;
ptr = 0LL;
sll_delete_head((_QWORD **)v15, &ptr);
if ( !ptr )
__assert_fail("l != NULL", "test-sll.c", 0x71u, "basic_test");
free(ptr);
}
return result;
}

canonical_decompiled_code:
_BOOL8 func13()
{
unsigned int i; // ebx
__int64 *v1; // rsi
int v2; // ebx
_DWORD *v3; // rdi
int v4; // ebp
_DWORD *v5; // rdi
int v6; // ebp
int v7; // ebp
_DWORD *v8; // rdi
int v9; // er12
_DWORD *v10; // rdi
int v11; // er12
_BOOL8 result; // rax
__int64 v13; // [rsp+8h] [rbp-30h] BYREF
void *ptr; // [rsp+10h] [rbp-28h] BYREF
__int64 v15[4]; // [rsp+18h] [rbp-20h] BYREF

func8(v15);
if ( !func9(v15) )
__assert_fail("rc != 0", "test-sll.c", 0x2Au, "basic_test");
for ( i = 0; i != 50000; ++i )
{
v1 = (__int64 *)tst_basic_new(i);
if ( !v1 )
__assert_fail("np != NULL", "test-sll.c", 0x2Eu, "basic_test");
func10(v15, v1);
if ( func9(v15) )
__assert_fail("rc == 0", "test-sll.c", 0x33u, "basic_test");
v13 = 0LL;
func12((_QWORD **)v15, &v13);
if ( !v13 )
__assert_fail("midp != NULL", "test-sll.c", 0x37u, "basic_test");
if ( *(_DWORD *)(v13 + 8) != i >> 1 )
__assert_fail("np->number == (i >> 1)", "test-sll.c", 0x39u, "basic_test");
}
v2 = 10;
do
{
v3 = (_DWORD *)func11((__int64)v15);
ptr = v3;
if ( v3 )
{
v4 = 49999;
do
{
if ( v3[2] != v4 )
__assert_fail("np->number == i", "test-sll.c", 0x42u, "basic_test");
--v4;
v3 = (_DWORD *)func11((__int64)v3);
ptr = v3;
}
while ( v3 );
}
sll_reverse((_QWORD **)v15);
v5 = (_DWORD *)func11((__int64)v15);
ptr = v5;
if ( v5 )
{
v6 = 0;
do
{
if ( v5[2] != v6 )
__assert_fail("np->number == i", "test-sll.c", 0x4Du, "basic_test");
++v6;
v5 = (_DWORD *)func11((__int64)v5);
ptr = v5;
}
while ( v5 );
}
func7(v15);
--v2;
}
while ( v2 );
v7 = 10;
do
{
v8 = (_DWORD *)func11((__int64)v15);
ptr = v8;
if ( v8 )
{
v9 = 49999;
do
{
if ( v8[2] != v9 )
__assert_fail("np->number == i", "test-sll.c", 0x5Bu, "basic_test");
--v9;
v8 = (_DWORD *)func11((__int64)v8);
ptr = v8;
}
while ( v8 );
}
func7(v15);
v10 = (_DWORD *)func11((__int64)v15);
ptr = v10;
if ( v10 )
{
v11 = 0;
do
{
if ( v10[2] != v11 )
__assert_fail("np->number == i", "test-sll.c", 0x66u, "basic_test");
++v11;
v10 = (_DWORD *)func11((__int64)v10);
ptr = v10;
}
while ( v10 );
}
sll_reverse((_QWORD **)v15);
--v7;
}
while ( v7 );
while ( 1 )
{
result = func9(v15);
if ( result )
break;
ptr = 0LL;
sll_delete_head((_QWORD **)v15, &ptr);
if ( !ptr )
__assert_fail("l != NULL", "test-sll.c", 0x71u, "basic_test");
free(ptr);
}
return result;
}

original_code:
static void basic_test(void)
{
 const uint32_t NODES = 50000;
 sll_t head;
 int rc;
 struct tst_basic *np;
 sll_t *l;
 sll_t *midp;
 uint32_t n;
 uint32_t i;
 uint32_t j;
 sll_init(&head);
 rc = sll_is_empty(&head);
 ((void) sizeof ((rc != 0) ? 1 : 0), __extension__ ({ if (rc != 0) ; else __assert_fail ("rc != 0", "test-sll.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < NODES; i++) {
  np = tst_basic_new(i);
  ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 46, __extension__ __PRETTY_FUNCTION__); }));
  sll_insert_head(&head, &np->list);
  rc = sll_is_empty(&head);
  ((void) sizeof ((rc == 0) ? 1 : 0), __extension__ ({ if (rc == 0) ; else __assert_fail ("rc == 0", "test-sll.c", 51, __extension__ __PRETTY_FUNCTION__); }));
  midp = ((void *)0);
  sll_get_mid(&head, &midp);
  ((void) sizeof ((midp != ((void *)0)) ? 1 : 0), __extension__ ({ if (midp != ((void *)0)) ; else __assert_fail ("midp != NULL", "test-sll.c", 55, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) midp) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
  ((void) sizeof ((np->number == (i >> 1)) ? 1 : 0), __extension__ ({ if (np->number == (i >> 1)) ; else __assert_fail ("np->number == (i >> 1)", "test-sll.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 65, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 76, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 77, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 90, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 91, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 101, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 102, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse(&head);
 }
 while (sll_is_empty(&head) == 0) {
  l = ((void *)0);
  sll_delete_head(&head, &l);
  ((void) sizeof ((l != ((void *)0)) ? 1 : 0), __extension__ ({ if (l != ((void *)0)) ; else __assert_fail ("l != NULL", "test-sll.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) l) - ((size_t)(&(((struct tst_basic *) 0)->list)))));
  free(np);
 }
}

canonical_original_code:
static void basic_test()
{
 unsigned int NODES = 50000;
 struct sll head;
 int rc;
 struct tst_basic *np;
 struct sll *l;
 struct sll *midp;
 unsigned int n;
 unsigned int i;
 unsigned int j;
 sll_init(&head);
 rc = sll_is_empty(&head);
 ((void) sizeof ((rc != 0) ? 1 : 0), __extension__ ({ if (rc != 0) ; else __assert_fail ("rc != 0", "test-sll.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i < NODES; i++) {
  np = tst_basic_new(i);
  ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 46, __extension__ __PRETTY_FUNCTION__); }));
  sll_insert_head(&head, &np->list);
  rc = sll_is_empty(&head);
  ((void) sizeof ((rc == 0) ? 1 : 0), __extension__ ({ if (rc == 0) ; else __assert_fail ("rc == 0", "test-sll.c", 51, __extension__ __PRETTY_FUNCTION__); }));
  midp = ((void *)0);
  sll_get_mid(&head, &midp);
  ((void) sizeof ((midp != ((void *)0)) ? 1 : 0), __extension__ ({ if (midp != ((void *)0)) ; else __assert_fail ("midp != NULL", "test-sll.c", 55, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) midp) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
  ((void) sizeof ((np->number == (i >> 1)) ? 1 : 0), __extension__ ({ if (np->number == (i >> 1)) ; else __assert_fail ("np->number == (i >> 1)", "test-sll.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 65, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 66, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 76, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 77, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
 }
 for (j = 0; j < 10; j++) {
  i = NODES - 1;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 90, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 91, __extension__ __PRETTY_FUNCTION__); }));
   i--;
   l = sll_next(l);
  }
  sll_reverse_recursive(&head);
  i = 0;
  l = sll_next(&head);
  while (l != ((void *)0)) {
   np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
   ((void) sizeof ((np != ((void *)0)) ? 1 : 0), __extension__ ({ if (np != ((void *)0)) ; else __assert_fail ("np != NULL", "test-sll.c", 101, __extension__ __PRETTY_FUNCTION__); }));
   ((void) sizeof ((np->number == i) ? 1 : 0), __extension__ ({ if (np->number == i) ; else __assert_fail ("np->number == i", "test-sll.c", 102, __extension__ __PRETTY_FUNCTION__); }));
   i++;
   l = sll_next(l);
  }
  sll_reverse(&head);
 }
 while (sll_is_empty(&head) == 0) {
  l = ((void *)0);
  sll_delete_head(&head, &l);
  ((void) sizeof ((l != ((void *)0)) ? 1 : 0), __extension__ ({ if (l != ((void *)0)) ; else __assert_fail ("l != NULL", "test-sll.c", 113, __extension__ __PRETTY_FUNCTION__); }));
  np = ((struct tst_basic *) (((char *) l) - ((unsigned long)(&(((struct tst_basic *) 0)->list)))));
  free(np);
 }
}

variable_types:
NODES
unsigned int

variable_types:
head
struct sll { struct sll *next; }

variable_types: rc int

variable_types: struct tst_basic { struct sll { struct sll *next; } list; unsigned int number; } *

variable_types:
l
struct sll { struct sll *next; } *

variable_types:
midp
struct sll { struct sll *next; } *

variable_types:
n
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

user_defined_types: struct tst_basic { struct sll list; unsigned int number; }


main

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

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

original_code:
int main(void)
{
 basic_test();
 return 0;
}

canonical_original_code:
int main()
{
 basic_test();
 return 0;
}


decompiled_code:
__int64 __fastcall add_tail(_QWORD *a1, _QWORD **a2, __int64 a3)
{
_QWORD *v4; // r13
_QWORD *v5; // r14
_QWORD *v6; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v4 = (_QWORD *)*a1;
v5 = *a2;
v6 = get_new();
if ( !v6 )
return 0xFFFFFFFFLL;
v6[1] = a3;
if ( v4 )
*v5 = v6;
else
v4 = v6;
*a1 = v4;
*a2 = v6;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, _QWORD **a2, __int64 a3)
{
_QWORD *v4; // r13
_QWORD *v5; // r14
_QWORD *v6; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v4 = (_QWORD *)*a1;
v5 = *a2;
v6 = func7();
if ( !v6 )
return 0xFFFFFFFFLL;
v6[1] = a3;
if ( v4 )
*v5 = v6;
else
v4 = v6;
*a1 = v4;
*a2 = v6;
return 0LL;
}

original_code:
static int add_tail(struct list **head, struct list **tail, void *data)
{
 struct list *h;
 struct list *t;
 struct list *n;
 if (head == ((void *)0) || tail == ((void *)0)) {
  return (-1);
 }
 h = *head;
 t = *tail;
 n = get_new();
 if (n == ((void *)0)) {
  return (-1);
 }
 n->data = data;
 if (h == ((void *)0)) {
  t = h = n;
 } else {
  t->next = n;
  t = n;
 }
 *head = h;
 *tail = t;
 return (0);
}

variable_types: struct list { struct list *next; void *data; } **

variable_types:
tail
struct list **

variable_types:
data
void *


decompiled_code:
__int64 __fastcall is_empty(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 )
{
if ( !a1[1] )
__assert_fail("queue->rear != NULL", "queue.c", 0x57u, "is_empty");
result = 0LL;
}
else
{
if ( a1[1] )
__assert_fail("queue->rear == NULL", "queue.c", 0x53u, "is_empty");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 )
{
if ( !a1[1] )
__assert_fail("queue->rear != NULL", "queue.c", 0x57u, "is_empty");
result = 0LL;
}
else
{
if ( a1[1] )
__assert_fail("queue->rear == NULL", "queue.c", 0x53u, "is_empty");
result = 1LL;
}
return result;
}

original_code:
int is_empty(struct queue *queue)
{
 if (queue->front == ((void *)0)) {
  ((void) sizeof ((queue->rear == ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->rear == ((void *)0)) ; else __assert_fail ("queue->rear == NULL", "queue.c", 83, __extension__ __PRETTY_FUNCTION__); }));
  return (1);
 }
 ((void) sizeof ((queue->rear != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue->rear != ((void *)0)) ; else __assert_fail ("queue->rear != NULL", "queue.c", 87, __extension__ __PRETTY_FUNCTION__); }));
 return (0);
}

variable_types: struct queue { struct list { struct list *next; void *data; } *front; struct list *rear; } *

user_defined_types: struct queue { struct list *front; struct list *rear; }


enqueue

decompiled_code:
__int64 __fastcall enqueue(__int64 a1, __int64 a2)
{
return add_tail((_QWORD *)a1, (_QWORD **)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
return func8((_QWORD *)a1, (_QWORD **)(a1 + 8), a2);
}

original_code:
int enqueue(struct queue *queue, void *data)
{
 return (add_tail(&queue->front, &queue->rear, data));
}

user_defined_types: struct list { struct list *next; void *data; }


dequeue

decompiled_code:
__int64 __fastcall dequeue(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rbx

v1 = remove_head((_QWORD **)a1, (__int64 *)(a1 + 8));
if ( !v1 )
return 0LL;
v2 = v1[1];
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rbx

v1 = remove_head((_QWORD **)a1, (__int64 *)(a1 + 8));
if ( !v1 )
return 0LL;
v2 = v1[1];
free(v1);
return v2;
}

original_code:
void *dequeue(struct queue *queue)
{
 struct list *l = remove_head(&queue->front, &queue->rear);
 void *data = ((void *)0);
 if (l == ((void *)0)) {
  return (((void *)0));
 }
 data = l->data;
 free(l);
 return (data);
}

variable_types: struct list { struct list *next; void *data; } *


decompiled_code:
__int64 __fastcall next_direction(int a1)
{
return a1 + (unsigned int)(a1 != 4);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return a1 + (unsigned int)(a1 != 4);
}

variable_types: enum DIRECTION { START=0, ULD=1, ULU=2, URU=3, URD=4, DLU=5, DLD=6, DRD=7, DRU=8, INVAL=9 }


print

decompiled_code:
int __fastcall print(__int64 a1, int a2, int a3)
{
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // r14
__int64 v7; // r12
_BYTE *v8; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = (unsigned int)(a3 - 1);
v5 = a1 + v4 + 1;
v6 = a1 + v4 + 11 + 10LL * (unsigned int)(a2 - 1);
v7 = ~v4;
do
{
v8 = (_BYTE *)(v7 + v5);
if ( a3 > 0 )
{
do
{
if ( *v8 == 80 )
printf(" %c ", 80LL);
else
printf(" *%c* ", (unsigned int)(char)*v8);
++v8;
}
while ( v8 != (_BYTE *)v5 );
}
result = putchar(10);
v5 += 10LL;
}
while ( v5 != v6 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(__int64 a1, int a2, int a3)
{
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // r14
__int64 v7; // r12
_BYTE *v8; // rbx
int result; // eax

if ( a2 > 0 )
{
v4 = (unsigned int)(a3 - 1);
v5 = a1 + v4 + 1;
v6 = a1 + v4 + 11 + 10LL * (unsigned int)(a2 - 1);
v7 = ~v4;
do
{
v8 = (_BYTE *)(v7 + v5);
if ( a3 > 0 )
{
do
{
if ( *v8 == 80 )
printf(" %c ", 80LL);
else
printf(" *%c* ", (unsigned int)(char)*v8);
++v8;
}
while ( v8 != (_BYTE *)v5 );
}
result = putchar(10);
v5 += 10LL;
}
while ( v5 != v6 );
}
return result;
}

original_code:
void print(char arr[][10], int nrow, int ncol)
{
 int i;
 int j;
 for (i = 0; i < nrow; i++) {
  for (j = 0; j < ncol; j++) {
   if (arr[i][j] == 'P') {
   printf("  %c  ", arr[i][j]);
   } else {
   printf(" *%c* ", arr[i][j]);
   }
  }
  printf("\n");
 }
}

variable_types:
arr
char [][10]

variable_types: nrow int

variable_types: ncol int

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall Mem_Init(int a1, int a2)
{
int v3; // edi
float v4; // xmm0_4
int v5; // eax
__int64 result; // rax

globalDebug = a2;
v3 = getpagesize();
v4 = (float)(a1 % v3);
if ( v4 != 0.0 )
a1 = (int)(float)((float)(a1 + v3) - v4);
v5 = open("/dev/zero", 2);
result = (__int64)mmap(0LL, a1, 3, 2, v5, 0LL);
if ( result == -1 )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 4) = 0LL;
Head = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, int a2)
{
int v3; // edi
float v4; // xmm0_4
int v5; // eax
__int64 result; // rax

globalDebug = a2;
v3 = getpagesize();
v4 = (float)(a1 % v3);
if ( v4 != 0.0 )
a1 = (int)(float)((float)(a1 + v3) - v4);
v5 = open("/dev/zero", 2);
result = (__int64)mmap(0LL, a1, 3, 2, v5, 0LL);
if ( result == -1 )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 4) = 0LL;
Head = result;
}
return result;
}

original_code:
int Mem_Init(int sizeOfRegion,int debug)
{
globalDebug=debug;
int size;
float remainder;
int multiple=getpagesize();
remainder=sizeOfRegion % multiple;
 if ( remainder==0.0f )
   {size=sizeOfRegion;}
 else
    {size=sizeOfRegion+multiple-remainder;}
int fd =open("/dev/zero",02);
list *ptr =mmap(((void *)0),size, 0x1 | 0x2,0x02,fd,0);
 if(ptr == ((void *) -1))
 {
  perror("mmap");
  return -1;
 }
ptr->size=size;
ptr->next=((void *)0);
Head = ptr;
}

canonical_original_code:
int Mem_Init(int sizeOfRegion, int debug)
{
globalDebug=debug;
int size;
float remainder;
int multiple = getpagesize();
remainder=sizeOfRegion % multiple;
 if ( remainder==0.0f )
   {size=sizeOfRegion;}
 else
    {size=sizeOfRegion+multiple-remainder;}
int fd = open("/dev/zero",02);
struct freelist *ptr = mmap(((void *)0),size, 0x1 | 0x2,0x02,fd,0);
 if(ptr == ((void *) -1))
 {
  perror("mmap");
  return -1;
 }
ptr->size=size;
ptr->next=((void *)0);
Head = ptr;
}

variable_types: sizeOfRegion int

variable_types: debug int

variable_types: size int

variable_types: remainder float

variable_types: multiple int

variable_types: fd int

variable_types: struct freelist { int size; struct freelist *next; } *


original_code:
int Mem_Free(void *ptr)
{
list * header = (void *) ptr - sizeof(list);
list * traverse=Head;
list * trav_alloc=allocHead;
while(trav_alloc!=((void *)0))
{
 if(header == allocHead)
 {
  allocHead=allocHead->next;
  header->next=((void *)0);
  break;
 }
        else if((trav_alloc->next) == header)
 {
  trav_alloc->next=header->next;
  header->next=((void *)0);
  break;
 }
trav_alloc=trav_alloc->next;
}
int size_to_free= header->size;
int k=0;
while( (traverse!=((void *)0)) )
{
list * traverse_next= traverse->next;
  if(k==0)
  {
   if ( size_to_free < (traverse->size))
   {
    header->next=Head;
    Head=header;
   }
   else if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
  else
  {
   if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
traverse=traverse->next;
k++;
}
list * lhead=Head;
list *prev_lhead=Head;
int i=0;
int service=0;
list* saveList;
list* savePrev;
while(lhead!=((void *)0))
{
int isHead=0;
int isGreater=0;
list * trav=Head;
list * prev_trav=Head;
int sizetemp = lhead->size;
 int j=0;
 while(trav!=((void *)0))
 { list * temp =lhead;
  if( ( ((void*)temp+sizeof(list)+ sizetemp) == ((void*)trav)) )
  {
      if(i>j)
      {
     if( trav == prev_trav)
     {
       Head=Head->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
     else
     {
       prev_trav->next= trav->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
    }
      else if(i<j)
      {
    if (((lhead)->next) == trav )
    {
     lhead->next=trav->next;
     trav->next=((void *)0);
     lhead->size= lhead->size + trav->size + sizeof(list);
     service=1;
    }
    else
    {
     prev_trav->next= trav->next;
     trav->next=((void *)0);
     lhead->size= trav->size + lhead->size + sizeof(list);
     service=1;
    }
     }
   if(lhead==Head)
   {isHead=1;}
  if((lhead->next)!=((void *)0))
   {if( (lhead->size)> (lhead->next->size))
    {isGreater=1;}
    saveList=lhead;
    savePrev=prev_lhead;}
  }
  if(j!=0)
  {prev_trav = prev_trav->next;}
  trav=trav->next;
  j++;
 }
if(i!=0)
{ prev_lhead =prev_lhead->next; }
lhead= lhead-> next;
i++;
if(service ==1)
{
int complete=0;
list* tra=saveList;
list* tra_prev=saveList;
int sizecomp= saveList->size;
int count=0;
while((tra!=((void *)0)) && (complete==0))
{
 if((isHead==1) && (isGreater==1))
 {
  if(sizecomp < (tra->size) )
  {
   Head=Head->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
 else if((isHead==0) && (isGreater==1))
 {
  if(sizecomp < (tra->size))
  {
   savePrev->next=saveList->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
tra=tra->next;
if(count!=0)
{tra_prev=tra_prev->next;}
count++;
}
lhead=Head;
prev_lhead=Head;
i=0;
}
service=0;
}
}

canonical_original_code:
int Mem_Free(void *ptr)
{
struct freelist *header = (void *) ptr - sizeof(list);
struct freelist *traverse = Head;
struct freelist *trav_alloc = allocHead;
while(trav_alloc!=((void *)0))
{
 if(header == allocHead)
 {
  allocHead=allocHead->next;
  header->next=((void *)0);
  break;
 }
        else if((trav_alloc->next) == header)
 {
  trav_alloc->next=header->next;
  header->next=((void *)0);
  break;
 }
trav_alloc=trav_alloc->next;
}
int size_to_free = header->size;
int k = 0;
while( (traverse!=((void *)0)) )
{
struct freelist *traverse_next = traverse->next;
  if(k==0)
  {
   if ( size_to_free < (traverse->size))
   {
    header->next=Head;
    Head=header;
   }
   else if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
  else
  {
   if(((size_to_free) > (traverse->size)) && ( (size_to_free) <= (traverse_next->size) ))
   {
    traverse->next= header;
    header->next=traverse_next;
   }
  }
traverse=traverse->next;
k++;
}
struct freelist *lhead = Head;
struct freelist *prev_lhead = Head;
int i = 0;
int service = 0;
struct freelist *saveList;
struct freelist *savePrev;
while(lhead!=((void *)0))
{
int isHead = 0;
int isGreater = 0;
struct freelist *trav = Head;
struct freelist *prev_trav = Head;
int sizetemp = lhead->size;
 int j = 0;
 while(trav!=((void *)0))
 { struct freelist *temp = lhead;
  if( ( ((void *)temp+sizeof(list)+ sizetemp) == ((void *)trav)) )
  {
      if(i>j)
      {
     if( trav == prev_trav)
     {
       Head=Head->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
     else
     {
       prev_trav->next= trav->next;
       trav->next=((void *)0);
       lhead->size= lhead->size + trav->size + sizeof(list);
       service=1;
     }
    }
      else if(i<j)
      {
    if (((lhead)->next) == trav )
    {
     lhead->next=trav->next;
     trav->next=((void *)0);
     lhead->size= lhead->size + trav->size + sizeof(list);
     service=1;
    }
    else
    {
     prev_trav->next= trav->next;
     trav->next=((void *)0);
     lhead->size= trav->size + lhead->size + sizeof(list);
     service=1;
    }
     }
   if(lhead==Head)
   {isHead=1;}
  if((lhead->next)!=((void *)0))
   {if( (lhead->size)> (lhead->next->size))
    {isGreater=1;}
    saveList=lhead;
    savePrev=prev_lhead;}
  }
  if(j!=0)
  {prev_trav = prev_trav->next;}
  trav=trav->next;
  j++;
 }
if(i!=0)
{ prev_lhead =prev_lhead->next; }
lhead= lhead-> next;
i++;
if(service ==1)
{
int complete = 0;
struct freelist *tra = saveList;
struct freelist *tra_prev = saveList;
int sizecomp = saveList->size;
int count = 0;
while((tra!=((void *)0)) && (complete==0))
{
 if((isHead==1) && (isGreater==1))
 {
  if(sizecomp < (tra->size) )
  {
   Head=Head->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
 else if((isHead==0) && (isGreater==1))
 {
  if(sizecomp < (tra->size))
  {
   savePrev->next=saveList->next;
   tra_prev->next=saveList;
   saveList->next=tra;
  }
 }
tra=tra->next;
if(count!=0)
{tra_prev=tra_prev->next;}
count++;
}
lhead=Head;
prev_lhead=Head;
i=0;
}
service=0;
}
}

variable_types:
ptr
void *

variable_types: k int

variable_types: service int

variable_types: isHead int

variable_types: isGreater int

variable_types: sizetemp int

variable_types: complete int

variable_types: sizecomp int

variable_types: count int

user_defined_types: struct freelist { int size; struct freelist *next; }


decompiled_code:
int Mem_Dump()
{
_DWORD **v0; // rax
unsigned int *i; // rbx

v0 = &Head;
for ( i = Head; i; i = *(unsigned int **)(i + 1) )
LODWORD(v0) = printf(" FREE LIST ;size if -> %d , address -> %p\n", *i, i);
return (int)v0;
}

canonical_decompiled_code:
int func9()
{
_DWORD **v0; // rax
unsigned int *i; // rbx

v0 = &Head;
for ( i = Head; i; i = *(unsigned int **)(i + 1) )
LODWORD(v0) = printf(" FREE LIST ;size if -> %d , address -> %p\n", *i, i);
return (int)v0;
}

original_code:
void Mem_Dump()
{
list * traverse=Head;
 while(traverse!=((void *)0))
 {
  printf(" FREE LIST ;size if -> %d , address -> %p\n",traverse->size, (void*)traverse);
  traverse = traverse->next;
 }
}

canonical_original_code:
void Mem_Dump()
{
struct freelist *traverse = Head;
 while(traverse!=((void *)0))
 {
  printf(" FREE LIST ;size if -> %d , address -> %p\n",traverse->size, (void *)traverse);
  traverse = traverse->next;
 }
}


main

variable_types: argc int

variable_types:
argv
char *[]

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: e int

variable_types: f int

variable_types: m int

variable_types: p int


decompiled_code:
__int64 init_edges()
{
add_edge(5LL, 4LL, &list);
add_edge(0LL, 2LL, &unk_404088);
add_edge(6LL, 2LL, &unk_404088);
add_edge(1LL, 3LL, &unk_404090);
add_edge(4LL, 1LL, &unk_404098);
add_edge(2LL, 2LL, &unk_404098);
add_edge(5LL, 3LL, &unk_4040A0);
add_edge(6LL, 2LL, &unk_4040A0);
add_edge(6LL, 1LL, &unk_4040A8);
add_edge(0LL, 1LL, &unk_4040B0);
add_edge(5LL, 1LL, &unk_4040B0);
add_edge(3LL, 3LL, &unk_4040B0);
return add_edge(2LL, 4LL, &unk_4040B0);
}

canonical_decompiled_code:
__int64 func7()
{
add_edge(5LL, 4LL, &list);
add_edge(0LL, 2LL, &unk_404088);
add_edge(6LL, 2LL, &unk_404088);
add_edge(1LL, 3LL, &unk_404090);
add_edge(4LL, 1LL, &unk_404098);
add_edge(2LL, 2LL, &unk_404098);
add_edge(5LL, 3LL, &unk_4040A0);
add_edge(6LL, 2LL, &unk_4040A0);
add_edge(6LL, 1LL, &unk_4040A8);
add_edge(0LL, 1LL, &unk_4040B0);
add_edge(5LL, 1LL, &unk_4040B0);
add_edge(3LL, 3LL, &unk_4040B0);
return add_edge(2LL, 4LL, &unk_4040B0);
}


decompiled_code:
__int64 __fastcall initialize_data_structures(unsigned int a1)
{
init_edges();
init_heap(a1, &heap, (unsigned int)len_heap);
return init_weight_array(a1, &weights, (unsigned int)len_heap);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
func7();
func11(a1, &heap, (unsigned int)len_heap);
return init_weight_array(a1, &weights, (unsigned int)len_heap);
}

original_code:
void initialize_data_structures(int source)
{
 init_edges();
 init_heap(source, heap, len_heap);
 init_weight_array(source, weights, len_heap);
}

variable_types: source int


decompiled_code:
void do_dijkstra()
{
int *v0; // rbx
int v1; // ecx
__int64 v2; // rax
int v3; // er12
__int64 v4; // rbp

while ( len_heap > 0 )
{
v2 = extract_min(&heap, &len_heap);
v3 = v2;
weights[2 * (int)v2] = HIDWORD(v2);
v0 = (int *)list[(int)v2];
if ( v0 )
{
v4 = (int)v2;
do
{
v1 = weights[2 * v4] + v0[1];
if ( weights[2 * *v0] > v1 )
{
dword_4040C4[2 * *v0] = v3;
weights[2 * *v0] = v1;
decrease_key((unsigned int)*v0, &heap, (unsigned int)len_heap);
}
v0 = (int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
}
}
}

canonical_decompiled_code:
void func9()
{
int *v0; // rbx
int v1; // ecx
__int64 v2; // rax
int v3; // er12
__int64 v4; // rbp

while ( len_heap > 0 )
{
v2 = func13(&heap, &len_heap);
v3 = v2;
weights[2 * (int)v2] = HIDWORD(v2);
v0 = (int *)list[(int)v2];
if ( v0 )
{
v4 = (int)v2;
do
{
v1 = weights[2 * v4] + v0[1];
if ( weights[2 * *v0] > v1 )
{
dword_4040C4[2 * *v0] = v3;
weights[2 * *v0] = v1;
func14((unsigned int)*v0, &heap, (unsigned int)len_heap);
}
v0 = (int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
}
}
}

original_code:
void do_dijkstra(int source)
{
 struct heap_t cur_min;
 struct adj_t *cur_ver;
 int index, new_weight;
 while (len_heap > 0) {
  cur_min = extract_min(heap, &len_heap);
  index = cur_min.index;
  weights[index].dist = cur_min.dist;
  for (cur_ver = list[index]; cur_ver != ((void *)0); cur_ver= cur_ver->next) {
   new_weight = weights[index].dist +
    cur_ver->edge;
   if (new_weight < weights[cur_ver->index].dist) {
    weights[cur_ver->index].parent = index;
    weights[cur_ver->index].dist = new_weight;
    decrease_key(cur_ver->index, heap, len_heap, new_weight);
   }
  }
 }
}

canonical_original_code:
void do_dijkstra(int source)
{
 struct heap_t cur_min;
 struct adj_t *cur_ver;
 int index; int new_weight;
 while (len_heap > 0) {
  cur_min = extract_min(heap, &len_heap);
  index = cur_min.index;
  weights[index].dist = cur_min.dist;
  for (cur_ver = list[index]; cur_ver != ((void *)0); cur_ver= cur_ver->next) {
   new_weight = weights[index].dist +
    cur_ver->edge;
   if (new_weight < weights[cur_ver->index].dist) {
    weights[cur_ver->index].parent = index;
    weights[cur_ver->index].dist = new_weight;
    decrease_key(cur_ver->index, heap, len_heap, new_weight);
   }
  }
 }
}

variable_types: struct adj_t { int index; int edge; struct adj_t *next; } *

variable_types: index int


decompiled_code:
int __fastcall print_adj_list(unsigned int *a1)
{
unsigned int *i; // rbx

for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("ind = %d, edge = %d \t", *i, i[1]);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
unsigned int *i; // rbx

for ( i = a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
printf("ind = %d, edge = %d \t", *i, i[1]);
return putchar(10);
}

original_code:
void print_adj_list(struct adj_t *head)
{
 struct adj_t *cur;
 for (cur = head; cur != ((void *)0); cur=cur->next)
  printf("ind = %d, edge = %d \t", cur->index, cur->edge);
 printf("\n");
}

user_defined_types: struct adj_t { int index; int edge; struct adj_t *next; }


original_code:
void init_heap(int index_src, struct heap_t heap[], int len)
{
 int i;
 int ind = 0;
 heap[ind].index = index_src;
 heap[ind].dist = 0;
 ind++;
 for (i = 0; i < len; i++) {
  if (i != index_src) {
   heap[ind].index = i;
   heap[ind].dist = 0x7fffffff;
   ind++;
  }
 }
}

variable_types: struct heap_t { int index; int dist; } []

variable_types: len int

variable_types: i int

variable_types: ind int


decompiled_code:
__int64 __fastcall min_heapify(unsigned int a1, __int64 a2, int a3)
{
__int64 result; // rax
int v5; // edi
int v6; // edx
__int64 v7; // rdi
int *v8; // rdx
int v9; // er9
int v10; // ecx
__int64 v11; // rax

result = a1;
v5 = 2 * a1;
v6 = v5 + 1;
v7 = (unsigned int)(v5 + 2);
if ( v6 < a3 && *(_DWORD *)(a2 + 8LL * v6 + 4) < *(_DWORD *)(a2 + 8LL * (int)result + 4) )
{
if ( (int)v7 >= a3 )
{
v7 = (unsigned int)v6;
}
else if ( *(_DWORD *)(a2 + 8LL * (int)v7 + 4) >= *(_DWORD *)(a2 + 8LL * v6 + 4) )
{
v7 = (unsigned int)v6;
}
goto LABEL_10;
}
if ( (int)v7 < a3 && *(_DWORD *)(a2 + 8LL * (int)v7 + 4) < *(_DWORD *)(a2 + 8LL * (int)result + 4) )
{
LABEL_10:
if ( (_DWORD)v7 != (_DWORD)result )
{
v8 = (int *)(a2 + 8LL * (int)result);
v9 = *v8;
v10 = v8[1];
v11 = a2 + 8LL * (int)v7;
*(_QWORD *)v8 = *(_QWORD *)v11;
*(_DWORD *)v11 = v9;
*(_DWORD *)(v11 + 4) = v10;
result = min_heapify(v7, a2, (unsigned int)a3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, __int64 a2, int a3)
{
__int64 result; // rax
int v5; // edi
int v6; // edx
__int64 v7; // rdi
int *v8; // rdx
int v9; // er9
int v10; // ecx
__int64 v11; // rax

result = a1;
v5 = 2 * a1;
v6 = v5 + 1;
v7 = (unsigned int)(v5 + 2);
if ( v6 < a3 && *(_DWORD *)(a2 + 8LL * v6 + 4) < *(_DWORD *)(a2 + 8LL * (int)result + 4) )
{
if ( (int)v7 >= a3 )
{
v7 = (unsigned int)v6;
}
else if ( *(_DWORD *)(a2 + 8LL * (int)v7 + 4) >= *(_DWORD *)(a2 + 8LL * v6 + 4) )
{
v7 = (unsigned int)v6;
}
goto LABEL_10;
}
if ( (int)v7 < a3 && *(_DWORD *)(a2 + 8LL * (int)v7 + 4) < *(_DWORD *)(a2 + 8LL * (int)result + 4) )
{
LABEL_10:
if ( (_DWORD)v7 != (_DWORD)result )
{
v8 = (int *)(a2 + 8LL * (int)result);
v9 = *v8;
v10 = v8[1];
v11 = a2 + 8LL * (int)v7;
*(_QWORD *)v8 = *(_QWORD *)v11;
*(_DWORD *)v11 = v9;
*(_DWORD *)(v11 + 4) = v10;
result = func12(v7, a2, (unsigned int)a3);
}
}
return result;
}

original_code:
void min_heapify(int ind, struct heap_t heap[], int len)
{
 int l = 2 * ind + 1;
 int r = 2 * ind + 2;
 int ind_min = ind;
 if (l < len && heap[l].dist < heap[ind_min].dist)
  ind_min = l;
 if (r < len && heap[r].dist < heap[ind_min].dist)
  ind_min = r;
 if (ind_min != ind) {
  struct heap_t temp = heap[ind];
  heap[ind] = heap[ind_min];
  heap[ind_min] = temp;
  min_heapify(ind_min, heap, len);
 }
}

variable_types: l int

variable_types: r int

variable_types:
temp
struct heap_t { int index; int dist; }


decompiled_code:
__int64 __fastcall extract_min(unsigned int *a1, int *a2)
{
unsigned int v2; // ebx
__int64 v3; // rbp
int v4; // edx

v2 = *a1;
v3 = a1[1];
*(_QWORD *)a1 = *(_QWORD *)&a1[2 * *a2 - 2];
v4 = *a2 - 1;
*a2 = v4;
min_heapify(0, (__int64)a1, v4);
return (v3 << 32) | v2;
}

original_code:
struct heap_t extract_min(struct heap_t heap[], int *len)
{
 struct heap_t ret = heap[0];
 heap[0] = heap[*len-1];
 (*len)--;
 min_heapify(0, heap, *len);
 return ret;
}

variable_types:
heap
struct heap_t []

variable_types:
len
int *

variable_types:
ret
struct heap_t { int index; int dist; }

return_type: struct heap_t { int index; int dist; }


original_code:
void decrease_key(int index, struct heap_t heap[], int len, int new_val)
{
 int i = 0;
 int parent;
 struct heap_t temp;
 for (i; i < len && (heap[i].index != index); i++);
 heap[i].dist = new_val;
 while (i > 0) {
  parent = i / 2;
  if (heap[parent].dist > heap[i].dist) {
   temp = heap[parent];
   heap[parent] = heap[i];
   heap[i] = temp;
   i = parent;
  } else {
   break;
  }
 }
}

variable_types: parent int


decompiled_code:
int __fastcall print_fin_array(__int64 a1, int a2)
{
__int64 i; // rbx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
result = printf(
"Index = %d, Weight = %d, Parent = %d\n",
(unsigned int)i,
*(unsigned int *)(a1 + 8 * i),
*(unsigned int *)(a1 + 8 * i + 4));
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, int a2)
{
__int64 i; // rbx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
result = printf(
"Index = %d, Weight = %d, Parent = %d\n",
(unsigned int)i,
*(unsigned int *)(a1 + 8 * i),
*(unsigned int *)(a1 + 8 * i + 4));
}
return result;
}

original_code:
void print_fin_array(struct final_t final[], int len)
{
 int i;
 for (i = 0; i < len; i++)
  printf("Index = %d, Weight = %d, Parent = %d\n", i, final[i].dist, final[i].parent);
}

variable_types: struct final_t { int dist; int parent; } []


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
initialize_data_structures(3u);
do_dijkstra();
print_fin_array(weights, 7LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func8(3u);
func9();
func15(weights, 7LL);
return 0;
}

original_code:
int main()
{
 struct heap_t min;
 initialize_data_structures(3);
 do_dijkstra(3);
 print_fin_array(weights, 7);
 return 0;
}

variable_types:
min
struct heap_t { int index; int dist; }


decompiled_code:
__int64 __fastcall print_in_order(unsigned int *a1)
{
const char *v1; // rdx
__int64 result; // rax

if ( (unsigned int *)nil_node != a1 )
{
print_in_order(*((_QWORD *)a1 + 1));
v1 = (const char *)&unk_648;
if ( a1[8] != 1 )
v1 = (const char *)&unk_64A;
printf("%d(%s) ", *a1, v1);
result = print_in_order(*((_QWORD *)a1 + 2));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
const char *v1; // rdx
__int64 result; // rax

if ( (unsigned int *)nil_node != a1 )
{
func1(*((_QWORD *)a1 + 1));
v1 = (const char *)&unk_648;
if ( a1[8] != 1 )
v1 = (const char *)&unk_64A;
printf("%d(%s) ", *a1, v1);
result = func1(*((_QWORD *)a1 + 2));
}
return result;
}

original_code:
void print_in_order(struct node *node)
{
 if ((node == nil_node))
  return;
 print_in_order(node->l);
 printf("%d(%s) ", node->val,(node->col == RED) ? "R" : "B");
 print_in_order(node->r);
}

variable_types: struct node { int val; struct node *l; struct node *r; struct node *p; enum color { BLACK=0, RED=1 } col; } *

user_defined_types: struct node { int val; struct node *l; struct node *r; struct node *p; enum color col; }


successor

decompiled_code:
__int64 __fastcall successor(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rcx

v1 = *(_QWORD *)(a1 + 16);
if ( nil_node == v1 )
return *(_QWORD *)(a1 + 16);
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( nil_node != v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rcx

v1 = *(_QWORD *)(a1 + 16);
if ( nil_node == v1 )
return *(_QWORD *)(a1 + 16);
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( nil_node != v1 );
return v2;
}

original_code:
struct node *successor(struct node *s)
{
 struct node *next = s->r;
 if ((next == nil_node))
  return next;
 while (!(next->l == nil_node)) {
  next = next->l;
 }
 return next;
}

variable_types:
s
struct node *

return_type: struct node { int val; struct node *l; struct node *r; struct node *p; enum color { BLACK=0, RED=1 } col; } *


search

decompiled_code:
__int64 __fastcall search(__int64 a1, int a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)a1;
result = a1;
if ( *(_DWORD *)a1 != a2 )
{
if ( v2 <= a2 )
{
if ( v2 >= a2 || *(_QWORD *)(a1 + 16) == nil_node )
goto LABEL_4;
}
else if ( *(_QWORD *)(a1 + 8) == nil_node )
{
LABEL_4:
puts("Element not found");
return 0LL;
}
result = search();
}
return result;
}

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

v2 = *(_DWORD *)a1;
result = a1;
if ( *(_DWORD *)a1 != a2 )
{
if ( v2 <= a2 )
{
if ( v2 >= a2 || *(_QWORD *)(a1 + 16) == nil_node )
goto LABEL_4;
}
else if ( *(_QWORD *)(a1 + 8) == nil_node )
{
LABEL_4:
puts("Element not found");
return 0LL;
}
result = func3();
}
return result;
}

original_code:
struct node *search(struct node *cur, int val)
{
 if (cur->val == val)
  return cur;
 if (val < cur->val && !(cur->l == nil_node))
  return search(cur->l, val);
 else if (val > cur->val && !(cur->r == nil_node))
  return search(cur->r, val);
 else {
  printf("Element not found\n");
  return ((void *)0);
 }
}

variable_types:
cur
struct node *

variable_types: val int


original_code:
void rb_delete_fixup(struct node **root, struct node *x)
{
 struct node *w;
 while (!(x->p == nil_node) && !(x->col == RED)) {
  if ((x->p->l == x)) {
   printf("Not here\n");
   w = x->p->r;
   if ((w->col == RED)) {
    x->p->col = RED;
    w->col = BLACK;
    rotate_left(x->p, root);
    w = x->p->r;
   }
   if (!(w->l->col == RED) && !(w->r->col == RED)) {
    w->col = RED;
    x = x->p;
   } else {
    if ((w->l->col == RED)) {
     w->l->col = BLACK;
     w->col = RED;
     rotate_right(w, root);
     w = x->p->r;
    }
    w->col = x->p->col;
    x->p->col = BLACK;
    w->r->col = BLACK;
    rotate_left(x->p, root);
    break;
   }
  } else {
   w = x->p->l;
   if ((w->col == RED)) {
    x->p->col = RED;
    w->col = BLACK;
    rotate_right(x->p, root);
    w = x->p->l;
   }
   if (!(w->l->col == RED) && !(w->r->col == RED)) {
    w->col = RED;
    x = x->p;
   } else {
    if ((w->r->col == RED)) {
     w->r->col = BLACK;
     w->col = RED;
     rotate_left(w, root);
     w = x->p->l;
    }
    w->col = x->p->col;
    x->p->col = BLACK;
    w->l->col = BLACK;
    rotate_right(x->p, root);
    break;
   }
  }
 }
 if ((x->p == nil_node)) {
  *root = x;
  x->col = BLACK;
 }
}

variable_types: struct node { int val; struct node *l; struct node *r; struct node *p; enum color { BLACK=0, RED=1 } col; } **

variable_types:
x
struct node *


delete

original_code:
void delete(struct node **root, int val)
{
 struct node *del = search(*root, val);
 struct node *splice;
 struct node *child_splice;
 if (!del) {
  printf("No element to delete\n");
  return;
 }
 if ((del->l == nil_node) && (del->r == nil_node)) {
  if ((del->p->l == del))
   del->p->l = nil_node;
  else
   del->p->r = nil_node;
  if (del == *root)
   *root = ((void *)0);
  free(del);
  return;
 }
 if ((del->l == nil_node) || (del->r == nil_node)) {
  splice = del;
 } else {
  splice = successor(del);
 }
 if (!(splice->l == nil_node))
  child_splice = splice->l;
 else
  child_splice = splice->r;
 child_splice->p = splice->p;
 if ((splice->p == nil_node)) {
  *root = child_splice;
 } else if ((splice->p->l == splice)){
  splice->p->l = child_splice;
 } else {
  splice->p->r = child_splice;
 }
 if (splice != del)
  del->val = splice->val;
 if (!(splice->col == RED)) {
  rb_delete_fixup(root, child_splice);
 }
 free(splice);
 return;
}