createNewWord

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

result = malloc(0x30uLL);
result[1] = 0LL;
result[2] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
*(_DWORD *)result = 0;
*((_DWORD *)result + 6) = 0;
return result;
}

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

result = malloc(0x30uLL);
result[1] = 0LL;
result[2] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
*(_DWORD *)result = 0;
*((_DWORD *)result + 6) = 0;
return result;
}

original_code:
Word* createNewWord(){
 Word *w = malloc(sizeof(Word));
 w->begin = ((void *)0);
 w->end = ((void *)0);
 w->next = ((void *)0);
 w->previous = ((void *)0);
 w->type = EMPTY;
 w->count = 0;
 return w;
}

canonical_original_code:
struct _Word *createNewWord(){
 struct _Word *w = malloc(sizeof(Word));
 w->begin = ((void *)0);
 w->end = ((void *)0);
 w->next = ((void *)0);
 w->previous = ((void *)0);
 w->type = EMPTY;
 w->count = 0;
 return w;
}

variable_types: struct _Word { int type; struct _Element { char c; char isSelected; struct _Element *next; struct _Element *previous; struct _Word *father; } *begin; struct _Element *end; int count; struct _Word *next; struct _Word *previous; } *

user_defined_types: struct _Word { int type; struct _Element *begin; struct _Element *end; int count; struct _Word *next; struct _Word *previous; }


isEmptyWord

repo: lxdfigo/shedit

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

if ( !a1 )
return 1LL;
if ( *(int *)(a1 + 24) <= 0 || (result = 0LL, *(_QWORD *)(a1 + 8) == *(_QWORD *)(a1 + 16)) )
{
*(_DWORD *)a1 = 0;
result = 1LL;
}
return result;
}

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

if ( !a1 )
return 1LL;
if ( *(int *)(a1 + 24) <= 0 || (result = 0LL, *(_QWORD *)(a1 + 8) == *(_QWORD *)(a1 + 16)) )
{
*(_DWORD *)a1 = 0;
result = 1LL;
}
return result;
}

original_code:
char isEmptyWord(Word *word){
 if (word == ((void *)0)) return 1;
 if (word->count <= 0 || word->begin == word->end) {
  word->type = EMPTY;
  return 1;
 }
 return 0;
}

canonical_original_code:
char isEmptyWord(struct _Word *word){
 if (word == ((void *)0)) return 1;
 if (word->count <= 0 || word->begin == word->end) {
  word->type = EMPTY;
  return 1;
 }
 return 0;
}

return_type: char

user_defined_types: struct _Element { char c; char isSelected; struct _Element *next; struct _Element *previous; struct _Word *father; }


replaceWord

original_code:
char replaceWord(Word *word,Word *headWord,Word * endWord){
 if (word == ((void *)0) || headWord == ((void *)0) || endWord == ((void *)0)) return 0;
 if (word->previous != ((void *)0)){
  word->previous->next = headWord;
 }
 headWord->previous = word->previous;
 if (word->next != ((void *)0))
  word->next->previous = endWord;
 endWord->next = word->next;
 free(word);
 return 1;
}

canonical_original_code:
char replaceWord(struct _Word *word, struct _Word *headWord, struct _Word *endWord){
 if (word == ((void *)0) || headWord == ((void *)0) || endWord == ((void *)0)) return 0;
 if (word->previous != ((void *)0)){
  word->previous->next = headWord;
 }
 headWord->previous = word->previous;
 if (word->next != ((void *)0))
  word->next->previous = endWord;
 endWord->next = word->next;
 free(word);
 return 1;
}

variable_types:
headWord
struct _Word *

variable_types:
endWord
struct _Word *


combineWords

original_code:
Word* combineWords(Word *w1,Word* w2){
 if (w1 == ((void *)0)) return w2;
 if (w2 == ((void *)0)) return w1;
 Element *el = w2->begin;
 while (el != w2->end){
  el->father = w1;
  el = el->next;
 }
 w1->end = w2->end;
 w1->count += w2->count;
 if (w2->next != ((void *)0))
  w2->next->previous = w1;
 w1->next = w2->next;
 if (w1->begin == w1->end)
  w1->type = EMPTY;
 else
  w1->type = NORMAL;
 free(w2);
 return w1;
}

canonical_original_code:
struct _Word *combineWords(struct _Word *w1, struct _Word *w2){
 if (w1 == ((void *)0)) return w2;
 if (w2 == ((void *)0)) return w1;
 struct _Element *el = w2->begin;
 while (el != w2->end){
  el->father = w1;
  el = el->next;
 }
 w1->end = w2->end;
 w1->count += w2->count;
 if (w2->next != ((void *)0))
  w2->next->previous = w1;
 w1->next = w2->next;
 if (w1->begin == w1->end)
  w1->type = EMPTY;
 else
  w1->type = NORMAL;
 free(w2);
 return w1;
}

variable_types: struct _Element { char c; char isSelected; struct _Element *next; struct _Element *previous; struct _Word { int type; struct _Element *begin; struct _Element *end; int count; struct _Word *next; struct _Word *previous; } *father; } *

return_type: struct _Word { int type; struct _Element { char c; char isSelected; struct _Element *next; struct _Element *previous; struct _Word *father; } *begin; struct _Element *end; int count; struct _Word *next; struct _Word *previous; } *


delWord

original_code:
char delWord(Word *word){
 if (word == ((void *)0)) return 0;
 if (word->next != ((void *)0))
  word->next->previous = word->previous;
 if (word->previous != ((void *)0))
  word->previous->next = word->next;
 free(word);
 return 1;
}

canonical_original_code:
char delWord(struct _Word *word){
 if (word == ((void *)0)) return 0;
 if (word->next != ((void *)0))
  word->next->previous = word->previous;
 if (word->previous != ((void *)0))
  word->previous->next = word->next;
 free(word);
 return 1;
}


delElement

decompiled_code:
void __fastcall delElement(void *ptr)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rdx
_QWORD *v4; // rdi
__int64 v5; // rax

if ( ptr )
{
v1 = *((_QWORD *)ptr + 2);
v2 = *((_QWORD *)ptr + 3);
if ( v1 )
*(_QWORD *)(v1 + 8) = *((_QWORD *)ptr + 1);
v3 = *((_QWORD *)ptr + 1);
if ( v3 )
*(_QWORD *)(v3 + 16) = v1;
free(ptr);
if ( v2 )
{
if ( *(void **)(v2 + 8) != ptr )
{
--*(_DWORD *)(v2 + 24);
v4 = (_QWORD *)v2;
if ( !(unsigned __int8)isEmptyWord(v2) )
return;
LABEL_11:
delWord(v4);
return;
}
v5 = *((_QWORD *)ptr + 1);
--*(_DWORD *)(v2 + 24);
v4 = (_QWORD *)v2;
*(_QWORD *)(v2 + 8) = v5;
if ( (unsigned __int8)isEmptyWord(v2) )
goto LABEL_11;
}
}
}

original_code:
int delElement(Element *element){
 if (element == ((void *)0)) return;
 Word *word = element->father;
 if (element->previous != ((void *)0))
  element->previous->next = element->next;
 if (element->next != ((void *)0))
  element->next->previous = element->previous;
 free(element);
 if (word != ((void *)0)){
  if (element == word->begin){
   word->begin = element->next;
  }
  word->count--;
  if (isEmptyWord(word)){
   delWord(word);
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int delElement(struct _Element *element){
 if (element == ((void *)0)) return;
 struct _Word *word = element->father;
 if (element->previous != ((void *)0))
  element->previous->next = element->next;
 if (element->next != ((void *)0))
  element->next->previous = element->previous;
 free(element);
 if (word != ((void *)0)){
  if (element == word->begin){
   word->begin = element->next;
  }
  word->count--;
  if (isEmptyWord(word)){
   delWord(word);
   return 1;
  }
 }
 return 0;
}

return_type: int


clearWords

original_code:
char clearWords(){
 Element *el = textInput.beginElement;
 while(el != ((void *)0)){
  Element *te = el->next;
  if (te == ((void *)0) || te->father != el->father){
   delWord(el->father);
  }
  el = te;
 }
 return 1;
}

canonical_original_code:
char clearWords(){
 struct _Element *el = textInput.beginElement;
 while(el != ((void *)0)){
  struct _Element *te = el->next;
  if (te == ((void *)0) || te->father != el->father){
   delWord(el->father);
  }
  el = te;
 }
 return 1;
}


clearElements

decompiled_code:
__int64 clearElements()
{
_QWORD *v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = (_QWORD *)textInput[135];
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[1];
delElement(v1);
}
result = 1LL;
textInput[134] = 0LL;
textInput[135] = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
_QWORD *v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = (_QWORD *)textInput[135];
while ( v0 )
{
v1 = v0;
v0 = (_QWORD *)v0[1];
func5(v1);
}
result = 1LL;
textInput[134] = 0LL;
textInput[135] = 0LL;
return result;
}

original_code:
char clearElements(){
 Element *el = textInput.beginElement;
 while(el != ((void *)0)){
  Element *e = el;
  el = el->next;
  delElement(e);
 }
 textInput.curElement = ((void *)0);
 textInput.beginElement = ((void *)0);
 return 1;
}

canonical_original_code:
char clearElements(){
 struct _Element *el = textInput.beginElement;
 while(el != ((void *)0)){
  struct _Element *e = el;
  el = el->next;
  delElement(e);
 }
 textInput.curElement = ((void *)0);
 textInput.beginElement = ((void *)0);
 return 1;
}


clearText

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

result = clearElements();
if ( (_BYTE)result )
{
textInput[134] = 0LL;
result = 1LL;
textInput[135] = 0LL;
}
return result;
}

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

result = func7();
if ( (_BYTE)result )
{
textInput[134] = 0LL;
result = 1LL;
textInput[135] = 0LL;
}
return result;
}

original_code:
char clearText(){
 if (!clearElements()) return 0;
 textInput.curElement = ((void *)0);
 textInput.beginElement = ((void *)0);
 return 1;
}


isFunction

decompiled_code:
__int64 isFunction()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
char isFunction(Word *word){
 return 0;
}

canonical_original_code:
char isFunction(struct _Word *word){
 return 0;
}


isOperator

