main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
puts("Scenario 1");
smokeScenario(2u, 2u, 2u);
puts("Scenario 2");
smokeScenario(1u, 1u, 1u);
puts("Scenario 3");
smokeScenario(2u, 2u, 1u);
puts("Scenario 4");
smokeScenario(2u, 1u, 0);
fflush(_bss_start);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
puts("Scenario 1");
func15(2u, 2u, 2u);
puts("Scenario 2");
func15(1u, 1u, 1u);
puts("Scenario 3");
func15(2u, 2u, 1u);
puts("Scenario 4");
func15(2u, 1u, 0);
fflush(_bss_start);
exit(0);
}

original_code:
int main()
{
 printf("Scenario 1\n");
 smokeScenario(2, 2, 2);
 printf("Scenario 2\n");
 smokeScenario(1, 1, 1);
 printf("Scenario 3\n");
 smokeScenario(2, 2, 1);
 printf("Scenario 4\n");
 smokeScenario(2, 1, 0);
 fflush(stdout);
 exit(0);
 return 0;
}


repo: chaszhazha/elevator

original_code:
void list_free_guests(list_t **list)
{
 if ((*list) != ((void *)0)) {
  node_t *curr, *next;
  for (curr = (*list)->head; curr != ((void *)0); curr = next) {
   next = curr->next;
                        free((guest_t*)curr->data);
   free(curr);
  }
  free(*list);
  *list = ((void *)0);
 }
}

canonical_original_code:
void list_free_guests(struct list_t **list)
{
 if ((*list) != ((void *)0)) {
  struct node_t *curr; struct node_t *next;
  for (curr = (*list)->head; curr != ((void *)0); curr = next) {
   next = curr->next;
                        free((struct guest_t *)curr->data);
   free(curr);
  }
  free(*list);
  *list = ((void *)0);
 }
}

variable_types: struct list_t { struct node_t { void *data; struct node_t *next; } *head; int size; } **

return_type: void

user_defined_types: struct guest_t { int request_time; int off_time; int at; int to; int num; int total_time; }

user_defined_types: struct list_t { struct node_t *head; int size; }


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

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

original_code:
int list_empty (list_t *list)
{
 return list->head == ((void *)0);
}

canonical_original_code:
int list_empty(struct list_t *list)
{
 return list->head == ((void *)0);
}

variable_types: struct list_t { struct node_t { void *data; struct node_t *next; } *head; int size; } *

return_type: int


original_code:
void list_remove_guest(list_t* list, node_t** node)
{
    if(list->head == ((void *)0))
    {
        fprintf(stderr,"Error, trying to delete a node from an empty list\n");
        return;
    }
    list->size--;
    node_t * next_node = (*node)->next;
    if((*node)->next != ((void *)0))
    {
        memcpy((*node)->data, (*node)->next->data, sizeof(guest_t));
        (*node)->next = (*node)->next->next;
        free((guest_t*)next_node->data);
        free(next_node);
    }
    else
    {
        node_t* tmp = list->head, *pre = ((void *)0);
        while(tmp->next != ((void *)0))
        {
            pre = tmp;
            tmp = tmp->next;
        }
        if(pre == ((void *)0))
        {
            list->head = ((void *)0);
        }
        else
                pre->next = ((void *)0);
        free((guest_t*)(*node)->data);
        free((*node));
        *node = ((void *)0);
    }
}

canonical_original_code:
void list_remove_guest(struct list_t *list, struct node_t **node)
{
    if(list->head == ((void *)0))
    {
        fprintf(stderr,"Error, trying to delete a node from an empty list\n");
        return;
    }
    list->size--;
    struct node_t *next_node = (*node)->next;
    if((*node)->next != ((void *)0))
    {
        memcpy((*node)->data, (*node)->next->data, sizeof(guest_t));
        (*node)->next = (*node)->next->next;
        free((struct guest_t *)next_node->data);
        free(next_node);
    }
    else
    {
        struct node_t *tmp = list->head; struct node_t *pre = ((void *)0);
        while(tmp->next != ((void *)0))
        {
            pre = tmp;
            tmp = tmp->next;
        }
        if(pre == ((void *)0))
        {
            list->head = ((void *)0);
        }
        else
                pre->next = ((void *)0);
        free((struct guest_t *)(*node)->data);
        free((*node));
        *node = ((void *)0);
    }
}

variable_types:
node
struct node_t **

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


printDistNode

repo: chavli/C

decompiled_code:
int __fastcall printDistNode(unsigned int *a1)
{
const char *v1; // rax

v1 = (const char *)serializeListNode(*((_QWORD *)a1 + 5));
return printf(
"\n"
"DistNode: %d\n"
"\talive: %d\n"
"\trunning: %d\n"
"\tlast sent: %d\n"
"\toffset: %d\n"
"\tactive drift: %f\n"
"\tdefault drift: %f\n"
"\thistory: %s\n",
*a1,
a1[14] & 1,
(a1[14] & 2) != 0,
a1[4],
a1[5],
*((float *)a1 + 8),
*((float *)a1 + 9),
v1);
}

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

v1 = (const char *)serializeListNode(*((_QWORD *)a1 + 5));
return printf(
"\n"
"DistNode: %d\n"
"\talive: %d\n"
"\trunning: %d\n"
"\tlast sent: %d\n"
"\toffset: %d\n"
"\tactive drift: %f\n"
"\tdefault drift: %f\n"
"\thistory: %s\n",
*a1,
a1[14] & 1,
(a1[14] & 2) != 0,
a1[4],
a1[5],
*((float *)a1 + 8),
*((float *)a1 + 9),
v1);
}

original_code:
void printDistNode(DistNode *node){
  printf("\nDistNode: %d\n"
    "\talive: %d\n"
    "\trunning: %d\n"
    "\tlast sent: %d\n"
    "\toffset: %d\n"
    "\tactive drift: %f\n"
    "\tdefault drift: %f\n"
    "\thistory: %s\n",
    node->pid, node->alive, node->running, node->last_sent, node->offset,
    node->active_drift, node->default_drift, serializeListNode(node->local_hist)
  );
}

canonical_original_code:
void printDistNode(struct dnode *node){
  printf("\nDistNode: %d\n"
    "\talive: %d\n"
    "\trunning: %d\n"
    "\tlast sent: %d\n"
    "\toffset: %d\n"
    "\tactive drift: %f\n"
    "\tdefault drift: %f\n"
    "\thistory: %s\n",
    node->pid, node->alive, node->running, node->last_sent, node->offset,
    node->active_drift, node->default_drift, serializeListNode(node->local_hist)
  );
}

variable_types: struct dnode { int pid; int master_pid; long start_time; enum message_types { MSG_KILL=0, MSG_TICK=1, MSG_GETTIME=2, MSG_SETTIME=3, MSG_INIT_RING=4, MSG_ELECTION_E=5, MSG_ELECTION_C=6, MSG_EXIT=7, MSG_404=8, MSG_GETTIME_R=9, CMD_KILL=10, CMD_REV=11, CMD_TIME=12, CMD_STAT=13 } last_sent; int master_comm; int offset; int msg_count; float active_drift; struct lnode { struct lnode *prev; struct lnode *next; int pid; } *local_hist; short resp_count; int metadata; unsigned char alive; unsigned char running; unsigned char initiated_election; unsigned char election_in_progress; unsigned char padding; } *

user_defined_types: struct dnode { int pid; int master_pid; long start_time; enum message_types last_sent; int master_comm; int offset; int msg_count; float active_drift; struct lnode *local_hist; short resp_count; int metadata; unsigned char alive; unsigned char running; unsigned char initiated_election; unsigned char election_in_progress; unsigned char padding; }


killDistNode

decompiled_code:
void killDistNode()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void killDistNode(DistNode *node){
}

canonical_original_code:
void killDistNode(struct dnode *node){
}

user_defined_types: enum message_types { MSG_KILL=0, MSG_TICK=1, MSG_GETTIME=2, MSG_SETTIME=3, MSG_INIT_RING=4, MSG_ELECTION_E=5, MSG_ELECTION_C=6, MSG_EXIT=7, MSG_404=8, MSG_GETTIME_R=9, CMD_KILL=10, CMD_REV=11, CMD_TIME=12, CMD_STAT=13 }

user_defined_types: struct lnode { struct lnode *prev; struct lnode *next; int pid; }


exitDistNode

decompiled_code:
void exitDistNode()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void exitDistNode(DistNode* node) {
}

canonical_original_code:
void exitDistNode(struct dnode *node) {
}


convertPidToPipe

decompiled_code:
char *__fastcall convertPidToPipe(unsigned int a1)
{
char *v1; // rax
char *v2; // rbx

v1 = (char *)malloc(0xBuLL);
if ( !v1 )
{
perror("Failed to malloc");
exit(-1);
}
v2 = v1;
if ( sprintf(v1, "%d", a1) < 0 )
{
perror("Failed to convert pid to char");
exit(-1);
}
strcat(v2, ".pipe");
return v2;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
char *v1; // rax
char *v2; // rbx

v1 = (char *)malloc(0xBuLL);
if ( !v1 )
{
perror("Failed to malloc");
exit(-1);
}
v2 = v1;
if ( sprintf(v1, "%d", a1) < 0 )
{
perror("Failed to convert pid to char");
exit(-1);
}
strcat(v2, ".pipe");
return v2;
}

original_code:
char* convertPidToPipe(int pid) {
 char* pipe;
 if ((pipe = (char*) malloc(sizeof(char) * 11)) == ((void *)0)) {
  perror("Failed to malloc");
  exit(-1);
 }
 if (sprintf(pipe, "%d", pid) < 0) {
  perror("Failed to convert pid to char");
  exit(-1);
 }
 if (strcat(pipe, ".pipe") == ((void *)0)) {
  perror("Failed to strcat");
  exit(-1);
 }
 return pipe;
}

canonical_original_code:
char *convertPidToPipe(int pid) {
 char *pipe;
 if ((pipe = (char *) malloc(sizeof(char) * 11)) == ((void *)0)) {
  perror("Failed to malloc");
  exit(-1);
 }
 if (sprintf(pipe, "%d", pid) < 0) {
  perror("Failed to convert pid to char");
  exit(-1);
 }
 if (strcat(pipe, ".pipe") == ((void *)0)) {
  perror("Failed to strcat");
  exit(-1);
 }
 return pipe;
}

variable_types: pid int

variable_types:
pipe
char *

return_type: char *


sendMessage

decompiled_code:
__int64 __fastcall sendMessage(unsigned int a1, char a2, int a3, const char *a4)
{
int v6; // er14
size_t v7; // r13
_DWORD *v8; // rbx
size_t v9; // rax
char *v10; // r12
int v11; // eax
unsigned int v12; // ebp
unsigned int v14; // eax

if ( a4 )
{
v6 = strlen(a4);
v7 = v6 + 21;
v8 = malloc(v7);
v8[1] = getpid();
*v8 = a2;
v8[3] = v6 + 1;
v8[2] = 0;
v8[4] = a3;
v9 = strlen(a4);
memcpy(v8 + 5, a4, v9);
}
else
{
v8 = malloc(0x15uLL);
v8[1] = getpid();
*v8 = a2;
v8[3] = 1;
v8[2] = 0;
v8[4] = a3;
v7 = 21LL;
}
*((_BYTE *)v8 + v7 - 1) = 0;
v10 = convertPidToPipe(a1);
v11 = open(v10, 1);
v12 = v11;
if ( v11 == -1 )
{
v14 = getpid();
printf("Node (%i) ", v14);
perror("Failed to open pipe for writing");
puts(v10);
}
else if ( write(v11, v8, v7) == -1 )
{
perror("Failed to write to pipe");
v12 = -1;
}
else
{
v12 = close(v12);
if ( v12 == -1 )
perror("Failed to close pipe");
else
v12 = 0;
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2, int a3, const char *a4)
{
int v6; // er14
size_t v7; // r13
_DWORD *v8; // rbx
size_t v9; // rax
char *v10; // r12
int v11; // eax
unsigned int v12; // ebp
unsigned int v14; // eax

if ( a4 )
{
v6 = strlen(a4);
v7 = v6 + 21;
v8 = malloc(v7);
v8[1] = getpid();
*v8 = a2;
v8[3] = v6 + 1;
v8[2] = 0;
v8[4] = a3;
v9 = strlen(a4);
memcpy(v8 + 5, a4, v9);
}
else
{
v8 = malloc(0x15uLL);
v8[1] = getpid();
*v8 = a2;
v8[3] = 1;
v8[2] = 0;
v8[4] = a3;
v7 = 21LL;
}
*((_BYTE *)v8 + v7 - 1) = 0;
v10 = func4(a1);
v11 = open(v10, 1);
v12 = v11;
if ( v11 == -1 )
{
v14 = getpid();
printf("Node (%i) ", v14);
perror("Failed to open pipe for writing");
puts(v10);
}
else if ( write(v11, v8, v7) == -1 )
{
perror("Failed to write to pipe");
v12 = -1;
}
else
{
v12 = close(v12);
if ( v12 == -1 )
perror("Failed to close pipe");
else
v12 = 0;
}
return v12;
}

original_code:
int sendMessage(int dest_pid, char msg_type, int metadata, char *body){
  int fd;
 char* pipe;
  int body_len = (body) ? strlen(body) : 0;
 int pktsize = body_len + sizeof(MessageHeader) + 1;
 char *packet = malloc(pktsize * sizeof(char));
 MessageHeader *header = (MessageHeader *)packet;
 header->source_pid = getpid();
 header->type = msg_type;
 header->body_length = body_len + 1;
 header->timestamp = 0;
 header->metadata = metadata;
  if(body)
   memcpy(packet + sizeof(MessageHeader), body, strlen(body));
 packet[pktsize - 1] = 0;
 pipe = convertPidToPipe(dest_pid);
 if ((fd = open(pipe, 01)) == -1) {
  printf("Node (%i) ", getpid());
  perror("Failed to open pipe for writing");
  printf("%s\n", pipe);
  return -1;
 }
 if (write(fd, packet, pktsize) == -1) {
  perror("Failed to write to pipe");
  return -1;
 }
 if (close(fd) == -1) {
  perror("Failed to close pipe");
  return -1;
 }
 return 0;
}

canonical_original_code:
int sendMessage(int dest_pid, char msg_type, int metadata, char *body){
  int fd;
 char *pipe;
  int body_len = (body) ? strlen(body) : 0;
 int pktsize = body_len + sizeof(MessageHeader) + 1;
 char *packet = malloc(pktsize * sizeof(char));
 struct header *header = (MessageHeader *)packet;
 header->source_pid = getpid();
 header->type = msg_type;
 header->body_length = body_len + 1;
 header->timestamp = 0;
 header->metadata = metadata;
  if(body)
   memcpy(packet + sizeof(MessageHeader), body, strlen(body));
 packet[pktsize - 1] = 0;
 pipe = convertPidToPipe(dest_pid);
 if ((fd = open(pipe, 01)) == -1) {
  printf("Node (%i) ", getpid());
  perror("Failed to open pipe for writing");
  printf("%s\n", pipe);
  return -1;
 }
 if (write(fd, packet, pktsize) == -1) {
  perror("Failed to write to pipe");
  return -1;
 }
 if (close(fd) == -1) {
  perror("Failed to close pipe");
  return -1;
 }
 return 0;
}

variable_types: metadata int

variable_types:
body
char *

variable_types: fd int

variable_types: pktsize int

variable_types:
packet
char *

variable_types: struct header { enum message_types { MSG_KILL=0, MSG_TICK=1, MSG_GETTIME=2, MSG_SETTIME=3, MSG_INIT_RING=4, MSG_ELECTION_E=5, MSG_ELECTION_C=6, MSG_EXIT=7, MSG_404=8, MSG_GETTIME_R=9, CMD_KILL=10, CMD_REV=11, CMD_TIME=12, CMD_STAT=13 } type; int source_pid; int timestamp; int body_length; int metadata; } *

user_defined_types: struct header { enum message_types type; int source_pid; int timestamp; int body_length; int metadata; }


decompiled_code:
__int64 __fastcall peek_bottom(__int64 a1)
{
__int64 result; // rax

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
ListNode *peek_bottom(ListNode* root) {
 while (root->next) {
  root = root->next;
 }
 return root;
}

canonical_original_code:
struct lnode *peek_bottom(struct lnode *root) {
 while (root->next) {
  root = root->next;
 }
 return root;
}

variable_types:
root
struct lnode *

return_type: struct lnode { struct lnode *prev; struct lnode *next; int pid; } *


findListNode

decompiled_code:
__int64 __fastcall findListNode(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)(a1 + 16) != a2 )
{
a1 = *(_QWORD *)(a1 + 8);
if ( !a1 )
return 0LL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)(a1 + 16) != a2 )
{
a1 = *(_QWORD *)(a1 + 8);
if ( !a1 )
return 0LL;
}
return a1;
}

