decompiled_code:
int test_push_pop_proper_errors()
{
int result; // eax
_QWORD v1[3]; // [rsp+0h] [rbp-38h] BYREF
int v2; // [rsp+18h] [rbp-20h]
__int64 v3; // [rsp+20h] [rbp-18h]

mf_init(v1, 100LL);
v1[2] = 1LL;
mf_push(v1, 1LL);
++minunit_assert;
if ( v2 )
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
63LL,
"mf.error==0");
minunit_status = 1;
}
else
{
putchar(46);
mf_push(v1, 1LL);
++minunit_assert;
if ( v2 && v3 )
{
putchar(46);
v2 = 0;
mf_pop(v1);
++minunit_assert;
if ( v2 )
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
68LL,
"mf.error==0");
minunit_status = 1;
}
else
{
putchar(46);
mf_pop(v1);
++minunit_assert;
if ( v2 )
{
putchar(46);
result = mf_destroy(v1);
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
70LL,
"mf.error!=0");
minunit_status = 1;
}
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
65LL,
"mf.error!=0 && mf.error_msg!=NULL");
minunit_status = 1;
}
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
_QWORD v1[3]; // [rsp+0h] [rbp-38h] BYREF
int v2; // [rsp+18h] [rbp-20h]
__int64 v3; // [rsp+20h] [rbp-18h]

func13(v1, 100LL);
v1[2] = 1LL;
func11(v1, 1LL);
++minunit_assert;
if ( v2 )
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
63LL,
"mf.error==0");
minunit_status = 1;
}
else
{
putchar(46);
func11(v1, 1LL);
++minunit_assert;
if ( v2 && v3 )
{
putchar(46);
v2 = 0;
func12(v1);
++minunit_assert;
if ( v2 )
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
68LL,
"mf.error==0");
minunit_status = 1;
}
else
{
putchar(46);
func12(v1);
++minunit_assert;
if ( v2 )
{
putchar(46);
result = func14(v1);
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
70LL,
"mf.error!=0");
minunit_status = 1;
}
}
}
else
{
result = snprintf(
minunit_last_message,
0x400uLL,
"%s failed:\n\t%s:%d: %s",
"test_push_pop_proper_errors",
"unittests.c",
65LL,
"mf.error!=0 && mf.error_msg!=NULL");
minunit_status = 1;
}
}
return result;
}

original_code:
static void test_push_pop_proper_errors()
{
  mf_state_t mf;
  mf_init(&mf, 100);
  mf.stacklen=1;
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 63, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error!=0 && mf.error_msg!=((void *)0))) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 65, "mf.error!=0 && mf.error_msg!=NULL"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf.error=0;
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 68, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error!=0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 70, "mf.error!=0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

canonical_original_code:
static void test_push_pop_proper_errors()
{
  struct mf_state mf;
  mf_init(&mf, 100);
  mf.stacklen=1;
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 63, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_push(&mf, 1);
  do { minunit_assert++; if (!(mf.error!=0 && mf.error_msg!=((void *)0))) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 65, "mf.error!=0 && mf.error_msg!=NULL"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf.error=0;
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error==0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 68, "mf.error==0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_pop(&mf);
  do { minunit_assert++; if (!(mf.error!=0)) { snprintf(minunit_last_message, 1024, "%s failed:\n\t%s:%d: %s", __func__, "unittests.c", 70, "mf.error!=0"); minunit_status = 1; return; } else { printf("."); }} while(0);
  mf_destroy(&mf);
}

user_defined_types: struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state *state, char *context); }


repo: Earlz/microforth

decompiled_code:
double mu_timer_real()
{
return -1.0;
}

canonical_decompiled_code:
double func9()
{
return -1.0;
}

original_code:
double mu_timer_real( )
{
        return -1.0;
}

canonical_original_code:
double mu_timer_real()
{
        return -1.0;
}

return_type: double


decompiled_code:
double mu_timer_cpu()
{
return -1.0;
}

canonical_decompiled_code:
double func10()
{
return -1.0;
}

original_code:
double mu_timer_cpu( )
{
        return -1;
}

canonical_original_code:
double mu_timer_cpu()
{
        return -1;
}


original_code:
intptr_t mf_pop(mf_state_t* state)
{
  if(state->stackpos==0)
  {
    state->error=1;
    state->error_msg="Stack Underflow";
    return -1;
  }
  return state->stack[--state->stackpos];
}

canonical_original_code:
long mf_pop(struct mf_state *state)
{
  if(state->stackpos==0)
  {
    state->error=1;
    state->error_msg="Stack Underflow";
    return -1;
  }
  return state->stack[--state->stackpos];
}

variable_types: struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state *state, char *context); } word; struct mf_word_entry *next; } *words; } *

return_type: long

user_defined_types: struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry *words; }

user_defined_types: struct mf_word_entry { struct mf_word_t word; struct mf_word_entry *next; }


decompiled_code:
__int64 __fastcall mf_init(__int64 a1, int a2)
{
void *v2; // rax

v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
void *v2; // rax

v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
return 0LL;
}

original_code:
int mf_init(mf_state_t* state, int stacksize)
{
  state->stack=malloc(stacksize*sizeof(intptr_t*));
  if(state->stack==((void *)0))
  {
    return -1;
  }
  state->stackpos=0;
  state->stacklen=stacksize;
  state->error=0;
  state->error_msg=((void *)0);
  return 0;
}

canonical_original_code:
int mf_init(struct mf_state *state, int stacksize)
{
  state->stack=malloc(stacksize*sizeof(long *));
  if(state->stack==((void *)0))
  {
    return -1;
  }
  state->stackpos=0;
  state->stacklen=stacksize;
  state->error=0;
  state->error_msg=((void *)0);
  return 0;
}

variable_types: stacksize int

return_type: int


decompiled_code:
__int64 __fastcall mf_destroy(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}

original_code:
int mf_destroy(mf_state_t* state)
{
  if(state->stack!=((void *)0))
  {
    free(state->stack);
  }
  return 0;
}

canonical_original_code:
int mf_destroy(struct mf_state *state)
{
  if(state->stack!=((void *)0))
  {
    free(state->stack);
  }
  return 0;
}


cmpword

decompiled_code:
char *__fastcall cmpword(const char *a1, __int64 a2)
{
size_t v2; // rcx
__int64 v3; // rax
char v4; // dl
char *v5; // rbx
char v7; // bp
int v8; // eax

v2 = strlen(a1);
v3 = 0LL;
while ( v2 != v3 )
{
v4 = a1[v3++];
if ( v4 != *(_BYTE *)(a2 + v3 - 1) )
return 0LL;
}
v5 = (char *)(a2 + v3 + 1);
v7 = *v5;
v8 = isspace(*v5);
if ( v7 && !v8 )
v5 = 0LL;
return v5;
}

canonical_decompiled_code:
char *__fastcall func16(const char *a1, __int64 a2)
{
size_t v2; // rcx
__int64 v3; // rax
char v4; // dl
char *v5; // rbx
char v7; // bp
int v8; // eax

v2 = strlen(a1);
v3 = 0LL;
while ( v2 != v3 )
{
v4 = a1[v3++];
if ( v4 != *(_BYTE *)(a2 + v3 - 1) )
return 0LL;
}
v5 = (char *)(a2 + v3 + 1);
v7 = *v5;
v8 = isspace(*v5);
if ( v7 && !v8 )
v5 = 0LL;
return v5;
}

original_code:
const char* cmpword(const char* word, const char* text)
{
  int i=0;
  for(i=0;i<strlen(word);i++)
  {
    if(word[i]!=text[i])
    {
      return ((void *)0);
    }
  }
  char c=text[i+1];
  if(isspace(c) || c==0)
  {
    return &text[i+1];
  }
  return ((void *)0);
}

canonical_original_code:
char *cmpword(char *word, char *text)
{
  int i = 0;
  for(i=0;i<strlen(word);i++)
  {
    if(word[i]!=text[i])
    {
      return ((void *)0);
    }
  }
  char c = text[i+1];
  if(isspace(c) || c==0)
  {
    return &text[i+1];
  }
  return ((void *)0);
}

variable_types:
word
char *

variable_types:
text
char *

variable_types: i int

variable_types: c char

return_type: char *


getword

decompiled_code:
__int64 __fastcall getword(__int64 a1, __int64 a2, char **a3)
{
__int64 v3; // rbx
char *v5; // rax

v3 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v5 = cmpword(*(const char **)v3, a2);
if ( v5 )
break;
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return 0LL;
}
*a3 = v5;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, char **a3)
{
__int64 v3; // rbx
char *v5; // rax

v3 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v5 = func16(*(const char **)v3, a2);
if ( v5 )
break;
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return 0LL;
}
*a3 = v5;
return v3;
}

original_code:
mf_word_t* getword(mf_word_entry_t* list, const char* text, char** endword)
{
  while(list!=((void *)0))
  {
    char* end=cmpword(list->word.name, text);
    if(end!=((void *)0))
    {
      *endword=end;
      return &list->word;
    }
    list=list->next;
  }
  return ((void *)0);
}

canonical_original_code:
struct mf_word_t *getword(struct mf_word_entry *list, char *text, char **endword)
{
  while(list!=((void *)0))
  {
    char *end = cmpword(list->word.name, text);
    if(end!=((void *)0))
    {
      *endword=end;
      return &list->word;
    }
    list=list->next;
  }
  return ((void *)0);
}

variable_types:
list
struct mf_word_entry *

variable_types:
endword
char **

variable_types:
end
char *

return_type: struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t word; struct mf_word_entry *next; } *words; } *state, char *context); } *


decompiled_code:
char *__fastcall mf_execute_word(__int64 a1, const char *a2)
{
char *v2; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)a2;
if ( *a2 )
{
endptr[0] = 0LL;
v4 = strtol(a2, endptr, 10);
if ( !endptr[0] || endptr[0] == a2 )
{
v5 = getword(*(_QWORD *)(a1 + 40), (__int64)a2, endptr);
if ( v5 )
{
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 16);
if ( v6 )
v2 = (char *)v6(a1, endptr[0]);
else
v2 = endptr[0];
}
else
{
*(_DWORD *)(a1 + 24) = 1;
*(_QWORD *)(a1 + 32) = "Unknown word";
}
}
else
{
if ( *endptr[0] == 117 )
v4 = strtoul(a2, endptr, 10);
mf_push((__int64 *)a1, v4);
v2 = endptr[0];
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func18(__int64 a1, const char *a2)
{
char *v2; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)a2;
if ( *a2 )
{
endptr[0] = 0LL;
v4 = strtol(a2, endptr, 10);
if ( !endptr[0] || endptr[0] == a2 )
{
v5 = func17(*(_QWORD *)(a1 + 40), (__int64)a2, endptr);
if ( v5 )
{
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 16);
if ( v6 )
v2 = (char *)v6(a1, endptr[0]);
else
v2 = endptr[0];
}
else
{
*(_DWORD *)(a1 + 24) = 1;
*(_QWORD *)(a1 + 32) = "Unknown word";
}
}
else
{
if ( *endptr[0] == 117 )
v4 = strtoul(a2, endptr, 10);
func11((__int64 *)a1, v4);
v2 = endptr[0];
}
}
return v2;
}

original_code:
const char* mf_execute_word(mf_state_t* state, const char* word)
{
  if(*word==0) return word;
  char *end=((void *)0);
  long result=strtol(word, &end, 10);
  if(end!=word && end!=((void *)0))
  {
    if(*end=='u')
    {
      result=(long)strtoul(word, &end, 10);
    }
    mf_push(state, (intptr_t)result);
    return end;
  }
  mf_word_t* item=getword(state->words, word, &end);
  if(item==((void *)0))
  {
    state->error=1;
    state->error_msg="Unknown word";
    return word;
  }
  if(item->internal_func!=((void *)0))
  {
    return item->internal_func(state, end);
  }
  return end;
}

canonical_original_code:
char *mf_execute_word(struct mf_state *state, char *word)
{
  if(*word==0) return word;
  char *end = ((void *)0);
  long result = strtol(word, &end, 10);
  if(end!=word && end!=((void *)0))
  {
    if(*end=='u')
    {
      result=(long)strtoul(word, &end, 10);
    }
    mf_push(state, (long)result);
    return end;
  }
  struct mf_word_t *item = getword(state->words, word, &end);
  if(item==((void *)0))
  {
    state->error=1;
    state->error_msg="Unknown word";
    return word;
  }
  if(item->internal_func!=((void *)0))
  {
    return item->internal_func(state, end);
  }
  return end;
}

variable_types: result long

variable_types: struct mf_word_t { char *name; char *body; char *(*internal_func)(struct mf_state { long *stack; unsigned long stackpos; unsigned long stacklen; int error; char *error_msg; struct mf_word_entry { struct mf_word_t word; struct mf_word_entry *next; } *words; } *state, char *context); } *


