original_code:
struct apply_med_handle *stack_get_med_ah() {
    struct stack_entry *se;
    se = stack_find_top();
    if (se == ((void *)0)) {
 return(((void *)0));
    }
    if (se->amedh == ((void *)0)) {
 se->amedh = apply_med_init(se->fsm);
 apply_med_set_align_symbol(se->amedh, "-");
    }
    return(se->amedh);
}

return_type: struct apply_med_handle { struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; } *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle { struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *hash; int lastvalue; } *sigmahash; struct state_array { struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *transitions; } *state_array; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *net; struct fsm_state *curr_ptr; _Bool hascm; } *

user_defined_types: struct apply_med_handle { struct astarnode *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle *sigmahash; struct state_array *state_array; struct fsm *net; struct fsm_state *curr_ptr; _Bool hascm; }

user_defined_types: struct apply_handle { int ptr; int curr_ptr; int ipos; int opos; int mode; int printcount; int *numlines; int *statemap; int *marks; struct sigma_trie *sigma_trie; struct sigmatch_array *sigmatch_array; struct sigma_trie_arrays *sigma_trie_arrays; int binsearch; int indexed; int state_has_index; int sigma_size; int sigmatch_array_size; int current_instring_length; int has_flags; int obey_flags; int show_flags; int print_space; int print_pairs; int apply_stack_ptr; int apply_stack_top; int oldflagneg; int outstringtop; int iterate_old; int iterator; unsigned char *flagstates; char *outstring; char *instring; struct sigs *sigs; char *oldflagvalue; struct fsm *last_net; struct fsm_state *gstates; struct sigma *gsigma; struct apply_state_index **index_in; struct flag_list *flag_list; struct flag_lookup *flag_lookup; struct searchstack *searchstack; }


repo: vchahun/foma

original_code:
struct apply_handle *stack_get_ah() {
    struct stack_entry *se;
    se = stack_find_top();
    if (se == ((void *)0)) {
 return(((void *)0));
    }
    if (se->ah == ((void *)0)) {
 se->ah = apply_init(se->fsm);
    }
    return(se->ah);
}

variable_types: struct stack_entry { int number; struct apply_handle { int ptr; int curr_ptr; int ipos; int opos; int mode; int printcount; int *numlines; int *statemap; int *marks; struct sigma_trie { int signum; struct sigma_trie *next; } *sigma_trie; struct sigmatch_array { int signumber; int consumes; } *sigmatch_array; struct sigma_trie_arrays { struct sigma_trie *arr; struct sigma_trie_arrays *next; } *sigma_trie_arrays; int binsearch; int indexed; int state_has_index; int sigma_size; int sigmatch_array_size; int current_instring_length; int has_flags; int obey_flags; int show_flags; int print_space; int print_pairs; int apply_stack_ptr; int apply_stack_top; int oldflagneg; int outstringtop; int iterate_old; int iterator; unsigned char *flagstates; char *outstring; char *instring; struct sigs { char *symbol; int length; } *sigs; char *oldflagvalue; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *last_net; struct fsm_state *gstates; struct sigma *gsigma; struct apply_state_index { int fsmptr; struct apply_state_index *next; } **index_in; struct flag_list { char *name; char *value; short neg; struct flag_list *next; } *flag_list; struct flag_lookup { int type; char *name; char *value; } *flag_lookup; struct searchstack { int offset; struct apply_state_index *iptr; int state_has_index; int opos; int ipos; int visitmark; char *flagname; char *flagvalue; int flagneg; } *searchstack; } *ah; struct apply_med_handle { struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; } *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle { struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *hash; int lastvalue; } *sigmahash; struct state_array { struct fsm_state *transitions; } *state_array; struct fsm *net; struct fsm_state *curr_ptr; _Bool hascm; } *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; } *

user_defined_types: struct stack_entry { int number; struct apply_handle *ah; struct apply_med_handle *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; }

user_defined_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state *states; struct sigma *sigma; struct medlookup *medlookup; }

user_defined_types: struct sh_handle { struct sh_hashtable *hash; int lastvalue; }


decompiled_code:
__int64 stack_turn()
{
__int64 result; // rax
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rsi

if ( stack_isempty() )
{
puts("Stack is empty.");
result = 0LL;
}
else
{
result = stack_size();
if ( (_DWORD)result != 1 )
{
v1 = stack_find_top();
v2 = main_stack;
v3 = *(_QWORD *)(v1 + 32);
*(_QWORD *)(main_stack + 32) = v3;
*(_QWORD *)(v3 + 40) = v2;
main_stack = v1;
v4 = *(_QWORD *)(v1 + 40);
if ( v4 )
{
v5 = v1;
while ( 1 )
{
*(_QWORD *)(v5 + 32) = v4;
v5 = v4;
if ( !*(_QWORD *)(v4 + 40) )
break;
v4 = *(_QWORD *)(v4 + 40);
}
}
if ( *(_DWORD *)v1 == -1 )
{
result = 1LL;
}
else
{
do
*(_QWORD *)(*(_QWORD *)(v1 + 32) + 40LL) = v1;
while ( *(_DWORD *)v1 != -1 );
result = 1LL;
}
}
}
return result;
}

original_code:
int stack_turn () {
  struct stack_entry *stack_ptr;
  if (stack_isempty()) {
    printf("Stack is empty.\n");
    return 0;
  }
  if (stack_size() == 1) {
    return 1;
  }
  stack_ptr = stack_find_top();
  main_stack->next = stack_ptr->next;
  (stack_ptr->next)->previous = main_stack;
  main_stack = stack_ptr;
  while (stack_ptr->previous != ((void *)0)) {
    stack_ptr->next = stack_ptr->previous;
    stack_ptr = stack_ptr->next;
  }
  for (stack_ptr = main_stack; stack_ptr->number != -1;) {
    (stack_ptr->next)->previous = stack_ptr;
  }
  return 1;
}

canonical_original_code:
int stack_turn() {
  struct stack_entry *stack_ptr;
  if (stack_isempty()) {
    printf("Stack is empty.\n");
    return 0;
  }
  if (stack_size() == 1) {
    return 1;
  }
  stack_ptr = stack_find_top();
  main_stack->next = stack_ptr->next;
  (stack_ptr->next)->previous = main_stack;
  main_stack = stack_ptr;
  while (stack_ptr->previous != ((void *)0)) {
    stack_ptr->next = stack_ptr->previous;
    stack_ptr = stack_ptr->next;
  }
  for (stack_ptr = main_stack; stack_ptr->number != -1;) {
    (stack_ptr->next)->previous = stack_ptr;
  }
  return 1;
}

return_type: int

user_defined_types: struct sigma_trie { int signum; struct sigma_trie *next; }

user_defined_types: struct sigmatch_array { int signumber; int consumes; }

user_defined_types: struct sigma_trie_arrays { struct sigma_trie *arr; struct sigma_trie_arrays *next; }

user_defined_types: struct sigs { char *symbol; int length; }

user_defined_types: struct flag_list { char *name; char *value; short neg; struct flag_list *next; }

user_defined_types: struct flag_lookup { int type; char *name; char *value; }

user_defined_types: struct searchstack { int offset; struct apply_state_index *iptr; int state_has_index; int opos; int ipos; int visitmark; char *flagname; char *flagvalue; int flagneg; }

user_defined_types: struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; }

user_defined_types: struct state_array { struct fsm_state *transitions; }

user_defined_types: struct apply_state_index { int fsmptr; struct apply_state_index *next; }

user_defined_types: struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; }

user_defined_types: struct sigma { int number; char *symbol; struct sigma *next; }

user_defined_types: struct medlookup { int *confusion_matrix; }

user_defined_types: struct sh_hashtable { char *string; int value; struct sh_hashtable *next; }


decompiled_code:
__int64 stack_find_bottom()
{
__int64 result; // rax

result = main_stack;
if ( *(_DWORD *)main_stack == -1 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax

result = main_stack;
if ( *(_DWORD *)main_stack == -1 )
result = 0LL;
return result;
}

original_code:
struct stack_entry *stack_find_bottom () {
  if (main_stack->number == -1) {
    return ((void *)0);
  }
  return(main_stack);
}

canonical_original_code:
struct stack_entry *stack_find_bottom() {
  if (main_stack->number == -1) {
    return ((void *)0);
  }
  return(main_stack);
}

return_type: struct stack_entry { int number; struct apply_handle { int ptr; int curr_ptr; int ipos; int opos; int mode; int printcount; int *numlines; int *statemap; int *marks; struct sigma_trie { int signum; struct sigma_trie *next; } *sigma_trie; struct sigmatch_array { int signumber; int consumes; } *sigmatch_array; struct sigma_trie_arrays { struct sigma_trie *arr; struct sigma_trie_arrays *next; } *sigma_trie_arrays; int binsearch; int indexed; int state_has_index; int sigma_size; int sigmatch_array_size; int current_instring_length; int has_flags; int obey_flags; int show_flags; int print_space; int print_pairs; int apply_stack_ptr; int apply_stack_top; int oldflagneg; int outstringtop; int iterate_old; int iterator; unsigned char *flagstates; char *outstring; char *instring; struct sigs { char *symbol; int length; } *sigs; char *oldflagvalue; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *last_net; struct fsm_state *gstates; struct sigma *gsigma; struct apply_state_index { int fsmptr; struct apply_state_index *next; } **index_in; struct flag_list { char *name; char *value; short neg; struct flag_list *next; } *flag_list; struct flag_lookup { int type; char *name; char *value; } *flag_lookup; struct searchstack { int offset; struct apply_state_index *iptr; int state_has_index; int opos; int ipos; int visitmark; char *flagname; char *flagvalue; int flagneg; } *searchstack; } *ah; struct apply_med_handle { struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; } *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle { struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *hash; int lastvalue; } *sigmahash; struct state_array { struct fsm_state *transitions; } *state_array; struct fsm *net; struct fsm_state *curr_ptr; _Bool hascm; } *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; } *

user_defined_types: struct stack_entry { int number; struct apply_handle *ah; struct apply_med_handle *amedh; struct fsm *fsm; struct stack_entry *next; struct stack_entry *previous; }

user_defined_types: struct apply_handle { int ptr; int curr_ptr; int ipos; int opos; int mode; int printcount; int *numlines; int *statemap; int *marks; struct sigma_trie *sigma_trie; struct sigmatch_array *sigmatch_array; struct sigma_trie_arrays *sigma_trie_arrays; int binsearch; int indexed; int state_has_index; int sigma_size; int sigmatch_array_size; int current_instring_length; int has_flags; int obey_flags; int show_flags; int print_space; int print_pairs; int apply_stack_ptr; int apply_stack_top; int oldflagneg; int outstringtop; int iterate_old; int iterator; unsigned char *flagstates; char *outstring; char *instring; struct sigs *sigs; char *oldflagvalue; struct fsm *last_net; struct fsm_state *gstates; struct sigma *gsigma; struct apply_state_index **index_in; struct flag_list *flag_list; struct flag_lookup *flag_lookup; struct searchstack *searchstack; }

user_defined_types: struct apply_med_handle { struct astarnode *agenda; int bytes_per_letter_array; unsigned char *letterbits; unsigned char *nletterbits; int astarcount; int heapcount; int heap_size; int agenda_size; int maxdepth; int maxsigma; int wordlen; int utf8len; int cost; int nummatches; int curr_state; int curr_g; int curr_pos; int lines; int curr_agenda_offset; int curr_node_has_match; int med_limit; int med_cutoff; int med_max_heap_size; int nodes_expanded; int *cm; char *word; char *instring; int instring_length; char *outstring; int outstring_length; char *align_symbol; int *heap; int *intword; struct sh_handle *sigmahash; struct state_array *state_array; struct fsm *net; struct fsm_state *curr_ptr; _Bool hascm; }


decompiled_code:
__int64 stack_find_second()
{
__int64 v0; // rax
__int64 v1; // rdx

v0 = main_stack;
do
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 32);
}
while ( *(_DWORD *)v0 != -1 );
return *(_QWORD *)(v1 + 40);
}

original_code:
struct stack_entry *stack_find_second () {
  struct stack_entry *stack_ptr;
  for (stack_ptr = main_stack; (stack_ptr->next)->number != -1; stack_ptr = stack_ptr->next);
  return(stack_ptr->previous);
}

canonical_original_code:
struct stack_entry *stack_find_second() {
  struct stack_entry *stack_ptr;
  for (stack_ptr = main_stack; (stack_ptr->next)->number != -1; stack_ptr = stack_ptr->next);
  return(stack_ptr->previous);
}

user_defined_types: struct sigma_trie { int signum; struct sigma_trie *next; }

user_defined_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state *states; struct sigma *sigma; struct medlookup *medlookup; }

user_defined_types: struct sh_handle { struct sh_hashtable *hash; int lastvalue; }


decompiled_code:
__int64 stack_clear()
{
_QWORD *i; // rbx

for ( i = (_QWORD *)main_stack; *(_QWORD *)(main_stack + 32); i = (_QWORD *)main_stack )
{
if ( i[1] )
apply_clear();
if ( i[2] )
apply_med_clear();
main_stack = i[4];
fsm_destroy(i[3]);
xxfree(i);
}
xxfree(i);
return stack_init();
}

