decompiled_code:
char *get_remaining_line()
{
const char *v0; // r12
size_t v1; // rbp
char *v2; // rbx
char *result; // rax

eat_whitespace();
v0 = (const char *)(*(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5));
v1 = (int)strlen(v0);
v2 = (char *)calloc(v1, 1uLL);
result = strncpy(v2, v0, v1);
v2[v1] = 0;
return result;
}

canonical_decompiled_code:
char *func10()
{
const char *v0; // r12
size_t v1; // rbp
char *v2; // rbx
char *result; // rax

func1();
v0 = (const char *)(*(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5));
v1 = (int)strlen(v0);
v2 = (char *)calloc(v1, 1uLL);
result = strncpy(v2, v0, v1);
v2[v1] = 0;
return result;
}

original_code:
char *get_remaining_line(){
 eat_whitespace();
 char *start = input_file_stack->line_buffer + input_file_stack->line_buffer_pos;
 int size = strlen(start);
 char *out = calloc(size, sizeof(char));
 strncpy(out, start, size);
 out[size] = '\0';
 return out;
}

variable_types:
out
char *


ltrim

decompiled_code:
__int64 __fastcall ltrim(unsigned __int8 *a1)
{
const unsigned __int16 *v1; // rsi
unsigned __int8 *i; // rdx
__int64 result; // rax
__int64 v4; // rcx

v1 = *_ctype_b_loc();
for ( i = a1; ; ++i )
{
result = *i;
if ( (v1[(char)result] & 0x2000) == 0 )
break;
}
if ( (_BYTE)result )
{
v4 = 0LL;
do
{
a1[v4++] = result;
result = i[v4];
}
while ( (_BYTE)result );
}
else
{
v4 = 0LL;
}
a1[v4] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1)
{
const unsigned __int16 *v1; // rsi
unsigned __int8 *i; // rdx
__int64 result; // rax
__int64 v4; // rcx

v1 = *_ctype_b_loc();
for ( i = a1; ; ++i )
{
result = *i;
if ( (v1[(char)result] & 0x2000) == 0 )
break;
}
if ( (_BYTE)result )
{
v4 = 0LL;
do
{
a1[v4++] = result;
result = i[v4];
}
while ( (_BYTE)result );
}
else
{
v4 = 0LL;
}
a1[v4] = 0;
return result;
}

original_code:
void ltrim(char *s){
 char *cpy = s;
 int i = 0;
 while(((*__ctype_b_loc ())[(int) ((*cpy))] & (unsigned short int) _ISspace)){
  cpy++;
 }
 while(cpy[i]){
  s[i] = cpy[i];
  i++;
 }
 s[i] = '\0';
}

canonical_original_code:
void ltrim(char *s){
 char *cpy = s;
 int i = 0;
 while(((*__ctype_b_loc ())[(int) ((*cpy))] & (unsigned short) _ISspace)){
  cpy++;
 }
 while(cpy[i]){
  s[i] = cpy[i];
  i++;
 }
 s[i] = '\0';
}

variable_types:
s
char *

variable_types:
cpy
char *

variable_types: i int

return_type: void


rtrim

decompiled_code:
const unsigned __int16 *__fastcall rtrim(const char *a1)
{
const char *v1; // rbx
const unsigned __int16 **v2; // rcx
const unsigned __int16 *result; // rax

v1 = &a1[strlen(a1) - 1];
v2 = _ctype_b_loc();
while ( 1 )
{
result = *v2;
if ( ((*v2)[*v1] & 0x2000) == 0 )
break;
*v1-- = 0;
}
return result;
}

canonical_decompiled_code:
const unsigned __int16 *__fastcall func12(const char *a1)
{
const char *v1; // rbx
const unsigned __int16 **v2; // rcx
const unsigned __int16 *result; // rax

v1 = &a1[strlen(a1) - 1];
v2 = _ctype_b_loc();
while ( 1 )
{
result = *v2;
if ( ((*v2)[*v1] & 0x2000) == 0 )
break;
*v1-- = 0;
}
return result;
}