decompiled_code:
__int64 __fastcall mf_execute(__int64 a1, unsigned __int8 *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rax

v2 = (char *)a2;
while ( *v2 )
{
v3 = skip_whitespace(a2);
v2 = mf_execute_word(a1, (const char *)v3);
if ( *(_DWORD *)(a1 + 24) )
{
fprintf(
stderr,
"Error at character '%il'. Message: '%s'\n",
(unsigned int)((_DWORD)v2 - (_DWORD)a2),
*(const char **)(a1 + 32));
return 0xFFFFFFFFLL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned __int8 *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rax

v2 = (char *)a2;
while ( *v2 )
{
v3 = func15(a2);
v2 = func18(a1, (const char *)v3);
if ( *(_DWORD *)(a1 + 24) )
{
fprintf(
stderr,
"Error at character '%il'. Message: '%s'\n",
(unsigned int)((_DWORD)v2 - (_DWORD)a2),
*(const char **)(a1 + 32));
return 0xFFFFFFFFLL;
}
}
return 0LL;
}

original_code:
int mf_execute(mf_state_t* state, const char* text)
{
  const char* word=text;
  while(*word!=0)
  {
    word=skip_whitespace(text);
    word=mf_execute_word(state, word);
    if(state->error!=0)
    {
      fprintf(stderr, "Error at character '%il'. Message: '%s'\n",(unsigned int)(word-text), state->error_msg);
      return -1;
    }
  }
  return 0;
}

canonical_original_code:
int mf_execute(struct mf_state *state, char *text)
{
  char *word = text;
  while(*word!=0)
  {
    word=skip_whitespace(text);
    word=mf_execute_word(state, word);
    if(state->error!=0)
    {
      fprintf(stderr, "Error at character '%il'. Message: '%s'\n",(unsigned int)(word-text), state->error_msg);
      return -1;
    }
  }
  return 0;
}


main

canonical_name: main

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

test_suite();
minunit_setup = 0LL;
minunit_teardown = 0LL;
printf(
"\n\n%d tests, %d assertions, %d failures\n",
(unsigned int)minunit_run,
(unsigned int)minunit_assert,
(unsigned int)minunit_fail);
v3 = mu_timer_real();
v4 = mu_timer_cpu();
printf(
"\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n",
v3 - *(double *)&minunit_real_timer,
v4 - *(double *)&minunit_proc_timer);
return 0;
}

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

test_suite();
minunit_setup = 0LL;
minunit_teardown = 0LL;
printf(
"\n\n%d tests, %d assertions, %d failures\n",
(unsigned int)minunit_run,
(unsigned int)minunit_assert,
(unsigned int)minunit_fail);
v3 = func9();
v4 = func10();
printf(
"\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n",
v3 - *(double *)&minunit_real_timer,
v4 - *(double *)&minunit_proc_timer);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    do { test_suite(); minunit_setup = ((void *)0); minunit_teardown = ((void *)0);} while(0);
    do { printf("\n\n%d tests, %d assertions, %d failures\n", minunit_run, minunit_assert, minunit_fail); double minunit_end_real_timer = mu_timer_real(); double minunit_end_proc_timer = mu_timer_cpu(); printf("\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n", minunit_end_real_timer - minunit_real_timer, minunit_end_proc_timer - minunit_proc_timer);} while(0);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


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

v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = a2;
*(_DWORD *)(a1 + 24) = 0;
*(_QWORD *)(a1 + 32) = 0LL;
return 0LL;
}


canonical_decompiled_code:
__int64 __fastcall func10(void **a1)
{
void *v1; // rdi

v1 = *a1;
if ( v1 )
free(v1);
return 0LL;
}


cmpword

canonical_decompiled_code:
char *__fastcall func12(const char *a1, __int64 a2)
{
size_t v2; // rcx
__int64 v3; // rax
char v4; // dl
char *v5; // rbx
char v7; // bp
int v8; // eax

v2 = strlen(a1);
v3 = 0LL;
while ( v2 != v3 )
{
v4 = a1[v3++];
if ( v4 != *(_BYTE *)(a2 + v3 - 1) )
return 0LL;
}
v5 = (char *)(a2 + v3 + 1);
v7 = *v5;
v8 = isspace(*v5);
if ( v7 && !v8 )
v5 = 0LL;
return v5;
}


getword

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, char **a3)
{
__int64 v3; // rbx
char *v5; // rax

v3 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
v5 = func12(*(const char **)v3, a2);
if ( v5 )
break;
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return 0LL;
}
*a3 = v5;
return v3;
}


canonical_decompiled_code:
char *__fastcall func14(__int64 a1, const char *a2)
{
char *v2; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 (__fastcall *v6)(__int64, char *); // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = (char *)a2;
if ( *a2 )
{
endptr[0] = 0LL;
v4 = strtol(a2, endptr, 10);
if ( !endptr[0] || endptr[0] == a2 )
{
v5 = func13(*(_QWORD *)(a1 + 40), (__int64)a2, endptr);
if ( v5 )
{
v6 = *(__int64 (__fastcall **)(__int64, char *))(v5 + 16);
if ( v6 )
v2 = (char *)v6(a1, endptr[0]);
else
v2 = endptr[0];
}
else
{
*(_DWORD *)(a1 + 24) = 1;
*(_QWORD *)(a1 + 32) = "Unknown word";
}
}
else
{
if ( *endptr[0] == 117 )
v4 = strtoul(a2, endptr, 10);
func7((__int64 *)a1, v4);
v2 = endptr[0];
}
}
return v2;
}


canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int8 *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rax

v2 = (char *)a2;
while ( *v2 )
{
v3 = func11(a2);
v2 = func14(a1, (const char *)v3);
if ( *(_DWORD *)(a1 + 24) )
{
fprintf(
stderr,
"Error at character '%il'. Message: '%s'\n",
(unsigned int)((_DWORD)v2 - (_DWORD)a2),
*(const char **)(a1 + 32));
return 0xFFFFFFFFLL;
}
}
return 0LL;
}


strlcmpt