canonical_decompiled_code:
__int64 func10()
{
_QWORD *i; // rbx

for ( i = (_QWORD *)main_stack; *(_QWORD *)(main_stack + 32); i = (_QWORD *)main_stack )
{
if ( i[1] )
apply_clear();
if ( i[2] )
apply_med_clear();
main_stack = i[4];
fsm_destroy(i[3]);
xxfree(i);
}
xxfree(i);
return func1();
}

original_code:
int stack_clear(void) {
  struct stack_entry *stack_ptr;
  for (stack_ptr = main_stack ; stack_ptr->next != ((void *)0); stack_ptr = main_stack) {
    if (stack_ptr->ah != ((void *)0))
 apply_clear(stack_ptr->ah);
    if (stack_ptr->amedh != ((void *)0))
 apply_med_clear(stack_ptr->amedh);
    main_stack = stack_ptr->next;
    fsm_destroy(stack_ptr->fsm);
    xxfree(stack_ptr);
  }
  xxfree(stack_ptr);
  return(stack_init());
}

canonical_original_code:
int stack_clear() {
  struct stack_entry *stack_ptr;
  for (stack_ptr = main_stack ; stack_ptr->next != ((void *)0); stack_ptr = main_stack) {
    if (stack_ptr->ah != ((void *)0))
 apply_clear(stack_ptr->ah);
    if (stack_ptr->amedh != ((void *)0))
 apply_med_clear(stack_ptr->amedh);
    main_stack = stack_ptr->next;
    fsm_destroy(stack_ptr->fsm);
    xxfree(stack_ptr);
  }
  xxfree(stack_ptr);
  return(stack_init());
}

user_defined_types: struct sigmatch_array { int signumber; int consumes; }

user_defined_types: struct sigma_trie_arrays { struct sigma_trie *arr; struct sigma_trie_arrays *next; }

user_defined_types: struct sigs { char *symbol; int length; }


original_code:
struct fsm *stack_pop(void) {
  int i;
  struct fsm *fsm;
  struct stack_entry *stack_ptr;
  if (stack_size() == 1) {
    fsm = main_stack->fsm;
    main_stack->fsm = ((void *)0);
    stack_clear();
    return(fsm);
  }
  for (i=0, stack_ptr = main_stack; (stack_ptr->next)->number != -1; stack_ptr = stack_ptr->next, i++);
  (stack_ptr->previous)->next = stack_ptr->next;
  (stack_ptr->next)->previous = stack_ptr->previous;
  fsm = stack_ptr->fsm;
  if (stack_ptr->ah != ((void *)0)) {
      apply_clear(stack_ptr->ah);
      stack_ptr->ah = ((void *)0);
  }
  if (stack_ptr->amedh != ((void *)0)) {
      apply_med_clear(stack_ptr->amedh);
      stack_ptr->amedh = ((void *)0);
  }
  stack_ptr->fsm = ((void *)0);
  xxfree(stack_ptr);
  return(fsm);
}

canonical_original_code:
struct fsm *stack_pop() {
  int i;
  struct fsm *fsm;
  struct stack_entry *stack_ptr;
  if (stack_size() == 1) {
    fsm = main_stack->fsm;
    main_stack->fsm = ((void *)0);
    stack_clear();
    return(fsm);
  }
  for (i=0, stack_ptr = main_stack; (stack_ptr->next)->number != -1; stack_ptr = stack_ptr->next, i++);
  (stack_ptr->previous)->next = stack_ptr->next;
  (stack_ptr->next)->previous = stack_ptr->previous;
  fsm = stack_ptr->fsm;
  if (stack_ptr->ah != ((void *)0)) {
      apply_clear(stack_ptr->ah);
      stack_ptr->ah = ((void *)0);
  }
  if (stack_ptr->amedh != ((void *)0)) {
      apply_med_clear(stack_ptr->amedh);
      stack_ptr->amedh = ((void *)0);
  }
  stack_ptr->fsm = ((void *)0);
  xxfree(stack_ptr);
  return(fsm);
}

variable_types: i int

variable_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *

user_defined_types: struct flag_list { char *name; char *value; short neg; struct flag_list *next; }

user_defined_types: struct flag_lookup { int type; char *name; char *value; }

user_defined_types: struct searchstack { int offset; struct apply_state_index *iptr; int state_has_index; int opos; int ipos; int visitmark; char *flagname; char *flagvalue; int flagneg; }


decompiled_code:
__int64 stack_rotate()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rcx

