decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
_DWORD *v4; // rdi
const char *v5; // rbp
size_t v6; // rax
char *v7; // rbx
size_t v8; // rax
void *v9; // rbp
char v11[32]; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 2 )
{
puts("Usage: fsmrom filename");
exit(0);
}
head = malloc(0x40uLL);
v3 = 16LL;
v4 = head;
while ( v3 )
{
*v4++ = 0;
--v3;
}
register_token_parsers(parsers, 3LL);
parse_file(argv[1], v11);
v5 = argv[1];
v6 = strlen(v5);
v7 = (char *)malloc(v6 + 5);
v8 = strlen(v5);
strncpy(v7, v5, v8 + 5);
gen_outfile(v7);
if ( !head )
{
puts("Nothing parsed!");
exit(0);
}
v9 = (void *)*((_QWORD *)head + 6);
free(head);
head = v9;
generate_binary(v9, v7);
free(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
_DWORD *v4; // rdi
const char *v5; // rbp
size_t v6; // rax
char *v7; // rbx
size_t v8; // rax
void *v9; // rbp
char v11[32]; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 2 )
{
puts("Usage: fsmrom filename");
exit(0);
}
head = malloc(0x40uLL);
v3 = 16LL;
v4 = head;
while ( v3 )
{
*v4++ = 0;
--v3;
}
register_token_parsers(parsers, 3LL);
parse_file(argv[1], v11);
v5 = argv[1];
v6 = strlen(v5);
v7 = (char *)malloc(v6 + 5);
v8 = strlen(v5);
strncpy(v7, v5, v8 + 5);
func0(v7);
if ( !head )
{
puts("Nothing parsed!");
exit(0);
}
v9 = (void *)*((_QWORD *)head + 6);
free(head);
head = v9;
generate_binary(v9, v7);
free(v7);
return 0;
}

original_code:
int main(int argc, char** argv) {
 if(argc != 2) {
  printf("Usage: fsmrom filename\n");
  exit(0);
 }
 size_t count;
 head = malloc(sizeof(macro_state));
 memset(head, 0, sizeof(macro_state));
 register_token_parsers(parsers, 3);
 parse_file(argv[1], &count);
 char *outfile = malloc(strlen(argv[1])+5);
 strncpy(outfile, argv[1],strlen(argv[1])+5);
 gen_outfile(outfile);
 if(head == ((void *)0)) {
  printf("Nothing parsed!\n");
  exit(0);
 }
 macro_state* h = head->next;
 free(head);
 head = h;
 generate_binary(head,outfile);
 free(outfile);
}

canonical_original_code:
int main(int argc, char **argv) {
 if(argc != 2) {
  printf("Usage: fsmrom filename\n");
  exit(0);
 }
 unsigned long count;
 head = malloc(sizeof(macro_state));
 memset(head, 0, sizeof(macro_state));
 register_token_parsers(parsers, 3);
 parse_file(argv[1], &count);
 char *outfile = malloc(strlen(argv[1])+5);
 strncpy(outfile, argv[1],strlen(argv[1])+5);
 gen_outfile(outfile);
 if(head == ((void *)0)) {
  printf("Nothing parsed!\n");
  exit(0);
 }
 struct macro_state_ *h = head->next;
 free(head);
 head = h;
 generate_binary(head,outfile);
 free(outfile);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
count
unsigned long

variable_types: struct macro_state_ { unsigned long opcode; unsigned long step; unsigned int signal; struct transition_token_ { enum transition_type_ { DISPATCH=0, GOTO=1, ONZ=2, ONINT=3, ELSE=4 } type; enum current_parse_ { EMPTY=0, STATE_FILLED=1, SIGNALS_FILLED=2, TRANSITION_FILLING=3, TRANSITION_FILLED=4 } first_step; unsigned long step_a; unsigned long step_b; } transition; struct macro_state_ *next; enum current_parse_ { EMPTY=0, STATE_FILLED=1, SIGNALS_FILLED=2, TRANSITION_FILLING=3, TRANSITION_FILLED=4 } parse; } *

user_defined_types: struct macro_state_ { unsigned long opcode; unsigned long step; unsigned int signal; struct transition_token_ transition; struct macro_state_ *next; enum current_parse_ parse; }

user_defined_types: struct transition_token_ { enum transition_type_ type; enum current_parse_ first_step; unsigned long step_a; unsigned long step_b; }


repo: mamidon/state-machine

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

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[7] = 0LL;
result[6] = head;
head = result;
return result;
}

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

result = malloc(0x40uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[7] = 0LL;
result[6] = head;
head = result;
return result;
}

original_code:
void push_macro_state() {
 macro_state* n = malloc(sizeof(macro_state));
 memset(n, 0, sizeof(macro_state));
 n->next = head;
 head = n;
}

canonical_original_code:
void push_macro_state() {
 struct macro_state_ *n = malloc(sizeof(macro_state));
 memset(n, 0, sizeof(macro_state));
 n->next = head;
 head = n;
}

return_type: void

user_defined_types: enum current_parse_ { EMPTY=0, STATE_FILLED=1, SIGNALS_FILLED=2, TRANSITION_FILLING=3, TRANSITION_FILLED=4 }

user_defined_types: enum transition_type_ { DISPATCH=0, GOTO=1, ONZ=2, ONINT=3, ELSE=4 }


original_code:
uint8_t parse_state (char* buffer) {
 if(head->parse != EMPTY && head->parse != TRANSITION_FILLING)
  return 1;
 size_t index = best_match(buffer, opcodes, 16);
 if(index == 16)
  return 1;
 size_t count = strlen(opcodes[index]);
 size_t stp = atoi(buffer+count);
 stp > 9 ? (count)+= 2 : (count)++;
 if(head->parse == EMPTY) {
  head->opcode = index;
  head->step = stp;
 } else if(head->parse == TRANSITION_FILLING) {
  transition_type t = head->transition.type;
  if(head->transition.first_step == EMPTY) {
   head->transition.step_a = head->transition.step_b = stp +
    (index == 15 ? 0 : 10);
   if(t == GOTO) {head->parse = TRANSITION_FILLED;}
   else {head->transition.first_step = TRANSITION_FILLING;}
  } else {
   head->transition.step_b = stp +
    (index == 15 ? 0 : 10);
   head->parse = TRANSITION_FILLED;
  }
  if(head->parse == TRANSITION_FILLED)
   push_macro_state();
  return 0;
 }
 head->parse = STATE_FILLED;
 return 0;
}

canonical_original_code:
unsigned char parse_state(char *buffer) {
 if(head->parse != EMPTY && head->parse != TRANSITION_FILLING)
  return 1;
 unsigned long index = best_match(buffer, opcodes, 16);
 if(index == 16)
  return 1;
 unsigned long count = strlen(opcodes[index]);
 unsigned long stp = atoi(buffer+count);
 stp > 9 ? (count)+= 2 : (count)++;
 if(head->parse == EMPTY) {
  head->opcode = index;
  head->step = stp;
 } else if(head->parse == TRANSITION_FILLING) {
  enum transition_type_ t = head->transition.type;
  if(head->transition.first_step == EMPTY) {
   head->transition.step_a = head->transition.step_b = stp +
    (index == 15 ? 0 : 10);
   if(t == GOTO) {head->parse = TRANSITION_FILLED;}
   else {head->transition.first_step = TRANSITION_FILLING;}
  } else {
   head->transition.step_b = stp +
    (index == 15 ? 0 : 10);
   head->parse = TRANSITION_FILLED;
  }
  if(head->parse == TRANSITION_FILLED)
   push_macro_state();
  return 0;
 }
 head->parse = STATE_FILLED;
 return 0;
}

variable_types:
buffer
char *

variable_types:
index
unsigned long

variable_types:
stp
unsigned long

variable_types: enum transition_type_ { DISPATCH=0, GOTO=1, ONZ=2, ONINT=3, ELSE=4 }

return_type: unsigned char