decompiled_code:
__int64 __fastcall strlcmpt(char *a1, char *a2, unsigned __int8 (__fastcall *a3)(_QWORD))
{
_BYTE *v6; // r13
_BYTE *v7; // r14

while ( 1 )
{
v6 = a1;
if ( a3((unsigned int)*a1) )
break;
v7 = a2;
if ( a3((unsigned int)*a2) )
return 0LL;
++a1;
++a2;
if ( *v6 != *v7 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, char *a2, unsigned __int8 (__fastcall *a3)(_QWORD))
{
_BYTE *v6; // r13
_BYTE *v7; // r14

while ( 1 )
{
v6 = a1;
if ( a3((unsigned int)*a1) )
break;
v7 = a2;
if ( a3((unsigned int)*a2) )
return 0LL;
++a1;
++a2;
if ( *v6 != *v7 )
return 1LL;
}
return 0LL;
}

original_code:
int strlcmpt(const char* str1, const char* str2, _Bool (*terminating)(char c))
{
  int i=0;
  while(!terminating(str1[i]) && !terminating(str2[i]))
  {
    if(str1[i] != str2[i])
    {
      return 1;
    }
    i++;
  }
  return 0;
}

canonical_original_code:
int strlcmpt(char *str1, char *str2, _Bool (*terminating)(char c))
{
  int i = 0;
  while(!terminating(str1[i]) && !terminating(str2[i]))
  {
    if(str1[i] != str2[i])
    {
      return 1;
    }
    i++;
  }
  return 0;
}

variable_types:
terminating
_Bool (*)(char c)


repo: Earnit/Hello-World

decompiled_code:
void __fastcall list_basic_add(__int64 a1)
{
int i; // ebx
_QWORD *v2; // rax

for ( i = 0; i != 5; ++i )
{
v2 = malloc(0x18uLL);
*(_DWORD *)v2 = i;
list_add_tail(v2 + 1, a1 + 8);
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
int i; // ebx
_QWORD *v2; // rax

for ( i = 0; i != 5; ++i )
{
v2 = malloc(0x18uLL);
*(_DWORD *)v2 = i;
func8(v2 + 1, a1 + 8);
}
}

original_code:
void list_basic_add(kool_list_t *list) {
    int i;
    kool_list_t *element;
    for (i = 0; i < 5; i++) {
 element = malloc(sizeof(kool_list_t));
 element->data = i;
 list_add_tail(&element->list, &list->list);
    }
}

canonical_original_code:
void list_basic_add(struct kool_list *list) {
    int i;
    struct kool_list *element;
    for (i = 0; i < 5; i++) {
 element = malloc(sizeof(kool_list_t));
 element->data = i;
 list_add_tail(&element->list, &list->list);
    }
}

variable_types: struct kool_list { int data; struct list_head { struct list_head *next; } list; } *

return_type: void

user_defined_types: struct kool_list { int data; struct list_head list; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = (__int64)v5;
v5[1] = (__int64)v5;
list_basic_add((__int64)&v4);
list_basic_print((__int64)&v4);
list_basic_print_simple((__int64)&v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v5[0] = (__int64)v5;
v5[1] = (__int64)v5;
func9((__int64)&v4);
func10((__int64)&v4);
func11((__int64)&v4);
return 0;
}

original_code:
int main(void) {
    kool_list_t my_list;
    do { (&(my_list.list))->next = (&(my_list.list)); (&(my_list.list))->prev = (&(my_list.list)); } while (0);
    list_basic_add(&my_list);
    list_basic_print(&my_list);
    list_basic_print_simple(&my_list);
    return 0;
}

canonical_original_code:
int main() {
    struct kool_list my_list;
    do { (&(my_list.list))->next = (&(my_list.list)); (&(my_list.list))->prev = (&(my_list.list)); } while (0);
    list_basic_add(&my_list);
    list_basic_print(&my_list);
    list_basic_print_simple(&my_list);
    return 0;
}

variable_types: struct kool_list { int data; struct list_head { struct list_head *next; } list; }


repo: EirSpace/Hera

decompiled_code:
__int64 __fastcall fc0012_writereg(__int64 a1, char a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
return (unsigned int)((int)rtlsdr_i2c_write_fn(a1, 198LL, v4, 2LL) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
return (unsigned int)((int)rtlsdr_i2c_write_fn(a1, 198LL, v4, 2LL) >> 31);
}

original_code:
static int fc0012_writereg(void *dev, uint8_t reg, uint8_t val)
{
 uint8_t data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

canonical_original_code:
static int fc0012_writereg(void *dev, unsigned char reg, unsigned char val)
{
 unsigned char data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

variable_types:
dev
void *

variable_types:
reg
unsigned char

variable_types:
val
unsigned char

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall fc0012_readreg(__int64 a1, char a2, _BYTE *a3)
{
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v5[0] = a2;
if ( (int)rtlsdr_i2c_write_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
if ( (int)rtlsdr_i2c_read_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
*a3 = v5[0];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2, _BYTE *a3)
{
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v5[0] = a2;
if ( (int)rtlsdr_i2c_write_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
if ( (int)rtlsdr_i2c_read_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
*a3 = v5[0];
return 0LL;
}

original_code:
static int fc0012_readreg(void *dev, uint8_t reg, uint8_t *val)
{
 uint8_t data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

canonical_original_code:
static int fc0012_readreg(void *dev, unsigned char reg, unsigned char *val)
{
 unsigned char data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

variable_types:
val
unsigned char *

variable_types:
data
unsigned char


variable_types: ret int

variable_types:
i
unsigned int

variable_types:
reg
unsigned char []


original_code:
int fc0012_set_params(void *dev, uint32_t freq, uint32_t bandwidth)
{
 int i, ret = 0;
 uint8_t reg[7], am, pm, multi, tmp;
 uint64_t f_vco;
 uint32_t xtal_freq_div_2;
 uint16_t xin, xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else {
  multi = 4;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (uint16_t)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (uint8_t)(xdiv / 8);
 am = (uint8_t)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0012] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (uint16_t)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0012_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0012_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0012_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

canonical_original_code:
int fc0012_set_params(void *dev, unsigned int freq, unsigned int bandwidth)
{
 int i; int ret = 0;
 unsigned char reg[7]; unsigned char am; unsigned char pm; unsigned char multi; unsigned char tmp;
 unsigned long f_vco;
 unsigned int xtal_freq_div_2;
 unsigned short xin; unsigned short xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else {
  multi = 4;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (unsigned short)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (unsigned char)(xdiv / 8);
 am = (unsigned char)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0012] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (unsigned short)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0012_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0012_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0012_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0012_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0012_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0012_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

variable_types:
freq
unsigned int

variable_types:
bandwidth
unsigned int

variable_types: i int

variable_types:
reg
unsigned char [7]

variable_types:
am
unsigned char

variable_types:
pm
unsigned char

variable_types:
multi
unsigned char

variable_types:
tmp
unsigned char

variable_types:
xin
unsigned short

variable_types:
xdiv
unsigned short


original_code:
int fc0012_set_gain(void *dev, int gain)
{
 int ret;
 uint8_t tmp = 0;
 ret = fc0012_readreg(dev, 0x13, &tmp);
 tmp &= 0xe0;
 switch (gain) {
 case -99:
  tmp |= 0x02;
  break;
 case -40:
  break;
 case 71:
  tmp |= 0x08;
  break;
 case 179:
  tmp |= 0x17;
  break;
 case 192:
 default:
  tmp |= 0x10;
  break;
 }
 ret = fc0012_writereg(dev, 0x13, tmp);
 return ret;
}

canonical_original_code:
int fc0012_set_gain(void *dev, int gain)
{
 int ret;
 unsigned char tmp = 0;
 ret = fc0012_readreg(dev, 0x13, &tmp);
 tmp &= 0xe0;
 switch (gain) {
 case -99:
  tmp |= 0x02;
  break;
 case -40:
  break;
 case 71:
  tmp |= 0x08;
  break;
 case 179:
  tmp |= 0x17;
  break;
 case 192:
 default:
  tmp |= 0x10;
  break;
 }
 ret = fc0012_writereg(dev, 0x13, tmp);
 return ret;
}

variable_types:
dev
void *

variable_types: gain int


decompiled_code:
__int64 __fastcall fc0013_writereg(__int64 a1, char a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
return (unsigned int)((int)rtlsdr_i2c_write_fn(a1, 198LL, v4, 2LL) >> 31);
}

original_code:
static int fc0013_writereg(void *dev, uint8_t reg, uint8_t val)
{
 uint8_t data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

canonical_original_code:
static int fc0013_writereg(void *dev, unsigned char reg, unsigned char val)
{
 unsigned char data[2];
 data[0] = reg;
 data[1] = val;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, data, 2) < 0)
  return -1;
 return 0;
}

variable_types:
reg
unsigned char

variable_types:
val
unsigned char

variable_types:
data
unsigned char [2]


decompiled_code:
__int64 __fastcall fc0013_readreg(__int64 a1, char a2, _BYTE *a3)
{
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

v5[0] = a2;
if ( (int)rtlsdr_i2c_write_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
if ( (int)rtlsdr_i2c_read_fn(a1, 198LL, v5, 1LL) < 0 )
return 0xFFFFFFFFLL;
*a3 = v5[0];
return 0LL;
}

original_code:
static int fc0013_readreg(void *dev, uint8_t reg, uint8_t *val)
{
 uint8_t data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

canonical_original_code:
static int fc0013_readreg(void *dev, unsigned char reg, unsigned char *val)
{
 unsigned char data = reg;
 if (rtlsdr_i2c_write_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 if (rtlsdr_i2c_read_fn(dev, 0xc6, &data, 1) < 0)
  return -1;
 *val = data;
 return 0;
}

variable_types:
val
unsigned char *

variable_types:
data
unsigned char


decompiled_code:
__int64 __fastcall fc0013_set_vhf_track(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3; // dl
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

result = fc0013_readreg(a1, 29, v4);
if ( !(_DWORD)result )
{
v3 = v4[0] & 0xE3;
v4[0] &= 0xE3u;
if ( a2 <= 0xA946F60 )
{
result = fc0013_writereg(a1, 29, v3 | 0x1Cu);
}
else if ( a2 <= 0xAFF3F20 )
{
result = fc0013_writereg(a1, 29, v3 | 0x18u);
}
else if ( a2 <= 0xB6A0EE0 )
{
result = fc0013_writereg(a1, 29, v3 | 0x14u);
}
else if ( a2 <= 0xBD4DEA0 )
{
result = fc0013_writereg(a1, 29, v3 | 0x10u);
}
else if ( a2 <= 0xC3FAE60 )
{
result = fc0013_writereg(a1, 29, v3 | 0xCu);
}
else if ( a2 <= 0xD154DE0 )
{
result = fc0013_writereg(a1, 29, v3 | 8u);
}
else if ( a2 > 0x11E1A2FF )
{
result = fc0013_writereg(a1, 29, v3 | 0x1Cu);
}
else
{
result = fc0013_writereg(a1, 29, v3 | 4u);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3; // dl
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

result = func1(a1, 29, v4);
if ( !(_DWORD)result )
{
v3 = v4[0] & 0xE3;
v4[0] &= 0xE3u;
if ( a2 <= 0xA946F60 )
{
result = func0(a1, 29, v3 | 0x1Cu);
}
else if ( a2 <= 0xAFF3F20 )
{
result = func0(a1, 29, v3 | 0x18u);
}
else if ( a2 <= 0xB6A0EE0 )
{
result = func0(a1, 29, v3 | 0x14u);
}
else if ( a2 <= 0xBD4DEA0 )
{
result = func0(a1, 29, v3 | 0x10u);
}
else if ( a2 <= 0xC3FAE60 )
{
result = func0(a1, 29, v3 | 0xCu);
}
else if ( a2 <= 0xD154DE0 )
{
result = func0(a1, 29, v3 | 8u);
}
else if ( a2 > 0x11E1A2FF )
{
result = func0(a1, 29, v3 | 0x1Cu);
}
else
{
result = func0(a1, 29, v3 | 4u);
}
}
return result;
}

original_code:
static int fc0013_set_vhf_track(void *dev, uint32_t freq)
{
 int ret;
 uint8_t tmp;
 ret = fc0013_readreg(dev, 0x1d, &tmp);
 if (ret)
  goto error_out;
 tmp &= 0xe3;
 if (freq <= 177500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 } else if (freq <= 184500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x18);
 } else if (freq <= 191500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x14);
 } else if (freq <= 198500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x10);
 } else if (freq <= 205500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x0c);
 } else if (freq <= 219500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x08);
 } else if (freq < 300000000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x04);
 } else {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 }
error_out:
 return ret;
}

canonical_original_code:
static int fc0013_set_vhf_track(void *dev, unsigned int freq)
{
 int ret;
 unsigned char tmp;
 ret = fc0013_readreg(dev, 0x1d, &tmp);
 if (ret)
  goto error_out;
 tmp &= 0xe3;
 if (freq <= 177500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 } else if (freq <= 184500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x18);
 } else if (freq <= 191500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x14);
 } else if (freq <= 198500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x10);
 } else if (freq <= 205500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x0c);
 } else if (freq <= 219500000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x08);
 } else if (freq < 300000000) {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x04);
 } else {
  ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c);
 }
error_out:
 return ret;
}

variable_types:
freq
unsigned int

variable_types: ret int


decompiled_code:
__int64 __fastcall fc0013_rc_cal_add(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int8 v3; // r12
int v4; // ebp
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

result = fc0013_writereg(a1, 16, 0);
if ( !(_DWORD)result )
{
result = fc0013_readreg(a1, 16, v5);
if ( !(_DWORD)result )
{
v3 = v5[0] & 0xF;
v5[0] &= 0xFu;
result = fc0013_writereg(a1, 13, 17);
if ( !(_DWORD)result )
{
v4 = v3 + a2;
if ( v4 > 15 )
{
result = fc0013_writereg(a1, 16, 15);
}
else if ( v4 < 0 )
{
result = fc0013_writereg(a1, 16, 0);
}
else
{
result = fc0013_writereg(a1, 16, v4);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int8 v3; // r12
int v4; // ebp
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

result = func0(a1, 16, 0);
if ( !(_DWORD)result )
{
result = func1(a1, 16, v5);
if ( !(_DWORD)result )
{
v3 = v5[0] & 0xF;
v5[0] &= 0xFu;
result = func0(a1, 13, 17);
if ( !(_DWORD)result )
{
v4 = v3 + a2;
if ( v4 > 15 )
{
result = func0(a1, 16, 15);
}
else if ( v4 < 0 )
{
result = func0(a1, 16, 0);
}
else
{
result = func0(a1, 16, v4);
}
}
}
}
return result;
}

original_code:
int fc0013_rc_cal_add(void *dev, int rc_val)
{
 int ret;
 uint8_t rc_cal;
 int val;
 ret = fc0013_writereg(dev, 0x10, 0x00);
 if (ret)
  goto error_out;
 ret = fc0013_readreg(dev, 0x10, &rc_cal);
 if (ret)
  goto error_out;
 rc_cal &= 0x0f;
 val = (int)rc_cal + rc_val;
 ret = fc0013_writereg(dev, 0x0d, 0x11);
 if (ret)
  goto error_out;
 if (val > 15)
  ret = fc0013_writereg(dev, 0x10, 0x0f);
 else if (val < 0)
  ret = fc0013_writereg(dev, 0x10, 0x00);
 else
  ret = fc0013_writereg(dev, 0x10, (uint8_t)val);
error_out:
 return ret;
}

canonical_original_code:
int fc0013_rc_cal_add(void *dev, int rc_val)
{
 int ret;
 unsigned char rc_cal;
 int val;
 ret = fc0013_writereg(dev, 0x10, 0x00);
 if (ret)
  goto error_out;
 ret = fc0013_readreg(dev, 0x10, &rc_cal);
 if (ret)
  goto error_out;
 rc_cal &= 0x0f;
 val = (int)rc_cal + rc_val;
 ret = fc0013_writereg(dev, 0x0d, 0x11);
 if (ret)
  goto error_out;
 if (val > 15)
  ret = fc0013_writereg(dev, 0x10, 0x0f);
 else if (val < 0)
  ret = fc0013_writereg(dev, 0x10, 0x00);
 else
  ret = fc0013_writereg(dev, 0x10, (unsigned char)val);
error_out:
 return ret;
}

variable_types: val int


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

result = fc0013_writereg(a1, 13, 1);
if ( !(_DWORD)result )
result = fc0013_writereg(a1, 16, 0);
return result;
}

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

result = func0(a1, 13, 1);
if ( !(_DWORD)result )
result = func0(a1, 16, 0);
return result;
}

original_code:
int fc0013_rc_cal_reset(void *dev)
{
 int ret;
 ret = fc0013_writereg(dev, 0x0d, 0x01);
 if (!ret)
  ret = fc0013_writereg(dev, 0x10, 0x00);
 return ret;
}


decompiled_code:
__int64 __fastcall fc0013_set_params(__int64 a1, unsigned int a2, int a3)
{
unsigned int v6; // er14
unsigned int v7; // ebp
unsigned int v8; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned __int8 v14; // r15
unsigned int v15; // eax
unsigned __int64 v16; // rcx
unsigned __int64 v17; // rsi
unsigned __int16 v18; // dx
__int16 v19; // di
char v20; // al
unsigned __int8 v21; // dl
unsigned int v22; // eax
char v23; // al
char v24; // dl
char v25; // al
__int64 i; // r12
unsigned int v27; // eax
unsigned int v28; // eax
unsigned int v29; // eax
unsigned int v30; // eax
unsigned int v31; // eax
unsigned int v32; // eax
unsigned int v33; // eax
unsigned int v34; // eax
unsigned int v35; // eax
unsigned int v36; // eax
unsigned int v37; // eax
unsigned int v38; // eax
char v39; // dl
unsigned __int8 v40; // cl
char v41[2]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int8 v42; // [rsp+Ah] [rbp-3Eh]
char v43; // [rsp+Bh] [rbp-3Dh]
char v44; // [rsp+Ch] [rbp-3Ch]
char v45; // [rsp+Dh] [rbp-3Bh]
char v46; // [rsp+Eh] [rbp-3Ah]
char v47; // [rsp+Fh] [rbp-39h]

v6 = rtlsdr_get_tuner_clock();
v7 = fc0013_set_vhf_track(a1, a2);
if ( v7 )
return v7;
if ( a2 <= 0x11E1A2FF )
{
v10 = fc0013_readreg(a1, 7, v41);
if ( v10 )
return v10;
v11 = fc0013_writereg(a1, 7, v41[0] | 0x10u);
if ( v11 )
return v11;
v12 = fc0013_readreg(a1, 20, v41);
if ( v12 )
return v12;
v13 = fc0013_writereg(a1, 20, v41[0] & 0x1F);
if ( v13 )
return v13;
if ( a2 <= 0x235DB5F )
{
v46 = -126;
v47 = 0;
v14 = 96;
goto LABEL_16;
}
if ( a2 > 0x350C527 )
{
if ( a2 > 0x46BB2D7 )
{
if ( a2 > 0x6A18A4F )
{
if ( a2 > 0x8D765AF )
{
if ( a2 > 0xD43149F )
{
if ( a2 > 0x11AEC777 )
{
LABEL_42:
v46 = 34;
v47 = 2;
v14 = 8;
goto LABEL_16;
}
v46 = 18;
v47 = 0;
v14 = 12;
}
else
{
v46 = 66;
v47 = 2;
v14 = 16;
}
}
else
{
v46 = 34;
v47 = 0;
v14 = 24;
}
}
else
{
v46 = -126;
v47 = 2;
v14 = 32;
}
}
else
{
v46 = 66;
v47 = 0;
v14 = 48;
}
}
else
{
v46 = 2;
v47 = 2;
v14 = 64;
}
}
else
{
if ( a2 > 0x33611380 )
{
v33 = fc0013_readreg(a1, 7, v41);
if ( v33 )
return v33;
v34 = fc0013_writereg(a1, 7, v41[0] & 0xEF);
if ( v34 )
return v34;
v35 = fc0013_readreg(a1, 20, v41);
if ( v35 )
return v35;
v36 = fc0013_writereg(a1, 20, v41[0] & 0x1F | 0x20u);
if ( v36 )
return v36;
}
else
{
v8 = fc0013_readreg(a1, 7, v41);
if ( v8 )
return v8;
v30 = fc0013_writereg(a1, 7, v41[0] & 0xEF);
if ( v30 )
return v30;
v31 = fc0013_readreg(a1, 20, v41);
if ( v31 )
return v31;
v32 = fc0013_writereg(a1, 20, v41[0] & 0x1F | 0x40u);
if ( v32 )
return v32;
if ( a2 <= 0x1A86293F )
goto LABEL_42;
if ( a2 <= 0x235D8EEF )
{
v46 = 10;
v47 = 0;
v14 = 6;
goto LABEL_16;
}
}
if ( a2 > 0x389FD97F )
{
v46 = 10;
v47 = 2;
v14 = 2;
}
else
{
v46 = 18;
v47 = 2;
v14 = 4;
}
}
LABEL_16:
v15 = a2 * v14;
v16 = v15;
if ( v15 > 0xB663E4FF )
{
v47 |= 8u;
v7 = 1;
}
v17 = v6 >> 1;
v18 = v15 / (v6 >> 1)
- ((v15 - (unsigned __int64)((unsigned int)v17 * (unsigned __int16)(v15 / (v6 >> 1))) < v6 >> 2)
- 1);
v19 = v18 >> 3;
v20 = v18 >> 3;
v21 = v18 - 8 * v20;
if ( v21 <= 1u )
{
v21 += 8;
v20 = v19 - 1;
}
if ( (unsigned __int8)v20 > 0x1Fu )
{
v42 = v21 + 8 * v20 + 8;
v43 = 31;
if ( v42 <= 0xFu )
goto LABEL_22;
LABEL_69:
fprintf(stderr, "[FC0013] no valid PLL combination found for %u Hz!\n", a2);
return (unsigned int)-1;
}
v42 = v21;
v43 = v20;
if ( v21 > 0xFu || (unsigned __int8)v20 <= 0xAu )
goto LABEL_69;
LABEL_22:
v22 = ((unsigned __int16)(v16 % v17 / 0x3E8) << 15) / (v6 / 0x7D0);
if ( (unsigned __int16)v22 > 0x3FFFu )
LOWORD(v22) = v22 + 0x8000;
v44 = BYTE1(v22);
v45 = v22;
v23 = v47 & 0x3F;
if ( a3 == 6000000 )
{
v47 = v23 | 0xA0;
}
else
{
v24 = v23 | 0x60;
v25 = v23 | 0x20;
if ( a3 == 7000000 )
v25 = v24;
v47 = v25;
}
v46 |= 7u;
for ( i = 1LL; i != 7; ++i )
{
v27 = fc0013_writereg(a1, i, v41[i + 1]);
if ( v27 )
return v27;
}
v28 = fc0013_readreg(a1, 17, v41);
if ( v28 )
return v28;
if ( v14 == 64 )
v29 = fc0013_writereg(a1, 17, v41[0] | 4u);
else
v29 = fc0013_writereg(a1, 17, v41[0] & 0xFB);
if ( v29 )
return v29;
v37 = fc0013_writereg(a1, 14, 128);
if ( v37 )
return v37;
v37 = fc0013_writereg(a1, 14, 0);
if ( v37 )
return v37;
v37 = fc0013_writereg(a1, 14, 0);
if ( v37 )
return v37;
v38 = fc0013_readreg(a1, 14, v41);
if ( v38 )
return v38;
v39 = v41[0];
v40 = v41[0] & 0x3F;
v41[0] &= 0x3Fu;
if ( v7 )
{
v7 = 0;
if ( v40 > 0x3Cu )
{
v7 = fc0013_writereg(a1, 6, v47 & 0xF7);
if ( !v7 )
{
v7 = fc0013_writereg(a1, 14, 128);
if ( !v7 )
return (unsigned int)fc0013_writereg(a1, 14, 0);
}
}
}
else if ( (v39 & 0x3E) == 0 )
{
v7 = fc0013_writereg(a1, 6, v47 | 8u);
if ( !v7 )
{
v7 = fc0013_writereg(a1, 14, 128);
if ( !v7 )
return (unsigned int)fc0013_writereg(a1, 14, 0);
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, int a3)
{
unsigned int v6; // er14
unsigned int v7; // ebp
unsigned int v8; // eax
unsigned int v10; // eax
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // eax
unsigned __int8 v14; // r15
unsigned int v15; // eax
unsigned __int64 v16; // rcx
unsigned __int64 v17; // rsi
unsigned __int16 v18; // dx
__int16 v19; // di
char v20; // al
unsigned __int8 v21; // dl
unsigned int v22; // eax
char v23; // al
char v24; // dl
char v25; // al
__int64 i; // r12
unsigned int v27; // eax
unsigned int v28; // eax
unsigned int v29; // eax
unsigned int v30; // eax
unsigned int v31; // eax
unsigned int v32; // eax
unsigned int v33; // eax
unsigned int v34; // eax
unsigned int v35; // eax
unsigned int v36; // eax
unsigned int v37; // eax
unsigned int v38; // eax
char v39; // dl
unsigned __int8 v40; // cl
char v41[2]; // [rsp+8h] [rbp-40h] BYREF
unsigned __int8 v42; // [rsp+Ah] [rbp-3Eh]
char v43; // [rsp+Bh] [rbp-3Dh]
char v44; // [rsp+Ch] [rbp-3Ch]
char v45; // [rsp+Dh] [rbp-3Bh]
char v46; // [rsp+Eh] [rbp-3Ah]
char v47; // [rsp+Fh] [rbp-39h]

v6 = rtlsdr_get_tuner_clock();
v7 = func2(a1, a2);
if ( v7 )
return v7;
if ( a2 <= 0x11E1A2FF )
{
v10 = func1(a1, 7, v41);
if ( v10 )
return v10;
v11 = func0(a1, 7, v41[0] | 0x10u);
if ( v11 )
return v11;
v12 = func1(a1, 20, v41);
if ( v12 )
return v12;
v13 = func0(a1, 20, v41[0] & 0x1F);
if ( v13 )
return v13;
if ( a2 <= 0x235DB5F )
{
v46 = -126;
v47 = 0;
v14 = 96;
goto LABEL_16;
}
if ( a2 > 0x350C527 )
{
if ( a2 > 0x46BB2D7 )
{
if ( a2 > 0x6A18A4F )
{
if ( a2 > 0x8D765AF )
{
if ( a2 > 0xD43149F )
{
if ( a2 > 0x11AEC777 )
{
LABEL_42:
v46 = 34;
v47 = 2;
v14 = 8;
goto LABEL_16;
}
v46 = 18;
v47 = 0;
v14 = 12;
}
else
{
v46 = 66;
v47 = 2;
v14 = 16;
}
}
else
{
v46 = 34;
v47 = 0;
v14 = 24;
}
}
else
{
v46 = -126;
v47 = 2;
v14 = 32;
}
}
else
{
v46 = 66;
v47 = 0;
v14 = 48;
}
}
else
{
v46 = 2;
v47 = 2;
v14 = 64;
}
}
else
{
if ( a2 > 0x33611380 )
{
v33 = func1(a1, 7, v41);
if ( v33 )
return v33;
v34 = func0(a1, 7, v41[0] & 0xEF);
if ( v34 )
return v34;
v35 = func1(a1, 20, v41);
if ( v35 )
return v35;
v36 = func0(a1, 20, v41[0] & 0x1F | 0x20u);
if ( v36 )
return v36;
}
else
{
v8 = func1(a1, 7, v41);
if ( v8 )
return v8;
v30 = func0(a1, 7, v41[0] & 0xEF);
if ( v30 )
return v30;
v31 = func1(a1, 20, v41);
if ( v31 )
return v31;
v32 = func0(a1, 20, v41[0] & 0x1F | 0x40u);
if ( v32 )
return v32;
if ( a2 <= 0x1A86293F )
goto LABEL_42;
if ( a2 <= 0x235D8EEF )
{
v46 = 10;
v47 = 0;
v14 = 6;
goto LABEL_16;
}
}
if ( a2 > 0x389FD97F )
{
v46 = 10;
v47 = 2;
v14 = 2;
}
else
{
v46 = 18;
v47 = 2;
v14 = 4;
}
}
LABEL_16:
v15 = a2 * v14;
v16 = v15;
if ( v15 > 0xB663E4FF )
{
v47 |= 8u;
v7 = 1;
}
v17 = v6 >> 1;
v18 = v15 / (v6 >> 1)
- ((v15 - (unsigned __int64)((unsigned int)v17 * (unsigned __int16)(v15 / (v6 >> 1))) < v6 >> 2)
- 1);
v19 = v18 >> 3;
v20 = v18 >> 3;
v21 = v18 - 8 * v20;
if ( v21 <= 1u )
{
v21 += 8;
v20 = v19 - 1;
}
if ( (unsigned __int8)v20 > 0x1Fu )
{
v42 = v21 + 8 * v20 + 8;
v43 = 31;
if ( v42 <= 0xFu )
goto LABEL_22;
LABEL_69:
fprintf(stderr, "[FC0013] no valid PLL combination found for %u Hz!\n", a2);
return (unsigned int)-1;
}
v42 = v21;
v43 = v20;
if ( v21 > 0xFu || (unsigned __int8)v20 <= 0xAu )
goto LABEL_69;
LABEL_22:
v22 = ((unsigned __int16)(v16 % v17 / 0x3E8) << 15) / (v6 / 0x7D0);
if ( (unsigned __int16)v22 > 0x3FFFu )
LOWORD(v22) = v22 + 0x8000;
v44 = BYTE1(v22);
v45 = v22;
v23 = v47 & 0x3F;
if ( a3 == 6000000 )
{
v47 = v23 | 0xA0;
}
else
{
v24 = v23 | 0x60;
v25 = v23 | 0x20;
if ( a3 == 7000000 )
v25 = v24;
v47 = v25;
}
v46 |= 7u;
for ( i = 1LL; i != 7; ++i )
{
v27 = func0(a1, i, v41[i + 1]);
if ( v27 )
return v27;
}
v28 = func1(a1, 17, v41);
if ( v28 )
return v28;
if ( v14 == 64 )
v29 = func0(a1, 17, v41[0] | 4u);
else
v29 = func0(a1, 17, v41[0] & 0xFB);
if ( v29 )
return v29;
v37 = func0(a1, 14, 128);
if ( v37 )
return v37;
v37 = func0(a1, 14, 0);
if ( v37 )
return v37;
v37 = func0(a1, 14, 0);
if ( v37 )
return v37;
v38 = func1(a1, 14, v41);
if ( v38 )
return v38;
v39 = v41[0];
v40 = v41[0] & 0x3F;
v41[0] &= 0x3Fu;
if ( v7 )
{
v7 = 0;
if ( v40 > 0x3Cu )
{
v7 = func0(a1, 6, v47 & 0xF7);
if ( !v7 )
{
v7 = func0(a1, 14, 128);
if ( !v7 )
return (unsigned int)func0(a1, 14, 0);
}
}
}
else if ( (v39 & 0x3E) == 0 )
{
v7 = func0(a1, 6, v47 | 8u);
if ( !v7 )
{
v7 = func0(a1, 14, 128);
if ( !v7 )
return (unsigned int)func0(a1, 14, 0);
}
}
return v7;
}

original_code:
int fc0013_set_params(void *dev, uint32_t freq, uint32_t bandwidth)
{
 int i, ret = 0;
 uint8_t reg[7], am, pm, multi, tmp;
 uint64_t f_vco;
 uint32_t xtal_freq_div_2;
 uint16_t xin, xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 ret = fc0013_set_vhf_track(dev, freq);
 if (ret)
  goto exit;
 if (freq < 300000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp | 0x10);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, tmp & 0x1f);
  if (ret)
   goto exit;
 } else if (freq <= 862000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x40);
  if (ret)
   goto exit;
 } else {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x20);
  if (ret)
   goto exit;
 }
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x02;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else if (freq < 950000000) {
  multi = 4;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else {
  multi = 2;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (uint16_t)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (uint8_t)(xdiv / 8);
 am = (uint8_t)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0013] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (uint16_t)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0013_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0013_readreg(dev, 0x11, &tmp);
 if (ret)
  goto exit;
 if (multi == 64)
  ret = fc0013_writereg(dev, 0x11, tmp | 0x04);
 else
  ret = fc0013_writereg(dev, 0x11, tmp & 0xfb);
 if (ret)
  goto exit;
 ret = fc0013_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0013_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

canonical_original_code:
int fc0013_set_params(void *dev, unsigned int freq, unsigned int bandwidth)
{
 int i; int ret = 0;
 unsigned char reg[7]; unsigned char am; unsigned char pm; unsigned char multi; unsigned char tmp;
 unsigned long f_vco;
 unsigned int xtal_freq_div_2;
 unsigned short xin; unsigned short xdiv;
 int vco_select = 0;
 xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2;
 ret = fc0013_set_vhf_track(dev, freq);
 if (ret)
  goto exit;
 if (freq < 300000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp | 0x10);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, tmp & 0x1f);
  if (ret)
   goto exit;
 } else if (freq <= 862000000) {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x40);
  if (ret)
   goto exit;
 } else {
  ret = fc0013_readreg(dev, 0x07, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x07, tmp & 0xef);
  if (ret)
   goto exit;
  ret = fc0013_readreg(dev, 0x14, &tmp);
  if (ret)
   goto exit;
  ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x20);
  if (ret)
   goto exit;
 }
 if (freq < 37084000) {
  multi = 96;
  reg[5] = 0x82;
  reg[6] = 0x00;
 } else if (freq < 55625000) {
  multi = 64;
  reg[5] = 0x02;
  reg[6] = 0x02;
 } else if (freq < 74167000) {
  multi = 48;
  reg[5] = 0x42;
  reg[6] = 0x00;
 } else if (freq < 111250000) {
  multi = 32;
  reg[5] = 0x82;
  reg[6] = 0x02;
 } else if (freq < 148334000) {
  multi = 24;
  reg[5] = 0x22;
  reg[6] = 0x00;
 } else if (freq < 222500000) {
  multi = 16;
  reg[5] = 0x42;
  reg[6] = 0x02;
 } else if (freq < 296667000) {
  multi = 12;
  reg[5] = 0x12;
  reg[6] = 0x00;
 } else if (freq < 445000000) {
  multi = 8;
  reg[5] = 0x22;
  reg[6] = 0x02;
 } else if (freq < 593334000) {
  multi = 6;
  reg[5] = 0x0a;
  reg[6] = 0x00;
 } else if (freq < 950000000) {
  multi = 4;
  reg[5] = 0x12;
  reg[6] = 0x02;
 } else {
  multi = 2;
  reg[5] = 0x0a;
  reg[6] = 0x02;
 }
 f_vco = freq * multi;
 if (f_vco >= 3060000000U) {
  reg[6] |= 0x08;
  vco_select = 1;
 }
 xdiv = (unsigned short)(f_vco / xtal_freq_div_2);
 if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2))
  xdiv++;
 pm = (unsigned char)(xdiv / 8);
 am = (unsigned char)(xdiv - (8 * pm));
 if (am < 2) {
  am += 8;
  pm--;
 }
 if (pm > 31) {
  reg[1] = am + (8 * (pm - 31));
  reg[2] = 31;
 } else {
  reg[1] = am;
  reg[2] = pm;
 }
 if ((reg[1] > 15) || (reg[2] < 0x0b)) {
  fprintf(stderr, "[FC0013] no valid PLL combination "
    "found for %u Hz!\n", freq);
  return -1;
 }
 reg[6] |= 0x20;
 xin = (unsigned short)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000);
 xin = (xin << 15) / (xtal_freq_div_2 / 1000);
 if (xin >= 16384)
  xin += 32768;
 reg[3] = xin >> 8;
 reg[4] = xin & 0xff;
 reg[6] &= 0x3f;
 switch (bandwidth) {
 case 6000000:
  reg[6] |= 0x80;
  break;
 case 7000000:
  reg[6] |= 0x40;
  break;
 case 8000000:
 default:
  break;
 }
 reg[5] |= 0x07;
 for (i = 1; i <= 6; i++) {
  ret = fc0013_writereg(dev, i, reg[i]);
  if (ret)
   goto exit;
 }
 ret = fc0013_readreg(dev, 0x11, &tmp);
 if (ret)
  goto exit;
 if (multi == 64)
  ret = fc0013_writereg(dev, 0x11, tmp | 0x04);
 else
  ret = fc0013_writereg(dev, 0x11, tmp & 0xfb);
 if (ret)
  goto exit;
 ret = fc0013_writereg(dev, 0x0e, 0x80);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret)
  ret = fc0013_writereg(dev, 0x0e, 0x00);
 if (!ret) {
  ret = fc0013_readreg(dev, 0x0e, &tmp);
 }
 if (ret)
  goto exit;
 tmp &= 0x3f;
 if (vco_select) {
  if (tmp > 0x3c) {
   reg[6] &= ~0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 } else {
  if (tmp < 0x02) {
   reg[6] |= 0x08;
   ret = fc0013_writereg(dev, 0x06, reg[6]);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x80);
   if (!ret)
    ret = fc0013_writereg(dev, 0x0e, 0x00);
  }
 }
exit:
 return ret;
}