if ( stack_isempty() )
{
puts("Stack is empty.");
result = 0xFFFFFFFFLL;
}
else
{
result = stack_size();
if ( (_DWORD)result != 1 )
{
v1 = stack_find_top();
v2 = *(_QWORD *)(main_stack + 24);
*(_QWORD *)(main_stack + 24) = *(_QWORD *)(v1 + 24);
*(_QWORD *)(v1 + 24) = v2;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rcx

if ( func3() )
{
puts("Stack is empty.");
result = 0xFFFFFFFFLL;
}
else
{
result = func0();
if ( (_DWORD)result != 1 )
{
v1 = func4();
v2 = *(_QWORD *)(main_stack + 24);
*(_QWORD *)(main_stack + 24) = *(_QWORD *)(v1 + 24);
*(_QWORD *)(v1 + 24) = v2;
result = 1LL;
}
}
return result;
}

original_code:
int stack_rotate () {
  struct stack_entry *stack_ptr;
  struct fsm *temp_fsm;
  if (stack_isempty()) {
    printf("Stack is empty.\n");
    return -1;
  }
  if (stack_size() == 1) {
    return 1;
  }
  stack_ptr = stack_find_top();
  temp_fsm = main_stack->fsm;
  main_stack->fsm = stack_ptr->fsm;
  stack_ptr->fsm = temp_fsm;
  return 1;
}

canonical_original_code:
int stack_rotate() {
  struct stack_entry *stack_ptr;
  struct fsm *temp_fsm;
  if (stack_isempty()) {
    printf("Stack is empty.\n");
    return -1;
  }
  if (stack_size() == 1) {
    return 1;
  }
  stack_ptr = stack_find_top();
  temp_fsm = main_stack->fsm;
  main_stack->fsm = stack_ptr->fsm;
  stack_ptr->fsm = temp_fsm;
  return 1;
}

user_defined_types: struct astarnode { short wordpos; int fsmstate; short f; short g; short h; int in; int out; int parent; }

user_defined_types: struct state_array { struct fsm_state *transitions; }

user_defined_types: struct apply_state_index { int fsmptr; struct apply_state_index *next; }


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

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

original_code:
int stack_print () {
  return 1;
}

canonical_original_code:
int stack_print() {
  return 1;
}


decompiled_code:
__int64 __fastcall next_power_of_two(int a1)
{
char v1; // cl

if ( a1 <= 0 )
{
v1 = 0;
}
else
{
v1 = 0;
do
{
a1 >>= 1;
++v1;
}
while ( a1 > 0 );
}
return (unsigned int)(1 << v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
char v1; // cl

if ( a1 <= 0 )
{
v1 = 0;
}
else
{
v1 = 0;
do
{
a1 >>= 1;
++v1;
}
while ( a1 > 0 );
}
return (unsigned int)(1 << v1);
}

original_code:
int next_power_of_two(int v) {
    int i;
    for (i=0; v > 0; i++)
        v = v >> 1;
    return (1 << i);
}

variable_types: v int


original_code:
unsigned int round_up_to_power_of_two(unsigned int v) {
    v--;
    v |= v >> 1;
    v |= v >> 2;
    v |= v >> 4;
    v |= v >> 8;
    v |= v >> 16;
    v++;
    return(v);
}

variable_types:
v
unsigned int

return_type: unsigned int


xxstrndup

decompiled_code:
char *__fastcall xxstrndup(void *src, __int64 a2)
{
char *v2; // rax
signed __int64 v3; // rbx
size_t v4; // r13
char *v5; // rax
char *v6; // r12

v2 = (char *)src;
do
++v2;
while ( *(v2 - 1) && (char *)src + a2 + 1LL - (_QWORD)v2 );
v3 = v2 - (_BYTE *)src;
v4 = v2 - (_BYTE *)src - 1;
v5 = (char *)xxmalloc_localalias(v2 - (_BYTE *)src);
v6 = v5;
if ( v5 )
{
memcpy(v5, src, v4);
v6[v3 - 1] = 0;
}
return v6;
}

canonical_decompiled_code:
char *__fastcall func3(void *src, __int64 a2)
{
char *v2; // rax
signed __int64 v3; // rbx
size_t v4; // r13
char *v5; // rax
char *v6; // r12

v2 = (char *)src;
do
++v2;
while ( *(v2 - 1) && (char *)src + a2 + 1LL - (_QWORD)v2 );
v3 = v2 - (_BYTE *)src;
v4 = v2 - (_BYTE *)src - 1;
v5 = (char *)func2(v2 - (_BYTE *)src);
v6 = v5;
if ( v5 )
{
memcpy(v5, src, v4);
v6[v3 - 1] = 0;
}
return v6;
}

original_code:
char *xxstrndup(const char *s, size_t n) {
    char *r = ((void *)0);
    const char *p = s;
    while(*p++ && n--);
    n = p - s - 1;
    r = (char *) xxmalloc(n + 1);
    if(r != ((void *)0)) {
        memcpy(r, s, n);
        r[n] = 0;
    }
    return r;
}

canonical_original_code:
char *xxstrndup(char *s, unsigned long n) {
    char *r = ((void *)0);
    char *p = s;
    while(*p++ && n--);
    n = p - s - 1;
    r = (char *) xxmalloc(n + 1);
    if(r != ((void *)0)) {
        memcpy(r, s, n);
        r[n] = 0;
    }
    return r;
}

variable_types:
s
char *

variable_types:
n
unsigned long

variable_types:
r
char *

variable_types:
p
char *

return_type: char *


xxfree

decompiled_code:
void __fastcall xxfree(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(void *a1)
{
free(a1);
}

original_code:
inline void xxfree(void *ptr) {
    free(ptr);
}

variable_types:
ptr
void *

return_type: void


xxrealloc

decompiled_code:
void *__fastcall xxrealloc(void *a1, size_t a2)
{
return realloc(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func5(void *a1, size_t a2)
{
return realloc(a1, a2);
}

original_code:
void *xxrealloc(void *ptr, size_t size) {
    return(realloc(ptr, size));
}

canonical_original_code:
void *xxrealloc(void *ptr, unsigned long size) {
    return(realloc(ptr, size));
}

variable_types:
size
unsigned long

return_type: void *


xxcalloc

decompiled_code:
void *__fastcall xxcalloc(size_t a1, size_t a2)
{
return calloc(a1, a2);
}

canonical_decompiled_code:
void *__fastcall func6(size_t a1, size_t a2)
{
return calloc(a1, a2);
}

original_code:
inline void *xxcalloc(size_t nmemb, size_t size) {
    return(calloc(nmemb,size));
}

canonical_original_code:
inline void *xxcalloc(unsigned long nmemb, unsigned long size) {
    return(calloc(nmemb,size));
}

variable_types:
nmemb
unsigned long


xxstrdup

decompiled_code:
char *__fastcall xxstrdup(const char *a1)
{
return strdup(a1);
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
return strdup(a1);
}

original_code:
inline char *xxstrdup(const char *s) {
    return(strdup(s));
}

canonical_original_code:
inline char *xxstrdup(char *s) {
    return(strdup(s));
}


original_code:
struct fsm_trie_handle *fsm_trie_init() {
    struct fsm_trie_handle *th;
    th = xxcalloc(1,sizeof(struct fsm_trie_handle));
    th->trie_hash = xxcalloc(1048573, sizeof(struct trie_hash));
    th->trie_states = xxcalloc(32768, sizeof(struct trie_states));
    th->statesize = 32768;
    th->trie_cursor = 0;
    th->sh_hash = sh_init();
    return(th);
}

variable_types: struct fsm_trie_handle { struct trie_states { _Bool is_final; } *trie_states; unsigned int trie_cursor; struct trie_hash { char *insym; char *outsym; unsigned int sourcestate; unsigned int targetstate; struct trie_hash *next; } *trie_hash; unsigned int used_states; unsigned int statesize; struct sh_handle { struct sh_hashtable { char *string; int value; struct sh_hashtable *next; } *hash; int lastvalue; } *sh_hash; } *

user_defined_types: struct fsm_trie_handle { struct trie_states *trie_states; unsigned int trie_cursor; struct trie_hash *trie_hash; unsigned int used_states; unsigned int statesize; struct sh_handle *sh_hash; }


decompiled_code:
__int64 __fastcall fsm_trie_done(__int64 a1)
{
__int64 v2; // rbp
__int64 i; // r13
__int64 j; // rbx
__int64 v5; // rbx
__int64 v6; // r13
__int64 k; // rbp
__int64 v8; // rbx
__int64 v9; // rdi

v2 = fsm_construct_init("name");
for ( i = 0LL; i != 33554336; i += 32LL )
{
for ( j = *(_QWORD *)(a1 + 16) + i; j; j = *(_QWORD *)(j + 24) )
{
if ( !*(_QWORD *)j )
break;
fsm_construct_add_arc(v2, *(unsigned int *)(j + 16), *(unsigned int *)(j + 20), *(_QWORD *)j, *(_QWORD *)(j + 8));
}
}
v5 = 0LL;
do
{
if ( *(_BYTE *)(*(_QWORD *)a1 + v5) )
fsm_construct_set_final(v2, (unsigned int)v5);
++v5;
}
while ( *(_DWORD *)(a1 + 24) >= (unsigned int)v5 );
fsm_construct_set_initial(v2, 0LL);
v6 = fsm_construct_done(v2);
for ( k = 0LL; k != 33554336; k += 32LL )
{
v8 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + k + 24);
while ( v8 )
{
v9 = v8;
v8 = *(_QWORD *)(v8 + 24);
xxfree(v9);
}
}
sh_done(*(_QWORD *)(a1 + 32));
xxfree(*(_QWORD *)a1);
xxfree(*(_QWORD *)(a1 + 16));
xxfree(a1);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // rbp
__int64 i; // r13
__int64 j; // rbx
__int64 v5; // rbx
__int64 v6; // r13
__int64 k; // rbp
__int64 v8; // rbx
__int64 v9; // rdi

v2 = fsm_construct_init("name");
for ( i = 0LL; i != 33554336; i += 32LL )
{
for ( j = *(_QWORD *)(a1 + 16) + i; j; j = *(_QWORD *)(j + 24) )
{
if ( !*(_QWORD *)j )
break;
fsm_construct_add_arc(v2, *(unsigned int *)(j + 16), *(unsigned int *)(j + 20), *(_QWORD *)j, *(_QWORD *)(j + 8));
}
}
v5 = 0LL;
do
{
if ( *(_BYTE *)(*(_QWORD *)a1 + v5) )
fsm_construct_set_final(v2, (unsigned int)v5);
++v5;
}
while ( *(_DWORD *)(a1 + 24) >= (unsigned int)v5 );
fsm_construct_set_initial(v2, 0LL);
v6 = fsm_construct_done(v2);
for ( k = 0LL; k != 33554336; k += 32LL )
{
v8 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + k + 24);
while ( v8 )
{
v9 = v8;
v8 = *(_QWORD *)(v8 + 24);
xxfree(v9);
}
}
sh_done(*(_QWORD *)(a1 + 32));
xxfree(*(_QWORD *)a1);
xxfree(*(_QWORD *)(a1 + 16));
xxfree(a1);
return v6;
}

original_code:
struct fsm *fsm_trie_done(struct fsm_trie_handle *th) {
    struct trie_hash *thash, *thashp;
    struct fsm *newnet;
    struct fsm_construct_handle *newh;
    int i;
    newh = fsm_construct_init("name");
    for (i=0; i < 1048573; i++) {
 thash = (th->trie_hash)+i;
 for ( ; thash != ((void *)0); thash = thash->next) {
     if (thash->insym != ((void *)0)) {
  fsm_construct_add_arc(newh, thash->sourcestate, thash->targetstate, thash->insym, thash->outsym);
     } else {
  break;
     }
 }
    }
    for (i = 0; i <= th->used_states; i++) {
 if ((th->trie_states+i)->is_final == 1) {
     fsm_construct_set_final(newh, i);
 }
    }
    fsm_construct_set_initial(newh, 0);
    newnet = fsm_construct_done(newh);
    for (i=0; i < 1048573; i++) {
 for (thash=((th->trie_hash)+i)->next; thash != ((void *)0); thash = thashp) {
     thashp = thash->next;
     xxfree(thash);
 }
    }
    sh_done(th->sh_hash);
    xxfree(th->trie_states);
    xxfree(th->trie_hash);
    xxfree(th);
    return(newnet);
}

canonical_original_code:
struct fsm *fsm_trie_done(struct fsm_trie_handle *th) {
    struct trie_hash *thash; struct trie_hash *thashp;
    struct fsm *newnet;
    struct fsm_construct_handle *newh;
    int i;
    newh = fsm_construct_init("name");
    for (i=0; i < 1048573; i++) {
 thash = (th->trie_hash)+i;
 for ( ; thash != ((void *)0); thash = thash->next) {
     if (thash->insym != ((void *)0)) {
  fsm_construct_add_arc(newh, thash->sourcestate, thash->targetstate, thash->insym, thash->outsym);
     } else {
  break;
     }
 }
    }
    for (i = 0; i <= th->used_states; i++) {
 if ((th->trie_states+i)->is_final == 1) {
     fsm_construct_set_final(newh, i);
 }
    }
    fsm_construct_set_initial(newh, 0);
    newnet = fsm_construct_done(newh);
    for (i=0; i < 1048573; i++) {
 for (thash=((th->trie_hash)+i)->next; thash != ((void *)0); thash = thashp) {
     thashp = thash->next;
     xxfree(thash);
 }
    }
    sh_done(th->sh_hash);
    xxfree(th->trie_states);
    xxfree(th->trie_hash);
    xxfree(th);
    return(newnet);
}

variable_types: struct trie_hash { char *insym; char *outsym; unsigned int sourcestate; unsigned int targetstate; struct trie_hash *next; } *

variable_types: struct fsm_construct_handle { struct fsm_state_list { _Bool used; _Bool is_final; _Bool is_initial; short num_trans; int state_number; struct fsm_trans_list { short in; short out; int target; struct fsm_trans_list *next; } *fsm_trans_list; } *fsm_state_list; int fsm_state_list_size; struct fsm_sigma_list { char *symbol; } *fsm_sigma_list; int fsm_sigma_list_size; struct fsm_sigma_hash { char *symbol; short sym; struct fsm_sigma_hash *next; } *fsm_sigma_hash; int fsm_sigma_hash_size; int maxstate; int maxsigma; int numfinals; char *name; } *

return_type: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *

user_defined_types: struct fsm_construct_handle { struct fsm_state_list *fsm_state_list; int fsm_state_list_size; struct fsm_sigma_list *fsm_sigma_list; int fsm_sigma_list_size; struct fsm_sigma_hash *fsm_sigma_hash; int fsm_sigma_hash_size; int maxstate; int maxsigma; int numfinals; char *name; }

user_defined_types: struct fsm_state_list { _Bool used; _Bool is_final; _Bool is_initial; short num_trans; int state_number; struct fsm_trans_list *fsm_trans_list; }

user_defined_types: struct sh_hashtable { char *string; int value; struct sh_hashtable *next; }


decompiled_code:
void fsm_trie_new_word()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void fsm_trie_new_word(struct fsm_trie_handle *th) {
}

user_defined_types: struct trie_hash { char *insym; char *outsym; unsigned int sourcestate; unsigned int targetstate; struct trie_hash *next; }


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

result = *(unsigned int *)(a1 + 8);
*(_BYTE *)(*(_QWORD *)a1 + result) = 1;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

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

result = *(unsigned int *)(a1 + 8);
*(_BYTE *)(*(_QWORD *)a1 + result) = 1;
*(_DWORD *)(a1 + 8) = 0;
return result;
}

original_code:
void fsm_trie_end_word(struct fsm_trie_handle *th) {
    (th->trie_states+th->trie_cursor)->is_final = 1;
    th->trie_cursor = 0;
}


original_code:
unsigned int trie_hashf(unsigned int source, char *insym, char *outsym) {
    register unsigned int hash;
    hash = 0;
    while (*insym != '\0') {
        hash = hash * 101 + *insym++;
    }
    while (*outsym != '\0') {
        hash = hash * 101 + *outsym++;
    }
    hash = hash * 101 + source;
    return (hash % 1048573);
}

variable_types:
source
unsigned int

variable_types:
insym
char *

variable_types:
outsym
char *

variable_types:
hash
unsigned int


decompiled_code:
__int64 __fastcall fsm_trie_add_word(__int64 a1, const char *a2)
{
const char *v2; // rbx
char *v3; // rbp
int v4; // eax
int v5; // er14
int v6; // er12
int v7; // eax

v2 = a2;
v3 = (char *)xxstrdup(a2);
v4 = strlen(v3);
if ( *a2 )
{
v5 = v4;
if ( v4 > 0 )
{
v6 = 0;
do
{
v7 = utf8skip(v2);
strncpy(v3, v2, v7 + 1);
v3[(int)utf8skip(v2) + 1] = 0;
fsm_trie_symbol(a1, v3, v3);
v2 += (int)utf8skip(v2) + 1;
++v6;
}
while ( *v2 && v5 > v6 );
}
}
xxfree(v3);
return fsm_trie_end_word(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
const char *v2; // rbx
char *v3; // rbp
int v4; // eax
int v5; // er14
int v6; // er12
int v7; // eax

v2 = a2;
v3 = (char *)xxstrdup(a2);
v4 = strlen(v3);
if ( *a2 )
{
v5 = v4;
if ( v4 > 0 )
{
v6 = 0;
do
{
v7 = utf8skip(v2);
strncpy(v3, v2, v7 + 1);
v3[(int)utf8skip(v2) + 1] = 0;
func5(a1, v3, v3);
v2 += (int)utf8skip(v2) + 1;
++v6;
}
while ( *v2 && v5 > v6 );
}
}
xxfree(v3);
return func3(a1);
}

original_code:
void fsm_trie_add_word(struct fsm_trie_handle *th, char *word) {
    int i, len;
    char *wcopy;
    wcopy = xxstrdup(word);
    len = strlen(wcopy);
    for (i=0 ; *word != '\0' && i < len; word = word + utf8skip(word)+1, i++) {
 strncpy(wcopy, word, utf8skip(word)+1);
 *(wcopy+utf8skip(word)+1) = '\0';
 fsm_trie_symbol(th, wcopy, wcopy);
    }
    xxfree(wcopy);
    fsm_trie_end_word(th);
}

canonical_original_code:
void fsm_trie_add_word(struct fsm_trie_handle *th, char *word) {
    int i; int len;
    char *wcopy;
    wcopy = xxstrdup(word);
    len = strlen(wcopy);
    for (i=0 ; *word != '\0' && i < len; word = word + utf8skip(word)+1, i++) {
 strncpy(wcopy, word, utf8skip(word)+1);
 *(wcopy+utf8skip(word)+1) = '\0';
 fsm_trie_symbol(th, wcopy, wcopy);
    }
    xxfree(wcopy);
    fsm_trie_end_word(th);
}

variable_types:
word
char *

variable_types: i int

variable_types: len int

variable_types:
wcopy
char *


decompiled_code:
int server_init()
{
int v0; // eax
int v1; // ebx
unsigned int v2; // ebp
char *v3; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 0x40000;
v0 = socket(2, 2, 17);
listen_sd = v0;
if ( v0 == -1 )
{
perror("socket() failed");
exit(1);
}
v1 = v0;
if ( setsockopt(v0, 1, 8, optval, 4u) < 0 )
{
perror("setsockopt() failed");
exit(1);
}
if ( setsockopt(v1, 1, 7, optval, 4u) < 0 )
{
perror("setsockopt() failed");
exit(1);
}
*(_QWORD *)&serveraddr.sa_family = 2LL;
*(_QWORD *)&serveraddr.sa_data[6] = 0LL;
v2 = port_number;
*(_WORD *)serveraddr.sa_data = _bswap_16(port_number);
if ( server_address )
*(_DWORD *)&serveraddr.sa_data[2] = inet_addr(server_address);
if ( bind(v1, &serveraddr, 0x10u) == -1 )
{
perror("bind() failed");
exit(1);
}
v3 = inet_ntoa(*(struct in_addr *)&serveraddr.sa_data[2]);
printf("Started flookup server on %s port %i\n", v3, v2);
return fflush(stdout);
}

canonical_decompiled_code:
int func1()
{
int v0; // eax
int v1; // ebx
unsigned int v2; // ebp
char *v3; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 0x40000;
v0 = socket(2, 2, 17);
listen_sd = v0;
if ( v0 == -1 )
{
perror("socket() failed");
exit(1);
}
v1 = v0;
if ( setsockopt(v0, 1, 8, optval, 4u) < 0 )
{
perror("setsockopt() failed");
exit(1);
}
if ( setsockopt(v1, 1, 7, optval, 4u) < 0 )
{
perror("setsockopt() failed");
exit(1);
}
*(_QWORD *)&serveraddr.sa_family = 2LL;
*(_QWORD *)&serveraddr.sa_data[6] = 0LL;
v2 = port_number;
*(_WORD *)serveraddr.sa_data = func0(port_number);
if ( server_address )
*(_DWORD *)&serveraddr.sa_data[2] = inet_addr(server_address);
if ( bind(v1, &serveraddr, 0x10u) == -1 )
{
perror("bind() failed");
exit(1);
}
v3 = inet_ntoa(*(struct in_addr *)&serveraddr.sa_data[2]);
printf("Started flookup server on %s port %i\n", v3, v2);
return fflush(stdout);
}

original_code:
void server_init(void) {
    unsigned int rcvsize = 262144;
    if ((listen_sd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
 perror("socket() failed");
 exit(1);
    }
    if (setsockopt(listen_sd, 1, 8, (char *) &rcvsize, sizeof(rcvsize)) < 0) {
     perror("setsockopt() failed");
     exit(1);
    }
    if (setsockopt(listen_sd, 1, 7, (char *) &rcvsize, sizeof(rcvsize)) < 0) {
     perror("setsockopt() failed");
     exit(1);
    }
    memset((char *) &serveraddr, 0, sizeof(serveraddr));
    serveraddr.sin_family = 2;
    serveraddr.sin_port = htons(port_number);
    if (server_address != ((void *)0)) {
 serveraddr.sin_addr.s_addr = inet_addr(server_address);
    } else {
 serveraddr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    }
    if (bind(listen_sd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) == -1) {
 perror("bind() failed");
 exit(1);
    }
    printf("Started flookup server on %s port %i\n", inet_ntoa(serveraddr.sin_addr), port_number); fflush(stdout);
}

canonical_original_code:
void server_init() {
    unsigned int rcvsize = 262144;
    if ((listen_sd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
 perror("socket() failed");
 exit(1);
    }
    if (setsockopt(listen_sd, 1, 8, (char *) &rcvsize, sizeof(rcvsize)) < 0) {
     perror("setsockopt() failed");
     exit(1);
    }
    if (setsockopt(listen_sd, 1, 7, (char *) &rcvsize, sizeof(rcvsize)) < 0) {
     perror("setsockopt() failed");
     exit(1);
    }
    memset((char *) &serveraddr, 0, sizeof(serveraddr));
    serveraddr.sin_family = 2;
    serveraddr.sin_port = htons(port_number);
    if (server_address != ((void *)0)) {
 serveraddr.sin_addr.s_addr = inet_addr(server_address);
    } else {
 serveraddr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    }
    if (bind(listen_sd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) == -1) {
 perror("bind() failed");
 exit(1);
    }
    printf("Started flookup server on %s port %i\n", inet_ntoa(serveraddr.sin_addr), port_number); fflush(stdout);
}

variable_types:
rcvsize
unsigned int

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


decompiled_code:
char *get_next_line()
{
char *v0; // rbx
char *v1; // rbp

v0 = fgets(line, 0x40000, INFILE);
if ( v0 )
{
v1 = line;
v1[strcspn(line, "\n\r")] = 0;
}
return v0;
}

canonical_decompiled_code:
char *func4()
{
char *v0; // rbx
char *v1; // rbp

v0 = fgets(line, 0x40000, INFILE);
if ( v0 )
{
v1 = line;
v1[strcspn(line, "\n\r")] = 0;
}
return v0;
}

original_code:
char *get_next_line() {
    char *r;
    if ((r = fgets(line, 262144, INFILE)) != ((void *)0)) {
 line[strcspn(line, "\n\r")] = '\0';
    }
    return r;
}

variable_types:
r
char *


decompiled_code:
__int64 __fastcall find_defined(char *s1)
{
__int64 v1; // rbx

v1 = defines;
if ( defines )
{
while ( strcmp(s1, *(const char **)v1) )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 8);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
__int64 v1; // rbx

v1 = defines;
if ( defines )
{
while ( strcmp(s1, *(const char **)v1) )
{
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
return v1;
}
v1 = *(_QWORD *)(v1 + 8);
}
return v1;
}

original_code:
struct fsm *find_defined (char *string) {
  struct defined *defined;
  for (defined = defines; defined != ((void *)0); defined = defined->next) {
    if (strcmp(string, defined->name) == 0) {
      return(defined->net);
    }
  }
  return ((void *)0);
}

canonical_original_code:
struct fsm *find_defined(char *string) {
  struct defined *defined;
  for (defined = defines; defined != ((void *)0); defined = defined->next) {
    if (strcmp(string, defined->name) == 0) {
      return(defined->net);
    }
  }
  return ((void *)0);
}

variable_types:
string
char *

variable_types: struct defined { char *name; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *net; struct defined *next; } *

user_defined_types: struct defined { char *name; struct fsm *net; struct defined *next; }

user_defined_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state *states; struct sigma *sigma; struct medlookup *medlookup; }


decompiled_code:
__int64 get_defines()
{
return defines;
}

canonical_decompiled_code:
__int64 func1()
{
return defines;
}

original_code:
struct defined *get_defines() {
    return(defines);
}

return_type: struct defined { char *name; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *net; struct defined *next; } *


decompiled_code:
__int64 get_defines_f()
{
return defines_f;
}

canonical_decompiled_code:
__int64 func2()
{
return defines_f;
}

original_code:
struct definedf *get_defines_f() {
    return(defines_f);
}

return_type: struct definedf { char *name; char *regex; int numargs; struct definedf *next; } *


decompiled_code:
__int64 __fastcall remove_defined(char *s2)
{
_QWORD *v1; // rbx
_QWORD *v2; // r13
__int64 i; // rbx
_QWORD *v4; // rbp
__int64 v5; // rbx
unsigned int v6; // ebp
_QWORD *v7; // rbp
__int64 v8; // rdi

if ( s2 )
{
v1 = (_QWORD *)defines;
if ( defines )
{
v2 = 0LL;
while ( 1 )
{
v6 = strcmp((const char *)*v1, s2);
if ( !v6 )
break;
v2 = v1;
if ( !v1[2] )
return 1;
v1 = (_QWORD *)v1[2];
}
if ( v2 )
v2[2] = v1[2];
else
defines = v1[2];
fsm_destroy(v1[1]);
xxfree(*v1);
xxfree(v1);
}
else
{
v6 = 1;
}
}
else
{
for ( i = defines; i; defines = 0LL )
{
fsm_destroy(*(_QWORD *)(i + 8));
v4 = (_QWORD *)i;
i = *(_QWORD *)(i + 16);
xxfree(*v4);
xxfree(v4);
}
v5 = defines_f;
if ( defines_f )
{
do
{
v7 = (_QWORD *)v5;
v5 = *(_QWORD *)(v5 + 24);
if ( *v7 )
xxfree(*v7);
v8 = v7[1];
if ( v8 )
xxfree(v8);
xxfree(v7);
}
while ( v5 );
v6 = 0;
}
else
{
v6 = 0;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
_QWORD *v1; // rbx
_QWORD *v2; // r13
__int64 i; // rbx
_QWORD *v4; // rbp
__int64 v5; // rbx
unsigned int v6; // ebp
_QWORD *v7; // rbp
__int64 v8; // rdi

if ( s2 )
{
v1 = (_QWORD *)defines;
if ( defines )
{
v2 = 0LL;
while ( 1 )
{
v6 = strcmp((const char *)*v1, s2);
if ( !v6 )
break;
v2 = v1;
if ( !v1[2] )
return 1;
v1 = (_QWORD *)v1[2];
}
if ( v2 )
v2[2] = v1[2];
else
defines = v1[2];
fsm_destroy(v1[1]);
xxfree(*v1);
xxfree(v1);
}
else
{
v6 = 1;
}
}
else
{
for ( i = defines; i; defines = 0LL )
{
fsm_destroy(*(_QWORD *)(i + 8));
v4 = (_QWORD *)i;
i = *(_QWORD *)(i + 16);
xxfree(*v4);
xxfree(v4);
}
v5 = defines_f;
if ( defines_f )
{
do
{
v7 = (_QWORD *)v5;
v5 = *(_QWORD *)(v5 + 24);
if ( *v7 )
xxfree(*v7);
v8 = v7[1];
if ( v8 )
xxfree(v8);
xxfree(v7);
}
while ( v5 );
v6 = 0;
}
else
{
v6 = 0;
}
}
return v6;
}

original_code:
int remove_defined (char *string) {
  struct defined *defined, *defined_prev;
  struct definedf *df, *dfprev;
  int exists = 0;
  defined_prev = ((void *)0);
  if (string == ((void *)0)) {
      for (defined = defines; defined != ((void *)0); ) {
          fsm_destroy(defined->net);
          defined_prev = defined;
          defined = defined->next;
   xxfree(defined_prev->name);
          xxfree(defined_prev);
          defines = ((void *)0);
      }
      for (df = defines_f; df != ((void *)0); df = dfprev) {
   dfprev = df->next;
   if (df->name != ((void *)0))
       xxfree(df->name);
   if (df->regex != ((void *)0))
       xxfree(df->regex);
   xxfree(df);
      }
     return(0);
  }
  for (defined = defines; defined != ((void *)0); defined = defined->next) {
      if (strcmp(defined->name, string) == 0) {
          exists = 1;
          break;
      }
      defined_prev = defined;
  }
  if (exists == 0) {
      return 1;
  }
  if (defined_prev != ((void *)0)) {
      defined_prev->next = defined->next;
  } else {
      defines = defined->next;
  }
  fsm_destroy(defined->net);
  xxfree(defined->name);
  xxfree(defined);
  return(0);
}

canonical_original_code:
int remove_defined(char *string) {
  struct defined *defined; struct defined *defined_prev;
  struct definedf *df; struct definedf *dfprev;
  int exists = 0;
  defined_prev = ((void *)0);
  if (string == ((void *)0)) {
      for (defined = defines; defined != ((void *)0); ) {
          fsm_destroy(defined->net);
          defined_prev = defined;
          defined = defined->next;
   xxfree(defined_prev->name);
          xxfree(defined_prev);
          defines = ((void *)0);
      }
      for (df = defines_f; df != ((void *)0); df = dfprev) {
   dfprev = df->next;
   if (df->name != ((void *)0))
       xxfree(df->name);
   if (df->regex != ((void *)0))
       xxfree(df->regex);
   xxfree(df);
      }
     return(0);
  }
  for (defined = defines; defined != ((void *)0); defined = defined->next) {
      if (strcmp(defined->name, string) == 0) {
          exists = 1;
          break;
      }
      defined_prev = defined;
  }
  if (exists == 0) {
      return 1;
  }
  if (defined_prev != ((void *)0)) {
      defined_prev->next = defined->next;
  } else {
      defines = defined->next;
  }
  fsm_destroy(defined->net);
  xxfree(defined->name);
  xxfree(defined);
  return(0);
}

variable_types: struct definedf { char *name; char *regex; int numargs; struct definedf *next; } *

variable_types: exists int

user_defined_types: struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; }

user_defined_types: struct sigma { int number; char *symbol; struct sigma *next; }

user_defined_types: struct medlookup { int *confusion_matrix; }


decompiled_code:
__int64 __fastcall find_defined_function(char *s2, int a2)
{
__int64 v2; // rbx

v2 = defines_f;
if ( defines_f )
{
while ( strcmp(*(const char **)v2, s2) || *(_DWORD *)(v2 + 16) != a2 )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2, int a2)
{
__int64 v2; // rbx

v2 = defines_f;
if ( defines_f )
{
while ( strcmp(*(const char **)v2, s2) || *(_DWORD *)(v2 + 16) != a2 )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
char *find_defined_function(char *name, int numargs) {
    struct definedf *df;
    for (df = defines_f ; df != ((void *)0); df = df->next) {
        if (strcmp(df->name, name) == 0 && df->numargs == numargs) {
            return(df->regex);
        }
    }
    return(((void *)0));
}

variable_types:
name
char *

variable_types: numargs int

user_defined_types: struct definedf { char *name; char *regex; int numargs; struct definedf *next; }


decompiled_code:
__int64 __fastcall add_defined_function(char *s2, __int64 a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rbx

if ( find_defined_function(s2, a3) )
{
v4 = defines_f;
if ( defines_f )
{
while ( strcmp(*(const char **)v4, s2) || *(_DWORD *)(v4 + 16) != a3 )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return 1LL;
}
xxfree(*(_QWORD *)(v4 + 8));
*(_QWORD *)(v4 + 8) = xxstrdup(a2);
printf("redefined %s@%i)\n", s2, a3);
}
}
else
{
v5 = xxmalloc(32LL);
*(_QWORD *)v5 = xxstrdup(s2);
*(_QWORD *)(v5 + 8) = xxstrdup(a2);
*(_DWORD *)(v5 + 16) = a3;
*(_QWORD *)(v5 + 24) = defines_f;
defines_f = v5;
printf("defined %s@%i)\n", s2, a3);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2, __int64 a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rbx

if ( func4(s2, a3) )
{
v4 = defines_f;
if ( defines_f )
{
while ( strcmp(*(const char **)v4, s2) || *(_DWORD *)(v4 + 16) != a3 )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return 1LL;
}
xxfree(*(_QWORD *)(v4 + 8));
*(_QWORD *)(v4 + 8) = xxstrdup(a2);
printf("redefined %s@%i)\n", s2, a3);
}
}
else
{
v5 = xxmalloc(32LL);
*(_QWORD *)v5 = xxstrdup(s2);
*(_QWORD *)(v5 + 8) = xxstrdup(a2);
*(_DWORD *)(v5 + 16) = a3;
*(_QWORD *)(v5 + 24) = defines_f;
defines_f = v5;
printf("defined %s@%i)\n", s2, a3);
}
return 1LL;
}

original_code:
int add_defined_function(char *name, char *regex, int numargs) {
    struct definedf *df;
    if (find_defined_function(name, numargs) == ((void *)0)) {
        df = xxmalloc(sizeof(struct definedf));
        df->name = xxstrdup(name);
        df->regex = xxstrdup(regex);
        df->numargs = numargs;
        df->next = defines_f;
        defines_f = df;
        printf("defined %s@%i)\n", name, numargs);
    } else {
        for (df = defines_f; df != ((void *)0); df = df->next) {
            if (strcmp(df->name, name) == 0 && df->numargs == numargs) {
  xxfree(df->regex);
                df->regex = xxstrdup(regex);
                printf("redefined %s@%i)\n", name, numargs);
                break;
            }
        }
    }
    return 1;
}

variable_types:
regex
char *


decompiled_code:
__int64 __fastcall add_defined(__int64 a1, const char *a2)
{
unsigned int v2; // er13
_QWORD *v3; // rbx
__int64 v4; // rax

v2 = 0;
if ( a1 )
{
fsm_count();
v3 = (_QWORD *)defines;
if ( defines )
{
while ( strcmp((const char *)*v3, a2) )
{
if ( !v3[2] )
{
v4 = xxmalloc(24LL);
v3[2] = v4;
*(_QWORD *)(v4 + 16) = 0LL;
v3 = (_QWORD *)v4;
v2 = 0;
goto LABEL_9;
}
v3 = (_QWORD *)v3[2];
}
fsm_destroy(v3[1]);
xxfree(*v3);
v2 = 1;
}
else
{
v3 = (_QWORD *)xxmalloc(24LL);
defines = (__int64)v3;
v3[2] = 0LL;
}
LABEL_9:
*v3 = xxstrdup(a2);
v3[1] = a1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
unsigned int v2; // er13
_QWORD *v3; // rbx
__int64 v4; // rax

v2 = 0;
if ( a1 )
{
fsm_count();
v3 = (_QWORD *)defines;
if ( defines )
{
while ( strcmp((const char *)*v3, a2) )
{
if ( !v3[2] )
{
v4 = xxmalloc(24LL);
v3[2] = v4;
*(_QWORD *)(v4 + 16) = 0LL;
v3 = (_QWORD *)v4;
v2 = 0;
goto LABEL_9;
}
v3 = (_QWORD *)v3[2];
}
fsm_destroy(v3[1]);
xxfree(*v3);
v2 = 1;
}
else
{
v3 = (_QWORD *)xxmalloc(24LL);
defines = (__int64)v3;
v3[2] = 0LL;
}
LABEL_9:
*v3 = xxstrdup(a2);
v3[1] = a1;
}
return v2;
}

original_code:
int add_defined (struct fsm *net, char *string) {
  struct defined *defined, *defined_prev;
  int redefine;
  redefine = 0;
  if (net == ((void *)0)) { return 0; }
  fsm_count(net);
  if (defines == ((void *)0)) {
    defined = xxmalloc(sizeof(struct defined));
    defines = defined;
    defined->next = ((void *)0);
  } else {
    for (defined = defines; defined != ((void *)0); defined = defined->next) {
      defined_prev = defined;
      if (strcmp(defined->name, string) == 0) {
 redefine = 1;
 break;
      }
    }
    if (redefine == 0) {
      defined_prev->next = xxmalloc(sizeof(struct defined));
      defined = defined_prev->next;
      defined->next = ((void *)0);
    }
  }
  if (redefine) {
      fsm_destroy(defined->net);
      xxfree(defined->name);
  }
  defined->name = xxstrdup(string);
  defined->net = net;
  return(redefine);
}

canonical_original_code:
int add_defined(struct fsm *net, char *string) {
  struct defined *defined; struct defined *defined_prev;
  int redefine;
  redefine = 0;
  if (net == ((void *)0)) { return 0; }
  fsm_count(net);
  if (defines == ((void *)0)) {
    defined = xxmalloc(sizeof(struct defined));
    defines = defined;
    defined->next = ((void *)0);
  } else {
    for (defined = defines; defined != ((void *)0); defined = defined->next) {
      defined_prev = defined;
      if (strcmp(defined->name, string) == 0) {
 redefine = 1;
 break;
      }
    }
    if (redefine == 0) {
      defined_prev->next = xxmalloc(sizeof(struct defined));
      defined = defined_prev->next;
      defined->next = ((void *)0);
    }
  }
  if (redefine) {
      fsm_destroy(defined->net);
      xxfree(defined->name);
  }
  defined->name = xxstrdup(string);
  defined->net = net;
  return(redefine);
}

variable_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *

variable_types: redefine int


original_code:
struct fsm *fsm_coaccessible(struct fsm *net) {
    struct invtable *inverses, *temp_i, *temp_i_prev, *current_ptr;
  int i, j, s, t, *coacc, current_state, markcount, *mapping, terminate, new_linecount, new_arccount, *added, old_statecount;
  struct fsm_state *fsm;
  fsm = net->states;
  new_arccount = 0;
  old_statecount = net->statecount;
  inverses = xxcalloc(net->statecount, sizeof(struct invtable));
  coacc = xxmalloc(sizeof(int)*(net->statecount));
  mapping = xxmalloc(sizeof(int)*(net->statecount));
  added = xxmalloc(sizeof(int)*(net->statecount));
  for (i=0; i < (net->statecount); i++) {
    (inverses+i)->state = -1;
    *(coacc+i) = 0;
    *(added+i) = 0;
  }
  for (i=0; (fsm+i)->state_no != -1; i++) {
    s = (fsm+i)->state_no;
    t = (fsm+i)->target;
    if (t != -1 && s != t) {
      if (((inverses+t)->state) == -1) {
 (inverses+t)->state = s;
      } else {
        temp_i = xxmalloc(sizeof(struct invtable));
 temp_i->next = (inverses+t)->next;
 (inverses+t)->next = temp_i;
 temp_i->state = s;
      }
    }
  }
  markcount = 0;
  for (i=0; (fsm+i)->state_no != -1; i++) {
    if ((fsm+i)->final_state && (!*(coacc+((fsm+i)->state_no)))) {
      int_stack_push((fsm+i)->state_no);
      *(coacc+(fsm+i)->state_no) = 1;
      markcount++;
    }
  }
  terminate = 0;
  while(!int_stack_isempty()) {
    current_state = int_stack_pop();
    current_ptr = inverses+current_state;
    while(current_ptr != ((void *)0) && current_ptr->state != -1) {
      if (!*(coacc+(current_ptr->state))) {
 *(coacc+(current_ptr->state)) = 1;
 int_stack_push(current_ptr->state);
 markcount++;
      }
      current_ptr = current_ptr->next;
    }
    if (markcount >= net->statecount) {
      terminate = 1;
      int_stack_clear();
      break;
    }
  }
  if (terminate == 0) {
    *mapping = 0;
    new_linecount = 0;
    for (i=1,j=0; i < (net->statecount);i++) {
      if (*(coacc+i) == 1) {
 j++;
 *(mapping+i) = j;
      }
    }
    for (i=0,j=0; (fsm+i)->state_no != -1; i++) {
      if (i > 0 && (fsm+i)->state_no != (fsm+i-1)->state_no && (fsm+i-1)->final_state && !*(added+((fsm+i-1)->state_no))) {
 add_fsm_arc(fsm, j++, *(mapping+((fsm+i-1)->state_no)), -1, -1, -1, 1, (fsm+i-1)->start_state);
 new_linecount++;
 *(added+((fsm+i-1)->state_no)) = 1;
      }
      if (*(coacc+((fsm+i)->state_no)) && (((fsm+i)->target == -1) || *(coacc+((fsm+i)->target)))) {
 (fsm+j)->state_no = *(mapping+((fsm+i)->state_no));
 if ((fsm+i)->target == -1) {
   (fsm+j)->target = -1;
 } else {
   (fsm+j)->target = *(mapping+((fsm+i)->target));
 }
 (fsm+j)->final_state = (fsm+i)->final_state;
 (fsm+j)->start_state = (fsm+i)->start_state;
 (fsm+j)->in = (fsm+i)->in;
 (fsm+j)->out = (fsm+i)->out;
 j++;
 new_linecount++;
 *(added+(fsm+i)->state_no) = 1;
 if ((fsm+i)->target != -1) {
   new_arccount++;
 }
      }
    }
    if ((i > 1) && ((fsm+i-1)->final_state) && *(added+((fsm+i-1)->state_no)) == 0) {
      add_fsm_arc(fsm, j++, *(mapping+((fsm+i-1)->state_no)), -1, -1, -1, 1, (fsm+i-1)->start_state);
      new_linecount++;
    }
    if (new_linecount == 0) {
      add_fsm_arc(fsm, j++, 0, -1, -1, -1, -1, -1);
    }
    add_fsm_arc(fsm, j, -1, -1, -1, -1, -1, -1);
    if (markcount == 0) {
      xxfree(fsm);
      net->states = fsm_empty();
      fsm_sigma_destroy(net->sigma);
      net->sigma = sigma_create();
    }
    net->linecount = new_linecount;
    net->arccount = new_arccount;
    net->statecount = markcount;
  }
  for (i = 0; i < old_statecount ; i++) {
      for (temp_i = inverses+i; temp_i != ((void *)0) ; ) {
          temp_i_prev = temp_i;
          temp_i = temp_i->next;
          if (temp_i_prev != inverses+i)
              xxfree(temp_i_prev);
      }
  }
  xxfree(inverses);
  xxfree(coacc);
  xxfree(added);
  xxfree(mapping);
  net->is_pruned = 1;
  return(net);
}

canonical_original_code:
struct fsm *fsm_coaccessible(struct fsm *net) {
    struct invtable *inverses; struct invtable *temp_i; struct invtable *temp_i_prev; struct invtable *current_ptr;
  int i; int j; int s; int t; int *coacc; int current_state; int markcount; int *mapping; int terminate; int new_linecount; int new_arccount; int *added; int old_statecount;
  struct fsm_state *fsm;
  fsm = net->states;
  new_arccount = 0;
  old_statecount = net->statecount;
  inverses = xxcalloc(net->statecount, sizeof(struct invtable));
  coacc = xxmalloc(sizeof(int)*(net->statecount));
  mapping = xxmalloc(sizeof(int)*(net->statecount));
  added = xxmalloc(sizeof(int)*(net->statecount));
  for (i=0; i < (net->statecount); i++) {
    (inverses+i)->state = -1;
    *(coacc+i) = 0;
    *(added+i) = 0;
  }
  for (i=0; (fsm+i)->state_no != -1; i++) {
    s = (fsm+i)->state_no;
    t = (fsm+i)->target;
    if (t != -1 && s != t) {
      if (((inverses+t)->state) == -1) {
 (inverses+t)->state = s;
      } else {
        temp_i = xxmalloc(sizeof(struct invtable));
 temp_i->next = (inverses+t)->next;
 (inverses+t)->next = temp_i;
 temp_i->state = s;
      }
    }
  }
  markcount = 0;
  for (i=0; (fsm+i)->state_no != -1; i++) {
    if ((fsm+i)->final_state && (!*(coacc+((fsm+i)->state_no)))) {
      int_stack_push((fsm+i)->state_no);
      *(coacc+(fsm+i)->state_no) = 1;
      markcount++;
    }
  }
  terminate = 0;
  while(!int_stack_isempty()) {
    current_state = int_stack_pop();
    current_ptr = inverses+current_state;
    while(current_ptr != ((void *)0) && current_ptr->state != -1) {
      if (!*(coacc+(current_ptr->state))) {
 *(coacc+(current_ptr->state)) = 1;
 int_stack_push(current_ptr->state);
 markcount++;
      }
      current_ptr = current_ptr->next;
    }
    if (markcount >= net->statecount) {
      terminate = 1;
      int_stack_clear();
      break;
    }
  }
  if (terminate == 0) {
    *mapping = 0;
    new_linecount = 0;
    for (i=1,j=0; i < (net->statecount);i++) {
      if (*(coacc+i) == 1) {
 j++;
 *(mapping+i) = j;
      }
    }
    for (i=0,j=0; (fsm+i)->state_no != -1; i++) {
      if (i > 0 && (fsm+i)->state_no != (fsm+i-1)->state_no && (fsm+i-1)->final_state && !*(added+((fsm+i-1)->state_no))) {
 add_fsm_arc(fsm, j++, *(mapping+((fsm+i-1)->state_no)), -1, -1, -1, 1, (fsm+i-1)->start_state);
 new_linecount++;
 *(added+((fsm+i-1)->state_no)) = 1;
      }
      if (*(coacc+((fsm+i)->state_no)) && (((fsm+i)->target == -1) || *(coacc+((fsm+i)->target)))) {
 (fsm+j)->state_no = *(mapping+((fsm+i)->state_no));
 if ((fsm+i)->target == -1) {
   (fsm+j)->target = -1;
 } else {
   (fsm+j)->target = *(mapping+((fsm+i)->target));
 }
 (fsm+j)->final_state = (fsm+i)->final_state;
 (fsm+j)->start_state = (fsm+i)->start_state;
 (fsm+j)->in = (fsm+i)->in;
 (fsm+j)->out = (fsm+i)->out;
 j++;
 new_linecount++;
 *(added+(fsm+i)->state_no) = 1;
 if ((fsm+i)->target != -1) {
   new_arccount++;
 }
      }
    }
    if ((i > 1) && ((fsm+i-1)->final_state) && *(added+((fsm+i-1)->state_no)) == 0) {
      add_fsm_arc(fsm, j++, *(mapping+((fsm+i-1)->state_no)), -1, -1, -1, 1, (fsm+i-1)->start_state);
      new_linecount++;
    }
    if (new_linecount == 0) {
      add_fsm_arc(fsm, j++, 0, -1, -1, -1, -1, -1);
    }
    add_fsm_arc(fsm, j, -1, -1, -1, -1, -1, -1);
    if (markcount == 0) {
      xxfree(fsm);
      net->states = fsm_empty();
      fsm_sigma_destroy(net->sigma);
      net->sigma = sigma_create();
    }
    net->linecount = new_linecount;
    net->arccount = new_arccount;
    net->statecount = markcount;
  }
  for (i = 0; i < old_statecount ; i++) {
      for (temp_i = inverses+i; temp_i != ((void *)0) ; ) {
          temp_i_prev = temp_i;
          temp_i = temp_i->next;
          if (temp_i_prev != inverses+i)
              xxfree(temp_i_prev);
      }
  }
  xxfree(inverses);
  xxfree(coacc);
  xxfree(added);
  xxfree(mapping);
  net->is_pruned = 1;
  return(net);
}

variable_types:
net
struct fsm *

variable_types: struct invtable { int state; struct invtable *next; } *

variable_types: j int

variable_types: s int

variable_types: t int

variable_types:
coacc
int *

variable_types: markcount int

variable_types:
mapping
int *

variable_types: terminate int

variable_types:
added
int *

variable_types: struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *


original_code:
struct fsm *fsm_topsort (struct fsm *net) {
    int i, j, curr_state, *statemap, treatcount, *order, lc, *newnum, newtarget, newstate;
    unsigned short int *invcount;
    unsigned char *treated, overflow;
    long long grand_pathcount, *pathcount;
    struct fsm_state *fsm, *curr_fsm, *new_fsm;
    fsm_count(net);
    fsm = net->states;
    statemap = xxmalloc(sizeof(int)*net->statecount);
    order = xxmalloc(sizeof(int)*net->statecount);
    pathcount = xxmalloc(sizeof(long long)*net->statecount);
    newnum = xxmalloc(sizeof(int)*net->statecount);
    invcount = xxmalloc(sizeof(unsigned short int)*net->statecount);
    treated = xxmalloc(sizeof(unsigned char)*net->statecount);
    for (i=0; i < net->statecount; i++) {
 *(statemap+i) = -1;
 *(invcount+i) = 0;
 *(treated+i) = 0;
 *(order+i) = 0;
 *(pathcount+i) = 0;
    }
    for (i=0, lc=0; (fsm+i)->state_no != -1; i++) {
        lc++;
        if ((fsm+i)->target != -1) {
            (*(invcount+(fsm+i)->target))++;
            if ((fsm+i)->state_no == (fsm+i)->target) {
                net->pathcount = -1;
                net->is_loop_free = 0;
                goto cyclic;
            }
        }
 if (*(statemap+(fsm+i)->state_no) == -1) {
     *(statemap+(fsm+i)->state_no) = i;
 }
    }
    treatcount = net->statecount;
    int_stack_clear();
    int_stack_push(0);
    grand_pathcount = 0;
    *(pathcount+0) = 1;
    overflow = 0;
    for (i=0 ; !int_stack_isempty(); i++) {
        curr_state = int_stack_pop();
        *(treated+curr_state) = 1;
        *(order+i) = curr_state;
        *(newnum+curr_state) = i;
        treatcount--;
        curr_fsm = fsm+*(statemap+curr_state);
        while (curr_fsm->state_no == curr_state) {
            if (curr_fsm->target != -1 ) {
                (*(invcount+(curr_fsm->target)))--;
                if (!overflow) {
                    *(pathcount+(curr_fsm->target)) += *(pathcount+curr_state);
                    if ((*(pathcount+(curr_fsm->target)) < 0)) {
                        overflow = 1;
                    }
                }
                if (*(treated+(curr_fsm)->target) == 1) {
                    net->pathcount = -1;
                    net->is_loop_free = 0;
                    goto cyclic;
                }
                if ( *(invcount+(curr_fsm->target)) == 0) {
                    int_stack_push(curr_fsm->target);
                }
            }
            curr_fsm++;
        }
    }
    if (treatcount > 0) {
        net->pathcount = -1;
        net->is_loop_free = 0;
        goto cyclic;
    }
    new_fsm = xxmalloc(sizeof(struct fsm_state) * (lc+1));
    for (i=0, j=0 ; i < net->statecount; i++) {
        curr_state = *(order+i);
        curr_fsm = fsm+*(statemap+curr_state);
        if (curr_fsm->final_state == 1 && !overflow) {
            grand_pathcount += *(pathcount + curr_state);
            if (grand_pathcount < 0)
                overflow = 1;
        }
        for (; curr_fsm->state_no == curr_state; curr_fsm++) {
            newstate = curr_fsm->state_no == -1 ? -1 : *(newnum+(curr_fsm->state_no));
            newtarget = curr_fsm->target == -1 ? -1 : *(newnum+(curr_fsm->target));
            add_fsm_arc(new_fsm, j, newstate, curr_fsm->in, curr_fsm->out, newtarget, curr_fsm->final_state, curr_fsm->start_state);
            j++;
        }
    }
    add_fsm_arc(new_fsm, j, -1, -1, -1, -1, -1, -1);
    net->states = new_fsm;
    net->pathcount = grand_pathcount;
    net->is_loop_free = 1;
    if (overflow == 1) {
        net->pathcount = -2;
    }
    xxfree(fsm);
 cyclic:
    xxfree(statemap);
    xxfree(order);
    xxfree(pathcount);
    xxfree(newnum);
    xxfree(invcount);
    xxfree(treated);
    int_stack_clear();
    return(net);
}

canonical_original_code:
struct fsm *fsm_topsort(struct fsm *net) {
    int i; int j; int curr_state; int *statemap; int treatcount; int *order; int lc; int *newnum; int newtarget; int newstate;
    unsigned short *invcount;
    unsigned char *treated; unsigned char overflow;
    long long grand_pathcount; long long *pathcount;
    struct fsm_state *fsm; struct fsm_state *curr_fsm; struct fsm_state *new_fsm;
    fsm_count(net);
    fsm = net->states;
    statemap = xxmalloc(sizeof(int)*net->statecount);
    order = xxmalloc(sizeof(int)*net->statecount);
    pathcount = xxmalloc(sizeof(long long)*net->statecount);
    newnum = xxmalloc(sizeof(int)*net->statecount);
    invcount = xxmalloc(sizeof(unsigned short)*net->statecount);
    treated = xxmalloc(sizeof(unsigned char)*net->statecount);
    for (i=0; i < net->statecount; i++) {
 *(statemap+i) = -1;
 *(invcount+i) = 0;
 *(treated+i) = 0;
 *(order+i) = 0;
 *(pathcount+i) = 0;
    }
    for (i=0, lc=0; (fsm+i)->state_no != -1; i++) {
        lc++;
        if ((fsm+i)->target != -1) {
            (*(invcount+(fsm+i)->target))++;
            if ((fsm+i)->state_no == (fsm+i)->target) {
                net->pathcount = -1;
                net->is_loop_free = 0;
                goto cyclic;
            }
        }
 if (*(statemap+(fsm+i)->state_no) == -1) {
     *(statemap+(fsm+i)->state_no) = i;
 }
    }
    treatcount = net->statecount;
    int_stack_clear();
    int_stack_push(0);
    grand_pathcount = 0;
    *(pathcount+0) = 1;
    overflow = 0;
    for (i=0 ; !int_stack_isempty(); i++) {
        curr_state = int_stack_pop();
        *(treated+curr_state) = 1;
        *(order+i) = curr_state;
        *(newnum+curr_state) = i;
        treatcount--;
        curr_fsm = fsm+*(statemap+curr_state);
        while (curr_fsm->state_no == curr_state) {
            if (curr_fsm->target != -1 ) {
                (*(invcount+(curr_fsm->target)))--;
                if (!overflow) {
                    *(pathcount+(curr_fsm->target)) += *(pathcount+curr_state);
                    if ((*(pathcount+(curr_fsm->target)) < 0)) {
                        overflow = 1;
                    }
                }
                if (*(treated+(curr_fsm)->target) == 1) {
                    net->pathcount = -1;
                    net->is_loop_free = 0;
                    goto cyclic;
                }
                if ( *(invcount+(curr_fsm->target)) == 0) {
                    int_stack_push(curr_fsm->target);
                }
            }
            curr_fsm++;
        }
    }
    if (treatcount > 0) {
        net->pathcount = -1;
        net->is_loop_free = 0;
        goto cyclic;
    }
    new_fsm = xxmalloc(sizeof(struct fsm_state) * (lc+1));
    for (i=0, j=0 ; i < net->statecount; i++) {
        curr_state = *(order+i);
        curr_fsm = fsm+*(statemap+curr_state);
        if (curr_fsm->final_state == 1 && !overflow) {
            grand_pathcount += *(pathcount + curr_state);
            if (grand_pathcount < 0)
                overflow = 1;
        }
        for (; curr_fsm->state_no == curr_state; curr_fsm++) {
            newstate = curr_fsm->state_no == -1 ? -1 : *(newnum+(curr_fsm->state_no));
            newtarget = curr_fsm->target == -1 ? -1 : *(newnum+(curr_fsm->target));
            add_fsm_arc(new_fsm, j, newstate, curr_fsm->in, curr_fsm->out, newtarget, curr_fsm->final_state, curr_fsm->start_state);
            j++;
        }
    }
    add_fsm_arc(new_fsm, j, -1, -1, -1, -1, -1, -1);
    net->states = new_fsm;
    net->pathcount = grand_pathcount;
    net->is_loop_free = 1;
    if (overflow == 1) {
        net->pathcount = -2;
    }
    xxfree(fsm);
 cyclic:
    xxfree(statemap);
    xxfree(order);
    xxfree(pathcount);
    xxfree(newnum);
    xxfree(invcount);
    xxfree(treated);
    int_stack_clear();
    return(net);
}

variable_types: i int

variable_types:
statemap
int *

variable_types: treatcount int

variable_types:
order
int *

variable_types: lc int

variable_types:
newnum
int *

variable_types: newtarget int

variable_types: newstate int

variable_types:
invcount
unsigned short *

variable_types:
treated
unsigned char *

variable_types:
overflow
unsigned char

variable_types:
pathcount
long long *


decompiled_code:
__int64 __fastcall fsm_lower(__int64 a1)
{
unsigned int *v2; // rbx
unsigned int v3; // eax
int v4; // ebp
__int64 v5; // rdi
__int64 v6; // rcx
__int16 v7; // si

v2 = *(unsigned int **)(a1 + 104);
v3 = sigma_max(*(_QWORD *)(a1 + 112));
fsm_state_init(v3);
v4 = -1;
if ( *v2 != -1 )
{
while ( 1 )
{
v5 = *v2;
if ( (_DWORD)v5 != v4 )
fsm_state_set_current_state(v5, (unsigned int)*((char *)v2 + 12), (unsigned int)*((char *)v2 + 13));
v6 = v2[2];
if ( (_DWORD)v6 != -1 )
{
v7 = *((_WORD *)v2 + 3);
if ( v7 == 1 )
v7 = 2;
fsm_state_add_arc(
*v2,
(unsigned int)v7,
(unsigned int)v7,
v6,
(unsigned int)*((char *)v2 + 12),
(unsigned int)*((char *)v2 + 13));
}
v4 = *v2;
v2 += 4;
if ( *v2 == -1 )
break;
if ( *v2 != v4 && v4 != -1 )
fsm_state_end_state();
}
}
fsm_state_end_state();
xxfree(*(_QWORD *)(a1 + 104));
fsm_state_close(a1);
sigma_cleanup(a1, 0LL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int *v2; // rbx
unsigned int v3; // eax
int v4; // ebp
__int64 v5; // rdi
__int64 v6; // rcx
__int16 v7; // si

v2 = *(unsigned int **)(a1 + 104);
v3 = sigma_max(*(_QWORD *)(a1 + 112));
fsm_state_init(v3);
v4 = -1;
if ( *v2 != -1 )
{
while ( 1 )
{
v5 = *v2;
if ( (_DWORD)v5 != v4 )
fsm_state_set_current_state(v5, (unsigned int)*((char *)v2 + 12), (unsigned int)*((char *)v2 + 13));
v6 = v2[2];
if ( (_DWORD)v6 != -1 )
{
v7 = *((_WORD *)v2 + 3);
if ( v7 == 1 )
v7 = 2;
fsm_state_add_arc(
*v2,
(unsigned int)v7,
(unsigned int)v7,
v6,
(unsigned int)*((char *)v2 + 12),
(unsigned int)*((char *)v2 + 13));
}
v4 = *v2;
v2 += 4;
if ( *v2 == -1 )
break;
if ( *v2 != v4 && v4 != -1 )
fsm_state_end_state();
}
}
fsm_state_end_state();
xxfree(*(_QWORD *)(a1 + 104));
fsm_state_close(a1);
sigma_cleanup(a1, 0LL);
return a1;
}

original_code:
struct fsm *fsm_lower(struct fsm *net) {
    struct fsm_state *fsm;
    int i, prevstate, out;
    fsm = net->states;
    fsm_state_init(sigma_max(net->sigma));
    prevstate = -1;
    for (i = 0; (fsm+i)->state_no != - 1; prevstate = (fsm+i)->state_no, i++) {
        if (prevstate != -1 && prevstate != (fsm+i)->state_no) {
            fsm_state_end_state();
        }
        if (prevstate != (fsm+i)->state_no) {
            fsm_state_set_current_state((fsm+i)->state_no, (fsm+i)->final_state, (fsm+i)->start_state);
        }
        if ((fsm+i)->target != -1) {
            out = ((fsm+i)->out == 1) ? 2 : (fsm+i)->out;
            fsm_state_add_arc((fsm+i)->state_no, out, out, (fsm+i)->target, (fsm+i)->final_state, (fsm+i)->start_state);
        }
    }
    fsm_state_end_state();
    xxfree(net->states);
    fsm_state_close(net);
    sigma_cleanup(net,0);
    return(net);
}

canonical_original_code:
struct fsm *fsm_lower(struct fsm *net) {
    struct fsm_state *fsm;
    int i; int prevstate; int out;
    fsm = net->states;
    fsm_state_init(sigma_max(net->sigma));
    prevstate = -1;
    for (i = 0; (fsm+i)->state_no != - 1; prevstate = (fsm+i)->state_no, i++) {
        if (prevstate != -1 && prevstate != (fsm+i)->state_no) {
            fsm_state_end_state();
        }
        if (prevstate != (fsm+i)->state_no) {
            fsm_state_set_current_state((fsm+i)->state_no, (fsm+i)->final_state, (fsm+i)->start_state);
        }
        if ((fsm+i)->target != -1) {
            out = ((fsm+i)->out == 1) ? 2 : (fsm+i)->out;
            fsm_state_add_arc((fsm+i)->state_no, out, out, (fsm+i)->target, (fsm+i)->final_state, (fsm+i)->start_state);
        }
    }
    fsm_state_end_state();
    xxfree(net->states);
    fsm_state_close(net);
    sigma_cleanup(net,0);
    return(net);
}

variable_types:
net
struct fsm *

variable_types: prevstate int

variable_types: out int


decompiled_code:
__int64 __fastcall fsm_upper(__int64 a1)
{
unsigned int *v2; // rbx
__int64 v3; // rdi
int v4; // ebp
__int64 v5; // rdi
__int64 v6; // rcx
__int16 v7; // si

v2 = *(unsigned int **)(a1 + 104);
v3 = (unsigned int)sigma_max(*(_QWORD *)(a1 + 112));
fsm_state_init(v3);
v4 = -1;
if ( *v2 != -1 )
{
while ( 1 )
{
v5 = *v2;
if ( (_DWORD)v5 != v4 )
fsm_state_set_current_state(v5, (unsigned int)*((char *)v2 + 12), (unsigned int)*((char *)v2 + 13));
v6 = v2[2];
if ( (_DWORD)v6 != -1 )
{
v7 = *((_WORD *)v2 + 2);
if ( v7 == 1 )
v7 = 2;
fsm_state_add_arc(
*v2,
(unsigned int)v7,
(unsigned int)v7,
v6,
(unsigned int)*((char *)v2 + 12),
(unsigned int)*((char *)v2 + 13));
}
v4 = *v2;
v2 += 4;
if ( *v2 == -1 )
break;
if ( *v2 != v4 && v4 != -1 )
fsm_state_end_state();
}
}
fsm_state_end_state();
xxfree(*(_QWORD *)(a1 + 104));
fsm_state_close(a1);
fsm_update_flags(a1, 0LL, 0LL, 0LL, 2LL, 2LL, 2LL);
sigma_cleanup(a1, 0LL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int *v2; // rbx
__int64 v3; // rdi
int v4; // ebp
__int64 v5; // rdi
__int64 v6; // rcx
__int16 v7; // si

v2 = *(unsigned int **)(a1 + 104);
v3 = (unsigned int)sigma_max(*(_QWORD *)(a1 + 112));
fsm_state_init(v3);
v4 = -1;
if ( *v2 != -1 )
{
while ( 1 )
{
v5 = *v2;
if ( (_DWORD)v5 != v4 )
fsm_state_set_current_state(v5, (unsigned int)*((char *)v2 + 12), (unsigned int)*((char *)v2 + 13));
v6 = v2[2];
if ( (_DWORD)v6 != -1 )
{
v7 = *((_WORD *)v2 + 2);
if ( v7 == 1 )
v7 = 2;
fsm_state_add_arc(
*v2,
(unsigned int)v7,
(unsigned int)v7,
v6,
(unsigned int)*((char *)v2 + 12),
(unsigned int)*((char *)v2 + 13));
}
v4 = *v2;
v2 += 4;
if ( *v2 == -1 )
break;
if ( *v2 != v4 && v4 != -1 )
fsm_state_end_state();
}
}
fsm_state_end_state();
xxfree(*(_QWORD *)(a1 + 104));
fsm_state_close(a1);
fsm_update_flags(a1, 0LL, 0LL, 0LL, 2LL, 2LL, 2LL);
sigma_cleanup(a1, 0LL);
return a1;
}

original_code:
struct fsm *fsm_upper(struct fsm *net) {
    struct fsm_state *fsm;
    int i, prevstate, in;
    fsm = net->states;
    fsm_state_init(sigma_max(net->sigma));
    prevstate = -1;
    for (i = 0; (fsm+i)->state_no != - 1; prevstate = (fsm+i)->state_no, i++) {
        if (prevstate != -1 && prevstate != (fsm+i)->state_no) {
            fsm_state_end_state();
        }
        if (prevstate != (fsm+i)->state_no) {
            fsm_state_set_current_state((fsm+i)->state_no, (fsm+i)->final_state, (fsm+i)->start_state);
        }
        if ((fsm+i)->target != -1) {
            in = ((fsm+i)->in == 1) ? 2 : (fsm+i)->in;
            fsm_state_add_arc((fsm+i)->state_no, in, in, (fsm+i)->target, (fsm+i)->final_state, (fsm+i)->start_state);
        }
    }
    fsm_state_end_state();
    xxfree(net->states);
    fsm_state_close(net);
    fsm_update_flags(net,0,0,0,2,2,2);
    sigma_cleanup(net,0);
    return(net);
}

canonical_original_code:
struct fsm *fsm_upper(struct fsm *net) {
    struct fsm_state *fsm;
    int i; int prevstate; int in;
    fsm = net->states;
    fsm_state_init(sigma_max(net->sigma));
    prevstate = -1;
    for (i = 0; (fsm+i)->state_no != - 1; prevstate = (fsm+i)->state_no, i++) {
        if (prevstate != -1 && prevstate != (fsm+i)->state_no) {
            fsm_state_end_state();
        }
        if (prevstate != (fsm+i)->state_no) {
            fsm_state_set_current_state((fsm+i)->state_no, (fsm+i)->final_state, (fsm+i)->start_state);
        }
        if ((fsm+i)->target != -1) {
            in = ((fsm+i)->in == 1) ? 2 : (fsm+i)->in;
            fsm_state_add_arc((fsm+i)->state_no, in, in, (fsm+i)->target, (fsm+i)->final_state, (fsm+i)->start_state);
        }
    }
    fsm_state_end_state();
    xxfree(net->states);
    fsm_state_close(net);
    fsm_update_flags(net,0,0,0,2,2,2);
    sigma_cleanup(net,0);
    return(net);
}

variable_types: in int


decompiled_code:
__int64 __fastcall fsm_reverse(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
unsigned int v3; // er15
unsigned int v4; // er14
int v5; // er13
int v6; // eax
int v7; // eax
int v8; // eax
__int64 v9; // rbx

v1 = fsm_read_init();
v2 = fsm_construct_init(a1);
fsm_construct_copy_sigma(v2, *(_QWORD *)(a1 + 112));
while ( (unsigned int)fsm_get_next_arc(v1) )
{
v3 = fsm_get_arc_num_out(v1);
v4 = fsm_get_arc_num_in(v1);
v5 = fsm_get_arc_source(v1);
v6 = fsm_get_arc_target(v1);
fsm_construct_add_arc_nums(v2, (unsigned int)(v6 + 1), (unsigned int)(v5 + 1), v4, v3);
}
while ( 1 )
{
v7 = fsm_get_next_final(v1);
if ( v7 == -1 )
break;
fsm_construct_add_arc_nums(v2, 0LL, (unsigned int)(v7 + 1), 0LL, 0LL);
}
while ( 1 )
{
v8 = fsm_get_next_initial(v1);
if ( v8 == -1 )
break;
fsm_construct_set_final(v2, (unsigned int)(v8 + 1));
}
fsm_construct_set_initial(v2, 0LL);
fsm_read_done(v1);
v9 = fsm_construct_done(v2);
*(_DWORD *)(v9 + 72) = 0;
*(_DWORD *)(v9 + 84) = 0;
fsm_destroy(a1);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
unsigned int v3; // er15
unsigned int v4; // er14
int v5; // er13
int v6; // eax
int v7; // eax
int v8; // eax
__int64 v9; // rbx

v1 = fsm_read_init();
v2 = fsm_construct_init(a1);
fsm_construct_copy_sigma(v2, *(_QWORD *)(a1 + 112));
while ( (unsigned int)fsm_get_next_arc(v1) )
{
v3 = fsm_get_arc_num_out(v1);
v4 = fsm_get_arc_num_in(v1);
v5 = fsm_get_arc_source(v1);
v6 = fsm_get_arc_target(v1);
fsm_construct_add_arc_nums(v2, (unsigned int)(v6 + 1), (unsigned int)(v5 + 1), v4, v3);
}
while ( 1 )
{
v7 = fsm_get_next_final(v1);
if ( v7 == -1 )
break;
fsm_construct_add_arc_nums(v2, 0LL, (unsigned int)(v7 + 1), 0LL, 0LL);
}
while ( 1 )
{
v8 = fsm_get_next_initial(v1);
if ( v8 == -1 )
break;
fsm_construct_set_final(v2, (unsigned int)(v8 + 1));
}
fsm_construct_set_initial(v2, 0LL);
fsm_read_done(v1);
v9 = fsm_construct_done(v2);
*(_DWORD *)(v9 + 72) = 0;
*(_DWORD *)(v9 + 84) = 0;
fsm_destroy(a1);
return v9;
}

original_code:
struct fsm *fsm_reverse(struct fsm *net) {
    struct fsm *revnet;
    struct fsm_construct_handle *revh;
    struct fsm_read_handle *inh;
    int i;
    inh = fsm_read_init(net);
    revh = fsm_construct_init(net->name);
    fsm_construct_copy_sigma(revh, net->sigma);
    while (fsm_get_next_arc(inh)) {
 fsm_construct_add_arc_nums(revh, fsm_get_arc_target(inh)+1, fsm_get_arc_source(inh)+1, fsm_get_arc_num_in(inh), fsm_get_arc_num_out(inh));
    }
    while ((i = fsm_get_next_final(inh)) != -1) {
 fsm_construct_add_arc_nums(revh, 0, i+1, 0, 0);
    }
    while ((i = fsm_get_next_initial(inh)) != -1) {
 fsm_construct_set_final(revh, i+1);
    }
    fsm_construct_set_initial(revh, 0);
    fsm_read_done(inh);
    revnet = fsm_construct_done(revh);
    revnet->is_deterministic = 0;
    revnet->is_epsilon_free = 0;
    fsm_destroy(net);
    return(revnet);
}

variable_types: struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *

variable_types: struct fsm_construct_handle { struct fsm_state_list { _Bool used; _Bool is_final; _Bool is_initial; short num_trans; int state_number; struct fsm_trans_list { short in; short out; int target; struct fsm_trans_list *next; } *fsm_trans_list; } *fsm_state_list; int fsm_state_list_size; struct fsm_sigma_list { char *symbol; } *fsm_sigma_list; int fsm_sigma_list_size; struct fsm_sigma_hash { char *symbol; short sym; struct fsm_sigma_hash *next; } *fsm_sigma_hash; int fsm_sigma_hash_size; int maxstate; int maxsigma; int numfinals; char *name; } *

variable_types: struct fsm_read_handle { struct fsm_state { int state_no; short in; short out; int target; char final_state; char start_state; } *arcs_head; struct fsm_state **states_head; struct fsm_state *arcs_cursor; int *finals_head; int *finals_cursor; struct fsm_state **states_cursor; int *initials_head; int *initials_cursor; int current_state; struct fsm_sigma_list { char *symbol; } *fsm_sigma_list; int sigma_list_size; struct fsm { char name[40]; int arity; int arccount; int statecount; int linecount; int finalcount; long long pathcount; int is_deterministic; int is_pruned; int is_minimized; int is_epsilon_free; int is_loop_free; int is_completed; int arcs_sorted_in; int arcs_sorted_out; struct fsm_state *states; struct sigma { int number; char *symbol; struct sigma *next; } *sigma; struct medlookup { int *confusion_matrix; } *medlookup; } *net; unsigned char *lookuptable; _Bool has_unknowns; } *

user_defined_types: struct fsm_read_handle { struct fsm_state *arcs_head; struct fsm_state **states_head; struct fsm_state *arcs_cursor; int *finals_head; int *finals_cursor; struct fsm_state **states_cursor; int *initials_head; int *initials_cursor; int current_state; struct fsm_sigma_list *fsm_sigma_list; int sigma_list_size; struct fsm *net; unsigned char *lookuptable; _Bool has_unknowns; }


isBeginningOf

repo: vchungg/Lemonade-Stand

decompiled_code:
__int64 __fastcall isBeginningOf(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
char v4; // cl

v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a2 + v2);
if ( !v3 )
break;
v4 = *(_BYTE *)(a1 + v2++);
if ( v4 != v3 )
return 0LL;
}
return 1LL;
}

original_code:
static int isBeginningOf(char *s, char *scode) {
 while (*scode) {
  if (*s++ != *scode++)
   return 0;
 }
 return 1;
}

variable_types:
s
char *

variable_types:
scode
char *


decompiled_code:
__int64 get_circ()
{
unsigned int v0; // esi

if ( !dword_404158 )
return (unsigned int)-2;
v0 = circ[dword_404154];
dword_404154 = (dword_404154 + 1) % 20;
--dword_404158;
return v0;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // esi

if ( !dword_404158 )
return (unsigned int)-2;
v0 = circ[dword_404154];
dword_404154 = (dword_404154 + 1) % 20;
--dword_404158;
return v0;
}

original_code:
static int get_circ(void) {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}

canonical_original_code:
static int get_circ() {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}


decompiled_code:
int getkey_terminate()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

canonical_decompiled_code:
int func13()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

original_code:
void getkey_terminate(void) {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}

canonical_original_code:
void getkey_terminate() {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}


decompiled_code:
int __fastcall xt_par0(const char *a1)
{
return printf("%s", a1);
}

canonical_decompiled_code:
int __fastcall func14(const char *a1)
{
return printf("%s", a1);
}

original_code:
void xt_par0(char *control_sequence) {
 printf("%s",control_sequence);
}


decompiled_code:
int __fastcall xt_par1(const char *a1)
{
return printf(a1);
}

canonical_decompiled_code:
int __fastcall func15(const char *a1)
{
return printf(a1);
}

original_code:
void xt_par1(char *control_sequence, int parameter1) {
 printf(control_sequence, parameter1);
}


decompiled_code:
int __fastcall xt_par2(const char *a1)
{
return printf(a1);
}

canonical_decompiled_code:
int __fastcall func16(const char *a1)
{
return printf(a1);
}

original_code:
void xt_par2(char *control_sequence, int parameter1, int parameter2) {
 printf(control_sequence, parameter1, parameter2);
}


lsSetCurrFloorSquares

repo: vcosta/derclou

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

result = ls;
if ( a1 == *(_DWORD *)(ls + 320LL) )
*(_QWORD *)(ls + 288LL) = *(_QWORD *)(ls + 296LL);
if ( a1 == *(_DWORD *)(result + 324) )
*(_QWORD *)(result + 288) = *(_QWORD *)(result + 304);
if ( *(_DWORD *)(result + 328) == a1 )
*(_QWORD *)(result + 288) = *(_QWORD *)(result + 312);
return result;
}

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

result = ls;
if ( a1 == *(_DWORD *)(ls + 320LL) )
*(_QWORD *)(ls + 288LL) = *(_QWORD *)(ls + 296LL);
if ( a1 == *(_DWORD *)(result + 324) )
*(_QWORD *)(result + 288) = *(_QWORD *)(result + 304);
if ( *(_DWORD *)(result + 328) == a1 )
*(_QWORD *)(result + 288) = *(_QWORD *)(result + 312);
return result;
}

original_code:
static void lsSetCurrFloorSquares(U32 areaId)
{
    S32 i;
    for (i = 0; i < 3; i++)
 if (areaId == ls->ul_FloorAreaId[i])
     ls->p_CurrFloor = ls->p_AllFloors[i];
}

canonical_original_code:
static void lsSetCurrFloorSquares(unsigned int areaId)
{
    int i;
    for (i = 0; i < 3; i++)
 if (areaId == ls->ul_FloorAreaId[i])
     ls->p_CurrFloor = ls->p_AllFloors[i];
}

variable_types:
areaId
unsigned int

variable_types: i int


lsLoadAllSpots

decompiled_code:
__int64 lsLoadAllSpots()
{
__int64 v0; // rax
__int64 v1; // rbx
char v3[265]; // [rsp+1h] [rbp-109h]
char v4[264]; // [rsp+2h] [rbp-108h] BYREF

SetObjectListAttr(5LL, 509992LL);
v0 = dbGetObject((unsigned int)*ls);
AskAll(v0, 500002LL, &BuildObjectList);
v1 = ObjectListPrivate;
strcpy(v4, *(const char **)(*ObjectListPrivate + 16LL));
v3[strlen(v4)] = 0;
strcat(v4, ".spo");
lsLoadSpots((unsigned int)*ls, v4);
return RemoveList(v1);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
__int64 v1; // rbx
char v3[265]; // [rsp+1h] [rbp-109h]
char v4[264]; // [rsp+2h] [rbp-108h] BYREF

SetObjectListAttr(5LL, 509992LL);
v0 = dbGetObject((unsigned int)*ls);
AskAll(v0, 500002LL, &BuildObjectList);
v1 = ObjectListPrivate;
strcpy(v4, *(const char **)(*ObjectListPrivate + 16LL));
v3[strlen(v4)] = 0;
strcat(v4, ".spo");
lsLoadSpots((unsigned int)*ls, v4);
return RemoveList(v1);
}

original_code:
static void lsLoadAllSpots(void)
{
    char fileName[256];
    LIST *areas;
    NODE *n;
    { SetObjectListAttr ((1 << 2) | (1),509992L); AskAll (dbGetObject (ls->ul_BuildingID), 500002, BuildObjectList); };
    areas = ObjectListPrivate;
    n = (NODE *) ((((NODE *)((&((areas))->Head)))->Succ));
    strcpy(fileName, (((NODE *)(n))->Name));
    fileName[strlen(fileName) - 1] = '\0';
    strcat(fileName, (".spo"));
    lsLoadSpots(ls->ul_BuildingID, fileName);
    RemoveList(areas);
}

canonical_original_code:
static void lsLoadAllSpots()
{
    char fileName[256];
    struct List *areas;
    struct Node *n;
    { SetObjectListAttr ((1 << 2) | (1),509992L); AskAll (dbGetObject (ls->ul_BuildingID), 500002, BuildObjectList); };
    areas = ObjectListPrivate;
    n = (struct Node *) ((((struct Node *)((&((areas))->Head)))->Succ));
    strcpy(fileName, (((struct Node *)(n))->Name));
    fileName[strlen(fileName) - 1] = '\0';
    strcat(fileName, (".spo"));
    lsLoadSpots(ls->ul_BuildingID, fileName);
    RemoveList(areas);
}

variable_types:
fileName
char [256]

variable_types: struct List { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Head; struct Node Tail; } *

variable_types: struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } *

user_defined_types: struct List { struct Node Head; struct Node Tail; }


lsDoneFloorSquares

decompiled_code:
__int64 lsDoneFloorSquares()
{
__int64 i; // rbx
__int64 result; // rax
__int64 v2; // rdi

for ( i = 0LL; i != 3; ++i )
{
result = ls;
v2 = *(_QWORD *)(ls + 8 * i + 296);
if ( v2 )
{
result = TCFreeMem(v2, 160LL);
*(_QWORD *)(ls + 8 * i + 296) = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 i; // rbx
__int64 result; // rax
__int64 v2; // rdi

for ( i = 0LL; i != 3; ++i )
{
result = ls;
v2 = *(_QWORD *)(ls + 8 * i + 296);
if ( v2 )
{
result = TCFreeMem(v2, 160LL);
*(_QWORD *)(ls + 8 * i + 296) = 0LL;
}
}
return result;
}

original_code:
static void lsDoneFloorSquares(void)
{
    size_t count, i, size;
    for (i = 0; i < 3; i++) {
 if (ls->p_AllFloors[i]) {
     count = (640/32) * (256/32);
     size = sizeof(struct LSFloorSquare) * count;
     TCFreeMem(ls->p_AllFloors[i], size);
     ls->p_AllFloors[i] = ((void *)0);
 }
    }
}

canonical_original_code:
static void lsDoneFloorSquares()
{
    unsigned long count; unsigned long i; unsigned long size;
    for (i = 0; i < 3; i++) {
 if (ls->p_AllFloors[i]) {
     count = (640/32) * (256/32);
     size = sizeof(struct LSFloorSquare) * count;
     TCFreeMem(ls->p_AllFloors[i], size);
     ls->p_AllFloors[i] = ((void *)0);
 }
    }
}

variable_types:
count
unsigned long

variable_types:
i
unsigned long

variable_types:
size
unsigned long

user_defined_types: struct LSFloorSquare { unsigned char uch_FloorType; }


lsInitRelations

decompiled_code:
__int64 __fastcall lsInitRelations(__int64 a1)
{
__int64 v1; // rbx

v1 = dbGetObject(a1);
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 3));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 4));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 5));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 6));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 7));
return AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 10));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx

v1 = dbGetObject(a1);
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 3));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 4));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 5));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 6));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 7));
return AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 10));
}

original_code:
void lsInitRelations(U32 areaID)
{
    LSArea area = dbGetObject(areaID);
    AddRelation(area->ul_ObjectBaseNr + 3);
    AddRelation(area->ul_ObjectBaseNr + 4);
    AddRelation(area->ul_ObjectBaseNr + 5);
    AddRelation(area->ul_ObjectBaseNr + 6);
    AddRelation(area->ul_ObjectBaseNr + 7);
    AddRelation(area->ul_ObjectBaseNr + 10);
}

canonical_original_code:
void lsInitRelations(unsigned int areaID)
{
    struct _LSArea *area = dbGetObject(areaID);
    AddRelation(area->ul_ObjectBaseNr + 3);
    AddRelation(area->ul_ObjectBaseNr + 4);
    AddRelation(area->ul_ObjectBaseNr + 5);
    AddRelation(area->ul_ObjectBaseNr + 6);
    AddRelation(area->ul_ObjectBaseNr + 7);
    AddRelation(area->ul_ObjectBaseNr + 10);
}

variable_types:
areaID
unsigned int

variable_types: struct _LSArea { unsigned short us_Coll16ID; unsigned short us_Coll32ID; unsigned short us_Coll48ID; unsigned short us_PlanColl16ID; unsigned short us_PlanColl32ID; unsigned short us_PlanColl48ID; unsigned short us_FloorCollID; unsigned short us_PlanFloorCollID; unsigned short us_Width; unsigned short us_Height; unsigned int ul_ObjectBaseNr; unsigned char uch_Darkness; unsigned short us_StartX0; unsigned short us_StartX1; unsigned short us_StartX2; unsigned short us_StartX3; unsigned short us_StartX4; unsigned short us_StartX5; unsigned short us_StartY0; unsigned short us_StartY1; unsigned short us_StartY2; unsigned short us_StartY3; unsigned short us_StartY4; unsigned short us_StartY5; } *