decompiled_code:
__int64 __fastcall isOperator(__int64 a1)
{
char *v1; // rax

v1 = operators;
while ( **(_BYTE **)(a1 + 8) != *v1 )
{
if ( ++v1 == &operators[14] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
char *v1; // rax

v1 = operators;
while ( **(_BYTE **)(a1 + 8) != *v1 )
{
if ( ++v1 == &operators[14] )
return 0LL;
}
return 1LL;
}

original_code:
char isOperator(Word *word){
 Element *el = word->begin;
 int i;
 for(i = 0; i < 14; ++i){
  if (el->c == operators[i])
   return 1;
 }
 return 0;
}

canonical_original_code:
char isOperator(struct _Word *word){
 struct _Element *el = word->begin;
 int i;
 for(i = 0; i < 14; ++i){
  if (el->c == operators[i])
   return 1;
 }
 return 0;
}

variable_types: i int


isKeyWord

original_code:
char isKeyWord(Word *word){
 int i,j;
 for(i = 0; i < 14; ++i){
  char sign = 1;
  if (word->count == keywords[i].length){
   Element * el = word->begin;
   for(j = 0; j < word->count; ++j){
    if (el == ((void *)0) || keywords[i].str[j] != el->c){
     sign = 0;
     break;
    }
    el = el->next;
   }
   if (sign == 1) return 1;
  }
 }
 return 0;
}

canonical_original_code:
char isKeyWord(struct _Word *word){
 int i; int j;
 for(i = 0; i < 14; ++i){
  char sign = 1;
  if (word->count == keywords[i].length){
   struct _Element *el = word->begin;
   for(j = 0; j < word->count; ++j){
    if (el == ((void *)0) || keywords[i].str[j] != el->c){
     sign = 0;
     break;
    }
    el = el->next;
   }
   if (sign == 1) return 1;
  }
 }
 return 0;
}

variable_types: j int

variable_types: sign char


isString

decompiled_code:
bool __fastcall isString(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 34;
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 34;
}

original_code:
char isString(Word *word){
 Element *el = word->begin;
 if (el->c == '\"')
  return 1;
 return 0;
}

canonical_original_code:
char isString(struct _Word *word){
 struct _Element *el = word->begin;
 if (el->c == '\"')
  return 1;
 return 0;
}


isStringDot

decompiled_code:
bool __fastcall isStringDot(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 39;
}

canonical_decompiled_code:
bool __fastcall func13(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 39;
}

original_code:
char isStringDot(Word *word){
 Element *el = word->begin;
 if (el->c == '\'')
  return 1;
 return 0;
}

canonical_original_code:
char isStringDot(struct _Word *word){
 struct _Element *el = word->begin;
 if (el->c == '\'')
  return 1;
 return 0;
}


isExplain

decompiled_code:
bool __fastcall isExplain(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 35;
}

canonical_decompiled_code:
bool __fastcall func14(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 35;
}

original_code:
char isExplain(Word *word){
 Element *el = word->begin;
 if (el->c == '#')
  return 1;
 return 0;
}

canonical_original_code:
char isExplain(struct _Word *word){
 struct _Element *el = word->begin;
 if (el->c == '#')
  return 1;
 return 0;
}


isSeparate

decompiled_code:
__int64 __fastcall isSeparate(__int64 a1)
{
char *v1; // rax
char v2; // dl

v1 = *(char **)(a1 + 8);
v2 = *v1;
LOBYTE(v1) = *v1 == 32;
return (v2 == 9) | (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
char *v1; // rax
char v2; // dl

v1 = *(char **)(a1 + 8);
v2 = *v1;
LOBYTE(v1) = *v1 == 32;
return (v2 == 9) | (unsigned int)v1;
}

original_code:
char isSeparate(Word *word){
 Element *el = word->begin;
 if (el->c == ' ' || el->c == '\t')
  return 1;
 return 0;
}

canonical_original_code:
char isSeparate(struct _Word *word){
 struct _Element *el = word->begin;
 if (el->c == ' ' || el->c == '\t')
  return 1;
 return 0;
}


isNewline

decompiled_code:
bool __fastcall isNewline(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 10;
}

canonical_decompiled_code:
bool __fastcall func16(__int64 a1)
{
return **(_BYTE **)(a1 + 8) == 10;
}

original_code:
char isNewline(Word *word){
 Element *el = word->begin;
 if (el->c == '\n')
  return 1;
 return 0;
}

canonical_original_code:
char isNewline(struct _Word *word){
 struct _Element *el = word->begin;
 if (el->c == '\n')
  return 1;
 return 0;
}


checkWord

decompiled_code:
char __fastcall checkWord(__int64 a1)
{
__int64 v1; // rax
_DWORD *v2; // r11
__int64 v3; // rdi
_DWORD *v4; // r11
_DWORD *v5; // r11
_DWORD *v6; // r11

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(a1 + 8) != v1 )
{
LOBYTE(v1) = isFunction();
if ( (_BYTE)v1 )
{
*(_DWORD *)a1 = 2;
}
else
{
LOBYTE(v1) = isOperator(a1);
if ( (_BYTE)v1 )
{
*(_DWORD *)a1 = 4;
}
else
{
LOBYTE(v1) = isString(a1);
if ( (_BYTE)v1 )
{
*(_DWORD *)a1 = 11;
}
else
{
LOBYTE(v1) = isStringDot(a1);
if ( (_BYTE)v1 )
{
*(_DWORD *)a1 = 12;
}
else
{
LOBYTE(v1) = isKeyWord(a1);
if ( (_BYTE)v1 )
{
*v2 = 3;
}
else
{
v3 = (__int64)v2;
LOBYTE(v1) = isExplain((__int64)v2);
if ( (_BYTE)v1 )
{
*v4 = 13;
}
else
{
LOBYTE(v1) = isSeparate(v3);
if ( (_BYTE)v1 )
{
*v5 = 22;
}
else
{
LODWORD(v1) = !isNewline(v3) ? 1 : 21;
*v6 = v1;
}
}
}
}
}
}
}
}
}
else
{
LOBYTE(v1) = printw("There is no word!\n");
}
return v1;
}

original_code:
void checkWord(Word * word){
 if (word == ((void *)0)){
  printw("There is no word!\n");
  return;
 }
 if (word->begin == word->end)
  return;
 if (isFunction(word)){
  word->type = FUNCTION;
 }else if (isOperator(word)){
  word->type = OPERATOR;
 }else if (isString(word)){
  word->type = STRING;
 }else if (isStringDot(word)){
  word->type = STRING_DOT;
 }else if (isKeyWord(word)){
  word->type = KEYWORD;
 }else if (isExplain(word)){
  word->type = EXPLAIN;
 }else if (isSeparate(word)){
  word->type = SEPARATE;
 }else if (isNewline(word)){
  word->type = NEWLINE;
 }else{
  word->type = NORMAL;
 }
}

canonical_original_code:
void checkWord(struct _Word *word){
 if (word == ((void *)0)){
  printw("There is no word!\n");
  return;
 }
 if (word->begin == word->end)
  return;
 if (isFunction(word)){
  word->type = FUNCTION;
 }else if (isOperator(word)){
  word->type = OPERATOR;
 }else if (isString(word)){
  word->type = STRING;
 }else if (isStringDot(word)){
  word->type = STRING_DOT;
 }else if (isKeyWord(word)){
  word->type = KEYWORD;
 }else if (isExplain(word)){
  word->type = EXPLAIN;
 }else if (isSeparate(word)){
  word->type = SEPARATE;
 }else if (isNewline(word)){
  word->type = NEWLINE;
 }else{
  word->type = NORMAL;
 }
}

return_type: void


checkSeparate

decompiled_code:
unsigned __int64 __fastcall checkSeparate(_DWORD *a1, unsigned __int8 a2)
{
unsigned __int64 result; // rax

switch ( *a1 )
{
case 1:
case 2:
case 3:
case 4:
result = 0LL;
if ( a2 <= 0x27u )
result = (0x8D00000600uLL >> a2) & 1;
break;
case 0xB:
result = 2 * (unsigned int)(a2 == 34);
break;
case 0xC:
result = 2 * (unsigned int)(a2 == 39);
break;
case 0xD:
result = 2 * (unsigned int)(a2 == 10);
break;
case 0x15:
result = a2 != 10;
break;
case 0x16:
result = (a2 != 32) & (unsigned __int8)(a2 != 9);
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func18(_DWORD *a1, unsigned __int8 a2)
{
unsigned __int64 result; // rax

switch ( *a1 )
{
case 1:
case 2:
case 3:
case 4:
result = 0LL;
if ( a2 <= 0x27u )
result = (0x8D00000600uLL >> a2) & 1;
break;
case 0xB:
result = 2 * (unsigned int)(a2 == 34);
break;
case 0xC:
result = 2 * (unsigned int)(a2 == 39);
break;
case 0xD:
result = 2 * (unsigned int)(a2 == 10);
break;
case 0x15:
result = a2 != 10;
break;
case 0x16:
result = (a2 != 32) & (unsigned __int8)(a2 != 9);
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int checkSeparate(Word *word,char input){
 switch(word->type){
  case EMPTY:
   break;
  case FUNCTION:
  case KEYWORD:
  case OPERATOR:
  case NORMAL:
   if (input == '#' || input == '\"' || input == '\''||
    input == '\n' || input == ' ' || input == '\t'){
     return 1;
   }
   break;
  case STRING:
   if (input == '\"'){
    return 2;
   }
   break;
  case STRING_DOT:
   if (input == '\''){
    return 2;
   }
   break;
  case SEPARATE:
   if (input != ' ' & input != '\t'){
    return 1;
   }
   break;
  case NEWLINE:
   if (input != '\n')
    return 1;
   break;
  case EXPLAIN:
   if (input == '\n'){
    return 2;
   }
   break;
 }
 return 0;
}

canonical_original_code:
int checkSeparate(struct _Word *word, char input){
 switch(word->type){
  case EMPTY:
   break;
  case FUNCTION:
  case KEYWORD:
  case OPERATOR:
  case NORMAL:
   if (input == '#' || input == '\"' || input == '\''||
    input == '\n' || input == ' ' || input == '\t'){
     return 1;
   }
   break;
  case STRING:
   if (input == '\"'){
    return 2;
   }
   break;
  case STRING_DOT:
   if (input == '\''){
    return 2;
   }
   break;
  case SEPARATE:
   if (input != ' ' & input != '\t'){
    return 1;
   }
   break;
  case NEWLINE:
   if (input != '\n')
    return 1;
   break;
  case EXPLAIN:
   if (input == '\n'){
    return 2;
   }
   break;
 }
 return 0;
}

variable_types: input char


linkElementInWord

original_code:
void linkElementInWord(Element *el,Word *word){
 if (word == ((void *)0) || el == ((void *)0)) return;
 if (word->begin == word->end){
  word->begin = el;
  word->type = NORMAL;
 }
 word->end = el->next;
 word->count++;
 el->father = word;
}

canonical_original_code:
void linkElementInWord(struct _Element *el, struct _Word *word){
 if (word == ((void *)0) || el == ((void *)0)) return;
 if (word->begin == word->end){
  word->begin = el;
  word->type = NORMAL;
 }
 word->end = el->next;
 word->count++;
 el->father = word;
}

variable_types:
word
struct _Word *


isCombine

decompiled_code:
__int64 __fastcall isCombine(int *a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax
unsigned int v4; // ecx

if ( !a1 || !a2 )
return 0LL;
v2 = *a1;
if ( !*a1 || !*a2 )
goto LABEL_4;
if ( v2 > 13 )
{
if ( v2 == 22 )
{
LABEL_4:
combineWords((__int64)a1, (__int64)a2);
return 1LL;
}
return 0LL;
}
if ( v2 > 10 )
goto LABEL_4;
v4 = v2 - 1;
result = 0LL;
if ( v4 <= 3 && *a2 != 22 )
goto LABEL_4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(int *a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax
unsigned int v4; // ecx

if ( !a1 || !a2 )
return 0LL;
v2 = *a1;
if ( !*a1 || !*a2 )
goto LABEL_4;
if ( v2 > 13 )
{
if ( v2 == 22 )
{
LABEL_4:
func3((__int64)a1, (__int64)a2);
return 1LL;
}
return 0LL;
}
if ( v2 > 10 )
goto LABEL_4;
v4 = v2 - 1;
result = 0LL;
if ( v4 <= 3 && *a2 != 22 )
goto LABEL_4;
return result;
}

original_code:
char isCombine(Word *w1,Word*w2){
 if (w1 == ((void *)0) || w2 == ((void *)0)) return 0;
 char result = 0;
 if (w1->type == EMPTY || w2->type == EMPTY) result = 1;
 switch (w1->type){
  case FUNCTION:
  case KEYWORD:
  case OPERATOR:
  case NORMAL:
   if (w2->type != SEPARATE)
    result = 1;
   break;
  case SEPARATE:
   if (w2->type != NORMAL && w2->type != OPERATOR &&
    w2->type != KEYWORD && w2->type != FUNCTION)
    result = 1;
  case STRING:
  case STRING_DOT:
  case EXPLAIN:
   result = 1;
   break;
 }
 if (result == 1){
  w1 = combineWords(w1,w2);
 }
 return result;
}

canonical_original_code:
char isCombine(struct _Word *w1, struct _Word *w2){
 if (w1 == ((void *)0) || w2 == ((void *)0)) return 0;
 char result = 0;
 if (w1->type == EMPTY || w2->type == EMPTY) result = 1;
 switch (w1->type){
  case FUNCTION:
  case KEYWORD:
  case OPERATOR:
  case NORMAL:
   if (w2->type != SEPARATE)
    result = 1;
   break;
  case SEPARATE:
   if (w2->type != NORMAL && w2->type != OPERATOR &&
    w2->type != KEYWORD && w2->type != FUNCTION)
    result = 1;
  case STRING:
  case STRING_DOT:
  case EXPLAIN:
   result = 1;
   break;
 }
 if (result == 1){
  w1 = combineWords(w1,w2);
 }
 return result;
}

variable_types: result char


resetWords

decompiled_code:
__int64 resetWords()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = textInput[135];
for ( result = clearWords(); v0; v0 = *(_QWORD *)(v0 + 8) )
;
return result;
}

canonical_decompiled_code:
__int64 func21()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = textInput[135];
for ( result = func6(); v0; v0 = *(_QWORD *)(v0 + 8) )
;
return result;
}

original_code:
void resetWords(){
 Element *el = textInput.beginElement;
 clearWords();
 while(el != ((void *)0)){
  el = el->next;
 }
}

canonical_original_code:
void resetWords(){
 struct _Element *el = textInput.beginElement;
 clearWords();
 while(el != ((void *)0)){
  el = el->next;
 }
}


rebuildWords

decompiled_code:
__int64 rebuildWords()
{
return resetWords();
}

canonical_decompiled_code:
__int64 func22()
{
return func21();
}

original_code:
void rebuildWords(Word *word){
 resetWords();
return;
}

canonical_original_code:
void rebuildWords(struct _Word *word){
 resetWords();
return;
}


addCharInTemp

decompiled_code:
__int64 __fastcall addCharInTemp(char a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = LOWORD(textInput[128]);
if ( (unsigned __int16)result <= 0x3FEu )
{
v2 = (__int16)result;
result = (unsigned int)(result + 1);
*((_BYTE *)textInput + v2) = a1;
LOWORD(textInput[128]) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(char a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = LOWORD(textInput[128]);
if ( (unsigned __int16)result <= 0x3FEu )
{
v2 = (__int16)result;
result = (unsigned int)(result + 1);
*((_BYTE *)textInput + v2) = a1;
LOWORD(textInput[128]) = result;
}
return result;
}

original_code:
void addCharInTemp(char input){
 if (textInput.tmpCur < sizeof(textInput.tmpStr) - 1){
  textInput.tmpStr[textInput.tmpCur] = input;
  textInput.tmpCur++;
 }
}


addCharInMenu

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

if ( shSystem[517] <= 1u )
result = addCharInTemp(a1);
return result;
}

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

if ( shSystem[517] <= 1u )
result = func23(a1);
return result;
}

original_code:
void addCharInMenu(char input){
 switch(shSystem.subState){
  case InSave:
  case InLoad:
   addCharInTemp(input);
   break;
 }
}


addchar

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

result = (unsigned int)shSystem[516];
if ( (_DWORD)result == 1 )
return addCharInMenu(a1);
if ( (_DWORD)result == 2 )
result = addCharInEdit(a1);
return result;
}

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

result = (unsigned int)shSystem[516];
if ( (_DWORD)result == 1 )
return func24(a1);
if ( (_DWORD)result == 2 )
result = func25(a1);
return result;
}

original_code:
void addchar(char input){
 switch(shSystem.state){
  case InMenu:
   addCharInMenu(input);
   break;
  case InTextEdit:
   addCharInEdit(input);
   break;
 }
}


initSystem

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

shSystem = 0LL;
*(&shSystem + 258) = 0x500000002LL;
result = 0LL;
*((_BYTE *)&shSystem + 8) = 0;
*((_DWORD *)&shSystem + 515) = 2;
*(__int64 *)((char *)&shSystem + 9) = 0LL;
*(__int64 *)((char *)&shSystem + 1025) = 0LL;
memset(
(void *)(((_DWORD)&shSystem + 17) & 0xFFFFFFF8),
0,
8LL * (((_DWORD)&shSystem + 9 - (((_DWORD)&shSystem + 17) & 0xFFFFFFF8) + 1024) >> 3));
return result;
}

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

shSystem = 0LL;
*(&shSystem + 258) = 0x500000002LL;
result = 0LL;
*((_BYTE *)&shSystem + 8) = 0;
*((_DWORD *)&shSystem + 515) = 2;
*(__int64 *)((char *)&shSystem + 9) = 0LL;
*(__int64 *)((char *)&shSystem + 1025) = 0LL;
memset(
(void *)(((_DWORD)&shSystem + 17) & 0xFFFFFFF8),
0,
8LL * (((_DWORD)&shSystem + 9 - (((_DWORD)&shSystem + 17) & 0xFFFFFFF8) + 1024) >> 3));
return result;
}