variable_types:
bandwidth
unsigned int

variable_types: i int

variable_types:
reg
unsigned char [7]


decompiled_code:
__int64 __fastcall fc0013_set_gain_mode(__int64 a1, int a2)
{
int v2; // ebp
char v3; // dl
int v4; // ebx
char v6[41]; // [rsp+Fh] [rbp-29h] BYREF

v6[0] = 0;
v2 = fc0013_readreg(a1, 13, v6);
if ( a2 )
v3 = v6[0] | 8;
else
v3 = v6[0] & 0xF7;
v6[0] = v3;
v4 = fc0013_writereg(a1, 13, v3);
return v2 | v4 | (unsigned int)fc0013_writereg(a1, 19, 10);
}

original_code:
int fc0013_set_gain_mode(void *dev, int manual)
{
 int ret = 0;
 uint8_t tmp = 0;
 ret |= fc0013_readreg(dev, 0x0d, &tmp);
 if (manual)
  tmp |= (1 << 3);
 else
  tmp &= ~(1 << 3);
 ret |= fc0013_writereg(dev, 0x0d, tmp);
 ret |= fc0013_writereg(dev, 0x13, 0x0a);
 return ret;
}

canonical_original_code:
int fc0013_set_gain_mode(void *dev, int manual)
{
 int ret = 0;
 unsigned char tmp = 0;
 ret |= fc0013_readreg(dev, 0x0d, &tmp);
 if (manual)
  tmp |= (1 << 3);
 else
  tmp &= ~(1 << 3);
 ret |= fc0013_writereg(dev, 0x0d, tmp);
 ret |= fc0013_writereg(dev, 0x13, 0x0a);
 return ret;
}

