decompiled_code:
void __fastcall makefile_colorize_line(_DWORD *a1, int a2)
{
int v4; // ebx
int v5; // er14
int v6; // er13
int v7; // er13
int v8; // er13
int v9; // edx
__int64 v10; // rax
int v11; // esi
int v12; // ecx
int v13; // edx
__int64 v14; // rax
unsigned __int64 v15; // rdi
int v16; // ecx
int v17; // er13
__int64 v18; // rax
__int64 v19; // rdx

if ( *a1 == 105 )
{
v4 = ustristart(a1, "ifeq", 0LL);
if ( v4 )
{
v4 = 0;
}
else
{
v6 = ustristart(a1, "ifneq", 0LL);
if ( !v6 )
{
v4 = ustristart(a1, "ifdef", 0LL);
if ( v4 )
{
v4 = v6;
}
else
{
v7 = ustristart(a1, "ifndef", 0LL);
if ( !v7 )
{
v4 = ustristart(a1, "include", 0LL);
if ( !v4 )
goto LABEL_3;
v4 = v7;
}
}
}
}
}
else
{
v4 = 0;
if ( *a1 != 101 )
goto LABEL_3;
v8 = ustristart(a1, "else", 0LL);
if ( v8 )
{
v4 = 0;
}
else
{
v4 = ustristart(a1, "endif", 0LL);
if ( !v4 )
goto LABEL_3;
v4 = v8;
}
}
while ( 2 )
{
v17 = v4 + 1;
if ( v4 + 1 < a2 )
{
v18 = v17;
do
{
v17 = v18;
if ( a1[v18] == 35 )
break;
v17 = ++v18;
}
while ( a2 > (int)v18 );
}
set_color((unsigned __int64)&a1[v4], (unsigned __int64)&a1[v17], 9);
v4 = v17;
LABEL_3:
v5 = v4;
if ( a2 > v4 )
{
LABEL_31:
v14 = v4;
v15 = (unsigned __int64)&a1[v14];
v16 = a1[v14];
switch ( v16 )
{
case 9:
case 32:
if ( !v4 )
v5 = 1;
goto LABEL_29;
case 33:
if ( v4 <= 0 )
continue;
goto LABEL_29;
case 34:
case 39:
case 96:
if ( a2 <= ++v4 )
goto LABEL_59;
v19 = v4;
while ( v16 != a1[v19] )
{
v4 = ++v19;
if ( a2 <= (int)v19 )
goto LABEL_59;
}
v4 = v19 + 1;
LABEL_59:
set_color(v15, (unsigned __int64)&a1[v4], 10);
v5 = v4;
goto LABEL_30;
case 35:
if ( v4 > 0 && a1[v14 - 1] == 92 )
goto LABEL_29;
set_color(v15, (unsigned __int64)&a1[a2], 8);
return;
case 36:
v9 = v4 + 1;
v4 += 2;
if ( a1[v14 + 1] != 40 )
goto LABEL_15;
if ( a2 <= v4 )
return;
v10 = v4;
v11 = 1;
break;
case 43:
if ( v5 )
goto LABEL_29;
if ( a1[v14 + 1] != 61 )
goto LABEL_34;
goto LABEL_39;
case 58:
if ( v5 )
goto LABEL_29;
if ( a1[v14 + 1] == 61 )
{
LABEL_39:
set_color((unsigned __int64)&a1[v5], v15, 15);
}
else
{
LABEL_34:
set_color((unsigned __int64)a1, (unsigned __int64)&a1[v14], 14);
v5 = 0;
}
LABEL_29:
++v4;
goto LABEL_30;
case 61:
if ( !v5 )
goto LABEL_39;
goto LABEL_29;
default:
goto LABEL_29;
}
do
{
v13 = a1[v10];
if ( v13 == 40 )
{
++v11;
}
else if ( v13 == 41 )
{
if ( --v11 <= 0 )
{
v9 = v4;
v4 = v10;
LABEL_15:
v5 = v4;
if ( v9 < v4 )
{
LABEL_16:
set_color((unsigned __int64)&a1[v9], (unsigned __int64)&a1[v4], 16);
v5 = v4;
}
LABEL_30:
if ( v4 >= a2 )
return;
goto LABEL_31;
}
}
else if ( (v13 & 0xFFFFFFFB) == 32 )
{
v5 = v4;
goto LABEL_31;
}
v12 = ++v10;
}
while ( a2 > (int)v10 );
if ( v4 < v12 )
{
v9 = v4;
v4 = v12;
goto LABEL_16;
}
}
break;
}
}

canonical_decompiled_code:
void __fastcall func3(_DWORD *a1, int a2)
{
int v4; // ebx
int v5; // er14
int v6; // er13
int v7; // er13
int v8; // er13
int v9; // edx
__int64 v10; // rax
int v11; // esi
int v12; // ecx
int v13; // edx
__int64 v14; // rax
unsigned __int64 v15; // rdi
int v16; // ecx
int v17; // er13
__int64 v18; // rax
__int64 v19; // rdx

if ( *a1 == 105 )
{
v4 = ustristart(a1, "ifeq", 0LL);
if ( v4 )
{
v4 = 0;
}
else
{
v6 = ustristart(a1, "ifneq", 0LL);
if ( !v6 )
{
v4 = ustristart(a1, "ifdef", 0LL);
if ( v4 )
{
v4 = v6;
}
else
{
v7 = ustristart(a1, "ifndef", 0LL);
if ( !v7 )
{
v4 = ustristart(a1, "include", 0LL);
if ( !v4 )
goto LABEL_3;
v4 = v7;
}
}
}
}
}
else
{
v4 = 0;
if ( *a1 != 101 )
goto LABEL_3;
v8 = ustristart(a1, "else", 0LL);
if ( v8 )
{
v4 = 0;
}
else
{
v4 = ustristart(a1, "endif", 0LL);
if ( !v4 )
goto LABEL_3;
v4 = v8;
}
}
while ( 2 )
{
v17 = v4 + 1;
if ( v4 + 1 < a2 )
{
v18 = v17;
do
{
v17 = v18;
if ( a1[v18] == 35 )
break;
v17 = ++v18;
}
while ( a2 > (int)v18 );
}
func0((unsigned __int64)&a1[v4], (unsigned __int64)&a1[v17], 9);
v4 = v17;
LABEL_3:
v5 = v4;
if ( a2 > v4 )
{
LABEL_31:
v14 = v4;
v15 = (unsigned __int64)&a1[v14];
v16 = a1[v14];
switch ( v16 )
{
case 9:
case 32:
if ( !v4 )
v5 = 1;
goto LABEL_29;
case 33:
if ( v4 <= 0 )
continue;
goto LABEL_29;
case 34:
case 39:
case 96:
if ( a2 <= ++v4 )
goto LABEL_59;
v19 = v4;
while ( v16 != a1[v19] )
{
v4 = ++v19;
if ( a2 <= (int)v19 )
goto LABEL_59;
}
v4 = v19 + 1;
LABEL_59:
func0(v15, (unsigned __int64)&a1[v4], 10);
v5 = v4;
goto LABEL_30;
case 35:
if ( v4 > 0 && a1[v14 - 1] == 92 )
goto LABEL_29;
func0(v15, (unsigned __int64)&a1[a2], 8);
return;
case 36:
v9 = v4 + 1;
v4 += 2;
if ( a1[v14 + 1] != 40 )
goto LABEL_15;
if ( a2 <= v4 )
return;
v10 = v4;
v11 = 1;
break;
case 43:
if ( v5 )
goto LABEL_29;
if ( a1[v14 + 1] != 61 )
goto LABEL_34;
goto LABEL_39;
case 58:
if ( v5 )
goto LABEL_29;
if ( a1[v14 + 1] == 61 )
{
LABEL_39:
func0((unsigned __int64)&a1[v5], v15, 15);
}
else
{
LABEL_34:
func0((unsigned __int64)a1, (unsigned __int64)&a1[v14], 14);
v5 = 0;
}
LABEL_29:
++v4;
goto LABEL_30;
case 61:
if ( !v5 )
goto LABEL_39;
goto LABEL_29;
default:
goto LABEL_29;
}
do
{
v13 = a1[v10];
if ( v13 == 40 )
{
++v11;
}
else if ( v13 == 41 )
{
if ( --v11 <= 0 )
{
v9 = v4;
v4 = v10;
LABEL_15:
v5 = v4;
if ( v9 < v4 )
{
LABEL_16:
func0((unsigned __int64)&a1[v9], (unsigned __int64)&a1[v4], 16);
v5 = v4;
}
LABEL_30:
if ( v4 >= a2 )
return;
goto LABEL_31;
}
}
else if ( (v13 & 0xFFFFFFFB) == 32 )
{
v5 = v4;
goto LABEL_31;
}
v12 = ++v10;
}
while ( a2 > (int)v10 );
if ( v4 < v12 )
{
v9 = v4;
v4 = v12;
goto LABEL_16;
}
}
break;
}
}

original_code:
static void makefile_colorize_line(unsigned int *str, int n, int *statep,
                                   int state_only)
{
    int i, j, level;
    i = j = 0;
    if (str[0] == 'i') {
        if (ustristart(str, "ifeq", ((void *)0))
        || ustristart(str, "ifneq", ((void *)0))
        || ustristart(str, "ifdef", ((void *)0))
        || ustristart(str, "ifndef", ((void *)0))
        || ustristart(str, "include", ((void *)0)))
            goto preprocess;
    } else
    if (str[0] == 'e') {
        if (ustristart(str, "else", ((void *)0))
        || ustristart(str, "endif", ((void *)0)))
            goto preprocess;
    }
    while (i < n) {
        switch (str[i]) {
        case '$':
            i += 1;
            j = i + 1;
            if (str[i] == '(') {
                i += 1;
                level = 1;
                for (j = i; j < n; j++) {
                    if (str[j] == '(')
                        level++;
                    if (str[j] == ')' && --level <= 0)
                        break;
                    if (str[j] == ' ' || str[j] == '$') {
                        j = i;
                        break;
                    }
                }
            }
            if (i < j)
                set_color(str + i, str + j, QE_STYLE_TYPE);
            i = j;
            continue;
        case ' ':
        case '\t':
            if (i == 0)
                j = 1;
            break;
        case '+':
            if (!j && str[i+1] == '=')
                goto variable;
        case ':':
            if (j)
                break;
            if (str[i+1] == '=')
                goto variable;
            set_color(str + j, str + i, QE_STYLE_FUNCTION);
            break;
        case '=':
            if (j)
                break;
        variable:
            set_color(str + j, str + i, QE_STYLE_VARIABLE);
            break;
        case '#':
            if (i > 0 && str[i - 1] == '\\')
                break;
            set_color(str + i, str + n, QE_STYLE_COMMENT);
            i = n;
            continue;
        case '!':
            if (i > 0)
                break;
        preprocess:
            for (j = i + 1; j < n; j++) {
                if (str[j] == '#')
                    break;
            }
            set_color(str + i, str + j, QE_STYLE_PREPROCESS);
            i = j;
            continue;
        case '\'':
        case '`':
        case '"':
            for (j = i + 1; j < n; j++) {
                if (str[j] == str[i]) {
                    j++;
                    break;
                }
            }
            set_color(str + i, str + j, QE_STYLE_STRING);
            i = j;
            continue;
        default:
            break;
        }
        i++;
    }
}

canonical_original_code:
static void makefile_colorize_line(unsigned int *str, int n, int *statep, int state_only)
{
    int i; int j; int level;
    i = j = 0;
    if (str[0] == 'i') {
        if (ustristart(str, "ifeq", ((void *)0))
        || ustristart(str, "ifneq", ((void *)0))
        || ustristart(str, "ifdef", ((void *)0))
        || ustristart(str, "ifndef", ((void *)0))
        || ustristart(str, "include", ((void *)0)))
            goto preprocess;
    } else
    if (str[0] == 'e') {
        if (ustristart(str, "else", ((void *)0))
        || ustristart(str, "endif", ((void *)0)))
            goto preprocess;
    }
    while (i < n) {
        switch (str[i]) {
        case '$':
            i += 1;
            j = i + 1;
            if (str[i] == '(') {
                i += 1;
                level = 1;
                for (j = i; j < n; j++) {
                    if (str[j] == '(')
                        level++;
                    if (str[j] == ')' && --level <= 0)
                        break;
                    if (str[j] == ' ' || str[j] == '$') {
                        j = i;
                        break;
                    }
                }
            }
            if (i < j)
                set_color(str + i, str + j, QE_STYLE_TYPE);
            i = j;
            continue;
        case ' ':
        case '\t':
            if (i == 0)
                j = 1;
            break;
        case '+':
            if (!j && str[i+1] == '=')
                goto variable;
        case ':':
            if (j)
                break;
            if (str[i+1] == '=')
                goto variable;
            set_color(str + j, str + i, QE_STYLE_FUNCTION);
            break;
        case '=':
            if (j)
                break;
        variable:
            set_color(str + j, str + i, QE_STYLE_VARIABLE);
            break;
        case '#':
            if (i > 0 && str[i - 1] == '\\')
                break;
            set_color(str + i, str + n, QE_STYLE_COMMENT);
            i = n;
            continue;
        case '!':
            if (i > 0)
                break;
        preprocess:
            for (j = i + 1; j < n; j++) {
                if (str[j] == '#')
                    break;
            }
            set_color(str + i, str + j, QE_STYLE_PREPROCESS);
            i = j;
            continue;
        case '\'':
        case '`':
        case '"':
            for (j = i + 1; j < n; j++) {
                if (str[j] == str[i]) {
                    j++;
                    break;
                }
            }
            set_color(str + i, str + j, QE_STYLE_STRING);
            i = j;
            continue;
        default:
            break;
        }
        i++;
    }
}

variable_types:
str
unsigned int *

variable_types: n int

variable_types:
statep
int *

variable_types: i int

variable_types: j int

variable_types: level int


repo: dgdunix/qemacs-tmp