decompiled_code:
__int64 __fastcall parse_transition(__int64 a1)
{
__int64 v2; // rax
unsigned int v3; // edx
_DWORD *v4; // rdx

if ( (unsigned int)(*((_DWORD *)head + 14) - 2) > 1 )
return 1LL;
v2 = best_match(a1, transitions, 5LL);
v3 = 1;
if ( v2 != 5 )
{
v4 = head;
if ( !*((_DWORD *)head + 6) )
*((_DWORD *)head + 6) = v2;
if ( v2 )
{
v4[14] = 3;
}
else
{
v4[14] = 4;
*((_QWORD *)v4 + 5) = 10LL;
*((_QWORD *)v4 + 4) = 10LL;
push_macro_state();
}
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rax
unsigned int v3; // edx
_DWORD *v4; // rdx

if ( (unsigned int)(*((_DWORD *)head + 14) - 2) > 1 )
return 1LL;
v2 = best_match(a1, transitions, 5LL);
v3 = 1;
if ( v2 != 5 )
{
v4 = head;
if ( !*((_DWORD *)head + 6) )
*((_DWORD *)head + 6) = v2;
if ( v2 )
{
v4[14] = 3;
}
else
{
v4[14] = 4;
*((_QWORD *)v4 + 5) = 10LL;
*((_QWORD *)v4 + 4) = 10LL;
func2();
}
v3 = 0;
}
return v3;
}

original_code:
uint8_t parse_transition (char* buffer) {
 if(head->parse != SIGNALS_FILLED && head->parse != TRANSITION_FILLING)
  return 1;
 size_t index = best_match(buffer, transitions, 5);
 if(index == 5)
  return 1;
 if(head->transition.type == 0)
  head->transition.type = index;
 if(index == DISPATCH) {
  head->parse = TRANSITION_FILLED;
  head->transition.step_a =
   head->transition.step_b = 10;
  push_macro_state();
 } else
  head->parse = TRANSITION_FILLING;
 return 0;
}

canonical_original_code:
unsigned char parse_transition(char *buffer) {
 if(head->parse != SIGNALS_FILLED && head->parse != TRANSITION_FILLING)
  return 1;
 unsigned long index = best_match(buffer, transitions, 5);
 if(index == 5)
  return 1;
 if(head->transition.type == 0)
  head->transition.type = index;
 if(index == DISPATCH) {
  head->parse = TRANSITION_FILLED;
  head->transition.step_a =
   head->transition.step_b = 10;
  push_macro_state();
 } else
  head->parse = TRANSITION_FILLING;
 return 0;
}


decompiled_code:
void emit_binary()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: void emit_binary() {}

canonical_original_code: void emit_binary() {}


decompiled_code:
__int64 __fastcall emit_addr(int a1, char a2, char a3, char a4)
{
return a4 | (a1 << 7) | (a3 << 11) | (unsigned int)(a2 << 12);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char a2, char a3, char a4)
{
return a4 | (a1 << 7) | (a3 << 11) | (unsigned int)(a2 << 12);
}

original_code:
uint32_t emit_addr(size_t opcode, char zero, char interrupt, char step) {
 uint32_t tmp = zero<<12 | interrupt<<11 | opcode<<7
     | step<<0;
 return tmp;
}

canonical_original_code:
unsigned int emit_addr(unsigned long opcode, char zero, char interrupt, char step) {
 unsigned int tmp = zero<<12 | interrupt<<11 | opcode<<7
     | step<<0;
 return tmp;
}

variable_types:
opcode
unsigned long

variable_types: zero char

variable_types: interrupt char

variable_types: step char

variable_types:
tmp
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall burn_signals(int a1, char a2, int a3, int a4, __int64 a5, int a6)
{
int v7; // edx
__int64 v8; // rbx
int v9; // er15
int v10; // er12
__int64 result; // rax
char v12; // [rsp+0h] [rbp-38h]
char v13; // [rsp+4h] [rbp-34h]

v7 = a3 << 7;
v8 = 0LL;
v9 = v7 | a4;
v10 = a6 | v7;
do
{
while ( 1 )
{
if ( !a5 && v8 )
{
v12 = a2;
v13 = v8;
binary[(unsigned int)emit_addr(a1, 0, v8, a2)] = v10;
goto LABEL_5;
}
v12 = a2;
v13 = v8;
binary[(unsigned int)emit_addr(a1, 0, v8, a2)] = v9;
if ( a5 )
break;
LABEL_5:
if ( v8 )
break;
binary[(unsigned int)emit_addr(a1, 1, v13, v12)] = v9;
v8 = 1LL;
}
result = (unsigned int)emit_addr(a1, 1, v13, v12);
binary[(unsigned int)result] = v10;
++v8;
}
while ( v8 != 2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char a2, int a3, int a4, __int64 a5, int a6)
{
int v7; // edx
__int64 v8; // rbx
int v9; // er15
int v10; // er12
__int64 result; // rax
char v12; // [rsp+0h] [rbp-38h]
char v13; // [rsp+4h] [rbp-34h]

v7 = a3 << 7;
v8 = 0LL;
v9 = v7 | a4;
v10 = a6 | v7;
do
{
while ( 1 )
{
if ( !a5 && v8 )
{
v12 = a2;
v13 = v8;
binary[(unsigned int)func1(a1, 0, v8, a2)] = v10;
goto LABEL_5;
}
v12 = a2;
v13 = v8;
binary[(unsigned int)func1(a1, 0, v8, a2)] = v9;
if ( a5 )
break;
LABEL_5:
if ( v8 )
break;
binary[(unsigned int)func1(a1, 1, v13, v12)] = v9;
v8 = 1LL;
}
result = (unsigned int)func1(a1, 1, v13, v12);
binary[(unsigned int)result] = v10;
++v8;
}
while ( v8 != 2 );
return result;
}

original_code:
void burn_signals(size_t opcode, size_t step, signal_token signals,
         size_t reg, size_t is_onz, size_t on_branch) {
 for(size_t i = 0; i < 2; i++)
  for(size_t z = 0; z < 2; z++) {
   size_t br = is_onz && z || !is_onz && i ? on_branch : reg;
   binary[emit_addr(opcode, z, i, step)] =
    (signals << 7) | br;
 }
}

canonical_original_code:
void burn_signals(unsigned long opcode, unsigned long step, unsigned int signals, unsigned long reg, unsigned long is_onz, unsigned long on_branch) {
 for(unsigned long i = 0; i < 2; i++)
  for(unsigned long z = 0; z < 2; z++) {
   unsigned long br = is_onz && z || !is_onz && i ? on_branch : reg;
   binary[emit_addr(opcode, z, i, step)] =
    (signals << 7) | br;
 }
}

variable_types:
step
unsigned long

variable_types:
signals
unsigned int

variable_types:
reg
unsigned long

variable_types:
i
unsigned long

variable_types:
z
unsigned long

variable_types:
br
unsigned long


decompiled_code:
__int64 __fastcall generate_micro_fetch(__int64 a1)
{
__int64 v1; // r14
int v2; // er13
unsigned int v3; // ebx
__int64 v4; // r15
__int64 v5; // r12
__int64 i; // rbp
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_DWORD *)(a1 + 16);
v3 = *(_DWORD *)(a1 + 24);
v4 = *(_QWORD *)(a1 + 32);
v5 = *(_QWORD *)(a1 + 40);
for ( i = 0LL; i != 15; ++i )
{
if ( v3 == 2 )
{
result = burn_signals(i, v1, v2, v5, 1LL, v4);
}
else if ( v3 > 2 )
{
if ( v3 == 3 )
result = burn_signals(i, v1, v2, v5, 0LL, v4);
}
else
{
result = burn_signals(i, v1, v2, v5, 0LL, v5);
}
}
return result;
}

original_code:
void generate_micro_fetch(macro_state* fetch_step) {
 macro_state st = *fetch_step;
 size_t a = st.transition.step_b;
 size_t b = st.transition.step_a;
 for(size_t i = 0; i < 15; i++)
 switch(st.transition.type) {
  case(DISPATCH):
   burn_signals(i, st.step, st.signal, a, 0, a);
   break;
  case(GOTO):
   burn_signals(i, st.step, st.signal, a, 0, a);
   break;
  case(ONZ):
   burn_signals(i, st.step, st.signal, a, 1, b);
   break;
  case(ONINT):
   burn_signals(i, st.step, st.signal, a, 0, b);
   break;
 }
 return;
}

canonical_original_code:
void generate_micro_fetch(struct macro_state_ *fetch_step) {
 struct macro_state_ st = *fetch_step;
 unsigned long a = st.transition.step_b;
 unsigned long b = st.transition.step_a;
 for(unsigned long i = 0; i < 15; i++)
 switch(st.transition.type) {
  case(DISPATCH):
   burn_signals(i, st.step, st.signal, a, 0, a);
   break;
  case(GOTO):
   burn_signals(i, st.step, st.signal, a, 0, a);
   break;
  case(ONZ):
   burn_signals(i, st.step, st.signal, a, 1, b);
   break;
  case(ONINT):
   burn_signals(i, st.step, st.signal, a, 0, b);
   break;
 }
 return;
}

variable_types: struct macro_state_ { unsigned long opcode; unsigned long step; unsigned int signal; struct transition_token_ { enum transition_type_ { DISPATCH=0, GOTO=1, ONZ=2, ONINT=3, ELSE=4 } type; enum current_parse_ { EMPTY=0, STATE_FILLED=1, SIGNALS_FILLED=2, TRANSITION_FILLING=3, TRANSITION_FILLED=4 } first_step; unsigned long step_a; unsigned long step_b; } transition; struct macro_state_ *next; enum current_parse_ { EMPTY=0, STATE_FILLED=1, SIGNALS_FILLED=2, TRANSITION_FILLING=3, TRANSITION_FILLED=4 } parse; }

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
__int64 __fastcall generate_micro_inst(__int64 a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // r9
__int64 v4; // rcx
__int64 v5; // rsi

v1 = *(_DWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 24);
v3 = *(_QWORD *)(a1 + 32);
v4 = *(_QWORD *)(a1 + 40);
v5 = *(_QWORD *)(a1 + 8) + 10LL;
if ( (_DWORD)result == 2 )
return burn_signals(*(_QWORD *)a1, v5, v1, v4, 1LL, v3);
if ( (unsigned int)result > 2 )
{
if ( (_DWORD)result == 3 )
result = burn_signals(*(_QWORD *)a1, v5, v1, v4, 0LL, v3);
}
else if ( (_DWORD)result )
{
result = burn_signals(*(_QWORD *)a1, v5, v1, v4, 0LL, *(_QWORD *)(a1 + 40));
}
else
{
result = burn_signals(*(_QWORD *)a1, 10, v1, v4, 0LL, *(_QWORD *)(a1 + 40));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // r9
__int64 v4; // rcx
__int64 v5; // rsi

v1 = *(_DWORD *)(a1 + 16);
result = *(unsigned int *)(a1 + 24);
v3 = *(_QWORD *)(a1 + 32);
v4 = *(_QWORD *)(a1 + 40);
v5 = *(_QWORD *)(a1 + 8) + 10LL;
if ( (_DWORD)result == 2 )
return func2(*(_QWORD *)a1, v5, v1, v4, 1LL, v3);
if ( (unsigned int)result > 2 )
{
if ( (_DWORD)result == 3 )
result = func2(*(_QWORD *)a1, v5, v1, v4, 0LL, v3);
}
else if ( (_DWORD)result )
{
result = func2(*(_QWORD *)a1, v5, v1, v4, 0LL, *(_QWORD *)(a1 + 40));
}
else
{
result = func2(*(_QWORD *)a1, 10, v1, v4, 0LL, *(_QWORD *)(a1 + 40));
}
return result;
}

original_code:
void generate_micro_inst(macro_state* inst_step) {
 macro_state st = *inst_step;
 st.step += 10;
 size_t a = st.transition.step_b;
 size_t b = st.transition.step_a;
 switch(st.transition.type) {
  case(DISPATCH):
   burn_signals(st.opcode, 10, st.signal, a, 0, a);
   break;
  case(GOTO):
   burn_signals(st.opcode, st.step, st.signal, a, 0, a);
   break;
  case(ONZ):
   burn_signals(st.opcode, st.step, st.signal, a, 1, b);
   break;
  case(ONINT):
   burn_signals(st.opcode, st.step, st.signal, a, 0, b);
   break;
 }
 return;
}

canonical_original_code:
void generate_micro_inst(struct macro_state_ *inst_step) {
 struct macro_state_ st = *inst_step;
 st.step += 10;
 unsigned long a = st.transition.step_b;
 unsigned long b = st.transition.step_a;
 switch(st.transition.type) {
  case(DISPATCH):
   burn_signals(st.opcode, 10, st.signal, a, 0, a);
   break;
  case(GOTO):
   burn_signals(st.opcode, st.step, st.signal, a, 0, a);
   break;
  case(ONZ):
   burn_signals(st.opcode, st.step, st.signal, a, 1, b);
   break;
  case(ONINT):
   burn_signals(st.opcode, st.step, st.signal, a, 0, b);
   break;
 }
 return;
}

variable_types: struct macro_state_ { unsigned long opcode; unsigned long step; unsigned int signal; struct transition_token_ { enum transition_type_ { DISPATCH=0, GOTO=1, ONZ=2, ONINT=3, ELSE=4 } type; enum current_parse_ { EMPTY=0, STATE_FILLED=1, SIGNALS_FILLED=2, TRANSITION_FILLING=3, TRANSITION_FILLED=4 } first_step; unsigned long step_a; unsigned long step_b; } transition; struct macro_state_ *next; enum current_parse_ { EMPTY=0, STATE_FILLED=1, SIGNALS_FILLED=2, TRANSITION_FILLING=3, TRANSITION_FILLED=4 } parse; } *


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

if ( *a1 == 15LL )
result = generate_micro_fetch((__int64)a1);
else
result = generate_micro_inst((__int64)a1);
return result;
}

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

if ( *a1 == 15LL )
result = func3((__int64)a1);
else
result = func4((__int64)a1);
return result;
}

original_code:
void generate_micro_state(macro_state* state) {
 if(state->opcode == 15)
  generate_micro_fetch(state);
 else
  generate_micro_inst(state);
}

canonical_original_code:
void generate_micro_state(struct macro_state_ *state) {
 if(state->opcode == 15)
  generate_micro_fetch(state);
 else
  generate_micro_inst(state);
}


decompiled_code:
void __fastcall register_token_parsers(__int64 a1, __int64 a2)
{
parse_funcs = a1;
func_count = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
parse_funcs = a1;
func_count = a2;
}

original_code:
void register_token_parsers (parse_token* functions, size_t count) {
 parse_funcs = functions;
 func_count = count;
}

canonical_original_code:
void register_token_parsers(unsigned char (**functions)(char *buffer), unsigned long count) {
 parse_funcs = functions;
 func_count = count;
}

variable_types:
functions
unsigned char (**)(char *buffer)

variable_types:
count
unsigned long


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

v3 = a3;
if ( !a3 )
return 0LL;
v4 = a3;
v5 = 0LL;
v6 = 0LL;
do
{
v7 = *(const char **)(a2 + 8 * v5);
v8 = strlen(v7);
v9 = strncasecmp(a1, v7, v8);
if ( v8 > v6 )
{
if ( !v9 )
v4 = v5;
if ( !v9 )
v6 = v8;
}
++v5;
}
while ( v3 != v5 );
return v4;
}

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

v3 = a3;
if ( !a3 )
return 0LL;
v4 = a3;
v5 = 0LL;
v6 = 0LL;
do
{
v7 = *(const char **)(a2 + 8 * v5);
v8 = strlen(v7);
v9 = strncasecmp(a1, v7, v8);
if ( v8 > v6 )
{
if ( !v9 )
v4 = v5;
if ( !v9 )
v6 = v8;
}
++v5;
}
while ( v3 != v5 );
return v4;
}

original_code:
size_t best_match(char* buffer, const char** strs, size_t count) {
 size_t max = 0, ret = count;
 for(size_t i = 0; i < count; i++)
  if(strncasecmp(buffer, strs[i], strlen(strs[i])) == 0
    && strlen(strs[i]) > max) {
   ret = i;
   max = strlen(strs[i]);
  }
 return ret;
}

canonical_original_code:
unsigned long best_match(char *buffer, char **strs, unsigned long count) {
 unsigned long max = 0; unsigned long ret = count;
 for(unsigned long i = 0; i < count; i++)
  if(strncasecmp(buffer, strs[i], strlen(strs[i])) == 0
    && strlen(strs[i]) > max) {
   ret = i;
   max = strlen(strs[i]);
  }
 return ret;
}

variable_types:
buffer
char *

variable_types:
strs
char **

variable_types:
max
unsigned long

variable_types:
ret
unsigned long

return_type: unsigned long


main

canonical_name: main

repo: mammut/Remember-The-Milk

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

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

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

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