variable_types: manual int


original_code:
int fc0013_set_lna_gain(void *dev, int gain)
{
 int ret = 0;
 unsigned int i;
 uint8_t tmp = 0;
 ret |= fc0013_readreg(dev, 0x14, &tmp);
 tmp &= 0xe0;
 for (i = 0; i < (sizeof(fc0013_lna_gains) / sizeof(int) / 2); i++) {
  if ((fc0013_lna_gains[i*2] >= gain) || (i+1 == (sizeof(fc0013_lna_gains) / sizeof(int) / 2))) {
   tmp |= fc0013_lna_gains[i*2 + 1];
   break;
  }
 }
 ret |= fc0013_writereg(dev, 0x14, tmp);
 return ret;
}

canonical_original_code:
int fc0013_set_lna_gain(void *dev, int gain)
{
 int ret = 0;
 unsigned int i;
 unsigned char tmp = 0;
 ret |= fc0013_readreg(dev, 0x14, &tmp);
 tmp &= 0xe0;
 for (i = 0; i < (sizeof(fc0013_lna_gains) / sizeof(int) / 2); i++) {
  if ((fc0013_lna_gains[i*2] >= gain) || (i+1 == (sizeof(fc0013_lna_gains) / sizeof(int) / 2))) {
   tmp |= fc0013_lna_gains[i*2 + 1];
   break;
  }
 }
 ret |= fc0013_writereg(dev, 0x14, tmp);
 return ret;
}

variable_types:
i
unsigned int

variable_types:
tmp
unsigned char


initializetcpudpchannel

repo: Eivindfy/Prosjekt-sanntid

decompiled_code:
__int64 initializetcpudpchannel()
{
_DWORD *v0; // rax
pthread_t v2; // [rsp+0h] [rbp-18h] BYREF
int fds[2]; // [rsp+8h] [rbp-10h] BYREF

socketpair(1, 1, 0, fds);
v0 = malloc(4uLL);
*v0 = fds[0];
pthread_create(&v2, 0LL, (void *(*)(void *))tcpudpchannel, v0);
return (unsigned int)fds[1];
}

canonical_decompiled_code:
__int64 func9()
{
_DWORD *v0; // rax
pthread_t v2; // [rsp+0h] [rbp-18h] BYREF
int fds[2]; // [rsp+8h] [rbp-10h] BYREF

socketpair(1, 1, 0, fds);
v0 = malloc(4uLL);
*v0 = fds[0];
pthread_create(&v2, 0LL, (void *(*)(void *))tcpudpchannel, v0);
return (unsigned int)fds[1];
}

original_code:
int initializetcpudpchannel(){
 int fd[2];
 socketpair(1, SOCK_STREAM, 0, fd);
 int* dynamic_int_pointer = malloc(sizeof(*dynamic_int_pointer));
 *dynamic_int_pointer = fd[0];
 void* dynamic_void_pointer;
 dynamic_void_pointer = (void*)dynamic_int_pointer;
 pthread_t channel;
 pthread_create(&channel,((void *)0), tcpudpchannel, dynamic_void_pointer);
 return fd[1];
}

canonical_original_code:
int initializetcpudpchannel(){
 int fd[2];
 socketpair(1, SOCK_STREAM, 0, fd);
 int *dynamic_int_pointer = malloc(sizeof(*dynamic_int_pointer));
 *dynamic_int_pointer = fd[0];
 void *dynamic_void_pointer;
 dynamic_void_pointer = (void *)dynamic_int_pointer;
 unsigned long channel;
 pthread_create(&channel,((void *)0), tcpudpchannel, dynamic_void_pointer);
 return fd[1];
}

variable_types:
fd
int [2]

variable_types:
channel
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
char v6[1024]; // [rsp+0h] [rbp-818h] BYREF
__int64 buf[131]; // [rsp+400h] [rbp-418h] BYREF

puts("UDPTEST: starta programmet");
strcpy((char *)buf, "melding\n");
v3 = initializetcpudpchannel("UDPTEST: starta programmet", argv);
v4 = initializetcpudpchannel("UDPTEST: starta programmet", argv);
sleep(2u);
puts("UDPTEST: Sending to socketfd");
send(v3, buf, 0x400uLL, 0);
puts("UDPTEST: Receiving from socketfd2 ");
recv(v4, v6, 0x400uLL, 0);
printf("her skal melding komme: %s \n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
char v6[1024]; // [rsp+0h] [rbp-818h] BYREF
__int64 buf[131]; // [rsp+400h] [rbp-418h] BYREF

puts("UDPTEST: starta programmet");
strcpy((char *)buf, "melding\n");
v3 = func9("UDPTEST: starta programmet", argv);
v4 = func9("UDPTEST: starta programmet", argv);
sleep(2u);
puts("UDPTEST: Sending to socketfd");
send(v3, buf, 0x400uLL, 0);
puts("UDPTEST: Receiving from socketfd2 ");
recv(v4, v6, 0x400uLL, 0);
printf("her skal melding komme: %s \n", v6);
return 0;
}

original_code:
int main(){
 printf("UDPTEST: starta programmet\n");
 char send_buffer[1024];
 strcpy(send_buffer,"melding\n");
 char recv_buffer[1024];
 int socketfd = initializetcpudpchannel();
 int socketfd2 = initializetcpudpchannel();
 sleep(2);
 printf("UDPTEST: Sending to socketfd\n");
 send(socketfd, send_buffer, sizeof(send_buffer), 0);
 printf("UDPTEST: Receiving from socketfd2 \n");
 recv(socketfd2, recv_buffer, sizeof(recv_buffer), 0);
 printf("her skal melding komme: %s \n", recv_buffer);
 return 0;
}

variable_types: socketfd int


repo: ElFeesho/OldCProjects

decompiled_code:
int __fastcall convert_to_dec(const char *a1)
{
int v2; // eax
int v3; // er10
const char *v4; // rdi
int v5; // esi
unsigned int v6; // er8
char v7; // cl
int v8; // eax

v2 = strlen(a1);
if ( v2 <= 0 )
{
v6 = 0;
}
else
{
v3 = v2;
v4 = &a1[v2 - 1];
v5 = 0;
v6 = 0;
do
{
v7 = v5++;
v8 = 0;
if ( *v4 != 48 )
v8 = 1 << v7;
v6 += v8;
--v4;
}
while ( v5 != v3 );
}
return printf("Binary: %s - Dec: %d\n", a1, v6);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
int v2; // eax
int v3; // er10
const char *v4; // rdi
int v5; // esi
unsigned int v6; // er8
char v7; // cl
int v8; // eax

v2 = strlen(a1);
if ( v2 <= 0 )
{
v6 = 0;
}
else
{
v3 = v2;
v4 = &a1[v2 - 1];
v5 = 0;
v6 = 0;
do
{
v7 = v5++;
v8 = 0;
if ( *v4 != 48 )
v8 = 1 << v7;
v6 += v8;
--v4;
}
while ( v5 != v3 );
}
return printf("Binary: %s - Dec: %d\n", a1, v6);
}

original_code:
void convert_to_dec(char *binary_str)
{
 int res = 0;
 int binary_len = strlen(binary_str);
 int i = 0;
 for(i = 0; i<binary_len; i++)
 {
  res += (binary_str[binary_len-(i+1)]=='0')?(0):(1<<i);
 }
 printf("Binary: %s - Dec: %d\n",binary_str, res);
}