decompiled_code:
__int64 __fastcall makefile_mode_probe(__int64 a1)
{
__int64 v1; // rbx
int v2; // edx
__int64 result; // rax

v1 = get_basename(*(_QWORD *)(a1 + 8));
v2 = match_extension(v1, "mk|mak");
result = 70LL;
if ( !v2 )
{
result = qe_stristart(v1, "makefile", 0LL);
if ( (_DWORD)result )
result = 70LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
int v2; // edx
__int64 result; // rax

v1 = get_basename(*(_QWORD *)(a1 + 8));
v2 = match_extension(v1, "mk|mak");
result = 70LL;
if ( !v2 )
{
result = qe_stristart(v1, "makefile", 0LL);
if ( (_DWORD)result )
result = 70LL;
}
return result;
}

original_code:
static int makefile_mode_probe(ModeProbeData *p)
{
    const char *base = get_basename(p->filename);
    if (match_extension(base, "mk|mak")
    || qe_stristart(base, "makefile", ((void *)0)))
        return 70;
    return 0;
}

canonical_original_code:
static int makefile_mode_probe(struct ModeProbeData *p)
{
    char *base = get_basename(p->filename);
    if (match_extension(base, "mk|mak")
    || qe_stristart(base, "makefile", ((void *)0)))
        return 70;
    return 0;
}

variable_types: struct ModeProbeData { char *real_filename; char *filename; unsigned char *buf; int buf_size; int line_len; int mode; long total_size; } *

variable_types:
base
char *

return_type: int


SLDestroy

decompiled_code:
void __fastcall SLDestroy(void *ptr)
{
__int64 i; // rbx
void *v3; // rdi

if ( ptr )
{
for ( i = *(_QWORD *)(*((_QWORD *)ptr + 2) + 16LL); i; i = *(_QWORD *)(i + 16) )
free(*(void **)(i + 8));
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 i; // rbx
void *v3; // rdi

if ( ptr )
{
for ( i = *(_QWORD *)(*((_QWORD *)ptr + 2) + 16LL); i; i = *(_QWORD *)(i + 16) )
free(*(void **)(i + 8));
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void SLDestroy(SortedListPtr list) {
  if ( !list ) {
    return;
  }
  Container *container = list->tail->prev;
  for ( ; container; container = container->prev ) {
    free ( container->next );
  }
  if ( list->head ) {
    free ( list->head );
  }
  free(list);
}

canonical_original_code:
void SLDestroy(struct SortedList *list) {
  if ( !list ) {
    return;
  }
  struct Container *container = list->tail->prev;
  for ( ; container; container = container->prev ) {
    free ( container->next );
  }
  if ( list->head ) {
    free ( list->head );
  }
  free(list);
}

variable_types: struct SortedList { int (*compare)(void *, void *); struct Container { void *value; struct Container *next; struct Container *prev; int count; } *head; struct Container *tail; unsigned int size; } *

return_type: void

user_defined_types: struct SortedList { int (*compare)(void *, void *); struct Container *head; struct Container *tail; unsigned int size; }


insertEmpty

original_code:
int insertEmpty ( SortedListPtr list, void *newObj ) {
  Container *container = malloc ( sizeof(Container) );
  if ( container ) {
    *container = (Container) { newObj, ((void *)0), ((void *)0), 2 };
    list->head = list->tail = container;
    ++list->size;
    return 1;
  }
  return 0;
}

canonical_original_code:
int insertEmpty(struct SortedList *list, void *newObj) {
  struct Container *container = malloc ( sizeof(Container) );
  if ( container ) {
    *container = (struct Container) { newObj, ((void *)0), ((void *)0), 2 };
    list->head = list->tail = container;
    ++list->size;
    return 1;
  }
  return 0;
}

variable_types:
newObj
void *

variable_types: struct Container { void *value; struct Container *next; struct Container *prev; int count; } *


insertBegin

original_code:
int insertBegin ( SortedListPtr list, void *newObj, Container *container ) {
  *container = (Container) { newObj, list->head, ((void *)0), 2 };
  list->head = list->head->prev = container;
  ++list->size;
  return 1;
}

canonical_original_code:
int insertBegin(struct SortedList *list, void *newObj, struct Container *container) {
  *container = (struct Container) { newObj, list->head, ((void *)0), 2 };
  list->head = list->head->prev = container;
  ++list->size;
  return 1;
}

variable_types:
container
struct Container *

user_defined_types: struct Container { void *value; struct Container *next; struct Container *prev; int count; }


insertIn

original_code:
int insertIn (
    SortedListPtr list,
    void *newObj,
    Container* current,
    Container *container
) {
  *container = (Container) { newObj, current, current->prev, 2 };
  current->prev = current->prev->next = container;
  ++list->size;
  return 1;
}

canonical_original_code:
int insertIn(struct SortedList *list, void *newObj, struct Container *current, struct Container *container) {
  *container = (struct Container) { newObj, current, current->prev, 2 };
  current->prev = current->prev->next = container;
  ++list->size;
  return 1;
}

variable_types:
current
struct Container *


insertEnd

original_code:
int insertEnd ( SortedListPtr list, void *newObj, Container *container ) {
  *container = (Container) { newObj, ((void *)0), list->tail, 2 };
  list->tail = list->tail->next = container;
  ++list->size;
  return 1;
}

canonical_original_code:
int insertEnd(struct SortedList *list, void *newObj, struct Container *container) {
  *container = (struct Container) { newObj, ((void *)0), list->tail, 2 };
  list->tail = list->tail->next = container;
  ++list->size;
  return 1;
}


insert

original_code:
int insert ( SortedListPtr list, void *newObj ) {
  Container *current;
  Container *container = malloc ( sizeof(Container) );
  if ( !container || !list || !newObj ) { return 0; }
  if ( list->compare ( newObj, list->head->value ) >= 0 ) {
    return insertBegin ( list, newObj, container);
  }
  if ( list->compare ( newObj, list->tail->value ) <= 0 ) {
    return insertEnd( list, newObj, container );
  }
  for ( current = list->head->next;
        list->compare ( newObj, current->value ) < 0 && current->next;
        current = current->next ) { ; }
  return insertIn ( list, newObj, current, container );
}

canonical_original_code:
int insert(struct SortedList *list, void *newObj) {
  struct Container *current;
  struct Container *container = malloc ( sizeof(Container) );
  if ( !container || !list || !newObj ) { return 0; }
  if ( list->compare ( newObj, list->head->value ) >= 0 ) {
    return insertBegin ( list, newObj, container);
  }
  if ( list->compare ( newObj, list->tail->value ) <= 0 ) {
    return insertEnd( list, newObj, container );
  }
  for ( current = list->head->next;
        list->compare ( newObj, current->value ) < 0 && current->next;
        current = current->next ) { ; }
  return insertIn ( list, newObj, current, container );
}


SLInsert

decompiled_code:
__int64 __fastcall SLInsert(__int64 a1, __int64 a2)
{
if ( !a1 || !a2 )
return 0LL;
if ( *(_DWORD *)(a1 + 24) )
return insert(a1, a2);
return insertEmpty(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
if ( !a1 || !a2 )
return 0LL;
if ( *(_DWORD *)(a1 + 24) )
return func5(a1, a2);
return func1(a1, a2);
}

original_code:
int SLInsert ( SortedListPtr list, void *newObj ) {
  if ( !list || !newObj ) {
    return 0;
  }
  if ( list->size ) {
    return insert(list, newObj);
  }
  return insertEmpty(list, newObj);
}

canonical_original_code:
int SLInsert(struct SortedList *list, void *newObj) {
  if ( !list || !newObj ) {
    return 0;
  }
  if ( list->size ) {
    return insert(list, newObj);
  }
  return insertEmpty(list, newObj);
}


SLDestroyIterator

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

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

original_code:
void SLDestroyIterator(SortedListIteratorPtr iter) {
  if ( !iter ) {
    return;
  }
  free ( iter );
}

canonical_original_code:
void SLDestroyIterator(struct SortedListIterator *iter) {
  if ( !iter ) {
    return;
  }
  free ( iter );
}

variable_types: struct SortedListIterator { struct Container { void *value; struct Container *next; struct Container *prev; int count; } *iterator; } *

user_defined_types: struct SortedListIterator { struct Container *iterator; }


getValue

original_code:
void *getValue ( SortedListPtr list, Container *current, int compareTo ) {
  void * ret = current->value;
  if ( !current || compareTo ) { return ((void *)0); }
  if ( current->prev ) {
    current->prev->next = current->next;
    if ( current->count != 2 ) {
      ++current->next->count;
    }
  }
  else { list->head = current->next; }
  if ( current->next ) {
    current->next->prev = current->prev;
    if ( current->count != 2) {
      ++current->prev->count;
    }
  }
  else { list->tail = current->prev; }
  current->count -= 2;
  if ( !current->count ) {
    free ( current );
  }
  else { current->count *= -1; }
  --list->size;
  return ret;
}

canonical_original_code:
void *getValue(struct SortedList *list, struct Container *current, int compareTo) {
  void *ret = current->value;
  if ( !current || compareTo ) { return ((void *)0); }
  if ( current->prev ) {
    current->prev->next = current->next;
    if ( current->count != 2 ) {
      ++current->next->count;
    }
  }
  else { list->head = current->next; }
  if ( current->next ) {
    current->next->prev = current->prev;
    if ( current->count != 2) {
      ++current->prev->count;
    }
  }
  else { list->tail = current->prev; }
  current->count -= 2;
  if ( !current->count ) {
    free ( current );
  }
  else { current->count *= -1; }
  --list->size;
  return ret;
}

variable_types: compareTo int

variable_types:
ret
void *

return_type: void *


SLGet

original_code:
void *SLGet(SortedListPtr list, void *newObj) {
  Container *current = list->head;
  int compareTo = 0;
  if ( !list || !newObj || !list->size ) {
    return ((void *)0);
  }
  for ( ;
        current && (compareTo = list->compare ( newObj, current->value )) < 0;
        current = current->next ) { ; }
  return getValue ( list, current, compareTo );
}

canonical_original_code:
void *SLGet(struct SortedList *list, void *newObj) {
  struct Container *current = list->head;
  int compareTo = 0;
  if ( !list || !newObj || !list->size ) {
    return ((void *)0);
  }
  for ( ;
        current && (compareTo = list->compare ( newObj, current->value )) < 0;
        current = current->next ) { ; }
  return getValue ( list, current, compareTo );
}


SLRemove

decompiled_code:
_BOOL8 __fastcall SLRemove(__int64 a1, __int64 a2)
{
return SLGet(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, __int64 a2)
{
return func9(a1, a2) != 0;
}

original_code:
int SLRemove(SortedListPtr list, void *newObj) {
  return (SLGet(list, newObj) ? 1 : 0);
}

canonical_original_code:
int SLRemove(struct SortedList *list, void *newObj) {
  return (SLGet(list, newObj) ? 1 : 0);
}


SLDestroyValuesAndList

decompiled_code:
void __fastcall SLDestroyValuesAndList(void *ptr, void (__fastcall *a2)(_QWORD *))
{
_QWORD *v3; // rax
__int64 v4; // rbp
_QWORD *v5; // rdi

v3 = SLCreateIterator((__int64)ptr);
if ( ptr )
{
v4 = (__int64)v3;
if ( a2 )
{
while ( 1 )
{
v5 = SLNextItem(v4);
if ( !v5 )
break;
a2(v5);
}
SLDestroy(ptr);
}
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr, void (__fastcall *a2)(_QWORD *))
{
_QWORD *v3; // rax
__int64 v4; // rbp
_QWORD *v5; // rdi

v3 = SLCreateIterator((__int64)ptr);
if ( ptr )
{
v4 = (__int64)v3;
if ( a2 )
{
while ( 1 )
{
v5 = SLNextItem(v4);
if ( !v5 )
break;
a2(v5);
}
func0(ptr);
}
}
}

original_code:
void SLDestroyValuesAndList( SortedListPtr list, DestroyFuncT destroy ) {
  SortedListIteratorPtr iter = SLCreateIterator(list);
  void * value = ((void *)0);
  if ( !list || !destroy ) { return; }
  while ( ( value = SLNextItem(iter) ) ) {
    destroy ( value );
  }
  SLDestroy( list );
}

canonical_original_code:
void SLDestroyValuesAndList(struct SortedList *list, int (*destroy)(void *)) {
  struct SortedListIterator *iter = SLCreateIterator(list);
  void *value = ((void *)0);
  if ( !list || !destroy ) { return; }
  while ( ( value = SLNextItem(iter) ) ) {
    destroy ( value );
  }
  SLDestroy( list );
}

variable_types:
destroy
int (*)(void *)

variable_types:
value
void *


main

canonical_name: main

repo: eddieborjas/sample-c-project

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+0h] [rbp-18h]
int v5; // [rsp+4h] [rbp-14h]
int v6; // [rsp+8h] [rbp-10h]
int v7; // [rsp+Ch] [rbp-Ch]

puts("Enter four numbers to add");
__isoc99_scanf();
printf("Sum of entered numbers = %d\n", (unsigned int)(v4 + v5 + v7 + v6));
return 0;
}

original_code:
int main()
{
  int a, b, c, d, e;
   printf("Enter four numbers to add\n");
   scanf("%d%d%d%d",&a,&b,&c,&d);
   e = a + b + c + d;
   printf("Sum of entered numbers = %d\n",e);
   return 0;
}

canonical_original_code:
int main()
{
  int a; int b; int c; int d; int e;
   printf("Enter four numbers to add\n");
   scanf("%d%d%d%d",&a,&b,&c,&d);
   e = a + b + c + d;
   printf("Sum of entered numbers = %d\n",e);
   return 0;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: e int


createGenotype

repo: eoinomurchu/CGE

decompiled_code:
_QWORD *createGenotype()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
*v0 = malloc(4LL * config[10]);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
*v0 = malloc(4LL * config[10]);
return v0;
}

original_code:
Genotype *createGenotype() {
  Genotype *genotype = (Genotype *) malloc(sizeof(Genotype));
  genotype->codons = (unsigned int*) malloc(config.maxInitialSize*sizeof(unsigned int));
  return genotype;
}

canonical_original_code:
struct Genotype *createGenotype() {
  struct Genotype *genotype = (Genotype *) malloc(sizeof(Genotype));
  genotype->codons = (unsigned int *) malloc(config.maxInitialSize*sizeof(unsigned int));
  return genotype;
}

variable_types: struct Genotype { unsigned int *codons; unsigned char **mappedSymbols; unsigned int length; unsigned int maxLength; unsigned int encodingLength; } *


printMedsList

decompiled_code:
int __fastcall printMedsList(__int64 a1)
{
int result; // eax
__int64 v2; // rbp
int v3; // ebx

result = *(_DWORD *)a1;
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)a1 - 1;
if ( *(int *)a1 > 0 )
{
do
{
result = printf("Necesita %d de %s\n", *(unsigned int *)(*(_QWORD *)v2 + 8LL), **(const char ***)v2);
v2 = *(_QWORD *)(v2 + 8);
--v3;
}
while ( v3 != -1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax
__int64 v2; // rbp
int v3; // ebx

result = *(_DWORD *)a1;
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)a1 - 1;
if ( *(int *)a1 > 0 )
{
do
{
result = printf("Necesita %d de %s\n", *(unsigned int *)(*(_QWORD *)v2 + 8LL), **(const char ***)v2);
v2 = *(_QWORD *)(v2 + 8);
--v3;
}
while ( v3 != -1 );
}
return result;
}

original_code:
void printMedsList(medList * list) {
 int count = list->nodesCount;
 medNode * actual = list->first;
 while (count-- > 0) {
  printf("Necesita %d de %s\n", actual->med->amountNeeded,
    actual->med->medicineName);
  actual = (medNode*) (actual->next);
 }
}

canonical_original_code:
void printMedsList(struct medList *list) {
 int count = list->nodesCount;
 struct medNode *actual = list->first;
 while (count-- > 0) {
  printf("Necesita %d de %s\n", actual->med->amountNeeded,
    actual->med->medicineName);
  actual = (struct medNode *) (actual->next);
 }
}

variable_types: struct medList { int nodesCount; struct medNode { struct medicine { char *medicineName; int amountNeeded; } *med; struct medNode *next; } *first; } *

variable_types: count int

user_defined_types: struct medList { int nodesCount; struct medNode *first; }

user_defined_types: struct medNode { struct medicine *med; struct medNode *next; }


printData

decompiled_code:
int __fastcall printData(__int64 a1)
{
int v1; // er13
__int64 i; // rbx
__int64 v3; // rbp
int result; // eax

v1 = *(_DWORD *)(a1 + 8);
if ( v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
v3 = **(_QWORD **)(*(_QWORD *)a1 + 8 * i);
printf("Nombre ciudad %d: %s\n", (unsigned int)i, *(const char **)v3);
result = printMedsList(*(_QWORD *)(v3 + 8));
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int v1; // er13
__int64 i; // rbx
__int64 v3; // rbp
int result; // eax

v1 = *(_DWORD *)(a1 + 8);
if ( v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
v3 = **(_QWORD **)(*(_QWORD *)a1 + 8 * i);
printf("Nombre ciudad %d: %s\n", (unsigned int)i, *(const char **)v3);
result = func6(*(_QWORD *)(v3 + 8));
}
}
return result;
}

original_code:
void printData(graph *map) {
 int nodeCount = map->nodeCount;
 int i = 0;
 for (i = 0; i < nodeCount; i++) {
  city * city = map->nodes[i]->info;
  printf("Nombre ciudad %d: %s\n", i, city->cityName);
  printMedsList(city->medicineList);
 }
}

canonical_original_code:
void printData(struct graph *map) {
 int nodeCount = map->nodeCount;
 int i = 0;
 for (i = 0; i < nodeCount; i++) {
  struct city *city = map->nodes[i]->info;
  printf("Nombre ciudad %d: %s\n", i, city->cityName);
  printMedsList(city->medicineList);
 }
}

variable_types: struct graph { struct graphNode { struct city { char *cityName; struct medList { int nodesCount; struct medNode { struct medicine { char *medicineName; int amountNeeded; } *med; struct medNode *next; } *first; } *medicineList; } *info; struct arc { int weight; struct city *neighbour; } **adjList; int arcQty; } **nodes; int nodeCount; } *

variable_types: nodeCount int

variable_types: i int

user_defined_types: struct graph { struct graphNode **nodes; int nodeCount; }

user_defined_types: struct city { char *cityName; struct medList *medicineList; }

user_defined_types: struct graphNode { struct city *info; struct arc **adjList; int arcQty; }


printDistance

decompiled_code:
int __fastcall printDistance(__int64 a1)
{
int v1; // er12
__int64 v2; // r12
__int64 v3; // rbx
int result; // eax

v1 = *(_DWORD *)(a1 + 16);
if ( v1 > 0 )
{
v2 = 8LL * (unsigned int)v1;
v3 = 0LL;
do
{
result = printf(
"Distancia de %s a %s: %d\n",
**(const char ***)a1,
**(const char ***)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + v3) + 8LL),
**(unsigned int **)(*(_QWORD *)(a1 + 8) + v3));
v3 += 8LL;
}
while ( v3 != v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
int v1; // er12
__int64 v2; // r12
__int64 v3; // rbx
int result; // eax

v1 = *(_DWORD *)(a1 + 16);
if ( v1 > 0 )
{
v2 = 8LL * (unsigned int)v1;
v3 = 0LL;
do
{
result = printf(
"Distancia de %s a %s: %d\n",
**(const char ***)a1,
**(const char ***)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + v3) + 8LL),
**(unsigned int **)(*(_QWORD *)(a1 + 8) + v3));
v3 += 8LL;
}
while ( v3 != v2 );
}
return result;
}

original_code:
void printDistance(graphNode *node) {
 int arcQty = node->arcQty;
 int i = 0;
 for (i = 0; i < arcQty; ++i) {
  printf("Distancia de %s a %s: %d\n", node->info->cityName,
    node->adjList[i]->neighbour->cityName, node->adjList[i]->weight);
 }
}

canonical_original_code:
void printDistance(struct graphNode *node) {
 int arcQty = node->arcQty;
 int i = 0;
 for (i = 0; i < arcQty; ++i) {
  printf("Distancia de %s a %s: %d\n", node->info->cityName,
    node->adjList[i]->neighbour->cityName, node->adjList[i]->weight);
 }
}

variable_types: struct graphNode { struct city { char *cityName; struct medList { int nodesCount; struct medNode { struct medicine { char *medicineName; int amountNeeded; } *med; struct medNode *next; } *first; } *medicineList; } *info; struct arc { int weight; struct city *neighbour; } **adjList; int arcQty; } *

variable_types: arcQty int


main

repo: farlepet/bfi

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

puts("BFI v1.00\n------------------");
get_options((unsigned int)argc, argv);
if ( *((_QWORD *)&options + 3) == 1LL )
usage(0LL);
if ( *((_QWORD *)&options + 1) == 1LL )
{
puts("No input file specified.");
usage(1LL);
}
input = fopen(*((const char **)&options + 1), "r");
if ( !input )
{
puts("Couldn't open specified input file.");
usage(1LL);
}
fseek(input, 0LL, 2);
v3 = ftell(input);
fseek(input, 0LL, 0);
file = malloc(v3);
fread(file, v3, 1uLL, input);
bf_interp(file, v3);
free(file);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 printf("BFI v" "1.00" "\n------------------\n");
 get_options(argc, argv);
 if((size_t)options[1].setting == 1) usage(0);
 if((size_t)options[0].setting == 1)
 {
  printf("No input file specified.\n");
  usage(1);
 }
 if(!(input = fopen(options[0].setting, "r")))
 {
  printf("Couldn't open specified input file.\n");
  usage(1);
 }
 fseek(input, 0, 2);
 size_t inputlen = ftell(input);
 fseek(input, 0, 0);
 file = (char *)malloc(inputlen);
 fread(file, inputlen, 1, input);
 bf_interp(file, inputlen);
 free(file);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 printf("BFI v" "1.00" "\n------------------\n");
 get_options(argc, argv);
 if((unsigned long)options[1].setting == 1) usage(0);
 if((unsigned long)options[0].setting == 1)
 {
  printf("No input file specified.\n");
  usage(1);
 }
 if(!(input = fopen(options[0].setting, "r")))
 {
  printf("Couldn't open specified input file.\n");
  usage(1);
 }
 fseek(input, 0, 2);
 unsigned long inputlen = ftell(input);
 fseek(input, 0, 0);
 file = (char *)malloc(inputlen);
 fread(file, inputlen, 1, input);
 bf_interp(file, inputlen);
 free(file);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
inputlen
unsigned long


helpMsg

decompiled_code:
int helpMsg()
{
puts("\x1B[32m==== [Command Available] ====");
puts("\x1B[33md\x1B[0m - \x1B[36mdump pins and regs");
puts("\x1B[33mn\x1B[0m - \x1B[36mnext digit");
printf("\x1B[33m0 or 1\x1B[0m - \x1B[36mbinary key input\n\x1B[35m\x1B[0m");
return printf("\x1B[33mh\x1B[0m - \x1B[36mprint this msg\n\n\x1B[35m\x1B[0m");
}

canonical_decompiled_code:
int func7()
{
puts("\x1B[32m==== [Command Available] ====");
puts("\x1B[33md\x1B[0m - \x1B[36mdump pins and regs");
puts("\x1B[33mn\x1B[0m - \x1B[36mnext digit");
printf("\x1B[33m0 or 1\x1B[0m - \x1B[36mbinary key input\n\x1B[35m\x1B[0m");
return printf("\x1B[33mh\x1B[0m - \x1B[36mprint this msg\n\n\x1B[35m\x1B[0m");
}


decompiled_code:
__int64 __fastcall pin2Dec(__int64 a1, int a2)
{
__int64 v2; // rcx
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = 0LL;
v3 = 0;
do
{
v3 += *(unsigned __int8 *)(a1 + v2) << v2;
++v2;
}
while ( v2 != a2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 v2; // rcx
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = 0LL;
v3 = 0;
do
{
v3 += *(unsigned __int8 *)(a1 + v2) << v2;
++v2;
}
while ( v2 != a2 );
return v3;
}

original_code:
int pin2Dec(pin* pins, int length) {
 int acc = 0;
 int i;
 for (i = 0; i < length; i++) {
  acc += (pins[i] << i);
 }
 return acc;
}

canonical_original_code:
int pin2Dec(unsigned char *pins, int length) {
 int acc = 0;
 int i;
 for (i = 0; i < length; i++) {
  acc += (pins[i] << i);
 }
 return acc;
}

variable_types:
pins
unsigned char *

variable_types: length int

variable_types: acc int


dumpPin

decompiled_code:
int dumpPin()
{
__int64 v0; // rax
unsigned int v1; // eax
const char *v2; // rcx

printf("\x1B[32m==== [Current Pin State] ====\n\x1B[32m");
v0 = pin2Dec((__int64)&PIN_IN_K, 4);
printf(
"\x1B[31mPIN_IN_K:\t%s0b%1d%1d%1d%1d\t(%x)\n",
"\x1B[33m",
HIBYTE(PIN_IN_K),
BYTE2(PIN_IN_K),
BYTE1(PIN_IN_K),
(unsigned __int8)PIN_IN_K,
v0);
v1 = pin2Dec((__int64)&PIN_IN_CK, 2);
printf("\x1B[31mPIN_IN_CK:\t%s0b%1d%1d\t(%d)\n", "\x1B[33m", HIBYTE(PIN_IN_CK), (unsigned __int8)PIN_IN_CK, v1);
v2 = "UNLOCKED";
if ( !PIN_OUT_UL )
v2 = "UNLOCKED" + 2;
printf("\x1B[31mPIN_OUT_UL:\t%s0b%1d\t[%s]\n", "\x1B[33m", (unsigned __int8)PIN_OUT_UL, v2);
printf("\x1B[31mPIN_OUT_E3:\t%s0b%1d\n", "\x1B[33m", (unsigned __int8)PIN_OUT_E3);
return printf("\x1B[31mPIN_OUT_E5:\t%s0b%1d\n", "\x1B[33m", (unsigned __int8)PIN_OUT_E5);
}

canonical_decompiled_code:
int func9()
{
__int64 v0; // rax
unsigned int v1; // eax
const char *v2; // rcx

printf("\x1B[32m==== [Current Pin State] ====\n\x1B[32m");
v0 = func8((__int64)&PIN_IN_K, 4);
printf(
"\x1B[31mPIN_IN_K:\t%s0b%1d%1d%1d%1d\t(%x)\n",
"\x1B[33m",
HIBYTE(PIN_IN_K),
BYTE2(PIN_IN_K),
BYTE1(PIN_IN_K),
(unsigned __int8)PIN_IN_K,
v0);
v1 = func8((__int64)&PIN_IN_CK, 2);
printf("\x1B[31mPIN_IN_CK:\t%s0b%1d%1d\t(%d)\n", "\x1B[33m", HIBYTE(PIN_IN_CK), (unsigned __int8)PIN_IN_CK, v1);
v2 = "UNLOCKED";
if ( !PIN_OUT_UL )
v2 = "UNLOCKED" + 2;
printf("\x1B[31mPIN_OUT_UL:\t%s0b%1d\t[%s]\n", "\x1B[33m", (unsigned __int8)PIN_OUT_UL, v2);
printf("\x1B[31mPIN_OUT_E3:\t%s0b%1d\n", "\x1B[33m", (unsigned __int8)PIN_OUT_E3);
return printf("\x1B[31mPIN_OUT_E5:\t%s0b%1d\n", "\x1B[33m", (unsigned __int8)PIN_OUT_E5);
}

original_code:
void dumpPin() {
 printf("\x1B[32m" "==== [Current Pin State] ====\n" "\x1B[32m");
 printf("\x1B[31m" "PIN_IN_K:\t%s0b%1d%1d%1d%1d\t(%x)\n", "\x1B[33m",
             PIN_IN_K[3],
             PIN_IN_K[2],
             PIN_IN_K[1],
             PIN_IN_K[0],
             pin2Dec(PIN_IN_K, 4));
 printf("\x1B[31m" "PIN_IN_CK:\t%s0b%1d%1d\t(%d)\n", "\x1B[33m", PIN_IN_CK[1], PIN_IN_CK[0], pin2Dec(PIN_IN_CK, 2));
 printf("\x1B[31m" "PIN_OUT_UL:\t%s0b%1d\t[%s]\n", "\x1B[33m", PIN_OUT_UL, PIN_OUT_UL?"UNLOCKED":"LOCKED");
 printf("\x1B[31m" "PIN_OUT_E3:\t%s0b%1d\n", "\x1B[33m", PIN_OUT_E3);
 printf("\x1B[31m" "PIN_OUT_E5:\t%s0b%1d\n", "\x1B[33m", PIN_OUT_E5);
}


dumpReg

decompiled_code:
int dumpReg()
{
unsigned int v0; // er12
unsigned int v1; // ebp
unsigned int v2; // ebx
unsigned int v3; // eax
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // eax
unsigned int v8; // eax

printf("\x1B[32m==== [Current Reg State] ====\n\x1B[32m");
v0 = pin2Dec(4210812LL, 4);
v1 = pin2Dec((__int64)&qword_404078, 4);
v2 = pin2Dec(4210804LL, 4);
v3 = pin2Dec((__int64)&KEY, 4);
printf("\x1B[31mKEY:\t%s0x%x%x%x%x\n", "\x1B[33m", v3, v2, v1, v0);
v4 = pin2Dec(4210796LL, 4);
v5 = pin2Dec((__int64)&qword_404068, 4);
v6 = pin2Dec(4210788LL, 4);
v7 = pin2Dec((__int64)&BUF, 4);
printf("\x1B[31mBUF:\t%s0x%x%x%x%x\n", "\x1B[33m", v7, v6, v5, v4);
v8 = pin2Dec((__int64)&ERR, 3);
return printf("\x1B[31mERR:\t%s0x%x\t(%d)\n\x1B[0m", "\x1B[33m", v8, v8);
}

canonical_decompiled_code:
int func10()
{
unsigned int v0; // er12
unsigned int v1; // ebp
unsigned int v2; // ebx
unsigned int v3; // eax
unsigned int v4; // er12
unsigned int v5; // ebp
unsigned int v6; // ebx
unsigned int v7; // eax
unsigned int v8; // eax

printf("\x1B[32m==== [Current Reg State] ====\n\x1B[32m");
v0 = func8(4210812LL, 4);
v1 = func8((__int64)&qword_404078, 4);
v2 = func8(4210804LL, 4);
v3 = func8((__int64)&KEY, 4);
printf("\x1B[31mKEY:\t%s0x%x%x%x%x\n", "\x1B[33m", v3, v2, v1, v0);
v4 = func8(4210796LL, 4);
v5 = func8((__int64)&qword_404068, 4);
v6 = func8(4210788LL, 4);
v7 = func8((__int64)&BUF, 4);
printf("\x1B[31mBUF:\t%s0x%x%x%x%x\n", "\x1B[33m", v7, v6, v5, v4);
v8 = func8((__int64)&ERR, 3);
return printf("\x1B[31mERR:\t%s0x%x\t(%d)\n\x1B[0m", "\x1B[33m", v8, v8);
}


regCmp

decompiled_code:
__int64 __fastcall regCmp(int a1, int a2, int a3)
{
__int64 v4; // rax
bool v5; // dl
bool v6; // si
char v8; // [rsp+1h] [rbp-9h]
int v9[2]; // [rsp+2h] [rbp-8h]

v9[1] = a1;
v9[0] = a2;
if ( a3 <= 0 )
return 1LL;
v4 = 1LL;
do
{
v5 = *((_BYTE *)v9 + v4 + 3) == (unsigned __int8)*(&v8 + v4);
v6 = a3 > (int)v4++;
}
while ( v5 && v6 );
return v5;
}

original_code:
int regCmp(reg A, reg B, int length) {
 int i,match=1;
 for (i=0; i<length && match; i++) match = A.d[i] == B.d[i];
 return match;
}

canonical_original_code:
int regCmp(struct registers A, struct registers B, int length) {
 int i; int match = 1;
 for (i=0; i<length && match; i++) match = A.d[i] == B.d[i];
 return match;
}

variable_types: struct registers { unsigned char d[4]; }

variable_types:
B
struct registers

variable_types: match int


reset

decompiled_code:
void reset()
{
PIN_IN_K = 0;
PIN_IN_CK = 0;
KEY = 0LL;
qword_404078 = 0LL;
BUF = 0LL;
qword_404068 = 0LL;
ERR = 0;
PIN_OUT_UL = 1;
PIN_OUT_E5 = 0;
PIN_OUT_E3 = 0;
}

canonical_decompiled_code:
void func12()
{
PIN_IN_K = 0;
PIN_IN_CK = 0;
KEY = 0LL;
qword_404078 = 0LL;
BUF = 0LL;
qword_404068 = 0LL;
ERR = 0;
PIN_OUT_UL = 1;
PIN_OUT_E5 = 0;
PIN_OUT_E3 = 0;
}

original_code:
void reset() {
 bzero(PIN_IN_K, sizeof(pin) * 4);
 bzero(PIN_IN_CK, sizeof(pin) * 2);
 bzero(KEY, sizeof(struct registers) * 4);
 bzero(BUF, sizeof(struct registers) * 4);
 bzero(&ERR, sizeof(struct registers) * 1);
 PIN_OUT_UL = 1;
 PIN_OUT_E5 = 0;
 PIN_OUT_E3 = 0;
}

user_defined_types: struct registers { unsigned char d[4]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er14
int v5; // er12
char v6; // r15
int v7; // ebx
int v8; // ebp
int v9; // eax
char v10; // dl
__int64 v11; // rax
int v12; // eax
char v13; // dl
__int64 v14; // rax
int v15; // er12
int v16; // eax

printf("\x1B[35m==== [VLSI Final Project - Combination Lock Simulator] ====\n\x1B[0m");
helpMsg();
printf("Initializinging...\n\x1B[0m");
reset();
dumpPin();
dumpReg();
v3 = pin2Dec((__int64)&PIN_IN_CK, 2);
v4 = (unsigned __int8)PIN_OUT_E5;
if ( !PIN_OUT_E5 )
{
v5 = v3;
v6 = PIN_OUT_E5;
v7 = 3;
do
{
printf("\r> ");
v8 = (unsigned __int8)PIN_OUT_UL;
if ( PIN_OUT_UL )
{
v9 = (unsigned __int8)getchar();
if ( (_BYTE)v9 == 104 )
goto LABEL_18;
if ( v9 > 104 )
{
if ( v9 == 110 )
{
PIN_IN_K = 0;
if ( (_BYTE)++v5 == 4 )
{
PIN_OUT_UL = 0;
v5 = v4;
}
HIBYTE(PIN_IN_CK) = (unsigned __int8)v5 >> 1;
LOBYTE(PIN_IN_CK) = v5 & 1;
}
goto LABEL_5;
}
if ( v9 <= 49 )
{
if ( v9 > 47 )
{
v10 = v9 - 48;
v11 = (unsigned __int8)v7;
*((_BYTE *)&PIN_IN_K + (unsigned __int8)v7--) = v10;
*((_BYTE *)&KEY + 4 * (unsigned __int8)v5 + v11) = v10;
}
goto LABEL_5;
}
if ( v9 == 100 )
goto LABEL_13;
}
else
{
v12 = (unsigned __int8)getchar();
if ( (_BYTE)v12 == 104 )
{
LABEL_18:
helpMsg();
goto LABEL_5;
}
if ( v12 > 104 )
{
if ( v12 == 110 )
{
PIN_IN_K = 0;
if ( (_BYTE)++v5 == 4 )
{
v15 = 0;
do
{
v16 = regCmp(*((_DWORD *)&KEY + v15), *((_DWORD *)&BUF + v15), 4);
++v15;
}
while ( v15 <= 3 && v16 );
if ( v16 )
{
ERR = 0;
PIN_OUT_UL = 1;
v6 = v8;
}
else
{
BYTE2(ERR) = (++v6 & 4) != 0;
BYTE1(ERR) = (v6 & 2) != 0;
LOBYTE(ERR) = v6 & 1;
if ( v6 == 3 )
{
PIN_OUT_E3 = 1;
}
else if ( v6 == 5 )
{
PIN_OUT_E3 = 0;
PIN_OUT_E5 = 1;
}
}
BUF = 0LL;
qword_404068 = 0LL;
v5 = v8;
}
HIBYTE(PIN_IN_CK) = (unsigned __int8)v5 >> 1;
LOBYTE(PIN_IN_CK) = v5 & 1;
}
goto LABEL_5;
}
if ( v12 <= 49 )
{
if ( v12 > 47 )
{
v13 = v12 - 48;
v14 = (unsigned __int8)v7;
*((_BYTE *)&PIN_IN_K + (unsigned __int8)v7--) = v13;
*((_BYTE *)&BUF + 4 * (unsigned __int8)v5 + v14) = v13;
}
goto LABEL_5;
}
if ( v12 == 100 )
{
LABEL_13:
dumpPin();
dumpReg();
goto LABEL_5;
}
}
LABEL_5:
if ( (_BYTE)v7 == 0xFF )
v7 = 3;
}
while ( !PIN_OUT_E5 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er14
int v5; // er12
char v6; // r15
int v7; // ebx
int v8; // ebp
int v9; // eax
char v10; // dl
__int64 v11; // rax
int v12; // eax
char v13; // dl
__int64 v14; // rax
int v15; // er12
int v16; // eax

printf("\x1B[35m==== [VLSI Final Project - Combination Lock Simulator] ====\n\x1B[0m");
func7();
printf("Initializinging...\n\x1B[0m");
func12();
func9();
func10();
v3 = func8((__int64)&PIN_IN_CK, 2);
v4 = (unsigned __int8)PIN_OUT_E5;
if ( !PIN_OUT_E5 )
{
v5 = v3;
v6 = PIN_OUT_E5;
v7 = 3;
do
{
printf("\r> ");
v8 = (unsigned __int8)PIN_OUT_UL;
if ( PIN_OUT_UL )
{
v9 = (unsigned __int8)getchar();
if ( (_BYTE)v9 == 104 )
goto LABEL_18;
if ( v9 > 104 )
{
if ( v9 == 110 )
{
PIN_IN_K = 0;
if ( (_BYTE)++v5 == 4 )
{
PIN_OUT_UL = 0;
v5 = v4;
}
HIBYTE(PIN_IN_CK) = (unsigned __int8)v5 >> 1;
LOBYTE(PIN_IN_CK) = v5 & 1;
}
goto LABEL_5;
}
if ( v9 <= 49 )
{
if ( v9 > 47 )
{
v10 = v9 - 48;
v11 = (unsigned __int8)v7;
*((_BYTE *)&PIN_IN_K + (unsigned __int8)v7--) = v10;
*((_BYTE *)&KEY + 4 * (unsigned __int8)v5 + v11) = v10;
}
goto LABEL_5;
}
if ( v9 == 100 )
goto LABEL_13;
}
else
{
v12 = (unsigned __int8)getchar();
if ( (_BYTE)v12 == 104 )
{
LABEL_18:
func7();
goto LABEL_5;
}
if ( v12 > 104 )
{
if ( v12 == 110 )
{
PIN_IN_K = 0;
if ( (_BYTE)++v5 == 4 )
{
v15 = 0;
do
{
v16 = func11(*((_DWORD *)&KEY + v15), *((_DWORD *)&BUF + v15), 4);
++v15;
}
while ( v15 <= 3 && v16 );
if ( v16 )
{
ERR = 0;
PIN_OUT_UL = 1;
v6 = v8;
}
else
{
BYTE2(ERR) = (++v6 & 4) != 0;
BYTE1(ERR) = (v6 & 2) != 0;
LOBYTE(ERR) = v6 & 1;
if ( v6 == 3 )
{
PIN_OUT_E3 = 1;
}
else if ( v6 == 5 )
{
PIN_OUT_E3 = 0;
PIN_OUT_E5 = 1;
}
}
BUF = 0LL;
qword_404068 = 0LL;
v5 = v8;
}
HIBYTE(PIN_IN_CK) = (unsigned __int8)v5 >> 1;
LOBYTE(PIN_IN_CK) = v5 & 1;
}
goto LABEL_5;
}
if ( v12 <= 49 )
{
if ( v12 > 47 )
{
v13 = v12 - 48;
v14 = (unsigned __int8)v7;
*((_BYTE *)&PIN_IN_K + (unsigned __int8)v7--) = v13;
*((_BYTE *)&BUF + 4 * (unsigned __int8)v5 + v14) = v13;
}
goto LABEL_5;
}
if ( v12 == 100 )
{
LABEL_13:
func9();
func10();
goto LABEL_5;
}
}
LABEL_5:
if ( (_BYTE)v7 == 0xFF )
v7 = 3;
}
while ( !PIN_OUT_E5 );
}
return 0;
}

original_code:
int main(int argc, char** argv) {
 uint1 input;
 uint1 curPos;
 uint1 errCount = 0;
 uint1 bitpos=3;
 printf("\x1B[35m" "==== [VLSI Final Project - Combination Lock Simulator] ====\n" "\x1B[0m");
 helpMsg();
 printf("Initializinging...\n" "\x1B[0m");
 reset();
 dumpPin();
 dumpReg();
 curPos = pin2Dec(PIN_IN_CK, 2);
 while (1 && !PIN_OUT_E5) {
  printf("\r> ");
  if ( PIN_OUT_UL) {
   input = getchar();
   switch (input) {
    case 'd':
     dumpPin();
     dumpReg();
     break;
    case 'h':
     helpMsg();
     break;
    case 'n':
     bzero(PIN_IN_K, sizeof(pin) * 4);
     if (++curPos == 4) {
      PIN_OUT_UL = 0;
      curPos = 0;
     }
     PIN_IN_CK[1] = (pin) (curPos / 2);
     PIN_IN_CK[0] = (pin) (curPos % 2);
     break;
    case '0':
    case '1':
     PIN_IN_K[bitpos] = (pin) (input-'0');
     KEY[curPos].d[bitpos--] = PIN_IN_K[bitpos];
   }
  } else {
   input = getchar();
   switch (input) {
    case 'd':
     dumpPin();
     dumpReg();
     break;
    case 'h':
     helpMsg();
     break;
    case 'n':
     bzero(PIN_IN_K, sizeof(pin) * 4);
     if (++curPos == 4) {
      int i, match=1;
      for (i=0; i<4 && match; i++) match = regCmp(KEY[i], BUF[i], 4);
      if (!match) {
       errCount++;
       ERR.d[2]=(errCount >> 2) & 1;;
       ERR.d[1]=(errCount >> 1) & 1;
       ERR.d[0]=errCount & 1;
      } else {
       errCount = 0;
       bzero(&ERR, sizeof(struct registers));
       PIN_OUT_UL = 1;
      }
      if (errCount == 3) {
       PIN_OUT_E3 = 1;
      } else if (errCount == 5) {
       PIN_OUT_E3 = 0;
       PIN_OUT_E5 = 1;
      }
      curPos = 0;
      bzero(BUF, sizeof(struct registers) * 4);
     }
     PIN_IN_CK[1] = (pin) (curPos / 2);
     PIN_IN_CK[0] = (pin) (curPos % 2);
     break;
    case '0':
    case '1':
     PIN_IN_K[bitpos] = (pin) (input-'0');
     BUF[curPos].d[bitpos--] = PIN_IN_K[bitpos];
   }
  }
  if (bitpos == 255) bitpos = 3;
 }
}

canonical_original_code:
int main(int argc, char **argv) {
 unsigned char input;
 unsigned char curPos;
 unsigned char errCount = 0;
 unsigned char bitpos = 3;
 printf("\x1B[35m" "==== [VLSI Final Project - Combination Lock Simulator] ====\n" "\x1B[0m");
 helpMsg();
 printf("Initializinging...\n" "\x1B[0m");
 reset();
 dumpPin();
 dumpReg();
 curPos = pin2Dec(PIN_IN_CK, 2);
 while (1 && !PIN_OUT_E5) {
  printf("\r> ");
  if ( PIN_OUT_UL) {
   input = getchar();
   switch (input) {
    case 'd':
     dumpPin();
     dumpReg();
     break;
    case 'h':
     helpMsg();
     break;
    case 'n':
     bzero(PIN_IN_K, sizeof(pin) * 4);
     if (++curPos == 4) {
      PIN_OUT_UL = 0;
      curPos = 0;
     }
     PIN_IN_CK[1] = (pin) (curPos / 2);
     PIN_IN_CK[0] = (pin) (curPos % 2);
     break;
    case '0':
    case '1':
     PIN_IN_K[bitpos] = (pin) (input-'0');
     KEY[curPos].d[bitpos--] = PIN_IN_K[bitpos];
   }
  } else {
   input = getchar();
   switch (input) {
    case 'd':
     dumpPin();
     dumpReg();
     break;
    case 'h':
     helpMsg();
     break;
    case 'n':
     bzero(PIN_IN_K, sizeof(pin) * 4);
     if (++curPos == 4) {
      int i; int match = 1;
      for (i=0; i<4 && match; i++) match = regCmp(KEY[i], BUF[i], 4);
      if (!match) {
       errCount++;
       ERR.d[2]=(errCount >> 2) & 1;;
       ERR.d[1]=(errCount >> 1) & 1;
       ERR.d[0]=errCount & 1;
      } else {
       errCount = 0;
       bzero(&ERR, sizeof(struct registers));
       PIN_OUT_UL = 1;
      }
      if (errCount == 3) {
       PIN_OUT_E3 = 1;
      } else if (errCount == 5) {
       PIN_OUT_E3 = 0;
       PIN_OUT_E5 = 1;
      }
      curPos = 0;
      bzero(BUF, sizeof(struct registers) * 4);
     }
     PIN_IN_CK[1] = (pin) (curPos / 2);
     PIN_IN_CK[0] = (pin) (curPos % 2);
     break;
    case '0':
    case '1':
     PIN_IN_K[bitpos] = (pin) (input-'0');
     BUF[curPos].d[bitpos--] = PIN_IN_K[bitpos];
   }
  }
  if (bitpos == 255) bitpos = 3;
 }
}

variable_types:
input
unsigned char

variable_types:
curPos
unsigned char

variable_types:
errCount
unsigned char

variable_types:
bitpos
unsigned char


repo: gamelinux/cxtracker

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

*(_WORD *)a1 = a3;
result = 32LL;
if ( a3 != 2 )
result = 4294967168LL;
*(_BYTE *)(a1 + 2) = result;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

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

*(_WORD *)a1 = a3;
result = 32LL;
if ( a3 != 2 )
result = 4294967168LL;
*(_BYTE *)(a1 + 2) = result;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void ip_set_raw_with_pointer_copy(ip_t *dst, const void *src, int family)
{
    dst->family = family;
    dst->bits = (family == 2) ? 32 : 128;
    dst->addr = (ip_addr_t *)src;
}

canonical_original_code:
void ip_set_raw_with_pointer_copy(struct _ip_s *dst, void *src, int family)
{
    dst->family = family;
    dst->bits = (family == 2) ? 32 : 128;
    dst->addr = (struct _ip_addr_s *)src;
}

variable_types: struct _ip_s { short family; unsigned char bits; struct _ip_addr_s { union { unsigned char u_addr8[16]; unsigned short u_addr16[8]; unsigned int u_addr32[4]; unsigned long u_addr64[2]; } ip; } *addr; } *

variable_types:
src
void *

variable_types: family int

user_defined_types: struct _ip_s { short family; unsigned char bits; struct _ip_addr_s *addr; }


decompiled_code:
void __fastcall ip_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void ip_free(ip_t *ip)
{
    if( ((void *)0) != ip )
    {
        if( ((void *)0) != ip->addr )
            free(ip->addr);
        free(ip);
    };
}

canonical_original_code:
void ip_free(struct _ip_s *ip)
{
    if( ((void *)0) != ip )
    {
        if( ((void *)0) != ip->addr )
            free(ip->addr);
        free(ip);
    };
}

user_defined_types: struct _ip_addr_s { union { unsigned char u_addr8[16]; unsigned short u_addr16[8]; unsigned int u_addr32[4]; unsigned long u_addr64[2]; } ip; }


decompiled_code:
void *__fastcall ip_alloc_raw(const __m128i *a1, int a2)
{
void *v2; // rbx
void *v3; // rax

if ( !a1 )
return 0LL;
v2 = 0LL;
if ( (a2 & 0xFFFFFFF7) == 2 )
{
v3 = calloc(1uLL, 0x10uLL);
v2 = v3;
if ( v3 )
ip_set_raw_with_memcpy((__int64)v3, a1, a2);
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func6(const __m128i *a1, int a2)
{
void *v2; // rbx
void *v3; // rax

if ( !a1 )
return 0LL;
v2 = 0LL;
if ( (a2 & 0xFFFFFFF7) == 2 )
{
v3 = calloc(1uLL, 0x10uLL);
v2 = v3;
if ( v3 )
func2((__int64)v3, a1, a2);
}
return v2;
}

original_code:
ip_t *ip_alloc_raw(const void *ip, int family)
{
    ip_t *ret;
    if( ((void *)0) == ip || (family != 2 && family != 10) )
        return ((void *)0);
    if( (ret=calloc(1, sizeof(ip_t))) == ((void *)0) )
        return ((void *)0);
    ip_set_raw_with_memcpy(ret, ip, family);
    return ret;
}

canonical_original_code:
struct _ip_s *ip_alloc_raw(void *ip, int family)
{
    struct _ip_s *ret;
    if( ((void *)0) == ip || (family != 2 && family != 10) )
        return ((void *)0);
    if( (ret=calloc(1, sizeof(ip_t))) == ((void *)0) )
        return ((void *)0);
    ip_set_raw_with_memcpy(ret, ip, family);
    return ret;
}

variable_types:
ip
void *

return_type: struct _ip_s { short family; unsigned char bits; struct _ip_addr_s { union { unsigned char u_addr8[16]; unsigned short u_addr16[8]; unsigned int u_addr32[4]; unsigned long u_addr64[2]; } ip; } *addr; } *


decompiled_code:
__int64 __fastcall ip_init(_QWORD *a1, int a2)
{
__int64 result; // rax

if ( !a1 )
return 1LL;
if ( a2 == 2 )
{
*a1 = ip_set_raw_with_memcpy;
result = 0LL;
}
else if ( a2 == 1 )
{
*a1 = ip_set_raw_with_pointer_copy;
result = 0LL;
}
else
{
result = 1LL;
if ( a2 == 4 )
{
*a1 = ip_set_raw_with_obfuscate;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2)
{
__int64 result; // rax

if ( !a1 )
return 1LL;
if ( a2 == 2 )
{
*a1 = ip_set_raw_with_memcpy;
result = 0LL;
}
else if ( a2 == 1 )
{
*a1 = ip_set_raw_with_pointer_copy;
result = 0LL;
}
else
{
result = 1LL;
if ( a2 == 4 )
{
*a1 = ip_set_raw_with_obfuscate;
result = 0LL;
}
}
return result;
}

original_code:
int ip_init(ip_config_t *config, int mode)
{
    if( ((void *)0) == config )
        return 1;
    if( mode == 0x02 )
    {
        config->set = (void *)&ip_set_raw_with_memcpy;
        return 0;
    }
    if( mode == 0x01 )
    {
        config->set = (void *)&ip_set_raw_with_pointer_copy;
        return 0;
    }
    if( mode == 0x04 )
    {
        config->set = (void *)&ip_set_raw_with_obfuscate;
        return 0;
    }
    return 1;
}

canonical_original_code:
int ip_init(struct _ip_config_s *config, int mode)
{
    if( ((void *)0) == config )
        return 1;
    if( mode == 0x02 )
    {
        config->set = (void *)&ip_set_raw_with_memcpy;
        return 0;
    }
    if( mode == 0x01 )
    {
        config->set = (void *)&ip_set_raw_with_pointer_copy;
        return 0;
    }
    if( mode == 0x04 )
    {
        config->set = (void *)&ip_set_raw_with_obfuscate;
        return 0;
    }
    return 1;
}

variable_types: struct _ip_config_s { void (*set)(struct _ip_s { short family; unsigned char bits; struct _ip_addr_s { union { unsigned char u_addr8[16]; unsigned short u_addr16[8]; unsigned int u_addr32[4]; unsigned long u_addr64[2]; } ip; } *addr; } *, void *, int); } *

variable_types: mode int

user_defined_types: struct _ip_config_s { void (*set)(struct _ip_s *, void *, int); }


decompiled_code:
__int64 __fastcall ip_set(__int64 (__fastcall **a1)(__int64, __int64, _QWORD), __int64 a2, __int64 a3, unsigned int a4)
{
return (*a1)(a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 (__fastcall **a1)(__int64, __int64, _QWORD), __int64 a2, __int64 a3, unsigned int a4)
{
return (*a1)(a2, a3, a4);
}

original_code:
void ip_set(ip_config_t *config, ip_t *dst, const void *src, int family)
{
    config->set(dst, src, family);
}

canonical_original_code:
void ip_set(struct _ip_config_s *config, struct _ip_s *dst, void *src, int family)
{
    config->set(dst, src, family);
}

variable_types:
dst
struct _ip_s *


decompiled_code:
__int64 __fastcall ip_pton(__int64 a1, const char *a2)
{
char *v3; // rax
char *v4; // rbx
int v5; // er13
unsigned int v6; // ebx
struct addrinfo *v7; // rdi
int v8; // eax
struct addrinfo v10; // [rsp+0h] [rbp-478h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-440h] BYREF
char dest[1080]; // [rsp+40h] [rbp-438h] BYREF

v3 = strchr(a2, 47);
if ( v3 )
{
v4 = v3;
v5 = atoi(v3);
}
else
{
v4 = (char *)&a2[strlen(a2)];
v5 = -1;
}
strncpy(dest, a2, v4 - a2);
*(_QWORD *)&v10.ai_flags = 4LL;
*(_QWORD *)&v10.ai_socktype = 0LL;
*(_QWORD *)&v10.ai_addrlen = 0LL;
v10.ai_addr = 0LL;
v10.ai_canonname = 0LL;
v10.ai_next = 0LL;
v6 = getaddrinfo(a2, 0LL, &v10, &pai);
if ( !v6 )
{
v7 = pai;
*(_WORD *)a1 = pai->ai_family;
if ( v5 < 0 )
{
LOBYTE(v5) = 32;
if ( v7->ai_family != 2 )
LOBYTE(v5) = 0x80;
}
*(_BYTE *)(a1 + 2) = v5;
v8 = v7->ai_family;
if ( v8 == 2 )
{
memcpy(*(void **)(a1 + 8), &v7->ai_addr->sa_data[2], v7->ai_addrlen);
}
else if ( v8 == 10 )
{
memcpy(*(void **)(a1 + 8), &v7->ai_addr->sa_data[6], v7->ai_addrlen);
}
else
{
freeaddrinfo(v7);
v6 = -6;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2)
{
char *v3; // rax
char *v4; // rbx
int v5; // er13
unsigned int v6; // ebx
struct addrinfo *v7; // rdi
int v8; // eax
struct addrinfo v10; // [rsp+0h] [rbp-478h] BYREF
struct addrinfo *pai; // [rsp+38h] [rbp-440h] BYREF
char dest[1080]; // [rsp+40h] [rbp-438h] BYREF

v3 = strchr(a2, 47);
if ( v3 )
{
v4 = v3;
v5 = atoi(v3);
}
else
{
v4 = (char *)&a2[strlen(a2)];
v5 = -1;
}
strncpy(dest, a2, v4 - a2);
*(_QWORD *)&v10.ai_flags = 4LL;
*(_QWORD *)&v10.ai_socktype = 0LL;
*(_QWORD *)&v10.ai_addrlen = 0LL;
v10.ai_addr = 0LL;
v10.ai_canonname = 0LL;
v10.ai_next = 0LL;
v6 = getaddrinfo(a2, 0LL, &v10, &pai);
if ( !v6 )
{
v7 = pai;
*(_WORD *)a1 = pai->ai_family;
if ( v5 < 0 )
{
LOBYTE(v5) = 32;
if ( v7->ai_family != 2 )
LOBYTE(v5) = 0x80;
}
*(_BYTE *)(a1 + 2) = v5;
v8 = v7->ai_family;
if ( v8 == 2 )
{
memcpy(*(void **)(a1 + 8), &v7->ai_addr->sa_data[2], v7->ai_addrlen);
}
else if ( v8 == 10 )
{
memcpy(*(void **)(a1 + 8), &v7->ai_addr->sa_data[6], v7->ai_addrlen);
}
else
{
freeaddrinfo(v7);
v6 = -6;
}
}
return v6;
}

original_code:
int ip_pton(ip_t *ip, const char *name)
{
    const char *mask;
    char ip_buf[1025];
    int bits = -1;
    if( (mask=strchr(name, (int)'/')) == ((void *)0) )
        mask = name + strlen(name);
    else
        bits = atoi(mask);
    strncpy(ip_buf, name, mask-name);
    struct addrinfo *ai;
    struct addrinfo hints;
    memset(&hints, '\0', sizeof(hints));
    hints.ai_flags = 0x0004;
    hints.ai_family = 0;
    int ret;
    if( (ret=getaddrinfo(name, ((void *)0), &hints, &ai)) != 0 )
        return ret;
    ip->family = ai->ai_family;
    if( bits < 0 )
        bits = (ai->ai_family == 2) ? 32 : 128;
    ip->bits = (uint8_t)bits;
    if( ai->ai_family == 2 )
        memcpy(ip->addr->ip.u_addr8, &((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr, ai->ai_addrlen);
    else if( ai->ai_family == 10 )
        memcpy(ip->addr->ip.u_addr8, ((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr.__in6_u.__u6_addr8, ai->ai_addrlen);
    else
    {
        freeaddrinfo(ai);
        return -6;
    }
    return 0;
}

canonical_original_code:
int ip_pton(struct _ip_s *ip, char *name)
{
    char *mask;
    char ip_buf[1025];
    int bits = -1;
    if( (mask=strchr(name, (int)'/')) == ((void *)0) )
        mask = name + strlen(name);
    else
        bits = atoi(mask);
    strncpy(ip_buf, name, mask-name);
    struct addrinfo *ai;
    struct addrinfo hints;
    memset(&hints, '\0', sizeof(hints));
    hints.ai_flags = 0x0004;
    hints.ai_family = 0;
    int ret;
    if( (ret=getaddrinfo(name, ((void *)0), &hints, &ai)) != 0 )
        return ret;
    ip->family = ai->ai_family;
    if( bits < 0 )
        bits = (ai->ai_family == 2) ? 32 : 128;
    ip->bits = (unsigned char)bits;
    if( ai->ai_family == 2 )
        memcpy(ip->addr->ip.u_addr8, &((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr, ai->ai_addrlen);
    else if( ai->ai_family == 10 )
        memcpy(ip->addr->ip.u_addr8, ((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr.__in6_u.__u6_addr8, ai->ai_addrlen);
    else
    {
        freeaddrinfo(ai);
        return -6;
    }
    return 0;
}

variable_types:
name
char *

variable_types:
mask
char *

variable_types: bits int

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

variable_types: ret int

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

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
void *__fastcall ip_alloc(const char *a1)
{
void *v1; // rax
void *v2; // rbx

if ( !a1 )
return 0LL;
v1 = calloc(1uLL, 0x10uLL);
v2 = v1;
if ( v1 && (unsigned int)ip_pton((__int64)v1, a1) != 1 )
{
ip_free(v2);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func10(const char *a1)
{
void *v1; // rax
void *v2; // rbx

if ( !a1 )
return 0LL;
v1 = calloc(1uLL, 0x10uLL);
v2 = v1;
if ( v1 && (unsigned int)func9((__int64)v1, a1) != 1 )
{
func5(v2);
v2 = 0LL;
}
return v2;
}

original_code:
ip_t *ip_alloc(const char *ip)
{
    ip_t *ret;
    if( ((void *)0) == ip )
        return ((void *)0);
    if( (ret=calloc(1, sizeof(ip_t))) == ((void *)0) )
        return ((void *)0);
    if( ip_pton(ret, ip) != 1 )
    {
        ip_free(ret);
        return ((void *)0);
    }
    return ret;
}

canonical_original_code:
struct _ip_s *ip_alloc(char *ip)
{
    struct _ip_s *ret;
    if( ((void *)0) == ip )
        return ((void *)0);
    if( (ret=calloc(1, sizeof(ip_t))) == ((void *)0) )
        return ((void *)0);
    if( ip_pton(ret, ip) != 1 )
    {
        ip_free(ret);
        return ((void *)0);
    }
    return ret;
}

variable_types:
ip
char *


decompiled_code:
char *__fastcall ip_ntops(__int64 a1, char a2)
{
if ( ip_ntop(a1, ip_buf_0, 1025, a2) )
snprintf(ip_buf_0, 0x401uLL, "%s%c", "unknown", 0LL);
return ip_buf_0;
}

canonical_decompiled_code:
char *__fastcall func12(__int64 a1, char a2)
{
if ( func11(a1, ip_buf_0, 1025, a2) )
snprintf(ip_buf_0, 0x401uLL, "%s%c", "unknown", 0LL);
return ip_buf_0;
}

original_code:
const char *ip_ntops(const ip_t *ip, int flags)
{
    static char ip_buf[1025];
    if( ip_ntop(ip, ip_buf, 1025, flags) )
      snprintf(ip_buf, 1025, "%s%c", "unknown", '\0');
    return ip_buf;
}

canonical_original_code:
char *ip_ntops(struct _ip_s *ip, int flags)
{
    static char ip_buf[1025];
    if( ip_ntop(ip, ip_buf, 1025, flags) )
      snprintf(ip_buf, 1025, "%s%c", "unknown", '\0');
    return ip_buf;
}

variable_types: flags int

return_type: char *


decompiled_code:
__int64 __fastcall ip_isloopback(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
unsigned int v3; // edi
int v4; // edx

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
if ( (unsigned __int16)ip_family_get((unsigned __int16 *)a1) == 2 )
return *(_BYTE *)v1 == 127;
result = 0LL;
if ( !*(_QWORD *)v1 )
{
v3 = *(_DWORD *)(v1 + 8);
if ( v3 )
{
v4 = _bswap_32(v3);
result = 0LL;
if ( v4 == 0xFFFF )
result = *(_BYTE *)(v1 + 12) == 127;
}
else
{
result = 1LL;
if ( *(_BYTE *)(v1 + 12) != 127 )
result = (unsigned int)_bswap_32(*(_DWORD *)(v1 + 12)) == 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
unsigned int v3; // edi
int v4; // edx

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
if ( (unsigned __int16)func0((unsigned __int16 *)a1) == 2 )
return *(_BYTE *)v1 == 127;
result = 0LL;
if ( !*(_QWORD *)v1 )
{
v3 = *(_DWORD *)(v1 + 8);
if ( v3 )
{
v4 = func4(v3);
result = 0LL;
if ( v4 == 0xFFFF )
result = *(_BYTE *)(v1 + 12) == 127;
}
else
{
result = 1LL;
if ( *(_BYTE *)(v1 + 12) != 127 )
result = (unsigned int)func4(*(_DWORD *)(v1 + 12)) == 1;
}
}
return result;
}

original_code:
int ip_isloopback(const ip_t *ip)
{
    if( ((void *)0) == ip || ((void *)0) == ip->addr )
        return 0;
    if( ip_family_get(ip) == 2 )
        return ( ip->addr->ip.u_addr8[0] == 0x7f );
    if( ip->addr->ip.u_addr32[0] || ip->addr->ip.u_addr32[1] )
        return 0;
    if( ip->addr->ip.u_addr32[2] == 0 )
        return ( ( ip->addr->ip.u_addr8[12] == 0x7f ) ||
                 ( ntohl(ip->addr->ip.u_addr32[3]) == 0x1 ) );
    if( ntohl(ip->addr->ip.u_addr32[2]) == 0xffff )
        return ( ip->addr->ip.u_addr8[12] == 0x7f );
    return 0;
}

canonical_original_code:
int ip_isloopback(struct _ip_s *ip)
{
    if( ((void *)0) == ip || ((void *)0) == ip->addr )
        return 0;
    if( ip_family_get(ip) == 2 )
        return ( ip->addr->ip.u_addr8[0] == 0x7f );
    if( ip->addr->ip.u_addr32[0] || ip->addr->ip.u_addr32[1] )
        return 0;
    if( ip->addr->ip.u_addr32[2] == 0 )
        return ( ( ip->addr->ip.u_addr8[12] == 0x7f ) ||
                 ( ntohl(ip->addr->ip.u_addr32[3]) == 0x1 ) );
    if( ntohl(ip->addr->ip.u_addr32[2]) == 0xffff )
        return ( ip->addr->ip.u_addr8[12] == 0x7f );
    return 0;
}


decompiled_code:
_BOOL8 __fastcall ip_ismapped(__int64 a1)
{
__int64 v1; // rbx
__int16 v2; // dx
_BOOL8 result; // rax
unsigned int v4; // ebx

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = ip_family_get((unsigned __int16 *)a1);
result = 0LL;
if ( v2 != 2 && !*(_QWORD *)v1 )
{
v4 = *(_DWORD *)(v1 + 8);
result = (unsigned int)_bswap_32(v4) == 0xFFFF || v4 == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1)
{
__int64 v1; // rbx
__int16 v2; // dx
_BOOL8 result; // rax
unsigned int v4; // ebx

if ( !a1 )
return 0LL;
v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
v2 = func0((unsigned __int16 *)a1);
result = 0LL;
if ( v2 != 2 && !*(_QWORD *)v1 )
{
v4 = *(_DWORD *)(v1 + 8);
result = (unsigned int)func4(v4) == 0xFFFF || v4 == 0;
}
return result;
}

original_code:
int ip_ismapped(const ip_t *ip)
{
    if( ((void *)0) == ip || ((void *)0) == ip->addr )
        return 0;
    if( ip_family_get(ip) == 2 )
        return 0;
    if( ip->addr->ip.u_addr32[0] ||
        ip->addr->ip.u_addr32[1] ||
        ( ntohl(ip->addr->ip.u_addr32[2]) != 0xffff &&
          ip->addr->ip.u_addr32[2] != 0 ) )
        return 0;
    return 1;
}

canonical_original_code:
int ip_ismapped(struct _ip_s *ip)
{
    if( ((void *)0) == ip || ((void *)0) == ip->addr )
        return 0;
    if( ip_family_get(ip) == 2 )
        return 0;
    if( ip->addr->ip.u_addr32[0] ||
        ip->addr->ip.u_addr32[1] ||
        ( ntohl(ip->addr->ip.u_addr32[2]) != 0xffff &&
          ip->addr->ip.u_addr32[2] != 0 ) )
        return 0;
    return 1;
}


decompiled_code:
void ip_obfuscate()
{
;
}

canonical_decompiled_code:
void func15()
{
;
}

original_code:
void ip_obfuscate(ip_t *ob, const ip_t *ip)
{
    if( ((void *)0) == ob || ((void *)0) == ip )
        return;
}

canonical_original_code:
void ip_obfuscate(struct _ip_s *ob, struct _ip_s *ip)
{
    if( ((void *)0) == ob || ((void *)0) == ip )
        return;
}

variable_types:
ip
struct _ip_s *


saveArgf

repo: gmn/ftc

decompiled_code:
int __fastcall saveArgf(float a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

snprintf(v2, 0x80uLL, "echo %f > /tmp/.ftc_last_result", a1);
return system(v2);
}

canonical_decompiled_code:
int __fastcall func0(float a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

snprintf(v2, 0x80uLL, "echo %f > /tmp/.ftc_last_result", a1);
return system(v2);
}

original_code:
void saveArgf( float f ) {
    char buf[128];
    snprintf(buf, 128, "echo %f > /tmp/.ftc_last_result", f);
    system(buf);
}

canonical_original_code:
void saveArgf(float f) {
    char buf[128];
    snprintf(buf, 128, "echo %f > /tmp/.ftc_last_result", f);
    system(buf);
}

variable_types: f float

variable_types:
buf
char [128]


saveArgi

decompiled_code:
int __fastcall saveArgi(unsigned int a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

snprintf(v2, 0x80uLL, "echo %i > /tmp/.ftc_last_result", a1);
return system(v2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

snprintf(v2, 0x80uLL, "echo %i > /tmp/.ftc_last_result", a1);
return system(v2);
}

original_code:
void saveArgi( int i ) {
    char buf[128];
    snprintf(buf, 128, "echo %i > /tmp/.ftc_last_result", i);
    system(buf);
}

canonical_original_code:
void saveArgi(int i) {
    char buf[128];
    snprintf(buf, 128, "echo %i > /tmp/.ftc_last_result", i);
    system(buf);
}

variable_types: i int


trim

original_code:
char * trim ( char *val ) {
 char buf[256];
 char *p = buf;
 char *v = val;
 while ( *v == ' ' )
  ++v;
 while ( *v && *v != ' ' ) {
  *p++ = *v++;
 }
 *p = '\0';
 p = buf; v = val;
 while ( *v++ = *p++ )
  ;
 return val;
}

canonical_original_code:
char *trim(char *val) {
 char buf[256];
 char *p = buf;
 char *v = val;
 while ( *v == ' ' )
  ++v;
 while ( *v && *v != ' ' ) {
  *p++ = *v++;
 }
 *p = '\0';
 p = buf; v = val;
 while ( *v++ = *p++ )
  ;
 return val;
}

variable_types:
val
char *

variable_types:
buf
char [256]

variable_types:
p
char *

variable_types:
v
char *


isOperator

decompiled_code:
_BOOL8 __fastcall isOperator(char *a1)
{
char v1; // al
_BOOL4 v2; // edx

if ( !a1 )
return 0;
v1 = *a1;
if ( *a1 > 47 )
return v1 == 94;
v2 = 0;
if ( v1 > 36 )
{
switch ( v1 )
{
case '%':
case '*':
case '/':
v2 = 1;
break;
case '+':
case '-':
v2 = (unsigned __int8)(a1[1] - 48) > 9u;
break;
default:
v2 = 0;
break;
}
}
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *a1)
{
char v1; // al
_BOOL4 v2; // edx

if ( !a1 )
return 0;
v1 = *a1;
if ( *a1 > 47 )
return v1 == 94;
v2 = 0;
if ( v1 > 36 )
{
switch ( v1 )
{
case '%':
case '*':
case '/':
v2 = 1;
break;
case '+':
case '-':
v2 = (unsigned __int8)(a1[1] - 48) > 9u;
break;
default:
v2 = 0;
break;
}
}
return v2;
}

original_code:
int isOperator( char *t ) {
 char c = 0;
    if ( !t )
        return 0;
    switch ( *t ) {
 case '+': case '-':
  if ( (c=*(t+1)) && c >= '0' && c <= '9' )
   return 0;
    case '*': case '/': case '%': case '^':
        return 1;
    }
    return 0;
}

canonical_original_code:
int isOperator(char *t) {
 char c = 0;
    if ( !t )
        return 0;
    switch ( *t ) {
 case '+': case '-':
  if ( (c=*(t+1)) && c >= '0' && c <= '9' )
   return 0;
    case '*': case '/': case '%': case '^':
        return 1;
    }
    return 0;
}

variable_types:
t
char *

variable_types: c char


hexLetter

decompiled_code:
__int64 __fastcall hexLetter(int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 65) <= 5 )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6;
result = 0LL;
if ( v4 )
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 65) <= 5 )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6;
result = 0LL;
if ( v4 )
result = v3;
}
}
return result;
}

original_code:
int hexLetter( int h ) {
    if ( h >= '0' && h <= '9' ) {
        return h - 48;
    } else if ( h >= 'A' && h <= 'F' ) {
     return h - 55;
 } else if ( h >= 'a' && h <= 'f' ) {
  return h - 87;
 }
 return 0;
}

canonical_original_code:
int hexLetter(int h) {
    if ( h >= '0' && h <= '9' ) {
        return h - 48;
    } else if ( h >= 'A' && h <= 'F' ) {
     return h - 55;
 } else if ( h >= 'a' && h <= 'f' ) {
  return h - 87;
 }
 return 0;
}

variable_types: h int


hexToInt

original_code:
int hexToInt( char *hexstr ) {
    char *p = hexstr, *e;
    int val = 0;
    int mult = 1;
    if ( *p++ != '0' )
  return 0;
 if ( *p != 'x' && *p != 'h' )
        return 0;
 ++p;
    e = p + strlen( p );
    while ( e != p ) {
        val += hexLetter(*--e) * mult;
        mult *= 16;
    }
    return val;
}

canonical_original_code:
int hexToInt(char *hexstr) {
    char *p = hexstr; char *e;
    int val = 0;
    int mult = 1;
    if ( *p++ != '0' )
  return 0;
 if ( *p != 'x' && *p != 'h' )
        return 0;
 ++p;
    e = p + strlen( p );
    while ( e != p ) {
        val += hexLetter(*--e) * mult;
        mult *= 16;
    }
    return val;
}

variable_types:
hexstr
char *

variable_types:
e
char *

variable_types: val int

variable_types: mult int


binToInt

original_code:
int binToInt( char *binstr ) {
    char *p = binstr, *e;
    int val = 0;
    int mult = 1;
    if ( *p++ != '0' || *p++ != 'b' )
        return 0;
    e = p + strlen( p );
    while ( e != p ) {
        if ( *--e == '1' ) {
            val += mult;
        }
        mult *= 2;
    }
    return val;
}

canonical_original_code:
int binToInt(char *binstr) {
    char *p = binstr; char *e;
    int val = 0;
    int mult = 1;
    if ( *p++ != '0' || *p++ != 'b' )
        return 0;
    e = p + strlen( p );
    while ( e != p ) {
        if ( *--e == '1' ) {
            val += mult;
        }
        mult *= 2;
    }
    return val;
}

variable_types:
binstr
char *


octToInt

original_code:
int octToInt( char *octstr ) {
 char *p = octstr, *e;
 int mult = 1;
 int val = 0;
 if ( *p++ != '0' )
  return 0;
 e = p + strlen( p );
 while ( e-- != p ) {
     if ( *e >= '0' && *e <= '7' ) {
         val += ( *e - 48 ) * mult;
  }
  mult *= 8;
 }
 return val;
}

canonical_original_code:
int octToInt(char *octstr) {
 char *p = octstr; char *e;
 int mult = 1;
 int val = 0;
 if ( *p++ != '0' )
  return 0;
 e = p + strlen( p );
 while ( e-- != p ) {
     if ( *e >= '0' && *e <= '7' ) {
         val += ( *e - 48 ) * mult;
  }
  mult *= 8;
 }
 return val;
}

variable_types:
octstr
char *


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "usage: %s 'number [-H|-B] (*|/|+|-|%%) number'\n", a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
return fprintf(stderr, "usage: %s 'number [-H|-B] (*|/|+|-|%%) number'\n", a1);
}

original_code:
void usage( const char *name ) {
    fprintf(stderr, "usage: %s \'number [-H|-B] (*|/|+|-|%%) number\'\n", name ) ;
}

canonical_original_code:
void usage(char *name) {
    fprintf(stderr, "usage: %s \'number [-H|-B] (*|/|+|-|%%) number\'\n", name ) ;
}

variable_types:
name
char *


clipLeadingWord

original_code:
char *clipLeadingWord(char *string, char *word)
{
    int i,j;
    char buf[256];
    memset(buf, 0, sizeof(buf));
    i = j = 0;
    while (string[j] == ' ' || string[j] == '\t')
        ++j;
    while ((word[i] = string[j]) != ' ' && word[i] != '\0')
        ++i, ++j;
    if (word[i] != '\0')
        word[i++] = '\0';
    strncpy(buf, &string[j], 256);
    memset(string, 0, 256);
    strncpy(string, buf, 256);
    return word;
}

canonical_original_code:
char *clipLeadingWord(char *string, char *word)
{
    int i; int j;
    char buf[256];
    memset(buf, 0, sizeof(buf));
    i = j = 0;
    while (string[j] == ' ' || string[j] == '\t')
        ++j;
    while ((word[i] = string[j]) != ' ' && word[i] != '\0')
        ++i, ++j;
    if (word[i] != '\0')
        word[i++] = '\0';
    strncpy(buf, &string[j], 256);
    memset(string, 0, 256);
    strncpy(string, buf, 256);
    return word;
}

variable_types:
string
char *

variable_types:
word
char *

variable_types: j int


yankCharacter

decompiled_code:
__int64 __fastcall yankCharacter(_BYTE *a1, char a2)
{
_BYTE *v2; // rax
char v3; // dl
char *v4; // rdi

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

canonical_decompiled_code:
__int64 __fastcall func12(_BYTE *a1, char a2)
{
_BYTE *v2; // rax
char v3; // dl
char *v4; // rdi

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

original_code:
int yankCharacter(char *str, const char y)
{
    int i;
    while (str[i] != '\0')
    {
        if (str[i] == y)
        {
            str[i] = ' ';
            return 1;
        }
        ++i;
    }
    return 0;
}

canonical_original_code:
int yankCharacter(char *str, char y)
{
    int i;
    while (str[i] != '\0')
    {
        if (str[i] == y)
        {
            str[i] = ' ';
            return 1;
        }
        ++i;
    }
    return 0;
}

variable_types:
str
char *

variable_types: y char

variable_types: i int


isEquallyDivisible

decompiled_code:
_BOOL8 __fastcall isEquallyDivisible(int a1, int a2)
{
return (float)((float)((float)a1 / (float)a2) - (float)(int)(float)((float)a1 / (float)a2)) == 0.0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int a1, int a2)
{
return (float)((float)((float)a1 / (float)a2) - (float)(int)(float)((float)a1 / (float)a2)) == 0.0;
}

original_code:
int isEquallyDivisible(int a, int b)
{
    float sum = (float) a / (float) b;
    int sumi = (int) sum;
    sum -= sumi;
    if (sum == 0.0)
        return 1;
    return 0;
}

variable_types: a int

variable_types: b int

variable_types: sum float

variable_types: sumi int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er15
const char *v5; // rbp
char *v6; // rax
const char *v7; // rbp
const char *v8; // r12
int v9; // er13
bool v10; // zf
int v11; // ebx
float v12; // xmm0_4
float v14; // xmm0_4
float v15; // xmm7_4
int v16; // ebp
int v17; // ebx
float v18; // xmm2_4
const char *v19; // rax
float x; // [rsp+8h] [rbp-4240h]
float xa; // [rsp+8h] [rbp-4240h]
float xb; // [rsp+8h] [rbp-4240h]
float y; // [rsp+Ch] [rbp-423Ch]
char s[16384]; // [rsp+10h] [rbp-4238h] BYREF
char haystack[256]; // [rsp+4010h] [rbp-238h] BYREF
char dest[312]; // [rsp+4110h] [rbp-138h] BYREF

memset(dest, 0, 0x100uLL);
memset(haystack, 0, sizeof(haystack));
memset(program_name, 0, sizeof(program_name));
memset(s, 0, sizeof(s));
v5 = *argv;
v6 = strrchr(*argv, 47);
if ( v6 )
strncpy(program_name, v6 + 1, 0x100uLL);
else
strncpy(program_name, v5, 0x100uLL);
v7 = argv[1];
if ( argc != 3 )
{
if ( argc == 2 )
{
v8 = argv[1];
v9 = 0;
goto LABEL_6;
}
LABEL_17:
usage(program_name);
return 1;
}
if ( !strcmp("-H", argv[1]) )
{
v9 = 2;
}
else
{
v9 = 1;
if ( strcmp("-B", v7) )
goto LABEL_17;
}
v8 = argv[2];
LABEL_6:
v10 = strcmp(v7, "--version") == 0;
v11 = !v10;
if ( v10 )
{
fprintf(stdout, "ftc Version: %s (c) 2008, Greg Naughton\n", "0.1.9");
return v11;
}
v11 = strcmp(v7, "--help");
if ( !v11 )
{
usage(program_name);
return v11;
}
strcpy(dest, v8);
clipLeadingWord(dest, haystack);
if ( isOperator(haystack) )
{
printf("isOperator, string: %s, token: %s \n", dest, haystack);
if ( !(unsigned int)checkStoredResult(dest, haystack) )
{
printf("!isStoredResult, string: %s, token: %s\n", dest, haystack);
fwrite("error: argument not found\n", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
printf("isStoredResult, string: \"%s\", token: \"%s\"\n", dest, haystack);
}
if ( !strstr(haystack, "log") )
{
if ( strstr(haystack, "ln") )
{
clipLeadingWord(dest, haystack);
v14 = atof(haystack);
xb = logf(v14);
fprintf(stdout, "%f\n", xb);
saveArgf(xb);
return 0;
}
if ( strchr(haystack, 46) )
{
v15 = atof(haystack);
x = v15;
v16 = 1;
}
else if ( strchr(haystack, 120) || strchr(haystack, 104) )
{
v3 = hexToInt((__int64)haystack);
v16 = 0;
}
else if ( strchr(haystack, 98) )
{
v3 = binToInt((__int64)haystack);
v16 = 0;
}
else
{
if ( *trim(haystack) == 48 )
v3 = octToInt((__int64)haystack);
else
v3 = atoi(haystack);
v16 = 0;
}
clipLeadingWord(dest, haystack);
v17 = 1;
if ( !strchr(haystack, 42) )
{
v17 = 2;
if ( !strchr(haystack, 47) )
{
v17 = 5;
if ( !strchr(haystack, 45) )
{
v17 = 3;
if ( !strchr(haystack, 43) )
{
v17 = 4;
if ( !strchr(haystack, 37) )
{
v17 = 6;
if ( !strchr(haystack, 94) )
{
if ( v16 <= 0 )
{
if ( v9 != 1 )
{
if ( v9 != 2 )
{
LABEL_49:
fprintf(stdout, "%d\n", (unsigned int)v3);
LABEL_50:
saveArgi(v3);
return 0;
}
LABEL_53:
fprintf(stdout, "0x%X\n", (unsigned int)v3);
goto LABEL_50;
}
goto LABEL_52;
}
LABEL_71:
fprintf(stdout, "%f\n", x);
saveArgf(x);
return 0;
}
}
}
}
}
}
clipLeadingWord(dest, haystack);
if ( strchr(haystack, 46) )
{
v18 = atof(haystack);
y = v18;
v16 += 2;
if ( v16 == 2 )
x = (float)v3;
}
else
{
if ( strchr(haystack, 120) || strchr(haystack, 104) )
{
v4 = hexToInt((__int64)haystack);
}
else if ( strchr(haystack, 98) )
{
v4 = binToInt((__int64)haystack);
}
else if ( *trim(haystack) == 48 )
{
v4 = octToInt((__int64)haystack);
}
else
{
v4 = atoi(haystack);
}
if ( v16 != 1 )
{
if ( v17 == 2 )
{
if ( !isEquallyDivisible(v3, v4) )
{
x = (float)v3;
y = (float)v4;
LABEL_60:
x = x / y;
goto LABEL_71;
}
LABEL_74:
v3 /= v4;
}
else
{
switch ( v17 )
{
case 1:
LABEL_69:
if ( v16 > 0 )
{
x = x * y;
goto LABEL_71;
}
v3 *= v4;
break;
case 2:
LABEL_73:
if ( v16 <= 0 )
goto LABEL_74;
goto LABEL_60;
case 3:
LABEL_78:
if ( v16 > 0 )
{
x = x + y;
goto LABEL_71;
}
v3 += v4;
break;
case 4:
v3 %= v4;
break;
case 5:
LABEL_75:
if ( v16 > 0 )
{
x = x - y;
goto LABEL_71;
}
v3 -= v4;
break;
case 6:
LABEL_83:
if ( (float)v16 <= 0.0 )
v3 = (int)powf((float)v3, (float)v4);
else
x = powf(x, y);
goto LABEL_85;
default:
LABEL_85:
if ( v16 <= 0 )
break;
goto LABEL_71;
}
}
if ( v9 != 1 )
{
if ( v9 != 2 )
goto LABEL_49;
goto LABEL_53;
}
LABEL_52:
v19 = intToBin((__int64)haystack, v3);
fprintf(stdout, "%s\n", v19);
goto LABEL_50;
}
y = (float)v4;
}
switch ( v17 )
{
case 1:
goto LABEL_69;
case 2:
goto LABEL_73;
case 3:
goto LABEL_78;
case 4:
fwrite("error: cant take modulus of floats!\n", 1uLL, 0x24uLL, stderr);
exit(1);
case 5:
goto LABEL_75;
case 6:
goto LABEL_83;
default:
goto LABEL_85;
}
}
clipLeadingWord(dest, haystack);
v12 = atof(haystack);
xa = log10f(v12);
fprintf(stdout, "%f\n", xa);
saveArgf(xa);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er15
const char *v5; // rbp
char *v6; // rax
const char *v7; // rbp
const char *v8; // r12
int v9; // er13
bool v10; // zf
int v11; // ebx
float v12; // xmm0_4
float v14; // xmm0_4
float v15; // xmm7_4
int v16; // ebp
int v17; // ebx
float v18; // xmm2_4
const char *v19; // rax
float x; // [rsp+8h] [rbp-4240h]
float xa; // [rsp+8h] [rbp-4240h]
float xb; // [rsp+8h] [rbp-4240h]
float y; // [rsp+Ch] [rbp-423Ch]
char s[16384]; // [rsp+10h] [rbp-4238h] BYREF
char haystack[256]; // [rsp+4010h] [rbp-238h] BYREF
char dest[312]; // [rsp+4110h] [rbp-138h] BYREF

memset(dest, 0, 0x100uLL);
memset(haystack, 0, sizeof(haystack));
memset(program_name, 0, sizeof(program_name));
memset(s, 0, sizeof(s));
v5 = *argv;
v6 = strrchr(*argv, 47);
if ( v6 )
strncpy(program_name, v6 + 1, 0x100uLL);
else
strncpy(program_name, v5, 0x100uLL);
v7 = argv[1];
if ( argc != 3 )
{
if ( argc == 2 )
{
v8 = argv[1];
v9 = 0;
goto LABEL_6;
}
LABEL_17:
func9(program_name);
return 1;
}
if ( !strcmp("-H", argv[1]) )
{
v9 = 2;
}
else
{
v9 = 1;
if ( strcmp("-B", v7) )
goto LABEL_17;
}
v8 = argv[2];
LABEL_6:
v10 = strcmp(v7, "--version") == 0;
v11 = !v10;
if ( v10 )
{
fprintf(stdout, "ftc Version: %s (c) 2008, Greg Naughton\n", "0.1.9");
return v11;
}
v11 = strcmp(v7, "--help");
if ( !v11 )
{
func9(program_name);
return v11;
}
strcpy(dest, v8);
func11(dest, haystack);
if ( func4(haystack) )
{
printf("isOperator, string: %s, token: %s \n", dest, haystack);
if ( !(unsigned int)func3(dest, haystack) )
{
printf("!isStoredResult, string: %s, token: %s\n", dest, haystack);
fwrite("error: argument not found\n", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
printf("isStoredResult, string: \"%s\", token: \"%s\"\n", dest, haystack);
}
if ( !strstr(haystack, "log") )
{
if ( strstr(haystack, "ln") )
{
func11(dest, haystack);
v14 = atof(haystack);
xb = logf(v14);
fprintf(stdout, "%f\n", xb);
func0(xb);
return 0;
}
if ( strchr(haystack, 46) )
{
v15 = atof(haystack);
x = v15;
v16 = 1;
}
else if ( strchr(haystack, 120) || strchr(haystack, 104) )
{
v3 = func6((__int64)haystack);
v16 = 0;
}
else if ( strchr(haystack, 98) )
{
v3 = func7((__int64)haystack);
v16 = 0;
}
else
{
if ( *func2(haystack) == 48 )
v3 = func8((__int64)haystack);
else
v3 = atoi(haystack);
v16 = 0;
}
func11(dest, haystack);
v17 = 1;
if ( !strchr(haystack, 42) )
{
v17 = 2;
if ( !strchr(haystack, 47) )
{
v17 = 5;
if ( !strchr(haystack, 45) )
{
v17 = 3;
if ( !strchr(haystack, 43) )
{
v17 = 4;
if ( !strchr(haystack, 37) )
{
v17 = 6;
if ( !strchr(haystack, 94) )
{
if ( v16 <= 0 )
{
if ( v9 != 1 )
{
if ( v9 != 2 )
{
LABEL_49:
fprintf(stdout, "%d\n", (unsigned int)v3);
LABEL_50:
func1(v3);
return 0;
}
LABEL_53:
fprintf(stdout, "0x%X\n", (unsigned int)v3);
goto LABEL_50;
}
goto LABEL_52;
}
LABEL_71:
fprintf(stdout, "%f\n", x);
func0(x);
return 0;
}
}
}
}
}
}
func11(dest, haystack);
if ( strchr(haystack, 46) )
{
v18 = atof(haystack);
y = v18;
v16 += 2;
if ( v16 == 2 )
x = (float)v3;
}
else
{
if ( strchr(haystack, 120) || strchr(haystack, 104) )
{
v4 = func6((__int64)haystack);
}
else if ( strchr(haystack, 98) )
{
v4 = func7((__int64)haystack);
}
else if ( *func2(haystack) == 48 )
{
v4 = func8((__int64)haystack);
}
else
{
v4 = atoi(haystack);
}
if ( v16 != 1 )
{
if ( v17 == 2 )
{
if ( !func13(v3, v4) )
{
x = (float)v3;
y = (float)v4;
LABEL_60:
x = x / y;
goto LABEL_71;
}
LABEL_74:
v3 /= v4;
}
else
{
switch ( v17 )
{
case 1:
LABEL_69:
if ( v16 > 0 )
{
x = x * y;
goto LABEL_71;
}
v3 *= v4;
break;
case 2:
LABEL_73:
if ( v16 <= 0 )
goto LABEL_74;
goto LABEL_60;
case 3:
LABEL_78:
if ( v16 > 0 )
{
x = x + y;
goto LABEL_71;
}
v3 += v4;
break;
case 4:
v3 %= v4;
break;
case 5:
LABEL_75:
if ( v16 > 0 )
{
x = x - y;
goto LABEL_71;
}
v3 -= v4;
break;
case 6:
LABEL_83:
if ( (float)v16 <= 0.0 )
v3 = (int)powf((float)v3, (float)v4);
else
x = powf(x, y);
goto LABEL_85;
default:
LABEL_85:
if ( v16 <= 0 )
break;
goto LABEL_71;
}
}
if ( v9 != 1 )
{
if ( v9 != 2 )
goto LABEL_49;
goto LABEL_53;
}
LABEL_52:
v19 = intToBin((__int64)haystack, v3);
fprintf(stdout, "%s\n", v19);
goto LABEL_50;
}
y = (float)v4;
}
switch ( v17 )
{
case 1:
goto LABEL_69;
case 2:
goto LABEL_73;
case 3:
goto LABEL_78;
case 4:
fwrite("error: cant take modulus of floats!\n", 1uLL, 0x24uLL, stderr);
exit(1);
case 5:
goto LABEL_75;
case 6:
goto LABEL_83;
default:
goto LABEL_85;
}
}
func11(dest, haystack);
v12 = atof(haystack);
xa = log10f(v12);
fprintf(stdout, "%f\n", xa);
func0(xa);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
    int floatState = 0;
    float arg1f, arg2f;
    int arg1i, arg2i;
    operator_t op = OP_NONE;
    char string[256];
    char token[256];
    char args[16384];
    char *p;
 enum output_t out_type = OUTPUT_NORMAL;
    memset( string, 0, sizeof(string) );
    memset( token, 0, sizeof(token) );
    memset( program_name, 0, sizeof(program_name) );
    memset( args, 0, sizeof(args) );
    if ( (p = strrchr( argv[0], '/' )) )
        strncpy( program_name, ++p, sizeof(program_name) );
    else
        strncpy( program_name, argv[0], sizeof(program_name) );
 p = argv[1];
    if ( argc == 3 ) {
  if ( !strcmp( "-H", argv[1] ) ) {
   out_type = OUTPUT_HEXADECIMAL;
  }
  else if ( !strcmp( "-B", argv[1] ) ) {
   out_type = OUTPUT_BINARY;
  }
  else {
         usage( program_name );
         return 1;
  }
  p = argv[2];
 } else if ( argc != 2 ) {
        usage( program_name );
        return 1;
    }
 if ( !strcmp( argv[1], "--version" ) ) {
  fprintf( stdout, "ftc Version: %s (c) 2008, Greg Naughton\n", "0.1.9" );
  return 0;
 }
 if ( !strcmp( argv[1], "--help" ) ) {
  usage( program_name );
  return 0;
 }
    strcpy( string, p );
    clipLeadingWord(string, token);
    if ( isOperator(token) ) {
printf( "isOperator, string: %s, token: %s \n", string, token );
        if (!checkStoredResult(string, token)) {
printf( "!isStoredResult, string: %s, token: %s\n", string, token );
            fprintf(stderr, "error: argument not found\n");
            exit(-1);
        }
else
printf( "isStoredResult, string: \"%s\", token: \"%s\"\n", string, token );
    }
    if ( strstr( token, "log" ) ) {
        op = OP_LOG_BASE10;
        clipLeadingWord(string, token);
        arg2f = atof(token);
    } else if ( strstr( token, "ln" ) ) {
        op = OP_NATURAL_LOG;
        clipLeadingWord(string, token);
        arg2f = atof(token);
    } else if ( strchr(token, '.') ) {
        arg1f = atof(token);
        floatState = 1;
    } else if ( strchr(token, 'x') || strchr(token, 'h') ) {
        arg1i = hexToInt( token );
    } else if ( strchr( token , 'b' ) ) {
        arg1i = binToInt( token );
 } else if ( *trim(token) == '0' ) {
  arg1i = octToInt( token );
    } else
        arg1i = atoi(token);
    if ( op == OP_NATURAL_LOG ) {
        arg1f = logf( arg2f );
        fprintf(stdout, "%f\n", arg1f);
        saveArgf( arg1f );
        return 0;
    } else if ( op == OP_LOG_BASE10 ) {
        arg1f = log10f( arg2f );
        fprintf(stdout, "%f\n", arg1f);
        saveArgf( arg1f );
        return 0;
    }
    clipLeadingWord(string, token);
    if (strchr(token, '*') != ((void *)0))
        op = OP_MULTIPLY;
    else if (strchr(token, '/') != ((void *)0))
        op = OP_DIVIDE;
    else if (strchr(token, '-') != ((void *)0))
        op = OP_SUBTRACT;
    else if (strchr(token, '+') != ((void *)0))
        op = OP_ADD;
    else if (strchr(token, '%') != ((void *)0))
        op = OP_MODULUS;
    else if (strchr(token, '^') != ((void *)0))
        op = OP_RAISE_TO_THE_POWER;
    else {
        if (floatState > 0) {
            fprintf(stdout, "%f\n", arg1f);
            saveArgf( arg1f );
        } else {
   if ( OUTPUT_BINARY == out_type ) {
          fprintf(stdout, "%s\n", intToBin(token, arg1i) );
   } else if ( OUTPUT_HEXADECIMAL == out_type ) {
          fprintf(stdout, "0x%X\n", arg1i);
   } else {
          fprintf(stdout, "%d\n", arg1i);
   }
            saveArgi( arg1i );
        }
        return 0;
    }
    clipLeadingWord( string, token );
    if (strchr(token, '.') ) {
        arg2f = atof(token);
        floatState += 2;
    } else if ( strchr( token , 'x' ) || strchr(token, 'h') ) {
        arg2i = hexToInt( token );
    } else if ( strchr( token , 'b' ) ) {
        arg2i = binToInt( token );
 } else if ( *trim(token) == '0' ) {
  arg2i = octToInt( token );
    } else
        arg2i = atoi(token);
    switch (floatState) {
    case 1:
        arg2f = arg2i;
        break;
    case 2:
        arg1f = arg1i;
        break;
    }
    if (!floatState && op == OP_DIVIDE) {
        if (!isEquallyDivisible(arg1i, arg2i)) {
            ++floatState;
            arg1f = arg1i;
            arg2f = arg2i;
        }
    }
    switch (op) {
    case OP_MULTIPLY:
        if (floatState > 0)
            arg1f *= arg2f;
        else
            arg1i *= arg2i;
        break;
    case OP_DIVIDE:
        if (floatState > 0)
            arg1f /= arg2f;
        else
            arg1i /= arg2i;
        break;
    case OP_SUBTRACT:
        if (floatState > 0)
            arg1f -= arg2f;
        else
            arg1i -= arg2i;
        break;
    case OP_ADD:
        if (floatState > 0)
            arg1f += arg2f;
        else
            arg1i += arg2i;
        break;
    case OP_MODULUS:
        if (floatState > 0) {
            fprintf(stderr, "error: cant take modulus of floats!\n");
            exit(1);
        } else
            arg1i %= arg2i;
           break;
    case OP_RAISE_TO_THE_POWER:
        if ( floatState > 0.0f ) {
            arg1f = powf( arg1f, arg2f );
        } else {
            arg1i = (int) powf( (float)arg1i, (float)arg2i );
        }
    default:
        break;
    }
    if (floatState > 0) {
        fprintf(stdout, "%f\n", arg1f);
        saveArgf( arg1f );
    } else {
  if ( OUTPUT_BINARY == out_type ) {
         fprintf(stdout, "%s\n", intToBin(token, arg1i) );
  } else if ( OUTPUT_HEXADECIMAL == out_type ) {
         fprintf(stdout, "0x%X\n", arg1i);
  } else {
         fprintf(stdout, "%d\n", arg1i);
  }
        saveArgi( arg1i );
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int floatState = 0;
    float arg1f; float arg2f;
    int arg1i; int arg2i;
    enum operator_t op = OP_NONE;
    char string[256];
    char token[256];
    char args[16384];
    char *p;
 enum output_t out_type = OUTPUT_NORMAL;
    memset( string, 0, sizeof(string) );
    memset( token, 0, sizeof(token) );
    memset( program_name, 0, sizeof(program_name) );
    memset( args, 0, sizeof(args) );
    if ( (p = strrchr( argv[0], '/' )) )
        strncpy( program_name, ++p, sizeof(program_name) );
    else
        strncpy( program_name, argv[0], sizeof(program_name) );
 p = argv[1];
    if ( argc == 3 ) {
  if ( !strcmp( "-H", argv[1] ) ) {
   out_type = OUTPUT_HEXADECIMAL;
  }
  else if ( !strcmp( "-B", argv[1] ) ) {
   out_type = OUTPUT_BINARY;
  }
  else {
         usage( program_name );
         return 1;
  }
  p = argv[2];
 } else if ( argc != 2 ) {
        usage( program_name );
        return 1;
    }
 if ( !strcmp( argv[1], "--version" ) ) {
  fprintf( stdout, "ftc Version: %s (c) 2008, Greg Naughton\n", "0.1.9" );
  return 0;
 }
 if ( !strcmp( argv[1], "--help" ) ) {
  usage( program_name );
  return 0;
 }
    strcpy( string, p );
    clipLeadingWord(string, token);
    if ( isOperator(token) ) {
printf( "isOperator, string: %s, token: %s \n", string, token );
        if (!checkStoredResult(string, token)) {
printf( "!isStoredResult, string: %s, token: %s\n", string, token );
            fprintf(stderr, "error: argument not found\n");
            exit(-1);
        }
else
printf( "isStoredResult, string: \"%s\", token: \"%s\"\n", string, token );
    }
    if ( strstr( token, "log" ) ) {
        op = OP_LOG_BASE10;
        clipLeadingWord(string, token);
        arg2f = atof(token);
    } else if ( strstr( token, "ln" ) ) {
        op = OP_NATURAL_LOG;
        clipLeadingWord(string, token);
        arg2f = atof(token);
    } else if ( strchr(token, '.') ) {
        arg1f = atof(token);
        floatState = 1;
    } else if ( strchr(token, 'x') || strchr(token, 'h') ) {
        arg1i = hexToInt( token );
    } else if ( strchr( token , 'b' ) ) {
        arg1i = binToInt( token );
 } else if ( *trim(token) == '0' ) {
  arg1i = octToInt( token );
    } else
        arg1i = atoi(token);
    if ( op == OP_NATURAL_LOG ) {
        arg1f = logf( arg2f );
        fprintf(stdout, "%f\n", arg1f);
        saveArgf( arg1f );
        return 0;
    } else if ( op == OP_LOG_BASE10 ) {
        arg1f = log10f( arg2f );
        fprintf(stdout, "%f\n", arg1f);
        saveArgf( arg1f );
        return 0;
    }
    clipLeadingWord(string, token);
    if (strchr(token, '*') != ((void *)0))
        op = OP_MULTIPLY;
    else if (strchr(token, '/') != ((void *)0))
        op = OP_DIVIDE;
    else if (strchr(token, '-') != ((void *)0))
        op = OP_SUBTRACT;
    else if (strchr(token, '+') != ((void *)0))
        op = OP_ADD;
    else if (strchr(token, '%') != ((void *)0))
        op = OP_MODULUS;
    else if (strchr(token, '^') != ((void *)0))
        op = OP_RAISE_TO_THE_POWER;
    else {
        if (floatState > 0) {
            fprintf(stdout, "%f\n", arg1f);
            saveArgf( arg1f );
        } else {
   if ( OUTPUT_BINARY == out_type ) {
          fprintf(stdout, "%s\n", intToBin(token, arg1i) );
   } else if ( OUTPUT_HEXADECIMAL == out_type ) {
          fprintf(stdout, "0x%X\n", arg1i);
   } else {
          fprintf(stdout, "%d\n", arg1i);
   }
            saveArgi( arg1i );
        }
        return 0;
    }
    clipLeadingWord( string, token );
    if (strchr(token, '.') ) {
        arg2f = atof(token);
        floatState += 2;
    } else if ( strchr( token , 'x' ) || strchr(token, 'h') ) {
        arg2i = hexToInt( token );
    } else if ( strchr( token , 'b' ) ) {
        arg2i = binToInt( token );
 } else if ( *trim(token) == '0' ) {
  arg2i = octToInt( token );
    } else
        arg2i = atoi(token);
    switch (floatState) {
    case 1:
        arg2f = arg2i;
        break;
    case 2:
        arg1f = arg1i;
        break;
    }
    if (!floatState && op == OP_DIVIDE) {
        if (!isEquallyDivisible(arg1i, arg2i)) {
            ++floatState;
            arg1f = arg1i;
            arg2f = arg2i;
        }
    }
    switch (op) {
    case OP_MULTIPLY:
        if (floatState > 0)
            arg1f *= arg2f;
        else
            arg1i *= arg2i;
        break;
    case OP_DIVIDE:
        if (floatState > 0)
            arg1f /= arg2f;
        else
            arg1i /= arg2i;
        break;
    case OP_SUBTRACT:
        if (floatState > 0)
            arg1f -= arg2f;
        else
            arg1i -= arg2i;
        break;
    case OP_ADD:
        if (floatState > 0)
            arg1f += arg2f;
        else
            arg1i += arg2i;
        break;
    case OP_MODULUS:
        if (floatState > 0) {
            fprintf(stderr, "error: cant take modulus of floats!\n");
            exit(1);
        } else
            arg1i %= arg2i;
           break;
    case OP_RAISE_TO_THE_POWER:
        if ( floatState > 0.0f ) {
            arg1f = powf( arg1f, arg2f );
        } else {
            arg1i = (int) powf( (float)arg1i, (float)arg2i );
        }
    default:
        break;
    }
    if (floatState > 0) {
        fprintf(stdout, "%f\n", arg1f);
        saveArgf( arg1f );
    } else {
  if ( OUTPUT_BINARY == out_type ) {
         fprintf(stdout, "%s\n", intToBin(token, arg1i) );
  } else if ( OUTPUT_HEXADECIMAL == out_type ) {
         fprintf(stdout, "0x%X\n", arg1i);
  } else {
         fprintf(stdout, "%d\n", arg1i);
  }
        saveArgi( arg1i );
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: floatState int

variable_types: enum operator_t { OP_NONE=0, OP_MULTIPLY=1, OP_DIVIDE=2, OP_ADD=3, OP_MODULUS=4, OP_SUBTRACT=5, OP_RAISE_TO_THE_POWER=6, OP_NATURAL_LOG=7, OP_LOG_BASE10=8, OP_LOG_ARBITRARY_BASE=9 }

variable_types:
string
char [256]

variable_types:
token
char [256]

variable_types:
args
char [16384]

variable_types:
p
char *

variable_types: enum output_t { OUTPUT_NORMAL=0, OUTPUT_BINARY=1, OUTPUT_HEXADECIMAL=2 }


repo: gonzus/zc

decompiled_code:
_BOOL8 zc_zmq_is_valid()
{
_BOOL8 result; // rax

result = 0LL;
if ( stype_ >= 0 && nadd > 0 )
result = __PAIR64__(bind_, connect_) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 func0()
{
_BOOL8 result; // rax

result = 0LL;
if ( stype_ >= 0 && nadd > 0 )
result = __PAIR64__(bind_, connect_) != 0;
return result;
}

original_code:
static int zc_zmq_is_valid(void)
{
    if (stype_ < 0)
        return 0;
    if (nadd <= 0)
        return 0;
    if (!bind_ && !connect_)
        return 0;
    return 1;
}

canonical_original_code:
static int zc_zmq_is_valid()
{
    if (stype_ < 0)
        return 0;
    if (nadd <= 0)
        return 0;
    if (!bind_ && !connect_)
        return 0;
    return 1;
}