original_code:
void rtrim(char *s){
 char *end = s + (strlen(s) - 1);
 while(((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)){
  *end-- = 0;
 }
}

canonical_original_code:
void rtrim(char *s){
 char *end = s + (strlen(s) - 1);
 while(((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)){
  *end-- = 0;
 }
}

variable_types:
end
char *


trim

decompiled_code:
__int64 __fastcall trim(char *a1)
{
rtrim(a1);
return ltrim((unsigned __int8 *)a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
func12(a1);
return func11((unsigned __int8 *)a1);
}

original_code:
void trim(char *s){
 rtrim(s);
 ltrim(s);
}


decompiled_code:
bool __fastcall is_digit(char a1, int a2)
{
__int32_t v2; // edx
bool result; // al

v2 = (*_ctype_toupper_loc())[a1];
result = 1;
if ( (unsigned __int8)(a1 - 48) > 9u )
{
result = 0;
if ( a2 == 16 )
result = (unsigned __int8)(v2 - 65) <= 5u;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func14(char a1, int a2)
{
__int32_t v2; // edx
bool result; // al

v2 = (*_ctype_toupper_loc())[a1];
result = 1;
if ( (unsigned __int8)(a1 - 48) > 9u )
{
result = 0;
if ( a2 == 16 )
result = (unsigned __int8)(v2 - 65) <= 5u;
}
return result;
}

original_code:
_Bool is_digit(const char c, const int base){
 char upper_c = toupper(c);
 if((c >= '0' && c <= '9')
   || ((base == 16) &&
     (upper_c >= 'A' &&
     upper_c <= 'F'))){
  return 1;
 }else{
  return 0;
 }
}

canonical_original_code:
_Bool is_digit(char c, int base){
 char upper_c = toupper(c);
 if((c >= '0' && c <= '9')
   || ((base == 16) &&
     (upper_c >= 'A' &&
     upper_c <= 'F'))){
  return 1;
 }else{
  return 0;
 }
}

variable_types: c char

variable_types: base int


decompiled_code:
_BOOL8 __fastcall is_square_bracketed(const char *a1)
{
_BOOL8 result; // rax

if ( *a1 == 91 )
result = a1[strlen(a1) - 1] == 93;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(const char *a1)
{
_BOOL8 result; // rax

if ( *a1 == 91 )
result = a1[strlen(a1) - 1] == 93;
else
result = 0LL;
return result;
}

original_code:
_Bool is_square_bracketed(const char *str){
 return (str[0] == '[') && (str[strlen(str) - 1] == ']');
}

canonical_original_code:
_Bool is_square_bracketed(char *str){
 return (str[0] == '[') && (str[strlen(str) - 1] == ']');
}

variable_types:
str
char *


decompiled_code:
_BOOL8 __fastcall is_quoted_string(const char *a1)
{
_BOOL8 result; // rax

if ( *a1 == 34 )
result = a1[strlen(a1) - 1] == 34;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(const char *a1)
{
_BOOL8 result; // rax

if ( *a1 == 34 )
result = a1[strlen(a1) - 1] == 34;
else
result = 0LL;
return result;
}

original_code:
_Bool is_quoted_string(const char *str){
 return (str[0] == '"') && (str[strlen(str) - 1] == '"');
}

canonical_original_code:
_Bool is_quoted_string(char *str){
 return (str[0] == '"') && (str[strlen(str) - 1] == '"');
}


decompiled_code:
__int64 __fastcall get_string_number_base(_BYTE *a1)
{
__int64 result; // rax
bool v2; // zf

result = 10LL;
if ( *a1 == 48 )
{
v2 = (*_ctype_toupper_loc())[(char)a1[1]] == 88;
result = 10LL;
if ( v2 )
result = 16LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(_BYTE *a1)
{
__int64 result; // rax
bool v2; // zf

result = 10LL;
if ( *a1 == 48 )
{
v2 = (*_ctype_toupper_loc())[(char)a1[1]] == 88;
result = 10LL;
if ( v2 )
result = 16LL;
}
return result;
}

original_code:
int get_string_number_base(const char *str){
 if(str[0] == '0' && toupper(str[1]) == 'X'){
  return 16;
 }else{
  return 10;
 }
}

canonical_original_code:
int get_string_number_base(char *str){
 if(str[0] == '0' && toupper(str[1]) == 'X'){
  return 16;
 }else{
  return 10;
 }
}

return_type: int


decompiled_code:
bool __fastcall is_string_number(char *a1)
{
const char *v1; // r12
int v2; // ebp
int v3; // eax
char *v4; // rbx
__int64 v5; // r12
bool result; // al

v1 = a1;
v2 = get_string_number_base(a1);
if ( v2 == 16 )
v1 = a1 + 2;
v3 = strlen(v1);
if ( v3 <= 0 )
return 1;
v4 = (char *)v1;
v5 = (__int64)&v1[v3 - 1 + 1];
do
{
result = is_digit(*v4, v2);
if ( !result )
break;
++v4;
}
while ( v4 != (char *)v5 );
return result;
}

canonical_decompiled_code:
bool __fastcall func19(char *a1)
{
const char *v1; // r12
int v2; // ebp
int v3; // eax
char *v4; // rbx
__int64 v5; // r12
bool result; // al

v1 = a1;
v2 = func18(a1);
if ( v2 == 16 )
v1 = a1 + 2;
v3 = strlen(v1);
if ( v3 <= 0 )
return 1;
v4 = (char *)v1;
v5 = (__int64)&v1[v3 - 1 + 1];
do
{
result = func14(*v4, v2);
if ( !result )
break;
++v4;
}
while ( v4 != (char *)v5 );
return result;
}

original_code:
_Bool is_string_number(const char *str){
 int base = get_string_number_base(str);
 if(base == 16){
  str += 2;
 }
 int len = strlen(str);
 for(int i = 0; i < len; i++){
  if(!is_digit(str[i], base)){
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool is_string_number(char *str){
 int base = get_string_number_base(str);
 if(base == 16){
  str += 2;
 }
 int len = strlen(str);
 for(int i = 0; i < len; i++){
  if(!is_digit(str[i], base)){
   return 0;
  }
 }
 return 1;
}

variable_types: len int


decompiled_code:
__int64 __fastcall get_string_as_number(const char *a1)
{
bool v1; // zf
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-Ch] BYREF

v1 = sscanf(a1, "%i", &v3) == 1;
result = 0LL;
if ( v1 )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(const char *a1)
{
bool v1; // zf
__int64 result; // rax
unsigned int v3; // [rsp+Ch] [rbp-Ch] BYREF

v1 = sscanf(a1, "%i", &v3) == 1;
result = 0LL;
if ( v1 )
result = v3;
return result;
}

original_code:
int get_string_as_number(const char *str){
 int ret;
 if(sscanf(str, "%i", &ret) == 1){
  return ret;
 }else{
  return 0;
 }
}

canonical_original_code:
int get_string_as_number(char *str){
 int ret;
 if(sscanf(str, "%i", &ret) == 1){
  return ret;
 }else{
  return 0;
 }
}

variable_types: ret int


decompiled_code:
void __fastcall str_to_upper(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func21(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void str_to_upper(char *str){
 char *cur = str;
 while(*cur){
  *cur = toupper(*cur);
  cur++;
 }
}

variable_types:
cur
char *


decompiled_code:
__int64 read_input_line()
{
char *v0; // rbx
__int64 result; // rax
char *v2; // rax
char **v3; // rbx
const char *v4; // rbp
size_t v5; // rax
char **v6; // rax

v0 = fgets(*((char **)input_file_stack + 1), 256, *((FILE **)input_file_stack + 3));
result = 0LL;
if ( v0 )
{
v2 = &v0[(int)strlen(v0) - 1];
if ( *v2 == 10 )
*v2 = 0;
v3 = (char **)input_file_stack;
v4 = (const char *)*((_QWORD *)input_file_stack + 1);
v5 = strlen(v4);
strncpy(*v3, v4, v5 + 1);
v6 = (char **)input_file_stack;
*((_DWORD *)input_file_stack + 5) = 0;
str_to_upper(*v6);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func22()
{
char *v0; // rbx
__int64 result; // rax
char *v2; // rax
char **v3; // rbx
const char *v4; // rbp
size_t v5; // rax
char **v6; // rax

v0 = fgets(*((char **)input_file_stack + 1), 256, *((FILE **)input_file_stack + 3));
result = 0LL;
if ( v0 )
{
v2 = &v0[(int)strlen(v0) - 1];
if ( *v2 == 10 )
*v2 = 0;
v3 = (char **)input_file_stack;
v4 = (const char *)*((_QWORD *)input_file_stack + 1);
v5 = strlen(v4);
strncpy(*v3, v4, v5 + 1);
v6 = (char **)input_file_stack;
*((_DWORD *)input_file_stack + 5) = 0;
func21(*v6);
result = 1LL;
}
return result;
}

original_code:
_Bool read_input_line(){
 char *s = fgets(input_file_stack->orig_line_buffer, 256, input_file_stack->fd);
 if(s){
  int len = strlen(s);
  if(s[len - 1] == '\n'){
   s[len - 1] = 0;
  }
  strncpy(input_file_stack->line_buffer,
      input_file_stack->orig_line_buffer,
      strlen(input_file_stack->orig_line_buffer) + 1);
  input_file_stack->line_buffer_pos = 0;
  str_to_upper(input_file_stack->line_buffer);
  return 1;
 }else{
  return 0;
 }
}


decompiled_code:
__int64 get_rest_of_line()
{
return *(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5);
}

canonical_decompiled_code:
__int64 func23()
{
return *(_QWORD *)input_file_stack + *((unsigned int *)input_file_stack + 5);
}

original_code:
char *get_rest_of_line(){
 return input_file_stack->line_buffer +
  input_file_stack->line_buffer_pos;
}

return_type: char *


decompiled_code:
bool is_line_comment()
{
return *(_BYTE *)get_rest_of_line() == 59;
}

canonical_decompiled_code:
bool func24()
{
return *(_BYTE *)func23() == 59;
}

original_code:
_Bool is_line_comment(){
 if(get_rest_of_line()[0] == ';'){
  return 1;
 }else{
  return 0;
 }
}


decompiled_code:
bool is_line_dat()
{
return memcmp((const void *)get_rest_of_line(), "DAT", 3uLL) == 0;
}

canonical_decompiled_code:
bool func25()
{
return memcmp((const void *)get_rest_of_line(), "DAT", 3uLL) == 0;
}

original_code:
_Bool is_line_dat(){
 if(strncmp(get_rest_of_line(), "DAT", 3) == 0){
  return 1;
 }
 return 0;
}


decompiled_code:
bool is_line_include()
{
return memcmp((const void *)get_rest_of_line(), "#INCLUDE", 8uLL) == 0;
}

canonical_decompiled_code:
bool func26()
{
return memcmp((const void *)get_rest_of_line(), "#INCLUDE", 8uLL) == 0;
}

original_code:
_Bool is_line_include(){
 if(strncmp(get_rest_of_line(), "#INCLUDE", 8) == 0){
  return 1;
 }
 return 0;
}


decompiled_code:
bool is_line_blank()
{
return *(_BYTE *)get_rest_of_line() == 0;
}

canonical_decompiled_code:
bool func27()
{
return *(_BYTE *)func23() == 0;
}

original_code:
_Bool is_line_blank(){
 return (strlen(get_rest_of_line()) == 0 ? 1 : 0);
}


decompiled_code:
bool is_line_label()
{
return *(_BYTE *)get_rest_of_line() == 58;
}

canonical_decompiled_code:
bool func28()
{
return *(_BYTE *)func23() == 58;
}

original_code:
_Bool is_line_label(){
 if(get_rest_of_line()[0] == ':'){
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 get_rest_of_orig_line()
{
return *((_QWORD *)input_file_stack + 1) + *((unsigned int *)input_file_stack + 5);
}

canonical_decompiled_code:
__int64 func29()
{
return *((_QWORD *)input_file_stack + 1) + *((unsigned int *)input_file_stack + 5);
}

original_code:
char *get_rest_of_orig_line(){
 return input_file_stack->orig_line_buffer +
  input_file_stack->line_buffer_pos;
}


decompiled_code:
__int64 get_include_filename()
{
return get_rest_of_orig_line() + 9;
}

canonical_decompiled_code:
__int64 func30()
{
return func29() + 9;
}

original_code:
char *get_include_filename(){
 return get_rest_of_orig_line() + strlen("#INCLUDE ");
}


decompiled_code:
__int64 __fastcall codelist_entry_size(int *a1)
{
int v1; // edx
__int64 result; // rax
int v3; // ebp

v1 = *a1;
if ( *a1 == 1 )
return (unsigned int)token_val_size(*((_QWORD *)a1 + 1), 1LL) + 1;
if ( v1 == 3 )
return *((unsigned __int16 *)a1 + 20);
result = 0LL;
if ( !v1 )
{
v3 = token_val_size(*((_QWORD *)a1 + 1), 1LL) + 1;
result = v3 + (unsigned int)token_val_size(*((_QWORD *)a1 + 2), 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
int v1; // edx
__int64 result; // rax
int v3; // ebp

v1 = *a1;
if ( *a1 == 1 )
return (unsigned int)token_val_size(*((_QWORD *)a1 + 1), 1LL) + 1;
if ( v1 == 3 )
return *((unsigned __int16 *)a1 + 20);
result = 0LL;
if ( !v1 )
{
v3 = token_val_size(*((_QWORD *)a1 + 1), 1LL) + 1;
result = v3 + (unsigned int)token_val_size(*((_QWORD *)a1 + 2), 0LL);
}
return result;
}

original_code:
int codelist_entry_size(codelist_entry *entry){
 int size = 0;
 switch(entry->type){
 case CODELIST_ENTRY_TYPE_OP:
  size = 1;
  size += token_val_size(entry->aval, 1);
  size += token_val_size(entry->bval, 0);
  break;
 case CODELIST_ENTRY_TYPE_SPECIAL_OP:
  size = 1;
  size += token_val_size(entry->aval, 1);
  break;
 case CODELIST_ENTRY_TYPE_DATA:
  size = entry->data_size;
  break;
 case CODELIST_ENTRY_TYPE_LABEL:
  size = 0;
  break;
 }
 return size;
}

canonical_original_code:
int codelist_entry_size(struct codelist_entry_t *entry){
 int size = 0;
 switch(entry->type){
 case CODELIST_ENTRY_TYPE_OP:
  size = 1;
  size += token_val_size(entry->aval, 1);
  size += token_val_size(entry->bval, 0);
  break;
 case CODELIST_ENTRY_TYPE_SPECIAL_OP:
  size = 1;
  size += token_val_size(entry->aval, 1);
  break;
 case CODELIST_ENTRY_TYPE_DATA:
  size = entry->data_size;
  break;
 case CODELIST_ENTRY_TYPE_LABEL:
  size = 0;
  break;
 }
 return size;
}

variable_types: struct codelist_entry_t { enum codelist_entry_type { CODELIST_ENTRY_TYPE_OP=0, CODELIST_ENTRY_TYPE_SPECIAL_OP=1, CODELIST_ENTRY_TYPE_LABEL=2, CODELIST_ENTRY_TYPE_DATA=3 } type; unsigned short op; struct token_val_t { enum vm_loc_type { LOC_REGISTER=0, LOC_MEMORY=1, LOC_REGISTER_MEMORY=2, LOC_REGISTER_MEMORY_OFFSET=3, LOC_PUSHPOP=4, LOC_PEEK=5, LOC_PICK=6, LOC_LITERAL=7, LOC_SP=8, LOC_PC=9, LOC_EX=10, LOC_LABEL=11, LOC_LABEL_MEM=12, LOC_IA=13 } type; unsigned short reg; unsigned short loc; unsigned short val; char *label_name; } *aval; struct token_val_t *bval; struct code_label_t { char *label_name; unsigned short loc; struct code_label_t *next; } *label; int *data; unsigned short data_size; unsigned short codeloc; struct codelist_entry_t *next; } *

variable_types: size int

user_defined_types: struct codelist_entry_t { enum codelist_entry_type type; unsigned short op; struct token_val_t *aval; struct token_val_t *bval; struct code_label_t *label; int *data; unsigned short data_size; unsigned short codeloc; struct codelist_entry_t *next; }

user_defined_types: struct token_val_t { enum vm_loc_type type; unsigned short reg; unsigned short loc; unsigned short val; char *label_name; }


decompiled_code:
_BOOL8 __fastcall token_val_size(__int64 a1, char a2)
{
_BOOL8 result; // rax

switch ( *(_DWORD *)a1 )
{
case 1:
case 3:
case 6:
case 0xB:
case 0xC:
result = 1LL;
break;
case 7:
result = 1LL;
if ( a2 )
result = *(_WORD *)(a1 + 8) > 0x1Fu;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, char a2)
{
_BOOL8 result; // rax

switch ( *(_DWORD *)a1 )
{
case 1:
case 3:
case 6:
case 0xB:
case 0xC:
result = 1LL;
break;
case 7:
result = 1LL;
if ( a2 )
result = *(_WORD *)(a1 + 8) > 0x1Fu;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int token_val_size(token_val *val, _Bool a_mode){
 switch(val->type){
 case LOC_REGISTER_MEMORY_OFFSET:
 case LOC_PICK:
 case LOC_MEMORY:
 case LOC_LABEL:
 case LOC_LABEL_MEM:
  return 1;
 case LOC_LITERAL:
  if(a_mode && (val->val <= 0x1f)){
   return 0;
  }else{
   return 1;
  }
 case LOC_REGISTER:
 case LOC_REGISTER_MEMORY:
 case LOC_PUSHPOP:
 case LOC_PEEK:
 case LOC_SP:
 case LOC_PC:
 case LOC_EX:
 case LOC_IA:
  return 0;
 }
 return 0;
}

canonical_original_code:
int token_val_size(struct token_val_t *val, _Bool a_mode){
 switch(val->type){
 case LOC_REGISTER_MEMORY_OFFSET:
 case LOC_PICK:
 case LOC_MEMORY:
 case LOC_LABEL:
 case LOC_LABEL_MEM:
  return 1;
 case LOC_LITERAL:
  if(a_mode && (val->val <= 0x1f)){
   return 0;
  }else{
   return 1;
  }
 case LOC_REGISTER:
 case LOC_REGISTER_MEMORY:
 case LOC_PUSHPOP:
 case LOC_PEEK:
 case LOC_SP:
 case LOC_PC:
 case LOC_EX:
 case LOC_IA:
  return 0;
 }
 return 0;
}

variable_types: struct token_val_t { enum vm_loc_type { LOC_REGISTER=0, LOC_MEMORY=1, LOC_REGISTER_MEMORY=2, LOC_REGISTER_MEMORY_OFFSET=3, LOC_PUSHPOP=4, LOC_PEEK=5, LOC_PICK=6, LOC_LITERAL=7, LOC_SP=8, LOC_PC=9, LOC_EX=10, LOC_LABEL=11, LOC_LABEL_MEM=12, LOC_IA=13 } type; unsigned short reg; unsigned short loc; unsigned short val; char *label_name; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
char v5[256]; // [rsp+0h] [rbp-208h] BYREF
char dest[264]; // [rsp+100h] [rbp-108h] BYREF

initscr();
cbreak();
noecho();
do
{
while ( 1 )
{
while ( 1 )
{
wclear(stdscr);
printw("Menu:\n--------------\n1) Compile\n2) Run\nq) Exit\n----------\n> ", argv);
v3 = wgetch(stdscr);
if ( v3 != 49 )
break;
wclear(stdscr);
printw("Compiling: \n");
printw("Enter file to compile (test.dasm) : ");
echo();
wrefresh(stdscr);
wgetnstr(stdscr, dest, 255);
printw("Enter file to output (test.dbin) : ");
wrefresh(stdscr);
wgetnstr(stdscr, v5, 255);
noecho();
if ( !dest[0] )
strncpy(dest, "test.dasm", 0x64uLL);
if ( !v5[0] )
strncpy(v5, "test.dbin", 0x64uLL);
argv = (const char **)dest;
printw("Compiling %s to %s\n", dest, v5);
wrefresh(stdscr);
printw("Press any key to continue");
wrefresh(stdscr);
wgetch(stdscr);
}
if ( v3 != 50 )
break;
wclear(stdscr);
printw("Running: \n");
wrefresh(stdscr);
sleep(1u);
}
}
while ( v3 != 113 );
wclear(stdscr);
printw("Exiting... \n");
wrefresh(stdscr);
endwin();
return 0;
}

original_code:
int main(int argc, char **argv){
 initscr();
 cbreak();
 noecho();
 char input;
 char buf1[256];
 char buf2[256];
 while(1){
  wclear(stdscr);
  printw("Menu:\n--------------\n1) Compile\n2) Run\nq) Exit\n----------\n> ");
  input = wgetch(stdscr);
  if(input == '1'){
   wclear(stdscr);
   printw("Compiling: \n");
   printw("Enter file to compile (test.dasm) : ");
   echo();
   wrefresh(stdscr);
   wgetnstr(stdscr, buf1, (255));
   printw("Enter file to output (test.dbin) : ");
   wrefresh(stdscr);
   wgetnstr(stdscr, buf2, (255));
   noecho();
   if(strlen(buf1) == 0){
    strncpy(buf1, "test.dasm", 100);
   }
   if(strlen(buf2) == 0){
    strncpy(buf2, "test.dbin", 100);
   }
   printw("Compiling %s to %s\n", buf1, buf2);
   wrefresh(stdscr);
   printw("Press any key to continue");
   wrefresh(stdscr);
   wgetch(stdscr);
  }
  if(input == '2'){
   wclear(stdscr);
   printw("Running: \n");
   wrefresh(stdscr);
   sleep(1);
  }
  if(input == 'q'){
   wclear(stdscr);
   printw("Exiting... \n");
   wrefresh(stdscr);
   break;
  }
 }
 endwin();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: input char


repo: compudj/nscanf

original_code:
int main(int argc, char **argv)
{
 int ret;
 const char *test[] = {
  "test askdjhfaskljdfh aa % again",
  "test lkjlkjlkjlkjlkj zzzz bb %",
  "net123other",
 };
 char name[10];
 char name2[5];
 int testint;
 name[0] = '\0';
 name2[0] = '\0';
 ret = sscanf(test[0], "test %9s aa %% again", name);
 printf("%d \"%s\"\n", ret, name);
 name[0] = '\0';
 name2[0] = '\0';
 ret = sscanf(test[1], "test %9s %4s bb %%", name, name2);
 printf("%d \"%s\" \"%s\"\n", ret, name, name2);
 name[0] = '\0';
 testint = 0;
 ret = sscanf(test[2], "net%d%s", &testint, name);
 printf("%d \"%d\" \"%s\"\n", ret, testint, name);
 name[0] = '\0';
 name2[0] = '\0';
 ret = snscanf(test[0],
  "test %s aa %% again",
  (const ssize_t []) { sizeof(name) },
  name);
 printf("%d \"%s\"\n", ret, name);
 name[0] = '\0';
 name2[0] = '\0';
 ret = snscanf(test[1],
  "test %s %s bb %%",
  (const ssize_t []) { sizeof(name), sizeof(name2) },
  name, name2),
 printf("%d \"%s\" \"%s\"\n", ret, name, name2);
 name[0] = '\0';
 name2[0] = '\0';
 testint = 0;
 ret = snscanf(test[2],
  "net%d%s",
  (const ssize_t []) { -1, sizeof(name) },
  &testint, name);
 printf("%d \"%d\" \"%s\"\n", ret, testint, name);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int ret;
 char *test[] = {
  "test askdjhfaskljdfh aa % again",
  "test lkjlkjlkjlkjlkj zzzz bb %",
  "net123other",
 };
 char name[10];
 char name2[5];
 int testint;
 name[0] = '\0';
 name2[0] = '\0';
 ret = sscanf(test[0], "test %9s aa %% again", name);
 printf("%d \"%s\"\n", ret, name);
 name[0] = '\0';
 name2[0] = '\0';
 ret = sscanf(test[1], "test %9s %4s bb %%", name, name2);
 printf("%d \"%s\" \"%s\"\n", ret, name, name2);
 name[0] = '\0';
 testint = 0;
 ret = sscanf(test[2], "net%d%s", &testint, name);
 printf("%d \"%d\" \"%s\"\n", ret, testint, name);
 name[0] = '\0';
 name2[0] = '\0';
 ret = snscanf(test[0],
  "test %s aa %% again",
  (long []) { sizeof(name) },
  name);
 printf("%d \"%s\"\n", ret, name);
 name[0] = '\0';
 name2[0] = '\0';
 ret = snscanf(test[1],
  "test %s %s bb %%",
  (long []) { sizeof(name), sizeof(name2) },
  name, name2),
 printf("%d \"%s\" \"%s\"\n", ret, name, name2);
 name[0] = '\0';
 name2[0] = '\0';
 testint = 0;
 ret = snscanf(test[2],
  "net%d%s",
  (long []) { -1, sizeof(name) },
  &testint, name);
 printf("%d \"%d\" \"%s\"\n", ret, testint, name);
 return 0;
}

variable_types:
test
char *[]

variable_types:
name
char [10]

variable_types: testint int


decompiled_code:
__int64 __fastcall nscanf_prepare_fmt(void *src, _QWORD *a2, __int64 *a3)
{
const char *v3; // rbp
char v5; // r15
const char *v6; // rbx
__int64 v7; // r14
const char *v8; // rax
char v9; // r12
char v10; // al
char *v11; // rax
char v12; // al
const unsigned __int16 *v13; // rdx
const char *v14; // rax
char v15; // al
_BYTE *v16; // rdi
char *v17; // rax
unsigned int v18; // ebp
signed __int64 v20; // rbx
_BYTE *v21; // r12
_BYTE *v22; // r14
char v23; // r15
_BYTE *v24; // r14
_BYTE *v25; // rbx
char v26; // al
char *v27; // rax
char *v28; // r14
size_t v29; // r15
char v30; // al
const unsigned __int16 *v31; // rbp
char v32; // al
__int64 v33; // rdx
__int64 v34; // rcx
int v35; // eax
char v36; // dl
_BYTE *v37; // rdi
char *v38; // rax
size_t v39; // r14
_BYTE *dest; // [rsp+8h] [rbp-40h]

v3 = (const char *)src;
v5 = *(_BYTE *)src;
if ( *(_BYTE *)src )
{
v6 = (const char *)src;
v7 = 0LL;
do
{
v11 = strchrnul(v6, 37);
v6 = v11;
if ( !*v11 )
break;
v12 = v11[1];
if ( v12 == 37 )
{
v6 += 2;
}
else
{
v6 += (v12 == 42) + 1;
v9 = *v6;
if ( !*v6 )
goto LABEL_34;
v13 = *__ctype_b_loc();
v8 = v6;
while ( (v13[v9] & 0x800) != 0 )
{
v9 = *++v8;
if ( !*v8 )
goto LABEL_34;
}
v14 = v8 + 1;
if ( v9 == 36 )
v6 = v14;
v15 = *v6;
if ( *v6 == 97 || (v13[v15] & 0x800) != 0 )
goto LABEL_34;
switch ( v15 )
{
case 'L':
case 'j':
case 'q':
case 't':
case 'z':
++v6;
break;
case 'h':
if ( v6[1] == 104 )
v6 += 2;
else
++v6;
break;
case 'l':
if ( v6[1] == 108 )
v6 += 2;
else
++v6;
break;
default:
break;
}
v10 = *v6;
if ( *v6 == 97 || v10 == 110 )
{
LABEL_34:
*__errno_location() = 22;
return (unsigned int)-1;
}
if ( v10 == 91 )
{
v16 = v6 + 2;
if ( v6[1] != 94 )
v16 = v6 + 1;
v17 = strchrnul(&v16[*v16 == 93], 93);
if ( !*v17 )
goto LABEL_34;
v6 = v17 + 1;
}
++v7;
}
}
while ( *v6 );
}
else
{
v6 = (const char *)src;
v7 = 0LL;
}
v20 = v6 - v3;
if ( strlen(v3) != v20 )
__assert_fail("strlen(format) == p - format", "nscanf.c", 0xB8u, "nscanf_prepare_fmt");
dest = malloc(v20 + 20 * v7 + 1);
if ( !dest )
{
*__errno_location() = 12;
return (unsigned int)-1;
}
*dest = 0;
if ( !v5 )
{
LABEL_44:
*a2 = dest;
return 0;
}
v21 = dest;
while ( 1 )
{
v27 = strchrnul(v3, 37);
v28 = v27;
if ( !*v27 )
{
memcpy(v21, v3, v27 - v3);
goto LABEL_44;
}
v25 = v27 + 1;
v29 = v27 + 1 - v3;
memcpy(v21, v3, v29);
v21 += v29;
v30 = v28[1];
if ( v30 != 37 )
break;
v3 = v28 + 2;
*v21++ = 37;
LABEL_63:
if ( !*v3 )
goto LABEL_44;
}
if ( v30 == 42 )
{
v25 = v28 + 2;
*v21++ = 42;
}
v23 = *v25;
if ( !*v25 )
LABEL_47:
__assert_fail("*p != '\\0'", "nscanf.c", 0xDFu, "nscanf_prepare_fmt");
v31 = *__ctype_b_loc();
v22 = v25;
while ( (v31[v23] & 0x800) != 0 )
{
v23 = *++v22;
if ( !*v22 )
goto LABEL_47;
}
if ( v23 == 36 )
{
v24 = v22 + 1;
memcpy(v21, v25, v24 - v25);
v21 += v24 - v25;
v25 = v24;
}
v32 = *v25;
if ( *v25 == 97 )
__assert_fail("*p != 'a'", "nscanf.c", 0xF0u, "nscanf_prepare_fmt");
if ( (v31[v32] & 0x800) != 0 )
__assert_fail("!isdigit(*p)", "nscanf.c", 0xF1u, "nscanf_prepare_fmt");
v33 = *a3;
if ( *a3 < 0 )
{
LABEL_83:
++a3;
v36 = *v25;
switch ( *v25 )
{
case 'L':
case 'j':
case 'q':
case 't':
case 'z':
++v25;
*v21++ = v36;
break;
case 'h':
*v21 = 104;
if ( v25[1] == 104 )
{
v25 += 2;
v21[1] = 104;
v21 += 2;
}
else
{
++v25;
++v21;
}
break;
case 'l':
*v21 = 108;
if ( v25[1] == 108 )
{
v25 += 2;
v21[1] = 108;
v21 += 2;
}
else
{
++v25;
++v21;
}
break;
default:
break;
}
v26 = *v25;
if ( *v25 == 110 || v26 == 97 )
__assert_fail("*p != 'n' && *p != 'a'", "nscanf.c", 0x133u, "nscanf_prepare_fmt");
v3 = v25;
if ( v26 == 91 )
{
v37 = v25 + 2;
if ( v25[1] != 94 )
v37 = v25 + 1;
v38 = strchrnul(&v37[*v37 == 93], 93);
if ( !*v38 )
__assert_fail("*p != '\\0'", "nscanf.c", 0x144u, "nscanf_prepare_fmt");
v3 = v38 + 1;
v39 = v38 + 1 - v25;
memcpy(v21, v25, v39);
v21 += v39;
}
goto LABEL_63;
}
v34 = *a3;
if ( v32 != 91 && v32 != 115 )
{
LABEL_80:
v35 = sprintf(v21, "%zu", v34);
v18 = v35;
if ( v35 < 0 )
goto LABEL_51;
if ( v35 > 20 )
__assert_fail("ret <= NSCANF_NUM_WIDTH", "nscanf.c", 0x111u, "nscanf_prepare_fmt");
v21 += v35;
goto LABEL_83;
}
if ( v33 )
{
v34 = v33 - 1;
goto LABEL_80;
}
*__errno_location() = 22;
v18 = -1;
LABEL_51:
free(dest);
return v18;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *src, _QWORD *a2, __int64 *a3)
{
const char *v3; // rbp
char v5; // r15
const char *v6; // rbx
__int64 v7; // r14
const char *v8; // rax
char v9; // r12
char v10; // al
char *v11; // rax
char v12; // al
const unsigned __int16 *v13; // rdx
const char *v14; // rax
char v15; // al
_BYTE *v16; // rdi
char *v17; // rax
unsigned int v18; // ebp
signed __int64 v20; // rbx
_BYTE *v21; // r12
_BYTE *v22; // r14
char v23; // r15
_BYTE *v24; // r14
_BYTE *v25; // rbx
char v26; // al
char *v27; // rax
char *v28; // r14
size_t v29; // r15
char v30; // al
const unsigned __int16 *v31; // rbp
char v32; // al
__int64 v33; // rdx
__int64 v34; // rcx
int v35; // eax
char v36; // dl
_BYTE *v37; // rdi
char *v38; // rax
size_t v39; // r14
_BYTE *dest; // [rsp+8h] [rbp-40h]

v3 = (const char *)src;
v5 = *(_BYTE *)src;
if ( *(_BYTE *)src )
{
v6 = (const char *)src;
v7 = 0LL;
do
{
v11 = strchrnul(v6, 37);
v6 = v11;
if ( !*v11 )
break;
v12 = v11[1];
if ( v12 == 37 )
{
v6 += 2;
}
else
{
v6 += (v12 == 42) + 1;
v9 = *v6;
if ( !*v6 )
goto LABEL_34;
v13 = *__ctype_b_loc();
v8 = v6;
while ( (v13[v9] & 0x800) != 0 )
{
v9 = *++v8;
if ( !*v8 )
goto LABEL_34;
}
v14 = v8 + 1;
if ( v9 == 36 )
v6 = v14;
v15 = *v6;
if ( *v6 == 97 || (v13[v15] & 0x800) != 0 )
goto LABEL_34;
switch ( v15 )
{
case 'L':
case 'j':
case 'q':
case 't':
case 'z':
++v6;
break;
case 'h':
if ( v6[1] == 104 )
v6 += 2;
else
++v6;
break;
case 'l':
if ( v6[1] == 108 )
v6 += 2;
else
++v6;
break;
default:
break;
}
v10 = *v6;
if ( *v6 == 97 || v10 == 110 )
{
LABEL_34:
*__errno_location() = 22;
return (unsigned int)-1;
}
if ( v10 == 91 )
{
v16 = v6 + 2;
if ( v6[1] != 94 )
v16 = v6 + 1;
v17 = strchrnul(&v16[*v16 == 93], 93);
if ( !*v17 )
goto LABEL_34;
v6 = v17 + 1;
}
++v7;
}
}
while ( *v6 );
}
else
{
v6 = (const char *)src;
v7 = 0LL;
}
v20 = v6 - v3;
if ( strlen(v3) != v20 )
__assert_fail("strlen(format) == p - format", "nscanf.c", 0xB8u, "nscanf_prepare_fmt");
dest = malloc(v20 + 20 * v7 + 1);
if ( !dest )
{
*__errno_location() = 12;
return (unsigned int)-1;
}
*dest = 0;
if ( !v5 )
{
LABEL_44:
*a2 = dest;
return 0;
}
v21 = dest;
while ( 1 )
{
v27 = strchrnul(v3, 37);
v28 = v27;
if ( !*v27 )
{
memcpy(v21, v3, v27 - v3);
goto LABEL_44;
}
v25 = v27 + 1;
v29 = v27 + 1 - v3;
memcpy(v21, v3, v29);
v21 += v29;
v30 = v28[1];
if ( v30 != 37 )
break;
v3 = v28 + 2;
*v21++ = 37;
LABEL_63:
if ( !*v3 )
goto LABEL_44;
}
if ( v30 == 42 )
{
v25 = v28 + 2;
*v21++ = 42;
}
v23 = *v25;
if ( !*v25 )
LABEL_47:
__assert_fail("*p != '\\0'", "nscanf.c", 0xDFu, "nscanf_prepare_fmt");
v31 = *__ctype_b_loc();
v22 = v25;
while ( (v31[v23] & 0x800) != 0 )
{
v23 = *++v22;
if ( !*v22 )
goto LABEL_47;
}
if ( v23 == 36 )
{
v24 = v22 + 1;
memcpy(v21, v25, v24 - v25);
v21 += v24 - v25;
v25 = v24;
}
v32 = *v25;
if ( *v25 == 97 )
__assert_fail("*p != 'a'", "nscanf.c", 0xF0u, "nscanf_prepare_fmt");
if ( (v31[v32] & 0x800) != 0 )
__assert_fail("!isdigit(*p)", "nscanf.c", 0xF1u, "nscanf_prepare_fmt");
v33 = *a3;
if ( *a3 < 0 )
{
LABEL_83:
++a3;
v36 = *v25;
switch ( *v25 )
{
case 'L':
case 'j':
case 'q':
case 't':
case 'z':
++v25;
*v21++ = v36;
break;
case 'h':
*v21 = 104;
if ( v25[1] == 104 )
{
v25 += 2;
v21[1] = 104;
v21 += 2;
}
else
{
++v25;
++v21;
}
break;
case 'l':
*v21 = 108;
if ( v25[1] == 108 )
{
v25 += 2;
v21[1] = 108;
v21 += 2;
}
else
{
++v25;
++v21;
}
break;
default:
break;
}
v26 = *v25;
if ( *v25 == 110 || v26 == 97 )
__assert_fail("*p != 'n' && *p != 'a'", "nscanf.c", 0x133u, "nscanf_prepare_fmt");
v3 = v25;
if ( v26 == 91 )
{
v37 = v25 + 2;
if ( v25[1] != 94 )
v37 = v25 + 1;
v38 = strchrnul(&v37[*v37 == 93], 93);
if ( !*v38 )
__assert_fail("*p != '\\0'", "nscanf.c", 0x144u, "nscanf_prepare_fmt");
v3 = v38 + 1;
v39 = v38 + 1 - v25;
memcpy(v21, v25, v39);
v21 += v39;
}
goto LABEL_63;
}
v34 = *a3;
if ( v32 != 91 && v32 != 115 )
{
LABEL_80:
v35 = sprintf(v21, "%zu", v34);
v18 = v35;
if ( v35 < 0 )
goto LABEL_51;
if ( v35 > 20 )
__assert_fail("ret <= NSCANF_NUM_WIDTH", "nscanf.c", 0x111u, "nscanf_prepare_fmt");
v21 += v35;
goto LABEL_83;
}
if ( v33 )
{
v34 = v33 - 1;
goto LABEL_80;
}
*__errno_location() = 22;
v18 = -1;
LABEL_51:
free(dest);
return v18;
}

original_code:
static
int nscanf_prepare_fmt(const char *format,
  char **format_out,
  const ssize_t *field_widths)
{
 char *format_a, *dest_p;
 size_t format_a_len;
 const char *p, *prev_p;
 int ret;
 const ssize_t *fw_iter = field_widths;
 size_t nr_fw = 0;
 p = format;
 while (*p != '\0') {
  p = strchrnul(p, '%');
  if (*p == '\0') {
   break;
  }
  p++;
  switch (*p) {
  case '%':
   p++;
   continue;
  case '*':
   p++;
   break;
  default:
   break;
  }
  prev_p = p;
  for (;;) {
   if (*p == '\0') {
    (*__errno_location ()) = 22;
    return -1;
   }
   if (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) {
    p++;
    continue;
   }
   if (*p == '$') {
    p++;
    break;
   }
   p = prev_p;
   break;
  }
  if (*p == 'a') {
   (*__errno_location ()) = 22;
   return -1;
  }
  if (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) {
   (*__errno_location ()) = 22;
   return -1;
  }
  switch (*p) {
  case 'h':
   p++;
   if (*p == 'h') {
    p++;
   }
   break;
  case 'l':
   p++;
   if (*p == 'l') {
    p++;
   }
   break;
  case 'j':
  case 'z':
  case 't':
  case 'q':
  case 'L':
   p++;
   break;
  default:
   break;
  }
  switch (*p) {
  case '[':
   p++;
   if (*p == '^') {
    p++;
   }
   if (*p == ']') {
    p++;
   }
   p = strchrnul(p, ']');
   if (*p == '\0') {
    (*__errno_location ()) = 22;
    return -1;
   }
   p++;
   break;
  case 'n':
  case 'a':
   (*__errno_location ()) = 22;
   return -1;
  default:
   break;
  }
  nr_fw++;
 }
 ((void) sizeof ((strlen(format) == p - format) ? 1 : 0), __extension__ ({ if (strlen(format) == p - format) ; else __assert_fail ("strlen(format) == p - format", "nscanf.c", 184, __extension__ __PRETTY_FUNCTION__); }));
 format_a_len = p - format + 1 + (nr_fw * 20);
 format_a = malloc(format_a_len);
 if (!format_a) {
  (*__errno_location ()) = 12;
  return -1;
 }
 format_a[0] = '\0';
 p = format;
 dest_p = format_a;
 while (*p != '\0') {
  prev_p = p;
  p = strchrnul(p, '%');
  if (*p == '\0') {
   memcpy(dest_p, prev_p, p - prev_p);
   break;
  }
  p++;
  memcpy(dest_p, prev_p, p - prev_p);
  dest_p += p - prev_p;
  switch (*p) {
  case '%':
   *(dest_p++) = *(p++);
   continue;
  case '*':
   *(dest_p++) = *(p++);
   break;
  default:
   break;
  }
  prev_p = p;
  for (;;) {
   ((void) sizeof ((*p != '\0') ? 1 : 0), __extension__ ({ if (*p != '\0') ; else __assert_fail ("*p != '\\0'", "nscanf.c", 223, __extension__ __PRETTY_FUNCTION__); }));
   if (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) {
    p++;
    continue;
   }
   if (*p == '$') {
    p++;
    memcpy(dest_p, prev_p, p - prev_p);
    dest_p += p - prev_p;
    break;
   }
   p = prev_p;
   break;
  }
  ((void) sizeof ((*p != 'a') ? 1 : 0), __extension__ ({ if (*p != 'a') ; else __assert_fail ("*p != 'a'", "nscanf.c", 240, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) ? 1 : 0), __extension__ ({ if (!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit)) ; else __assert_fail ("!isdigit(*p)", "nscanf.c", 241, __extension__ __PRETTY_FUNCTION__); }));
  if (*fw_iter >= 0) {
   size_t width = *fw_iter;
   switch (*p) {
   case 's':
   case '[':
    if (!width) {
     (*__errno_location ()) = 22;
     ret = -1;
     goto end_error;
    }
    width--;
    break;
   default:
    break;
   }
   ret = sprintf(dest_p, "%zu", width);
   if (ret < 0) {
    goto end_error;
   }
   ((void) sizeof ((ret <= 20) ? 1 : 0), __extension__ ({ if (ret <= 20) ; else __assert_fail ("ret <= NSCANF_NUM_WIDTH", "nscanf.c", 273, __extension__ __PRETTY_FUNCTION__); }));
   dest_p += ret;
  }
  fw_iter++;
  switch (*p) {
  case 'h':
   *(dest_p++) = *(p++);
   if (*p == 'h') {
    *(dest_p++) = *(p++);
   }
   break;
  case 'l':
   *(dest_p++) = *(p++);
   if (*p == 'l') {
    *(dest_p++) = *(p++);
   }
   break;
  case 'j':
  case 'z':
  case 't':
  case 'q':
  case 'L':
   *(dest_p++) = *(p++);
   break;
  default:
   break;
  }
  ((void) sizeof ((*p != 'n' && *p != 'a') ? 1 : 0), __extension__ ({ if (*p != 'n' && *p != 'a') ; else __assert_fail ("*p != 'n' && *p != 'a'", "nscanf.c", 307, __extension__ __PRETTY_FUNCTION__); }));
  prev_p = p;
  switch (*p) {
  case '[':
   p++;
   if (*p == '^') {
    p++;
   }
   if (*p == ']') {
    p++;
   }
   p = strchrnul(p, ']');
   ((void) sizeof ((*p != '\0') ? 1 : 0), __extension__ ({ if (*p != '\0') ; else __assert_fail ("*p != '\\0'", "nscanf.c", 324, __extension__ __PRETTY_FUNCTION__); }));
   p++;
   memcpy(dest_p, prev_p, p - prev_p);
   dest_p += p - prev_p;
   break;
  default:
   break;
  }
 }
 *format_out = format_a;
 return 0;
end_error:
 free(format_a);
 return ret;
}

canonical_original_code:
static int nscanf_prepare_fmt(char *format, char **format_out, long *field_widths)
{
 char *format_a; char *dest_p;
 unsigned long format_a_len;
 char *p; char *prev_p;
 int ret;
 long *fw_iter = field_widths;
 unsigned long nr_fw = 0;
 p = format;
 while (*p != '\0') {
  p = strchrnul(p, '%');
  if (*p == '\0') {
   break;
  }
  p++;
  switch (*p) {
  case '%':
   p++;
   continue;
  case '*':
   p++;
   break;
  default:
   break;
  }
  prev_p = p;
  for (;;) {
   if (*p == '\0') {
    (*__errno_location ()) = 22;
    return -1;
   }
   if (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) {
    p++;
    continue;
   }
   if (*p == '$') {
    p++;
    break;
   }
   p = prev_p;
   break;
  }
  if (*p == 'a') {
   (*__errno_location ()) = 22;
   return -1;
  }
  if (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) {
   (*__errno_location ()) = 22;
   return -1;
  }
  switch (*p) {
  case 'h':
   p++;
   if (*p == 'h') {
    p++;
   }
   break;
  case 'l':
   p++;
   if (*p == 'l') {
    p++;
   }
   break;
  case 'j':
  case 'z':
  case 't':
  case 'q':
  case 'L':
   p++;
   break;
  default:
   break;
  }
  switch (*p) {
  case '[':
   p++;
   if (*p == '^') {
    p++;
   }
   if (*p == ']') {
    p++;
   }
   p = strchrnul(p, ']');
   if (*p == '\0') {
    (*__errno_location ()) = 22;
    return -1;
   }
   p++;
   break;
  case 'n':
  case 'a':
   (*__errno_location ()) = 22;
   return -1;
  default:
   break;
  }
  nr_fw++;
 }
 ((void) sizeof ((strlen(format) == p - format) ? 1 : 0), __extension__ ({ if (strlen(format) == p - format) ; else __assert_fail ("strlen(format) == p - format", "nscanf.c", 184, __extension__ __PRETTY_FUNCTION__); }));
 format_a_len = p - format + 1 + (nr_fw * 20);
 format_a = malloc(format_a_len);
 if (!format_a) {
  (*__errno_location ()) = 12;
  return -1;
 }
 format_a[0] = '\0';
 p = format;
 dest_p = format_a;
 while (*p != '\0') {
  prev_p = p;
  p = strchrnul(p, '%');
  if (*p == '\0') {
   memcpy(dest_p, prev_p, p - prev_p);
   break;
  }
  p++;
  memcpy(dest_p, prev_p, p - prev_p);
  dest_p += p - prev_p;
  switch (*p) {
  case '%':
   *(dest_p++) = *(p++);
   continue;
  case '*':
   *(dest_p++) = *(p++);
   break;
  default:
   break;
  }
  prev_p = p;
  for (;;) {
   ((void) sizeof ((*p != '\0') ? 1 : 0), __extension__ ({ if (*p != '\0') ; else __assert_fail ("*p != '\\0'", "nscanf.c", 223, __extension__ __PRETTY_FUNCTION__); }));
   if (((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) {
    p++;
    continue;
   }
   if (*p == '$') {
    p++;
    memcpy(dest_p, prev_p, p - prev_p);
    dest_p += p - prev_p;
    break;
   }
   p = prev_p;
   break;
  }
  ((void) sizeof ((*p != 'a') ? 1 : 0), __extension__ ({ if (*p != 'a') ; else __assert_fail ("*p != 'a'", "nscanf.c", 240, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) ? 1 : 0), __extension__ ({ if (!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit)) ; else __assert_fail ("!isdigit(*p)", "nscanf.c", 241, __extension__ __PRETTY_FUNCTION__); }));
  if (*fw_iter >= 0) {
   unsigned long width = *fw_iter;
   switch (*p) {
   case 's':
   case '[':
    if (!width) {
     (*__errno_location ()) = 22;
     ret = -1;
     goto end_error;
    }
    width--;
    break;
   default:
    break;
   }
   ret = sprintf(dest_p, "%zu", width);
   if (ret < 0) {
    goto end_error;
   }
   ((void) sizeof ((ret <= 20) ? 1 : 0), __extension__ ({ if (ret <= 20) ; else __assert_fail ("ret <= NSCANF_NUM_WIDTH", "nscanf.c", 273, __extension__ __PRETTY_FUNCTION__); }));
   dest_p += ret;
  }
  fw_iter++;
  switch (*p) {
  case 'h':
   *(dest_p++) = *(p++);
   if (*p == 'h') {
    *(dest_p++) = *(p++);
   }
   break;
  case 'l':
   *(dest_p++) = *(p++);
   if (*p == 'l') {
    *(dest_p++) = *(p++);
   }
   break;
  case 'j':
  case 'z':
  case 't':
  case 'q':
  case 'L':
   *(dest_p++) = *(p++);
   break;
  default:
   break;
  }
  ((void) sizeof ((*p != 'n' && *p != 'a') ? 1 : 0), __extension__ ({ if (*p != 'n' && *p != 'a') ; else __assert_fail ("*p != 'n' && *p != 'a'", "nscanf.c", 307, __extension__ __PRETTY_FUNCTION__); }));
  prev_p = p;
  switch (*p) {
  case '[':
   p++;
   if (*p == '^') {
    p++;
   }
   if (*p == ']') {
    p++;
   }
   p = strchrnul(p, ']');
   ((void) sizeof ((*p != '\0') ? 1 : 0), __extension__ ({ if (*p != '\0') ; else __assert_fail ("*p != '\\0'", "nscanf.c", 324, __extension__ __PRETTY_FUNCTION__); }));
   p++;
   memcpy(dest_p, prev_p, p - prev_p);
   dest_p += p - prev_p;
   break;
  default:
   break;
  }
 }
 *format_out = format_a;
 return 0;
end_error:
 free(format_a);
 return ret;
}

variable_types:
format
char *

variable_types:
p
char *

variable_types:
width
unsigned long


vsnscanf

decompiled_code:
__int64 __fastcall vsnscanf(char *s, void *src, __int64 *a3, void *a4)
{
int v5; // ebx
char *format; // [rsp+8h] [rbp-20h] BYREF

v5 = nscanf_prepare_fmt(src, &format, a3);
if ( v5 >= 0 )
{
v5 = vsscanf(s, format, a4);
free(format);
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s, void *src, __int64 *a3, void *a4)
{
int v5; // ebx
char *format; // [rsp+8h] [rbp-20h] BYREF

v5 = func6(src, &format, a3);
if ( v5 >= 0 )
{
v5 = vsscanf(s, format, a4);
free(format);
}
return (unsigned int)v5;
}

original_code:
int vsnscanf(const char *str, const char *format,
  const ssize_t *field_widths, va_list ap)
{
 char *format_a;
 int ret;
 ret = nscanf_prepare_fmt(format, &format_a, field_widths);
 if (ret < 0) {
  goto end;
 }
 ret = vsscanf(str, format_a, ap);
 free(format_a);
end:
 return ret;
}

canonical_original_code:
int vsnscanf(char *str, char *format, long *field_widths, __builtin_va_list ap)
{
 char *format_a;
 int ret;
 ret = nscanf_prepare_fmt(format, &format_a, field_widths);
 if (ret < 0) {
  goto end;
 }
 ret = vsscanf(str, format_a, ap);
 free(format_a);
end:
 return ret;
}


snscanf

decompiled_code:
__int64 __fastcall snscanf(char *a1, void *a2)
{
return vsnscanf(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, void *a2)
{
return func7(a1, a2);
}

original_code:
int snscanf(const char *str, const char *format,
  const ssize_t *field_widths, ...)
{
 va_list ap;
 int ret;
 __builtin_va_start(ap,field_widths);
 ret = vsnscanf(str, format, field_widths, ap);
 __builtin_va_end(ap);
 return ret;
}

canonical_original_code:
int snscanf(char *str, char *format, long *field_widths, ...)
{
 __builtin_va_list ap;
 int ret;
 __builtin_va_start(ap,field_widths);
 ret = vsnscanf(str, format, field_widths, ap);
 __builtin_va_end(ap);
 return ret;
}


vnscanf

decompiled_code:
__int64 __fastcall vnscanf(void *src)
{
return vfnscanf(stdin, src);
}

canonical_decompiled_code:
__int64 __fastcall func11(void *src)
{
return func9(stdin, src);
}

original_code:
int vnscanf(const char *format,
  const ssize_t *field_widths, va_list ap)
{
 return vfnscanf(stdin, format, field_widths, ap);
}

canonical_original_code:
int vnscanf(char *format, long *field_widths, __builtin_va_list ap)
{
 return vfnscanf(stdin, format, field_widths, ap);
}


nscanf

decompiled_code:
__int64 __fastcall nscanf(void *src)
{
return vfnscanf(stdin, src);
}

canonical_decompiled_code:
__int64 __fastcall func12(void *src)
{
return func9(stdin, src);
}

original_code:
int nscanf(const char *format, const ssize_t *field_widths, ...)
{
 va_list ap;
 int ret;
 __builtin_va_start(ap,field_widths);
 ret = vfnscanf(stdin, format, field_widths, ap);
 __builtin_va_end(ap);
 return ret;
}

canonical_original_code:
int nscanf(char *format, long *field_widths, ...)
{
 __builtin_va_list ap;
 int ret;
 __builtin_va_start(ap,field_widths);
 ret = vfnscanf(stdin, format, field_widths, ap);
 __builtin_va_end(ap);
 return ret;
}


repo: computersforpeace/bbb-floppy

original_code:
static void add_to_timespec(struct timespec *ts, int us)
{
 ts->tv_nsec += us * 1000;
 ts->tv_sec += ts->tv_nsec / 1000000000;
 ts->tv_nsec %= 1000000000;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types: us int


decompiled_code:
double __fastcall get_frequency(double a1)
{
return pow(2.0, a1 / 12.0) * 440.0;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
return pow(2.0, a1 / 12.0) * 440.0;
}

original_code:
static double get_frequency(double delta_a4)
{
 return 440.0 * pow(2, (double)delta_a4 / 12.0);
}

return_type: double


decompiled_code:
__int64 __fastcall get_period_us(double a1)
{
double v1; // xmm1_8

v1 = get_frequency(a1);
return lround(1000000.0 / v1);
}

canonical_decompiled_code:
__int64 __fastcall func9(double a1)
{
double v1; // xmm1_8

v1 = func8(a1);
return lround(1000000.0 / v1);
}

original_code:
static long int get_period_us(double delta_a4)
{
 return lround(1000000.0 / get_frequency(delta_a4));
}

canonical_original_code:
static long get_period_us(double delta_a4)
{
 return lround(1000000.0 / get_frequency(delta_a4));
}

return_type: long


decompiled_code:
__int64 init_tones()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = -24LL; i != 25; ++i )
{
result = get_period_us((double)(int)i);
qword_404540[i] = result;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 i; // rbx
__int64 result; // rax

for ( i = -24LL; i != 25; ++i )
{
result = func9((double)(int)i);
qword_404540[i] = result;
}
return result;
}

original_code:
static void init_tones(void)
{
 int i;
 for (i = -24; i <= 24; i++)
  tone_period_us[i - -24] = get_period_us(i);
}

canonical_original_code:
static void init_tones()
{
 int i;
 for (i = -24; i <= 24; i++)
  tone_period_us[i - -24] = get_period_us(i);
}

variable_types: i int


tone

decompiled_code:
__int64 __fastcall tone(int a1, int a2)
{
int v2; // ebp
int v3; // ebx
__int64 result; // rax
struct timespec v5[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = 1000 * a2 / a1;
if ( clock_gettime(1, v5) < 0 )
{
perror("clock_gettime");
result = (unsigned int)*__errno_location();
}
else
{
v3 = 0;
result = 0LL;
if ( v2 > 0 )
{
while ( 1 )
{
take_step();
add_to_timespec(v5, a1);
if ( clock_nanosleep(1, 1, v5, 0LL) < 0 )
break;
if ( v2 == ++v3 )
return 0LL;
}
perror("clock_nanosleep");
result = (unsigned int)*__errno_location();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
int v2; // ebp
int v3; // ebx
__int64 result; // rax
struct timespec v5[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = 1000 * a2 / a1;
if ( clock_gettime(1, v5) < 0 )
{
perror("clock_gettime");
result = (unsigned int)*__errno_location();
}
else
{
v3 = 0;
result = 0LL;
if ( v2 > 0 )
{
while ( 1 )
{
func23();
func7(v5, a1);
if ( clock_nanosleep(1, 1, v5, 0LL) < 0 )
break;
if ( v2 == ++v3 )
return 0LL;
}
perror("clock_nanosleep");
result = (unsigned int)*__errno_location();
}
}
return result;
}

original_code:
int tone(int tone_us, int ms)
{
 int cycles = 1000 * ms / tone_us;
 int i, ret;
 struct timespec ts;
 ret = clock_gettime(1, &ts);
 if (ret < 0) {
  perror("clock_gettime");
  return (*__errno_location ());
 }
 for (i = 0; i < cycles; i++) {
  take_step();
  add_to_timespec(&ts, tone_us);
  ret = clock_nanosleep(1, 1, &ts, ((void *)0));
  if (ret < 0) {
   perror("clock_nanosleep");
   return (*__errno_location ());
  }
 }
 return 0;
}

canonical_original_code:
int tone(int tone_us, int ms)
{
 int cycles = 1000 * ms / tone_us;
 int i; int ret;
 struct timespec ts;
 ret = clock_gettime(1, &ts);
 if (ret < 0) {
  perror("clock_gettime");
  return (*__errno_location ());
 }
 for (i = 0; i < cycles; i++) {
  take_step();
  add_to_timespec(&ts, tone_us);
  ret = clock_nanosleep(1, 1, &ts, ((void *)0));
  if (ret < 0) {
   perror("clock_nanosleep");
   return (*__errno_location ());
  }
 }
 return 0;
}

variable_types: ms int

variable_types: cycles int

variable_types: ret int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall play_score(_DWORD *a1, int a2)
{
_DWORD *v2; // rbp
int i; // ebx
int v4; // ebx
__int64 result; // rax

v2 = a1;
for ( i = a1[1]; i; i = v2[1] )
{
v4 = a2 * i;
tone(tone_period_us[*v2 + 12], 12 * v4);
result = udelay_0(18000 * v4 / 1000000, 18000 * v4 % 1000000);
v2 += 2;
}
return result;
}

original_code:
static void play_score(struct note *score, int speed)
{
 struct note *n = score;
 while (n->duration) {
  long int period_us = (tone_period_us[(n->delta_a4 - 12) - -24]);
  int ms = n->duration * 12 * speed;
  tone(period_us, ms);
  ms *= 1500;
  udelay(ms / 1000000, ms % 1000000);
  n++;
 }
}

canonical_original_code:
static void play_score(struct note *score, int speed)
{
 struct note *n = score;
 while (n->duration) {
  long period_us = (tone_period_us[(n->delta_a4 - 12) - -24]);
  int ms = n->duration * 12 * speed;
  tone(period_us, ms);
  ms *= 1500;
  udelay(ms / 1000000, ms % 1000000);
  n++;
 }
}

variable_types: struct note { int delta_a4; int duration; } *

variable_types: speed int


decompiled_code:
__int64 play_looney_tunes()
{
return play_score(looney_tunes, 2);
}

canonical_decompiled_code:
__int64 func14()
{
return func13(looney_tunes, 2);
}

original_code:
static void play_looney_tunes(void)
{
 play_score(looney_tunes, SPEED_FAST);
}

canonical_original_code:
static void play_looney_tunes()
{
 play_score(looney_tunes, SPEED_FAST);
}


decompiled_code:
__int64 play_mario()
{
play_score(mario1, 4);
play_score(mario2, 4);
play_score(mario2, 4);
play_score(mario3, 4);
return play_score(mario3, 4);
}

canonical_decompiled_code:
__int64 func15()
{
func13(mario1, 4);
func13(mario2, 4);
func13(mario2, 4);
func13(mario3, 4);
return func13(mario3, 4);
}

original_code:
static void play_mario(void)
{
 int speed = SPEED_NORMAL;
 play_score(mario1, speed);
 play_score(mario2, speed);
 play_score(mario2, speed);
 play_score(mario3, speed);
 play_score(mario3, speed);
}

canonical_original_code:
static void play_mario()
{
 int speed = SPEED_NORMAL;
 play_score(mario1, speed);
 play_score(mario2, speed);
 play_score(mario2, speed);
 play_score(mario3, speed);
 play_score(mario3, speed);
}


main

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

init_tones(argc, argv, envp);
v3 = 1;
if ( !(unsigned int)init_drives() )
{
v3 = 0;
puts("Done resetting...");
udelay_0(1, 0);
puts("GO!");
play_looney_tunes();
play_mario();
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

func10(argc, argv, envp);
v3 = 1;
if ( !(unsigned int)func24() )
{
v3 = 0;
puts("Done resetting...");
func11(1, 0);
puts("GO!");
func14();
func15();
}
return v3;
}

original_code:
int main()
{
 init_tones();
 if (init_drives())
  return 1;
 printf("Done resetting...\n");
 udelay(1, 0);
 printf("GO!\n");
 play_looney_tunes();
 play_mario();
 return 0;
}


decompiled_code:
int __fastcall open_gpio(unsigned int a1)
{
int result; // eax
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v2, "/sys/class/gpio/gpio%d/value", a1);
result = open(v2, 1);
if ( result < 0 )
{
perror("open");
result = *__errno_location();
}
return result;
}

canonical_decompiled_code:
int __fastcall func18(unsigned int a1)
{
int result; // eax
char v2[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v2, "/sys/class/gpio/gpio%d/value", a1);
result = open(v2, 1);
if ( result < 0 )
{
perror("open");
result = *__errno_location();
}
return result;
}

original_code:
static int open_gpio(int idx)
{
 char str[80];
 int fd;
 sprintf(str, "/sys/class/gpio" "/gpio%d" "/value", idx);
 fd = open(str, 01);
 if (fd < 0) {
  perror("open");
  return (*__errno_location ());
 }
 return fd;
}

variable_types: idx int

variable_types:
str
char [80]

variable_types: fd int


decompiled_code:
__int64 __fastcall export_gpio(unsigned int a1)
{
int v1; // ebp
size_t v2; // rax
signed __int64 v3; // r12
int v4; // eax
int v5; // ebx
ssize_t v6; // rax
struct stat v8; // [rsp+0h] [rbp-F8h] BYREF
char s[104]; // [rsp+90h] [rbp-68h] BYREF

sprintf(s, "/sys/class/gpio/gpio%d", a1);
if ( (unsigned int)stat(s, &v8) || (v8.st_mode & 0xF000) != 0x4000 )
{
v1 = open("/sys/class/gpio/export", 1);
if ( v1 < 0 )
{
LABEL_11:
perror("open");
return (unsigned int)*__errno_location();
}
sprintf(s, "%d", a1);
v2 = strlen(s);
v3 = write(v1, s, v2);
if ( v3 < 0 )
{
perror("write to export");
return (unsigned int)*__errno_location();
}
if ( strlen(s) > v3 )
goto LABEL_16;
close(v1);
}
sprintf(s, "/sys/class/gpio/gpio%d/direction", a1);
v4 = open(s, 1);
v5 = v4;
if ( v4 < 0 )
goto LABEL_11;
v6 = write(v4, "out", 3uLL);
if ( v6 < 0 )
{
perror("write");
return (unsigned int)*__errno_location();
}
if ( (unsigned __int64)v6 > 2 )
{
close(v5);
return 0LL;
}
LABEL_16:
puts("error: didn't write full length");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1)
{
int v1; // ebp
size_t v2; // rax
signed __int64 v3; // r12
int v4; // eax
int v5; // ebx
ssize_t v6; // rax
struct stat v8; // [rsp+0h] [rbp-F8h] BYREF
char s[104]; // [rsp+90h] [rbp-68h] BYREF

sprintf(s, "/sys/class/gpio/gpio%d", a1);
if ( (unsigned int)func27(s, &v8) || (v8.st_mode & 0xF000) != 0x4000 )
{
v1 = open("/sys/class/gpio/export", 1);
if ( v1 < 0 )
{
LABEL_11:
perror("open");
return (unsigned int)*__errno_location();
}
sprintf(s, "%d", a1);
v2 = strlen(s);
v3 = write(v1, s, v2);
if ( v3 < 0 )
{
perror("write to export");
return (unsigned int)*__errno_location();
}
if ( strlen(s) > v3 )
goto LABEL_16;
close(v1);
}
sprintf(s, "/sys/class/gpio/gpio%d/direction", a1);
v4 = open(s, 1);
v5 = v4;
if ( v4 < 0 )
goto LABEL_11;
v6 = write(v4, "out", 3uLL);
if ( v6 < 0 )
{
perror("write");
return (unsigned int)*__errno_location();
}
if ( (unsigned __int64)v6 > 2 )
{
close(v5);
return 0LL;
}
LABEL_16:
puts("error: didn't write full length");
return 0xFFFFFFFFLL;
}

original_code:
static int export_gpio(int idx)
{
 char str[80];
 int fd;
 ssize_t ret;
 struct stat sb;
 sprintf(str, "/sys/class/gpio" "/gpio%d", idx);
 if (!stat(str, &sb) == 0 || !((((sb.st_mode)) & 0170000) == (0040000))) {
  fd = open("/sys/class/gpio" "/export", 01);
  if (fd < 0) {
   perror("open");
   return (*__errno_location ());
  }
  sprintf(str, "%d", idx);
  ret = write(fd, str, strlen(str));
  if (ret < 0) {
   perror("write to export");
   return (*__errno_location ());
  } else if ((size_t)ret < strlen(str)) {
   printf("error: didn't write full length\n");
   return -1;
  }
  close(fd);
 }
 sprintf(str, "/sys/class/gpio" "/gpio%d" "/direction", idx);
 fd = open(str, 01);
 if (fd < 0) {
  perror("open");
  return (*__errno_location ());
 }
 ret = write(fd, "out", strlen("out"));
 if (ret < 0) {
  perror("write");
  return (*__errno_location ());
 } else if ((size_t)ret < strlen("out")) {
  printf("error: didn't write full length\n");
  return -1;
 }
 close(fd);
 return 0;
}

canonical_original_code:
static int export_gpio(int idx)
{
 char str[80];
 int fd;
 long ret;
 struct stat sb;
 sprintf(str, "/sys/class/gpio" "/gpio%d", idx);
 if (!stat(str, &sb) == 0 || !((((sb.st_mode)) & 0170000) == (0040000))) {
  fd = open("/sys/class/gpio" "/export", 01);
  if (fd < 0) {
   perror("open");
   return (*__errno_location ());
  }
  sprintf(str, "%d", idx);
  ret = write(fd, str, strlen(str));
  if (ret < 0) {
   perror("write to export");
   return (*__errno_location ());
  } else if ((unsigned long)ret < strlen(str)) {
   printf("error: didn't write full length\n");
   return -1;
  }
  close(fd);
 }
 sprintf(str, "/sys/class/gpio" "/gpio%d" "/direction", idx);
 fd = open(str, 01);
 if (fd < 0) {
  perror("open");
  return (*__errno_location ());
 }
 ret = write(fd, "out", strlen("out"));
 if (ret < 0) {
  perror("write");
  return (*__errno_location ());
 } else if ((unsigned long)ret < strlen("out")) {
  printf("error: didn't write full length\n");
  return -1;
 }
 close(fd);
 return 0;
}

variable_types: ret long

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
int init_gpios()
{
int result; // eax

result = export_gpio(0x3Cu);
if ( !result )
{
result = export_gpio(0x32u);
if ( !result )
{
result = open_gpio(0x3Cu);
step_fd = result;
if ( result >= 0 )
{
result = open_gpio(0x32u);
dir_fd = result;
if ( result > 0 )
result = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int func20()
{
int result; // eax

result = func19(0x3Cu);
if ( !result )
{
result = func19(0x32u);
if ( !result )
{
result = func18(0x3Cu);
step_fd = result;
if ( result >= 0 )
{
result = func18(0x32u);
dir_fd = result;
if ( result > 0 )
result = 0;
}
}
}
return result;
}

original_code:
static int init_gpios(void)
{
 int ret;
 ret = export_gpio(60);
 if (ret)
  return ret;
 ret = export_gpio(50);
 if (ret)
  return ret;
 step_fd = open_gpio(60);
 if (step_fd < 0)
  return step_fd;
 dir_fd = open_gpio(50);
 if (dir_fd < 0)
  return dir_fd;
 return 0;
}

canonical_original_code:
static int init_gpios()
{
 int ret;
 ret = export_gpio(60);
 if (ret)
  return ret;
 ret = export_gpio(50);
 if (ret)
  return ret;
 step_fd = open_gpio(60);
 if (step_fd < 0)
  return step_fd;
 dir_fd = open_gpio(50);
 if (dir_fd < 0)
  return dir_fd;
 return 0;
}


decompiled_code:
__int64 reset_floppy_positions()
{
int v0; // ebx

set_direction(0);
v0 = 80;
do
{
write_value(step_fd, 0);
write_value(step_fd, 1u);
udelay(0, 2000);
--v0;
}
while ( v0 );
set_direction(1u);
return 0LL;
}

original_code:
static int reset_floppy_positions(void)
{
 int i;
 set_direction(0);
 for (i = 0; i < 80; i++) {
  write_value(step_fd, 0);
  write_value(step_fd, 1);
  udelay(0, 2000);
 }
 set_direction(1);
 return 0;
}

canonical_original_code:
static int reset_floppy_positions()
{
 int i;
 set_direction(0);
 for (i = 0; i < 80; i++) {
  write_value(step_fd, 0);
  write_value(step_fd, 1);
  udelay(0, 2000);
 }
 set_direction(1);
 return 0;
}


decompiled_code:
__int64 take_step()
{
int v0; // eax

write_value(step_fd, 0);
write_value(step_fd, 1u);
v0 = floppy_position + 2 * floppy_direction - 1;
floppy_position = v0;
if ( v0 | floppy_direction )
{
if ( v0 == 79 && floppy_direction == 1 )
set_direction(0);
}
else
{
set_direction(1u);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func23()
{
int v0; // eax

func16(step_fd, 0);
func16(step_fd, 1u);
v0 = floppy_position + 2 * floppy_direction - 1;
floppy_position = v0;
if ( v0 | floppy_direction )
{
if ( v0 == 79 && floppy_direction == 1 )
func17(0);
}
else
{
func17(1u);
}
return 0LL;
}

original_code:
int take_step(void)
{
 write_value(step_fd, 0);
 write_value(step_fd, 1);
 floppy_position += floppy_direction * 2 - 1;
 if (floppy_direction == 0 && floppy_position == 0)
  set_direction(1);
 else if (floppy_direction == 1 && floppy_position == 80 - 1)
  set_direction(0);
 return 0;
}

canonical_original_code:
int take_step()
{
 write_value(step_fd, 0);
 write_value(step_fd, 1);
 floppy_position += floppy_direction * 2 - 1;
 if (floppy_direction == 0 && floppy_position == 0)
  set_direction(1);
 else if (floppy_direction == 1 && floppy_position == 80 - 1)
  set_direction(0);
 return 0;
}


decompiled_code:
int init_drives()
{
int result; // eax

result = init_gpios();
if ( !result )
result = reset_floppy_positions();
return result;
}

canonical_decompiled_code:
int func24()
{
int result; // eax

result = func20();
if ( !result )
result = func22();
return result;
}

original_code:
int init_drives(void)
{
 int ret;
 ret = init_gpios();
 if (ret)
  return ret;
 return reset_floppy_positions();
}

canonical_original_code:
int init_drives()
{
 int ret;
 ret = init_gpios();
 if (ret)
  return ret;
 return reset_floppy_positions();
}


repo: comstud/mysqlsniffer

decompiled_code:
int __fastcall dump_pkt(unsigned __int8 *a1, int a2, char a3)
{
const unsigned __int16 **v4; // rbp
unsigned __int8 *v5; // rbx
__int64 v6; // r12
unsigned __int8 v7; // si

printf("::DUMP:: ");
if ( a2 )
{
v4 = _ctype_b_loc();
v5 = a1;
v6 = (__int64)&a1[a2 - 1 + 1];
do
{
v7 = *v5;
if ( ((*v4)[*v5] & 0x4000) == 0 || a3 )
printf("%02x ", v7);
else
printf("%c ", v7);
++v5;
}
while ( v5 != (unsigned __int8 *)v6 );
}
return printf("::DUMP::");
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, int a2, char a3)
{
const unsigned __int16 **v4; // rbp
unsigned __int8 *v5; // rbx
__int64 v6; // r12
unsigned __int8 v7; // si

printf("::DUMP:: ");
if ( a2 )
{
v4 = _ctype_b_loc();
v5 = a1;
v6 = (__int64)&a1[a2 - 1 + 1];
do
{
v7 = *v5;
if ( ((*v4)[*v5] & 0x4000) == 0 || a3 )
printf("%02x ", v7);
else
printf("%c ", v7);
++v5;
}
while ( v5 != (unsigned __int8 *)v6 );
}
return printf("::DUMP::");
}

original_code:
void dump_pkt(u_char *pkt, u_int len, char only_hex)
{
   int i;
   printf("::DUMP:: ");
   for(i = 0; i < len; i++) {
      if(((*__ctype_b_loc ())[(int) ((pkt[i]))] & (unsigned short int) _ISprint) && !only_hex) printf("%c ", pkt[i]);
      else printf("%02x ", pkt[i]);
   }
   printf("::DUMP::");
}

canonical_original_code:
void dump_pkt(unsigned char *pkt, unsigned int len, char only_hex)
{
   int i;
   printf("::DUMP:: ");
   for(i = 0; i < len; i++) {
      if(((*__ctype_b_loc ())[(int) ((pkt[i]))] & (unsigned short) _ISprint) && !only_hex) printf("%c ", pkt[i]);
      else printf("%02x ", pkt[i]);
   }
   printf("::DUMP::");
}

variable_types:
pkt
unsigned char *

variable_types:
len
unsigned int


decompiled_code:
char *__fastcall get_arg(__int64 a1, unsigned int a2)
{
size_t v2; // rbx

if ( a2 > 0x1000 )
a2 = 4096;
v2 = a2 - 1;
memcpy(arg_0, (const void *)(a1 + 1), v2);
arg_0[v2] = 0;
return arg_0;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, unsigned int a2)
{
size_t v2; // rbx

if ( a2 > 0x1000 )
a2 = 4096;
v2 = a2 - 1;
memcpy(arg_0, (const void *)(a1 + 1), v2);
arg_0[v2] = 0;
return arg_0;
}

original_code:
const u_char *get_arg(u_char *pkt, u_int len)
{
   static u_char arg[4096];
   if(len > 4096) len = 4096;
   pkt++;
   memcpy(arg, pkt, len - 1);
   arg[len - 1] = 0;
   return (const u_char *)arg;
}

canonical_original_code:
unsigned char *get_arg(unsigned char *pkt, unsigned int len)
{
   static unsigned char arg[4096];
   if(len > 4096) len = 4096;
   pkt++;
   memcpy(arg, pkt, len - 1);
   arg[len - 1] = 0;
   return (unsigned char *)arg;
}

variable_types:
arg
unsigned char [4096]

return_type: unsigned char *


decompiled_code:
unsigned __int8 *__fastcall my_strcpy(_QWORD *a1, unsigned __int8 *a2, int a3)
{
unsigned __int8 v3; // r8
unsigned __int8 *v4; // r9
unsigned int v5; // edx
unsigned __int8 *result; // rax

v3 = *a2;
if ( *a2 )
{
v4 = a2 + 1;
if ( a1 )
{
v5 = a3 - 1;
if ( v5 > *a2 )
v5 = *a2;
if ( v5 >= 8 )
{
*a1 = *(_QWORD *)(a2 + 1);
*(_QWORD *)((char *)a1 + v5 - 8) = *(_QWORD *)&v4[v5 - 8];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4 - ((unsigned __int8 *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v5 + (_DWORD)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)(a2 + 1);
*(_DWORD *)((char *)a1 + v5 - 4) = *(_DWORD *)&v4[v5 - 4];
}
else if ( v5 )
{
*(_BYTE *)a1 = a2[1];
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)a1 + v5 - 2) = *(_WORD *)&v4[v5 - 2];
}
*((_BYTE *)a1 + v5) = 0;
result = &v4[v3];
}
else
{
result = &v4[v3];
}
}
else
{
if ( a1 )
*(_BYTE *)a1 = 0;
result = a2 + 1;
}
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func2(_QWORD *a1, unsigned __int8 *a2, int a3)
{
unsigned __int8 v3; // r8
unsigned __int8 *v4; // r9
unsigned int v5; // edx
unsigned __int8 *result; // rax

v3 = *a2;
if ( *a2 )
{
v4 = a2 + 1;
if ( a1 )
{
v5 = a3 - 1;
if ( v5 > *a2 )
v5 = *a2;
if ( v5 >= 8 )
{
*a1 = *(_QWORD *)(a2 + 1);
*(_QWORD *)((char *)a1 + v5 - 8) = *(_QWORD *)&v4[v5 - 8];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4 - ((unsigned __int8 *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v5 + (_DWORD)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)(a2 + 1);
*(_DWORD *)((char *)a1 + v5 - 4) = *(_DWORD *)&v4[v5 - 4];
}
else if ( v5 )
{
*(_BYTE *)a1 = a2[1];
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)a1 + v5 - 2) = *(_WORD *)&v4[v5 - 2];
}
*((_BYTE *)a1 + v5) = 0;
result = &v4[v3];
}
else
{
result = &v4[v3];
}
}
else
{
if ( a1 )
*(_BYTE *)a1 = 0;
result = a2 + 1;
}
return result;
}

original_code:
u_char *my_strcpy(u_char *to, u_char *from, u_int to_size)
{
   u_int str_len, real_str_len;
   str_len = real_str_len = (u_int)*from;
   if(!str_len) {
      if(to) to[0] = 0;
      return (from + 1);
   }
   from++;
   if(!to)
      return (from + str_len);
   if(str_len > (to_size - 1)) str_len = to_size - 1;
   memcpy(to, from, str_len);
   to[str_len] = 0;
   return (from + real_str_len);
}

canonical_original_code:
unsigned char *my_strcpy(unsigned char *to, unsigned char *from, unsigned int to_size)
{
   unsigned int str_len; unsigned int real_str_len;
   str_len = real_str_len = (u_int)*from;
   if(!str_len) {
      if(to) to[0] = 0;
      return (from + 1);
   }
   from++;
   if(!to)
      return (from + str_len);
   if(str_len > (to_size - 1)) str_len = to_size - 1;
   memcpy(to, from, str_len);
   to[str_len] = 0;
   return (from + real_str_len);
}

variable_types:
to
unsigned char *

variable_types:
from
unsigned char *


decompiled_code:
__int64 __fastcall G3(__int64 a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

LOWORD(v2) = *(_WORD *)a1;
HIWORD(v2) = *(unsigned __int8 *)(a1 + 2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v2; // [rsp+0h] [rbp-4h]

LOWORD(v2) = *(_WORD *)a1;
HIWORD(v2) = *(unsigned __int8 *)(a1 + 2);
return v2;
}

original_code:
u_int G3(u_char *pkt)
{
   u_char buff[4];
   memcpy(buff, pkt, 3);
   buff[3] = 0;
   return *((u_int *)buff);
}

canonical_original_code:
unsigned int G3(unsigned char *pkt)
{
   unsigned char buff[4];
   memcpy(buff, pkt, 3);
   buff[3] = 0;
   return *((unsigned int *)buff);
}

variable_types:
buff
unsigned char [4]

return_type: unsigned int


original_code:
u_int convert_binary_number(u_char *number, u_short flags, u_int bytes, u_char *to)
{
   char sz[16];
   u_int len;
   long long ln = 0;
   int n = 0;
   if(bytes == 1) n = *number;
   else if(bytes == 2) n = *((u_short *)number);
   else if(bytes == 4) n = *((u_int *)number);
   else if(bytes == 8) { memcpy((void *)&ln, number, 8); }
   if(bytes != 8) {
      if(flags & 32)
         sprintf(sz, "%u", n);
      else
         sprintf(sz, "%d", n);
   }
   else {
      if(flags & 32)
         sprintf(sz, "%llu", ln);
      else
         sprintf(sz, "%lld", ln);
   }
   len = strlen(sz);
   to[0] = len;
   memcpy(to + 1, sz, len);
   return len + 1;
}

canonical_original_code:
unsigned int convert_binary_number(unsigned char *number, unsigned short flags, unsigned int bytes, unsigned char *to)
{
   char sz[16];
   unsigned int len;
   long long ln = 0;
   int n = 0;
   if(bytes == 1) n = *number;
   else if(bytes == 2) n = *((unsigned short *)number);
   else if(bytes == 4) n = *((unsigned int *)number);
   else if(bytes == 8) { memcpy((void *)&ln, number, 8); }
   if(bytes != 8) {
      if(flags & 32)
         sprintf(sz, "%u", n);
      else
         sprintf(sz, "%d", n);
   }
   else {
      if(flags & 32)
         sprintf(sz, "%llu", ln);
      else
         sprintf(sz, "%lld", ln);
   }
   len = strlen(sz);
   to[0] = len;
   memcpy(to + 1, sz, len);
   return len + 1;
}

variable_types:
number
unsigned char *

variable_types:
flags
unsigned short

variable_types:
bytes
unsigned int

variable_types:
sz
char [16]

variable_types:
ln
long long

variable_types: n int


decompiled_code:
__int64 __fastcall convert_binary_datetime(char *a1, __int64 a2)
{
char v3; // r14
size_t v5; // rax
size_t v6; // r12
__int64 v7; // rdx
unsigned __int64 v8; // rdi
__int64 v9; // rdx
char *v10; // r8
unsigned int v11; // edx
unsigned int v12; // edx
unsigned int v13; // ecx
unsigned int v15; // eax
_QWORD *v16; // rcx
unsigned __int64 v17; // rsi
char *v18; // rcx
unsigned int v19; // eax
unsigned int v20; // eax
unsigned int v21; // edx
__int64 v22; // rsi
unsigned __int64 v23; // rdi
__int64 v24; // rsi
unsigned int v25; // ecx
char s[8]; // [rsp+5h] [rbp-33h] BYREF

v3 = *a1;
if ( *a1 )
{
sprintf(s, "%04u-%02u-%02u", *(unsigned __int16 *)(a1 + 1), (unsigned __int8)a1[3], (unsigned __int8)a1[4]);
v5 = strlen(s);
v6 = v5;
*(_BYTE *)a2 = v5;
v7 = a2 + 1;
if ( (unsigned int)v5 >= 8 )
{
*(_QWORD *)(a2 + 1) = *(_QWORD *)s;
*(_QWORD *)(v7 + (unsigned int)v5 - 8) = *(_QWORD *)&s[(unsigned int)v5 - 8];
v8 = (a2 + 9) & 0xFFFFFFFFFFFFFFF8LL;
v9 = v7 - v8;
v10 = &s[-v9];
v11 = (v5 + v9) & 0xFFFFFFF8;
if ( v11 >= 8 )
{
v12 = v11 & 0xFFFFFFF8;
v13 = 0;
do
{
*(_QWORD *)(v8 + v13) = *(_QWORD *)&v10[v13];
v13 += 8;
}
while ( v13 < v12 );
}
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)(a2 + 1) = *(_DWORD *)s;
*(_DWORD *)(v7 + (unsigned int)v5 - 4) = *(_DWORD *)&s[(unsigned int)v5 - 4];
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)(a2 + 1) = s[0];
if ( (v5 & 2) != 0 )
*(_WORD *)(v7 + (unsigned int)v5 - 2) = *(_WORD *)&s[(unsigned int)v5 - 2];
}
if ( v3 == 7 )
{
sprintf(s, " %02u:%02u:%02u", (unsigned __int8)a1[5], (unsigned __int8)a1[6], (unsigned __int8)a1[7]);
*(_BYTE *)a2 += strlen(s);
v15 = strlen(s);
v16 = (_QWORD *)(a2 + v6 + 1);
if ( v15 >= 8 )
{
*v16 = *(_QWORD *)s;
*(_QWORD *)((char *)v16 + v15 - 8) = *(_QWORD *)&s[v15 - 8];
v17 = (a2 + v6 + 9) & 0xFFFFFFFFFFFFFFF8LL;
v18 = (char *)v16 - v17;
v19 = ((_DWORD)v18 + v15) & 0xFFFFFFF8;
if ( v19 >= 8 )
{
v20 = v19 & 0xFFFFFFF8;
v21 = 0;
do
{
*(_QWORD *)(v17 + v21) = *(_QWORD *)(s - v18 + v21);
v21 += 8;
}
while ( v21 < v20 );
}
}
else if ( (v15 & 4) != 0 )
{
*(_DWORD *)v16 = *(_DWORD *)s;
*(_DWORD *)((char *)v16 + v15 - 4) = *(_DWORD *)&s[v15 - 4];
}
else if ( v15 )
{
*(_BYTE *)v16 = s[0];
if ( (v15 & 2) != 0 )
*(_WORD *)((char *)v16 + v15 - 2) = *(_WORD *)&s[v15 - 2];
}
LODWORD(v5) = v6 + strlen(s);
}
}
else
{
sprintf(s, "%04u-%02u-%02u", 0LL, 0LL, 0LL);
LODWORD(v5) = strlen(s);
*(_BYTE *)a2 = v5;
v22 = a2 + 1;
if ( (unsigned int)v5 >= 8 )
{
*(_QWORD *)(a2 + 1) = *(_QWORD *)s;
*(_QWORD *)(v22 + (unsigned int)v5 - 8) = *(_QWORD *)&s[(unsigned int)v5 - 8];
v23 = (a2 + 9) & 0xFFFFFFFFFFFFFFF8LL;
v24 = v22 - v23;
if ( (((_DWORD)v24 + (_DWORD)v5) & 0xFFFFFFF8) >= 8 )
{
v25 = 0;
do
{
*(_QWORD *)(v23 + v25) = *(_QWORD *)&s[v25 - v24];
v25 += 8;
}
while ( v25 < (((_DWORD)v24 + (_DWORD)v5) & 0xFFFFFFF8) );
}
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)(a2 + 1) = *(_DWORD *)s;
*(_DWORD *)(v22 + (unsigned int)v5 - 4) = *(_DWORD *)&s[(unsigned int)v5 - 4];
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)(a2 + 1) = s[0];
if ( (v5 & 2) != 0 )
*(_WORD *)(v22 + (unsigned int)v5 - 2) = *(_WORD *)&s[(unsigned int)v5 - 2];
}
}
return (unsigned __int16)(v5 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2)
{
char v3; // r14
size_t v5; // rax
size_t v6; // r12
__int64 v7; // rdx
unsigned __int64 v8; // rdi
__int64 v9; // rdx
char *v10; // r8
unsigned int v11; // edx
unsigned int v12; // edx
unsigned int v13; // ecx
unsigned int v15; // eax
_QWORD *v16; // rcx
unsigned __int64 v17; // rsi
char *v18; // rcx
unsigned int v19; // eax
unsigned int v20; // eax
unsigned int v21; // edx
__int64 v22; // rsi
unsigned __int64 v23; // rdi
__int64 v24; // rsi
unsigned int v25; // ecx
char s[8]; // [rsp+5h] [rbp-33h] BYREF

v3 = *a1;
if ( *a1 )
{
sprintf(s, "%04u-%02u-%02u", *(unsigned __int16 *)(a1 + 1), (unsigned __int8)a1[3], (unsigned __int8)a1[4]);
v5 = strlen(s);
v6 = v5;
*(_BYTE *)a2 = v5;
v7 = a2 + 1;
if ( (unsigned int)v5 >= 8 )
{
*(_QWORD *)(a2 + 1) = *(_QWORD *)s;
*(_QWORD *)(v7 + (unsigned int)v5 - 8) = *(_QWORD *)&s[(unsigned int)v5 - 8];
v8 = (a2 + 9) & 0xFFFFFFFFFFFFFFF8LL;
v9 = v7 - v8;
v10 = &s[-v9];
v11 = (v5 + v9) & 0xFFFFFFF8;
if ( v11 >= 8 )
{
v12 = v11 & 0xFFFFFFF8;
v13 = 0;
do
{
*(_QWORD *)(v8 + v13) = *(_QWORD *)&v10[v13];
v13 += 8;
}
while ( v13 < v12 );
}
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)(a2 + 1) = *(_DWORD *)s;
*(_DWORD *)(v7 + (unsigned int)v5 - 4) = *(_DWORD *)&s[(unsigned int)v5 - 4];
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)(a2 + 1) = s[0];
if ( (v5 & 2) != 0 )
*(_WORD *)(v7 + (unsigned int)v5 - 2) = *(_WORD *)&s[(unsigned int)v5 - 2];
}
if ( v3 == 7 )
{
sprintf(s, " %02u:%02u:%02u", (unsigned __int8)a1[5], (unsigned __int8)a1[6], (unsigned __int8)a1[7]);
*(_BYTE *)a2 += strlen(s);
v15 = strlen(s);
v16 = (_QWORD *)(a2 + v6 + 1);
if ( v15 >= 8 )
{
*v16 = *(_QWORD *)s;
*(_QWORD *)((char *)v16 + v15 - 8) = *(_QWORD *)&s[v15 - 8];
v17 = (a2 + v6 + 9) & 0xFFFFFFFFFFFFFFF8LL;
v18 = (char *)v16 - v17;
v19 = ((_DWORD)v18 + v15) & 0xFFFFFFF8;
if ( v19 >= 8 )
{
v20 = v19 & 0xFFFFFFF8;
v21 = 0;
do
{
*(_QWORD *)(v17 + v21) = *(_QWORD *)(s - v18 + v21);
v21 += 8;
}
while ( v21 < v20 );
}
}
else if ( (v15 & 4) != 0 )
{
*(_DWORD *)v16 = *(_DWORD *)s;
*(_DWORD *)((char *)v16 + v15 - 4) = *(_DWORD *)&s[v15 - 4];
}
else if ( v15 )
{
*(_BYTE *)v16 = s[0];
if ( (v15 & 2) != 0 )
*(_WORD *)((char *)v16 + v15 - 2) = *(_WORD *)&s[v15 - 2];
}
LODWORD(v5) = v6 + strlen(s);
}
}
else
{
sprintf(s, "%04u-%02u-%02u", 0LL, 0LL, 0LL);
LODWORD(v5) = strlen(s);
*(_BYTE *)a2 = v5;
v22 = a2 + 1;
if ( (unsigned int)v5 >= 8 )
{
*(_QWORD *)(a2 + 1) = *(_QWORD *)s;
*(_QWORD *)(v22 + (unsigned int)v5 - 8) = *(_QWORD *)&s[(unsigned int)v5 - 8];
v23 = (a2 + 9) & 0xFFFFFFFFFFFFFFF8LL;
v24 = v22 - v23;
if ( (((_DWORD)v24 + (_DWORD)v5) & 0xFFFFFFF8) >= 8 )
{
v25 = 0;
do
{
*(_QWORD *)(v23 + v25) = *(_QWORD *)&s[v25 - v24];
v25 += 8;
}
while ( v25 < (((_DWORD)v24 + (_DWORD)v5) & 0xFFFFFFF8) );
}
}
else if ( (v5 & 4) != 0 )
{
*(_DWORD *)(a2 + 1) = *(_DWORD *)s;
*(_DWORD *)(v22 + (unsigned int)v5 - 4) = *(_DWORD *)&s[(unsigned int)v5 - 4];
}
else if ( (_DWORD)v5 )
{
*(_BYTE *)(a2 + 1) = s[0];
if ( (v5 & 2) != 0 )
*(_WORD *)(v22 + (unsigned int)v5 - 2) = *(_WORD *)&s[(unsigned int)v5 - 2];
}
}
return (unsigned __int16)(v5 + 1);
}

original_code:
u_int convert_binary_datetime(u_char *d, u_char *to)
{
   u_char dt_len = *d;
   u_short year = 0;
   u_char month = 0;
   u_char day = 0;
   u_char hour = 0;
   u_char min = 0;
   u_char sec = 0;
   char sz[11];
   u_short len;
   if(dt_len) {
      d++;
      year = *((u_short *)d);
      d += 2;
      month = *d++;
      day = *d++;
   }
   sprintf(sz, "%04u-%02u-%02u", year, month, day);
   to[0] = len = strlen(sz);
   memcpy(to + 1, sz, len);
   if(dt_len == 7) {
      hour = *d++;
      min = *d++;
      sec = *d++;
      sprintf(sz, " %02u:%02u:%02u", hour, min, sec);
      to[0] = to[0] + strlen(sz);
      memcpy(to + 1 + len, sz, strlen(sz));
      len += strlen(sz);
   }
   return len + 1;
}

canonical_original_code:
unsigned int convert_binary_datetime(unsigned char *d, unsigned char *to)
{
   unsigned char dt_len = *d;
   unsigned short year = 0;
   unsigned char month = 0;
   unsigned char day = 0;
   unsigned char hour = 0;
   unsigned char min = 0;
   unsigned char sec = 0;
   char sz[11];
   unsigned short len;
   if(dt_len) {
      d++;
      year = *((unsigned short *)d);
      d += 2;
      month = *d++;
      day = *d++;
   }
   sprintf(sz, "%04u-%02u-%02u", year, month, day);
   to[0] = len = strlen(sz);
   memcpy(to + 1, sz, len);
   if(dt_len == 7) {
      hour = *d++;
      min = *d++;
      sec = *d++;
      sprintf(sz, " %02u:%02u:%02u", hour, min, sec);
      to[0] = to[0] + strlen(sz);
      memcpy(to + 1 + len, sz, strlen(sz));
      len += strlen(sz);
   }
   return len + 1;
}

variable_types:
d
unsigned char *

variable_types:
year
unsigned short

variable_types:
month
unsigned char

variable_types:
day
unsigned char

variable_types:
hour
unsigned char

variable_types:
min
unsigned char

variable_types:
sec
unsigned char

variable_types:
sz
char [11]

variable_types:
len
unsigned short


original_code:
u_int convert_binary_time(u_char *t, u_char *to)
{
   u_char sign = 0;
   u_short days = 0;
   u_short hours = 0;
   u_short mins = 0;
   u_short secs = 0;
   char sz[11];
   u_short len;
   if(*t) {
      t++;
      sign = *t++;
      days = *((u_int *)t);
      t += 4;
      hours = *t++;
      mins = *t++;
      secs = *t++;
   }
   if(days)
      hours += (days * 24);
   sprintf(sz, "%s%02u:%02u:%02u", (sign ? "-" : ""), hours, mins, secs);
   to[0] = len = strlen(sz);
   memcpy(to + 1, sz, len);
   return len + 1;
}

canonical_original_code:
unsigned int convert_binary_time(unsigned char *t, unsigned char *to)
{
   unsigned char sign = 0;
   unsigned short days = 0;
   unsigned short hours = 0;
   unsigned short mins = 0;
   unsigned short secs = 0;
   char sz[11];
   unsigned short len;
   if(*t) {
      t++;
      sign = *t++;
      days = *((unsigned int *)t);
      t += 4;
      hours = *t++;
      mins = *t++;
      secs = *t++;
   }
   if(days)
      hours += (days * 24);
   sprintf(sz, "%s%02u:%02u:%02u", (sign ? "-" : ""), hours, mins, secs);
   to[0] = len = strlen(sz);
   memcpy(to + 1, sz, len);
   return len + 1;
}

variable_types:
t
unsigned char *

variable_types:
to
unsigned char *

variable_types:
sign
unsigned char

variable_types:
days
unsigned short

variable_types:
hours
unsigned short

variable_types:
mins
unsigned short

variable_types:
secs
unsigned short


decompiled_code:
__int64 __fastcall decode_len(char *a1)
{
unsigned __int8 v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( (unsigned __int8)*a1 <= 0xFBu )
{
decoded_len = v1;
v2 = 1;
}
else if ( v1 == 0xFC )
{
decoded_len = *((unsigned __int16 *)a1 + 1);
v2 = 2;
}
else if ( v1 == 0xFD )
{
decoded_len = *((unsigned int *)a1 + 1);
v2 = 4;
}
else
{
v2 = 0;
if ( v1 == 0xFE )
{
decoded_len = *(_QWORD *)(a1 + 1);
v2 = 8;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
unsigned __int8 v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( (unsigned __int8)*a1 <= 0xFBu )
{
decoded_len = v1;
v2 = 1;
}
else if ( v1 == 0xFC )
{
decoded_len = *((unsigned __int16 *)a1 + 1);
v2 = 2;
}
else if ( v1 == 0xFD )
{
decoded_len = *((unsigned int *)a1 + 1);
v2 = 4;
}
else
{
v2 = 0;
if ( v1 == 0xFE )
{
decoded_len = *(_QWORD *)(a1 + 1);
v2 = 8;
}
}
return v2;
}

original_code:
u_short decode_len(u_char *pkt)
{
   if(*pkt <= 0xFB) { decoded_len = *pkt; return 1; }
   if(*pkt == 0xFC) { decoded_len = *((u_short *)pkt + 1); return 2; }
   if(*pkt == 0xFD) { decoded_len = *((u_int *)pkt + 1); return 4; }
   if(*pkt == 0xFE) { memcpy((void *)&decoded_len, pkt + 1, 8); return 8; }
   return 0;
}

canonical_original_code:
unsigned short decode_len(unsigned char *pkt)
{
   if(*pkt <= 0xFB) { decoded_len = *pkt; return 1; }
   if(*pkt == 0xFC) { decoded_len = *((unsigned short *)pkt + 1); return 2; }
   if(*pkt == 0xFD) { decoded_len = *((unsigned int *)pkt + 1); return 4; }
   if(*pkt == 0xFE) { memcpy((void *)&decoded_len, pkt + 1, 8); return 8; }
   return 0;
}

variable_types:
pkt
unsigned char *

return_type: unsigned short


decompiled_code:
const char *__fastcall get_field_type(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 <= 0xF5u )
return field_type_names[a1];
switch ( a1 )
{
case 0xF6:
result = "new decimal";
break;
case 0xF7:
result = "enum";
break;
case 0xF8:
result = "set";
break;
case 0xF9:
result = "tiny BLOB";
break;
case 0xFA:
result = "medium BLOB";
break;
case 0xFB:
result = "long BLOB";
break;
case 0xFC:
result = "BLOB";
break;
case 0xFD:
result = "var string";
break;
case 0xFE:
result = "string";
break;
case 0xFF:
result = "geometry";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(unsigned __int8 a1)
{
const char *result; // rax

if ( a1 <= 0xF5u )
return field_type_names[a1];
switch ( a1 )
{
case 0xF6:
result = "new decimal";
break;
case 0xF7:
result = "enum";
break;
case 0xF8:
result = "set";
break;
case 0xF9:
result = "tiny BLOB";
break;
case 0xFA:
result = "medium BLOB";
break;
case 0xFB:
result = "long BLOB";
break;
case 0xFC:
result = "BLOB";
break;
case 0xFD:
result = "var string";
break;
case 0xFE:
result = "string";
break;
case 0xFF:
result = "geometry";
break;
}
return result;
}

original_code:
const char *get_field_type(u_char type)
{
   if(type < 246)
      return field_type_names[type];
   switch(type) {
      case MYSQL_TYPE_NEWDECIMAL: return "new decimal";
      case MYSQL_TYPE_ENUM: return "enum";
      case MYSQL_TYPE_SET: return "set";
      case MYSQL_TYPE_TINY_BLOB: return "tiny BLOB";
      case MYSQL_TYPE_MEDIUM_BLOB: return "medium BLOB";
      case MYSQL_TYPE_LONG_BLOB: return "long BLOB";
      case MYSQL_TYPE_BLOB: return "BLOB";
      case MYSQL_TYPE_VAR_STRING: return "var string";
      case MYSQL_TYPE_STRING: return "string";
      case MYSQL_TYPE_GEOMETRY: return "geometry";
   }
   return "unknown";
}

canonical_original_code:
char *get_field_type(unsigned char type)
{
   if(type < 246)
      return field_type_names[type];
   switch(type) {
      case MYSQL_TYPE_NEWDECIMAL: return "new decimal";
      case MYSQL_TYPE_ENUM: return "enum";
      case MYSQL_TYPE_SET: return "set";
      case MYSQL_TYPE_TINY_BLOB: return "tiny BLOB";
      case MYSQL_TYPE_MEDIUM_BLOB: return "medium BLOB";
      case MYSQL_TYPE_LONG_BLOB: return "long BLOB";
      case MYSQL_TYPE_BLOB: return "BLOB";
      case MYSQL_TYPE_VAR_STRING: return "var string";
      case MYSQL_TYPE_STRING: return "string";
      case MYSQL_TYPE_GEOMETRY: return "geometry";
   }
   return "unknown";
}

variable_types:
type
unsigned char


decompiled_code:
int __fastcall unmask_caps(int a1)
{
printf("(Caps: ");
if ( (a1 & 1) != 0 )
printf("Long password, ");
if ( (a1 & 2) != 0 )
printf("Found rows, ");
if ( (a1 & 4) != 0 )
printf("Get all column flags, ");
if ( (a1 & 8) != 0 )
printf("Connect w/DB, ");
if ( (a1 & 0x10) != 0 )
printf("No schema, ");
if ( (a1 & 0x20) != 0 )
printf("Compression, ");
if ( (a1 & 0x40) != 0 )
printf("ODBC client, ");
if ( (a1 & 0x80u) != 0 )
printf("LOAD DATA LOCAL, ");
if ( (a1 & 0x100) != 0 )
printf("Ignore space, ");
if ( (a1 & 0x200) != 0 )
printf("4.1 protocol, ");
if ( (a1 & 0x400) != 0 )
printf("Interactive, ");
if ( (a1 & 0x800) != 0 )
printf("SSL, ");
if ( (a1 & 0x1000) != 0 )
printf("Ignore SIGPIPE, ");
if ( (a1 & 0x2000) != 0 )
printf("Transactions, ");
if ( (a1 & 0x4000) != 0 )
printf("Reserved, ");
if ( (a1 & 0x8000) != 0 )
printf("4.1 authentication, ");
if ( (a1 & 0x10000) != 0 )
printf("Multi-statements, ");
if ( (a1 & 0x20000) != 0 )
printf("Multi-results");
return putchar(41);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
printf("(Caps: ");
if ( (a1 & 1) != 0 )
printf("Long password, ");
if ( (a1 & 2) != 0 )
printf("Found rows, ");
if ( (a1 & 4) != 0 )
printf("Get all column flags, ");
if ( (a1 & 8) != 0 )
printf("Connect w/DB, ");
if ( (a1 & 0x10) != 0 )
printf("No schema, ");
if ( (a1 & 0x20) != 0 )
printf("Compression, ");
if ( (a1 & 0x40) != 0 )
printf("ODBC client, ");
if ( (a1 & 0x80u) != 0 )
printf("LOAD DATA LOCAL, ");
if ( (a1 & 0x100) != 0 )
printf("Ignore space, ");
if ( (a1 & 0x200) != 0 )
printf("4.1 protocol, ");
if ( (a1 & 0x400) != 0 )
printf("Interactive, ");
if ( (a1 & 0x800) != 0 )
printf("SSL, ");
if ( (a1 & 0x1000) != 0 )
printf("Ignore SIGPIPE, ");
if ( (a1 & 0x2000) != 0 )
printf("Transactions, ");
if ( (a1 & 0x4000) != 0 )
printf("Reserved, ");
if ( (a1 & 0x8000) != 0 )
printf("4.1 authentication, ");
if ( (a1 & 0x10000) != 0 )
printf("Multi-statements, ");
if ( (a1 & 0x20000) != 0 )
printf("Multi-results");
return putchar(41);
}

original_code:
void unmask_caps(u_int caps)
{
   printf("(Caps: ");
   if(caps & 1) printf("Long password, ");
   if(caps & 2) printf("Found rows, ");
   if(caps & 4) printf("Get all column flags, ");
   if(caps & 8) printf("Connect w/DB, ");
   if(caps & 16) printf("No schema, ");
   if(caps & 32) printf("Compression, ");
   if(caps & 64) printf("ODBC client, ");
   if(caps & 128) printf("LOAD DATA LOCAL, ");
   if(caps & 256) printf("Ignore space, ");
   if(caps & 512) printf("4.1 protocol, ");
   if(caps & 1024) printf("Interactive, ");
   if(caps & 2048) printf("SSL, ");
   if(caps & 4096) printf("Ignore SIGPIPE, ");
   if(caps & 8192) printf("Transactions, ");
   if(caps & 16384) printf("Reserved, ");
   if(caps & 32768) printf("4.1 authentication, ");
   if(caps & 65536) printf("Multi-statements, ");
   if(caps & 131072) printf("Multi-results");
   printf(")");
}

canonical_original_code:
void unmask_caps(unsigned int caps)
{
   printf("(Caps: ");
   if(caps & 1) printf("Long password, ");
   if(caps & 2) printf("Found rows, ");
   if(caps & 4) printf("Get all column flags, ");
   if(caps & 8) printf("Connect w/DB, ");
   if(caps & 16) printf("No schema, ");
   if(caps & 32) printf("Compression, ");
   if(caps & 64) printf("ODBC client, ");
   if(caps & 128) printf("LOAD DATA LOCAL, ");
   if(caps & 256) printf("Ignore space, ");
   if(caps & 512) printf("4.1 protocol, ");
   if(caps & 1024) printf("Interactive, ");
   if(caps & 2048) printf("SSL, ");
   if(caps & 4096) printf("Ignore SIGPIPE, ");
   if(caps & 8192) printf("Transactions, ");
   if(caps & 16384) printf("Reserved, ");
   if(caps & 32768) printf("4.1 authentication, ");
   if(caps & 65536) printf("Multi-statements, ");
   if(caps & 131072) printf("Multi-results");
   printf(")");
}

variable_types:
caps
unsigned int


decompiled_code:
int __fastcall unmask_status(__int16 a1)
{
printf("(Status: ");
if ( (a1 & 1) != 0 )
printf("Transaction started, ");
if ( (a1 & 2) != 0 )
printf("Auto-commit, ");
if ( (a1 & 4) != 0 )
printf("More results, ");
if ( (a1 & 8) != 0 )
printf("Next query, ");
if ( (a1 & 0x10) != 0 )
printf("No good index used, ");
if ( (a1 & 0x20) != 0 )
printf("No index used, ");
if ( (a1 & 0x40) != 0 )
printf("Cursor ready, ");
if ( (a1 & 0x80u) != 0 )
printf("Last row sent, ");
if ( (a1 & 0x100) != 0 )
printf("DB dropped, ");
if ( (a1 & 0x200) != 0 )
printf("No backslash escapes");
return putchar(41);
}

canonical_decompiled_code:
int __fastcall func10(__int16 a1)
{
printf("(Status: ");
if ( (a1 & 1) != 0 )
printf("Transaction started, ");
if ( (a1 & 2) != 0 )
printf("Auto-commit, ");
if ( (a1 & 4) != 0 )
printf("More results, ");
if ( (a1 & 8) != 0 )
printf("Next query, ");
if ( (a1 & 0x10) != 0 )
printf("No good index used, ");
if ( (a1 & 0x20) != 0 )
printf("No index used, ");
if ( (a1 & 0x40) != 0 )
printf("Cursor ready, ");
if ( (a1 & 0x80u) != 0 )
printf("Last row sent, ");
if ( (a1 & 0x100) != 0 )
printf("DB dropped, ");
if ( (a1 & 0x200) != 0 )
printf("No backslash escapes");
return putchar(41);
}

original_code:
void unmask_status(u_short status)
{
   printf("(Status: ");
   if(status & 1) printf("Transaction started, ");
   if(status & 2) printf("Auto-commit, ");
   if(status & 4) printf("More results, ");
   if(status & 8) printf("Next query, ");
   if(status & 16) printf("No good index used, ");
   if(status & 32) printf("No index used, ");
   if(status & 64) printf("Cursor ready, ");
   if(status & 128) printf("Last row sent, ");
   if(status & 256) printf("DB dropped, ");
   if(status & 512) printf("No backslash escapes");
   printf(")");
}

canonical_original_code:
void unmask_status(unsigned short status)
{
   printf("(Status: ");
   if(status & 1) printf("Transaction started, ");
   if(status & 2) printf("Auto-commit, ");
   if(status & 4) printf("More results, ");
   if(status & 8) printf("Next query, ");
   if(status & 16) printf("No good index used, ");
   if(status & 32) printf("No index used, ");
   if(status & 64) printf("Cursor ready, ");
   if(status & 128) printf("Last row sent, ");
   if(status & 256) printf("DB dropped, ");
   if(status & 512) printf("No backslash escapes");
   printf(")");
}

variable_types:
status
unsigned short


repo: concurrency/kroc

decompiled_code:
__int64 __fastcall get_pixel(_DWORD *a1, int a2, int a3)
{
return *((unsigned __int8 *)a1 + a2 + *a1 * a3 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, int a2, int a3)
{
return *((unsigned __int8 *)a1 + a2 + *a1 * a3 + 16);
}

original_code:
static inline unsigned int get_pixel (image_t *img, int x, int y)
{
 return (unsigned int) img->data[(img->width * y) + x];
}

canonical_original_code:
static inline unsigned int get_pixel(struct _image_t *img, int x, int y)
{
 return (unsigned int) img->data[(img->width * y) + x];
}

variable_types: struct _image_t { int width; int height; struct _image_t *next; unsigned char data[1]; } *

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall set_pixel(_DWORD *a1, int a2, int a3, unsigned int a4)
{
__int64 result; // rax

result = 255LL;
if ( a4 >= 0xFF )
LOBYTE(a4) = -1;
*((_BYTE *)a1 + a2 + *a1 * a3 + 16) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, int a2, int a3, unsigned int a4)
{
__int64 result; // rax

result = 255LL;
if ( a4 >= 0xFF )
LOBYTE(a4) = -1;
*((_BYTE *)a1 + a2 + *a1 * a3 + 16) = a4;
return result;
}

original_code:
static inline void set_pixel (image_t *img, int x, int y, unsigned int v)
{
 img->data[(img->width * y) + x] = (unsigned char) (v < 255 ? v : 255);
}

canonical_original_code:
static inline void set_pixel(struct _image_t *img, int x, int y, unsigned int v)
{
 img->data[(img->width * y) + x] = (unsigned char) (v < 255 ? v : 255);
}

variable_types:
v
unsigned int

user_defined_types: struct _image_t { int width; int height; struct _image_t *next; unsigned char data[1]; }


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

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

original_code:
static void image_free (image_t *img)
{
 free (img);
}

canonical_original_code:
static void image_free(struct _image_t *img)
{
 free (img);
}


element

decompiled_code:
void *__fastcall element(void *a1)
{
int *v1; // rbx
int *v2; // rbp

while ( 1 )
{
pthread_mutex_lock(&lock);
while ( !complete )
{
if ( next_image )
break;
pthread_cond_signal(&want_work);
pthread_cond_wait(&work_available, &lock);
}
v1 = (int *)next_image;
if ( !next_image )
break;
next_image = *(_QWORD *)(next_image + 8);
pthread_mutex_unlock(&lock);
v2 = image_alloc(*v1, v1[1]);
blur_image(9, v1, v2);
image_free(v1);
image_free(v2);
}
--workers;
pthread_cond_signal(&worker_terminated);
pthread_mutex_unlock(&lock);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func12(void *a1)
{
int *v1; // rbx
int *v2; // rbp

while ( 1 )
{
pthread_mutex_lock(&lock);
while ( !complete )
{
if ( next_image )
break;
pthread_cond_signal(&want_work);
pthread_cond_wait(&work_available, &lock);
}
v1 = (int *)next_image;
if ( !next_image )
break;
next_image = *(_QWORD *)(next_image + 8);
pthread_mutex_unlock(&lock);
v2 = image_alloc(*v1, v1[1]);
func10(9, v1, v2);
func11(v1);
func11(v2);
}
--workers;
pthread_cond_signal(&worker_terminated);
pthread_mutex_unlock(&lock);
return 0LL;
}

original_code:
static void *element (void *p)
{
 for (;;) {
  image_t *img = ((void *)0);
  pthread_mutex_lock (&lock);
  while (!complete && next_image == ((void *)0)) {
   pthread_cond_signal (&want_work);
   pthread_cond_wait (&work_available, &lock);
  }
  img = next_image;
  if (img == ((void *)0)) {
   break;
  } else {
   next_image = img->next;
  }
  pthread_mutex_unlock (&lock);
  {
   image_t *buf = image_alloc (img->width, img->height);
   blur_image (9, img, buf);
   image_free (img);
   image_free (buf);
  }
 }
 workers--;
 pthread_cond_signal (&worker_terminated);
 pthread_mutex_unlock (&lock);
 return ((void *)0);
}

canonical_original_code:
static void *element(void *p)
{
 for (;;) {
  struct _image_t *img = ((void *)0);
  pthread_mutex_lock (&lock);
  while (!complete && next_image == ((void *)0)) {
   pthread_cond_signal (&want_work);
   pthread_cond_wait (&work_available, &lock);
  }
  img = next_image;
  if (img == ((void *)0)) {
   break;
  } else {
   next_image = img->next;
  }
  pthread_mutex_unlock (&lock);
  {
   struct _image_t *buf = image_alloc (img->width, img->height);
   blur_image (9, img, buf);
   image_free (img);
   image_free (buf);
  }
 }
 workers--;
 pthread_cond_signal (&worker_terminated);
 pthread_mutex_unlock (&lock);
 return ((void *)0);
}

variable_types:
p
void *

return_type: void *


decompiled_code:
int __fastcall proc_main(int a1, int a2, int a3)
{
int i; // ebx
pthread_t newthread[6]; // [rsp+8h] [rbp-30h] BYREF

pthread_mutex_init(&lock, 0LL);
pthread_cond_init(&want_work, 0LL);
pthread_cond_init(&work_available, 0LL);
pthread_cond_init(&worker_terminated, 0LL);
workers = a2;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
pthread_create(newthread, 0LL, element, 0LL);
}
return server(a1, (unsigned int)a2, a3);
}

canonical_decompiled_code:
int __fastcall func14(int a1, int a2, int a3)
{
int i; // ebx
pthread_t newthread[6]; // [rsp+8h] [rbp-30h] BYREF

pthread_mutex_init(&lock, 0LL);
pthread_cond_init(&want_work, 0LL);
pthread_cond_init(&work_available, 0LL);
pthread_cond_init(&worker_terminated, 0LL);
workers = a2;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
pthread_create(newthread, 0LL, element, 0LL);
}
return func13(a1, (unsigned int)a2, a3);
}

original_code:
static void proc_main (int frames, int elements, int queuing)
{
 int i;
 pthread_mutex_init (&lock, ((void *)0));
 pthread_cond_init (&want_work, ((void *)0));
 pthread_cond_init (&work_available, ((void *)0));
 pthread_cond_init (&worker_terminated, ((void *)0));
 workers = elements;
 for (i = 0; i < elements; ++i) {
  pthread_t thread;
  pthread_create (&thread, ((void *)0), element, ((void *)0));
 }
 server (frames, elements, queuing);
}

canonical_original_code:
static void proc_main(int frames, int elements, int queuing)
{
 int i;
 pthread_mutex_init (&lock, ((void *)0));
 pthread_cond_init (&want_work, ((void *)0));
 pthread_cond_init (&work_available, ((void *)0));
 pthread_cond_init (&worker_terminated, ((void *)0));
 workers = elements;
 for (i = 0; i < elements; ++i) {
  unsigned long thread;
  pthread_create (&thread, ((void *)0), element, ((void *)0));
 }
 server (frames, elements, queuing);
}

variable_types: frames int

variable_types: elements int

variable_types: queuing int

variable_types: i int

variable_types:
thread
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
int v5; // edx

v3 = 64;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = 1;
if ( argc > 2 )
v4 = atoi(argv[2]);
v5 = 0;
if ( argc > 3 )
v5 = atoi(argv[3]);
proc_main(v3, v4, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
int v5; // edx

v3 = 64;
if ( argc > 1 )
v3 = atoi(argv[1]);
v4 = 1;
if ( argc > 2 )
v4 = atoi(argv[2]);
v5 = 0;
if ( argc > 3 )
v5 = atoi(argv[3]);
func14(v3, v4, v5);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 int elements = 1;
 int frames = 64;
 int queuing = 0;
 if (argc >= 2)
  frames = atoi (argv[1]);
 if (argc >= 3)
  elements = atoi (argv[2]);
 if (argc >= 4)
  queuing = atoi (argv[3]);
 proc_main (frames, elements, queuing);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int elements = 1;
 int frames = 64;
 int queuing = 0;
 if (argc >= 2)
  frames = atoi (argv[1]);
 if (argc >= 3)
  elements = atoi (argv[2]);
 if (argc >= 4)
  queuing = atoi (argv[3]);
 proc_main (frames, elements, queuing);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: conformal/adsuck

decompiled_code:
void __fastcall log_init(int a1)
{
logdebug = a1;
if ( !a1 )
openlog(_progname, 9, 24);
tzset();
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
logdebug = a1;
if ( !a1 )
openlog(_progname, 9, 24);
tzset();
}

original_code:
void
log_init(int n_debug)
{
 extern char *__progname;
 logdebug = n_debug;
 if (!logdebug)
  openlog(__progname, 0x01 | 0x08, (3<<3));
 tzset();
}


vlog

decompiled_code:
void __fastcall vlog(int a1, const char *a2, void *a3)
{
char *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( logdebug )
{
if ( asprintf(&ptr, "%s\n", a2) == -1 )
{
vfprintf(stderr, a2, a3);
fputc(10, stderr);
}
else
{
vfprintf(stderr, ptr, a3);
free(ptr);
}
fflush(stderr);
}
else
{
vsyslog(a1, a2, a3);
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, const char *a2, void *a3)
{
char *ptr; // [rsp+8h] [rbp-20h] BYREF

if ( logdebug )
{
if ( asprintf(&ptr, "%s\n", a2) == -1 )
{
vfprintf(stderr, a2, a3);
fputc(10, stderr);
}
else
{
vfprintf(stderr, ptr, a3);
free(ptr);
}
fflush(stderr);
}
else
{
vsyslog(a1, a2, a3);
}
}

original_code:
void
vlog(int pri, const char *fmt, va_list ap)
{
 char *nfmt;
 if (logdebug) {
  if (asprintf(&nfmt, "%s\n", fmt) == -1) {
   vfprintf(stderr, fmt, ap);
   fprintf(stderr, "\n");
  } else {
   vfprintf(stderr, nfmt, ap);
   free(nfmt);
  }
  fflush(stderr);
 } else
  vsyslog(pri, fmt, ap);
}

canonical_original_code:
void vlog(int pri, char *fmt, __builtin_va_list ap)
{
 char *nfmt;
 if (logdebug) {
  if (asprintf(&nfmt, "%s\n", fmt) == -1) {
   vfprintf(stderr, fmt, ap);
   fprintf(stderr, "\n");
  } else {
   vfprintf(stderr, nfmt, ap);
   free(nfmt);
  }
  fflush(stderr);
 } else
  vsyslog(pri, fmt, ap);
}

variable_types: pri int

variable_types:
fmt
char *

variable_types:
nfmt
char *


logit

decompiled_code:
void logit(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
vlog(a1, a2, va);
}

canonical_decompiled_code:
void func2(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func1(a1, a2, va);
}

original_code:
void
logit(int pri, const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vlog(pri, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void logit(int pri, char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vlog(pri, fmt, ap);
 __builtin_va_end(ap);
}