decompiled_code:
__int64 __fastcall comando_valido(const char *a1)
{
bool v1; // zf
__int64 result; // rax

v1 = strcmp("new", a1) == 0;
result = !v1;
if ( !v1 )
{
result = 1LL;
if ( strcmp("get", a1) )
{
result = 2LL;
if ( strcmp("delete", a1) )
{
result = 3LL;
if ( strcmp("update", a1) )
{
result = 4LL;
if ( strcmp("do", a1) )
{
result = 5LL;
if ( strcmp("list", a1) )
result = strcmp("clear", a1) == 0 ? 6 : -1;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
bool v1; // zf
__int64 result; // rax

v1 = strcmp("new", a1) == 0;
result = !v1;
if ( !v1 )
{
result = 1LL;
if ( strcmp("get", a1) )
{
result = 2LL;
if ( strcmp("delete", a1) )
{
result = 3LL;
if ( strcmp("update", a1) )
{
result = 4LL;
if ( strcmp("do", a1) )
{
result = 5LL;
if ( strcmp("list", a1) )
result = strcmp("clear", a1) == 0 ? 6 : -1;
}
}
}
}
}
return result;
}

original_code:
int comando_valido(char *value){
 if ( ! strcmp("new", value)){
  return 0;
 } else if ( ! strcmp("get", value)){
  return 1;
 } else if ( ! strcmp("delete", value)){
  return 2;
 } else if ( ! strcmp("update", value)){
  return 3;
 } else if ( ! strcmp("do", value)){
  return 4;
 } else if ( ! strcmp("list", value)){
  return 5;
 } else if ( ! strcmp("clear", value)){
  return 6;
 }
 return -1;
}

variable_types:
value
char *


decompiled_code:
__int64 __fastcall parse_action(unsigned int a1, const char **a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // ebx
__int64 result; // rax
const char *v6; // rax
const char *v7; // rdx
const char *v8; // r12
char v9; // al
int v10; // [rsp+0h] [rbp-D8h] BYREF
char s[60]; // [rsp+4h] [rbp-D4h] BYREF
char v12[120]; // [rsp+40h] [rbp-98h] BYREF
int v13; // [rsp+B8h] [rbp-20h]
__int64 v14; // [rsp+C0h] [rbp-18h]
__int64 v15; // [rsp+C8h] [rbp-10h]

v15 = v3;
v14 = v2;
v4 = a1;
result = a1;
switch ( a1 )
{
case 1u:
return fwrite("Error. Debe ingresar los argumentos\n", 1uLL, 0x24uLL, stderr);
case 2u:
v6 = a2[1];
v4 = strcmp("list", v6) != 0;
if ( !v4 )
goto LABEL_34;
if ( !strcmp("clear", v6) )
{
v4 = 1;
goto LABEL_34;
}
if ( (int)comando_valido(v6) < 0 )
goto LABEL_14;
goto LABEL_6;
case 3u:
v10 = atoi(a2[2]);
if ( !v10 )
goto LABEL_28;
if ( !strcmp("do", a2[1]) )
{
v4 = 6;
goto LABEL_34;
}
if ( !strcmp("get", a2[1]) )
goto LABEL_34;
if ( !strcmp("delete", a2[1]) )
{
v4 = 4;
goto LABEL_34;
}
if ( (int)comando_valido(a2[1]) >= 0 )
goto LABEL_6;
LABEL_14:
result = fwrite(&unk_402088, 1uLL, 0x61uLL, stderr);
break;
case 4u:
snprintf(s, 0x3CuLL, "%s", a2[2]);
snprintf(v12, 0x78uLL, "%s", a2[3]);
v10 = 0;
v13 = 0;
if ( strcmp("new", a2[1]) )
goto LABEL_14;
v4 = 2;
goto LABEL_34;
case 5u:
v7 = a2[1];
if ( strcmp("update", v7) )
goto LABEL_14;
v8 = a2[3];
if ( !strcmp("-t", v8) || !strcmp("-d", a2[3]) )
{
v10 = atoi(a2[2]);
if ( v10 )
{
v9 = v8[1];
if ( v9 == 100 )
{
v13 = 3;
snprintf(v12, 0x78uLL, "%s", a2[4]);
}
else if ( v9 == 116 )
{
v13 = 2;
snprintf(s, 0x3CuLL, "%s", a2[4]);
}
LABEL_34:
result = ((__int64 (__fastcall *)(void *))funciones_base[v4])(&v10);
}
else
{
LABEL_28:
result = fwrite(&unk_402045, 1uLL, 0x15uLL, stderr);
}
}
else if ( (unsigned int)comando_valido(v7) == 3 )
{
LABEL_24:
result = fwrite("Argumentos para el comando 'update' no reconocido.\n", 1uLL, 0x33uLL, stderr);
}
else
{
LABEL_6:
result = fwrite("Faltan argumentos.\n", 1uLL, 0x13uLL, stderr);
}
break;
case 6u:
if ( strcmp("update", a2[1]) )
goto LABEL_14;
if ( strcmp("-b", a2[3]) )
goto LABEL_24;
v10 = atoi(a2[2]);
if ( !v10 )
goto LABEL_28;
v13 = 4;
snprintf(s, 0x3CuLL, "%s", a2[4]);
snprintf(v12, 0x78uLL, "%s", a2[5]);
v4 = 5;
goto LABEL_34;
default:
return result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, const char **a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int v4; // ebx
__int64 result; // rax
const char *v6; // rax
const char *v7; // rdx
const char *v8; // r12
char v9; // al
int v10; // [rsp+0h] [rbp-D8h] BYREF
char s[60]; // [rsp+4h] [rbp-D4h] BYREF
char v12[120]; // [rsp+40h] [rbp-98h] BYREF
int v13; // [rsp+B8h] [rbp-20h]
__int64 v14; // [rsp+C0h] [rbp-18h]
__int64 v15; // [rsp+C8h] [rbp-10h]

v15 = v3;
v14 = v2;
v4 = a1;
result = a1;
switch ( a1 )
{
case 1u:
return fwrite("Error. Debe ingresar los argumentos\n", 1uLL, 0x24uLL, stderr);
case 2u:
v6 = a2[1];
v4 = strcmp("list", v6) != 0;
if ( !v4 )
goto LABEL_34;
if ( !strcmp("clear", v6) )
{
v4 = 1;
goto LABEL_34;
}
if ( (int)func7(v6) < 0 )
goto LABEL_14;
goto LABEL_6;
case 3u:
v10 = atoi(a2[2]);
if ( !v10 )
goto LABEL_28;
if ( !strcmp("do", a2[1]) )
{
v4 = 6;
goto LABEL_34;
}
if ( !strcmp("get", a2[1]) )
goto LABEL_34;
if ( !strcmp("delete", a2[1]) )
{
v4 = 4;
goto LABEL_34;
}
if ( (int)func7(a2[1]) >= 0 )
goto LABEL_6;
LABEL_14:
result = fwrite(&unk_402088, 1uLL, 0x61uLL, stderr);
break;
case 4u:
snprintf(s, 0x3CuLL, "%s", a2[2]);
snprintf(v12, 0x78uLL, "%s", a2[3]);
v10 = 0;
v13 = 0;
if ( strcmp("new", a2[1]) )
goto LABEL_14;
v4 = 2;
goto LABEL_34;
case 5u:
v7 = a2[1];
if ( strcmp("update", v7) )
goto LABEL_14;
v8 = a2[3];
if ( !strcmp("-t", v8) || !strcmp("-d", a2[3]) )
{
v10 = atoi(a2[2]);
if ( v10 )
{
v9 = v8[1];
if ( v9 == 100 )
{
v13 = 3;
snprintf(v12, 0x78uLL, "%s", a2[4]);
}
else if ( v9 == 116 )
{
v13 = 2;
snprintf(s, 0x3CuLL, "%s", a2[4]);
}
LABEL_34:
result = ((__int64 (__fastcall *)(void *))funciones_base[v4])(&v10);
}
else
{
LABEL_28:
result = fwrite(&unk_402045, 1uLL, 0x15uLL, stderr);
}
}
else if ( (unsigned int)func7(v7) == 3 )
{
LABEL_24:
result = fwrite("Argumentos para el comando 'update' no reconocido.\n", 1uLL, 0x33uLL, stderr);
}
else
{
LABEL_6:
result = fwrite("Faltan argumentos.\n", 1uLL, 0x13uLL, stderr);
}
break;
case 6u:
if ( strcmp("update", a2[1]) )
goto LABEL_14;
if ( strcmp("-b", a2[3]) )
goto LABEL_24;
v10 = atoi(a2[2]);
if ( !v10 )
goto LABEL_28;
v13 = 4;
snprintf(s, 0x3CuLL, "%s", a2[4]);
snprintf(v12, 0x78uLL, "%s", a2[5]);
v4 = 5;
goto LABEL_34;
default:
return result;
}
return result;
}

original_code:
void parse_action(int counter, char *values[]){
 evento e;
 int run = -1;
 int error = -1;
 switch(counter) {
  case 1:
   fprintf(stderr, "Error. Debe ingresar los argumentos\n");
   break;
  case 2:
   if ( ! strcmp("list", values[1]))
    run = 0;
   else if ( ! strcmp("clear", values[1]))
    run = 1;
   else if (comando_valido(values[1]) < 0)
    error = 0;
   else
    error = 2;
   break;
  case 3:
   if((e.id = atoi(values[2])) == 0)
    error = 3;
   else {
    if ( ! strcmp("do", values[1]))
     run = 6;
    else if ( ! strcmp("get", values[1]))
     run = 3;
    else if ( ! strcmp("delete", values[1]))
     run = 4;
    else if (comando_valido(values[1]) < 0)
     error = 0;
    else
     error = 2;
   }
   break;
  case 4:
   snprintf(e.titl, sizeof(char)*60, "%s", values[2]);
   snprintf(e.desc, sizeof(char)*120, "%s", values[3]);
   e.id = 0;
   e.estado = 0;
   if ( ! strcmp("new", values[1]))
    run = 2;
   else
    error = 0;
   break;
  case 5:
   if ( ! strcmp("update", values[1])){
    if ( ! strcmp("-t", values[3]) || ! strcmp("-d", values[3])) {
     if((e.id = atoi(values[2])) == 0)
      error = 3;
     else {
      switch(values[3][1]) {
       case 't':
        e.estado = 2;
        snprintf(e.titl, sizeof(char)*60, "%s", values[4]);
        break;
       case 'd':
        e.estado = 3;
        snprintf(e.desc, sizeof(char)*120, "%s", values[4]);
      }
      run = 5;
     }
    } else if(comando_valido(values[1]) == 3)
     error = 1;
    else
     error = 2;
   } else
    error = 0;
   break;
  case 6:
   if ( ! strcmp("update", values[1])){
    if ( ! strcmp("-b", values[3])) {
     if((e.id = atoi(values[2]))
      == 0)
      error = 3;
     else {
      e.estado = 4;
      snprintf(e.titl, sizeof(char)*60, "%s", values[4]);
      snprintf(e.desc, sizeof(char)*120, "%s", values[5]);
      run = 5;
     }
    } else
     error = 1;
   } else
    error = 0;
   break;
 }
 if (run >= 0) {
  funciones_base[run](&e);
 } else if (error >= 0) {
  switch(error){
   case 0:
    fprintf(stderr, "El comando seleccionado no existe.\nComandos válidos: new, get, delete, update, do, list, clear.\n");
    break;
   case 1:
    fprintf(stderr, "Argumentos para el comando 'update' no reconocido.\n");
    break;
   case 2:
    fprintf(stderr, "Faltan argumentos.\n");
    break;
   case 3:
    fprintf(stderr, "Argumento inválido.\n");
    break;
   default:
    fprintf(stderr, "Error desconocido.\n");
  }
 }
}

canonical_original_code:
void parse_action(int counter, char *values[]){
 struct _evento e;
 int run = -1;
 int error = -1;
 switch(counter) {
  case 1:
   fprintf(stderr, "Error. Debe ingresar los argumentos\n");
   break;
  case 2:
   if ( ! strcmp("list", values[1]))
    run = 0;
   else if ( ! strcmp("clear", values[1]))
    run = 1;
   else if (comando_valido(values[1]) < 0)
    error = 0;
   else
    error = 2;
   break;
  case 3:
   if((e.id = atoi(values[2])) == 0)
    error = 3;
   else {
    if ( ! strcmp("do", values[1]))
     run = 6;
    else if ( ! strcmp("get", values[1]))
     run = 3;
    else if ( ! strcmp("delete", values[1]))
     run = 4;
    else if (comando_valido(values[1]) < 0)
     error = 0;
    else
     error = 2;
   }
   break;
  case 4:
   snprintf(e.titl, sizeof(char)*60, "%s", values[2]);
   snprintf(e.desc, sizeof(char)*120, "%s", values[3]);
   e.id = 0;
   e.estado = 0;
   if ( ! strcmp("new", values[1]))
    run = 2;
   else
    error = 0;
   break;
  case 5:
   if ( ! strcmp("update", values[1])){
    if ( ! strcmp("-t", values[3]) || ! strcmp("-d", values[3])) {
     if((e.id = atoi(values[2])) == 0)
      error = 3;
     else {
      switch(values[3][1]) {
       case 't':
        e.estado = 2;
        snprintf(e.titl, sizeof(char)*60, "%s", values[4]);
        break;
       case 'd':
        e.estado = 3;
        snprintf(e.desc, sizeof(char)*120, "%s", values[4]);
      }
      run = 5;
     }
    } else if(comando_valido(values[1]) == 3)
     error = 1;
    else
     error = 2;
   } else
    error = 0;
   break;
  case 6:
   if ( ! strcmp("update", values[1])){
    if ( ! strcmp("-b", values[3])) {
     if((e.id = atoi(values[2]))
      == 0)
      error = 3;
     else {
      e.estado = 4;
      snprintf(e.titl, sizeof(char)*60, "%s", values[4]);
      snprintf(e.desc, sizeof(char)*120, "%s", values[5]);
      run = 5;
     }
    } else
     error = 1;
   } else
    error = 0;
   break;
 }
 if (run >= 0) {
  funciones_base[run](&e);
 } else if (error >= 0) {
  switch(error){
   case 0:
    fprintf(stderr, "El comando seleccionado no existe.\nComandos válidos: new, get, delete, update, do, list, clear.\n");
    break;
   case 1:
    fprintf(stderr, "Argumentos para el comando 'update' no reconocido.\n");
    break;
   case 2:
    fprintf(stderr, "Faltan argumentos.\n");
    break;
   case 3:
    fprintf(stderr, "Argumento inválido.\n");
    break;
   default:
    fprintf(stderr, "Error desconocido.\n");
  }
 }
}

variable_types: counter int

variable_types:
values
char *[]

variable_types: struct _evento { int id; char titl[60]; char desc[120]; int estado; }

variable_types: run int

variable_types: error int


recorrer

decompiled_code:
void __fastcall recorrer(const char *a1, const char *a2, unsigned int a3)
{
int v4; // er13
int v5; // eax
int v6; // er12
__int64 v7; // r12
unsigned __int64 v8; // rbx
__int64 v9; // r13
unsigned __int64 v10; // rbx
char v11[4096]; // [rsp+0h] [rbp-2048h] BYREF
char dir[4096]; // [rsp+1000h] [rbp-1048h] BYREF
struct dirent **v13; // [rsp+2000h] [rbp-48h] BYREF
struct dirent **namelist; // [rsp+2008h] [rbp-40h] BYREF

v4 = scandir(
a1,
&namelist,
(int (*)(const struct dirent *))&filter_directories,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v5 = scandir(
a1,
&v13,
(int (*)(const struct dirent *))&filter_files,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v4 < 0 )
{
perror("Couldn't open the directory");
}
else
{
v6 = v5;
imprimidor(directorios, "\n%*.s", a3, &unk_448);
imprimidor(directorios, "Directorio %s contiene: %d Carpetas y %d Archivos", a2, (unsigned int)v4, (unsigned int)v6);
if ( v6 > 0 )
{
v7 = 8LL * (unsigned int)v6;
v8 = 0LL;
do
{
imprimidor(archivos, "\n%s ubicado en %s tiene permisos de: ", v13[v8 / 8]->d_name, a2);
sprintf(v11, "%s/%s", a1, v13[v8 / 8]->d_name);
if ( !access(v11, 4) )
imprimidor(archivos, "Lectura, ");
if ( !access(v11, 2) )
imprimidor(archivos, "Escritura, ");
if ( !access(v11, 1) )
imprimidor(archivos, "Ejecucion");
free(v13[v8 / 8]);
v8 += 8LL;
}
while ( v8 != v7 );
}
if ( v4 > 0 )
{
v9 = 8LL * (unsigned int)v4;
v10 = 0LL;
do
{
imprimidor(recorrido, "\n%s", namelist[v10 / 8]->d_name);
sprintf(dir, "%s/%s", a1, namelist[v10 / 8]->d_name);
recorrer(dir, namelist[v10 / 8]->d_name, a3 + 4);
free(namelist[v10 / 8]);
v10 += 8LL;
}
while ( v10 != v9 );
}
free(namelist);
free(v13);
}
}

canonical_decompiled_code:
void __fastcall func0(const char *a1, const char *a2, unsigned int a3)
{
int v4; // er13
int v5; // eax
int v6; // er12
__int64 v7; // r12
unsigned __int64 v8; // rbx
__int64 v9; // r13
unsigned __int64 v10; // rbx
char v11[4096]; // [rsp+0h] [rbp-2048h] BYREF
char dir[4096]; // [rsp+1000h] [rbp-1048h] BYREF
struct dirent **v13; // [rsp+2000h] [rbp-48h] BYREF
struct dirent **namelist; // [rsp+2008h] [rbp-40h] BYREF

v4 = scandir(
a1,
&namelist,
(int (*)(const struct dirent *))&filter_directories,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
v5 = scandir(
a1,
&v13,
(int (*)(const struct dirent *))&filter_files,
(int (*)(const struct dirent **, const struct dirent **))&alphasort);
if ( v4 < 0 )
{
perror("Couldn't open the directory");
}
else
{
v6 = v5;
imprimidor(directorios, "\n%*.s", a3, &unk_448);
imprimidor(directorios, "Directorio %s contiene: %d Carpetas y %d Archivos", a2, (unsigned int)v4, (unsigned int)v6);
if ( v6 > 0 )
{
v7 = 8LL * (unsigned int)v6;
v8 = 0LL;
do
{
imprimidor(archivos, "\n%s ubicado en %s tiene permisos de: ", v13[v8 / 8]->d_name, a2);
sprintf(v11, "%s/%s", a1, v13[v8 / 8]->d_name);
if ( !access(v11, 4) )
imprimidor(archivos, "Lectura, ");
if ( !access(v11, 2) )
imprimidor(archivos, "Escritura, ");
if ( !access(v11, 1) )
imprimidor(archivos, "Ejecucion");
free(v13[v8 / 8]);
v8 += 8LL;
}
while ( v8 != v7 );
}
if ( v4 > 0 )
{
v9 = 8LL * (unsigned int)v4;
v10 = 0LL;
do
{
imprimidor(recorrido, "\n%s", namelist[v10 / 8]->d_name);
sprintf(dir, "%s/%s", a1, namelist[v10 / 8]->d_name);
func0(dir, namelist[v10 / 8]->d_name, a3 + 4);
free(namelist[v10 / 8]);
v10 += 8LL;
}
while ( v10 != v9 );
}
free(namelist);
free(v13);
}
}

original_code:
void recorrer(const char path[4096], const char current_directory[4096], int indent) {
  int i;
  int number_directories;
  int number_files;
  struct dirent **directory;
  struct dirent **file;
  char next_directory[4096];
  char current_file[4096];
  number_directories = scandir(path, &directory, filter_directories, alphasort);
  number_files = scandir(path, &file, filter_files, alphasort);
  if (number_directories >= 0) {
    imprimidor(directorios, "\n%*.s", indent, " ");
    imprimidor(directorios, "Directorio %s contiene: %d Carpetas y %d Archivos", current_directory, number_directories, number_files);
    for(i = 0; i < number_files; i++) {
      imprimidor(archivos, "\n%s ubicado en %s tiene permisos de: ", file[i]->d_name, current_directory);
      sprintf(current_file, "%s/%s", path, file[i]->d_name);
      if ( access(current_file, 4) == 0 ) imprimidor(archivos, "Lectura, ");
      if ( access(current_file, 2) == 0 ) imprimidor(archivos, "Escritura, ");
      if ( access(current_file, 1) == 0 ) imprimidor(archivos, "Ejecucion");
      free(file[i]);
    }
    for (i = 0; i < number_directories; i++) {
      imprimidor(recorrido, "\n%s", directory[i]->d_name);
      sprintf(next_directory, "%s/%s", path, directory[i]->d_name);
      recorrer(next_directory, directory[i]->d_name, indent + 4);
      free(directory[i]);
    }
    free(directory);
    free(file);
  }else {
    perror("Couldn't open the directory");
  }
}

canonical_original_code:
void recorrer(char path[4096], char current_directory[4096], int indent) {
  int i;
  int number_directories;
  int number_files;
  struct dirent **directory;
  struct dirent **file;
  char next_directory[4096];
  char current_file[4096];
  number_directories = scandir(path, &directory, filter_directories, alphasort);
  number_files = scandir(path, &file, filter_files, alphasort);
  if (number_directories >= 0) {
    imprimidor(directorios, "\n%*.s", indent, " ");
    imprimidor(directorios, "Directorio %s contiene: %d Carpetas y %d Archivos", current_directory, number_directories, number_files);
    for(i = 0; i < number_files; i++) {
      imprimidor(archivos, "\n%s ubicado en %s tiene permisos de: ", file[i]->d_name, current_directory);
      sprintf(current_file, "%s/%s", path, file[i]->d_name);
      if ( access(current_file, 4) == 0 ) imprimidor(archivos, "Lectura, ");
      if ( access(current_file, 2) == 0 ) imprimidor(archivos, "Escritura, ");
      if ( access(current_file, 1) == 0 ) imprimidor(archivos, "Ejecucion");
      free(file[i]);
    }
    for (i = 0; i < number_directories; i++) {
      imprimidor(recorrido, "\n%s", directory[i]->d_name);
      sprintf(next_directory, "%s/%s", path, directory[i]->d_name);
      recorrer(next_directory, directory[i]->d_name, indent + 4);
      free(directory[i]);
    }
    free(directory);
    free(file);
  }else {
    perror("Couldn't open the directory");
  }
}

variable_types:
path
char [4096]

variable_types: indent int

variable_types: i int

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } **


main

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

if ( mkdir("Informacion", 0x1FDu) == -1 && *_errno_location() != 17 )
{
perror("No se pudo crear la carpeta informacion, por favor revise que tenga permisios necesarios\n");
result = 1;
}
else
{
recorrido = fopen("Informacion/recorrido.txt", "w");
if ( recorrido )
{
directorios = fopen("Informacion/directorios.txt", "w");
if ( directorios )
{
archivos = fopen("Informacion/archivos.txt", "w");
if ( archivos )
{
v3 = getpid();
v4 = getuid();
imprimidor(recorrido, "Id_usuario: %d Id_programa: %d", v4, v3);
v5 = getpid();
v6 = getuid();
imprimidor(directorios, "Id_usuario: %d Id_programa: %d", v6, v5);
v7 = getpid();
v8 = getuid();
imprimidor(archivos, "Id_usuario: %d Id_programa: %d", v8, v7);
if ( argc == 1 )
{
recorrer(".", ".", 0);
}
else
{
if ( argc != 2 )
{
perror("Argumentos invalidos\n");
return 1;
}
recorrer(argv[1], argv[1], 0);
}
fclose(recorrido);
fclose(directorios);
fclose(archivos);
result = 0;
}
else
{
perror("No se pudo abrir el archivo Informacion/archivos.txt");
result = 1;
}
}
else
{
perror("No se pudo abrir el archivo Informacion/directorios.txt");
result = 1;
}
}
else
{
perror("No se pudo abrir el archivo Informacion/recorrido.txt");
result = 1;
}
}
return result;
}

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

if ( mkdir("Informacion", 0x1FDu) == -1 && *_errno_location() != 17 )
{
perror("No se pudo crear la carpeta informacion, por favor revise que tenga permisios necesarios\n");
result = 1;
}
else
{
recorrido = fopen("Informacion/recorrido.txt", "w");
if ( recorrido )
{
directorios = fopen("Informacion/directorios.txt", "w");
if ( directorios )
{
archivos = fopen("Informacion/archivos.txt", "w");
if ( archivos )
{
v3 = getpid();
v4 = getuid();
imprimidor(recorrido, "Id_usuario: %d Id_programa: %d", v4, v3);
v5 = getpid();
v6 = getuid();
imprimidor(directorios, "Id_usuario: %d Id_programa: %d", v6, v5);
v7 = getpid();
v8 = getuid();
imprimidor(archivos, "Id_usuario: %d Id_programa: %d", v8, v7);
if ( argc == 1 )
{
func0(".", ".", 0);
}
else
{
if ( argc != 2 )
{
perror("Argumentos invalidos\n");
return 1;
}
func0(argv[1], argv[1], 0);
}
fclose(recorrido);
fclose(directorios);
fclose(archivos);
result = 0;
}
else
{
perror("No se pudo abrir el archivo Informacion/archivos.txt");
result = 1;
}
}
else
{
perror("No se pudo abrir el archivo Informacion/directorios.txt");
result = 1;
}
}
else
{
perror("No se pudo abrir el archivo Informacion/recorrido.txt");
result = 1;
}
}
return result;
}

original_code:
int main (int argc, char *argv[])
{
  if ( mkdir("Informacion", (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) == -1) {
    if ((*__errno_location ()) != 17) {
      perror("No se pudo crear la carpeta informacion, por favor revise que tenga permisios necesarios\n");
      return 1;
    }
  }
  if ( ! (recorrido = fopen("Informacion/recorrido.txt", "w")) ) {
    perror("No se pudo abrir el archivo Informacion/recorrido.txt");
    return 1;
  }
  if ( ! (directorios = fopen("Informacion/directorios.txt", "w")) ) {
    perror("No se pudo abrir el archivo Informacion/directorios.txt");
    return 1;
  }
  if ( ! (archivos = fopen("Informacion/archivos.txt", "w")) ) {
    perror("No se pudo abrir el archivo Informacion/archivos.txt");
    return 1;
  }
  imprimidor(recorrido, "Id_usuario: %d Id_programa: %d", getuid(), getpid());
  imprimidor(directorios, "Id_usuario: %d Id_programa: %d", getuid(), getpid());
  imprimidor(archivos, "Id_usuario: %d Id_programa: %d", getuid(), getpid());
  switch (argc) {
    case 1: recorrer(".", ".", 0); break;
    case 2: recorrer(argv[1], argv[1], 0); break;
    default: perror("Argumentos invalidos\n"); return 1;
  }
  fclose(recorrido);
  fclose(directorios);
  fclose(archivos);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if ( mkdir("Informacion", (0400|0200|0100) | ((0400|0200|0100) >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3)) == -1) {
    if ((*__errno_location ()) != 17) {
      perror("No se pudo crear la carpeta informacion, por favor revise que tenga permisios necesarios\n");
      return 1;
    }
  }
  if ( ! (recorrido = fopen("Informacion/recorrido.txt", "w")) ) {
    perror("No se pudo abrir el archivo Informacion/recorrido.txt");
    return 1;
  }
  if ( ! (directorios = fopen("Informacion/directorios.txt", "w")) ) {
    perror("No se pudo abrir el archivo Informacion/directorios.txt");
    return 1;
  }
  if ( ! (archivos = fopen("Informacion/archivos.txt", "w")) ) {
    perror("No se pudo abrir el archivo Informacion/archivos.txt");
    return 1;
  }
  imprimidor(recorrido, "Id_usuario: %d Id_programa: %d", getuid(), getpid());
  imprimidor(directorios, "Id_usuario: %d Id_programa: %d", getuid(), getpid());
  imprimidor(archivos, "Id_usuario: %d Id_programa: %d", getuid(), getpid());
  switch (argc) {
    case 1: recorrer(".", ".", 0); break;
    case 2: recorrer(argv[1], argv[1], 0); break;
    default: perror("Argumentos invalidos\n"); return 1;
  }
  fclose(recorrido);
  fclose(directorios);
  fclose(archivos);
  return 0;
}


original_code:
int filter_directories(const struct dirent *dir) {
  int is_hidden = (dir->d_name[0] == '.') || (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0);
  if (is_hidden && dir->d_type == DT_DIR)
    return 0;
  if (dir->d_type == DT_DIR)
    return 1;
  return 0;
}

canonical_original_code:
int filter_directories(struct dirent *dir) {
  int is_hidden = (dir->d_name[0] == '.') || (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0);
  if (is_hidden && dir->d_type == DT_DIR)
    return 0;
  if (dir->d_type == DT_DIR)
    return 1;
  return 0;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *


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

if ( *(_BYTE *)(a1 + 19) != 46 || (result = 0LL, *(_BYTE *)(a1 + 18) == 4) )
result = *(_BYTE *)(a1 + 18) != 4;
return result;
}

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

if ( *(_BYTE *)(a1 + 19) != 46 || (result = 0LL, *(_BYTE *)(a1 + 18) == 4) )
result = *(_BYTE *)(a1 + 18) != 4;
return result;
}

original_code:
int filter_files(const struct dirent *dir) {
  if (dir->d_name[0] == '.' && dir->d_type != DT_DIR)
    return 0;
  if (dir->d_type != DT_DIR)
    return 1;
  return 0;
}

canonical_original_code:
int filter_files(struct dirent *dir) {
  if (dir->d_name[0] == '.' && dir->d_type != DT_DIR)
    return 0;
  if (dir->d_type != DT_DIR)
    return 1;
  return 0;
}

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }


simulation

repo: mangrish/university-projects

decompiled_code:
__int64 __fastcall simulation(void (__fastcall *a1)(_QWORD, int *, unsigned int *), void (__fastcall *a2)(_QWORD, _QWORD, _QWORD))
{
_QWORD *v2; // rbx
unsigned int v3; // ebp
unsigned int v5; // er14
_DWORD *v6; // rax
int v7; // eax
__int64 v8; // rdx
__int64 v9; // rdx
unsigned int v10; // [rsp+8h] [rbp-30h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = event_q;
if ( event_q )
{
while ( 1 )
{
event_q = (void *)v2[3];
v3 = *(_DWORD *)v2;
if ( *((_DWORD *)v2 + 1) == 1 )
{
a1(v3, v11, &v10);
v5 = v10;
if ( v10 != -1 )
{
v6 = malloc(0x20uLL);
if ( !v6 )
{
fwrite("Ran out of memory.\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v6[2] = v5;
v6[1] = 1;
*v6 = v11[0] + v3;
event_insert(v6);
}
v7 = _isoc99_fscanf(*(_QWORD *)(fp + 8LL * *((int *)v2 + 2)), "%d %d %d", v2, (char *)v2 + 12, v2 + 2);
if ( v7 != -1 )
{
if ( v7 != 3 )
{
fprintf(stderr, "Malformed input: process %d\n", *((unsigned int *)v2 + 2));
exit(1);
}
v8 = *((unsigned int *)v2 + 4);
if ( (unsigned int)v8 > 1 )
{
fprintf(stderr, "Invalid request type %d)\n", v8);
exit(1);
}
*(_DWORD *)v2 += v3;
*((_DWORD *)v2 + 1) = 0;
event_insert(v2);
goto LABEL_11;
}
}
else
{
a2(*((unsigned int *)v2 + 2), *((unsigned int *)v2 + 3), *((unsigned int *)v2 + 4));
if ( (unsigned int)disk_idle() )
{
a1(v3, v11, &v10);
v9 = *((unsigned int *)v2 + 2);
if ( (_DWORD)v9 != v10 )
{
fprintf(stderr, "Expected process %d, got %d\n", v9, v10);
exit(1);
}
*((_DWORD *)v2 + 1) = 1;
*(_DWORD *)v2 = v11[0] + v3;
event_insert(v2);
goto LABEL_11;
}
}
free(v2);
LABEL_11:
v2 = event_q;
if ( !event_q )
return v3;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(void (__fastcall *a1)(_QWORD, int *, unsigned int *), void (__fastcall *a2)(_QWORD, _QWORD, _QWORD))
{
_QWORD *v2; // rbx
unsigned int v3; // ebp
unsigned int v5; // er14
_DWORD *v6; // rax
int v7; // eax
__int64 v8; // rdx
__int64 v9; // rdx
unsigned int v10; // [rsp+8h] [rbp-30h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = event_q;
if ( event_q )
{
while ( 1 )
{
event_q = (void *)v2[3];
v3 = *(_DWORD *)v2;
if ( *((_DWORD *)v2 + 1) == 1 )
{
a1(v3, v11, &v10);
v5 = v10;
if ( v10 != -1 )
{
v6 = malloc(0x20uLL);
if ( !v6 )
{
fwrite("Ran out of memory.\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v6[2] = v5;
v6[1] = 1;
*v6 = v11[0] + v3;
event_insert(v6);
}
v7 = _isoc99_fscanf(*(_QWORD *)(fp + 8LL * *((int *)v2 + 2)), "%d %d %d", v2, (char *)v2 + 12, v2 + 2);
if ( v7 != -1 )
{
if ( v7 != 3 )
{
fprintf(stderr, "Malformed input: process %d\n", *((unsigned int *)v2 + 2));
exit(1);
}
v8 = *((unsigned int *)v2 + 4);
if ( (unsigned int)v8 > 1 )
{
fprintf(stderr, "Invalid request type %d)\n", v8);
exit(1);
}
*(_DWORD *)v2 += v3;
*((_DWORD *)v2 + 1) = 0;
event_insert(v2);
goto LABEL_11;
}
}
else
{
a2(*((unsigned int *)v2 + 2), *((unsigned int *)v2 + 3), *((unsigned int *)v2 + 4));
if ( (unsigned int)disk_idle() )
{
a1(v3, v11, &v10);
v9 = *((unsigned int *)v2 + 2);
if ( (_DWORD)v9 != v10 )
{
fprintf(stderr, "Expected process %d, got %d\n", v9, v10);
exit(1);
}
*((_DWORD *)v2 + 1) = 1;
*(_DWORD *)v2 = v11[0] + v3;
event_insert(v2);
goto LABEL_11;
}
}
free(v2);
LABEL_11:
v2 = event_q;
if ( !event_q )
return v3;
}
}
return 0;
}

original_code:
int
simulation( void (*schedule)(int, int *, int *),
            void (*request)(int, int, ReadOrWrite))
{
 int time_now = 0;
 event *this, *new;
 int finish, got;
 while(event_q != ((void *)0)) {
  this = event_q;
  event_q = event_q->next;
  time_now = this->time;
  if(this->type == 1) {
   int current_proc;
   schedule(time_now, &finish, &current_proc);
   if(current_proc != -1) {
    new = (event *) malloc(sizeof(event));
    if(new == ((void *)0)) {
     fprintf(stderr, "Ran out of memory.\n");
     exit(1);
    }
    new->proc = current_proc;
    new->type = 1;
    new->time = time_now+finish;
    event_insert(new);
   }
   got = fscanf(fp[this->proc], "%d %d %d", &(this->time),
    &(this->track), (int *) &(this->rw));
   if(got == (-1)) {
    free(this);
   }
   else if(got != 3) {
    fprintf(stderr, "Malformed input: process %d\n",
     this->proc);
    exit(1);
   }
   else {
    if (this->rw < 0 || this->rw > 1) {
     fprintf(stderr, "Invalid request type %d)\n",this->rw);
     exit( 1);
    }
    this->time += time_now;
    this->type = 0;
    event_insert(this);
   }
  }
  else {
   request(this->proc, this->track, this->rw);
   if(disk_idle()) {
    int working_for;
    schedule(time_now, &finish, &working_for);
    if (working_for != this->proc) {
     fprintf(stderr,
         "Expected process %d, got %d\n",
         this->proc, working_for);
     exit(1);
    };
    this->type = 1;
    this->time = time_now+finish;
    event_insert(this);
   }
   else
    free(this);
  }
 }
 return time_now;
}

canonical_original_code:
int simulation(void (*schedule)(int, int *, int *), void (*request)(int, int, enum ReadOrWrite))
{
 int time_now = 0;
 struct event_rec *this; struct event_rec *new;
 int finish; int got;
 while(event_q != ((void *)0)) {
  this = event_q;
  event_q = event_q->next;
  time_now = this->time;
  if(this->type == 1) {
   int current_proc;
   schedule(time_now, &finish, &current_proc);
   if(current_proc != -1) {
    new = (struct event_rec *) malloc(sizeof(event));
    if(new == ((void *)0)) {
     fprintf(stderr, "Ran out of memory.\n");
     exit(1);
    }
    new->proc = current_proc;
    new->type = 1;
    new->time = time_now+finish;
    event_insert(new);
   }
   got = fscanf(fp[this->proc], "%d %d %d", &(this->time),
    &(this->track), (int *) &(this->rw));
   if(got == (-1)) {
    free(this);
   }
   else if(got != 3) {
    fprintf(stderr, "Malformed input: process %d\n",
     this->proc);
    exit(1);
   }
   else {
    if (this->rw < 0 || this->rw > 1) {
     fprintf(stderr, "Invalid request type %d)\n",this->rw);
     exit( 1);
    }
    this->time += time_now;
    this->type = 0;
    event_insert(this);
   }
  }
  else {
   request(this->proc, this->track, this->rw);
   if(disk_idle()) {
    int working_for;
    schedule(time_now, &finish, &working_for);
    if (working_for != this->proc) {
     fprintf(stderr,
         "Expected process %d, got %d\n",
         this->proc, working_for);
     exit(1);
    };
    this->type = 1;
    this->time = time_now+finish;
    event_insert(this);
   }
   else
    free(this);
  }
 }
 return time_now;
}

variable_types:
schedule
void (*)(int, int *, int *)

variable_types: void (*)(int, int, enum ReadOrWrite { Read=0, Write=1 })

variable_types: struct event_rec { int time; int type; int proc; int track; enum ReadOrWrite { Read=0, Write=1 } rw; struct event_rec *next; } *

variable_types: finish int

variable_types: got int

user_defined_types: struct event_rec { int time; int type; int proc; int track; enum ReadOrWrite rw; struct event_rec *next; }


makeConveyorBelt

decompiled_code:
__int64 __fastcall makeConveyorBelt(char *a1)
{
return readFile(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
return readFile(a1);
}

original_code:
ConveyorBelt* makeConveyorBelt(char *filename) {
  return readFile(filename, 100, 1024);
}

canonical_original_code:
int *makeConveyorBelt(char *filename) {
  return readFile(filename, 100, 1024);
}

variable_types:
filename
char *

return_type: int *


getItem

decompiled_code:
__int64 __fastcall getItem(__int64 a1, int a2)
{
return *(unsigned int *)(a1 + 4LL * a2 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
return *(unsigned int *)(a1 + 4LL * a2 + 4);
}

original_code:
int getItem(ConveyorBelt *cv,int index) {
  return (int)(cv[index+1]);
}

canonical_original_code:
int getItem(int *cv, int index) {
  return (int)(cv[index+1]);
}

variable_types:
cv
int *

variable_types: index int


setItem

decompiled_code:
void __fastcall setItem(__int64 a1, int a2, int a3)
{
*(_DWORD *)(a1 + 4LL * a2 + 4) = a3;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, int a3)
{
*(_DWORD *)(a1 + 4LL * a2 + 4) = a3;
}

original_code:
void setItem(ConveyorBelt *cv,int index, int value) {
  cv[index+1] = value;
  return;
}

canonical_original_code:
void setItem(int *cv, int index, int value) {
  cv[index+1] = value;
  return;
}

variable_types: value int


getSize

decompiled_code:
__int64 __fastcall getSize(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
return *a1;
}

original_code:
int getSize(ConveyorBelt *cv) {
  return (int)(cv[0]);
}

canonical_original_code:
int getSize(int *cv) {
  return (int)(cv[0]);
}


min

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

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

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

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

original_code:
int min( int a, int b){
 return (a < b ? a: b);
}

canonical_original_code:
int min(int a, int b){
 return (a < b ? a: b);
}

variable_types: a int

variable_types: b int


ReflexAgentWithState

decompiled_code:
__int64 __fastcall ReflexAgentWithState(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v5; // r12
const char *v8; // rdx
unsigned int v9; // eax

v5 = a3;
v8 = "Yes";
if ( !pickedUpState )
v8 = "No";
printf(
"Agent State : Min. of Items Filled -> %d, Is an Item Picked -> %s, Power Remaining -> %d, Previous Action: %s\n"
"Percepts : A(Current) -> %d, A(Next) -> %d, B(Current) -> %d, B(Next) -> %d\n",
(unsigned int)minOfItemFilled,
v8,
a5,
&ACTIONS[20 * previousAction],
a1,
a2,
v5,
a4);
v9 = interpretInput(a1, a2, v5, a4, a5);
return ruleMatch(v9);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v5; // r12
const char *v8; // rdx
unsigned int v9; // eax

v5 = a3;
v8 = "Yes";
if ( !pickedUpState )
v8 = "No";
printf(
"Agent State : Min. of Items Filled -> %d, Is an Item Picked -> %s, Power Remaining -> %d, Previous Action: %s\n"
"Percepts : A(Current) -> %d, A(Next) -> %d, B(Current) -> %d, B(Next) -> %d\n",
(unsigned int)minOfItemFilled,
v8,
a5,
&ACTIONS[20 * previousAction],
a1,
a2,
v5,
a4);
v9 = func12(a1, a2, v5, a4, a5);
return func13(v9);
}

original_code:
int ReflexAgentWithState(int belta_current, int belta_next, int beltb_current, int beltb_next, int power){
 int rule, action;
 printf("Agent State : Min. of Items Filled -> %d, Is an Item Picked -> %s, Power Remaining -> %d, Previous Action: %s\nPercepts : A(Current) -> %d, A(Next) -> %d, B(Current) -> %d, B(Next) -> %d\n", minOfItemFilled,( pickedUpState ? "Yes" : "No"), power, ACTIONS[previousAction], belta_current, belta_next, beltb_current, beltb_next);
 rule = interpretInput (belta_current, belta_next, beltb_current, beltb_next, power);;
 action = ruleMatch(rule);
 return action;
}

canonical_original_code:
int ReflexAgentWithState(int belta_current, int belta_next, int beltb_current, int beltb_next, int power){
 int rule; int action;
 printf("Agent State : Min. of Items Filled -> %d, Is an Item Picked -> %s, Power Remaining -> %d, Previous Action: %s\nPercepts : A(Current) -> %d, A(Next) -> %d, B(Current) -> %d, B(Next) -> %d\n", minOfItemFilled,( pickedUpState ? "Yes" : "No"), power, ACTIONS[previousAction], belta_current, belta_next, beltb_current, beltb_next);
 rule = interpretInput (belta_current, belta_next, beltb_current, beltb_next, power);;
 action = ruleMatch(rule);
 return action;
}

variable_types: power int

variable_types: rule int

variable_types: action int


getSize

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


ReflexAgent

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

v2 = interpretInput(a1, a2);
return ruleMatch(v2);
}

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

v2 = func10(a1, a2);
return func11(v2);
}

original_code:
int ReflexAgent(int percept1, int percept2){
 int rule, action;
 rule = interpretInput (percept1, percept2);
 action = ruleMatch(rule);
 return action;
}

canonical_original_code:
int ReflexAgent(int percept1, int percept2){
 int rule; int action;
 rule = interpretInput (percept1, percept2);
 action = ruleMatch(rule);
 return action;
}


gettotalrunningjobs

repo: tasimon/DynamicScheduler

decompiled_code:
__int64 __fastcall gettotalrunningjobs(int a1, __int64 a2)
{
_DWORD *v2; // rax
unsigned int v3; // edx

if ( a1 <= 0 )
return 0;
v2 = (_DWORD *)(a2 + 56);
v3 = 0;
do
{
v3 += *v2;
v2 += 18;
}
while ( v2 != (_DWORD *)(a2 + 72LL * (unsigned int)(a1 - 1) + 128) );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
_DWORD *v2; // rax
unsigned int v3; // edx

if ( a1 <= 0 )
return 0;
v2 = (_DWORD *)(a2 + 56);
v3 = 0;
do
{
v3 += *v2;
v2 += 18;
}
while ( v2 != (_DWORD *)(a2 + 72LL * (unsigned int)(a1 - 1) + 128) );
return v3;
}

original_code:
int gettotalrunningjobs(int jobs, Job *jobqueue){
int total=0;
int i;
for(i=0;i<jobs;i++)
 {
 total+=jobqueue[i].running;
 }
return total;
}

canonical_original_code:
int gettotalrunningjobs(int jobs, struct Job *jobqueue){
int total = 0;
int i;
for(i=0;i<jobs;i++)
 {
 total+=jobqueue[i].running;
 }
return total;
}

variable_types: jobs int

variable_types: struct Job { int jobid; int cores; double arrtime; double waittime; double runtime; double origruntime; double queuepr; double priority; int running; int complete; int backfill; } *

variable_types: total int

variable_types: i int


totalwaittime

decompiled_code:
__int64 __fastcall totalwaittime(int a1, __int64 a2)
{
double *v2; // rax
int v3; // edx

if ( a1 <= 0 )
{
v3 = 0;
}
else
{
v2 = (double *)(a2 + 16);
v3 = 0;
do
{
v3 = (int)((double)v3 + *v2);
v2 += 9;
}
while ( v2 != (double *)(a2 + 72LL * (unsigned int)(a1 - 1) + 88) );
}
return (unsigned int)v3;
}

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

if ( a1 <= 0 )
{
v3 = 0;
}
else
{
v2 = (double *)(a2 + 16);
v3 = 0;
do
{
v3 = (int)((double)v3 + *v2);
v2 += 9;
}
while ( v2 != (double *)(a2 + 72LL * (unsigned int)(a1 - 1) + 88) );
}
return (unsigned int)v3;
}

original_code:
int totalwaittime(int jobs, Job *jobqueue){
int totalwt=0;
int i;
for(i=0;i<jobs;i++)
 {
 totalwt+=jobqueue[i].waittime;
 }
return totalwt;
}

canonical_original_code:
int totalwaittime(int jobs, struct Job *jobqueue){
int totalwt = 0;
int i;
for(i=0;i<jobs;i++)
 {
 totalwt+=jobqueue[i].waittime;
 }
return totalwt;
}

variable_types: totalwt int

user_defined_types: struct Job { int jobid; int cores; double arrtime; double waittime; double runtime; double origruntime; double queuepr; double priority; int running; int complete; int backfill; }


backfill

decompiled_code:
void __fastcall backfill(__int64 a1, int a2)
{
int i; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
;
}
}

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

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
;
}
}

original_code:
void backfill(Job * jobqueue, int jobcount, int coresneeded){
double time, cores, offset;
int i;
for (i=0; i<jobcount; i++)
 {
 if (jobqueue[i].running == 1 && jobqueue[i].complete == 0)
 cores+= jobqueue[i].cores;
 time += jobqueue[i].runtime;
 }
}

canonical_original_code:
void backfill(struct Job *jobqueue, int jobcount, int coresneeded){
double time; double cores; double offset;
int i;
for (i=0; i<jobcount; i++)
 {
 if (jobqueue[i].running == 1 && jobqueue[i].complete == 0)
 cores+= jobqueue[i].cores;
 time += jobqueue[i].runtime;
 }
}

variable_types: jobcount int

variable_types: coresneeded int

variable_types: time double

variable_types: cores double

variable_types: offset double


factorial

decompiled_code:
void __fastcall factorial(int a1)
{
if ( a1 )
factorial((unsigned int)(a1 - 1), 1.0);
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
if ( a1 )
func8((unsigned int)(a1 - 1), 1.0);
}

original_code:
double factorial(int n)
{
   if(n==0)
      return(1);
   else
      return(n*factorial(n-1));
}

variable_types: n int

return_type: double


canonical_decompiled_code:
void __fastcall func9(int a1)
{
if ( a1 )
func9((unsigned int)(a1 - 1), 1.0);
}

canonical_original_code:
double factorial(int n)
{
   if(n==0)
      return(1);
   else
      return(n*factorial(n-1));
}


repo: tasimon/PPS

decompiled_code:
__int64 check_X_display()
{
char *v0; // rdx
__int64 result; // rax

v0 = getenv("DISPLAY");
result = 0LL;
if ( !v0 )
{
fwrite("cannot find DISPLAY variable: is it set?\n", 1uLL, 0x29uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
char *v0; // rdx
__int64 result; // rax

v0 = getenv("DISPLAY");
result = 0LL;
if ( !v0 )
{
fwrite("cannot find DISPLAY variable: is it set?\n", 1uLL, 0x29uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int check_X_display(void)
{
    char * display ;
    display = getenv("DISPLAY") ;
    if (display == ((void *)0)) {
        fprintf(stderr, "cannot find DISPLAY variable: is it set?\n") ;
        return 1 ;
    } else {
        return 0 ;
    }
}

canonical_original_code:
int check_X_display()
{
    char *display;
    display = getenv("DISPLAY") ;
    if (display == ((void *)0)) {
        fprintf(stderr, "cannot find DISPLAY variable: is it set?\n") ;
        return 1 ;
    } else {
        return 0 ;
    }
}

variable_types:
display
char *


Input

repo: tatsui/backprop

decompiled_code:
__int64 Input()
{
__int64 result; // rax
__int64 v1; // xmm0_8

nt[0] = (double)(rand() % 2);
result = (unsigned int)(rand() % 2);
nt[1] = (double)(int)result;
if ( (double)(int)result == nt[0] )
v1 = 0LL;
else
v1 = LC2;
*(_QWORD *)&nt[8] = v1;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // xmm0_8

nt[0] = (double)(rand() % 2);
result = (unsigned int)(rand() % 2);
nt[1] = (double)(int)result;
if ( (double)(int)result == nt[0] )
v1 = 0LL;
else
v1 = LC2;
*(_QWORD *)&nt[8] = v1;
return result;
}

variable_types: k int


sigmoid

decompiled_code:
double __fastcall sigmoid(double a1)
{
return 1.0 / (exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC4)) + 1.0);
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
return 1.0 / (exp(COERCE_DOUBLE(*(_QWORD *)&a1 ^ LC4)) + 1.0);
}

original_code:
double sigmoid(double x){
 return (1.0/(1.0+exp(-1.0*x)));
}

variable_types: x double


Forward

canonical_original_code:
void Forward(){
 int i; int j; int k;
 double Tj[3]; double Uk[1];
 for (j = 0; j < 3 ; j++) {
  for (Tj[j] = 0, i = 0; i < 2 +1; i++) {
   Tj[j] += nt.X[i]*nt.Wji[j][i];
  }
  nt.H[j] = sigmoid(Tj[j]);
 }
 for (k = 0; k < 1; k++) {
  for (Uk[k] = 0, j = 0; j < 3 +1; j++) {
   Uk[k] += nt.H[j]*nt.Wkj[k][j];
  }
  nt.O[k] = sigmoid(Uk[k]);
 }
}

variable_types: j int

variable_types:
Tj
double [3]

variable_types:
Uk
double [1]


BackProp

variable_types:
dWji
double [3][-1]

variable_types:
dWkj
double [1][-1]

variable_types: sum double


CheckError

decompiled_code:
double CheckError()
{
double v1; // [rsp+8h] [rbp-10h]
double v2; // [rsp+8h] [rbp-10h]
double v3; // [rsp+8h] [rbp-10h]

nt[0] = 0.0;
nt[1] = 0.0;
Forward();
v1 = COERCE_DOUBLE(*(_QWORD *)&nt[7] & LC7) + 0.0;
nt[0] = 0.0;
*(_QWORD *)&nt[1] = LC2;
Forward();
v2 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(nt[7] - 1.0) & LC7) + v1;
*(_QWORD *)&nt[0] = LC2;
nt[1] = 0.0;
Forward();
v3 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(nt[7] - 1.0) & LC7) + v2;
*(_QWORD *)&nt[0] = LC2;
*(_QWORD *)&nt[1] = LC2;
Forward();
return COERCE_DOUBLE(*(_QWORD *)&nt[7] & LC7) + v3;
}

canonical_decompiled_code:
double func5()
{
double v1; // [rsp+8h] [rbp-10h]
double v2; // [rsp+8h] [rbp-10h]
double v3; // [rsp+8h] [rbp-10h]

nt[0] = 0.0;
nt[1] = 0.0;
func3();
v1 = COERCE_DOUBLE(*(_QWORD *)&nt[7] & LC7) + 0.0;
nt[0] = 0.0;
*(_QWORD *)&nt[1] = LC2;
func3();
v2 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(nt[7] - 1.0) & LC7) + v1;
*(_QWORD *)&nt[0] = LC2;
nt[1] = 0.0;
func3();
v3 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(nt[7] - 1.0) & LC7) + v2;
*(_QWORD *)&nt[0] = LC2;
*(_QWORD *)&nt[1] = LC2;
func3();
return COERCE_DOUBLE(*(_QWORD *)&nt[7] & LC7) + v3;
}

variable_types: err double


main

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
i
unsigned int


Translation

repo: tatsui/brainf-ck

decompiled_code:
void __fastcall Translation(char a1)
{
int v1; // ebx

switch ( a1 )
{
case '+':
++value[addr];
break;
case ',':
v1 = addr;
value[v1] = getchar();
break;
case '-':
--value[addr];
break;
case '.':
if ( debug == 1 )
printf("%d, ASCII:(%s)\n", (unsigned int)value[addr], (const char *)&value[addr]);
else
printf("%s", (const char *)&value[addr]);
break;
case '<':
--addr;
break;
case '>':
++addr;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func7(char a1)
{
int v1; // ebx

switch ( a1 )
{
case '+':
++value[addr];
break;
case ',':
v1 = addr;
value[v1] = getchar();
break;
case '-':
--value[addr];
break;
case '.':
if ( debug == 1 )
printf("%d, ASCII:(%s)\n", (unsigned int)value[addr], (const char *)&value[addr]);
else
printf("%s", (const char *)&value[addr]);
break;
case '<':
--addr;
break;
case '>':
++addr;
break;
default:
return;
}
}

original_code:
void Translation(char ope)
{
 switch (ope) {
  case '>':
   addr++;
   break;
  case '<':
   addr--;
   break;
  case '+':
   value[addr]++;
   break;
  case '-':
   value[addr]--;
   break;
  case '.':
   if(debug == 1)printf("%d, ASCII:(%s)\n", value[addr], &value[addr]);
   else printf("%s", &value[addr]);
   break;
  case ',':
   value[addr] = getchar();
   break;
  default:
   break;
 }
}

variable_types: ope char


search

original_code:
int search(char *code, int offset, int codelen){
 int n, block = 1;
 for(n = offset+1; n < codelen ; n++){
  if(code[n] == '[')block++;
  if((code[n] == ']') && (block--) && (block == 0))break;
 }
 return (n + 1);
}

canonical_original_code:
int search(char *code, int offset, int codelen){
 int n; int block = 1;
 for(n = offset+1; n < codelen ; n++){
  if(code[n] == '[')block++;
  if((code[n] == ']') && (block--) && (block == 0))break;
 }
 return (n + 1);
}

variable_types:
code
char *

variable_types: offset int

variable_types: codelen int

variable_types: block int


original_code:
int search_r(char *code, int offset){
 int n, block = 1;
 for(n = offset-1; n > 0 ; n--){
  if(code[n] == ']')block++;
  if((code[n] == '[') && (block--) && (block == 0))break;
 }
 return (n + 1);
}

canonical_original_code:
int search_r(char *code, int offset){
 int n; int block = 1;
 for(n = offset-1; n > 0 ; n--){
  if(code[n] == ']')block++;
  if((code[n] == '[') && (block--) && (block == 0))break;
 }
 return (n + 1);
}

variable_types: n int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int i; // ebx
char v6; // al
char v8[256]; // [rsp+0h] [rbp-518h] BYREF
char dest[1048]; // [rsp+100h] [rbp-418h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "dhf:e:");
if ( v3 == -1 )
break;
if ( v3 == 102 )
{
strcpy(v8, optarg);
ReadLine(v8, dest, 1024);
}
else if ( v3 > 102 )
{
if ( v3 == 104 )
puts("bf Usage:\n -f <bf file>\n -e <script>");
}
else if ( v3 == 100 )
{
debug = 1;
}
else if ( v3 == 101 )
{
strcpy(dest, optarg);
}
}
v4 = strlen(dest);
if ( v4 > 0 )
{
for ( i = 0; i < v4; ++i )
{
if ( debug == 1 )
printf("%d mem:%d code:%d\n", (unsigned int)addr, (unsigned int)value[addr], (unsigned int)dest[i]);
v6 = dest[i];
if ( v6 == 91 )
{
if ( !value[addr] )
i = search((__int64)dest, i, v4);
}
else if ( v6 == 93 && value[addr] )
{
i = search_r((__int64)dest, i);
}
Translation(dest[i]);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
int i; // ebx
char v6; // al
char v8[256]; // [rsp+0h] [rbp-518h] BYREF
char dest[1048]; // [rsp+100h] [rbp-418h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "dhf:e:");
if ( v3 == -1 )
break;
if ( v3 == 102 )
{
strcpy(v8, optarg);
func10(v8, dest, 1024);
}
else if ( v3 > 102 )
{
if ( v3 == 104 )
puts("bf Usage:\n -f <bf file>\n -e <script>");
}
else if ( v3 == 100 )
{
debug = 1;
}
else if ( v3 == 101 )
{
strcpy(dest, optarg);
}
}
v4 = strlen(dest);
if ( v4 > 0 )
{
for ( i = 0; i < v4; ++i )
{
if ( debug == 1 )
printf("%d mem:%d code:%d\n", (unsigned int)addr, (unsigned int)value[addr], (unsigned int)dest[i]);
v6 = dest[i];
if ( v6 == 91 )
{
if ( !value[addr] )
i = func8((__int64)dest, i, v4);
}
else if ( v6 == 93 && value[addr] )
{
i = func9((__int64)dest, i);
}
func7(dest[i]);
}
}
return 0;
}

original_code:
int main(int argc ,char *argv[])
{
 int n = 0, len = 0, opt;
 char code[1024], FileName[256];
 while((opt=getopt(argc,argv,"dhf:e:"))!=-1){
  switch (opt)
  {
   case 'f':
    strcpy(FileName, optarg);
    ReadLine(FileName, code, sizeof(code));
    break;
   case 'e':
    strcpy(code, optarg);
    break;
   case 'h':
    printf("bf Usage:\n"
     "   -f <bf file>\n"
     "   -e <script>\n");
    break;
   case 'd':
    debug = 1;
    break;
   default:
    break;
  }
 }
 len = strlen(code);
 for(n = 0;n<len;n++){
  if(debug == 1){
   printf("%d mem:%d code:%d\n",addr, value[addr], code[n]);
  }
  if((code[n] == '[') && (value[addr] == 0)) n = search(code, n, len);
  if((code[n] == ']') && (value[addr] != 0)) n = search_r(code, n);
  Translation(code[n]);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int n = 0; int len = 0; int opt;
 char code[1024]; char FileName[256];
 while((opt=getopt(argc,argv,"dhf:e:"))!=-1){
  switch (opt)
  {
   case 'f':
    strcpy(FileName, optarg);
    ReadLine(FileName, code, sizeof(code));
    break;
   case 'e':
    strcpy(code, optarg);
    break;
   case 'h':
    printf("bf Usage:\n"
     "   -f <bf file>\n"
     "   -e <script>\n");
    break;
   case 'd':
    debug = 1;
    break;
   default:
    break;
  }
 }
 len = strlen(code);
 for(n = 0;n<len;n++){
  if(debug == 1){
   printf("%d mem:%d code:%d\n",addr, value[addr], code[n]);
  }
  if((code[n] == '[') && (value[addr] == 0)) n = search(code, n, len);
  if((code[n] == ']') && (value[addr] != 0)) n = search_r(code, n);
  Translation(code[n]);
 }
 return 0;
}

variable_types: len int

variable_types: opt int

variable_types:
code
char [1024]

variable_types:
FileName
char [256]


repo: tatsui/haminng-test

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // bx
__int64 v4; // rax
unsigned int v5; // ebp
unsigned __int16 v6; // bx
unsigned __int16 v7; // ax
unsigned __int16 v8; // bp
unsigned __int16 v9; // ax

v3 = bitdiv(1702LL, 19LL, envp) | 0x6A60;
v4 = rbin(v3, 15LL);
printf(format, v4);
v5 = v3 >> 4;
printf(asc_108, v3, v3 >> 4);
v6 = v3 ^ 4;
printf(aCX0x04xIXD, v6, v5);
v7 = check(v6);
if ( v7 )
{
v8 = v7;
v9 = correct(v6, (unsigned __int8)v7);
printf(asc_180, v8, v9);
}
else
{
puts(s);
}
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 uint16_t ix = 1702;
 uint16_t gx = 0x13;
 uint16_t rx = bitdiv(ix, gx);
 uint16_t cx = rx|(ix<<(5 -1));
 uint16_t res = 0;
 printf("[組織符号化]\nC(x)=[%s]\n\t\tx_1 -> x_10\n\n", rbin(cx,15));
 printf("[誤り訂正]\nC(x)=0x%04x,I(x)=%d : 誤りなしの場合\n", cx, cx>>4);
 cx = cx ^ 0x04;
 printf("C(x)=0x%04x,I(x)=%d : 誤りビットを加える", cx, cx>>4);
 if((res = check(cx)) != 0)
  printf("\n下位のビットから数えて%dビット目に誤り\n正しくはC(x)=0x%04x\n",
    res,correct(cx,res));
 else
  printf("\n誤りビットなし\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 unsigned short ix = 1702;
 unsigned short gx = 0x13;
 unsigned short rx = bitdiv(ix, gx);
 unsigned short cx = rx|(ix<<(5 -1));
 unsigned short res = 0;
 printf("[組織符号化]\nC(x)=[%s]\n\t\tx_1 -> x_10\n\n", rbin(cx,15));
 printf("[誤り訂正]\nC(x)=0x%04x,I(x)=%d : 誤りなしの場合\n", cx, cx>>4);
 cx = cx ^ 0x04;
 printf("C(x)=0x%04x,I(x)=%d : 誤りビットを加える", cx, cx>>4);
 if((res = check(cx)) != 0)
  printf("\n下位のビットから数えて%dビット目に誤り\n正しくはC(x)=0x%04x\n",
    res,correct(cx,res));
 else
  printf("\n誤りビットなし\n");
 return 0;
}

variable_types:
ix
unsigned short

variable_types:
gx
unsigned short

variable_types:
rx
unsigned short

variable_types:
cx
unsigned short

variable_types:
res
unsigned short


rbin

decompiled_code:
char *__fastcall rbin(unsigned __int16 a1, unsigned __int8 a2)
{
int i; // ebp

bin = 0;
if ( !a2 )
return &bin;
for ( i = 0; i != a2; ++i )
{
sprintf(&bin, "%s%01d", &bin, a1 & 1);
a1 >>= 1;
}
return &bin;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int16 a1, unsigned __int8 a2)
{
int i; // ebp

bin = 0;
if ( !a2 )
return &bin;
for ( i = 0; i != a2; ++i )
{
sprintf(&bin, "%s%01d", &bin, a1 & 1);
a1 >>= 1;
}
return &bin;
}

original_code:
int8_t *rbin(uint16_t num, uint8_t bit){
 int i = 0;
 uint16_t shnum = num;
 bin.string16[0]='\0';
 for(;i < bit; i++, shnum >>= 1)
  sprintf(bin.string16, "%s%01d", bin.string16, shnum&1);
 return bin.string16;
}

canonical_original_code:
char *rbin(unsigned short num, unsigned char bit){
 int i = 0;
 unsigned short shnum = num;
 bin.string16[0]='\0';
 for(;i < bit; i++, shnum >>= 1)
  sprintf(bin.string16, "%s%01d", bin.string16, shnum&1);
 return bin.string16;
}

variable_types:
num
unsigned short

variable_types:
bit
unsigned char

variable_types: i int

variable_types:
shnum
unsigned short

return_type: char *


bitdiv

decompiled_code:
__int16 __fastcall bitdiv(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned int i; // ebp
int v5; // edx

for ( i = 0; i != 11; ++i )
{
v5 = (unsigned __int16)(a2 & a1);
if ( _bittest(&v5, i) )
a1 ^= a2;
else
a1 = AND(a1, a2);
a2 *= 2;
}
return a1 >> 11;
}

canonical_decompiled_code:
__int16 __fastcall func2(unsigned __int16 a1, unsigned __int16 a2)
{
unsigned int i; // ebp
int v5; // edx

for ( i = 0; i != 11; ++i )
{
v5 = (unsigned __int16)(a2 & a1);
if ( _bittest(&v5, i) )
a1 ^= a2;
else
a1 = func1(a1, a2);
a2 *= 2;
}
return a1 >> 11;
}

original_code:
uint16_t bitdiv(uint16_t info, uint16_t gen){
 int i= 0;
 uint16_t res = info;
 uint16_t shgen = gen;
 for(;i < 11; i++, shgen <<= 1)
  if((((res&shgen)>>i)&1) == 1)
   res = res^shgen;
  else
   res = _AND(res,shgen);
 return res>>11;
}

canonical_original_code:
unsigned short bitdiv(unsigned short info, unsigned short gen){
 int i = 0;
 unsigned short res = info;
 unsigned short shgen = gen;
 for(;i < 11; i++, shgen <<= 1)
  if((((res&shgen)>>i)&1) == 1)
   res = res^shgen;
  else
   res = _AND(res,shgen);
 return res>>11;
}

variable_types:
info
unsigned short

variable_types:
gen
unsigned short

variable_types:
shgen
unsigned short

return_type: unsigned short


check

original_code:
uint16_t check(uint16_t cx){
 int i = 0;
 uint16_t shcx = cx;
 uint16_t checkbit = 0;
 uint8_t check_table[]={
   0x1,0x2,0x4,0x8,0x3,
   0x6,0xc,0xb,0x5,0xa,
   0x7,0xe,0xf,0xd,0x9
 };
 for(;i<15;i++, shcx >>= 1)
  if(shcx&1 == 1)
   checkbit^=check_table[i];
 if(checkbit == 0)
  return 0;
 else
  for(i=0;i<15;i++)
   if(checkbit == check_table[i])return i+1;
}

canonical_original_code:
unsigned short check(unsigned short cx){
 int i = 0;
 unsigned short shcx = cx;
 unsigned short checkbit = 0;
 unsigned char check_table[] = {
   0x1,0x2,0x4,0x8,0x3,
   0x6,0xc,0xb,0x5,0xa,
   0x7,0xe,0xf,0xd,0x9
 };
 for(;i<15;i++, shcx >>= 1)
  if(shcx&1 == 1)
   checkbit^=check_table[i];
 if(checkbit == 0)
  return 0;
 else
  for(i=0;i<15;i++)
   if(checkbit == check_table[i])return i+1;
}

variable_types:
shcx
unsigned short

variable_types:
checkbit
unsigned short


correct

decompiled_code:
__int64 __fastcall correct(unsigned int a1, unsigned __int8 a2)
{
int v2; // eax

v2 = 1;
if ( a2 != 1 )
{
while ( a2 - 1 != v2 )
{
if ( ++v2 == 16 )
return a1;
}
}
return a1 ^ (1 << (a2 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned __int8 a2)
{
int v2; // eax

v2 = 1;
if ( a2 != 1 )
{
while ( a2 - 1 != v2 )
{
if ( ++v2 == 16 )
return a1;
}
}
return a1 ^ (1 << (a2 - 1));
}

original_code:
uint16_t correct(uint16_t num, uint8_t bit){
 int i = 0;
 uint16_t ret = num;
 for(;i<16;i++)
  if(i == (bit-1)){
   ret ^= (1<<i);
   break;
  }
 return ret;
}

canonical_original_code:
unsigned short correct(unsigned short num, unsigned char bit){
 int i = 0;
 unsigned short ret = num;
 for(;i<16;i++)
  if(i == (bit-1)){
   ret ^= (1<<i);
   break;
  }
 return ret;
}

variable_types:
ret
unsigned short


decompiled_code:
int init_print_disas_ssdd()
{
init_str_src();
return init_str_dst();
}

canonical_decompiled_code:
int func4()
{
func2();
return func3();
}

original_code:
char init_print_disas_ssdd(){
 init_str_src();
 init_str_dst();
}

return_type: char


decompiled_code:
int init_print_disas_dd()
{
return init_str_dst();
}

canonical_decompiled_code:
int func5()
{
return func3();
}

original_code:
char init_print_disas_dd()
{
 init_str_dst();
}


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("%s Usage:\n -v <v6 file>\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("%s Usage:\n -v <v6 file>\n", a1);
exit(0);
}

original_code:
void usage(char *pname)
{
  printf("%s Usage:\n"
     "  -v <v6 file>\n", pname);
  exit(0);
}

variable_types:
pname
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rax
unsigned __int16 v4; // r12
__int64 v5; // r13
int v6; // eax
unsigned __int16 v7; // r14
__int64 v8; // r13
const char **v9; // r12
__int64 v10; // rbp
int v11; // eax
int v12; // ebx
int v13; // eax
__int16 v14; // dx
unsigned __int16 v15; // dx
unsigned __int16 v16; // ax
unsigned __int16 v17; // ax
unsigned int v18; // eax
char v20[808]; // [rsp+0h] [rbp-328h] BYREF

*(&dbg + 1) = 1;
v3 = (unsigned int)((_DWORD)w_data + 256);
do
*(_BYTE *)v3++ = 0;
while ( v3 != (_DWORD)w_data + 65792 );
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt((unsigned __int16)argc, (char *const *)argv, "dhv:m:");
if ( v6 == -1 )
break;
if ( v6 == 109 )
{
dbg = strtol(optarg, 0LL, 16);
}
else if ( v6 > 109 )
{
if ( v6 != 118 )
goto LABEL_14;
v4 = optind - 1;
strcpy(v20, optarg);
v5 = (int)ReadFile(v20, (unsigned int)((_DWORD)w_data + 256));
}
else
{
if ( v6 != 100 )
{
if ( v6 == 104 )
usage(*argv);
LABEL_14:
usage(*argv);
}
*(&dbg + 1) = 0;
}
}
v7 = argc - v4;
if ( !v5 )
usage(*argv);
LODWORD(v8) = v7 - 1;
if ( (int)v8 >= 0 )
{
v8 = (int)v8;
v9 = &argv[v4];
v10 = (int)v8;
do
{
v11 = (strlen(v9[v10]) + 2) & 0xFFFFFFFE;
v12 = greg[6] - v11;
greg[6] -= v11;
strcpy(&w_data[(unsigned __int16)v12 + 256], v9[v10]);
*(_WORD *)&v20[2 * v10-- + 256] = v12;
}
while ( (int)v10 >= 0 );
v13 = v12 - 2;
do
{
v14 = *(_WORD *)&v20[2 * v8 + 256];
w_data[(unsigned __int16)v13 + 256] = v14;
w_data[(unsigned __int16)v13 + 257] = HIBYTE(v14);
v15 = v13;
v13 -= 2;
--v8;
}
while ( (int)v8 >= 0 );
greg[6] = v15;
}
v16 = greg[6] - 2;
greg[6] = v16;
w_data[v16 + 256] = v7;
w_data[v16 + 257] = HIBYTE(v7);
greg[7] = 2;
if ( v6_h[1] > 1u )
{
v17 = 2;
do
{
greg[8] = v17 - 2;
print_mem();
v18 = read_word(greg[8]);
Translation(v18);
v17 = greg[7] + 2;
greg[7] = v17;
}
while ( v17 <= v6_h[1] );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rax
unsigned __int16 v4; // r12
__int64 v5; // r13
int v6; // eax
unsigned __int16 v7; // r14
__int64 v8; // r13
const char **v9; // r12
__int64 v10; // rbp
int v11; // eax
int v12; // ebx
int v13; // eax
__int16 v14; // dx
unsigned __int16 v15; // dx
unsigned __int16 v16; // ax
unsigned __int16 v17; // ax
unsigned int v18; // eax
char v20[808]; // [rsp+0h] [rbp-328h] BYREF

*(&dbg + 1) = 1;
v3 = (unsigned int)((_DWORD)w_data + 256);
do
*(_BYTE *)v3++ = 0;
while ( v3 != (_DWORD)w_data + 65792 );
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = getopt((unsigned __int16)argc, (char *const *)argv, "dhv:m:");
if ( v6 == -1 )
break;
if ( v6 == 109 )
{
dbg = strtol(optarg, 0LL, 16);
}
else if ( v6 > 109 )
{
if ( v6 != 118 )
goto LABEL_14;
v4 = optind - 1;
strcpy(v20, optarg);
v5 = (int)ReadFile(v20, (unsigned int)((_DWORD)w_data + 256));
}
else
{
if ( v6 != 100 )
{
if ( v6 == 104 )
func0(*argv);
LABEL_14:
func0(*argv);
}
*(&dbg + 1) = 0;
}
}
v7 = argc - v4;
if ( !v5 )
func0(*argv);
LODWORD(v8) = v7 - 1;
if ( (int)v8 >= 0 )
{
v8 = (int)v8;
v9 = &argv[v4];
v10 = (int)v8;
do
{
v11 = (strlen(v9[v10]) + 2) & 0xFFFFFFFE;
v12 = greg[6] - v11;
greg[6] -= v11;
strcpy(&w_data[(unsigned __int16)v12 + 256], v9[v10]);
*(_WORD *)&v20[2 * v10-- + 256] = v12;
}
while ( (int)v10 >= 0 );
v13 = v12 - 2;
do
{
v14 = *(_WORD *)&v20[2 * v8 + 256];
w_data[(unsigned __int16)v13 + 256] = v14;
w_data[(unsigned __int16)v13 + 257] = HIBYTE(v14);
v15 = v13;
v13 -= 2;
--v8;
}
while ( (int)v8 >= 0 );
greg[6] = v15;
}
v16 = greg[6] - 2;
greg[6] = v16;
w_data[v16 + 256] = v7;
w_data[v16 + 257] = HIBYTE(v7);
greg[7] = 2;
if ( v6_h[1] > 1u )
{
v17 = 2;
do
{
greg[8] = v17 - 2;
print_mem();
v18 = read_word(greg[8]);
Translation(v18);
v17 = greg[7] + 2;
greg[7] = v17;
}
while ( v17 <= v6_h[1] );
}
return 0;
}

original_code:
int main(int argc ,char *argv[])
{
 unsigned long tail = 0;
 uint16_t nargc=1;
 int len = 0,i = 0, j = 0, opt;
 uint16_t iargc = 0,pargv[0xFF];
 unsigned char FileName[256];
 dbg.flag = 1;
 for(i = 0;i < 0x10000; i++)w_data.mem[i]=0;
 while((opt=getopt(argc,argv, "dhv:m:"))!=-1){
  switch (opt)
  {
   case 'v':
    iargc = optind - 1;
    strcpy(FileName, optarg);
    tail = ReadFile(FileName, w_data.mem);
    j+=2;
    break;
   case 'm':
    dbg.break_mem = strtol(optarg, ((void *)0), 16);
    j+=2;
    break;
   case 'd':
    dbg.flag = 0;
    j++;
    break;
   case 'h':
    usage(argv[0]);
    break;
   default:
    usage(argv[0]);
    break;
  }
 }
 nargc = argc-iargc;
 if(tail <= 0)usage(argv[0]);
 for(i=nargc-1; i>=0; i--){
  (greg.r[6])-=((strlen(argv[iargc+i])+2)&~1);
  strcpy(&w_data.mem[(greg.r[6])],argv[iargc+i]);
  pargv[i] = (greg.r[6]);
 }
 for(i=nargc-1; i>=0; i--){
  (greg.r[6])-=sizeof(uint16_t);
  w_data.mem[(greg.r[6])] = (uint8_t)pargv[i];
  w_data.mem[(greg.r[6])+1] = (uint8_t)(pargv[i]>>8);
 }
 (greg.r[6]) -= sizeof(uint16_t);
 w_data.mem[(greg.r[6])] = (uint8_t)nargc;
 w_data.mem[(greg.r[6])+1] = (uint8_t)(nargc>>8);
 for((greg.r[7]) = 2; (greg.r[7]) <= v6_h.text; (greg.r[7])+=2){
  greg.work = (greg.r[7]) - 2;
  print_mem();
  Translation(read_word(greg.work));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned long tail = 0;
 unsigned short nargc = 1;
 int len = 0; int i = 0; int j = 0; int opt;
 unsigned short iargc = 0; unsigned short pargv[255];
 unsigned char FileName[256];
 dbg.flag = 1;
 for(i = 0;i < 0x10000; i++)w_data.mem[i]=0;
 while((opt=getopt(argc,argv, "dhv:m:"))!=-1){
  switch (opt)
  {
   case 'v':
    iargc = optind - 1;
    strcpy(FileName, optarg);
    tail = ReadFile(FileName, w_data.mem);
    j+=2;
    break;
   case 'm':
    dbg.break_mem = strtol(optarg, ((void *)0), 16);
    j+=2;
    break;
   case 'd':
    dbg.flag = 0;
    j++;
    break;
   case 'h':
    usage(argv[0]);
    break;
   default:
    usage(argv[0]);
    break;
  }
 }
 nargc = argc-iargc;
 if(tail <= 0)usage(argv[0]);
 for(i=nargc-1; i>=0; i--){
  (greg.r[6])-=((strlen(argv[iargc+i])+2)&~1);
  strcpy(&w_data.mem[(greg.r[6])],argv[iargc+i]);
  pargv[i] = (greg.r[6]);
 }
 for(i=nargc-1; i>=0; i--){
  (greg.r[6])-=sizeof(unsigned short);
  w_data.mem[(greg.r[6])] = (unsigned char)pargv[i];
  w_data.mem[(greg.r[6])+1] = (unsigned char)(pargv[i]>>8);
 }
 (greg.r[6]) -= sizeof(unsigned short);
 w_data.mem[(greg.r[6])] = (unsigned char)nargc;
 w_data.mem[(greg.r[6])+1] = (unsigned char)(nargc>>8);
 for((greg.r[7]) = 2; (greg.r[7]) <= v6_h.text; (greg.r[7])+=2){
  greg.work = (greg.r[7]) - 2;
  print_mem();
  Translation(read_word(greg.work));
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
tail
unsigned long

variable_types:
nargc
unsigned short

variable_types: len int

variable_types: j int

variable_types: opt int

variable_types:
iargc
unsigned short

variable_types:
pargv
unsigned short [255]

variable_types:
FileName
unsigned char [256]


loadSymbol

decompiled_code:
__int64 __fastcall loadSymbol(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax
char *v4; // rbp
__int64 v5; // rbx

v2 = (unsigned __int16)v6_h[2] + (unsigned __int16)v6_h[1];
result = v2;
if ( a2 > v2 )
{
v4 = v6_sym;
v5 = a1 + v2;
do
{
strcpy(v4, (const char *)v5);
v4[8] = 0;
*((_DWORD *)v4 + 3) = *(unsigned __int16 *)(v5 + 8);
*((_DWORD *)v4 + 4) = *(unsigned __int16 *)(v5 + 10);
++v6_sym_array_num;
v4 += 20;
v5 += 12LL;
result = v5 - a1;
}
while ( a2 > v5 - a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax
char *v4; // rbp
__int64 v5; // rbx

v2 = (unsigned __int16)v6_h[2] + (unsigned __int16)v6_h[1];
result = v2;
if ( a2 > v2 )
{
v4 = v6_sym;
v5 = a1 + v2;
do
{
strcpy(v4, (const char *)v5);
v4[8] = 0;
*((_DWORD *)v4 + 3) = *(unsigned __int16 *)(v5 + 8);
*((_DWORD *)v4 + 4) = *(unsigned __int16 *)(v5 + 10);
++v6_sym_array_num;
v4 += 20;
v5 += 12LL;
result = v5 - a1;
}
while ( a2 > v5 - a1 );
}
return result;
}

original_code:
int loadSymbol(unsigned char *p_code, long file_size){
 int start = 0,i = 0,j = 0;
 start = v6_h.text + v6_h.data;
 for(i = start, j = 0; i < file_size; i+=12,j++){
  strcpy(v6_sym[j].symbol_name ,&p_code[i]);
  v6_sym[j].symbol_name[8] = '\0';
  v6_sym[j].type = p_code[i + 8]|p_code[i + 9] << 8;
  v6_sym[j].addr = p_code[i + 10]|p_code[i + 11] << 8;
  v6_sym_array_num++;
 }
}

canonical_original_code:
int loadSymbol(unsigned char *p_code, long file_size){
 int start = 0; int i = 0; int j = 0;
 start = v6_h.text + v6_h.data;
 for(i = start, j = 0; i < file_size; i+=12,j++){
  strcpy(v6_sym[j].symbol_name ,&p_code[i]);
  v6_sym[j].symbol_name[8] = '\0';
  v6_sym[j].type = p_code[i + 8]|p_code[i + 9] << 8;
  v6_sym[j].addr = p_code[i + 10]|p_code[i + 11] << 8;
  v6_sym_array_num++;
 }
}

variable_types: start int

variable_types: i int


selectSymbol

decompiled_code:
int __fastcall selectSymbol(int a1)
{
char *v1; // rbx
int v2; // ebp
int result; // eax
__int64 v4; // rsi

if ( v6_sym_array_num > 0 )
{
v1 = v6_sym;
v2 = 0;
do
{
v4 = *((unsigned int *)v1 + 4);
if ( (_DWORD)v4 == a1 )
{
switch ( *((_DWORD *)v1 + 3) )
{
case 2:
result = printf("%07ot %s\n", v4, v1);
break;
case 3:
result = printf("%07od %s\n", v4, v1);
break;
case 4:
result = printf("%07ob %s\n", v4, v1);
break;
case 0x1F:
result = printf("%07oa %s\n", v4, v1);
break;
case 0x22:
result = printf("%07oT %s\n", v4, v1);
break;
case 0x24:
result = printf("%07oB %s\n", v4, v1);
break;
default:
result = printf("%07o? %s\n", v4, v1);
break;
}
}
++v2;
v1 += 20;
}
while ( v6_sym_array_num > v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
char *v1; // rbx
int v2; // ebp
int result; // eax
__int64 v4; // rsi

if ( v6_sym_array_num > 0 )
{
v1 = v6_sym;
v2 = 0;
do
{
v4 = *((unsigned int *)v1 + 4);
if ( (_DWORD)v4 == a1 )
{
switch ( *((_DWORD *)v1 + 3) )
{
case 2:
result = printf("%07ot %s\n", v4, v1);
break;
case 3:
result = printf("%07od %s\n", v4, v1);
break;
case 4:
result = printf("%07ob %s\n", v4, v1);
break;
case 0x1F:
result = printf("%07oa %s\n", v4, v1);
break;
case 0x22:
result = printf("%07oT %s\n", v4, v1);
break;
case 0x24:
result = printf("%07oB %s\n", v4, v1);
break;
default:
result = printf("%07o? %s\n", v4, v1);
break;
}
}
++v2;
v1 += 20;
}
while ( v6_sym_array_num > v2 );
}
return result;
}

original_code:
int selectSymbol(int v6_sym_addr){
 int i = 0, j = 0;
 for(j = 0; j < v6_sym_array_num; j++){
  if(v6_sym_addr == v6_sym[j].addr){
   switch(v6_sym[j].type){
    case 0x0024:
     printf("%07oB  %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0022:
     printf("%07oT %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0002:
     printf("%07ot %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0003:
     printf("%07od %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0004:
     printf("%07ob %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x001F:
     printf("%07oa %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    default:
     printf("%07o? %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
   }
  }
 }
}

canonical_original_code:
int selectSymbol(int v6_sym_addr){
 int i = 0; int j = 0;
 for(j = 0; j < v6_sym_array_num; j++){
  if(v6_sym_addr == v6_sym[j].addr){
   switch(v6_sym[j].type){
    case 0x0024:
     printf("%07oB  %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0022:
     printf("%07oT %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0002:
     printf("%07ot %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0003:
     printf("%07od %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x0004:
     printf("%07ob %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    case 0x001F:
     printf("%07oa %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
    default:
     printf("%07o? %s\n", v6_sym[j].addr, v6_sym[j].symbol_name);
     break;
   }
  }
 }
}


main

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

puts("please input a string!");
_isoc99_scanf("%s", v4);
return printf("%s", v4);
}

original_code:
void main(){
 char buf[1000];
 printf("%s","please input a string!\n");
 scanf("%s",buf);
 printf("%s",buf);
}

variable_types:
buf
char [1000]


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

result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_BYTE *)result + 16) = 110;
result[3] = 0LL;
}
return result;
}

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

result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_BYTE *)result + 16) = 110;
result[3] = 0LL;
}
return result;
}

original_code:
struct threaded_binary_node * new_threaded_binary_node() {
    struct threaded_binary_node * result = malloc( sizeof( struct threaded_binary_node ) );
    if ( !result ) {
        return ((void *)0);
    }
    result->left_link = ((void *)0);
    result->right_link = ((void *)0);
    result->threaded = 'n';
    result->data = ((void *)0);
    return result;
}

canonical_original_code:
struct threaded_binary_node *new_threaded_binary_node() {
    struct threaded_binary_node *result = malloc( sizeof( struct threaded_binary_node ) );
    if ( !result ) {
        return ((void *)0);
    }
    result->left_link = ((void *)0);
    result->right_link = ((void *)0);
    result->threaded = 'n';
    result->data = ((void *)0);
    return result;
}

variable_types: struct threaded_binary_node { struct threaded_binary_node *left_link; struct threaded_binary_node *right_link; char threaded; void *data; } *


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

result = new_threaded_binary_node();
result[1] = result;
*result = result;
*((_BYTE *)result + 16) = 108;
return result;
}

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

result = func0();
result[1] = result;
*result = result;
*((_BYTE *)result + 16) = 108;
return result;
}

original_code:
struct threaded_binary_node * new_threaded_binary_head() {
    struct threaded_binary_node * head = new_threaded_binary_node();
    head->right_link = head;
    head->left_link = head;
    head->threaded = 'l';
    return head;
}

canonical_original_code:
struct threaded_binary_node *new_threaded_binary_head() {
    struct threaded_binary_node *head = new_threaded_binary_node();
    head->right_link = head;
    head->left_link = head;
    head->threaded = 'l';
    return head;
}

return_type: struct threaded_binary_node { struct threaded_binary_node *left_link; struct threaded_binary_node *right_link; char threaded; void *data; } *


original_code:
struct threaded_binary_node * insert_left_leaf( struct threaded_binary_node * node, struct threaded_binary_node * child ) {
    child->left_link = node->left_link;
    node->left_link = child;
    child->right_link = node;
    child->threaded = 'b';
    if ( node->right_link == node ||
         node->threaded == 'l' ) {
        node->threaded = 'n';
    } else {
        node->threaded = 'r';
    }
    return child;
}

canonical_original_code:
struct threaded_binary_node *insert_left_leaf(struct threaded_binary_node *node, struct threaded_binary_node *child) {
    child->left_link = node->left_link;
    node->left_link = child;
    child->right_link = node;
    child->threaded = 'b';
    if ( node->right_link == node ||
         node->threaded == 'l' ) {
        node->threaded = 'n';
    } else {
        node->threaded = 'r';
    }
    return child;
}

variable_types:
node
struct threaded_binary_node *

variable_types:
child
struct threaded_binary_node *

user_defined_types: struct threaded_binary_node { struct threaded_binary_node *left_link; struct threaded_binary_node *right_link; char threaded; void *data; }


original_code:
struct threaded_binary_node * insert_right_leaf( struct threaded_binary_node * node, struct threaded_binary_node * child ) {
    child->right_link = node->right_link;
    node->right_link = child;
    child->left_link = node;
    child->threaded = 'b';
    if ( node->threaded == 'b' ) {
        node->threaded = 'l';
    } else {
        node->threaded = 'n';
    }
    return child;
}

canonical_original_code:
struct threaded_binary_node *insert_right_leaf(struct threaded_binary_node *node, struct threaded_binary_node *child) {
    child->right_link = node->right_link;
    node->right_link = child;
    child->left_link = node;
    child->threaded = 'b';
    if ( node->threaded == 'b' ) {
        node->threaded = 'l';
    } else {
        node->threaded = 'n';
    }
    return child;
}


decompiled_code:
__int64 __fastcall get_threaded_left_child(__int64 *a1)
{
char v1; // al
__int64 result; // rax

v1 = *((_BYTE *)a1 + 16);
if ( v1 == 108 || v1 == 98 )
result = 0LL;
else
result = *a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
char v1; // al
__int64 result; // rax

v1 = *((_BYTE *)a1 + 16);
if ( v1 == 108 || v1 == 98 )
result = 0LL;
else
result = *a1;
return result;
}

original_code:
struct threaded_binary_node * get_threaded_left_child( struct threaded_binary_node * self ) {
    if ( self->threaded == 'l' || self->threaded == 'b' ) {
        return ((void *)0);
    }
    return self->left_link;
}

canonical_original_code:
struct threaded_binary_node *get_threaded_left_child(struct threaded_binary_node *self) {
    if ( self->threaded == 'l' || self->threaded == 'b' ) {
        return ((void *)0);
    }
    return self->left_link;
}

variable_types:
self
struct threaded_binary_node *


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

if ( (*(_BYTE *)(a1 + 16) & 0xEF) == 98 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 8);
return result;
}

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

if ( (*(_BYTE *)(a1 + 16) & 0xEF) == 98 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
struct threaded_binary_node * get_threaded_right_child( struct threaded_binary_node * self ) {
    if ( self->threaded == 'r' || self->threaded == 'b' ) {
        return ((void *)0);
    }
    return self->right_link;
}

canonical_original_code:
struct threaded_binary_node *get_threaded_right_child(struct threaded_binary_node *self) {
    if ( self->threaded == 'r' || self->threaded == 'b' ) {
        return ((void *)0);
    }
    return self->right_link;
}