lsSetRelations

decompiled_code:
__int64 __fastcall lsSetRelations(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(dbGetObject(a1) + 20);
ConsistOfRelationID = v1 + 3;
hasLockRelationID = v1 + 4;
hasAlarmRelationID = v1 + 5;
hasPowerRelationID = v1 + 6;
hasLootRelationID = v1 + 7;
result = (unsigned int)(v1 + 10);
hasRoomRelationID = result;
return result;
}

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

v1 = *(_DWORD *)(dbGetObject(a1) + 20);
ConsistOfRelationID = v1 + 3;
hasLockRelationID = v1 + 4;
hasAlarmRelationID = v1 + 5;
hasPowerRelationID = v1 + 6;
hasLootRelationID = v1 + 7;
result = (unsigned int)(v1 + 10);
hasRoomRelationID = result;
return result;
}

original_code:
void lsSetRelations(U32 areaID)
{
    LSArea area = dbGetObject(areaID);
    ConsistOfRelationID = area->ul_ObjectBaseNr + 3;
    hasLockRelationID = area->ul_ObjectBaseNr + 4;
    hasAlarmRelationID = area->ul_ObjectBaseNr + 5;
    hasPowerRelationID = area->ul_ObjectBaseNr + 6;
    hasLootRelationID = area->ul_ObjectBaseNr + 7;
    hasRoomRelationID = area->ul_ObjectBaseNr + 10;
}