original_code:
void initSystem(){
 shSystem.isQuit = 0;
 shSystem.lastState = InTextEdit;
 shSystem.state = InTextEdit;
 shSystem.menuIndex = 0;
 shSystem.menuSection = 0;
 shSystem.subState = InDefault;
 memset(shSystem.fileName,0,sizeof(shSystem.fileName));
}


initCurses

decompiled_code:
__int64 initCurses()
{
initscr();
wclear(stdscr);
noecho();
cbreak();
keypad(stdscr, 1);
wrefresh(stdscr);
if ( has_colors() && start_color() != -1 )
return initSystem();
printw("Terminal don't support colors!\n");
return initSystem();
}

canonical_decompiled_code:
__int64 func1()
{
initscr();
wclear(stdscr);
noecho();
cbreak();
keypad(stdscr, 1);
wrefresh(stdscr);
if ( has_colors() && start_color() != -1 )
return func0();
printw("Terminal don't support colors!\n");
return func0();
}

original_code:
void initCurses(){
 initscr();
 wclear(stdscr);
 noecho();
 cbreak();
 keypad(stdscr,1);
 wrefresh(stdscr);
 if (!has_colors() || start_color() == (-1)){
  printw("Terminal don't support colors!\n");
 }
 initSystem();
}


destroyCurses

decompiled_code:
int destroyCurses()
{
wclrtoeol(stdscr);
wrefresh(stdscr);
return endwin();
}

canonical_decompiled_code:
int func2()
{
wclrtoeol(stdscr);
wrefresh(stdscr);
return endwin();
}

original_code:
void destroyCurses(){
 wclrtoeol(stdscr);
 wrefresh(stdscr);
 endwin();
}


setSystemState

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

result = *((unsigned int *)&shSystem + 516);
if ( *((_DWORD *)&shSystem + 515) != (_DWORD)result )
*((_DWORD *)&shSystem + 515) = result;
*((_DWORD *)&shSystem + 516) = a1;
return result;
}

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

result = *((unsigned int *)&shSystem + 516);
if ( *((_DWORD *)&shSystem + 515) != (_DWORD)result )
*((_DWORD *)&shSystem + 515) = result;
*((_DWORD *)&shSystem + 516) = a1;
return result;
}

original_code:
void setSystemState(enum SystemState state){
 if (shSystem.lastState != shSystem.state)
  shSystem.lastState = shSystem.state;
 shSystem.state = state;
}

variable_types: enum SystemState { InQuit=0, InMenu=1, InTextEdit=2, InDebug=3 }


setSubState

decompiled_code:
void __fastcall setSubState(int a1)
{
*((_DWORD *)&shSystem + 517) = a1;
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
*((_DWORD *)&shSystem + 517) = a1;
}

original_code:
void setSubState(enum SubState state){
 shSystem.subState = state;
}

variable_types: enum SubState { InLoad=0, InSave=1, InAbout=2, InManual=3, InSelect=4, InDefault=5 }


isSubState

decompiled_code:
bool __fastcall isSubState(int a1)
{
return *((_DWORD *)&shSystem + 517) == a1;
}

canonical_decompiled_code:
bool __fastcall func5(int a1)
{
return *((_DWORD *)&shSystem + 517) == a1;
}

original_code:
char isSubState(enum SubState state){
 if (shSystem.subState == state)
  return 1;
 return 0;
}

user_defined_types: enum SubState { InLoad=0, InSave=1, InAbout=2, InManual=3, InSelect=4, InDefault=5 }


revertSystemState

decompiled_code:
__int64 revertSystemState()
{
return setSystemState(*((_DWORD *)&shSystem + 515));
}

canonical_decompiled_code:
__int64 func6()
{
return func3(*((_DWORD *)&shSystem + 515));
}

original_code:
void revertSystemState(){
 setSystemState(shSystem.lastState);
}


isSystemState

decompiled_code:
bool __fastcall isSystemState(int a1)
{
return *((_DWORD *)&shSystem + 516) == a1;
}

canonical_decompiled_code:
bool __fastcall func7(int a1)
{
return *((_DWORD *)&shSystem + 516) == a1;
}

original_code:
char isSystemState(enum SystemState state){
 if (shSystem.state == state)
  return 1;
 return 0;
}

user_defined_types: enum SystemState { InQuit=0, InMenu=1, InTextEdit=2, InDebug=3 }


main

canonical_name: main

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

v3 = endian("#ifndef __CDIAM_ENDIAN__", argv, envp);
puts("#ifndef __CDIAM_ENDIAN__");
puts("#define __CDIAM_ENDIAN__");
if ( v3 == 1 )
puts("#undef WORDS_BIGENDIAN");
else
puts("#define WORDS_BIGENDIAN 1");
puts("#endif");
return 0;
}

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

v3 = func7("#ifndef __CDIAM_ENDIAN__", argv, envp);
puts("#ifndef __CDIAM_ENDIAN__");
puts("#define __CDIAM_ENDIAN__");
if ( v3 == 1 )
puts("#undef WORDS_BIGENDIAN");
else
puts("#define WORDS_BIGENDIAN 1");
puts("#endif");
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int value;
 value = endian();
 printf("#ifndef __CDIAM_ENDIAN__\n");
 printf("#define __CDIAM_ENDIAN__\n");
 if (value == 1) {
  printf("#undef WORDS_BIGENDIAN\n");
 } else {
  printf("#define WORDS_BIGENDIAN 1\n");
 }
 printf("#endif\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: value int


endian

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

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

original_code:
int endian() {
 short int word = 0x0001;
 char *byte = (char *) &word;
 return (byte[0] ? 1 : 0);
}

canonical_original_code:
int endian() {
 short word = 0x0001;
 char *byte = (char *) &word;
 return (byte[0] ? 1 : 0);
}

variable_types: word short

variable_types:
byte
char *


decompiled_code:
void __fastcall command_queue_init(__int64 a1)
{
if ( !a1 )
_assert_fail("q != NULL", "command_queue.c", 0x14u, "command_queue_init");
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
if ( !a1 )
_assert_fail("q != NULL", "command_queue.c", 0x14u, "command_queue_init");
*(_QWORD *)(a1 + 16) = 0LL;
*(_OWORD *)a1 = 0LL;
}

original_code:
void command_queue_init(command_queue_t *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "command_queue.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    memset(q, 0, sizeof(command_queue_t));
}

canonical_original_code:
void command_queue_init(struct command_queue *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "command_queue.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    memset(q, 0, sizeof(command_queue_t));
}

variable_types: struct command_queue { struct qnode { struct qnode *next; unsigned char cmd; } *head; struct qnode *tail; int size; } *

user_defined_types: struct command_queue { struct qnode *head; struct qnode *tail; int size; }


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

if ( !a1 )
_assert_fail("q != NULL", "command_queue.c", 0x1Fu, "command_queue_empty");
result = 0LL;
if ( !*(_DWORD *)(a1 + 16) )
result = (*(_QWORD *)(a1 + 8) == *(_QWORD *)a1) & (unsigned __int8)(*(_QWORD *)a1 == 0LL);
return result;
}

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

if ( !a1 )
_assert_fail("q != NULL", "command_queue.c", 0x1Fu, "command_queue_empty");
result = 0LL;
if ( !*(_DWORD *)(a1 + 16) )
result = (*(_QWORD *)(a1 + 8) == *(_QWORD *)a1) & (unsigned __int8)(*(_QWORD *)a1 == 0LL);
return result;
}

original_code:
int command_queue_empty(const command_queue_t *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "command_queue.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    return q->size == 0 && q->head == q->tail && q->head == ((void *)0);
}

canonical_original_code:
int command_queue_empty(struct command_queue *q)
{
    ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "command_queue.c", 31, __extension__ __PRETTY_FUNCTION__); }));
    return q->size == 0 && q->head == q->tail && q->head == ((void *)0);
}

user_defined_types: struct qnode { struct qnode *next; unsigned char cmd; }