variable_types: res int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
convert_to_dec(argv[1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
func7(argv[1]);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if(argc<2)
 {
  return 0;
 }
 convert_to_dec(argv[1]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


original_code:
static void mimic_init(MimCtx *ctx, gint width, gint height)
{
    gint bufsize, i;
    ctx->frame_width = width;
    ctx->frame_height = height;
    ctx->y_stride = ctx->frame_width;
    ctx->y_row_count = ctx->frame_height;
    ctx->y_size = ctx->y_stride * ctx->y_row_count;
    ctx->crcb_stride = ctx->y_stride / 2;
    ctx->crcb_row_count = ctx->y_row_count / 2;
    ctx->crcb_size = ctx->crcb_stride * ctx->crcb_row_count;
    ctx->num_vblocks_y = ctx->frame_height / 8;
    ctx->num_hblocks_y = ctx->frame_width / 8;
    ctx->num_vblocks_cbcr = ctx->frame_height / 16;
    ctx->num_hblocks_cbcr = ctx->frame_width / 16;
    if (ctx->frame_height % 16 != 0)
        ctx->num_vblocks_cbcr++;
    ctx->frame_num = 0;
    ctx->ptr_index = 15;
    ctx->num_coeffs = 28;
    ctx->cur_frame_buf = ((guchar *) g_malloc_n (((320 * 240 * 3) / 2), sizeof (guchar)));
    bufsize = ctx->y_size + (ctx->crcb_size * 2);
    for (i = 0; i < 16; i++)
        ctx->buf_ptrs[i] = ((guchar *) g_malloc_n ((bufsize), sizeof (guchar)));
    _initialize_vlcdec_lookup(ctx->vlcdec_lookup);
}

canonical_original_code:
static void mimic_init(struct _MimCtx *ctx, int width, int height)
{
    int bufsize; int i;
    ctx->frame_width = width;
    ctx->frame_height = height;
    ctx->y_stride = ctx->frame_width;
    ctx->y_row_count = ctx->frame_height;
    ctx->y_size = ctx->y_stride * ctx->y_row_count;
    ctx->crcb_stride = ctx->y_stride / 2;
    ctx->crcb_row_count = ctx->y_row_count / 2;
    ctx->crcb_size = ctx->crcb_stride * ctx->crcb_row_count;
    ctx->num_vblocks_y = ctx->frame_height / 8;
    ctx->num_hblocks_y = ctx->frame_width / 8;
    ctx->num_vblocks_cbcr = ctx->frame_height / 16;
    ctx->num_hblocks_cbcr = ctx->frame_width / 16;
    if (ctx->frame_height % 16 != 0)
        ctx->num_vblocks_cbcr++;
    ctx->frame_num = 0;
    ctx->ptr_index = 15;
    ctx->num_coeffs = 28;
    ctx->cur_frame_buf = ((unsigned char *) g_malloc_n (((320 * 240 * 3) / 2), sizeof (guchar)));
    bufsize = ctx->y_size + (ctx->crcb_size * 2);
    for (i = 0; i < 16; i++)
        ctx->buf_ptrs[i] = ((unsigned char *) g_malloc_n ((bufsize), sizeof (guchar)));
    _initialize_vlcdec_lookup(ctx->vlcdec_lookup);
}

variable_types: struct _MimCtx { int encoder_initialized; int decoder_initialized; int frame_width; int frame_height; int quality; int num_coeffs; int y_stride; int y_row_count; int y_size; int crcb_stride; int crcb_row_count; int crcb_size; int num_vblocks_y; int num_hblocks_y; int num_vblocks_cbcr; int num_hblocks_cbcr; unsigned char *cur_frame_buf; unsigned char *prev_frame_buf; char vlcdec_lookup[2296]; char *data_buffer; unsigned int data_index; unsigned int cur_chunk; int cur_chunk_len; unsigned int *chunk_ptr; int read_odd; int frame_num; int ptr_index; unsigned char *buf_ptrs[16]; } *

variable_types: width int

variable_types: height int

variable_types: bufsize int


decompiled_code:
_DWORD *mimic_open()
{
_DWORD *result; // rax

result = (_DWORD *)g_malloc0(2552LL);
*result = 0;
result[1] = 0;
return result;
}

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

result = (_DWORD *)g_malloc0(2552LL);
*result = 0;
result[1] = 0;
return result;
}

original_code:
MimCtx *mimic_open()
{
    MimCtx *ctx;
    ctx = ((MimCtx *) g_malloc0_n ((1), sizeof (MimCtx)));
    ctx->encoder_initialized = (0);
    ctx->decoder_initialized = (0);
    return ctx;
}

canonical_original_code:
struct _MimCtx *mimic_open()
{
    struct _MimCtx *ctx;
    ctx = ((struct _MimCtx *) g_malloc0_n ((1), sizeof (MimCtx)));
    ctx->encoder_initialized = (0);
    ctx->decoder_initialized = (0);
    return ctx;
}

return_type: struct _MimCtx { int encoder_initialized; int decoder_initialized; int frame_width; int frame_height; int quality; int num_coeffs; int y_stride; int y_row_count; int y_size; int crcb_stride; int crcb_row_count; int crcb_size; int num_vblocks_y; int num_hblocks_y; int num_vblocks_cbcr; int num_hblocks_cbcr; unsigned char *cur_frame_buf; unsigned char *prev_frame_buf; char vlcdec_lookup[2296]; char *data_buffer; unsigned int data_index; unsigned int cur_chunk; int cur_chunk_len; unsigned int *chunk_ptr; int read_odd; int frame_num; int ptr_index; unsigned char *buf_ptrs[16]; } *


decompiled_code:
__int64 __fastcall mimic_close(_QWORD *a1)
{
_QWORD *v2; // rbx

if ( *a1 )
{
g_free(a1[8]);
v2 = a1 + 303;
do
g_free(*v2++);
while ( v2 != a1 + 319 );
}
return g_free(a1);
}

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

if ( *a1 )
{
g_free(a1[8]);
v2 = a1 + 303;
do
g_free(*v2++);
while ( v2 != a1 + 319 );
}
return g_free(a1);
}

original_code:
void mimic_close(MimCtx *ctx)
{
    if (ctx->encoder_initialized || ctx->decoder_initialized) {
        gint i;
        g_free(ctx->cur_frame_buf);
        for (i = 0; i < 16; i++)
            g_free(ctx->buf_ptrs[i]);
    }
    g_free(ctx);
}

canonical_original_code:
void mimic_close(struct _MimCtx *ctx)
{
    if (ctx->encoder_initialized || ctx->decoder_initialized) {
        int i;
        g_free(ctx->cur_frame_buf);
        for (i = 0; i < 16; i++)
            g_free(ctx->buf_ptrs[i]);
    }
    g_free(ctx);
}

user_defined_types: struct _MimCtx { int encoder_initialized; int decoder_initialized; int frame_width; int frame_height; int quality; int num_coeffs; int y_stride; int y_row_count; int y_size; int crcb_stride; int crcb_row_count; int crcb_size; int num_vblocks_y; int num_hblocks_y; int num_vblocks_cbcr; int num_hblocks_cbcr; unsigned char *cur_frame_buf; unsigned char *prev_frame_buf; char vlcdec_lookup[2296]; char *data_buffer; unsigned int data_index; unsigned int cur_chunk; int cur_chunk_len; unsigned int *chunk_ptr; int read_odd; int frame_num; int ptr_index; unsigned char *buf_ptrs[16]; }


decompiled_code:
__int64 __fastcall mimic_encoder_init(_DWORD *a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // esi

result = 0LL;
if ( !*(_QWORD *)a1 )
{
if ( a2 )
{
if ( a2 != 1 )
return result;
v3 = 240;
v4 = 320;
}
else
{
v3 = 120;
v4 = 160;
}
mimic_init((__int64)a1, v4, v3);
a1[4] = 0;
*a1 = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // esi

result = 0LL;
if ( !*(_QWORD *)a1 )
{
if ( a2 )
{
if ( a2 != 1 )
return result;
v3 = 240;
v4 = 320;
}
else
{
v3 = 120;
v4 = 160;
}
func0((__int64)a1, v4, v3);
a1[4] = 0;
*a1 = 1;
result = 1LL;
}
return result;
}

original_code:
gboolean mimic_encoder_init(MimCtx *ctx, const MimicResEnum resolution)
{
    gint width, height;
    if (ctx->encoder_initialized || ctx->decoder_initialized)
        return (0);
    if (resolution == MIMIC_RES_LOW) {
        width = 160;
        height = 120;
    } else if (resolution == MIMIC_RES_HIGH) {
        width = 320;
        height = 240;
    } else {
        return (0);
    }
    mimic_init(ctx, width, height);
    ctx->quality = 0;
    ctx->encoder_initialized = (!(0));
    return (!(0));
}

canonical_original_code:
int mimic_encoder_init(struct _MimCtx *ctx, enum MimicResEnum resolution)
{
    int width; int height;
    if (ctx->encoder_initialized || ctx->decoder_initialized)
        return (0);
    if (resolution == MIMIC_RES_LOW) {
        width = 160;
        height = 120;
    } else if (resolution == MIMIC_RES_HIGH) {
        width = 320;
        height = 240;
    } else {
        return (0);
    }
    mimic_init(ctx, width, height);
    ctx->quality = 0;
    ctx->encoder_initialized = (!(0));
    return (!(0));
}

variable_types: enum MimicResEnum { MIMIC_RES_LOW=0, MIMIC_RES_HIGH=1 }


decompiled_code:
__int64 __fastcall mimic_decoder_init(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3; // ecx
int v4; // edx

if ( *(_QWORD *)a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v3 = *(unsigned __int16 *)(a2 + 4);
v4 = *(unsigned __int16 *)(a2 + 6);
if ( v3 == 160 && v4 == 120 || v3 == 320 && v4 == 240 )
{
result = 0LL;
if ( !*(_DWORD *)(a2 + 12) )
{
*(_DWORD *)(a1 + 16) = *(unsigned __int16 *)(a2 + 2);
mimic_init(a1, v3, v4);
*(_DWORD *)(a1 + 4) = 1;
result = 1LL;
}
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
gboolean mimic_decoder_init(MimCtx *ctx, const guchar *frame_buffer)
{
    gint width, height;
    gboolean is_keyframe;
    if (ctx->encoder_initialized || ctx->decoder_initialized ||
        frame_buffer == ((void *)0))
    {
        return (0);
    }
    width = (((guint16) (*((guint16 *) (frame_buffer + 4)))));
    height = (((guint16) (*((guint16 *) (frame_buffer + 6)))));
    if (!(width == 160 && height == 120) && !(width == 320 && height == 240))
        return (0);
    is_keyframe = ((((guint32) (*((guint32 *) (frame_buffer + 12))))) == 0);
    if (!is_keyframe)
        return (0);
    ctx->quality = (((guint16) (*((guint16 *) (frame_buffer + 2)))));
    mimic_init(ctx, width, height);
    ctx->decoder_initialized = (!(0));
    return (!(0));
}

canonical_original_code:
int mimic_decoder_init(struct _MimCtx *ctx, unsigned char *frame_buffer)
{
    int width; int height;
    int is_keyframe;
    if (ctx->encoder_initialized || ctx->decoder_initialized ||
        frame_buffer == ((void *)0))
    {
        return (0);
    }
    width = (((guint16) (*((unsigned short *) (frame_buffer + 4)))));
    height = (((guint16) (*((unsigned short *) (frame_buffer + 6)))));
    if (!(width == 160 && height == 120) && !(width == 320 && height == 240))
        return (0);
    is_keyframe = ((((guint32) (*((unsigned int *) (frame_buffer + 12))))) == 0);
    if (!is_keyframe)
        return (0);
    ctx->quality = (((guint16) (*((unsigned short *) (frame_buffer + 2)))));
    mimic_init(ctx, width, height);
    ctx->decoder_initialized = (!(0));
    return (!(0));
}


decompiled_code:
__int64 __fastcall mimic_get_property(_DWORD *a1, const char *a2, _DWORD *a3)
{
unsigned int v4; // edx

v4 = 0;
if ( *(_QWORD *)a1 )
{
if ( *a1 )
{
if ( !strcmp(a2, "buffer_size") )
{
*a3 = 0x4000;
return 1;
}
}
else if ( !strcmp(a2, "buffer_size") )
{
*a3 = 3 * a1[3] * a1[2];
return 1;
}
if ( !strcmp(a2, "width") )
{
*a3 = a1[2];
v4 = 1;
}
else if ( !strcmp(a2, "height") )
{
*a3 = a1[3];
v4 = 1;
}
else
{
v4 = 0;
if ( !strcmp(a2, "quality") )
{
*a3 = a1[4];
v4 = 1;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, const char *a2, _DWORD *a3)
{
unsigned int v4; // edx

v4 = 0;
if ( *(_QWORD *)a1 )
{
if ( *a1 )
{
if ( !strcmp(a2, "buffer_size") )
{
*a3 = 0x4000;
return 1;
}
}
else if ( !strcmp(a2, "buffer_size") )
{
*a3 = 3 * a1[3] * a1[2];
return 1;
}
if ( !strcmp(a2, "width") )
{
*a3 = a1[2];
v4 = 1;
}
else if ( !strcmp(a2, "height") )
{
*a3 = a1[3];
v4 = 1;
}
else
{
v4 = 0;
if ( !strcmp(a2, "quality") )
{
*a3 = a1[4];
v4 = 1;
}
}
}
return v4;
}

original_code:
gboolean mimic_get_property(MimCtx *ctx, const gchar *name, gpointer data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "buffer_size") == 0) {
            *((gint *) data) = 16384;
            return (!(0));
        }
    } else {
        if (strcmp(name, "buffer_size") == 0) {
            *((gint *) data) = ctx->frame_width * ctx->frame_height * 3;
            return (!(0));
        }
    }
    if (strcmp(name, "width") == 0) {
        *((gint *) data) = ctx->frame_width;
        return (!(0));
    } else if (strcmp(name, "height") == 0) {
        *((gint *) data) = ctx->frame_height;
        return (!(0));
    } else if (strcmp(name, "quality") == 0) {
        *((gint *) data) = ctx->quality;
        return (!(0));
    }
    return (0);
}

canonical_original_code:
int mimic_get_property(struct _MimCtx *ctx, char *name, void *data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "buffer_size") == 0) {
            *((int *) data) = 16384;
            return (!(0));
        }
    } else {
        if (strcmp(name, "buffer_size") == 0) {
            *((int *) data) = ctx->frame_width * ctx->frame_height * 3;
            return (!(0));
        }
    }
    if (strcmp(name, "width") == 0) {
        *((int *) data) = ctx->frame_width;
        return (!(0));
    } else if (strcmp(name, "height") == 0) {
        *((int *) data) = ctx->frame_height;
        return (!(0));
    } else if (strcmp(name, "quality") == 0) {
        *((int *) data) = ctx->quality;
        return (!(0));
    }
    return (0);
}

variable_types:
name
char *

variable_types:
data
void *


decompiled_code:
__int64 __fastcall mimic_set_property(unsigned int *a1, const char *a2, unsigned int *a3)
{
__int64 result; // rax
bool v4; // zf
unsigned int v5; // edx

result = 0LL;
if ( *(_QWORD *)a1 )
{
result = *a1;
if ( (_DWORD)result )
{
v4 = strcmp(a2, "quality") == 0;
result = !v4;
if ( v4 )
{
v5 = *a3;
if ( v5 <= 0x2710 )
{
a1[4] = v5;
result = 1LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, const char *a2, unsigned int *a3)
{
__int64 result; // rax
bool v4; // zf
unsigned int v5; // edx

result = 0LL;
if ( *(_QWORD *)a1 )
{
result = *a1;
if ( (_DWORD)result )
{
v4 = strcmp(a2, "quality") == 0;
result = !v4;
if ( v4 )
{
v5 = *a3;
if ( v5 <= 0x2710 )
{
a1[4] = v5;
result = 1LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
gboolean mimic_set_property(MimCtx *ctx, const gchar *name, gpointer data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "quality") == 0) {
            gint new_quality = *((gint *) data);
            if (new_quality < 0 ||
                new_quality > 10000)
            {
                return (0);
            }
            ctx->quality = new_quality;
            return (!(0));
        }
    } else { }
    return (0);
}

canonical_original_code:
int mimic_set_property(struct _MimCtx *ctx, char *name, void *data)
{
    if (!ctx->encoder_initialized && !ctx->decoder_initialized)
        return (0);
    if (ctx->encoder_initialized) {
        if (strcmp(name, "quality") == 0) {
            int new_quality = *((gint *) data);
            if (new_quality < 0 ||
                new_quality > 10000)
            {
                return (0);
            }
            ctx->quality = new_quality;
            return (!(0));
        }
    } else { }
    return (0);
}


decompiled_code:
int __fastcall log_file_open(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
char *v8; // rbx
struct tm *v9; // rax
double v10; // xmm4_8
double v11; // xmm5_8
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v8 = (char *)malloc(0x40uLL);
timer = time(0LL);
v9 = localtime(&timer);
sprintf(
v8,
"logs/nlpad-%.2d-%.2d-%.2d.log",
(unsigned int)v9->tm_mday,
(unsigned int)v9->tm_mon,
(unsigned int)v9->tm_year);
log_file = fopen(v8, "w");
return log_writef(0, "Nonlogic Pad Logging Started\n", a1, a2, a3, a4, v10, v11, a7, a8);
}

canonical_decompiled_code:
int __fastcall func1(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
char *v8; // rbx
struct tm *v9; // rax
double v10; // xmm4_8
double v11; // xmm5_8
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v8 = (char *)malloc(0x40uLL);
timer = time(0LL);
v9 = localtime(&timer);
sprintf(
v8,
"logs/nlpad-%.2d-%.2d-%.2d.log",
(unsigned int)v9->tm_mday,
(unsigned int)v9->tm_mon,
(unsigned int)v9->tm_year);
log_file = fopen(v8, "w");
return func0(0, "Nonlogic Pad Logging Started\n", a1, a2, a3, a4, v10, v11, a7, a8);
}

original_code:
void log_file_open()
{
 char *filename = malloc(64);
 time_t current_time = time(((void *)0));
 struct tm *now = localtime(&current_time);
 sprintf(filename,"logs/nlpad-%.2d-%.2d-%.2d.log",now->tm_mday,now->tm_mon,now->tm_year);
 log_file = fopen(filename,"w");
 log_writef(0,"Nonlogic Pad Logging Started\n");
}

canonical_original_code:
void log_file_open()
{
 char *filename = malloc(64);
 long current_time = time(((void *)0));
 struct tm *now = localtime(&current_time);
 sprintf(filename,"logs/nlpad-%.2d-%.2d-%.2d.log",now->tm_mday,now->tm_mon,now->tm_year);
 log_file = fopen(filename,"w");
 log_writef(0,"Nonlogic Pad Logging Started\n");
}

variable_types:
filename
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
int __fastcall log_file_close(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
log_writef(0, "Nonlogic Pad Logging Stopped\n", a1, a2, a3, a4, a5, a6, a7, a8);
return fclose(log_file);
}

canonical_decompiled_code:
int __fastcall func2(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
func0(0, "Nonlogic Pad Logging Stopped\n", a1, a2, a3, a4, a5, a6, a7, a8);
return fclose(log_file);
}

original_code:
void log_file_close()
{
 log_writef(0,"Nonlogic Pad Logging Stopped\n");
 fclose(log_file);
}


decompiled_code:
struct hostent *network_init()
{
socket(2, 1, 0);
return gethostbyname("localhost");
}

canonical_decompiled_code:
struct hostent *func0()
{
socket(2, 1, 0);
return gethostbyname("localhost");
}

original_code:
void network_init(short port)
{
 network_listen_sock = socket(2, SOCK_STREAM,0);
 struct sockaddr_in network_host;
 struct hostent *network_hent = gethostbyname("localhost");
 network_host.sin_family = 2;
 network_host.sin_port = htons(port);
}

variable_types: port short

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

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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


decompiled_code:
__int64 __fastcall con_new(const char *a1)
{
struct hostent *v1; // rax
struct hostent *v2; // rbx
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v1 = gethostbyname(a1);
if ( v1 )
{
v2 = v1;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(80);
*(_DWORD *)&v5.sa_data[2] = **(_DWORD **)v2->h_addr_list;
*(_QWORD *)&v5.sa_data[6] = 0LL;
v3 = socket(2, 1, 0);
if ( connect(v3, &v5, 0x10u) < 0 )
{
fprintf(_bss_start, "Failed to connect to %s.\n", a1);
v3 = -1;
}
}
else
{
fprintf(_bss_start, "Failed resolving %s - check network status\n", a1);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
struct hostent *v1; // rax
struct hostent *v2; // rbx
unsigned int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v1 = gethostbyname(a1);
if ( v1 )
{
v2 = v1;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func7(80);
*(_DWORD *)&v5.sa_data[2] = **(_DWORD **)v2->h_addr_list;
*(_QWORD *)&v5.sa_data[6] = 0LL;
v3 = socket(2, 1, 0);
if ( connect(v3, &v5, 0x10u) < 0 )
{
fprintf(_bss_start, "Failed to connect to %s.\n", a1);
v3 = -1;
}
}
else
{
fprintf(_bss_start, "Failed resolving %s - check network status\n", a1);
v3 = -1;
}
return v3;
}

original_code:
int con_new(char *host)
{
 struct hostent *host_resolv = gethostbyname(host);
 if(!host_resolv)
 {
  fprintf(stderr, "Failed resolving %s - check network status\n",host);
  return -1;
 }
 struct sockaddr_in g_addr;
 g_addr.sin_family = 2;
 g_addr.sin_port = htons(80);
 g_addr.sin_addr = *((struct in_addr*)host_resolv->h_addr_list[0]);
 memset(g_addr.sin_zero, '\0', 8);
 int sock = socket(2,SOCK_STREAM,0);
 if(connect(sock, (struct sockaddr*)&g_addr,sizeof(struct sockaddr))<0)
 {
  fprintf(stderr, "Failed to connect to %s.\n",host);
  return -1;
 }
 return sock;
}

canonical_original_code:
int con_new(char *host)
{
 struct hostent *host_resolv = gethostbyname(host);
 if(!host_resolv)
 {
  fprintf(stderr, "Failed resolving %s - check network status\n",host);
  return -1;
 }
 struct sockaddr_in g_addr;
 g_addr.sin_family = 2;
 g_addr.sin_port = htons(80);
 g_addr.sin_addr = *((struct in_addr *)host_resolv->h_addr_list[0]);
 memset(g_addr.sin_zero, '\0', 8);
 int sock = socket(2,SOCK_STREAM,0);
 if(connect(sock, (struct sockaddr *)&g_addr,sizeof(struct sockaddr))<0)
 {
  fprintf(stderr, "Failed to connect to %s.\n",host);
  return -1;
 }
 return sock;
}

variable_types:
host
char *

variable_types: sock int

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

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


decompiled_code:
size_t __fastcall con_send_data(int a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = a3;
result = send(a1, a2, a3, 0);
if ( result != v3 )
result = fwrite("Failed sending data - byte count mismatch\n", 1uLL, 0x2AuLL, _bss_start);
return result;
}

canonical_decompiled_code:
size_t __fastcall func9(int a1, const void *a2, int a3)
{
__int64 v3; // rbx
size_t result; // rax

v3 = a3;
result = send(a1, a2, a3, 0);
if ( result != v3 )
result = fwrite("Failed sending data - byte count mismatch\n", 1uLL, 0x2AuLL, _bss_start);
return result;
}

original_code:
void con_send_data(int con, void *data, int len)
{
 if(send(con,data,len,0)!=len)
 {
  fprintf(stderr,"Failed sending data - byte count mismatch\n");
 }
}

variable_types: con int

variable_types: len int


decompiled_code:
char *__fastcall con_recv_data(int fd)
{
char *v1; // r12
void *v2; // rbx
int v3; // ebp

v1 = (char *)malloc(0x8000uLL);
v2 = malloc(0x400uLL);
memset(v2, 0, 0x400uLL);
v3 = 11;
do
{
recv(fd, v2, 0x400uLL, 0);
sprintf(v1, "%s%s", v1, (const char *)v2);
memset(v2, 0, 0x400uLL);
--v3;
}
while ( v3 );
return v1;
}

canonical_decompiled_code:
char *__fastcall func10(int fd)
{
char *v1; // r12
void *v2; // rbx
int v3; // ebp

v1 = (char *)malloc(0x8000uLL);
v2 = malloc(0x400uLL);
memset(v2, 0, 0x400uLL);
v3 = 11;
do
{
recv(fd, v2, 0x400uLL, 0);
sprintf(v1, "%s%s", v1, (const char *)v2);
memset(v2, 0, 0x400uLL);
--v3;
}
while ( v3 );
return v1;
}

original_code:
char *con_recv_data(int con)
{
 char *data = malloc(32768);
 char *chunk = malloc(1024);
 int chunks = 0;
 memset(chunk,'\0', 1024);
 while(chunks<11)
 {
  recv(con,chunk,1024,0);
  sprintf(data,"%s%s",data,chunk);
  chunks++;
  memset(chunk,'\0',1024);
 }
 return data;
}

variable_types:
data
char *

variable_types:
chunk
char *

variable_types: chunks int


decompiled_code:
__int64 __fastcall parse_check_char(char a1)
{
return (unsigned __int8)(a1 - 65) < 0x3Au ? 1 : 3;
}

canonical_decompiled_code:
__int64 __fastcall func11(char a1)
{
return (unsigned __int8)(a1 - 65) < 0x3Au ? 1 : 3;
}

original_code:
static int parse_check_char(char letter)
{
 if(letter<'A' || letter >'z')
 {
  return 3;
 }
 return 1;
}

variable_types: letter char


decompiled_code:
void *__fastcall parse_query(char *s)
{
char *v1; // rbx
char *v2; // r12
int v3; // ebp
void *v4; // r12
size_t i; // rbx
unsigned int v6; // ebp

v1 = s;
v2 = &s[strlen(s)];
v3 = 10;
while ( v1 != v2 )
v3 += parse_check_char(*v1++);
v4 = malloc(v3 + 1);
memset(v4, 0, v3);
strcpy((char *)v4, "/search?q=");
for ( i = 0LL; strlen(s) > i; ++i )
{
v6 = s[i];
if ( (unsigned int)parse_check_char(s[i]) == 3 )
sprintf((char *)v4, "%s%%%X", (const char *)v4, v6);
else
sprintf((char *)v4, "%s%c", (const char *)v4, v6);
}
return v4;
}

canonical_decompiled_code:
void *__fastcall func12(char *s)
{
char *v1; // rbx
char *v2; // r12
int v3; // ebp
void *v4; // r12
size_t i; // rbx
unsigned int v6; // ebp

v1 = s;
v2 = &s[strlen(s)];
v3 = 10;
while ( v1 != v2 )
v3 += func11(*v1++);
v4 = malloc(v3 + 1);
memset(v4, 0, v3);
strcpy((char *)v4, "/search?q=");
for ( i = 0LL; strlen(s) > i; ++i )
{
v6 = s[i];
if ( (unsigned int)func11(s[i]) == 3 )
sprintf((char *)v4, "%s%%%X", (const char *)v4, v6);
else
sprintf((char *)v4, "%s%c", (const char *)v4, v6);
}
return v4;
}

original_code:
char *parse_query(char *query)
{
 char *result_str;
 int result_len = 10;
 int i = 0;
 for(;i<strlen(query);i++)
 {
  result_len += parse_check_char(query[i]);
 }
 result_str = malloc(result_len+1);
 memset(result_str, '\0', result_len);
 strcpy(result_str, "/search?q=");
 for(i=0;i<strlen(query);i++)
 {
  if(parse_check_char(query[i])==3)
   sprintf(result_str, "%s%%%X",result_str, query[i]);
  else
  sprintf(result_str, "%s%c",result_str, query[i]);
 }
 return result_str;
}

variable_types:
query
char *

variable_types: i int


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

v1 = strstr(a1, " of about ");
if ( !v1 )
return strdup("None found");
v2 = v1 + 17;
*strstr(v1 + 17, "") = 0;
return strdup(v2);
}

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

v1 = strstr(a1, " of about ");
if ( !v1 )
return strdup("None found");
v2 = v1 + 17;
*strstr(v1 + 17, "") = 0;
return strdup(v2);
}

original_code:
char *interp_google_count(char *html_data)
{
 char *result = ((void *)0);
 html_data = strstr(html_data," of about ");
 if(html_data == ((void *)0))
 {
  result = strdup("None found");
  return result;
 }
 html_data+=17;
 char *end_point = strstr(html_data, "");
 end_point[0] = '\0';
 result = strdup(html_data);
 return result;
}

variable_types:
result
char *


decompiled_code:
void *__fastcall http_create_request(char *s, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
void *v4; // rbx
size_t v5; // r13
size_t v6; // rax

v2 = strlen(s);
v3 = strlen(a2);
v4 = malloc(v2 + v3 + 69);
v5 = strlen(s);
v6 = strlen(a2);
memset(v4, 0, v5 + v6 + 69);
sprintf((char *)v4, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Linux: X11:UTF-8)\r\n\r\n", a2, s);
return v4;
}

canonical_decompiled_code:
void *__fastcall func14(char *s, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
void *v4; // rbx
size_t v5; // r13
size_t v6; // rax

v2 = strlen(s);
v3 = strlen(a2);
v4 = malloc(v2 + v3 + 69);
v5 = strlen(s);
v6 = strlen(a2);
memset(v4, 0, v5 + v6 + 69);
sprintf((char *)v4, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Linux: X11:UTF-8)\r\n\r\n", a2, s);
return v4;
}

original_code:
char *http_create_request(char *address, char *file)
{
 char *http_header = malloc(strlen(address)+strlen(file)+69);
 memset(http_header, '\0', strlen(address)+strlen(file)+69);
 sprintf(http_header,"GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Linux: X11:UTF-8)\r\n\r\n",file, address);
 return http_header;
}

variable_types:
address
char *

variable_types:
file
char *


decompiled_code:
void __fastcall fill_audio(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // ebx

v3 = audio_len;
if ( audio_len )
{
if ( a3 <= audio_len )
v3 = a3;
SDL_MixAudio(a2, audio_pos, (unsigned int)v3, 128LL);
audio_pos += v3;
if ( audio_len == v3 )
{
audio_len = 512;
audio_pos = audio_chunk;
}
else
{
audio_len -= v3;
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, unsigned int a3)
{
int v3; // ebx

v3 = audio_len;
if ( audio_len )
{
if ( a3 <= audio_len )
v3 = a3;
SDL_MixAudio(a2, audio_pos, (unsigned int)v3, 128LL);
audio_pos += v3;
if ( audio_len == v3 )
{
audio_len = 512;
audio_pos = audio_chunk;
}
else
{
audio_len -= v3;
}
}
}

original_code:
static void fill_audio(void *udata, Uint8 *stream, int len)
{
 if (audio_len == 0)
 {
  return;
 }
    len = ( len > audio_len ? audio_len : len );
    SDL_MixAudio(stream, audio_pos, len, 128);
    audio_pos += len;
    audio_len -= len;
    if(audio_len == 0)
    {
     audio_len = 512;
     audio_pos = audio_chunk;
    }
}

canonical_original_code:
static void fill_audio(void *udata, unsigned char *stream, int len)
{
 if (audio_len == 0)
 {
  return;
 }
    len = ( len > audio_len ? audio_len : len );
    SDL_MixAudio(stream, audio_pos, len, 128);
    audio_pos += len;
    audio_len -= len;
    if(audio_len == 0)
    {
     audio_len = 512;
     audio_pos = audio_chunk;
    }
}

variable_types:
udata
void *

variable_types:
stream
unsigned char *


decompiled_code:
__int64 sound_init()
{
_BYTE *v0; // rbx
__int64 v1; // r12
double v2; // rbp
__int64 result; // rax
const char *v4; // rax
int v5; // [rsp+0h] [rbp-38h] BYREF
__int16 v6; // [rsp+4h] [rbp-34h]
char v7; // [rsp+6h] [rbp-32h]
__int16 v8; // [rsp+8h] [rbp-30h]
void (__fastcall *v9)(__int64, __int64, unsigned int); // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+18h] [rbp-20h]

SDL_Init(16LL);
v5 = 22050;
v6 = -32752;
v7 = 2;
v8 = 1024;
v9 = fill_audio;
v10 = 0LL;
if ( (int)SDL_OpenAudio(&v5, 0LL) < 0 )
{
v4 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open audio: %s\n", v4);
}
audio_chunk = (__int64)malloc(0x400uLL);
audio_pos = audio_chunk;
v0 = (_BYTE *)audio_chunk;
v1 = audio_chunk + 512;
v2 = LC0;
do
{
result = (unsigned int)(int)(sin(v2) * 128.0);
*v0 = result;
v2 = v2 + 0.05711986642890533;
++v0;
}
while ( v0 != (_BYTE *)v1 );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_BYTE *v0; // rbx
__int64 v1; // r12
double v2; // rbp
__int64 result; // rax
const char *v4; // rax
int v5; // [rsp+0h] [rbp-38h] BYREF
__int16 v6; // [rsp+4h] [rbp-34h]
char v7; // [rsp+6h] [rbp-32h]
__int16 v8; // [rsp+8h] [rbp-30h]
void (__fastcall *v9)(__int64, __int64, unsigned int); // [rsp+10h] [rbp-28h]
__int64 v10; // [rsp+18h] [rbp-20h]

SDL_Init(16LL);
v5 = 22050;
v6 = -32752;
v7 = 2;
v8 = 1024;
v9 = fill_audio;
v10 = 0LL;
if ( (int)SDL_OpenAudio(&v5, 0LL) < 0 )
{
v4 = (const char *)SDL_GetError();
fprintf(stderr, "Couldn't open audio: %s\n", v4);
}
audio_chunk = (__int64)malloc(0x400uLL);
audio_pos = audio_chunk;
v0 = (_BYTE *)audio_chunk;
v1 = audio_chunk + 512;
v2 = LC0;
do
{
result = (unsigned int)(int)(sin(v2) * 128.0);
*v0 = result;
v2 = v2 + 0.05711986642890533;
++v0;
}
while ( v0 != (_BYTE *)v1 );
return result;
}

original_code:
void sound_init()
{
 SDL_Init(0x00000010);
 SDL_AudioSpec wanted;
    wanted.freq = 22050;
    wanted.format = 0x8010;
    wanted.channels = 2;
    wanted.samples = 1024;
    wanted.callback = fill_audio;
    wanted.userdata = ((void *)0);
    if ( SDL_OpenAudio(&wanted, ((void *)0)) < 0 ) {
        fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
    }
    audio_chunk = malloc(1024);
    audio_pos = audio_chunk;
    double it = 0.0;
    double inc = (3.14159265358979323846*8.0f)/440.0f;
    for(int i = 0; i < 512; i++)
    {
     audio_chunk[i] = sin(it)*128.0;
     it+=inc;
    }
}

canonical_original_code:
void sound_init()
{
 SDL_Init(0x00000010);
 struct SDL_AudioSpec wanted;
    wanted.freq = 22050;
    wanted.format = 0x8010;
    wanted.channels = 2;
    wanted.samples = 1024;
    wanted.callback = fill_audio;
    wanted.userdata = ((void *)0);
    if ( SDL_OpenAudio(&wanted, ((void *)0)) < 0 ) {
        fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
    }
    audio_chunk = malloc(1024);
    audio_pos = audio_chunk;
    double it = 0.0;
    double inc = (3.14159265358979323846*8.0f)/440.0f;
    for(int i = 0; i < 512; i++)
    {
     audio_chunk[i] = sin(it)*128.0;
     it+=inc;
    }
}

variable_types: struct SDL_AudioSpec { int freq; unsigned short format; unsigned char channels; unsigned char silence; unsigned short samples; unsigned short padding; unsigned int size; void (*callback)(void *userdata, unsigned char *stream, int len); void *userdata; }

variable_types: it double

variable_types: inc double


decompiled_code:
__int64 sound_start()
{
audio_len = 512;
return SDL_PauseAudio(0LL);
}

canonical_decompiled_code:
__int64 func2()
{
audio_len = 512;
return SDL_PauseAudio(0LL);
}

original_code:
void sound_start()
{
 audio_len = 512;
 SDL_PauseAudio(0);
}


decompiled_code:
__int64 sound_stop()
{
audio_len = 0;
return SDL_PauseAudio(1LL);
}

canonical_decompiled_code:
__int64 func3()
{
audio_len = 0;
return SDL_PauseAudio(1LL);
}

original_code:
void sound_stop()
{
 audio_len = 0;
 SDL_PauseAudio(1);
}


decompiled_code:
int __fastcall joy_open(const char *a1)
{
int v1; // eax
unsigned int v2; // eax
int result; // eax

v1 = open(a1, 0);
fd = v1;
if ( v1 < 0 )
{
fwrite("Failed openning joystick device\n", 1uLL, 0x20uLL, stderr);
exit(0);
}
v2 = fcntl(v1, 3, 0LL);
BYTE1(v2) |= 8u;
result = fcntl(fd, 4, v2);
if ( result )
{
fwrite("Failed to set nonblocking\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
int v1; // eax
unsigned int v2; // eax
int result; // eax

v1 = open(a1, 0);
fd = v1;
if ( v1 < 0 )
{
fwrite("Failed openning joystick device\n", 1uLL, 0x20uLL, stderr);
exit(0);
}
v2 = fcntl(v1, 3, 0LL);
BYTE1(v2) |= 8u;
result = fcntl(fd, 4, v2);
if ( result )
{
fwrite("Failed to set nonblocking\n", 1uLL, 0x1AuLL, stderr);
exit(0);
}
return result;
}

original_code:
void joy_open(char *device)
{
 fd = open(device,00);
 if(fd<0)
 {
  fprintf(stderr, "Failed openning joystick device\n");
  exit(0);
 }
 int opts = fcntl(fd,3,0);
 opts |= 04000;
 if(fcntl(fd,4,opts)!=0)
 {
  fprintf(stderr, "Failed to set nonblocking\n");
  exit(0);
 }
}

variable_types:
device
char *

variable_types: opts int


decompiled_code:
int *joy_get_axis()
{
return joy_axis;
}

canonical_decompiled_code:
int *func12()
{
return joy_axis;
}

return_type: int *


decompiled_code:
int *joy_get_button()
{
return joy_button;
}

canonical_decompiled_code:
int *func13()
{
return joy_button;
}


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

v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s error %d, %s\n", a1, (unsigned int)*v1, v2);
exit(1);
}

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

v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s error %d, %s\n", a1, (unsigned int)*v1, v2);
exit(1);
}

original_code:
static void errno_exit(const char *s)
{
  fprintf (stderr, "%s error %d, %s\n", s, (*__errno_location ()), strerror ((*__errno_location ())));
  exit (1);
}

canonical_original_code:
static void errno_exit(char *s)
{
  fprintf (stderr, "%s error %d, %s\n", s, (*__errno_location ()), strerror ((*__errno_location ())));
  exit (1);
}

variable_types:
s
char *