canonical_original_code:
void lsSetRelations(unsigned int areaID)
{
    struct _LSArea *area = dbGetObject(areaID);
    ConsistOfRelationID = area->ul_ObjectBaseNr + 3;
    hasLockRelationID = area->ul_ObjectBaseNr + 4;
    hasAlarmRelationID = area->ul_ObjectBaseNr + 5;
    hasPowerRelationID = area->ul_ObjectBaseNr + 6;
    hasLootRelationID = area->ul_ObjectBaseNr + 7;
    hasRoomRelationID = area->ul_ObjectBaseNr + 10;
}

user_defined_types: struct _LSArea { unsigned short us_Coll16ID; unsigned short us_Coll32ID; unsigned short us_Coll48ID; unsigned short us_PlanColl16ID; unsigned short us_PlanColl32ID; unsigned short us_PlanColl48ID; unsigned short us_FloorCollID; unsigned short us_PlanFloorCollID; unsigned short us_Width; unsigned short us_Height; unsigned int ul_ObjectBaseNr; unsigned char uch_Darkness; unsigned short us_StartX0; unsigned short us_StartX1; unsigned short us_StartX2; unsigned short us_StartX3; unsigned short us_StartX4; unsigned short us_StartX5; unsigned short us_StartY0; unsigned short us_StartY1; unsigned short us_StartY2; unsigned short us_StartY3; unsigned short us_StartY4; unsigned short us_StartY5; }