decompiled_code:
__int64 __fastcall command_queue_dequeue(__int64 a1)
{
unsigned __int8 *v2; // rdi
unsigned int v3; // er12
__int64 result; // rax

if ( (unsigned int)command_queue_empty(a1) )
{
fwrite("Error: tried to dequeue from an empty queue.\n", 1uLL, 0x2DuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = *(unsigned __int8 **)a1;
*(_QWORD *)a1 = **(_QWORD **)a1;
v3 = v2[8];
free(v2);
--*(_DWORD *)(a1 + 16);
if ( !*(_QWORD *)a1 )
*(_QWORD *)(a1 + 8) = 0LL;
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned __int8 *v2; // rdi
unsigned int v3; // er12
__int64 result; // rax

if ( (unsigned int)func1(a1) )
{
fwrite("Error: tried to dequeue from an empty queue.\n", 1uLL, 0x2DuLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v2 = *(unsigned __int8 **)a1;
*(_QWORD *)a1 = **(_QWORD **)a1;
v3 = v2[8];
free(v2);
--*(_DWORD *)(a1 + 16);
if ( !*(_QWORD *)a1 )
*(_QWORD *)(a1 + 8) = 0LL;
result = v3;
}
return result;
}

original_code:
uint8_t command_queue_dequeue(command_queue_t *q)
{
    if (command_queue_empty(q))
    {
        fprintf(stderr, "Error: tried to dequeue from an empty queue.\n");
        return -1;
    }
    else
    {
        qnode_t* head = q->head;
        q->head = q->head->next;
        uint8_t cmd = head->cmd;
        free(head);
        q->size--;
        if (q->head == ((void *)0))
            q->tail = ((void *)0);
        return cmd;
    }
}

canonical_original_code:
unsigned char command_queue_dequeue(struct command_queue *q)
{
    if (command_queue_empty(q))
    {
        fprintf(stderr, "Error: tried to dequeue from an empty queue.\n");
        return -1;
    }
    else
    {
        struct qnode *head = q->head;
        q->head = q->head->next;
        unsigned char cmd = head->cmd;
        free(head);
        q->size--;
        if (q->head == ((void *)0))
            q->tail = ((void *)0);
        return cmd;
    }
}

variable_types: struct qnode { struct qnode *next; unsigned char cmd; } *

variable_types:
cmd
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall command_queue_head(__int64 a1)
{
if ( !(unsigned int)command_queue_empty(a1) )
return *(unsigned __int8 *)(*(_QWORD *)a1 + 8LL);
fwrite("Error: tried to get head from an empty queue.\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !(unsigned int)func1(a1) )
return *(unsigned __int8 *)(*(_QWORD *)a1 + 8LL);
fwrite("Error: tried to get head from an empty queue.\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
uint8_t command_queue_head(const command_queue_t* q)
{
    if (command_queue_empty(q))
    {
        fprintf(stderr, "Error: tried to get head from an empty queue.\n");
        return -1;
    }else
        return q->head->cmd;
}

canonical_original_code:
unsigned char command_queue_head(struct command_queue *q)
{
    if (command_queue_empty(q))
    {
        fprintf(stderr, "Error: tried to get head from an empty queue.\n");
        return -1;
    }else
        return q->head->cmd;
}


decompiled_code:
__int64 __fastcall free_queue(void **a1)
{
__int64 result; // rax
_QWORD *v2; // rbp

while ( 1 )
{
result = command_queue_empty((__int64)a1);
if ( (_DWORD)result )
break;
v2 = *(_QWORD **)*a1;
free(*a1);
*a1 = v2;
if ( !v2 )
a1[1] = 0LL;
--*((_DWORD *)a1 + 4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void **a1)
{
__int64 result; // rax
_QWORD *v2; // rbp

while ( 1 )
{
result = func1((__int64)a1);
if ( (_DWORD)result )
break;
v2 = *(_QWORD **)*a1;
free(*a1);
*a1 = v2;
if ( !v2 )
a1[1] = 0LL;
--*((_DWORD *)a1 + 4);
}
return result;
}

original_code:
void free_queue(command_queue_t* q)
{
    while (!command_queue_empty(q))
    {
        qnode_t* next = q->head->next;
        free(q->head);
        q->head = next;
        if (q->head == ((void *)0))
            q->tail = ((void *)0);
        q->size--;
    }
}

canonical_original_code:
void free_queue(struct command_queue *q)
{
    while (!command_queue_empty(q))
    {
        struct qnode *next = q->head->next;
        free(q->head);
        q->head = next;
        if (q->head == ((void *)0))
            q->tail = ((void *)0);
        q->size--;
    }
}


decompiled_code:
int signal_init()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)(signal_init + 1);
memset(&v1.sa_mask, 0, 0x90uLL);
sigaction(13, &v1, 0LL);
return sigaction(10, &v1, 0LL);
}

canonical_decompiled_code:
int func0()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)(signal_init + 1);
memset(&v1.sa_mask, 0, 0x90uLL);
sigaction(13, &v1, 0LL);
return sigaction(10, &v1, 0LL);
}

original_code:
static void signal_init(void)
{
 struct sigaction act;
 memset(&act, 0, sizeof(act));
 act.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
 sigaction(13, &act, ((void *)0));
 sigaction(10, &act, ((void *)0));
}

canonical_original_code:
static void signal_init()
{
 struct sigaction act;
 memset(&act, 0, sizeof(act));
 act.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
 sigaction(13, &act, ((void *)0));
 sigaction(10, &act, ((void *)0));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
int rlimit_init()
{
int result; // eax
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = 0x40000LL;
v1.rlim_max = 0x40000LL;
setrlimit(RLIMIT_CORE, &v1);
if ( getrlimit(RLIMIT_NOFILE, &v1) < 0 )
return fprintf(stderr, "%s %s %d:getrlimit:RLIMIT_NOFILE error\n", "cfg_ipc_server.c", "rlimit_init", 51LL);
if ( v1.rlim_cur <= 0x12B )
{
v1.rlim_cur = 300LL;
setrlimit(RLIMIT_NOFILE, &v1);
}
result = getrlimit(RLIMIT_STACK, &v1);
if ( v1.rlim_cur <= 0x1FFF )
{
v1.rlim_cur = 0x2000LL;
result = setrlimit(RLIMIT_STACK, &v1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
struct rlimit v1; // [rsp+0h] [rbp-18h] BYREF

v1.rlim_cur = 0x40000LL;
v1.rlim_max = 0x40000LL;
setrlimit(RLIMIT_CORE, &v1);
if ( getrlimit(RLIMIT_NOFILE, &v1) < 0 )
return fprintf(stderr, "%s %s %d:getrlimit:RLIMIT_NOFILE error\n", "cfg_ipc_server.c", "rlimit_init", 51LL);
if ( v1.rlim_cur <= 0x12B )
{
v1.rlim_cur = 300LL;
setrlimit(RLIMIT_NOFILE, &v1);
}
result = getrlimit(RLIMIT_STACK, &v1);
if ( v1.rlim_cur <= 0x1FFF )
{
v1.rlim_cur = 0x2000LL;
result = setrlimit(RLIMIT_STACK, &v1);
}
return result;
}

original_code:
static void rlimit_init(void)
{
 struct rlimit rlim;
 int ret;
 rlim.rlim_cur = (256 * 1024);
 rlim.rlim_max = (256 * 1024);
 setrlimit(RLIMIT_CORE, &rlim);
 ret = getrlimit(RLIMIT_NOFILE, &rlim);
 if (ret < 0)
 {
  fprintf(stderr, "%s %s %d:" "getrlimit:RLIMIT_NOFILE error\n", "cfg_ipc_server.c", __FUNCTION__, 51);;
  return;
 }
 if (rlim.rlim_cur < 300)
 {
  rlim.rlim_cur = 300;
  setrlimit(RLIMIT_NOFILE, &rlim);
 }
 getrlimit(RLIMIT_STACK, &rlim);
 if (ret < 0)
 {
  fprintf(stderr, "%s %s %d:" "getrlimit:RLIMIT_STACK error\n", "cfg_ipc_server.c", __FUNCTION__, 65);;
  return;
 }
 if (rlim.rlim_cur < 8192)
 {
  rlim.rlim_cur = 8192;
  setrlimit(RLIMIT_STACK, &rlim);
 }
}

canonical_original_code:
static void rlimit_init()
{
 struct rlimit rlim;
 int ret;
 rlim.rlim_cur = (256 * 1024);
 rlim.rlim_max = (256 * 1024);
 setrlimit(RLIMIT_CORE, &rlim);
 ret = getrlimit(RLIMIT_NOFILE, &rlim);
 if (ret < 0)
 {
  fprintf(stderr, "%s %s %d:" "getrlimit:RLIMIT_NOFILE error\n", "cfg_ipc_server.c", __FUNCTION__, 51);;
  return;
 }
 if (rlim.rlim_cur < 300)
 {
  rlim.rlim_cur = 300;
  setrlimit(RLIMIT_NOFILE, &rlim);
 }
 getrlimit(RLIMIT_STACK, &rlim);
 if (ret < 0)
 {
  fprintf(stderr, "%s %s %d:" "getrlimit:RLIMIT_STACK error\n", "cfg_ipc_server.c", __FUNCTION__, 65);;
  return;
 }
 if (rlim.rlim_cur < 8192)
 {
  rlim.rlim_cur = 8192;
  setrlimit(RLIMIT_STACK, &rlim);
 }
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types: ret int


decompiled_code:
__int64 __fastcall cfg_ipc_server_start(__int64 a1)
{
int v2; // eax
int v3; // er13
int v4; // eax
int v5; // ebx
unsigned int v6; // ebp
signed int v7; // eax
__int64 v8; // r15
char v9; // r14
unsigned int v10; // eax
int v11; // edi
char *v12; // rax
int *v14; // rax
char *v15; // rax
int v16[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v16[0] = -1;
signal_init();
rlimit_init();
if ( (int)cfg_fdevent_init(a1) < 0 )
{
fprintf(stderr, "%s %s %d:init server fdevent error", "cfg_ipc_server.c", "cfg_ipc_server_start", 230LL);
cfg_fdevent_free(a1);
}
else
{
cfg_fdevent_reset(a1);
v2 = server_listen_constprop_0(*(_DWORD *)(a1 + 8));
v3 = v2;
if ( v2 >= 0 )
{
cfg_fdevent_event_set(a1, v16, (unsigned int)v2, 1LL);
while ( 1 )
{
while ( 1 )
{
v4 = cfg_fdevent_poll(a1, 1LL);
v5 = v4;
if ( v4 <= 0 )
break;
v6 = -1;
do
{
v7 = cfg_fdevent_event_next_fdndx(a1, v6);
v6 = v7;
if ( v7 == -1 )
break;
v8 = v7;
v9 = cfg_fdevent_event_get_revent(a1, v7);
v10 = cfg_fdevent_event_get_fd(a1, v8);
if ( v3 == v10 )
handle_listen_event_isra_0(a1, v3, v9);
else
handle_client_event_isra_0(a1, v10, v9);
--v5;
}
while ( v5 );
}
if ( v4 )
{
v11 = *_errno_location();
if ( v11 != 4 )
{
v12 = strerror(v11);
fprintf(
stderr,
"%s %s %d:cfg poll fdevent error: %s\n",
"cfg_ipc_server.c",
"cfg_ipc_server_start",
273LL,
v12);
}
}
}
}
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "%s %s %d:create server socket error: %s\n", "cfg_ipc_server.c", "cfg_ipc_server_start", 239LL, v15);
cfg_fdevent_free(a1);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v2; // eax
int v3; // er13
int v4; // eax
int v5; // ebx
unsigned int v6; // ebp
signed int v7; // eax
__int64 v8; // r15
char v9; // r14
unsigned int v10; // eax
int v11; // edi
char *v12; // rax
int *v14; // rax
char *v15; // rax
int v16[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v16[0] = -1;
func0();
func1();
if ( (int)cfg_fdevent_init(a1) < 0 )
{
fprintf(stderr, "%s %s %d:init server fdevent error", "cfg_ipc_server.c", "cfg_ipc_server_start", 230LL);
cfg_fdevent_free(a1);
}
else
{
cfg_fdevent_reset(a1);
v2 = func5(*(_DWORD *)(a1 + 8));
v3 = v2;
if ( v2 >= 0 )
{
cfg_fdevent_event_set(a1, v16, (unsigned int)v2, 1LL);
while ( 1 )
{
while ( 1 )
{
v4 = cfg_fdevent_poll(a1, 1LL);
v5 = v4;
if ( v4 <= 0 )
break;
v6 = -1;
do
{
v7 = cfg_fdevent_event_next_fdndx(a1, v6);
v6 = v7;
if ( v7 == -1 )
break;
v8 = v7;
v9 = cfg_fdevent_event_get_revent(a1, v7);
v10 = cfg_fdevent_event_get_fd(a1, v8);
if ( v3 == v10 )
func4(a1, v3, v9);
else
func3(a1, v10, v9);
--v5;
}
while ( v5 );
}
if ( v4 )
{
v11 = *_errno_location();
if ( v11 != 4 )
{
v12 = strerror(v11);
fprintf(
stderr,
"%s %s %d:cfg poll fdevent error: %s\n",
"cfg_ipc_server.c",
"cfg_ipc_server_start",
273LL,
v12);
}
}
}
}
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "%s %s %d:create server socket error: %s\n", "cfg_ipc_server.c", "cfg_ipc_server_start", 239LL, v15);
cfg_fdevent_free(a1);
}
return 0xFFFFFFFFLL;
}

original_code:
int cfg_ipc_server_start(cfg_fdevents *ev)
{
 int listenfd = -1;
 int fde_ndx = -1;
 int timeout = 1;
 int ready_num = -1;
 signal_init();
 rlimit_init();
 if (cfg_fdevent_init(ev) < 0)
 {
  fprintf(stderr, "%s %s %d:" "init server fdevent error", "cfg_ipc_server.c", __FUNCTION__, 230);;
  goto errout;
 }
 cfg_fdevent_reset(ev);
 listenfd = server_listen("main.socket", ev->maxfds);
 if (listenfd < 0)
 {
  fprintf(stderr, "%s %s %d:" "create server socket error: %s\n", "cfg_ipc_server.c", __FUNCTION__, 239, strerror((*__errno_location ())));;
  goto errout;
 }
 cfg_fdevent_event_set(ev, &fde_ndx, listenfd, (1 << 0));
 while(1)
 {
  if ((ready_num = cfg_fdevent_poll(ev, timeout)) > 0)
  {
   int revents;
   int fd_ndx;
   int fd;
   fd_ndx = -1;
   do
   {
    fd_ndx = cfg_fdevent_event_next_fdndx(ev, fd_ndx);
    if (-1 == fd_ndx)
     break;
    revents = cfg_fdevent_event_get_revent(ev, fd_ndx);
    fd = cfg_fdevent_event_get_fd(ev, fd_ndx);
    if (fd == listenfd)
     handle_listen_event(ev, fd, revents);
    else
     handle_client_event(ev, fd, revents);
   }while (--ready_num > 0);
  }
  else if (ready_num < 0 && (*__errno_location ()) != 4)
  {
   fprintf(stderr, "%s %s %d:" "cfg poll fdevent error: %s\n", "cfg_ipc_server.c", __FUNCTION__, 273, strerror((*__errno_location ())));;
  }
 }
errout:
 cfg_fdevent_free(ev);
 if (listenfd > 0)
 {
  close(listenfd);
  unlink("main.socket");
 }
 return -1;
}

canonical_original_code:
int cfg_ipc_server_start(struct cfg_fdevents *ev)
{
 int listenfd = -1;
 int fde_ndx = -1;
 int timeout = 1;
 int ready_num = -1;
 signal_init();
 rlimit_init();
 if (cfg_fdevent_init(ev) < 0)
 {
  fprintf(stderr, "%s %s %d:" "init server fdevent error", "cfg_ipc_server.c", __FUNCTION__, 230);;
  goto errout;
 }
 cfg_fdevent_reset(ev);
 listenfd = server_listen("main.socket", ev->maxfds);
 if (listenfd < 0)
 {
  fprintf(stderr, "%s %s %d:" "create server socket error: %s\n", "cfg_ipc_server.c", __FUNCTION__, 239, strerror((*__errno_location ())));;
  goto errout;
 }
 cfg_fdevent_event_set(ev, &fde_ndx, listenfd, (1 << 0));
 while(1)
 {
  if ((ready_num = cfg_fdevent_poll(ev, timeout)) > 0)
  {
   int revents;
   int fd_ndx;
   int fd;
   fd_ndx = -1;
   do
   {
    fd_ndx = cfg_fdevent_event_next_fdndx(ev, fd_ndx);
    if (-1 == fd_ndx)
     break;
    revents = cfg_fdevent_event_get_revent(ev, fd_ndx);
    fd = cfg_fdevent_event_get_fd(ev, fd_ndx);
    if (fd == listenfd)
     handle_listen_event(ev, fd, revents);
    else
     handle_client_event(ev, fd, revents);
   }while (--ready_num > 0);
  }
  else if (ready_num < 0 && (*__errno_location ()) != 4)
  {
   fprintf(stderr, "%s %s %d:" "cfg poll fdevent error: %s\n", "cfg_ipc_server.c", __FUNCTION__, 273, strerror((*__errno_location ())));;
  }
 }
errout:
 cfg_fdevent_free(ev);
 if (listenfd > 0)
 {
  close(listenfd);
  unlink("main.socket");
 }
 return -1;
}

variable_types: struct cfg_fdevents { enum cfg_fdevent_handler_t { FDEVENT_HANDLER_UNSET=0, FDEVENT_HANDLER_SELECT=1 } type; unsigned long maxfds; struct fd_set { long __fds_bits[-1]; } select_read; struct fd_set select_write; struct fd_set select_error; struct fd_set select_set_read; struct fd_set select_set_write; struct fd_set select_set_error; int select_max_fd; int (*reset)(struct cfg_fdevents *ev); void (*free)(struct cfg_fdevents *ev); int (*event_set)(struct cfg_fdevents *ev, int fde_ndx, int fd, int events); int (*event_del)(struct cfg_fdevents *ev, int fde_ndx, int fd); int (*event_get_revent)(struct cfg_fdevents *ev, unsigned long ndx); int (*event_get_fd)(struct cfg_fdevents *ev, unsigned long ndx); int (*event_next_fdndx)(struct cfg_fdevents *ev, int ndx); int (*poll)(struct cfg_fdevents *ev, int timeout_ms); int (*handler_client_msg)(int fd, void *msg); } *

variable_types: listenfd int

variable_types: timeout int

variable_types: revents int

variable_types: fd int

user_defined_types: struct cfg_fdevents { enum cfg_fdevent_handler_t type; unsigned long maxfds; struct fd_set select_read; struct fd_set select_write; struct fd_set select_error; struct fd_set select_set_read; struct fd_set select_set_write; struct fd_set select_set_error; int select_max_fd; int (*reset)(struct cfg_fdevents *ev); void (*free)(struct cfg_fdevents *ev); int (*event_set)(struct cfg_fdevents *ev, int fde_ndx, int fd, int events); int (*event_del)(struct cfg_fdevents *ev, int fde_ndx, int fd); int (*event_get_revent)(struct cfg_fdevents *ev, unsigned long ndx); int (*event_get_fd)(struct cfg_fdevents *ev, unsigned long ndx); int (*event_next_fdndx)(struct cfg_fdevents *ev, int ndx); int (*poll)(struct cfg_fdevents *ev, int timeout_ms); int (*handler_client_msg)(int fd, void *msg); }


decompiled_code:
__int64 __fastcall fdevent_select_reset(_DWORD *a1)
{
__int64 result; // rax

result = 0LL;
memset(a1 + 100, 0, 0x80uLL);
memset(a1 + 132, 0, 0x80uLL);
memset(a1 + 164, 0, 0x80uLL);
a1[196] = -1;
return result;
}

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

result = 0LL;
memset(a1 + 100, 0, 0x80uLL);
memset(a1 + 132, 0, 0x80uLL);
memset(a1 + 164, 0, 0x80uLL);
a1[196] = -1;
return result;
}

original_code:
static int fdevent_select_reset(cfg_fdevents *ev)
{
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(ev->select_set_read))->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(ev->select_set_write))->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(ev->select_set_error))->__fds_bits)[0]) : "memory"); } while (0);
 ev->select_max_fd = -1;
 return 0;
}

canonical_original_code:
static int fdevent_select_reset(struct cfg_fdevents *ev)
{
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(ev->select_set_read))->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(ev->select_set_write))->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&(ev->select_set_error))->__fds_bits)[0]) : "memory"); } while (0);
 ev->select_max_fd = -1;
 return 0;
}