original_code:
ListNode *findListNode(ListNode *iter, int pid){
 while(iter){
  if( iter->pid == pid )
   break;
  iter = iter->next;
 }
 return iter;
}

canonical_original_code:
struct lnode *findListNode(struct lnode *iter, int pid){
 while(iter){
  if( iter->pid == pid )
   break;
  iter = iter->next;
 }
 return iter;
}

variable_types:
iter
struct lnode *


printListNode

decompiled_code:
int __fastcall printListNode(__int64 a1)
{
return printf("LISTNODE:(%i), ", *(unsigned int *)(a1 + 16));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
return printf("LISTNODE:(%i), ", *(unsigned int *)(a1 + 16));
}

original_code:
void printListNode(ListNode *node){
  printf("LISTNODE:(%i), ", node->pid);
}

canonical_original_code:
void printListNode(struct lnode *node){
  printf("LISTNODE:(%i), ", node->pid);
}

variable_types: struct lnode { struct lnode *prev; struct lnode *next; int pid; } *


printList

decompiled_code:
int __fastcall printList(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax

v1 = a1;
v2 = getpid();
printf("=== LIST DUMP(%d) ===: ", v2);
if ( a1 )
{
do
{
printListNode(v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // eax

v1 = a1;
v2 = getpid();
printf("=== LIST DUMP(%d) ===: ", v2);
if ( a1 )
{
do
{
func3(v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void printList(ListNode *root){
  printf("=== LIST DUMP(%d) ===: ", getpid());
  while(root){
    printListNode(root);
    root = root->next;
  }
  printf("\n");
}

canonical_original_code:
void printList(struct lnode *root){
  printf("=== LIST DUMP(%d) ===: ", getpid());
  while(root){
    printListNode(root);
    root = root->next;
  }
  printf("\n");
}


copyList

decompiled_code:
void __fastcall copyList(__int64 *a1, __int64 a2)
{
__int64 i; // rbx
_QWORD *v3; // rax

for ( i = a2; i; i = *(_QWORD *)(i + 8) )
{
v3 = initializeListNode(*(_DWORD *)(i + 16));
enqueue(a1, v3);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 *a1, __int64 a2)
{
__int64 i; // rbx
_QWORD *v3; // rax

for ( i = a2; i; i = *(_QWORD *)(i + 8) )
{
v3 = initializeListNode(*(_DWORD *)(i + 16));
func0(a1, v3);
}
}

original_code:
void copyList(ListNode **dest, ListNode *src){
  ListNode *node;
  while(src){
    node = initializeListNode(src->pid);
    enqueue(dest, node);
    src = src->next;
  }
}

canonical_original_code:
void copyList(struct lnode **dest, struct lnode *src){
  struct lnode *node;
  while(src){
    node = initializeListNode(src->pid);
    enqueue(dest, node);
    src = src->next;
  }
}

variable_types: struct lnode { struct lnode *prev; struct lnode *next; int pid; } **

variable_types:
src
struct lnode *


serializeListNode

decompiled_code:
void *__fastcall serializeListNode(__int64 a1)
{
__int64 v1; // r13
char *v2; // rax
char *v3; // rbp
int v4; // er14
char *v5; // rbx
size_t v6; // rax
size_t v7; // rax

v1 = a1;
v2 = (char *)malloc(6uLL);
if ( a1 )
{
v3 = v2;
v4 = 0;
v5 = 0LL;
do
{
sprintf(v3, "%d", *(unsigned int *)(v1 + 16));
v6 = strlen(v3);
v5 = (char *)realloc(v5, v4 + v6 + 2);
v7 = strlen(v3);
memcpy(&v5[v4], v3, v7);
v5[v4 + strlen(v3)] = 0;
v4 += strlen(v3) + 1;
*(_WORD *)&v5[strlen(v5)] = 44;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
else
{
v5 = 0LL;
v4 = 0;
}
return realloc(v5, v4 + 1);
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1)
{
__int64 v1; // r13
char *v2; // rax
char *v3; // rbp
int v4; // er14
char *v5; // rbx
size_t v6; // rax
size_t v7; // rax

v1 = a1;
v2 = (char *)malloc(6uLL);
if ( a1 )
{
v3 = v2;
v4 = 0;
v5 = 0LL;
do
{
sprintf(v3, "%d", *(unsigned int *)(v1 + 16));
v6 = strlen(v3);
v5 = (char *)realloc(v5, v4 + v6 + 2);
v7 = strlen(v3);
memcpy(&v5[v4], v3, v7);
v5[v4 + strlen(v3)] = 0;
v4 += strlen(v3) + 1;
*(_WORD *)&v5[strlen(v5)] = 44;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
else
{
v5 = 0LL;
v4 = 0;
}
return realloc(v5, v4 + 1);
}

original_code:
char* serializeListNode(ListNode* list) {
 char* pid = 0;
 char* convert = malloc(sizeof(char) * 6);
 int offset = 0;
 while (list) {
  sprintf(convert, "%d", list->pid);
  pid = realloc(pid, offset + strlen(convert) + 2);
  memcpy(pid + offset, convert, strlen(convert));
  pid[strlen(convert) + offset] = '\0';
  offset += strlen(convert) + 1;
  strcat(pid, ",");
  list = list->next;
 }
 pid = realloc(pid, offset + 1);
 strcat(pid, "\0");
 return pid;
}

canonical_original_code:
char *serializeListNode(struct lnode *list) {
 char *pid = 0;
 char *convert = malloc(sizeof(char) * 6);
 int offset = 0;
 while (list) {
  sprintf(convert, "%d", list->pid);
  pid = realloc(pid, offset + strlen(convert) + 2);
  memcpy(pid + offset, convert, strlen(convert));
  pid[strlen(convert) + offset] = '\0';
  offset += strlen(convert) + 1;
  strcat(pid, ",");
  list = list->next;
 }
 pid = realloc(pid, offset + 1);
 strcat(pid, "\0");
 return pid;
}

variable_types:
pid
char *

variable_types:
convert
char *

variable_types: offset int


deserializeListNode

decompiled_code:
__int64 __fastcall deserializeListNode(char *a1)
{
char *i; // rdi
int v2; // eax
_QWORD *v3; // rax
__int64 v5; // [rsp+0h] [rbp-18h] BYREF
char *save_ptr[2]; // [rsp+8h] [rbp-10h] BYREF

save_ptr[0] = 0LL;
v5 = 0LL;
for ( i = strtok_r(a1, ",", save_ptr); i; i = strtok_r(0LL, ",", save_ptr) )
{
v2 = atoi(i);
v3 = initializeListNode(v2);
enqueue(&v5, v3);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char *i; // rdi
int v2; // eax
_QWORD *v3; // rax
__int64 v5; // [rsp+0h] [rbp-18h] BYREF
char *save_ptr[2]; // [rsp+8h] [rbp-10h] BYREF

save_ptr[0] = 0LL;
v5 = 0LL;
for ( i = strtok_r(a1, ",", save_ptr); i; i = strtok_r(0LL, ",", save_ptr) )
{
v2 = atoi(i);
v3 = initializeListNode(v2);
func0(&v5, v3);
}
return v5;
}

original_code:
ListNode *deserializeListNode(char *serialized){
  char *pid, *iter = 0;
  char *delim = ",";
  ListNode *root = 0, *node;
  pid = strtok_r(serialized, delim, &iter);
  while( pid != ((void *)0) ){
    node = initializeListNode(atoi(pid));
    enqueue(&root, node);
    pid = strtok_r(((void *)0), delim, &iter);
  }
  return root;
}

canonical_original_code:
struct lnode *deserializeListNode(char *serialized){
  char *pid; char *iter = 0;
  char *delim = ",";
  struct lnode *root = 0; struct lnode *node;
  pid = strtok_r(serialized, delim, &iter);
  while( pid != ((void *)0) ){
    node = initializeListNode(atoi(pid));
    enqueue(&root, node);
    pid = strtok_r(((void *)0), delim, &iter);
  }
  return root;
}

variable_types:
serialized
char *

variable_types:
iter
char *

variable_types:
delim
char *


printMessageHeader

decompiled_code:
int __fastcall printMessageHeader(_DWORD *a1)
{
unsigned int v1; // eax
int result; // eax

v1 = getpid();
printf("Node (%i): ", v1);
printf("source: %d", (unsigned int)a1[1]);
printf(", timestamp: %d", (unsigned int)a1[2]);
printf(", metadata: %d", (unsigned int)a1[4]);
printf(", body_length: %d", (unsigned int)a1[3]);
printf(", type: ");
switch ( *a1 )
{
case 0:
result = puts("MSG_KILL");
break;
case 1:
result = puts("MSG_TICK");
break;
case 2:
result = puts("MSG_GETTIME");
break;
case 3:
result = puts("MSG_SETTIME");
break;
case 4:
result = puts("MSG_INIT_RING");
break;
case 5:
result = puts("MSG_ELECTION_E");
break;
case 6:
result = puts("MSG_ELECTION_C");
break;
case 7:
result = puts("MSG_EXIT");
break;
case 8:
result = puts("MSG_404");
break;
case 9:
result = puts("MSG_GETTIME_R");
break;
case 0xA:
result = puts("CMD_KILL");
break;
case 0xB:
result = puts("CMD_REV");
break;
case 0xC:
result = puts("CMD_TIME");
break;
case 0xD:
result = puts("CMD_STAT");
break;
default:
result = puts("NO TYPE");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(_DWORD *a1)
{
unsigned int v1; // eax
int result; // eax

v1 = getpid();
printf("Node (%i): ", v1);
printf("source: %d", (unsigned int)a1[1]);
printf(", timestamp: %d", (unsigned int)a1[2]);
printf(", metadata: %d", (unsigned int)a1[4]);
printf(", body_length: %d", (unsigned int)a1[3]);
printf(", type: ");
switch ( *a1 )
{
case 0:
result = puts("MSG_KILL");
break;
case 1:
result = puts("MSG_TICK");
break;
case 2:
result = puts("MSG_GETTIME");
break;
case 3:
result = puts("MSG_SETTIME");
break;
case 4:
result = puts("MSG_INIT_RING");
break;
case 5:
result = puts("MSG_ELECTION_E");
break;
case 6:
result = puts("MSG_ELECTION_C");
break;
case 7:
result = puts("MSG_EXIT");
break;
case 8:
result = puts("MSG_404");
break;
case 9:
result = puts("MSG_GETTIME_R");
break;
case 0xA:
result = puts("CMD_KILL");
break;
case 0xB:
result = puts("CMD_REV");
break;
case 0xC:
result = puts("CMD_TIME");
break;
case 0xD:
result = puts("CMD_STAT");
break;
default:
result = puts("NO TYPE");
break;
}
return result;
}

original_code:
void printMessageHeader(MessageHeader *header){
  printf("Node (%i): ", getpid());
  printf("source: %d", header->source_pid);
  printf(", timestamp: %d", header->timestamp);
  printf(", metadata: %d", header->metadata);
  printf(", body_length: %d", header->body_length);
  printf(", type: ");
  switch (header->type) {
    case MSG_KILL:
      printf("MSG_KILL\n");
      break;
    case MSG_TICK:
      printf("MSG_TICK\n");
      break;
    case MSG_GETTIME:
      printf("MSG_GETTIME\n");
      break;
    case MSG_GETTIME_R:
      printf("MSG_GETTIME_R\n");
      break;
    case MSG_SETTIME:
      printf("MSG_SETTIME\n");
      break;
    case MSG_INIT_RING:
      printf("MSG_INIT_RING\n");
      break;
    case MSG_ELECTION_E:
      printf("MSG_ELECTION_E\n");
      break;
    case MSG_ELECTION_C:
      printf("MSG_ELECTION_C\n");
      break;
    case MSG_EXIT:
      printf("MSG_EXIT\n");
      break;
    case MSG_404:
      printf("MSG_404\n");
      break;
    case CMD_TIME:
      printf("CMD_TIME\n");
      break;
    case CMD_STAT:
      printf("CMD_STAT\n");
      break;
    case CMD_KILL:
      printf("CMD_KILL\n");
      break;
    case CMD_REV:
      printf("CMD_REV\n");
      break;
    default:
      printf("NO TYPE\n");
      break;
  }
}

canonical_original_code:
void printMessageHeader(struct header *header){
  printf("Node (%i): ", getpid());
  printf("source: %d", header->source_pid);
  printf(", timestamp: %d", header->timestamp);
  printf(", metadata: %d", header->metadata);
  printf(", body_length: %d", header->body_length);
  printf(", type: ");
  switch (header->type) {
    case MSG_KILL:
      printf("MSG_KILL\n");
      break;
    case MSG_TICK:
      printf("MSG_TICK\n");
      break;
    case MSG_GETTIME:
      printf("MSG_GETTIME\n");
      break;
    case MSG_GETTIME_R:
      printf("MSG_GETTIME_R\n");
      break;
    case MSG_SETTIME:
      printf("MSG_SETTIME\n");
      break;
    case MSG_INIT_RING:
      printf("MSG_INIT_RING\n");
      break;
    case MSG_ELECTION_E:
      printf("MSG_ELECTION_E\n");
      break;
    case MSG_ELECTION_C:
      printf("MSG_ELECTION_C\n");
      break;
    case MSG_EXIT:
      printf("MSG_EXIT\n");
      break;
    case MSG_404:
      printf("MSG_404\n");
      break;
    case CMD_TIME:
      printf("CMD_TIME\n");
      break;
    case CMD_STAT:
      printf("CMD_STAT\n");
      break;
    case CMD_KILL:
      printf("CMD_KILL\n");
      break;
    case CMD_REV:
      printf("CMD_REV\n");
      break;
    default:
      printf("NO TYPE\n");
      break;
  }
}


main

canonical_name: main

repo: chbarts/gopher

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setvbuf(stdout, 0LL, 2, 0LL);
run();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setvbuf(stdout, 0LL, 2, 0LL);
func12();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    setvbuf(stdout, ((void *)0), 2, 0);
    run();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


lenstr

repo: che-nikit/loooooong

decompiled_code:
// attributes: thunk
__int64 lenstr()
{
return __imp_lenstr();
}

canonical_decompiled_code:
__int64 func2()
{
return __imp_lenstr();
}

original_code:
int lenstr(unsigned char *t1)
{
 int i = 0;
 while(t1[i])
  i++;
 return i;
}

variable_types: i int


output

decompiled_code:
int __fastcall CSECOND::output(CSECOND *this, char *a2)
{
__int64 v3; // [rsp+18h] [rbp-18h]
FILE *stream; // [rsp+20h] [rbp-10h]
int i; // [rsp+2Ch] [rbp-4h]

stream = fopen(a2, "w");
if ( **((_DWORD **)this + 1) )
fputc(45, stream);
v3 = reverse();
for ( i = 0; i < (int)lenstr(); ++i )
fputc(*(unsigned __int8 *)(i + v3), stream);
return fclose(stream);
}

canonical_decompiled_code:
int __fastcall CSECOND::func8(CSECOND *this, char *a2)
{
__int64 v3; // [rsp+18h] [rbp-18h]
FILE *stream; // [rsp+20h] [rbp-10h]
int i; // [rsp+2Ch] [rbp-4h]

stream = fopen(a2, "w");
if ( **((_DWORD **)this + 1) )
fputc(45, stream);
v3 = reverse();
for ( i = 0; i < (int)func2(); ++i )
fputc(*(unsigned __int8 *)(i + v3), stream);
return fclose(stream);
}

original_code:
void output(unsigned char *t1, int *s)
{
 if(*s == '-')
  printf("%c",'-');
 int i = 0;
 while(t1[i])
 {
  printf("%c", t1[i]);
  i++;
 }
 printf("\n");
}

variable_types:
s
int *


main

repo: chenshuting/DataStructure

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
puts("Thank you for using data structure module!");
print_choice("Thank you for using data structure module!", argv);
do
{
putchar(62);
_isoc99_scanf("%d", v4);
if ( !v4[0] )
break;
switch ( v4[0] )
{
case 2:
CStack_test();
break;
case 3:
BTree_test();
break;
case 1:
SList_test();
break;
default:
print_choice("%d", v4);
break;
}
}
while ( v4[0] );
return 0;
}

original_code:
int main()
{
 int choice = 0;
 printf("Thank you for using data structure module!\n");
 print_choice();
 do{
  printf(">");
  scanf("%d", &choice);
  if(choice == 0)
   break;
  switch(choice) {
  case SLIST:
   SList_test();
   break;
  case CSTACK:
   CStack_test();
   break;
  case BTREE:
   BTree_test();
   break;
  default:
   print_choice();
   break;
  }
 }while(choice != 0);
}

variable_types: choice int


original_code:
void *VS_pop(VStack_t **stack)
{
 if (stack == ((void *)0) || *stack == ((void *)0))
  return ((void *)0);
 VStack_t *top = *stack;
 void *data = (void *)top->data;
 free(top);
 top = ((void *)0);
 *stack = (*stack)->next;
 return data;
}

canonical_original_code:
void *VS_pop(struct VStack **stack)
{
 if (stack == ((void *)0) || *stack == ((void *)0))
  return ((void *)0);
 struct VStack *top = *stack;
 void *data = (void *)top->data;
 free(top);
 top = ((void *)0);
 *stack = (*stack)->next;
 return data;
}

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

variable_types:
data
void *

return_type: void *


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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
void *VS_top(VStack_t *stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 return stack->data;
}

canonical_original_code:
void *VS_top(struct VStack *stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 return stack->data;
}

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


decompiled_code:
__int64 __fastcall VS_destroy(__int64 *a1)
{
__int64 v1; // rbx
void **v3; // rbp

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !*a1 )
return 0LL;
do
{
v3 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
if ( *v3 )
free(*v3);
free(v3);
}
while ( v1 );
*a1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
__int64 v1; // rbx
void **v3; // rbp

if ( !a1 )
return 0LL;
v1 = *a1;
if ( !*a1 )
return 0LL;
do
{
v3 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
if ( *v3 )
free(*v3);
free(v3);
}
while ( v1 );
*a1 = 0LL;
return 1LL;
}

original_code:
int VS_destroy(VStack_t **stack)
{
 if(stack == ((void *)0) || *stack == ((void *)0))
  return 0;
 VStack_t * pos = *stack, *next = pos->next;
 while (pos != ((void *)0)){
  next = pos->next;
  if (pos->data != ((void *)0)) {
   free(pos->data);
   pos->data = ((void *)0);
  }
  free(pos);
  pos = next;
 }
 *stack = ((void *)0);
 return 1;
}

canonical_original_code:
int VS_destroy(struct VStack **stack)
{
 if(stack == ((void *)0) || *stack == ((void *)0))
  return 0;
 struct VStack *pos = *stack; struct VStack *next = pos->next;
 while (pos != ((void *)0)){
  next = pos->next;
  if (pos->data != ((void *)0)) {
   free(pos->data);
   pos->data = ((void *)0);
  }
  free(pos);
  pos = next;
 }
 *stack = ((void *)0);
 return 1;
}

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


decompiled_code:
__int64 __fastcall VS_size(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
int VS_size(VStack_t *stack)
{
 if (stack == ((void *)0))
  return 0;
 int size = 0;
 VStack_t *pos = stack;
 while(pos != ((void *)0)){
  size++;
  pos = pos->next;
 }
 return size;
}

canonical_original_code:
int VS_size(struct VStack *stack)
{
 if (stack == ((void *)0))
  return 0;
 int size = 0;
 struct VStack *pos = stack;
 while(pos != ((void *)0)){
  size++;
  pos = pos->next;
 }
 return size;
}

variable_types: size int


decompiled_code:
_BOOL8 __fastcall is_empty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return a1 == 0;
}

original_code:
int is_empty(VStack_t *stack)
{
 if (stack == ((void *)0))
  return 1;
 return 0;
}

canonical_original_code:
int is_empty(struct VStack *stack)
{
 if (stack == ((void *)0))
  return 1;
 return 0;
}


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

if ( !a1 )
return 0LL;
result = *a1;
if ( *a1 )
*a1 = *(_QWORD *)(result + 8);
return result;
}

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

if ( !a1 )
return 0LL;
result = *a1;
if ( *a1 )
*a1 = *(_QWORD *)(result + 8);
return result;
}

original_code:
CStack_t *CS_pop(CStack_t **stack)
{
 if (stack == ((void *)0) || *stack == ((void *)0))
  return ((void *)0);
 CStack_t *top = *stack;
 *stack = (*stack)->next;
 return top;
}

canonical_original_code:
struct CStack *CS_pop(struct CStack **stack)
{
 if (stack == ((void *)0) || *stack == ((void *)0))
  return ((void *)0);
 struct CStack *top = *stack;
 *stack = (*stack)->next;
 return top;
}

variable_types:
stack
struct CStack **

variable_types: struct CStack { int value; struct CStack *next; } *


decompiled_code:
__int64 __fastcall CS_top(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1;
}

original_code:
CStack_t *CS_top(CStack_t *stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 return stack;
}

canonical_original_code:
struct CStack *CS_top(struct CStack *stack)
{
 if (stack == ((void *)0))
  return ((void *)0);
 return stack;
}

variable_types:
stack
struct CStack *

return_type: struct CStack { int value; struct CStack *next; } *


decompiled_code:
__int64 __fastcall CS_destroy(_QWORD *a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( !a1 )
return 0LL;
v2 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
*a1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( !a1 )
return 0LL;
v2 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
*a1 = 0LL;
return 1LL;
}

original_code:
int CS_destroy(CStack_t **stack)
{
 if(stack == ((void *)0) || *stack == ((void *)0))
  return 0;
 CStack_t * pos = *stack, *next = pos->next;
 while (pos != ((void *)0)){
  next = pos->next;
  free(pos);
  pos = next;
 }
 *stack = ((void *)0);
 return 1;
}

canonical_original_code:
int CS_destroy(struct CStack **stack)
{
 if(stack == ((void *)0) || *stack == ((void *)0))
  return 0;
 struct CStack *pos = *stack; struct CStack *next = pos->next;
 while (pos != ((void *)0)){
  next = pos->next;
  free(pos);
  pos = next;
 }
 *stack = ((void *)0);
 return 1;
}

variable_types: struct CStack { int value; struct CStack *next; } **


decompiled_code:
__int64 __fastcall CS_size(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
int CS_size(CStack_t *stack)
{
 if (stack == ((void *)0))
  return 0;
 int size = 0;
 CStack_t *pos = stack;
 while(pos != ((void *)0)){
  size++;
  pos = pos->next;
 }
 return size;
}

canonical_original_code:
int CS_size(struct CStack *stack)
{
 if (stack == ((void *)0))
  return 0;
 int size = 0;
 struct CStack *pos = stack;
 while(pos != ((void *)0)){
  size++;
  pos = pos->next;
 }
 return size;
}

user_defined_types: struct CStack { int value; struct CStack *next; }


decompiled_code:
int __fastcall CS_print(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
if ( a1 )
{
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
else
{
puts("The stack is NULL!");
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1)
{
unsigned int *v1; // rbx

v1 = a1;
if ( a1 )
{
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
}
else
{
puts("The stack is NULL!");
}
return putchar(10);
}

original_code:
void CS_print(CStack_t *stack)
{
 if (stack == ((void *)0))
  printf("The stack is NULL!\n");
 CStack_t *pos = stack;
 while (pos != ((void *)0)) {
  printf("%d ", pos->value);
  pos = pos->next;
 }
 printf("\n");
}

canonical_original_code:
void CS_print(struct CStack *stack)
{
 if (stack == ((void *)0))
  printf("The stack is NULL!\n");
 struct CStack *pos = stack;
 while (pos != ((void *)0)) {
  printf("%d ", pos->value);
  pos = pos->next;
 }
 printf("\n");
}


decompiled_code:
__int64 __fastcall BN_delete(void **a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 result; // rax
_QWORD *v4; // rdx
_QWORD *v5; // rax
_QWORD *v6; // rax
_QWORD *v7; // rcx
_QWORD *v8; // rdx
_QWORD *v9; // rdx
_QWORD *v10; // rdx

v2 = *a1;
result = 0LL;
v4 = 0LL;
if ( !*a1 )
return result;
while ( *(_DWORD *)v2 < (int)a2 )
{
v5 = (_QWORD *)v2[2];
LABEL_5:
v4 = v2;
if ( !v5 )
{
printf("Binary nodei[%d] is not find!\n", a2);
return 0LL;
}
v2 = v5;
}
if ( *(_DWORD *)v2 > (int)a2 )
{
v5 = (_QWORD *)v2[1];
goto LABEL_5;
}
v6 = (_QWORD *)v2[1];
v7 = (_QWORD *)v2[2];
if ( v4 )
{
if ( (_QWORD *)v4[1] == v2 )
{
if ( v7 )
{
v4[1] = v7;
do
{
v9 = v7;
v7 = (_QWORD *)v7[1];
}
while ( v7 );
v9[1] = v6;
}
else
{
v4[1] = v6;
}
}
else if ( (_QWORD *)v4[2] == v2 )
{
if ( v6 )
{
v4[2] = v6;
do
{
v10 = v6;
v6 = (_QWORD *)v6[2];
}
while ( v6 );
v10[2] = v7;
}
else
{
v4[2] = v7;
}
}
}
else if ( v6 )
{
*a1 = v6;
do
{
v8 = v6;
v6 = (_QWORD *)v6[2];
}
while ( v6 );
v8[2] = v7;
}
else if ( v7 )
{
*a1 = v7;
do
v7 = (_QWORD *)v7[1];
while ( v7 );
}
else
{
*a1 = 0LL;
}
printf("Binary nodei[%d] is find!\n", a2);
free(v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void **a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 result; // rax
_QWORD *v4; // rdx
_QWORD *v5; // rax
_QWORD *v6; // rax
_QWORD *v7; // rcx
_QWORD *v8; // rdx
_QWORD *v9; // rdx
_QWORD *v10; // rdx

v2 = *a1;
result = 0LL;
v4 = 0LL;
if ( !*a1 )
return result;
while ( *(_DWORD *)v2 < (int)a2 )
{
v5 = (_QWORD *)v2[2];
LABEL_5:
v4 = v2;
if ( !v5 )
{
printf("Binary nodei[%d] is not find!\n", a2);
return 0LL;
}
v2 = v5;
}
if ( *(_DWORD *)v2 > (int)a2 )
{
v5 = (_QWORD *)v2[1];
goto LABEL_5;
}
v6 = (_QWORD *)v2[1];
v7 = (_QWORD *)v2[2];
if ( v4 )
{
if ( (_QWORD *)v4[1] == v2 )
{
if ( v7 )
{
v4[1] = v7;
do
{
v9 = v7;
v7 = (_QWORD *)v7[1];
}
while ( v7 );
v9[1] = v6;
}
else
{
v4[1] = v6;
}
}
else if ( (_QWORD *)v4[2] == v2 )
{
if ( v6 )
{
v4[2] = v6;
do
{
v10 = v6;
v6 = (_QWORD *)v6[2];
}
while ( v6 );
v10[2] = v7;
}
else
{
v4[2] = v7;
}
}
}
else if ( v6 )
{
*a1 = v6;
do
{
v8 = v6;
v6 = (_QWORD *)v6[2];
}
while ( v6 );
v8[2] = v7;
}
else if ( v7 )
{
*a1 = v7;
do
v7 = (_QWORD *)v7[1];
while ( v7 );
}
else
{
*a1 = 0LL;
}
printf("Binary nodei[%d] is find!\n", a2);
free(v2);
return 1LL;
}

original_code:
int BN_delete(BinaryNode_t **root, int value)
{
 BinaryNode_t *parent = ((void *)0), *pos = *root;
 BinaryNode_t *left = ((void *)0), *right = ((void *)0);
 int ret = 0;
 if (root == ((void *)0) || *root == ((void *)0))
  return ret;
 while (pos != ((void *)0)) {
  if (pos->value < value) {
   parent = pos;
   pos = pos->right;
  } else if (pos->value > value) {
   parent = pos;
   pos = pos->left;
  } else {
   ret = 1;
   left = pos->left;
   right = pos->right;
   if (parent == ((void *)0)) {
    if (left != ((void *)0)) {
     *root = left;
     while (left->right!= ((void *)0))
      left = left->right;
     left->right = right;
    } else if (right != ((void *)0)){
     *root = right;
     while (right->left!= ((void *)0))
      right = right->left;
     right->left = left;
    } else {
     *root = ((void *)0);
    }
   } else if (parent->left == pos) {
    if(right != ((void *)0)) {
     parent->left = right;
     while(right->left != ((void *)0))
      right = right->left;
     right->left = left;
    } else {
     parent->left = left;
    }
   } else if (parent->right == pos) {
    if (left != ((void *)0)) {
     parent->right = left;
     while (left->right != ((void *)0))
      left = left->right;
     left->right = right;
    } else {
     parent->right = right;
    }
   }
   break;
  }
 }
 if (ret) {
  printf("Binary nodei[%d] is find!\n", value);
  free(pos);
 } else {
  printf("Binary nodei[%d] is not find!\n", value);
 }
 return ret;
}

canonical_original_code:
int BN_delete(struct BinaryNode **root, int value)
{
 struct BinaryNode *parent = ((void *)0); struct BinaryNode *pos = *root;
 struct BinaryNode *left = ((void *)0); struct BinaryNode *right = ((void *)0);
 int ret = 0;
 if (root == ((void *)0) || *root == ((void *)0))
  return ret;
 while (pos != ((void *)0)) {
  if (pos->value < value) {
   parent = pos;
   pos = pos->right;
  } else if (pos->value > value) {
   parent = pos;
   pos = pos->left;
  } else {
   ret = 1;
   left = pos->left;
   right = pos->right;
   if (parent == ((void *)0)) {
    if (left != ((void *)0)) {
     *root = left;
     while (left->right!= ((void *)0))
      left = left->right;
     left->right = right;
    } else if (right != ((void *)0)){
     *root = right;
     while (right->left!= ((void *)0))
      right = right->left;
     right->left = left;
    } else {
     *root = ((void *)0);
    }
   } else if (parent->left == pos) {
    if(right != ((void *)0)) {
     parent->left = right;
     while(right->left != ((void *)0))
      right = right->left;
     right->left = left;
    } else {
     parent->left = left;
    }
   } else if (parent->right == pos) {
    if (left != ((void *)0)) {
     parent->right = left;
     while (left->right != ((void *)0))
      left = left->right;
     left->right = right;
    } else {
     parent->right = right;
    }
   }
   break;
  }
 }
 if (ret) {
  printf("Binary nodei[%d] is find!\n", value);
  free(pos);
 } else {
  printf("Binary nodei[%d] is not find!\n", value);
 }
 return ret;
}

variable_types: struct BinaryNode { int value; struct BinaryNode *left; struct BinaryNode *right; } **

variable_types: value int

variable_types: ret int


decompiled_code:
__int64 __fastcall BN_search(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx

v2 = a1;
if ( a1 )
{
while ( 1 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 && !*(_QWORD *)(v3 + 16) )
break;
if ( *(_DWORD *)v3 == a2 )
return 0LL;
if ( *(_DWORD *)v3 < a2 )
v2 = *(_QWORD *)(v3 + 16);
}
}
else
{
puts("The binary tree is NULL");
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx

v2 = a1;
if ( a1 )
{
while ( 1 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 && !*(_QWORD *)(v3 + 16) )
break;
if ( *(_DWORD *)v3 == a2 )
return 0LL;
if ( *(_DWORD *)v3 < a2 )
v2 = *(_QWORD *)(v3 + 16);
}
}
else
{
puts("The binary tree is NULL");
v3 = 0LL;
}
return v3;
}

original_code:
BinaryNode_t *BN_search(BinaryNode_t *root, int value)
{
 if (root == ((void *)0)) {
  printf("The binary tree is NULL\n");
  return ((void *)0);
 }
 BinaryNode_t *node = root;
 int flag = 0;
 while (node->left != ((void *)0) || node->right != ((void *)0)) {
  if (node->value == value) {
   flag = 1;
   break;
  } else if (node->value < value) {
   node = node->right;
  } else {
   node = node->left;
  }
 }
 if (flag)
  node = ((void *)0);
 return node;
}

canonical_original_code:
struct BinaryNode *BN_search(struct BinaryNode *root, int value)
{
 if (root == ((void *)0)) {
  printf("The binary tree is NULL\n");
  return ((void *)0);
 }
 struct BinaryNode *node = root;
 int flag = 0;
 while (node->left != ((void *)0) || node->right != ((void *)0)) {
  if (node->value == value) {
   flag = 1;
   break;
  } else if (node->value < value) {
   node = node->right;
  } else {
   node = node->left;
  }
 }
 if (flag)
  node = ((void *)0);
 return node;
}

variable_types:
root
struct BinaryNode *

variable_types: struct BinaryNode { int value; struct BinaryNode *left; struct BinaryNode *right; } *

variable_types: flag int


decompiled_code:
void __fastcall BN_destroy(__int64 a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rdi

if ( a1 )
{
v2 = *(_QWORD **)a1;
if ( v2 )
{
BN_destroy(v2 + 1);
BN_destroy(*(_QWORD *)a1 + 16LL);
v3 = *(_QWORD **)a1;
if ( !*(_QWORD *)(*(_QWORD *)a1 + 8LL) && !v3[2] )
{
free(v3);
*(_QWORD *)a1 = 0LL;
}
}
}
}

original_code:
void BN_destroy(BinaryNode_t **root)
{
 if (root == ((void *)0) || *root == ((void *)0))
  return;
 BN_destroy(&(*root)->left);
 BN_destroy(&(*root)->right);
 BinaryNode_t *node = *root;
 if ((*root)->left == ((void *)0) && (*root)->right == ((void *)0)) {
  free(node);
  *root = ((void *)0);
 }
}

canonical_original_code:
void BN_destroy(struct BinaryNode **root)
{
 if (root == ((void *)0) || *root == ((void *)0))
  return;
 BN_destroy(&(*root)->left);
 BN_destroy(&(*root)->right);
 struct BinaryNode *node = *root;
 if ((*root)->left == ((void *)0) && (*root)->right == ((void *)0)) {
  free(node);
  *root = ((void *)0);
 }
}

user_defined_types: struct BinaryNode { int value; struct BinaryNode *left; struct BinaryNode *right; }


decompiled_code:
int __fastcall BN_post_print_r(unsigned int *a1, char a2, int a3)
{
unsigned int v4; // ebx
int v5; // ebx
int result; // eax

if ( a1 )
{
v4 = a3 + 1;
BN_post_print_r(*((_QWORD *)a1 + 1), 76LL, (unsigned int)(a3 + 1));
BN_post_print_r(*((_QWORD *)a1 + 2), 82LL, v4);
if ( a3 > 0 )
{
v5 = 0;
do
{
putchar(9);
++v5;
}
while ( a3 != v5 );
}
result = printf("%d %c:%d\n", (unsigned int)a3, (unsigned int)a2, *a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int *a1, char a2, int a3)
{
unsigned int v4; // ebx
int v5; // ebx
int result; // eax

if ( a1 )
{
v4 = a3 + 1;
func3(*((_QWORD *)a1 + 1), 76LL, (unsigned int)(a3 + 1));
func3(*((_QWORD *)a1 + 2), 82LL, v4);
if ( a3 > 0 )
{
v5 = 0;
do
{
putchar(9);
++v5;
}
while ( a3 != v5 );
}
result = printf("%d %c:%d\n", (unsigned int)a3, (unsigned int)a2, *a1);
}
return result;
}

original_code:
void BN_post_print_r(BinaryNode_t *root, char flag, int parent)
{
 if (root == ((void *)0))
  return;
 int cnt = 0;
 BN_post_print_r(root->left, 'L', parent + 1);
 BN_post_print_r(root->right, 'R', parent + 1);
 while(cnt < parent) {
  printf("\t");
  cnt++;
 }
 printf("%d %c:%d\n", parent, flag, root->value);
}

canonical_original_code:
void BN_post_print_r(struct BinaryNode *root, char flag, int parent)
{
 if (root == ((void *)0))
  return;
 int cnt = 0;
 BN_post_print_r(root->left, 'L', parent + 1);
 BN_post_print_r(root->right, 'R', parent + 1);
 while(cnt < parent) {
  printf("\t");
  cnt++;
 }
 printf("%d %c:%d\n", parent, flag, root->value);
}

variable_types: flag char

variable_types: parent int

variable_types: cnt int


decompiled_code:
int __fastcall BN_prev_print_r(unsigned int **a1, char a2, int a3)
{
int i; // ebx
int v5; // ebp
int result; // eax

if ( a1 )
{
if ( a3 > 0 )
{
for ( i = 0; i != a3; ++i )
putchar(9);
}
printf("%d %c:%d\n", (unsigned int)a3, (unsigned int)a2, *(unsigned int *)a1);
v5 = a3 + 1;
BN_post_print_r(a1[1], 76, v5);
result = BN_post_print_r(a1[2], 82, v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int **a1, char a2, int a3)
{
int i; // ebx
int v5; // ebp
int result; // eax

if ( a1 )
{
if ( a3 > 0 )
{
for ( i = 0; i != a3; ++i )
putchar(9);
}
printf("%d %c:%d\n", (unsigned int)a3, (unsigned int)a2, *(unsigned int *)a1);
v5 = a3 + 1;
func3(a1[1], 76, v5);
result = func3(a1[2], 82, v5);
}
return result;
}

original_code:
void BN_prev_print_r(BinaryNode_t *root, char flag, int parent)
{
 if (root == ((void *)0))
  return;
 int cnt = 0;
 while(cnt < parent) {
  printf("\t");
  cnt++;
 }
 printf("%d %c:%d\n", parent, flag, root->value);
 BN_post_print_r(root->left, 'L', parent + 1);
 BN_post_print_r(root->right,'R', parent + 1);
}

canonical_original_code:
void BN_prev_print_r(struct BinaryNode *root, char flag, int parent)
{
 if (root == ((void *)0))
  return;
 int cnt = 0;
 while(cnt < parent) {
  printf("\t");
  cnt++;
 }
 printf("%d %c:%d\n", parent, flag, root->value);
 BN_post_print_r(root->left, 'L', parent + 1);
 BN_post_print_r(root->right,'R', parent + 1);
}


decompiled_code:
int __fastcall BN_mid_print_r(unsigned int **a1, char a2, int a3)
{
int v4; // er14
int v5; // ebx
int result; // eax

if ( a1 )
{
v4 = a3 + 1;
BN_post_print_r(a1[1], 76, a3 + 1);
if ( a3 > 0 )
{
v5 = 0;
do
{
putchar(9);
++v5;
}
while ( a3 != v5 );
}
printf("%d %c:%d\n", (unsigned int)a3, (unsigned int)a2, *(unsigned int *)a1);
result = BN_post_print_r(a1[2], 82, v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(unsigned int **a1, char a2, int a3)
{
int v4; // er14
int v5; // ebx
int result; // eax

if ( a1 )
{
v4 = a3 + 1;
func3(a1[1], 76, a3 + 1);
if ( a3 > 0 )
{
v5 = 0;
do
{
putchar(9);
++v5;
}
while ( a3 != v5 );
}
printf("%d %c:%d\n", (unsigned int)a3, (unsigned int)a2, *(unsigned int *)a1);
result = func3(a1[2], 82, v4);
}
return result;
}

original_code:
void BN_mid_print_r(BinaryNode_t *root, char flag, int parent)
{
 if (root == ((void *)0))
  return;
 int cnt = 0;
 BN_post_print_r(root->left, 'L', parent + 1);
 while(cnt < parent) {
  printf("\t");
  cnt++;
 }
 printf("%d %c:%d\n", parent, flag, root->value);
 BN_post_print_r(root->right, 'R', parent + 1);
}

canonical_original_code:
void BN_mid_print_r(struct BinaryNode *root, char flag, int parent)
{
 if (root == ((void *)0))
  return;
 int cnt = 0;
 BN_post_print_r(root->left, 'L', parent + 1);
 while(cnt < parent) {
  printf("\t");
  cnt++;
 }
 printf("%d %c:%d\n", parent, flag, root->value);
 BN_post_print_r(root->right, 'R', parent + 1);
}


decompiled_code:
int __fastcall BN_prev_print(__int64 a1)
{
__int64 v2; // rsi
unsigned int *v3; // rbx
__int64 v4; // rsi
__int64 v5[2]; // [rsp+8h] [rbp-10h] BYREF

v5[0] = 0LL;
puts("++++++++++ Previous order ++++++++++++");
if ( !a1 )
return puts("The binary tree is NULL!");
VS_push(v5, a1);
while ( !(unsigned int)is_empty(v5[0]) )
{
v3 = (unsigned int *)VS_pop(v5);
printf("%d ", *v3);
v4 = *((_QWORD *)v3 + 2);
if ( v4 )
VS_push(v5, v4);
v2 = *((_QWORD *)v3 + 1);
if ( v2 )
VS_push(v5, v2);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v2; // rsi
unsigned int *v3; // rbx
__int64 v4; // rsi
__int64 v5[2]; // [rsp+8h] [rbp-10h] BYREF

v5[0] = 0LL;
puts("++++++++++ Previous order ++++++++++++");
if ( !a1 )
return puts("The binary tree is NULL!");
VS_push(v5, a1);
while ( !(unsigned int)is_empty(v5[0]) )
{
v3 = (unsigned int *)VS_pop(v5);
printf("%d ", *v3);
v4 = *((_QWORD *)v3 + 2);
if ( v4 )
VS_push(v5, v4);
v2 = *((_QWORD *)v3 + 1);
if ( v2 )
VS_push(v5, v2);
}
return putchar(10);
}

original_code:
void BN_prev_print(BinaryNode_t *root)
{
 VStack_t *stack = ((void *)0);
 BinaryNode_t *pos = root;
 printf("++++++++++ Previous order ++++++++++++\n");
 if (root == ((void *)0)) {
  printf("The binary tree is NULL!\n");
  return;
 }
 VS_push(&stack, pos);
 while(!is_empty(stack)){
  pos = (BinaryNode_t *)VS_pop(&stack);
  printf("%d ", pos->value);
  if (pos->right != ((void *)0))
   VS_push(&stack, pos->right);
  if (pos->left != ((void *)0))
   VS_push(&stack, pos->left);
 }
 printf("\n");
}

canonical_original_code:
void BN_prev_print(struct BinaryNode *root)
{
 struct VStack *stack = ((void *)0);
 struct BinaryNode *pos = root;
 printf("++++++++++ Previous order ++++++++++++\n");
 if (root == ((void *)0)) {
  printf("The binary tree is NULL!\n");
  return;
 }
 VS_push(&stack, pos);
 while(!is_empty(stack)){
  pos = (struct BinaryNode *)VS_pop(&stack);
  printf("%d ", pos->value);
  if (pos->right != ((void *)0))
   VS_push(&stack, pos->right);
  if (pos->left != ((void *)0))
   VS_push(&stack, pos->left);
 }
 printf("\n");
}


decompiled_code:
int __fastcall BN_post_print(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v2; // r12
unsigned int *v4; // rax
unsigned int *v5; // rbp
int v6; // eax
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = a1;
v7[0] = 0LL;
puts("++++++++++ Post order ++++++++++++");
if ( !a1 )
return puts("The binary tree is NULL!");
VS_push(v7, a1);
v2 = 0LL;
while ( 1 )
{
v6 = is_empty(v7[0]);
if ( !v1 )
{
if ( v6 )
break;
}
for ( ; v1; v1 = *(_QWORD *)(v1 + 8) )
VS_push(v7, v1);
v4 = (unsigned int *)VS_top(v7[0]);
v5 = v4;
v1 = *((_QWORD *)v4 + 2);
if ( (unsigned int *)v1 == v2 || !v1 )
{
printf("%d ", *v4);
VS_pop(v7);
v2 = v5;
v1 = 0LL;
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v2; // r12
unsigned int *v4; // rax
unsigned int *v5; // rbp
int v6; // eax
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = a1;
v7[0] = 0LL;
puts("++++++++++ Post order ++++++++++++");
if ( !a1 )
return puts("The binary tree is NULL!");
VS_push(v7, a1);
v2 = 0LL;
while ( 1 )
{
v6 = is_empty(v7[0]);
if ( !v1 )
{
if ( v6 )
break;
}
for ( ; v1; v1 = *(_QWORD *)(v1 + 8) )
VS_push(v7, v1);
v4 = (unsigned int *)VS_top(v7[0]);
v5 = v4;
v1 = *((_QWORD *)v4 + 2);
if ( (unsigned int *)v1 == v2 || !v1 )
{
printf("%d ", *v4);
VS_pop(v7);
v2 = v5;
v1 = 0LL;
}
}
return putchar(10);
}

original_code:
void BN_post_print(BinaryNode_t *root)
{
 VStack_t *stack = ((void *)0);
 BinaryNode_t *pos = root, *prev = ((void *)0);
 printf("++++++++++ Post order ++++++++++++\n");
 if (root == ((void *)0)) {
  printf("The binary tree is NULL!\n");
  return;
 }
 VS_push(&stack, pos);
 while (!is_empty(stack) || pos) {
  while (pos != ((void *)0)) {
   VS_push(&stack, pos);
   pos = pos->left;
  }
  pos = (BinaryNode_t *)VS_top(stack);
  if (pos->right == ((void *)0) || pos->right == prev){
   printf("%d ", pos->value);
   VS_pop(&stack);
   prev = pos;
   pos = ((void *)0);
  } else {
   pos = pos->right;
  }
 }
 printf("\n");
}

canonical_original_code:
void BN_post_print(struct BinaryNode *root)
{
 struct VStack *stack = ((void *)0);
 struct BinaryNode *pos = root; struct BinaryNode *prev = ((void *)0);
 printf("++++++++++ Post order ++++++++++++\n");
 if (root == ((void *)0)) {
  printf("The binary tree is NULL!\n");
  return;
 }
 VS_push(&stack, pos);
 while (!is_empty(stack) || pos) {
  while (pos != ((void *)0)) {
   VS_push(&stack, pos);
   pos = pos->left;
  }
  pos = (struct BinaryNode *)VS_top(stack);
  if (pos->right == ((void *)0) || pos->right == prev){
   printf("%d ", pos->value);
   VS_pop(&stack);
   prev = pos;
   pos = ((void *)0);
  } else {
   pos = pos->right;
  }
 }
 printf("\n");
}


decompiled_code:
int __fastcall BN_mid_print(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v3; // rbx
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = a1;
v4[0] = 0LL;
puts("++++++++++ Middle order ++++++++++++");
if ( !a1 )
return puts("The binary tree is NULL!");
while ( v1 )
{
do
{
VS_push(v4, v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
LABEL_4:
v3 = (unsigned int *)VS_pop(v4);
printf("%d ", *v3);
v1 = *((_QWORD *)v3 + 2);
}
if ( !(unsigned int)is_empty(v4[0]) )
goto LABEL_4;
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
__int64 v1; // rbx
unsigned int *v3; // rbx
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = a1;
v4[0] = 0LL;
puts("++++++++++ Middle order ++++++++++++");
if ( !a1 )
return puts("The binary tree is NULL!");
while ( v1 )
{
do
{
VS_push(v4, v1);
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
LABEL_4:
v3 = (unsigned int *)VS_pop(v4);
printf("%d ", *v3);
v1 = *((_QWORD *)v3 + 2);
}
if ( !(unsigned int)is_empty(v4[0]) )
goto LABEL_4;
return putchar(10);
}

original_code:
void BN_mid_print(BinaryNode_t *root)
{
 VStack_t *stack = ((void *)0);
 BinaryNode_t *pos = root;
 printf("++++++++++ Middle order ++++++++++++\n");
 if (root == ((void *)0)) {
  printf("The binary tree is NULL!\n");
  return;
 }
 while (pos || !is_empty(stack)) {
  while (pos) {
   VS_push(&stack, pos);
   pos = pos->left;
  }
  pos = (BinaryNode_t *)VS_pop(&stack);
  printf("%d ", pos->value);
  pos = pos->right;
 }
 printf("\n");
}

canonical_original_code:
void BN_mid_print(struct BinaryNode *root)
{
 struct VStack *stack = ((void *)0);
 struct BinaryNode *pos = root;
 printf("++++++++++ Middle order ++++++++++++\n");
 if (root == ((void *)0)) {
  printf("The binary tree is NULL!\n");
  return;
 }
 while (pos || !is_empty(stack)) {
  while (pos) {
   VS_push(&stack, pos);
   pos = pos->left;
  }
  pos = (struct BinaryNode *)VS_pop(&stack);
  printf("%d ", pos->value);
  pos = pos->right;
 }
 printf("\n");
}


decompiled_code:
int print_choice()
{
puts("Choice to run test unit!");
printf("%d. SList test\n", 1LL);
printf("%d. CStack test\n", 2LL);
printf("%d. BTree test\n", 3LL);
return puts("0. quit unit test");
}

canonical_decompiled_code:
int func0()
{
puts("Choice to run test unit!");
printf("%d. SList test\n", 1LL);
printf("%d. CStack test\n", 2LL);
printf("%d. BTree test\n", 3LL);
return puts("0. quit unit test");
}

original_code:
void print_choice()
{
 printf("Choice to run test unit!\n");
 printf("%d. SList test\n", SLIST);
 printf("%d. CStack test\n", CSTACK);
 printf("%d. BTree test\n", BTREE);
 printf("0. quit unit test\n");
}


decompiled_code:
int SList_test()
{
unsigned int v0; // eax
int i; // ebx
int v3; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v4; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+14h] [rbp-14h] BYREF
__int64 v6[2]; // [rsp+18h] [rbp-10h] BYREF

v6[0] = 0LL;
v5 = 0;
v4 = 0;
v3 = 0;
puts("----------------SList test----------------");
SList_print();
do
{
printf("Enter to choose operations:>");
_isoc99_scanf("%d", &v3);
if ( !v3 )
break;
switch ( v3 )
{
case 1:
printf("Enter num to find:>");
_isoc99_scanf("%d", &v4);
if ( (unsigned int)SL_find(v6[0], v4) )
printf("Find num:%d\n", v4);
else
printf("Not find num:%d\n", v4);
break;
case 2:
printf("Enter num to insert to end:>");
_isoc99_scanf("%d", &v4);
SL_add_tail(v6, v4);
SL_print(v6[0]);
break;
case 3:
printf("Enter num to insert to end:>");
_isoc99_scanf("%d", &v4);
SL_add(v6, v4);
SL_print(v6[0]);
break;
case 4:
SL_print(v6[0]);
printf("Enter num to delete element:>");
_isoc99_scanf("%d", &v4);
SL_delete(v6, v4);
SL_print(v6[0]);
break;
case 5:
puts("SList is destroyed!");
SL_destroy(v6);
SL_print(v6[0]);
break;
case 6:
do
{
printf("Enter list size:>");
_isoc99_scanf("%d", &v5);
if ( v5 < 0 )
puts("Please enter positive number!");
}
while ( v5 <= 0 );
puts("Start create list....");
v0 = time(0LL);
srand(v0);
if ( v5 > 0 )
{
for ( i = 0; i < v5; ++i )
{
v4 = rand() % 100;
SL_add_tail(v6, v4);
}
}
SL_print(v6[0]);
break;
default:
SList_print();
break;
}
}
while ( v3 > 0 );
return puts("--------------------------------------------------\n");
}

canonical_decompiled_code:
int func2()
{
unsigned int v0; // eax
int i; // ebx
int v3; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v4; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+14h] [rbp-14h] BYREF
__int64 v6[2]; // [rsp+18h] [rbp-10h] BYREF

v6[0] = 0LL;
v5 = 0;
v4 = 0;
v3 = 0;
puts("----------------SList test----------------");
func1();
do
{
printf("Enter to choose operations:>");
_isoc99_scanf("%d", &v3);
if ( !v3 )
break;
switch ( v3 )
{
case 1:
printf("Enter num to find:>");
_isoc99_scanf("%d", &v4);
if ( (unsigned int)SL_find(v6[0], v4) )
printf("Find num:%d\n", v4);
else
printf("Not find num:%d\n", v4);
break;
case 2:
printf("Enter num to insert to end:>");
_isoc99_scanf("%d", &v4);
SL_add_tail(v6, v4);
SL_print(v6[0]);
break;
case 3:
printf("Enter num to insert to end:>");
_isoc99_scanf("%d", &v4);
SL_add(v6, v4);
SL_print(v6[0]);
break;
case 4:
SL_print(v6[0]);
printf("Enter num to delete element:>");
_isoc99_scanf("%d", &v4);
SL_delete(v6, v4);
SL_print(v6[0]);
break;
case 5:
puts("SList is destroyed!");
SL_destroy(v6);
SL_print(v6[0]);
break;
case 6:
do
{
printf("Enter list size:>");
_isoc99_scanf("%d", &v5);
if ( v5 < 0 )
puts("Please enter positive number!");
}
while ( v5 <= 0 );
puts("Start create list....");
v0 = time(0LL);
srand(v0);
if ( v5 > 0 )
{
for ( i = 0; i < v5; ++i )
{
v4 = rand() % 100;
SL_add_tail(v6, v4);
}
}
SL_print(v6[0]);
break;
default:
func1();
break;
}
}
while ( v3 > 0 );
return puts("--------------------------------------------------\n");
}

original_code:
void SList_test()
{
 SList_t *head = ((void *)0);
 int list_size = 0, num = 0, i = 0, choice = 0;
 printf("----------------SList test----------------\n");
 _SList_print();
 do {
  printf("Enter to choose operations:>");
  scanf("%d", &choice);
  if (choice == 0)
   break;
  switch(choice){
  case 1:
   {
    printf("Enter num to find:>");
    scanf("%d", &num);
    int ret = SL_find(head, num);
    if (ret)
     printf("Find num:%d\n", num);
    else
     printf("Not find num:%d\n", num);
   }
   break;
  case 2:
   {
    printf("Enter num to insert to end:>");
    scanf("%d", &num);
    SL_add_tail(&head, num);
    SL_print(head);
   }
   break;
  case 3:
   {
    printf("Enter num to insert to end:>");
    scanf("%d", &num);
    SL_add(&head, num);
    SL_print(head);
   }
   break;
  case 4:
   {
    SL_print(head);
    printf("Enter num to delete element:>");
    scanf("%d", &num);
    SL_delete(&head, num);
    SL_print(head);
   }
   break;
  case 5:
   {
    printf("SList is destroyed!\n");
    SL_destroy(&head);
    SL_print(head);
   }
   break;
  case 6:
   {
    do {
     printf("Enter list size:>");
     scanf("%d", &list_size);
     if (list_size < 0)
      printf("Please enter positive number!\n");
    }while(list_size <= 0);
    printf("Start create list....\n");
    srand((unsigned)time(((void *)0)));
    for (i = 0; i < list_size; i++) {
     num = rand() % 100;
     SL_add_tail(&head, num);
    }
    SL_print(head);
   }
   break;
  default:
   _SList_print();
   break;
  }
 } while(choice > 0);
 printf("--------------------------------------------------\n\n");
}

canonical_original_code:
void SList_test()
{
 struct SList *head = ((void *)0);
 int list_size = 0; int num = 0; int i = 0; int choice = 0;
 printf("----------------SList test----------------\n");
 _SList_print();
 do {
  printf("Enter to choose operations:>");
  scanf("%d", &choice);
  if (choice == 0)
   break;
  switch(choice){
  case 1:
   {
    printf("Enter num to find:>");
    scanf("%d", &num);
    int ret = SL_find(head, num);
    if (ret)
     printf("Find num:%d\n", num);
    else
     printf("Not find num:%d\n", num);
   }
   break;
  case 2:
   {
    printf("Enter num to insert to end:>");
    scanf("%d", &num);
    SL_add_tail(&head, num);
    SL_print(head);
   }
   break;
  case 3:
   {
    printf("Enter num to insert to end:>");
    scanf("%d", &num);
    SL_add(&head, num);
    SL_print(head);
   }
   break;
  case 4:
   {
    SL_print(head);
    printf("Enter num to delete element:>");
    scanf("%d", &num);
    SL_delete(&head, num);
    SL_print(head);
   }
   break;
  case 5:
   {
    printf("SList is destroyed!\n");
    SL_destroy(&head);
    SL_print(head);
   }
   break;
  case 6:
   {
    do {
     printf("Enter list size:>");
     scanf("%d", &list_size);
     if (list_size < 0)
      printf("Please enter positive number!\n");
    }while(list_size <= 0);
    printf("Start create list....\n");
    srand((unsigned int)time(((void *)0)));
    for (i = 0; i < list_size; i++) {
     num = rand() % 100;
     SL_add_tail(&head, num);
    }
    SL_print(head);
   }
   break;
  default:
   _SList_print();
   break;
  }
 } while(choice > 0);
 printf("--------------------------------------------------\n\n");
}

variable_types: struct SList { int value; struct SList *next; } *

variable_types: num int

variable_types: i int

variable_types: choice int


decompiled_code:
int CStack_test()
{
unsigned int v0; // eax
int i; // ebx
unsigned int *v2; // rax
unsigned int *v3; // rax
int v5; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v6; // [rsp+10h] [rbp-18h] BYREF
int v7; // [rsp+14h] [rbp-14h] BYREF
__int64 v8[2]; // [rsp+18h] [rbp-10h] BYREF

v8[0] = 0LL;
v7 = 0;
v6 = 0;
v5 = 0;
puts("----------------CStack test----------------");
CStack_print();
do
{
printf("Enter to choose operations:>");
_isoc99_scanf("%d", &v5);
if ( !v5 )
break;
switch ( v5 )
{
case 1:
puts("Create stack by size");
do
{
printf("Enter stack size:>");
_isoc99_scanf("%d", &v7);
}
while ( v7 <= 0 );
v0 = time(0LL);
srand(v0);
if ( v7 > 0 )
{
for ( i = 0; i < v7; ++i )
{
v6 = rand() % 100;
CS_push(v8, v6);
}
}
goto LABEL_7;
case 2:
printf("Enter stack element:>");
_isoc99_scanf("%d", &v6);
CS_push(v8, v6);
CS_print(v8[0]);
break;
case 3:
puts("Pop stack");
v2 = (unsigned int *)CS_pop(v8);
printf("The pop element is %d\n", *v2);
CS_print(v8[0]);
break;
case 4:
puts("Top of stack");
v3 = (unsigned int *)CS_top(v8[0]);
printf("The top element is %d\n", *v3);
CS_print(v8[0]);
break;
case 5:
puts("Desctroy the stack");
CS_destroy(v8);
CS_print(v8[0]);
break;
case 6:
LABEL_7:
CS_print(v8[0]);
break;
default:
CStack_print();
break;
}
}
while ( v5 );
return puts("-------------------------------------------");
}

canonical_decompiled_code:
int func4()
{
unsigned int v0; // eax
int i; // ebx
unsigned int *v2; // rax
unsigned int *v3; // rax
int v5; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v6; // [rsp+10h] [rbp-18h] BYREF
int v7; // [rsp+14h] [rbp-14h] BYREF
__int64 v8[2]; // [rsp+18h] [rbp-10h] BYREF

v8[0] = 0LL;
v7 = 0;
v6 = 0;
v5 = 0;
puts("----------------CStack test----------------");
func3();
do
{
printf("Enter to choose operations:>");
_isoc99_scanf("%d", &v5);
if ( !v5 )
break;
switch ( v5 )
{
case 1:
puts("Create stack by size");
do
{
printf("Enter stack size:>");
_isoc99_scanf("%d", &v7);
}
while ( v7 <= 0 );
v0 = time(0LL);
srand(v0);
if ( v7 > 0 )
{
for ( i = 0; i < v7; ++i )
{
v6 = rand() % 100;
CS_push(v8, v6);
}
}
goto LABEL_7;
case 2:
printf("Enter stack element:>");
_isoc99_scanf("%d", &v6);
CS_push(v8, v6);
CS_print(v8[0]);
break;
case 3:
puts("Pop stack");
v2 = (unsigned int *)CS_pop(v8);
printf("The pop element is %d\n", *v2);
CS_print(v8[0]);
break;
case 4:
puts("Top of stack");
v3 = (unsigned int *)CS_top(v8[0]);
printf("The top element is %d\n", *v3);
CS_print(v8[0]);
break;
case 5:
puts("Desctroy the stack");
CS_destroy(v8);
CS_print(v8[0]);
break;
case 6:
LABEL_7:
CS_print(v8[0]);
break;
default:
func3();
break;
}
}
while ( v5 );
return puts("-------------------------------------------");
}

original_code:
void CStack_test()
{
 CStack_t *stack = ((void *)0), *pos = ((void *)0);
 int stack_size = 0, num = 0, i = 0, choice = 0;
 printf("----------------CStack test----------------\n");
 _CStack_print();
 do {
  printf("Enter to choose operations:>");
  scanf("%d", &choice);
  if (choice == 0)
   break;
  switch(choice){
  case 1:
   printf("Create stack by size\n");
   do{
    printf("Enter stack size:>");
    scanf("%d", &stack_size);
   }while(stack_size <= 0);
   srand((unsigned)time(((void *)0)));
   for (i = 0; i < stack_size; i++) {
    num = rand() % 100;
    CS_push(&stack, num);
   }
   CS_print(stack);
   break;
  case 2:
   printf("Enter stack element:>");
   scanf("%d", &num);
   CS_push(&stack, num);
   CS_print(stack);
   break;
  case 3:
   printf("Pop stack\n");
   pos = CS_pop(&stack);
   printf("The pop element is %d\n", pos->value);
   CS_print(stack);
   break;
  case 4:
   printf("Top of stack\n");
   pos = CS_top(stack);
   printf("The top element is %d\n", pos->value);
   CS_print(stack);
   break;
  case 5:
   printf("Desctroy the stack\n");
   CS_destroy(&stack);
   CS_print(stack);
   break;
  case 6:
   CS_print(stack);
   break;
  default:
   _CStack_print(stack);
   break;
  }
 }while(choice != 0);
 printf("-------------------------------------------\n");
}

canonical_original_code:
void CStack_test()
{
 struct CStack *stack = ((void *)0); struct CStack *pos = ((void *)0);
 int stack_size = 0; int num = 0; int i = 0; int choice = 0;
 printf("----------------CStack test----------------\n");
 _CStack_print();
 do {
  printf("Enter to choose operations:>");
  scanf("%d", &choice);
  if (choice == 0)
   break;
  switch(choice){
  case 1:
   printf("Create stack by size\n");
   do{
    printf("Enter stack size:>");
    scanf("%d", &stack_size);
   }while(stack_size <= 0);
   srand((unsigned int)time(((void *)0)));
   for (i = 0; i < stack_size; i++) {
    num = rand() % 100;
    CS_push(&stack, num);
   }
   CS_print(stack);
   break;
  case 2:
   printf("Enter stack element:>");
   scanf("%d", &num);
   CS_push(&stack, num);
   CS_print(stack);
   break;
  case 3:
   printf("Pop stack\n");
   pos = CS_pop(&stack);
   printf("The pop element is %d\n", pos->value);
   CS_print(stack);
   break;
  case 4:
   printf("Top of stack\n");
   pos = CS_top(stack);
   printf("The top element is %d\n", pos->value);
   CS_print(stack);
   break;
  case 5:
   printf("Desctroy the stack\n");
   CS_destroy(&stack);
   CS_print(stack);
   break;
  case 6:
   CS_print(stack);
   break;
  default:
   _CStack_print(stack);
   break;
  }
 }while(choice != 0);
 printf("-------------------------------------------\n");
}


decompiled_code:
int BTree_test()
{
unsigned int v0; // eax
int i; // ebx
int v3; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v4; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+14h] [rbp-14h] BYREF
__int64 v6[2]; // [rsp+18h] [rbp-10h] BYREF

v6[0] = 0LL;
v5 = 0;
v4 = 0;
v3 = 0;
puts("----------------Btree test----------------");
Btree_print();
do
{
printf("Enter to choose operations:>");
_isoc99_scanf("%d", &v3);
if ( !v3 )
break;
switch ( v3 )
{
case 1:
puts("Create binary tree by size");
do
{
printf("Enter binary tree size:>");
_isoc99_scanf("%d", &v5);
}
while ( v5 <= 0 );
v0 = time(0LL);
srand(v0);
if ( v5 > 0 )
{
for ( i = 0; i < v5; ++i )
{
v4 = rand() % 100;
BN_insert(v6, v4);
}
}
break;
case 2:
printf("Enter element num and insert to BT:>");
_isoc99_scanf("%d", &v4);
BN_insert(v6, v4);
break;
case 3:
printf("Enter element num and delete from BT:>");
_isoc99_scanf("%d", &v4);
BN_delete(v6, v4);
break;
case 4:
puts("Previous Order:");
BN_prev_print_r(v6[0], 84LL, 0LL);
break;
case 5:
puts("Middle Order:");
BN_mid_print_r(v6[0], 84LL, 0LL);
break;
case 6:
puts("Post Order:");
BN_post_print_r(v6[0], 84LL, 0LL);
break;
case 7:
puts("Previous Order use stack:");
BN_prev_print(v6[0]);
break;
case 8:
puts("Middle Order use stack:");
BN_mid_print(v6[0]);
break;
case 9:
puts("Post Order use stack:");
BN_post_print(v6[0]);
break;
case 10:
puts("Binary tree is destoyed!");
BN_destroy(v6);
break;
default:
Btree_print();
break;
}
}
while ( v3 );
return puts("-------------------------------------------");
}

canonical_decompiled_code:
int func6()
{
unsigned int v0; // eax
int i; // ebx
int v3; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v4; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+14h] [rbp-14h] BYREF
__int64 v6[2]; // [rsp+18h] [rbp-10h] BYREF

v6[0] = 0LL;
v5 = 0;
v4 = 0;
v3 = 0;
puts("----------------Btree test----------------");
func5();
do
{
printf("Enter to choose operations:>");
_isoc99_scanf("%d", &v3);
if ( !v3 )
break;
switch ( v3 )
{
case 1:
puts("Create binary tree by size");
do
{
printf("Enter binary tree size:>");
_isoc99_scanf("%d", &v5);
}
while ( v5 <= 0 );
v0 = time(0LL);
srand(v0);
if ( v5 > 0 )
{
for ( i = 0; i < v5; ++i )
{
v4 = rand() % 100;
BN_insert(v6, v4);
}
}
break;
case 2:
printf("Enter element num and insert to BT:>");
_isoc99_scanf("%d", &v4);
BN_insert(v6, v4);
break;
case 3:
printf("Enter element num and delete from BT:>");
_isoc99_scanf("%d", &v4);
BN_delete(v6, v4);
break;
case 4:
puts("Previous Order:");
BN_prev_print_r(v6[0], 84LL, 0LL);
break;
case 5:
puts("Middle Order:");
BN_mid_print_r(v6[0], 84LL, 0LL);
break;
case 6:
puts("Post Order:");
BN_post_print_r(v6[0], 84LL, 0LL);
break;
case 7:
puts("Previous Order use stack:");
BN_prev_print(v6[0]);
break;
case 8:
puts("Middle Order use stack:");
BN_mid_print(v6[0]);
break;
case 9:
puts("Post Order use stack:");
BN_post_print(v6[0]);
break;
case 10:
puts("Binary tree is destoyed!");
BN_destroy(v6);
break;
default:
func5();
break;
}
}
while ( v3 );
return puts("-------------------------------------------");
}

original_code:
void BTree_test()
{
 BinaryNode_t *root = ((void *)0), *pos = ((void *)0);
 int bt_size = 0, num = 0, i = 0, choice = 0;
 printf("----------------Btree test----------------\n");
 _Btree_print();
 do {
  printf("Enter to choose operations:>");
  scanf("%d", &choice);
  if (choice == 0)
   break;
  switch(choice){
  case 1:
   printf("Create binary tree by size\n");
   do{
    printf("Enter binary tree size:>");
    scanf("%d", &bt_size);
   }while(bt_size <= 0);
   srand((unsigned)time(((void *)0)));
   for (i = 0; i < bt_size; i++) {
    num = rand() % 100;
    BN_insert(&root, num);
   }
   break;
  case 2:
   printf("Enter element num and insert to BT:>");
   scanf("%d", &num);
   BN_insert(&root, num);
   break;
  case 3:
   printf("Enter element num and delete from BT:>");
   scanf("%d", &num);
   BN_delete(&root, num);
   break;
  case 4:
   printf("Previous Order:\n");
   BN_prev_print_r(root, 'T', 0);
   break;
  case 5:
   printf("Middle Order:\n");
   BN_mid_print_r(root, 'T', 0);
   break;
  case 6:
   printf("Post Order:\n");
   BN_post_print_r(root, 'T', 0);
   break;
  case 7:
   printf("Previous Order use stack:\n");
   BN_prev_print(root);
   break;
  case 8:
   printf("Middle Order use stack:\n");
   BN_mid_print(root);
   break;
  case 9:
   printf("Post Order use stack:\n");
   BN_post_print(root);
   break;
  case 10:
   printf("Binary tree is destoyed!\n");
   BN_destroy(&root);
   break;
  default:
   _Btree_print();
   break;
  }
 }while(choice != 0);
 printf("-------------------------------------------\n");
}

canonical_original_code:
void BTree_test()
{
 struct BinaryNode *root = ((void *)0); struct BinaryNode *pos = ((void *)0);
 int bt_size = 0; int num = 0; int i = 0; int choice = 0;
 printf("----------------Btree test----------------\n");
 _Btree_print();
 do {
  printf("Enter to choose operations:>");
  scanf("%d", &choice);
  if (choice == 0)
   break;
  switch(choice){
  case 1:
   printf("Create binary tree by size\n");
   do{
    printf("Enter binary tree size:>");
    scanf("%d", &bt_size);
   }while(bt_size <= 0);
   srand((unsigned int)time(((void *)0)));
   for (i = 0; i < bt_size; i++) {
    num = rand() % 100;
    BN_insert(&root, num);
   }
   break;
  case 2:
   printf("Enter element num and insert to BT:>");
   scanf("%d", &num);
   BN_insert(&root, num);
   break;
  case 3:
   printf("Enter element num and delete from BT:>");
   scanf("%d", &num);
   BN_delete(&root, num);
   break;
  case 4:
   printf("Previous Order:\n");
   BN_prev_print_r(root, 'T', 0);
   break;
  case 5:
   printf("Middle Order:\n");
   BN_mid_print_r(root, 'T', 0);
   break;
  case 6:
   printf("Post Order:\n");
   BN_post_print_r(root, 'T', 0);
   break;
  case 7:
   printf("Previous Order use stack:\n");
   BN_prev_print(root);
   break;
  case 8:
   printf("Middle Order use stack:\n");
   BN_mid_print(root);
   break;
  case 9:
   printf("Post Order use stack:\n");
   BN_post_print(root);
   break;
  case 10:
   printf("Binary tree is destoyed!\n");
   BN_destroy(&root);
   break;
  default:
   _Btree_print();
   break;
  }
 }while(choice != 0);
 printf("-------------------------------------------\n");
}


decompiled_code:
__int64 __fastcall SL_delete(_QWORD **a1, int a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rax
__int64 result; // rax

v3 = *a1;
if ( !v3 )
return 0LL;
if ( a2 == *(_DWORD *)v3 )
{
LABEL_6:
*a1 = (_QWORD *)v3[1];
free(v3);
result = 1LL;
}
else
{
while ( 1 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
if ( !v3 )
break;
if ( *(_DWORD *)v3 == a2 && v3 == v4 )
goto LABEL_6;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1, int a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rax
__int64 result; // rax

v3 = *a1;
if ( !v3 )
return 0LL;
if ( a2 == *(_DWORD *)v3 )
{
LABEL_6:
*a1 = (_QWORD *)v3[1];
free(v3);
result = 1LL;
}
else
{
while ( 1 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
if ( !v3 )
break;
if ( *(_DWORD *)v3 == a2 && v3 == v4 )
goto LABEL_6;
}
result = 0LL;
}
return result;
}

original_code:
int SL_delete(SList_t **head, int data)
{
 SList_t *pos = *head, *prev = *head;
 int result = 0;
 while(pos != ((void *)0)) {
  if (pos->value == data) {
   if (pos == prev) {
    *head = pos->next;
    free(pos);
    pos = ((void *)0);
    result = 1;
    break;
   }
  }
  prev = pos;
  pos = pos->next;
 }
 return result;
}

canonical_original_code:
int SL_delete(struct SList **head, int data)
{
 struct SList *pos = *head; struct SList *prev = *head;
 int result = 0;
 while(pos != ((void *)0)) {
  if (pos->value == data) {
   if (pos == prev) {
    *head = pos->next;
    free(pos);
    pos = ((void *)0);
    result = 1;
    break;
   }
  }
  prev = pos;
  pos = pos->next;
 }
 return result;
}

variable_types: struct SList { int value; struct SList *next; } **

variable_types: data int

variable_types: result int


decompiled_code:
int __fastcall SL_print(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( !a1 )
return puts("SList is NULL");
v1 = a1;
puts("Print SList>:");
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( !a1 )
return puts("SList is NULL");
v1 = a1;
puts("Print SList>:");
do
{
printf("%d ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( v1 );
return putchar(10);
}

original_code:
void SL_print(SList_t *head)
{
 if (head == ((void *)0)){
  printf("SList is NULL\n");
  return;
 }
 SList_t *pos = head;
 printf("Print SList>:\n");
 while (pos != ((void *)0)) {
  printf("%d ", pos->value);
  pos = pos->next;
 }
 printf("\n");
}

canonical_original_code:
void SL_print(struct SList *head)
{
 if (head == ((void *)0)){
  printf("SList is NULL\n");
  return;
 }
 struct SList *pos = head;
 printf("Print SList>:\n");
 while (pos != ((void *)0)) {
  printf("%d ", pos->value);
  pos = pos->next;
 }
 printf("\n");
}

user_defined_types: struct SList { int value; struct SList *next; }


decompiled_code:
__int64 __fastcall SL_size(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
int SL_size(SList_t *head) {
 int ret = 0;
 SList_t *pos = head;
 while(pos != ((void *)0)) {
  ret++;
  pos = pos->next;
 }
 return ret;
}

canonical_original_code:
int SL_size(struct SList *head) {
 int ret = 0;
 struct SList *pos = head;
 while(pos != ((void *)0)) {
  ret++;
  pos = pos->next;
 }
 return ret;
}


decompiled_code:
__int64 __fastcall SL_find(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)a1 != a2 )
{
a1 = *(_QWORD *)(a1 + 8);
if ( !a1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)a1 != a2 )
{
a1 = *(_QWORD *)(a1 + 8);
if ( !a1 )
return 0LL;
}
return 1LL;
}

original_code:
int SL_find(SList_t *head, int data)
{
 int ret = 0;
 SList_t *pos = head;
 while (pos != ((void *)0)) {
  if (pos->value == data) {
   ret = 1;
   break;
  }
  pos = pos->next;
 }
 return ret;
}

canonical_original_code:
int SL_find(struct SList *head, int data)
{
 int ret = 0;
 struct SList *pos = head;
 while (pos != ((void *)0)) {
  if (pos->value == data) {
   ret = 1;
   break;
  }
  pos = pos->next;
 }
 return ret;
}


repo: chenyf/wsh

decompiled_code:
__int64 __fastcall msg_array_import(__int64 a1, int a2, const char **a3)
{
const char **v3; // r12
__int64 v4; // r15
__int64 v5; // rbp
const char *v6; // r13
size_t v7; // rbx

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
*(_QWORD *)(a1 + 8188) = 0LL;
memset(
(void *)((a1 + 12) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 4 - (((_DWORD)a1 + 12) & 0xFFFFFFF8) + 0x2000) >> 3));
if ( a2 <= 0 )
return 0LL;
v3 = a3;
v4 = (__int64)&a3[(unsigned int)(a2 - 1) + 1];
v5 = 0LL;
while ( 1 )
{
v6 = *v3;
v7 = strlen(*v3);
if ( 0x2000 - v5 < v7 + 1 )
break;
memcpy((void *)(a1 + 4 + v5), v6, v7);
v5 += v7 + 1;
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, const char **a3)
{
const char **v3; // r12
__int64 v4; // r15
__int64 v5; // rbp
const char *v6; // r13
size_t v7; // rbx

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
*(_QWORD *)(a1 + 8188) = 0LL;
memset(
(void *)((a1 + 12) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 4 - (((_DWORD)a1 + 12) & 0xFFFFFFF8) + 0x2000) >> 3));
if ( a2 <= 0 )
return 0LL;
v3 = a3;
v4 = (__int64)&a3[(unsigned int)(a2 - 1) + 1];
v5 = 0LL;
while ( 1 )
{
v6 = *v3;
v7 = strlen(*v3);
if ( 0x2000 - v5 < v7 + 1 )
break;
memcpy((void *)(a1 + 4 + v5), v6, v7);
v5 += v7 + 1;
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int msg_array_import(msg__array_t * a, int count, const char ** ptr) {
  size_t off = 0;
  size_t len = 0;
  int i;
  a->count = count;
  memset(a->buf, 0, sizeof(a->buf));
  for (i = 0; i < count; i++) {
    len = strlen(ptr[i]);
    if ((sizeof(a->buf) - off) < (len + 1)) {
      return -1;
    }
    memcpy(a->buf + off, ptr[i], len);
    off += len + 1;
  }
  return 0;
}

canonical_original_code:
int msg_array_import(struct msg__array_s *a, int count, char **ptr) {
  unsigned long off = 0;
  unsigned long len = 0;
  int i;
  a->count = count;
  memset(a->buf, 0, sizeof(a->buf));
  for (i = 0; i < count; i++) {
    len = strlen(ptr[i]);
    if ((sizeof(a->buf) - off) < (len + 1)) {
      return -1;
    }
    memcpy(a->buf + off, ptr[i], len);
    off += len + 1;
  }
  return 0;
}

variable_types: struct msg__array_s { int count; char buf[-1]; } *

variable_types: count int

variable_types:
ptr
char **

variable_types:
off
unsigned long

variable_types:
len
unsigned long


original_code:
int msg_rlimit_import(msg__rlimit_t *r) {
  int i;
  struct rlimit rlim;
  char *value;
  int rv;
  r->count = 0;
  memset(r->rlim, 0, sizeof(r->rlim));
  for (i = 0; i < (sizeof(rlimits)/sizeof(rlimits[0])); i++) {
    rlim = rlimits[i].rlim;
    value = getenv(rlimits[i].name);
    if (value != ((void *)0)) {
      rv = sscanf(value, "%ld %ld", &rlim.rlim_cur, &rlim.rlim_max);
      if (rv > 0) {
        if (rv == 1) {
          rlim.rlim_max = rlim.rlim_cur;
        }
      } else {
        (*__errno_location ()) = 22;
        return -1;
      }
    }
    r->rlim[r->count].id = rlimits[i].id;
    r->rlim[r->count].rlim = rlim;
    r->count++;
  }
  return 0;
}

canonical_original_code:
int msg_rlimit_import(struct msg__rlimit_s *r) {
  int i;
  struct rlimit rlim;
  char *value;
  int rv;
  r->count = 0;
  memset(r->rlim, 0, sizeof(r->rlim));
  for (i = 0; i < (sizeof(rlimits)/sizeof(rlimits[0])); i++) {
    rlim = rlimits[i].rlim;
    value = getenv(rlimits[i].name);
    if (value != ((void *)0)) {
      rv = sscanf(value, "%ld %ld", &rlim.rlim_cur, &rlim.rlim_max);
      if (rv > 0) {
        if (rv == 1) {
          rlim.rlim_max = rlim.rlim_cur;
        }
      } else {
        (*__errno_location ()) = 22;
        return -1;
      }
    }
    r->rlim[r->count].id = rlimits[i].id;
    r->rlim[r->count].rlim = rlim;
    r->count++;
  }
  return 0;
}

variable_types: struct msg__rlimit_s { int count; struct { int id; struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; } rlim; } rlim[-1]; } *

variable_types:
value
char *

variable_types: rv int

user_defined_types: struct msg__rlimit_s { int count; struct { int id; struct rlimit rlim; } rlim[-1]; }


decompiled_code:
__int64 __fastcall msg_rlimit_export(_DWORD *a1)
{
const struct rlimit *v1; // rbp
int v2; // er12
unsigned int v3; // ebx

if ( (int)*a1 <= 0 )
return 0;
v1 = (const struct rlimit *)(a1 + 4);
v2 = 0;
while ( 1 )
{
v3 = setrlimit(v1[-1].rlim_max, v1);
if ( v3 == -1 )
break;
++v2;
v1 = (const struct rlimit *)((char *)v1 + 24);
if ( *a1 <= v2 )
return 0;
}
fprintf(stderr, "%d\n", (unsigned int)a1[6 * v2 + 2]);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
const struct rlimit *v1; // rbp
int v2; // er12
unsigned int v3; // ebx

if ( (int)*a1 <= 0 )
return 0;
v1 = (const struct rlimit *)(a1 + 4);
v2 = 0;
while ( 1 )
{
v3 = setrlimit(v1[-1].rlim_max, v1);
if ( v3 == -1 )
break;
++v2;
v1 = (const struct rlimit *)((char *)v1 + 24);
if ( *a1 <= v2 )
return 0;
}
fprintf(stderr, "%d\n", (unsigned int)a1[6 * v2 + 2]);
return v3;
}

original_code:
int msg_rlimit_export(msg__rlimit_t *r) {
  int i;
  int rv;
  for (i = 0; i < r->count; i++) {
    rv = setrlimit(r->rlim[i].id, &r->rlim[i].rlim);
    if (rv == -1) {
      fprintf(stderr, "%d\n", r->rlim[i].id);
      return rv;
    }
  }
  return 0;
}

canonical_original_code:
int msg_rlimit_export(struct msg__rlimit_s *r) {
  int i;
  int rv;
  for (i = 0; i < r->count; i++) {
    rv = setrlimit(r->rlim[i].id, &r->rlim[i].rlim);
    if (rv == -1) {
      fprintf(stderr, "%d\n", r->rlim[i].id);
      return rv;
    }
  }
  return 0;
}

user_defined_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
__int64 __fastcall msg_user_import(char *a1, const char *a2)
{
if ( !a2 )
return 0LL;
if ( (unsigned int)snprintf(a1, 0x20uLL, "%s", a2) > 0x1F )
_assert_fail("rv < sizeof(u->name)", "msg.c", 0x86u, "msg_user_import");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, const char *a2)
{
if ( !a2 )
return 0LL;
if ( (unsigned int)snprintf(a1, 0x20uLL, "%s", a2) > 0x1F )
_assert_fail("rv < sizeof(u->name)", "msg.c", 0x86u, "msg_user_import");
return 0LL;
}

original_code:
int msg_user_import(msg__user_t *u, const char *name) {
  int rv;
  if (name != ((void *)0)) {
    rv = snprintf(u->name, sizeof(u->name), "%s", name);
    ((void) sizeof ((rv < sizeof(u->name)) ? 1 : 0), __extension__ ({ if (rv < sizeof(u->name)) ; else __assert_fail ("rv < sizeof(u->name)", "msg.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  }
  return 0;
}

canonical_original_code:
int msg_user_import(struct msg__user_s *u, char *name) {
  int rv;
  if (name != ((void *)0)) {
    rv = snprintf(u->name, sizeof(u->name), "%s", name);
    ((void) sizeof ((rv < sizeof(u->name)) ? 1 : 0), __extension__ ({ if (rv < sizeof(u->name)) ; else __assert_fail ("rv < sizeof(u->name)", "msg.c", 134, __extension__ __PRETTY_FUNCTION__); }));
  }
  return 0;
}

variable_types:
u
struct msg__user_s { char name[32]; } *

variable_types:
name
char *


decompiled_code:
int __fastcall msg_user_export(__int64 a1, __int64 a2)
{
int result; // eax

result = setgid(*(unsigned __int16 *)(a2 + 18));
if ( result != -1 )
result = -(setuid(*(unsigned __int16 *)(a2 + 16)) == -1);
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
int result; // eax

result = setgid(*(unsigned __int16 *)(a2 + 18));
if ( result != -1 )
result = -(setuid(*(unsigned __int16 *)(a2 + 16)) == -1);
return result;
}

original_code:
int msg_user_export(msg__user_t *u, struct passwd *pw) {
  ((void) u);
  int rv;
  rv = setgid(pw->pw_gid);
  if (rv == -1) {
    return rv;
  }
  rv = setuid(pw->pw_uid);
  if (rv == -1) {
    return rv;
  }
  return 0;
}

canonical_original_code:
int msg_user_export(struct msg__user_s *u, struct passwd *pw) {
  ((void) u);
  int rv;
  rv = setgid(pw->pw_gid);
  if (rv == -1) {
    return rv;
  }
  rv = setuid(pw->pw_uid);
  if (rv == -1) {
    return rv;
  }
  return 0;
}

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned short pw_uid; unsigned short pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 __fastcall wsh__usage(__int64 a1)
{
fprintf(stderr, "Usage: %s OPTION...\n", **(const char ***)(a1 + 8));
fputc(10, stderr);
fwrite(" --socket PATH Path to socket\n", 1uLL, 0x1FuLL, stderr);
fwrite(" --user USER User to change to\n", 1uLL, 0x22uLL, stderr);
fwrite(" --rsh RSH compatibility mode\n", 1uLL, 0x27uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
fprintf(stderr, "Usage: %s OPTION...\n", **(const char ***)(a1 + 8));
fputc(10, stderr);
fwrite(" --socket PATH Path to socket\n", 1uLL, 0x1FuLL, stderr);
fwrite(" --user USER User to change to\n", 1uLL, 0x22uLL, stderr);
fwrite(" --rsh RSH compatibility mode\n", 1uLL, 0x27uLL, stderr);
return 0LL;
}

original_code:
int wsh__usage(wsh_t *w) {
  fprintf(stderr, "Usage: %s OPTION...\n", w->argv[0]);
  fprintf(stderr, "\n");
  fprintf(stderr, "  --socket PATH "
    "Path to socket"
    "\n");
  fprintf(stderr, "  --user USER   "
    "User to change to"
    "\n");
  fprintf(stderr, "  --rsh         "
    "RSH compatibility mode"
    "\n");
  return 0;
}

canonical_original_code:
int wsh__usage(struct wsh_s *w) {
  fprintf(stderr, "Usage: %s OPTION...\n", w->argv[0]);
  fprintf(stderr, "\n");
  fprintf(stderr, "  --socket PATH "
    "Path to socket"
    "\n");
  fprintf(stderr, "  --user USER   "
    "User to change to"
    "\n");
  fprintf(stderr, "  --rsh         "
    "RSH compatibility mode"
    "\n");
  return 0;
}

variable_types: struct wsh_s { int argc; char **argv; char *socket_path; char *user; } *


decompiled_code:
__int64 __fastcall wsh__getopt(__int64 a1)
{
int v1; // er14
int v2; // ebp
int v3; // ebx
__int64 result; // rax
int v5; // ebp
const char **v6; // r13
__int64 v7; // r8
const char *v8; // r12

v1 = *(_DWORD *)a1;
if ( *(int *)a1 > 1 )
{
v2 = v1 - 1;
v3 = 1;
while ( 1 )
{
v6 = *(const char ***)(a1 + 8);
v7 = v3;
if ( *v6[v7] != 45 )
goto LABEL_24;
if ( v2 <= 0 )
goto LABEL_37;
if ( !strcmp(v6[v3], "-h") || !strcmp(v6[v3], "--help") )
{
wsh__usage(a1);
return 0xFFFFFFFFLL;
}
if ( v2 > 1 )
{
if ( !strcmp(v6[v3], "--socket") )
{
*(_QWORD *)(a1 + 16) = strdup(v6[v7 + 1]);
v3 += 2;
v2 -= 2;
goto LABEL_9;
}
if ( !strcmp(v6[v3], "--user") )
{
*(_QWORD *)(a1 + 24) = strdup(v6[v7 + 1]);
v3 += 2;
v2 -= 2;
goto LABEL_9;
}
}
if ( strcmp(v6[v3], "--rsh") )
{
LABEL_37:
fprintf(stderr, "%s: invalid option -- %s\n", *v6, v6[v3]);
fprintf(stderr, "Try `%s --help' for more information.\n", **(const char ***)(a1 + 8));
return 0xFFFFFFFFLL;
}
++v3;
v5 = v2 - 1;
if ( v1 <= v3 )
goto LABEL_7;
while ( 1 )
{
v8 = v6[v3];
if ( *v8 != 45 )
break;
if ( v5 <= 0 || strlen(v6[v3]) != 2 )
{
if ( v5 <= 1 || strlen(v8) != 2 )
goto LABEL_37;
goto LABEL_28;
}
if ( !strchr("46dn", v8[1]) )
{
if ( v5 <= 1 )
goto LABEL_37;
LABEL_28:
if ( v8[1] == 108 )
{
*(_QWORD *)(a1 + 24) = strdup(v6[v3 + 1]);
v3 += 2;
v5 -= 2;
}
else
{
if ( v8[1] != 116 )
goto LABEL_37;
v3 += 2;
v5 -= 2;
}
goto LABEL_31;
}
++v3;
--v5;
LABEL_31:
if ( v1 <= v3 )
goto LABEL_7;
}
if ( v1 <= v3 )
LABEL_7:
_assert_fail("i < w->argc", "wsh.c", 0x60u, "wsh__getopt");
++v3;
v2 = v5 - 1;
LABEL_9:
if ( v1 <= v3 )
goto LABEL_24;
}
}
v3 = 1;
LABEL_24:
result = (unsigned int)(v1 - v3);
*(_DWORD *)a1 = result;
if ( v1 == v3 )
{
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) += 8LL * v3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // er14
int v2; // ebp
int v3; // ebx
__int64 result; // rax
int v5; // ebp
const char **v6; // r13
__int64 v7; // r8
const char *v8; // r12

v1 = *(_DWORD *)a1;
if ( *(int *)a1 > 1 )
{
v2 = v1 - 1;
v3 = 1;
while ( 1 )
{
v6 = *(const char ***)(a1 + 8);
v7 = v3;
if ( *v6[v7] != 45 )
goto LABEL_24;
if ( v2 <= 0 )
goto LABEL_37;
if ( !strcmp(v6[v3], "-h") || !strcmp(v6[v3], "--help") )
{
func0(a1);
return 0xFFFFFFFFLL;
}
if ( v2 > 1 )
{
if ( !strcmp(v6[v3], "--socket") )
{
*(_QWORD *)(a1 + 16) = strdup(v6[v7 + 1]);
v3 += 2;
v2 -= 2;
goto LABEL_9;
}
if ( !strcmp(v6[v3], "--user") )
{
*(_QWORD *)(a1 + 24) = strdup(v6[v7 + 1]);
v3 += 2;
v2 -= 2;
goto LABEL_9;
}
}
if ( strcmp(v6[v3], "--rsh") )
{
LABEL_37:
fprintf(stderr, "%s: invalid option -- %s\n", *v6, v6[v3]);
fprintf(stderr, "Try `%s --help' for more information.\n", **(const char ***)(a1 + 8));
return 0xFFFFFFFFLL;
}
++v3;
v5 = v2 - 1;
if ( v1 <= v3 )
goto LABEL_7;
while ( 1 )
{
v8 = v6[v3];
if ( *v8 != 45 )
break;
if ( v5 <= 0 || strlen(v6[v3]) != 2 )
{
if ( v5 <= 1 || strlen(v8) != 2 )
goto LABEL_37;
goto LABEL_28;
}
if ( !strchr("46dn", v8[1]) )
{
if ( v5 <= 1 )
goto LABEL_37;
LABEL_28:
if ( v8[1] == 108 )
{
*(_QWORD *)(a1 + 24) = strdup(v6[v3 + 1]);
v3 += 2;
v5 -= 2;
}
else
{
if ( v8[1] != 116 )
goto LABEL_37;
v3 += 2;
v5 -= 2;
}
goto LABEL_31;
}
++v3;
--v5;
LABEL_31:
if ( v1 <= v3 )
goto LABEL_7;
}
if ( v1 <= v3 )
LABEL_7:
_assert_fail("i < w->argc", "wsh.c", 0x60u, "wsh__getopt");
++v3;
v2 = v5 - 1;
LABEL_9:
if ( v1 <= v3 )
goto LABEL_24;
}
}
v3 = 1;
LABEL_24:
result = (unsigned int)(v1 - v3);
*(_DWORD *)a1 = result;
if ( v1 == v3 )
{
*(_QWORD *)(a1 + 8) = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) += 8LL * v3;
result = 0LL;
}
return result;
}

original_code:
int wsh__getopt(wsh_t *w) {
  int i = 1;
  int j = w->argc - i;
  while (i < w->argc) {
    if (w->argv[i][0] != '-') {
      break;
    }
    if (j >= 1 && ((strcmp(w->argv[i], "-h") == 0) || (strcmp(w->argv[i], "--help") == 0))) {
      wsh__usage(w);
      return -1;
    } else if (j >= 2 && strcmp(w->argv[i], "--socket") == 0) {
      w->socket_path = strdup(w->argv[i+1]);
      i += 2;
      j -= 2;
    } else if (j >= 2 && strcmp(w->argv[i], "--user") == 0) {
      w->user = strdup(w->argv[i+1]);
      i += 2;
      j -= 2;
    } else if (j >= 1 && strcmp(w->argv[i], "--rsh") == 0) {
      i += 1;
      j -= 1;
      while (i < w->argc) {
        if (w->argv[i][0] != '-') {
          break;
        }
        if (j >= 1 && strlen(w->argv[i]) == 2 && strchr("46dn", w->argv[i][1])) {
          i += 1;
          j -= 1;
        } else if (j >= 2 && strlen(w->argv[i]) == 2 && w->argv[i][1] == 'l') {
          w->user = strdup(w->argv[i+1]);
          i += 2;
          j -= 2;
        } else if (j >= 2 && strlen(w->argv[i]) == 2 && w->argv[i][1] == 't') {
          i += 2;
          j -= 2;
        } else {
          goto invalid;
        }
      }
      ((void) sizeof ((i < w->argc) ? 1 : 0), __extension__ ({ if (i < w->argc) ; else __assert_fail ("i < w->argc", "wsh.c", 96, __extension__ __PRETTY_FUNCTION__); }));
      i += 1;
      j -= 1;
    } else {
      goto invalid;
    }
  }
  w->argc = w->argc - i;
  if (w->argc) {
    w->argv = &w->argv[i];
  } else {
    w->argv = ((void *)0);
  }
  return 0;
invalid:
  fprintf(stderr, "%s: invalid option -- %s\n", w->argv[0], w->argv[i]);
  fprintf(stderr, "Try `%s --help' for more information.\n", w->argv[0]);
  return -1;
}

canonical_original_code:
int wsh__getopt(struct wsh_s *w) {
  int i = 1;
  int j = w->argc - i;
  while (i < w->argc) {
    if (w->argv[i][0] != '-') {
      break;
    }
    if (j >= 1 && ((strcmp(w->argv[i], "-h") == 0) || (strcmp(w->argv[i], "--help") == 0))) {
      wsh__usage(w);
      return -1;
    } else if (j >= 2 && strcmp(w->argv[i], "--socket") == 0) {
      w->socket_path = strdup(w->argv[i+1]);
      i += 2;
      j -= 2;
    } else if (j >= 2 && strcmp(w->argv[i], "--user") == 0) {
      w->user = strdup(w->argv[i+1]);
      i += 2;
      j -= 2;
    } else if (j >= 1 && strcmp(w->argv[i], "--rsh") == 0) {
      i += 1;
      j -= 1;
      while (i < w->argc) {
        if (w->argv[i][0] != '-') {
          break;
        }
        if (j >= 1 && strlen(w->argv[i]) == 2 && strchr("46dn", w->argv[i][1])) {
          i += 1;
          j -= 1;
        } else if (j >= 2 && strlen(w->argv[i]) == 2 && w->argv[i][1] == 'l') {
          w->user = strdup(w->argv[i+1]);
          i += 2;
          j -= 2;
        } else if (j >= 2 && strlen(w->argv[i]) == 2 && w->argv[i][1] == 't') {
          i += 2;
          j -= 2;
        } else {
          goto invalid;
        }
      }
      ((void) sizeof ((i < w->argc) ? 1 : 0), __extension__ ({ if (i < w->argc) ; else __assert_fail ("i < w->argc", "wsh.c", 96, __extension__ __PRETTY_FUNCTION__); }));
      i += 1;
      j -= 1;
    } else {
      goto invalid;
    }
  }
  w->argc = w->argc - i;
  if (w->argc) {
    w->argv = &w->argv[i];
  } else {
    w->argv = ((void *)0);
  }
  return 0;
invalid:
  fprintf(stderr, "%s: invalid option -- %s\n", w->argv[0], w->argv[i]);
  fprintf(stderr, "Try `%s --help' for more information.\n", w->argv[0]);
  return -1;
}

variable_types: i int

variable_types: j int

user_defined_types: struct wsh_s { int argc; char **argv; char *socket_path; char *user; }