user_defined_types: enum cfg_fdevent_handler_t { FDEVENT_HANDLER_UNSET=0, FDEVENT_HANDLER_SELECT=1 }


original_code:
static int fdevent_select_event_del(cfg_fdevents *ev, int fde_ndx, int fd)
{
 ( (void)(fde_ndx) );
 ((void) (((&(ev->select_set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->select_set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->select_set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 return -1;
}

canonical_original_code:
static int fdevent_select_event_del(struct cfg_fdevents *ev, int fde_ndx, int fd)
{
 ( (void)(fde_ndx) );
 ((void) (((&(ev->select_set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->select_set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&(ev->select_set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 return -1;
}


decompiled_code:
__int64 __fastcall fdevent_select_event_get_revent(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rdx
_QWORD *v3; // rsi
__int64 result; // rax

v2 = 1LL << a2;
v3 = (_QWORD *)(a1 + 8 * (a2 >> 6));
result = (v3[2] & v2) != 0;
if ( (v2 & v3[18]) != 0 )
result = ((v3[2] & v2) != 0) | 4u;
if ( (v3[34] & v2) != 0 )
result = (unsigned int)result | 8;
return result;
}

original_code:
static int fdevent_select_event_get_revent(cfg_fdevents *ev, size_t ndx)
{
 int revents = 0;
 if (((((&(ev->select_read))->__fds_bits)[((ndx) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ndx) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  revents |= (1 << 0);
 }
 if (((((&(ev->select_write))->__fds_bits)[((ndx) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ndx) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  revents |= (1 << 2);
 }
 if (((((&(ev->select_error))->__fds_bits)[((ndx) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ndx) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  revents |= (1 << 3);
 }
 return revents;
}

canonical_original_code:
static int fdevent_select_event_get_revent(struct cfg_fdevents *ev, unsigned long ndx)
{
 int revents = 0;
 if (((((&(ev->select_read))->__fds_bits)[((ndx) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ndx) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  revents |= (1 << 0);
 }
 if (((((&(ev->select_write))->__fds_bits)[((ndx) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ndx) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  revents |= (1 << 2);
 }
 if (((((&(ev->select_error))->__fds_bits)[((ndx) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ndx) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  revents |= (1 << 3);
 }
 return revents;
}

variable_types:
ndx
unsigned long


decompiled_code:
__int64 __fastcall fdevent_select_event_get_fd(__int64 a1, __int64 a2)
{
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return a2;
}

original_code:
static int fdevent_select_event_get_fd(cfg_fdevents *ev, size_t ndx)
{
 ( (void)(ev) );
 return ndx;
}

canonical_original_code:
static int fdevent_select_event_get_fd(struct cfg_fdevents *ev, unsigned long ndx)
{
 ( (void)(ev) );
 return ndx;
}


original_code:
static int fdevent_select_event_next_fdndx(cfg_fdevents *ev, int ndx)
{
 int i;
 i = (ndx < 0) ? 0 : ndx + 1;
 for (; i < ev->select_max_fd + 1; i++)
 {
  if (((((&(ev->select_read))->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   return i;
  if (((((&(ev->select_write))->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   return i;
  if (((((&(ev->select_error))->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   return i;
 }
 return -1;
}

canonical_original_code:
static int fdevent_select_event_next_fdndx(struct cfg_fdevents *ev, int ndx)
{
 int i;
 i = (ndx < 0) ? 0 : ndx + 1;
 for (; i < ev->select_max_fd + 1; i++)
 {
  if (((((&(ev->select_read))->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   return i;
  if (((((&(ev->select_write))->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   return i;
  if (((((&(ev->select_error))->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   return i;
 }
 return -1;
}

variable_types: ndx int

variable_types: i int


decompiled_code:
__int64 __fastcall fdevent_select_event_set(__int64 a1, __int64 a2, int a3, char a4)
{
__int64 result; // rax
int v5; // edx
_QWORD *v8; // rdx
__int64 v9; // rcx
__int64 v10; // rdi
__int64 v11; // rsi

if ( a3 > 1023 )
_assert_fail("fd < ((int)FD_SETSIZE)", "cfg_fdevent_select.c", 0x2Au, "fdevent_select_event_set");
result = (unsigned int)a3;
v5 = a3 + 63;
if ( (int)result >= 0 )
v5 = result;
v8 = (_QWORD *)(a1 + 8LL * (v5 >> 6));
v9 = 1LL << ((int)result % 64);
v10 = v9 | v8[50];
if ( (a4 & 1) == 0 )
v10 = ~v9 & v8[50];
v8[50] = v10;
v11 = v9 | v8[66];
if ( (a4 & 4) == 0 )
v11 = ~v9 & v8[66];
v8[82] |= v9;
v8[66] = v11;
if ( *(_DWORD *)(a1 + 784) < (int)result )
*(_DWORD *)(a1 + 784) = result;
return result;
}

original_code:
static int fdevent_select_event_set(cfg_fdevents *ev, int fde_ndx, int fd, int events)
{
 ( (void)(fde_ndx) );
 ((void) sizeof ((fd < ((int)1024)) ? 1 : 0), __extension__ ({ if (fd < ((int)1024)) ; else __assert_fail ("fd < ((int)FD_SETSIZE)", "cfg_fdevent_select.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 if (events & (1 << 0))
 {
  ((void) (((&(ev->select_set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 else
 {
  ((void) (((&(ev->select_set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 if (events & (1 << 2))
 {
  ((void) (((&(ev->select_set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 else
 {
  ((void) (((&(ev->select_set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 ((void) (((&(ev->select_set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (fd > ev->select_max_fd)
  ev->select_max_fd = fd;
 return fd;
}

canonical_original_code:
static int fdevent_select_event_set(struct cfg_fdevents *ev, int fde_ndx, int fd, int events)
{
 ( (void)(fde_ndx) );
 ((void) sizeof ((fd < ((int)1024)) ? 1 : 0), __extension__ ({ if (fd < ((int)1024)) ; else __assert_fail ("fd < ((int)FD_SETSIZE)", "cfg_fdevent_select.c", 42, __extension__ __PRETTY_FUNCTION__); }));
 if (events & (1 << 0))
 {
  ((void) (((&(ev->select_set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 else
 {
  ((void) (((&(ev->select_set_read))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 if (events & (1 << 2))
 {
  ((void) (((&(ev->select_set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 else
 {
  ((void) (((&(ev->select_set_write))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 }
 ((void) (((&(ev->select_set_error))->__fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
 if (fd > ev->select_max_fd)
  ev->select_max_fd = fd;
 return fd;
}

variable_types: events int


original_code:
static int fdevent_select_poll(cfg_fdevents *ev, int timeout_ms)
{
 struct timeval tv;
 tv.tv_sec = timeout_ms / 1000;
 tv.tv_usec = (timeout_ms % 1000) * 1000;
 ev->select_read = ev->select_set_read;
 ev->select_write = ev->select_set_write;
 ev->select_error = ev->select_set_error;
 return select(ev->select_max_fd + 1, &(ev->select_read), &(ev->select_write), &(ev->select_error), &tv);
}

canonical_original_code:
static int fdevent_select_poll(struct cfg_fdevents *ev, int timeout_ms)
{
 struct timeval tv;
 tv.tv_sec = timeout_ms / 1000;
 tv.tv_usec = (timeout_ms % 1000) * 1000;
 ev->select_read = ev->select_set_read;
 ev->select_write = ev->select_set_write;
 ev->select_error = ev->select_set_error;
 return select(ev->select_max_fd + 1, &(ev->select_read), &(ev->select_write), &(ev->select_error), &tv);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


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

*(_DWORD *)a1 = 1;
result = 0LL;
*(_QWORD *)(a1 + 792) = fdevent_select_reset;
*(_QWORD *)(a1 + 848) = fdevent_select_poll;
*(_QWORD *)(a1 + 816) = fdevent_select_event_del;
*(_QWORD *)(a1 + 808) = fdevent_select_event_set;
*(_QWORD *)(a1 + 840) = fdevent_select_event_next_fdndx;
*(_QWORD *)(a1 + 832) = fdevent_select_event_get_fd;
*(_QWORD *)(a1 + 824) = fdevent_select_event_get_revent;
return result;
}

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

*(_DWORD *)a1 = 1;
result = 0LL;
*(_QWORD *)(a1 + 792) = fdevent_select_reset;
*(_QWORD *)(a1 + 848) = fdevent_select_poll;
*(_QWORD *)(a1 + 816) = fdevent_select_event_del;
*(_QWORD *)(a1 + 808) = fdevent_select_event_set;
*(_QWORD *)(a1 + 840) = fdevent_select_event_next_fdndx;
*(_QWORD *)(a1 + 832) = fdevent_select_event_get_fd;
*(_QWORD *)(a1 + 824) = fdevent_select_event_get_revent;
return result;
}

original_code:
int fdevent_select_init(cfg_fdevents *ev)
{
 ev->type = FDEVENT_HANDLER_SELECT;
 ev->reset = fdevent_select_reset;;
 ev->poll = fdevent_select_poll;;
 ev->event_del = fdevent_select_event_del;;
 ev->event_set = fdevent_select_event_set;;
 ev->event_next_fdndx = fdevent_select_event_next_fdndx;;
 ev->event_get_fd = fdevent_select_event_get_fd;;
 ev->event_get_revent = fdevent_select_event_get_revent;;
 return 0;
}

canonical_original_code:
int fdevent_select_init(struct cfg_fdevents *ev)
{
 ev->type = FDEVENT_HANDLER_SELECT;
 ev->reset = fdevent_select_reset;;
 ev->poll = fdevent_select_poll;;
 ev->event_del = fdevent_select_event_del;;
 ev->event_set = fdevent_select_event_set;;
 ev->event_next_fdndx = fdevent_select_event_next_fdndx;;
 ev->event_get_fd = fdevent_select_event_get_fd;;
 ev->event_get_revent = fdevent_select_event_get_revent;;
 return 0;
}


decompiled_code:
__int64 __fastcall cfg_fdevent_init(_DWORD *a1)
{
__int64 result; // rax
int *v2; // rax
char *v3; // rax

if ( *a1 != 1 )
return 0xFFFFFFFFLL;
result = fdevent_select_init();
if ( (_DWORD)result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s %s %d:event-handler select failed: %s\n", "cfg_fdevent.c", "cfg_fdevent_init", 20LL, v3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 result; // rax
int *v2; // rax
char *v3; // rax

if ( *a1 != 1 )
return 0xFFFFFFFFLL;
result = fdevent_select_init();
if ( (_DWORD)result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s %s %d:event-handler select failed: %s\n", "cfg_fdevent.c", "cfg_fdevent_init", 20LL, v3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int cfg_fdevent_init(cfg_fdevents *ev)
{
 switch(ev->type)
 {
 case FDEVENT_HANDLER_SELECT:
  if (0 != fdevent_select_init(ev))
  {
   fprintf(stderr, "%s %s %d:" "event-handler select failed: %s\n", "cfg_fdevent.c", __FUNCTION__, 20, strerror((*__errno_location ())));;
   return -1;
  }
  return 0;
 case FDEVENT_HANDLER_UNSET:
  break;
 }
 return -1;
}

canonical_original_code:
int cfg_fdevent_init(struct cfg_fdevents *ev)
{
 switch(ev->type)
 {
 case FDEVENT_HANDLER_SELECT:
  if (0 != fdevent_select_init(ev))
  {
   fprintf(stderr, "%s %s %d:" "event-handler select failed: %s\n", "cfg_fdevent.c", __FUNCTION__, 20, strerror((*__errno_location ())));;
   return -1;
  }
  return 0;
 case FDEVENT_HANDLER_UNSET:
  break;
 }
 return -1;
}


decompiled_code:
void __fastcall cfg_fdevent_free(__int64 a1)
{
void (*v1)(void); // rax

if ( a1 )
{
v1 = *(void (**)(void))(a1 + 800);
if ( v1 )
v1();
}
}

original_code:
void cfg_fdevent_free(cfg_fdevents *ev)
{
 if (!ev)
  return;
 if (ev->free)
  ev->free(ev);
}

canonical_original_code:
void cfg_fdevent_free(struct cfg_fdevents *ev)
{
 if (!ev)
  return;
 if (ev->free)
  ev->free(ev);
}


decompiled_code:
__int64 __fastcall cfg_fdevent_reset(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 792);
if ( v1 )
result = v1();
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 792);
if ( v1 )
result = v1();
else
result = 0LL;
return result;
}

original_code:
int cfg_fdevent_reset(cfg_fdevents *ev)
{
 if (ev->reset)
  return ev->reset(ev);
 return 0;
}

canonical_original_code:
int cfg_fdevent_reset(struct cfg_fdevents *ev)
{
 if (ev->reset)
  return ev->reset(ev);
 return 0;
}


decompiled_code:
__int64 __fastcall cfg_fdevent_event_del(__int64 a1, _DWORD *a2)
{
__int64 (__fastcall *v2)(__int64, __int64); // rax
__int64 v4; // rsi

v2 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 816);
if ( a2 )
{
v4 = (unsigned int)*a2;
if ( v2 )
LODWORD(v4) = v2(a1, v4);
*a2 = v4;
return 0LL;
}
if ( !v2 )
return 0LL;
v2(a1, 0xFFFFFFFFLL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
__int64 (__fastcall *v2)(__int64, __int64); // rax
__int64 v4; // rsi

v2 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 816);
if ( a2 )
{
v4 = (unsigned int)*a2;
if ( v2 )
LODWORD(v4) = v2(a1, v4);
*a2 = v4;
return 0LL;
}
if ( !v2 )
return 0LL;
v2(a1, 0xFFFFFFFFLL);
return 0LL;
}

original_code:
int cfg_fdevent_event_del(cfg_fdevents *ev, int *fde_ndx, int fd)
{
 int fde = fde_ndx ? *fde_ndx : -1;
 if (ev->event_del)
  fde = ev->event_del(ev, fde, fd);
 if (fde_ndx)
  *fde_ndx = fde;
 return 0;
}

canonical_original_code:
int cfg_fdevent_event_del(struct cfg_fdevents *ev, int *fde_ndx, int fd)
{
 int fde = fde_ndx ? *fde_ndx : -1;
 if (ev->event_del)
  fde = ev->event_del(ev, fde, fd);
 if (fde_ndx)
  *fde_ndx = fde;
 return 0;
}

variable_types: fde int


decompiled_code:
__int64 __fastcall cfg_fdevent_event_set(__int64 a1, _DWORD *a2)
{
__int64 (__fastcall *v2)(__int64, __int64); // rax
__int64 v4; // rsi

v2 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 808);
if ( a2 )
{
v4 = (unsigned int)*a2;
if ( v2 )
LODWORD(v4) = v2(a1, v4);
*a2 = v4;
return 0LL;
}
if ( !v2 )
return 0LL;
v2(a1, 0xFFFFFFFFLL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2)
{
__int64 (__fastcall *v2)(__int64, __int64); // rax
__int64 v4; // rsi

v2 = *(__int64 (__fastcall **)(__int64, __int64))(a1 + 808);
if ( a2 )
{
v4 = (unsigned int)*a2;
if ( v2 )
LODWORD(v4) = v2(a1, v4);
*a2 = v4;
return 0LL;
}
if ( !v2 )
return 0LL;
v2(a1, 0xFFFFFFFFLL);
return 0LL;
}

original_code:
int cfg_fdevent_event_set(cfg_fdevents *ev, int *fde_ndx, int fd, int events)
{
 int fde = fde_ndx ? *fde_ndx : -1;
 if (ev->event_set)
  fde = ev->event_set(ev, fde, fd, events);
 if (fde_ndx)
  *fde_ndx = fde;
 return 0;
}

canonical_original_code:
int cfg_fdevent_event_set(struct cfg_fdevents *ev, int *fde_ndx, int fd, int events)
{
 int fde = fde_ndx ? *fde_ndx : -1;
 if (ev->event_set)
  fde = ev->event_set(ev, fde, fd, events);
 if (fde_ndx)
  *fde_ndx = fde;
 return 0;
}


decompiled_code:
__int64 __fastcall cfg_fdevent_poll(__int64 a1)
{
__int64 (*v1)(void); // rax

v1 = *(__int64 (**)(void))(a1 + 848);
if ( !v1 )
{
fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 77LL);
abort();
}
return v1();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 (*v1)(void); // rax

v1 = *(__int64 (**)(void))(a1 + 848);
if ( !v1 )
{
fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 77LL);
abort();
}
return v1();
}

original_code:
int cfg_fdevent_poll(cfg_fdevents *ev, int timeout_ms)
{
 if (ev->poll == ((void *)0))
  do { fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 77); abort(); } while(0);
 return ev->poll(ev, timeout_ms);
}

canonical_original_code:
int cfg_fdevent_poll(struct cfg_fdevents *ev, int timeout_ms)
{
 if (ev->poll == ((void *)0))
  do { fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 77); abort(); } while(0);
 return ev->poll(ev, timeout_ms);
}


decompiled_code:
__int64 __fastcall cfg_fdevent_event_get_revent(__int64 a1)
{
__int64 (*v1)(void); // rax

v1 = *(__int64 (**)(void))(a1 + 824);
if ( !v1 )
{
fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 84LL);
abort();
}
return v1();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 (*v1)(void); // rax

v1 = *(__int64 (**)(void))(a1 + 824);
if ( !v1 )
{
fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 84LL);
abort();
}
return v1();
}

original_code:
int cfg_fdevent_event_get_revent(cfg_fdevents *ev, size_t ndx)
{
 if (ev->event_get_revent == ((void *)0))
  do { fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 84); abort(); } while(0);
 return ev->event_get_revent(ev, ndx);
}

canonical_original_code:
int cfg_fdevent_event_get_revent(struct cfg_fdevents *ev, unsigned long ndx)
{
 if (ev->event_get_revent == ((void *)0))
  do { fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 84); abort(); } while(0);
 return ev->event_get_revent(ev, ndx);
}


decompiled_code:
__int64 __fastcall cfg_fdevent_event_get_fd(__int64 a1)
{
__int64 (*v1)(void); // rax

v1 = *(__int64 (**)(void))(a1 + 832);
if ( !v1 )
{
fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 92LL);
abort();
}
return v1();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 (*v1)(void); // rax

v1 = *(__int64 (**)(void))(a1 + 832);
if ( !v1 )
{
fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 92LL);
abort();
}
return v1();
}

original_code:
int cfg_fdevent_event_get_fd(cfg_fdevents *ev, size_t ndx)
{
 if (ev->event_get_fd == ((void *)0))
  do { fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 92); abort(); } while(0);
 return ev->event_get_fd(ev, ndx);
}

canonical_original_code:
int cfg_fdevent_event_get_fd(struct cfg_fdevents *ev, unsigned long ndx)
{
 if (ev->event_get_fd == ((void *)0))
  do { fprintf(stderr, "%s.%d: aborted\n", "cfg_fdevent.c", 92); abort(); } while(0);
 return ev->event_get_fd(ev, ndx);
}


decompiled_code:
__int64 __fastcall cfg_fdevent_event_next_fdndx(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 840);
if ( v1 )
result = v1();
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = *(__int64 (**)(void))(a1 + 840);
if ( v1 )
result = v1();
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int cfg_fdevent_event_next_fdndx(cfg_fdevents *ev, int ndx)
{
 if (ev->event_next_fdndx)
  return ev->event_next_fdndx(ev, ndx);
 return -1;
}

canonical_original_code:
int cfg_fdevent_event_next_fdndx(struct cfg_fdevents *ev, int ndx)
{
 if (ev->event_next_fdndx)
  return ev->event_next_fdndx(ev, ndx);
 return -1;
}


decompiled_code:
__int64 __fastcall dispatch_client_msg(unsigned int a1, const char *a2)
{
printf("server recv msg from cli_fd(%d) : %s\n", a1, a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, const char *a2)
{
printf("server recv msg from cli_fd(%d) : %s\n", a1, a2);
return 1LL;
}

original_code:
int dispatch_client_msg(int cli_fd, void *msg)
{
 printf("server recv msg from cli_fd(%d) : %s\n", cli_fd, (char *)msg);
 return 1;
}

variable_types:
msg
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (int)cfg_ipc_server_start(&server_ev, argv, envp) < 0 )
fwrite("cfg_ipc_server_start failed\n", 1uLL, 0x1CuLL, stderr);
return 0;
}

original_code:
int main()
{
 if (cfg_ipc_server_start(&server_ev) < 0)
  fprintf(stderr, "cfg_ipc_server_start failed\n");
 return 0;
}


decompiled_code:
int signal_init()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)1;
memset(&v1.sa_mask, 0, 0x90uLL);
sigaction(13, &v1, 0LL);
return sigaction(10, &v1, 0LL);
}

canonical_decompiled_code:
int func7()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)1;
memset(&v1.sa_mask, 0, 0x90uLL);
sigaction(13, &v1, 0LL);
return sigaction(10, &v1, 0LL);
}

original_code:
static void signal_init(void)
{
 struct sigaction act;
 memset(&act, 0, sizeof(act));
 act.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
 sigaction(13, &act, ((void *)0));
 sigaction(10, &act, ((void *)0));
}

canonical_original_code:
static void signal_init()
{
 struct sigaction act;
 memset(&act, 0, sizeof(act));
 act.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
 sigaction(13, &act, ((void *)0));
 sigaction(10, &act, ((void *)0));
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


swriten

decompiled_code:
size_t __fastcall swriten(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx
int v8; // eax

v3 = n;
v5 = n;
if ( !n )
return v3;
while ( 1 )
{
while ( 1 )
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
v5 -= v6;
buf = (char *)buf + v6;
if ( !v5 )
return v3;
}
if ( !v6 )
break;
v8 = *__errno_location();
if ( v8 == 11 )
break;
if ( v8 != 4 )
{
v5 -= v7;
buf = (char *)buf + v7;
if ( !v5 )
return v3;
}
}
return -1LL;
}

canonical_decompiled_code:
size_t __fastcall func9(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx
int v8; // eax

v3 = n;
v5 = n;
if ( !n )
return v3;
while ( 1 )
{
while ( 1 )
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
break;
v5 -= v6;
buf = (char *)buf + v6;
if ( !v5 )
return v3;
}
if ( !v6 )
break;
v8 = *__errno_location();
if ( v8 == 11 )
break;
if ( v8 != 4 )
{
v5 -= v7;
buf = (char *)buf + v7;
if ( !v5 )
return v3;
}
}
return -1LL;
}

original_code:
ssize_t swriten(int fd, const void *vptr, size_t n)
{
 size_t nleft;
 ssize_t nwritten;
 const char *ptr;
 ptr = vptr;
 nleft = n;
 while (nleft > 0)
 {
  if ( (nwritten = write(fd, ptr, nleft)) <= 0)
  {
   if (nwritten < 0)
   {
    if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
    {
     return (-1);
    }
    else if ((*__errno_location ()) == 4)
    {
     nwritten = 0;
    }
   }
   else
   {
    return(-1);
   }
  }
  nleft -= nwritten;
  ptr += nwritten;
 }
 return(n);
}

canonical_original_code:
long swriten(int fd, void *vptr, unsigned long n)
{
 unsigned long nleft;
 long nwritten;
 char *ptr;
 ptr = vptr;
 nleft = n;
 while (nleft > 0)
 {
  if ( (nwritten = write(fd, ptr, nleft)) <= 0)
  {
   if (nwritten < 0)
   {
    if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11)
    {
     return (-1);
    }
    else if ((*__errno_location ()) == 4)
    {
     nwritten = 0;
    }
   }
   else
   {
    return(-1);
   }
  }
  nleft -= nwritten;
  ptr += nwritten;
 }
 return(n);
}

variable_types:
vptr
void *

variable_types:
n
unsigned long

variable_types:
nleft
unsigned long

variable_types: nwritten long

variable_types:
ptr
char *

return_type: long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
__pid_t v5; // eax
unsigned int v7; // eax
int v8; // eax
__int64 v9; // r8
int v10; // ebp
__int128 v11[8]; // [rsp+0h] [rbp-498h] BYREF
char s[1024]; // [rsp+80h] [rbp-418h] BYREF
__int64 v13; // [rsp+480h] [rbp-18h] BYREF

*(_OWORD *)s = 0LL;
memset(&s[16], 0, 0x3F0uLL);
v11[0] = 0LL;
v11[1] = 0LL;
v11[2] = 0LL;
v11[3] = 0LL;
v11[4] = 0LL;
v11[5] = 0LL;
v11[6] = 0LL;
v11[7] = 0LL;
signal_init(&v13, argv, envp);
v3 = getpid();
sprintf((char *)v11, "%05d.socket", v3);
v4 = client_conn_constprop_0((char *)v11);
v5 = fork();
if ( v5 < 0 )
{
fprintf(stderr, "%s %s %d:fork error\n", "cfg_ipc_client.c", "main", 136LL);
}
else if ( !v5 )
{
v7 = getpid();
sprintf((char *)v11, "%05d.socket", v7);
v8 = client_conn_constprop_0((char *)v11);
v9 = 144LL;
v10 = v8;
if ( v8 >= 0 )
{
memset(s, 0, sizeof(s));
sprintf(s, "client_name %s", v11, 0LL, 144LL);
write(v10, s, 0x400uLL);
close(v10);
unlink((const char *)v11);
exit(0);
}
goto LABEL_9;
}
if ( v4 >= 0 )
{
sprintf(s, "client_name %s", (const char *)v11);
swriten(v4, s, 0x400uLL);
close(v4);
unlink((const char *)v11);
return 0;
}
v9 = 160LL;
LABEL_9:
fprintf(stderr, "%s %s %d:create server unix domain socket error\n", "cfg_ipc_client.c", "main", v9);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebp
__pid_t v5; // eax
unsigned int v7; // eax
int v8; // eax
__int64 v9; // r8
int v10; // ebp
__int128 v11[8]; // [rsp+0h] [rbp-498h] BYREF
char s[1024]; // [rsp+80h] [rbp-418h] BYREF
__int64 v13; // [rsp+480h] [rbp-18h] BYREF

*(_OWORD *)s = 0LL;
memset(&s[16], 0, 0x3F0uLL);
v11[0] = 0LL;
v11[1] = 0LL;
v11[2] = 0LL;
v11[3] = 0LL;
v11[4] = 0LL;
v11[5] = 0LL;
v11[6] = 0LL;
v11[7] = 0LL;
func7(&v13, argv, envp);
v3 = getpid();
sprintf((char *)v11, "%05d.socket", v3);
v4 = func8((char *)v11);
v5 = fork();
if ( v5 < 0 )
{
fprintf(stderr, "%s %s %d:fork error\n", "cfg_ipc_client.c", "main", 136LL);
}
else if ( !v5 )
{
v7 = getpid();
sprintf((char *)v11, "%05d.socket", v7);
v8 = func8((char *)v11);
v9 = 144LL;
v10 = v8;
if ( v8 >= 0 )
{
memset(s, 0, sizeof(s));
sprintf(s, "client_name %s", v11, 0LL, 144LL);
write(v10, s, 0x400uLL);
close(v10);
unlink((const char *)v11);
exit(0);
}
goto LABEL_9;
}
if ( v4 >= 0 )
{
sprintf(s, "client_name %s", (const char *)v11);
func9(v4, s, 0x400uLL);
close(v4);
unlink((const char *)v11);
return 0;
}
v9 = 160LL;
LABEL_9:
fprintf(stderr, "%s %s %d:create server unix domain socket error\n", "cfg_ipc_client.c", "main", v9);
return -1;
}

original_code:
int main()
{
 int fd;
 char buf[1024] = {0};
 char client_name[128] = {0};
 pid_t pid;
 signal_init();
 sprintf(client_name, "%05d.socket", getpid());
 fd = client_conn("main.socket", client_name);
 pid = fork();
 if (pid < 0)
 {
  fprintf(stderr, "%s %s %d:" "fork error\n", "cfg_ipc_client.c", __FUNCTION__, 136);;
 }
 else if (pid == 0)
 {
  sprintf(client_name, "%05d.socket", getpid());
  fd = client_conn("main.socket", client_name);
  if (fd < 0)
  {
   fprintf(stderr, "%s %s %d:" "create server unix domain socket error\n", "cfg_ipc_client.c", __FUNCTION__, 144);;
   return -1;
  }
  memset(buf, 0 ,sizeof(buf));
  sprintf(buf, "client_name %s", client_name);
  write(fd, buf, sizeof(buf));
  close(fd);
  unlink(client_name);
  exit(0);
 }
 if (fd < 0)
 {
  fprintf(stderr, "%s %s %d:" "create server unix domain socket error\n", "cfg_ipc_client.c", __FUNCTION__, 160);;
  return -1;
 }
 sprintf(buf, "client_name %s", client_name);
 swriten(fd, buf, sizeof(buf));
 close(fd);
 unlink(client_name);
 return 0;
}

canonical_original_code:
int main()
{
 int fd;
 char buf[1024] = {0};
 char client_name[128] = {0};
 int pid;
 signal_init();
 sprintf(client_name, "%05d.socket", getpid());
 fd = client_conn("main.socket", client_name);
 pid = fork();
 if (pid < 0)
 {
  fprintf(stderr, "%s %s %d:" "fork error\n", "cfg_ipc_client.c", __FUNCTION__, 136);;
 }
 else if (pid == 0)
 {
  sprintf(client_name, "%05d.socket", getpid());
  fd = client_conn("main.socket", client_name);
  if (fd < 0)
  {
   fprintf(stderr, "%s %s %d:" "create server unix domain socket error\n", "cfg_ipc_client.c", __FUNCTION__, 144);;
   return -1;
  }
  memset(buf, 0 ,sizeof(buf));
  sprintf(buf, "client_name %s", client_name);
  write(fd, buf, sizeof(buf));
  close(fd);
  unlink(client_name);
  exit(0);
 }
 if (fd < 0)
 {
  fprintf(stderr, "%s %s %d:" "create server unix domain socket error\n", "cfg_ipc_client.c", __FUNCTION__, 160);;
  return -1;
 }
 sprintf(buf, "client_name %s", client_name);
 swriten(fd, buf, sizeof(buf));
 close(fd);
 unlink(client_name);
 return 0;
}

variable_types:
buf
char [1024]

variable_types: pid int


repo: lynix/aerotools

decompiled_code:
char *__fastcall aq_strcat(void *src, void *a2)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // r12

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
memcpy(v4, src, v2);
memcpy(&v5[v2], a2, v3 + 1);
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func0(void *src, void *a2)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // r12

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
memcpy(v4, src, v2);
memcpy(&v5[v2], a2, v3 + 1);
}
return v5;
}

original_code:
char *aq_strcat(char *str1, char *str2)
{
 char *ret;
 if ((ret = malloc(strlen(str1) + strlen(str2) + 1)) == ((void *)0))
  return ((void *)0);
 strcpy(ret, str1);
 strcpy(ret + strlen(str1), str2);
 return ret;
}

variable_types:
ret
char *

return_type: char *


decompiled_code:
const char *__fastcall aq_libusb_strerr(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 + 99);
result = "unknown error";
if ( (unsigned int)v1 <= 0x63 )
result = CSWTCH_79[v1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 + 99);
result = "unknown error";
if ( (unsigned int)v1 <= 0x63 )
result = CSWTCH_79[v1];
return result;
}

original_code:
char *aq_libusb_strerr(int err)
{
 switch (err) {
  case LIBUSB_SUCCESS: return "success";;
  case LIBUSB_ERROR_IO: return "I/O error";;
  case LIBUSB_ERROR_INVALID_PARAM: return "invalid parameter";;
  case LIBUSB_ERROR_ACCESS: return "access denied";;
  case LIBUSB_ERROR_NO_DEVICE: return "no such device";;
  case LIBUSB_ERROR_NOT_FOUND: return "entity not found";;
  case LIBUSB_ERROR_BUSY: return "resource busy";;
  case LIBUSB_ERROR_TIMEOUT: return "operation timed out";;
  case LIBUSB_ERROR_OVERFLOW: return "overflow";;
  case LIBUSB_ERROR_PIPE: return "pipe error";;
  case LIBUSB_ERROR_INTERRUPTED: return "syscall interrupted";;
  case LIBUSB_ERROR_NO_MEM: return "insufficient memory";;
  case LIBUSB_ERROR_NOT_SUPPORTED: return "operation not supported";;
  case LIBUSB_ERROR_OTHER: return "other error";;
 }
 return "unknown error";;
}

variable_types: err int


original_code:
void aq_get_device(aq_device *device)
{
 device->name = strdup((char *)aq_data_buffer + 0x079);
 device->fw_name = strdup((char *)aq_data_buffer + 0x1f9);
 device->prod_month = aq_data_buffer[0x20a];
 device->prod_year = aq_data_buffer[0x20b];
 device->serial = ((*(aq_data_buffer + (0x208)) << 8) + *(aq_data_buffer + (0x208) + 1));
 device->flash_count = ((*(aq_data_buffer + (0x204)) << 8) + *(aq_data_buffer + (0x204) + 1));
 device->os_version = ((*(aq_data_buffer + (0x200)) << 8) + *(aq_data_buffer + (0x200) + 1));
 device->language = strdup((char *)aq_data_buffer + 0x20c);
 device->profile = aq_data_buffer[0x082] + 1;
 device->time_h = aq_data_buffer[0x171];
 device->time_m = aq_data_buffer[0x172];
 device->time_s = aq_data_buffer[0x173];
 device->time_d = aq_data_buffer[0x174];
}

canonical_original_code:
void aq_get_device(struct aq_device *device)
{
 device->name = strdup((char *)aq_data_buffer + 0x079);
 device->fw_name = strdup((char *)aq_data_buffer + 0x1f9);
 device->prod_month = aq_data_buffer[0x20a];
 device->prod_year = aq_data_buffer[0x20b];
 device->serial = ((*(aq_data_buffer + (0x208)) << 8) + *(aq_data_buffer + (0x208) + 1));
 device->flash_count = ((*(aq_data_buffer + (0x204)) << 8) + *(aq_data_buffer + (0x204) + 1));
 device->os_version = ((*(aq_data_buffer + (0x200)) << 8) + *(aq_data_buffer + (0x200) + 1));
 device->language = strdup((char *)aq_data_buffer + 0x20c);
 device->profile = aq_data_buffer[0x082] + 1;
 device->time_h = aq_data_buffer[0x171];
 device->time_m = aq_data_buffer[0x172];
 device->time_s = aq_data_buffer[0x173];
 device->time_d = aq_data_buffer[0x174];
}

variable_types: struct aq_device { char *name; char *fw_name; char *language; unsigned char profile; unsigned char prod_year; unsigned char prod_month; unsigned char time_h; unsigned char time_m; unsigned char time_s; unsigned char time_d; unsigned short os_version; unsigned short serial; unsigned short flash_count; } *


decompiled_code:
__int64 __fastcall aq_get_fan(__int64 a1, __int16 a2)
{
unsigned __int8 *v2; // r12
__int64 result; // rax

v2 = (unsigned __int8 *)aq_data_buffer;
*(_QWORD *)a1 = strdup((const char *)aq_data_buffer + 11 * a2);
*(_BYTE *)(a1 + 8) = 100 * (unsigned int)v2[a2 + 198] / 0xFF;
result = (v2[2 * a2 + 442] << 8) + (unsigned int)v2[2 * a2 + 443];
*(_WORD *)(a1 + 10) = (v2[2 * a2 + 442] << 8) + v2[2 * a2 + 443];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int16 a2)
{
unsigned __int8 *v2; // r12
__int64 result; // rax

v2 = (unsigned __int8 *)aq_data_buffer;
*(_QWORD *)a1 = strdup((const char *)aq_data_buffer + 11 * a2);
*(_BYTE *)(a1 + 8) = 100 * (unsigned int)v2[a2 + 198] / 0xFF;
result = (v2[2 * a2 + 442] << 8) + (unsigned int)v2[2 * a2 + 443];
*(_WORD *)(a1 + 10) = (v2[2 * a2 + 442] << 8) + v2[2 * a2 + 443];
return result;
}

original_code:
void aq_get_fan(aq_fan *fan, short num)
{
 fan->name = strdup((char *)aq_data_buffer + 0x000 +
   (num * (10 + 1)));
 fan->duty = aq_data_buffer[0x0c6 + (num * 1)]
              * 100 / 0xff;
 fan->rpm = ((*(aq_data_buffer + (0x1ba + (num * 2))) << 8) + *(aq_data_buffer + (0x1ba + (num * 2)) + 1));
}

canonical_original_code:
void aq_get_fan(struct aq_fan *fan, short num)
{
 fan->name = strdup((char *)aq_data_buffer + 0x000 +
   (num * (10 + 1)));
 fan->duty = aq_data_buffer[0x0c6 + (num * 1)]
              * 100 / 0xff;
 fan->rpm = ((*(aq_data_buffer + (0x1ba + (num * 2))) << 8) + *(aq_data_buffer + (0x1ba + (num * 2)) + 1));
}

variable_types: struct aq_fan { char *name; unsigned char duty; unsigned short rpm; } *

variable_types: num short


decompiled_code:
bool __fastcall aq_get_temp(__int64 a1, __int16 a2)
{
unsigned __int8 *v2; // r12
double v3; // xmm0_8
bool result; // al

v2 = (unsigned __int8 *)aq_data_buffer;
*(_QWORD *)a1 = strdup((const char *)aq_data_buffer + 11 * a2 + 55);
v3 = (double)((v2[2 * a2 + 460] << 8) + v2[2 * a2 + 461]) / 10.0;
*(double *)(a1 + 8) = v3;
result = v3 != 2000.0;
*(_BYTE *)(a1 + 16) = v3 != 2000.0;
return result;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1, __int16 a2)
{
unsigned __int8 *v2; // r12
double v3; // xmm0_8
bool result; // al

v2 = (unsigned __int8 *)aq_data_buffer;
*(_QWORD *)a1 = strdup((const char *)aq_data_buffer + 11 * a2 + 55);
v3 = (double)((v2[2 * a2 + 460] << 8) + v2[2 * a2 + 461]) / 10.0;
*(double *)(a1 + 8) = v3;
result = v3 != 2000.0;
*(_BYTE *)(a1 + 16) = v3 != 2000.0;
return result;
}

original_code:
void aq_get_temp(aq_temp *temp, short num)
{
 temp->name = strdup((char *)aq_data_buffer + 0x037 +
   (num * (10 + 1)));
 temp->value = (double)((*(aq_data_buffer + (0x1cc + (num * 2))) << 8) + *(aq_data_buffer + (0x1cc + (num * 2)) + 1)) /
     10.0;
 temp->connected = (temp->value != 0x7d0);
}

canonical_original_code:
void aq_get_temp(struct aq_temp *temp, short num)
{
 temp->name = strdup((char *)aq_data_buffer + 0x037 +
   (num * (10 + 1)));
 temp->value = (double)((*(aq_data_buffer + (0x1cc + (num * 2))) << 8) + *(aq_data_buffer + (0x1cc + (num * 2)) + 1)) /
     10.0;
 temp->connected = (temp->value != 0x7d0);
}

variable_types: struct aq_temp { char *name; double value; char connected; } *


decompiled_code:
bool __fastcall aq_get_flow(__int64 a1)
{
unsigned __int8 *v1; // rbp
double v2; // xmm0_8
bool result; // al

v1 = (unsigned __int8 *)aq_data_buffer;
*(_QWORD *)a1 = strdup((const char *)aq_data_buffer + 44);
v2 = (double)(v1[451] + (v1[450] << 8)) / 100.0;
*(double *)(a1 + 8) = v2;
result = v2 != 200.0;
*(_BYTE *)(a1 + 16) = v2 != 200.0;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(__int64 a1)
{
unsigned __int8 *v1; // rbp
double v2; // xmm0_8
bool result; // al

v1 = (unsigned __int8 *)aq_data_buffer;
*(_QWORD *)a1 = strdup((const char *)aq_data_buffer + 44);
v2 = (double)(v1[451] + (v1[450] << 8)) / 100.0;
*(double *)(a1 + 8) = v2;
result = v2 != 200.0;
*(_BYTE *)(a1 + 16) = v2 != 200.0;
return result;
}

original_code:
void aq_get_flow(aq_flow *flow)
{
 flow->name = strdup((char *)aq_data_buffer + 0x02c);
 flow->value = (double)((*(aq_data_buffer + (0x1c2)) << 8) + *(aq_data_buffer + (0x1c2) + 1)) / 100.0;
 flow->connected = (flow->value != 0x0c8);
}

canonical_original_code:
void aq_get_flow(struct aq_flow *flow)
{
 flow->name = strdup((char *)aq_data_buffer + 0x02c);
 flow->value = (double)((*(aq_data_buffer + (0x1c2)) << 8) + *(aq_data_buffer + (0x1c2) + 1)) / 100.0;
 flow->connected = (flow->value != 0x0c8);
}

variable_types: struct aq_flow { char *name; double value; char connected; } *


decompiled_code:
__int64 __fastcall aquaero_init(char **a1)
{
__int64 result; // rax

if ( (unsigned int)libusb_init(0LL) )
{
*a1 = "failed to initialize libusb";
result = 0xFFFFFFFFLL;
}
else
{
aq_data_buffer = calloc(0x228uLL, 1uLL);
if ( aq_data_buffer )
{
aq_usb_dev = aq_dev_find();
if ( aq_usb_dev )
{
result = aq_dev_init(a1);
if ( (_DWORD)result )
{
free(aq_data_buffer);
libusb_unref_device(aq_usb_dev);
aq_usb_dev = 0LL;
libusb_exit(0LL);
result = 0xFFFFFFFFLL;
}
}
else
{
*a1 = "no aquaero(R) device found";
free(aq_data_buffer);
libusb_exit(0LL);
result = 0xFFFFFFFFLL;
}
}
else
{
*a1 = "failed to allocate data buffer";
libusb_exit(0LL);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char **a1)
{
__int64 result; // rax

if ( (unsigned int)libusb_init(0LL) )
{
*a1 = "failed to initialize libusb";
result = 0xFFFFFFFFLL;
}
else
{
aq_data_buffer = calloc(0x228uLL, 1uLL);
if ( aq_data_buffer )
{
aq_usb_dev = func6();
if ( aq_usb_dev )
{
result = func7(a1);
if ( (_DWORD)result )
{
free(aq_data_buffer);
libusb_unref_device(aq_usb_dev);
aq_usb_dev = 0LL;
libusb_exit(0LL);
result = 0xFFFFFFFFLL;
}
}
else
{
*a1 = "no aquaero(R) device found";
free(aq_data_buffer);
libusb_exit(0LL);
result = 0xFFFFFFFFLL;
}
}
else
{
*a1 = "failed to allocate data buffer";
libusb_exit(0LL);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int aquaero_init(char **err_msg)
{
 if (libusb_init(((void *)0)) != 0) {
  *err_msg = "failed to initialize libusb";
  return -1;
 }
 if ((aq_data_buffer = calloc(552, 1)) == ((void *)0)) {
  *err_msg = "failed to allocate data buffer";
  libusb_exit(((void *)0));
  return -1;
 }
 if ((aq_usb_dev = aq_dev_find()) == ((void *)0)) {
  *err_msg = "no aquaero(R) device found";
  free(aq_data_buffer);
  libusb_exit(((void *)0));
  return -1;
 }
 if (aq_dev_init(err_msg) != 0) {
  free(aq_data_buffer);
  libusb_unref_device(aq_usb_dev);
  aq_usb_dev = ((void *)0);
  libusb_exit(((void *)0));
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall aquaero_poll_data(__int64 a1, char **a2)
{
__int64 v3; // rbp
int v4; // ebx
__int16 v5; // si
__int64 v6; // rdi
__int64 result; // rax

if ( aq_data_buffer && aq_usb_dev )
{
if ( (int)aq_dev_poll(a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v3 = a1 + 104;
v4 = 0;
aq_get_device(a1);
aq_get_fan(a1 + 40, 0);
aq_get_fan(a1 + 56, 1);
aq_get_fan(a1 + 72, 2);
aq_get_fan(a1 + 88, 3);
do
{
v5 = v4;
v6 = v3;
++v4;
v3 += 24LL;
aq_get_temp(v6, v5);
}
while ( v4 != 6 );
aq_get_flow(a1 + 248);
result = 0LL;
}
}
else
{
*a2 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char **a2)
{
__int64 v3; // rbp
int v4; // ebx
__int16 v5; // si
__int64 v6; // rdi
__int64 result; // rax

if ( aq_data_buffer && aq_usb_dev )
{
if ( (int)func8(a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v3 = a1 + 104;
v4 = 0;
func2(a1);
func3(a1 + 40, 0);
func3(a1 + 56, 1);
func3(a1 + 72, 2);
func3(a1 + 88, 3);
do
{
v5 = v4;
v6 = v3;
++v4;
v3 += 24LL;
func4(v6, v5);
}
while ( v4 != 6 );
func5(a1 + 248);
result = 0LL;
}
}
else
{
*a2 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int aquaero_poll_data(aquaero_data *aq_data, char **err_msg)
{
 int i;
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_get_device(&aq_data->device);
 for (i = 0; i < 4; i++)
  aq_get_fan(&aq_data->fans[i], i);
 for (i = 0; i < 6; i++)
  aq_get_temp(&aq_data->temps[i], i);
 aq_get_flow(&aq_data->flow);
 return 0;
}

canonical_original_code:
int aquaero_poll_data(struct aquaero_data *aq_data, char **err_msg)
{
 int i;
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_get_device(&aq_data->device);
 for (i = 0; i < 4; i++)
  aq_get_fan(&aq_data->fans[i], i);
 for (i = 0; i < 6; i++)
  aq_get_temp(&aq_data->temps[i], i);
 aq_get_flow(&aq_data->flow);
 return 0;
}

variable_types: struct aquaero_data { struct aq_device { char *name; char *fw_name; char *language; unsigned char profile; unsigned char prod_year; unsigned char prod_month; unsigned char time_h; unsigned char time_m; unsigned char time_s; unsigned char time_d; unsigned short os_version; unsigned short serial; unsigned short flash_count; } device; struct aq_fan { char *name; unsigned char duty; unsigned short rpm; } fans[4]; struct aq_temp { char *name; double value; char connected; } temps[6]; struct aq_flow { char *name; double value; char connected; } flow; } *

variable_types: i int

user_defined_types: struct aquaero_data { struct aq_device device; struct aq_fan fans[4]; struct aq_temp temps[6]; struct aq_flow flow; }


decompiled_code:
__int64 __fastcall aquaero_load_profile(char a1, char **a2)
{
__int64 result; // rax

if ( aq_data_buffer && aq_usb_dev )
{
if ( (unsigned __int8)(a1 - 1) > 1u )
{
*a2 = "invalid profile number";
result = 0xFFFFFFFFLL;
}
else if ( (int)aq_dev_poll(a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*((_BYTE *)aq_data_buffer + 130) = a1 - 1;
result = (unsigned int)((int)aq_dev_push(107, a2) >> 31);
}
}
else
{
*a2 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char a1, char **a2)
{
__int64 result; // rax

if ( aq_data_buffer && aq_usb_dev )
{
if ( (unsigned __int8)(a1 - 1) > 1u )
{
*a2 = "invalid profile number";
result = 0xFFFFFFFFLL;
}
else if ( (int)func8(a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
*((_BYTE *)aq_data_buffer + 130) = a1 - 1;
result = (unsigned int)((int)func9(107, a2) >> 31);
}
}
else
{
*a2 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int aquaero_load_profile(aq_byte profile, char **err_msg)
{
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (profile > 2 || profile == 0) {
  *err_msg = "invalid profile number";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_data_buffer[0x082] = profile - 1;
 if (aq_dev_push(AQ_REQ_PROFILE, err_msg) < 0)
  return -1;
 return 0;
}

canonical_original_code:
int aquaero_load_profile(unsigned char profile, char **err_msg)
{
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (profile > 2 || profile == 0) {
  *err_msg = "invalid profile number";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_data_buffer[0x082] = profile - 1;
 if (aq_dev_push(AQ_REQ_PROFILE, err_msg) < 0)
  return -1;
 return 0;
}

variable_types:
profile
unsigned char


decompiled_code:
__int64 __fastcall aquaero_set_time(char a1, char a2, char a3, char a4, char **a5)
{
_BYTE *v8; // rax
__int64 result; // rax

if ( aq_data_buffer && aq_usb_dev )
{
if ( (int)aq_dev_poll(a5) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v8 = aq_data_buffer;
*((_BYTE *)aq_data_buffer + 369) = a1;
v8[370] = a2;
v8[371] = a3;
v8[372] = a4;
result = (unsigned int)((int)aq_dev_push(103, a5) >> 31);
}
}
else
{
*a5 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char a1, char a2, char a3, char a4, char **a5)
{
_BYTE *v8; // rax
__int64 result; // rax

if ( aq_data_buffer && aq_usb_dev )
{
if ( (int)func8(a5) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v8 = aq_data_buffer;
*((_BYTE *)aq_data_buffer + 369) = a1;
v8[370] = a2;
v8[371] = a3;
v8[372] = a4;
result = (unsigned int)((int)func9(103, a5) >> 31);
}
}
else
{
*a5 = "uninitialized, call aquaero_init() first";
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int aquaero_set_time(aq_byte h, aq_byte m, aq_byte s, aq_byte d, char **err_msg)
{
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_data_buffer[0x171] = h;
 aq_data_buffer[0x172] = m;
 aq_data_buffer[0x173] = s;
 aq_data_buffer[0x174] = d;
 if (aq_dev_push(AQ_REQ_RAM, err_msg) < 0)
  return -1;
 return 0;
}

canonical_original_code:
int aquaero_set_time(unsigned char h, unsigned char m, unsigned char s, unsigned char d, char **err_msg)
{
 if (aq_data_buffer == ((void *)0) || aq_usb_dev == ((void *)0)) {
  *err_msg = "uninitialized, call aquaero_init() first";
  return -1;
 }
 if (aq_dev_poll(err_msg) < 0)
  return -1;
 aq_data_buffer[0x171] = h;
 aq_data_buffer[0x172] = m;
 aq_data_buffer[0x173] = s;
 aq_data_buffer[0x174] = d;
 if (aq_dev_push(AQ_REQ_RAM, err_msg) < 0)
  return -1;
 return 0;
}

variable_types:
h
unsigned char

variable_types:
m
unsigned char

variable_types:
s
unsigned char

variable_types:
d
unsigned char