statement

decompiled_code:
__int64 __fastcall statement(__int64 a1, __int64 a2)
{
void *v2; // rdi
__int64 v3; // rbp
void *v4; // rax
__int64 result; // rax
__int64 v6; // rbp
void *v7; // rdi
__int64 v8; // rax
__int64 v9; // r12
void *v10; // rax
void *v11; // rax
void *v12; // rdi
__int64 v13; // rax

if ( ifStatementPending() )
return ifStatement();
if ( whileStatementPending() )
return whileStatement();
if ( functionDefPending() )
return functionDef();
if ( check("RETURN") )
{
v2 = (void *)match("RETURN");
free(v2);
v3 = expression((__int64)v2, a2);
v4 = (void *)match("PERIOD");
free(v4);
result = cons("RETURN", v3, 0LL);
}
else
{
v6 = match("VARIABLE");
if ( check("ASSIGN") )
{
v12 = (void *)match("ASSIGN");
free(v12);
v13 = expression((__int64)v12, a2);
v9 = cons("ASSIGN", v6, v13);
}
else
{
v7 = (void *)match("OBRACKET");
free(v7);
v8 = optList((__int64)v7, a2);
v9 = cons("FUNCTION_CALL", v6, v8);
v10 = (void *)match("CBRACKET");
free(v10);
}
v11 = (void *)match("PERIOD");
free(v11);
result = v9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2)
{
void *v2; // rdi
__int64 v3; // rbp
void *v4; // rax
__int64 result; // rax
__int64 v6; // rbp
void *v7; // rdi
__int64 v8; // rax
__int64 v9; // r12
void *v10; // rax
void *v11; // rax
void *v12; // rdi
__int64 v13; // rax

if ( func18() )
return func26();
if ( func19() )
return func27();
if ( func22() )
return func28();
if ( func0("RETURN") )
{
v2 = (void *)func4("RETURN");
free(v2);
v3 = func12((__int64)v2, a2);
v4 = (void *)func4("PERIOD");
free(v4);
result = cons("RETURN", v3, 0LL);
}
else
{
v6 = func4("VARIABLE");
if ( func0("ASSIGN") )
{
v12 = (void *)func4("ASSIGN");
free(v12);
v13 = func12((__int64)v12, a2);
v9 = cons("ASSIGN", v6, v13);
}
else
{
v7 = (void *)func4("OBRACKET");
free(v7);
v8 = func14((__int64)v7, a2);
v9 = cons("FUNCTION_CALL", v6, v8);
v10 = (void *)func4("CBRACKET");
free(v10);
}
v11 = (void *)func4("PERIOD");
free(v11);
result = v9;
}
return result;
}

original_code:
lexeme* statement(void){
    lexeme* s;
 if(ifStatementPending())
  return ifStatement();
 else if(whileStatementPending())
  return whileStatement();
 else if(functionDefPending())
  return functionDef();
 else if(check("RETURN")){
  free(match("RETURN"));
        s = expression();
  free(match("PERIOD"));
  return cons("RETURN", s, ((void *)0));
 }
 else{
  s = match("VARIABLE");
  if(check("ASSIGN")){
   free(match("ASSIGN"));
   s = cons("ASSIGN", s, expression());
  }
  else{
   free(match("OBRACKET"));
   s = cons("FUNCTION_CALL", s, optList());
   free(match("CBRACKET"));
  }
  free(match("PERIOD"));
        return s;
 }
}

canonical_original_code:
struct lexeme *statement(){
    struct lexeme *s;
 if(ifStatementPending())
  return ifStatement();
 else if(whileStatementPending())
  return whileStatement();
 else if(functionDefPending())
  return functionDef();
 else if(check("RETURN")){
  free(match("RETURN"));
        s = expression();
  free(match("PERIOD"));
  return cons("RETURN", s, ((void *)0));
 }
 else{
  s = match("VARIABLE");
  if(check("ASSIGN")){
   free(match("ASSIGN"));
   s = cons("ASSIGN", s, expression());
  }
  else{
   free(match("OBRACKET"));
   s = cons("FUNCTION_CALL", s, optList());
   free(match("CBRACKET"));
  }
  free(match("PERIOD"));
        return s;
 }
}


block

repo: flyingcircle/ProgrammingLanguage

decompiled_code:
__int64 __fastcall block(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 result; // rax
void *v5; // rax

if ( check("SEMICOLON") )
{
v5 = (void *)match("SEMICOLON");
free(v5);
result = 0LL;
}
else
{
v2 = statement((__int64)"SEMICOLON", a2);
v3 = block();
result = cons("BODY", v2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax
__int64 result; // rax
void *v5; // rax

if ( func0("SEMICOLON") )
{
v5 = (void *)func4("SEMICOLON");
free(v5);
result = 0LL;
}
else
{
v2 = func23((__int64)"SEMICOLON", a2);
v3 = func24();
result = cons("BODY", v2, v3);
}
return result;
}

original_code:
lexeme* block(void){
    lexeme* s;
 if(check("SEMICOLON"))
  free(match("SEMICOLON"));
 else{
  s = statement();
  return cons("BODY", s, block());
 }
    return ((void *)0);
}

canonical_original_code:
struct lexeme *block(){
    struct lexeme *s;
 if(check("SEMICOLON"))
  free(match("SEMICOLON"));
 else{
  s = statement();
  return cons("BODY", s, block());
 }
    return ((void *)0);
}

variable_types: struct lexeme { char *type; char *string; int integer; struct lexeme *left; struct lexeme *right; } *


optElse

decompiled_code:
__int64 __fastcall optElse(__int64 a1, __int64 a2)
{
void *v3; // rdi
__int64 v4; // rax

if ( !check("ELSE") )
return 0LL;
v3 = (void *)match("ELSE");
free(v3);
v4 = block((__int64)v3, a2);
return cons("ELSE", v4, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, __int64 a2)
{
void *v3; // rdi
__int64 v4; // rax

if ( !func0("ELSE") )
return 0LL;
v3 = (void *)func4("ELSE");
free(v3);
v4 = func24((__int64)v3, a2);
return cons("ELSE", v4, 0LL);
}

original_code:
lexeme* optElse(void){
 if(check("ELSE")){
  free(match("ELSE"));
  return cons("ELSE", block(), ((void *)0));
 }
    return ((void *)0);
}

canonical_original_code:
struct lexeme *optElse(){
 if(check("ELSE")){
  free(match("ELSE"));
  return cons("ELSE", block(), ((void *)0));
 }
    return ((void *)0);
}

return_type: struct lexeme { char *type; char *string; int integer; struct lexeme *left; struct lexeme *right; } *


ifStatement

decompiled_code:
__int64 __fastcall ifStatement(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rdi
__int64 v4; // rbp
void *v5; // rdi
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax

v2 = (void *)match("IF");
free(v2);
v3 = (void *)match("OBRACKET");
free(v3);
v4 = expression((__int64)v3, a2);
v5 = (void *)match("CBRACKET");
free(v5);
v6 = block((__int64)v5, a2);
v7 = optElse((__int64)v5, a2);
v8 = cons("GLUE", v6, v7);
return cons("IF", v4, v8);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rdi
__int64 v4; // rbp
void *v5; // rdi
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // rax

v2 = (void *)func4("IF");
free(v2);
v3 = (void *)func4("OBRACKET");
free(v3);
v4 = func12((__int64)v3, a2);
v5 = (void *)func4("CBRACKET");
free(v5);
v6 = func24((__int64)v5, a2);
v7 = func25((__int64)v5, a2);
v8 = cons("GLUE", v6, v7);
return cons("IF", v4, v8);
}

original_code:
lexeme* ifStatement(void){
    lexeme* cond, *b, *e;
 free(match("IF"));
 free(match("OBRACKET"));
 cond = expression();
 free(match("CBRACKET"));
 b = block();
 e = optElse();
    return cons("IF", cond, cons("GLUE", b, e));
}

canonical_original_code:
struct lexeme *ifStatement(){
    struct lexeme *cond; struct lexeme *b; struct lexeme *e;
 free(match("IF"));
 free(match("OBRACKET"));
 cond = expression();
 free(match("CBRACKET"));
 b = block();
 e = optElse();
    return cons("IF", cond, cons("GLUE", b, e));
}

user_defined_types: struct lexeme { char *type; char *string; int integer; struct lexeme *left; struct lexeme *right; }


whileStatement

decompiled_code:
__int64 __fastcall whileStatement(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rdi
__int64 v4; // rbp
void *v5; // rdi
__int64 v6; // rax

v2 = (void *)match("WHILE");
free(v2);
v3 = (void *)match("OBRACKET");
free(v3);
v4 = expression((__int64)v3, a2);
v5 = (void *)match("CBRACKET");
free(v5);
v6 = block((__int64)v5, a2);
return cons("WHILE", v4, v6);
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1, __int64 a2)
{
void *v2; // rax
void *v3; // rdi
__int64 v4; // rbp
void *v5; // rdi
__int64 v6; // rax

v2 = (void *)func4("WHILE");
free(v2);
v3 = (void *)func4("OBRACKET");
free(v3);
v4 = func12((__int64)v3, a2);
v5 = (void *)func4("CBRACKET");
free(v5);
v6 = func24((__int64)v5, a2);
return cons("WHILE", v4, v6);
}

original_code:
lexeme* whileStatement(void){
    lexeme* cond;
 free(match("WHILE"));
 free(match("OBRACKET"));
 cond = expression();
 free(match("CBRACKET"));
 return cons("WHILE", cond, block());
}

canonical_original_code:
struct lexeme *whileStatement(){
    struct lexeme *cond;
 free(match("WHILE"));
 free(match("OBRACKET"));
 cond = expression();
 free(match("CBRACKET"));
 return cons("WHILE", cond, block());
}


functionDef

decompiled_code:
__int64 __fastcall functionDef(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3; // rbp
void *v4; // rax
__int64 v5; // r12
void *v6; // rdi
__int64 v7; // rax
__int64 v8; // rax

v2 = (void *)match("FUNCTION");
free(v2);
v3 = match("VARIABLE");
v4 = (void *)match("OBRACKET");
free(v4);
v5 = optArgs();
v6 = (void *)match("CBRACKET");
free(v6);
v7 = block((__int64)v6, a2);
v8 = cons("GLUE", v5, v7);
return cons("FUNCTION_DEF", v3, v8);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3; // rbp
void *v4; // rax
__int64 v5; // r12
void *v6; // rdi
__int64 v7; // rax
__int64 v8; // rax

v2 = (void *)func4("FUNCTION");
free(v2);
v3 = func4("VARIABLE");
v4 = (void *)func4("OBRACKET");
free(v4);
v5 = func21();
v6 = (void *)func4("CBRACKET");
free(v6);
v7 = func24((__int64)v6, a2);
v8 = cons("GLUE", v5, v7);
return cons("FUNCTION_DEF", v3, v8);
}

original_code:
lexeme* functionDef(void){
    lexeme* name, *parameters, *body;
 free(match("FUNCTION"));
 name = match("VARIABLE");
 free(match("OBRACKET"));
 parameters = optArgs();
 free(match("CBRACKET"));
 body = block();
    return cons("FUNCTION_DEF", name, cons("GLUE", parameters, body));
}

canonical_original_code:
struct lexeme *functionDef(){
    struct lexeme *name; struct lexeme *parameters; struct lexeme *body;
 free(match("FUNCTION"));
 name = match("VARIABLE");
 free(match("OBRACKET"));
 parameters = optArgs();
 free(match("CBRACKET"));
 body = block();
    return cons("FUNCTION_DEF", name, cons("GLUE", parameters, body));
}


statementPending

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

if ( ifStatementPending() || whileStatementPending() || functionDefPending() )
result = 1LL;
else
result = check("VARIABLE");
return result;
}

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

if ( func18() || func19() || func22() )
result = 1LL;
else
result = func0("VARIABLE");
return result;
}

original_code:
int statementPending(void){
 return (ifStatementPending() ||
  whileStatementPending() ||
  functionDefPending() ||
  check("VARIABLE"));
}

canonical_original_code:
int statementPending(){
 return (ifStatementPending() ||
  whileStatementPending() ||
  functionDefPending() ||
  check("VARIABLE"));
}

return_type: int


programPending

decompiled_code:
// attributes: thunk
_BOOL8 programPending()
{
return statementPending();
}

canonical_decompiled_code:
_BOOL8 func30()
{
return func29();
}

original_code:
int programPending(void){
 return (statementPending());
}

canonical_original_code:
int programPending(){
 return (statementPending());
}


program

decompiled_code:
__int64 __fastcall program(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = statement(a1, a2);
if ( programPending() )
v3 = program();
else
v3 = match("ENDOFINPUT");
return cons("GLOBAL", v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func31(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = func23(a1, a2);
if ( func30() )
v3 = func31();
else
v3 = func4("ENDOFINPUT");
return cons("GLOBAL", v2, v3);
}

original_code:
lexeme* program(void){
    lexeme* s;
 s = statement();
 if(programPending())
  return cons("GLOBAL", s, program());
 else
  return cons("GLOBAL", s, match("ENDOFINPUT"));
}

canonical_original_code:
struct lexeme *program(){
    struct lexeme *s;
 s = statement();
 if(programPending())
  return cons("GLOBAL", s, program());
 else
  return cons("GLOBAL", s, match("ENDOFINPUT"));
}


car

decompiled_code:
__int64 __fastcall car(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
lexeme* car(lexeme* parent){
    return parent->left;
}

canonical_original_code:
struct lexeme *car(struct lexeme *parent){
    return parent->left;
}

variable_types:
parent
struct lexeme *


cdr

decompiled_code:
__int64 __fastcall cdr(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
lexeme* cdr(lexeme* parent){
    return parent->right;
}

canonical_original_code:
struct lexeme *cdr(struct lexeme *parent){
    return parent->right;
}


setCar

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

result = *(_QWORD *)(a1 + 24);
if ( !strcmp(*(const char **)a1, "NUMBER") )
*(_DWORD *)(result + 16) = *a2;
else
*(_QWORD *)(result + 8) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 24);
if ( !strcmp(*(const char **)a1, "NUMBER") )
*(_DWORD *)(result + 16) = *a2;
else
*(_QWORD *)(result + 8) = a2;
return result;
}

original_code:
void setCar(lexeme* parent, void* value){
    if(strcmp(parent->type, "NUMBER") == 0){
        int* newValue = (int*) value;
        parent->left->integer = *newValue;
    }
    else{
        parent->left->string = (char*) value;
    }
}

canonical_original_code:
void setCar(struct lexeme *parent, void *value){
    if(strcmp(parent->type, "NUMBER") == 0){
        int *newValue = (int*) value;
        parent->left->integer = *newValue;
    }
    else{
        parent->left->string = (char *) value;
    }
}

variable_types:
value
void *

variable_types:
newValue
int *

return_type: void


setCdr

decompiled_code:
unsigned int *__fastcall setCdr(__int64 a1, unsigned int *a2)
{
__int64 v2; // r8
unsigned int *result; // rax

v2 = *(_QWORD *)(a1 + 32);
result = a2;
if ( !strcmp(*(const char **)v2, "NUMBER") )
{
result = (unsigned int *)*a2;
*(_DWORD *)(v2 + 16) = (_DWORD)result;
}
else
{
*(_QWORD *)(v2 + 8) = a2;
}
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func10(__int64 a1, unsigned int *a2)
{
__int64 v2; // r8
unsigned int *result; // rax

v2 = *(_QWORD *)(a1 + 32);
result = a2;
if ( !strcmp(*(const char **)v2, "NUMBER") )
{
result = (unsigned int *)*a2;
*(_DWORD *)(v2 + 16) = (_DWORD)result;
}
else
{
*(_QWORD *)(v2 + 8) = a2;
}
return result;
}

original_code:
void setCdr(lexeme* parent, void* value){
    if(strcmp(parent->right->type, "NUMBER") == 0){
        int* newValue = (int*) value;
        parent->right->integer = *newValue;
    }
    else{
        parent->right->string = (char*) value;
    }
}

canonical_original_code:
void setCdr(struct lexeme *parent, void *value){
    if(strcmp(parent->right->type, "NUMBER") == 0){
        int *newValue = (int*) value;
        parent->right->integer = *newValue;
    }
    else{
        parent->right->string = (char *) value;
    }
}


recognizer

decompiled_code:
int __fastcall recognizer(__int64 a1, int a2)
{
__int64 v2; // rax

newLexer();
newParser();
v2 = program();
if ( a2 )
prettyPrint(v2);
return puts("legal");
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rax

newLexer();
newParser();
v2 = program();
if ( a2 )
prettyPrint(v2);
return puts("legal");
}

original_code:
void recognizer(char* filename, int graphFlag){
 newLexer(filename);
 newParser();
 lexeme* parseTree = program();
    if(graphFlag)
        prettyPrint(parseTree);
 printf("legal\n");
}

canonical_original_code:
void recognizer(char *filename, int graphFlag){
 newLexer(filename);
 newParser();
 struct lexeme *parseTree = program();
    if(graphFlag)
        prettyPrint(parseTree);
 printf("legal\n");
}

variable_types:
filename
char *

variable_types: graphFlag int


main

canonical_name: main

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

v3 = argv[1];
if ( argc > 2 && !strcmp(argv[2], "--graph") )
recognizer((__int64)v3, 1);
else
recognizer((__int64)v3, 0);
return 0;
}

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

v3 = argv[1];
if ( argc > 2 && !strcmp(argv[2], "--graph") )
func0((__int64)v3, 1);
else
func0((__int64)v3, 0);
return 0;
}

original_code:
int main( int argc, char* argv[]){
    if(argc > 2 && strcmp(argv[2], "--graph") == 0)
     recognizer(argv[1], 1);
    else
        recognizer(argv[1], 0);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    if(argc > 2 && strcmp(argv[2], "--graph") == 0)
     recognizer(argv[1], 1);
    else
        recognizer(argv[1], 0);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


freeNode

decompiled_code:
// attributes: thunk
void freeNode(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void freeNode(Node* node){
    free(node);
}

canonical_original_code:
void freeNode(struct Node *node){
    free(node);
}

variable_types: struct Node { void *data; struct Node *next; } *


getNext

decompiled_code:
__int64 __fastcall getNext(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
Node* getNext(Node* node){
    return node->next;
}

canonical_original_code:
struct Node *getNext(struct Node *node){
    return node->next;
}

variable_types:
node
struct Node *

return_type: struct Node { void *data; struct Node *next; } *


setNext

decompiled_code:
void __fastcall setNext(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
}

original_code:
void setNext(Node* node, Node* nextNode){
    node->next = nextNode;
}

canonical_original_code:
void setNext(struct Node *node, struct Node *nextNode){
    node->next = nextNode;
}

variable_types:
nextNode
struct Node *

user_defined_types: struct Node { void *data; struct Node *next; }


newList

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

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

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

result = malloc(0x10uLL);
result[2] = 0;
*(_QWORD *)result = 0LL;
return result;
}

original_code:
List* newList(void){
    List* list = (List*) malloc(sizeof(List));
    list->size = 0;
    list->head = ((void *)0);
    return list;
}

canonical_original_code:
struct List *newList(){
    struct List *list = (List*) malloc(sizeof(List));
    list->size = 0;
    list->head = ((void *)0);
    return list;
}

variable_types: struct List { struct Node { void *data; struct Node *next; } *head; int size; } *

user_defined_types: struct List { struct Node *head; int size; }


freeList

decompiled_code:
void __fastcall freeList(void *ptr)
{
while ( *(_QWORD *)ptr )
deleteHead((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
while ( *(_QWORD *)ptr )
func1((__int64)ptr);
free(ptr);
}

original_code:
void freeList(List* list){
    while(list->head != ((void *)0)){
        deleteHead(list);
    }
    free(list);
}

canonical_original_code:
void freeList(struct List *list){
    while(list->head != ((void *)0)){
        deleteHead(list);
    }
    free(list);
}


prepend

decompiled_code:
__int64 __fastcall prepend(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax

v2 = newNode(a2);
result = setNext(*(_QWORD *)(v2 + 8), *(_QWORD *)a1);
*(_QWORD *)a1 = v2;
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax

v2 = newNode(a2);
result = setNext(*(_QWORD *)(v2 + 8), *(_QWORD *)a1);
*(_QWORD *)a1 = v2;
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void prepend(List* list, void* value){
    Node* node = newNode(value);
    setNext(node->next, list->head);
    list->head = node;
    list->size += 1;
}

canonical_original_code:
void prepend(struct List *list, void *value){
    struct Node *node = newNode(value);
    setNext(node->next, list->head);
    list->head = node;
    list->size += 1;
}


size

decompiled_code:
__int64 __fastcall size(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int size(List* list){
    return list->size;
}

canonical_original_code:
int size(struct List *list){
    return list->size;
}


searchlist

repo: fmertz/sdeclcd

decompiled_code:
__int64 __fastcall searchlist(__int64 a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == a2 )
break;
a1 = *(_QWORD *)(a1 + 16);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == a2 )
break;
a1 = *(_QWORD *)(a1 + 16);
}
return a1;
}

original_code:
static struct service *searchlist(struct service *servicebase, int number)
{
    struct service *item;
    for (item = servicebase; item != ((void *)0); item = item->next) {
 if (item->number == number)
     return (item);
    }
    return (((void *)0));
}

variable_types:
servicebase
struct service *

variable_types: number int

variable_types: struct service { int number; char *name; struct service *next; } *


decompiled_code:
char *__fastcall INET_print(struct in_addr *a1)
{
return inet_ntoa((struct in_addr)a1->s_addr);
}

canonical_decompiled_code:
char *__fastcall func2(struct in_addr *a1)
{
return inet_ntoa((struct in_addr)a1->s_addr);
}

original_code:
static char *INET_print(unsigned char *ptr)
{
    return (inet_ntoa((*(struct in_addr *) ptr)));
}

variable_types:
ptr
unsigned char *

return_type: char *


decompiled_code:
__int64 __fastcall INET_getnetmask(const char *a1, __int64 a2, char *a3)
{
char *v4; // rax
unsigned int v5; // er8
unsigned int v6; // eax
char v7; // r12
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = strchr(a1, 47);
v5 = 0;
if ( v4 )
{
*v4 = 0;
v6 = strtoul(v4 + 1, &endptr, 0);
v5 = -1;
v7 = v6;
if ( !*endptr )
{
if ( a3 )
sprintf(a3, "/%d", v6);
*(_WORD *)a2 = 2;
*(_DWORD *)(a2 + 4) = _bswap_32(~(0xFFFFFFFF >> v7));
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2, char *a3)
{
char *v4; // rax
unsigned int v5; // er8
unsigned int v6; // eax
char v7; // r12
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = strchr(a1, 47);
v5 = 0;
if ( v4 )
{
*v4 = 0;
v6 = strtoul(v4 + 1, &endptr, 0);
v5 = -1;
v7 = v6;
if ( !*endptr )
{
if ( a3 )
sprintf(a3, "/%d", v6);
*(_WORD *)a2 = 2;
*(_DWORD *)(a2 + 4) = func3(~(0xFFFFFFFF >> v7));
}
}
return v5;
}

original_code:
static int INET_getnetmask(char *adr, struct sockaddr *m, char *name)
{
    struct sockaddr_in *mask = (struct sockaddr_in *) m;
    char *slash, *end;
    int prefix;
    if ((slash = strchr(adr, '/')) == ((void *)0))
 return 0;
    *slash++ = '\0';
    prefix = strtoul(slash, &end, 0);
    if (*end != '\0')
 return -1;
    if (name) {
 sprintf(name, "/%d", prefix);
    }
    mask->sin_family = 2;
    mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix));
    return 1;
}

canonical_original_code:
static int INET_getnetmask(char *adr, struct sockaddr *m, char *name)
{
    struct sockaddr_in *mask = (struct sockaddr_in *) m;
    char *slash; char *end;
    int prefix;
    if ((slash = strchr(adr, '/')) == ((void *)0))
 return 0;
    *slash++ = '\0';
    prefix = strtoul(slash, &end, 0);
    if (*end != '\0')
 return -1;
    if (name) {
 sprintf(name, "/%d", prefix);
    }
    mask->sin_family = 2;
    mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix));
    return 1;
}

variable_types:
adr
char *

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

variable_types:
name
char *

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

variable_types:
slash
char *

variable_types:
end
char *

variable_types: prefix int

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


decompiled_code:
// attributes: thunk
void INET_reserror(const char *str)
{
herror(str);
}

canonical_decompiled_code:
void func5(const char *str)
{
herror(str);
}

original_code:
static void INET_reserror(char *text)
{
    herror(text);
}

variable_types:
text
char *


original_code:
static int INET_getsock(char *bufp, struct sockaddr *sap)
{
    char *sp = bufp, *bp;
    unsigned int i;
    unsigned val;
    struct sockaddr_in *sin;
    sin = (struct sockaddr_in *) sap;
    sin->sin_family = 2;
    sin->sin_port = 0;
    val = 0;
    bp = (char *) &val;
    for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) {
 *sp = toupper(*sp);
 if ((*sp >= 'A') && (*sp <= 'F'))
     bp[i] |= (int) (*sp - 'A') + 10;
 else if ((*sp >= '0') && (*sp <= '9'))
     bp[i] |= (int) (*sp - '0');
 else
     return (-1);
 bp[i] <<= 4;
 sp++;
 *sp = toupper(*sp);
 if ((*sp >= 'A') && (*sp <= 'F'))
     bp[i] |= (int) (*sp - 'A') + 10;
 else if ((*sp >= '0') && (*sp <= '9'))
     bp[i] |= (int) (*sp - '0');
 else
     return (-1);
 sp++;
    }
    sin->sin_addr.s_addr = htonl(val);
    return (sp - bufp);
}

canonical_original_code:
static int INET_getsock(char *bufp, struct sockaddr *sap)
{
    char *sp = bufp; char *bp;
    unsigned int i;
    unsigned int val;
    struct sockaddr_in *sin;
    sin = (struct sockaddr_in *) sap;
    sin->sin_family = 2;
    sin->sin_port = 0;
    val = 0;
    bp = (char *) &val;
    for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) {
 *sp = toupper(*sp);
 if ((*sp >= 'A') && (*sp <= 'F'))
     bp[i] |= (int) (*sp - 'A') + 10;
 else if ((*sp >= '0') && (*sp <= '9'))
     bp[i] |= (int) (*sp - '0');
 else
     return (-1);
 bp[i] <<= 4;
 sp++;
 *sp = toupper(*sp);
 if ((*sp >= 'A') && (*sp <= 'F'))
     bp[i] |= (int) (*sp - 'A') + 10;
 else if ((*sp >= '0') && (*sp <= '9'))
     bp[i] |= (int) (*sp - '0');
 else
     return (-1);
 sp++;
    }
    sin->sin_addr.s_addr = htonl(val);
    return (sp - bufp);
}

variable_types:
bufp
char *

variable_types:
sp
char *

variable_types:
bp
char *

variable_types:
i
unsigned int

variable_types:
val
unsigned int

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


decompiled_code:
__int64 __fastcall INET_resolve(char *name, struct in_addr *a2, int a3)
{
unsigned int v3; // er12
struct hostent *v6; // rax
struct netent *v7; // rax
int *v8; // rbx

a2->s_addr = 2;
if ( !strcmp(name, "default") )
{
a2[1].s_addr = 0;
return 1;
}
if ( inet_aton(name, a2 + 1) )
return 0LL;
if ( a3 )
{
v6 = gethostbyname(name);
if ( v6 )
{
LABEL_7:
a2[1].s_addr = (*(struct in_addr **)v6->h_addr_list)->s_addr;
return 0LL;
}
v7 = getnetbyname(name);
if ( !v7 )
{
LABEL_12:
v3 = -1;
v8 = _h_errno_location();
*_errno_location() = *v8;
return v3;
}
}
else
{
v7 = getnetbyname(name);
if ( !v7 )
{
v6 = gethostbyname(name);
if ( v6 )
goto LABEL_7;
goto LABEL_12;
}
}
a2[1].s_addr = _bswap_32(v7->n_net);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *name, struct in_addr *a2, int a3)
{
unsigned int v3; // er12
struct hostent *v6; // rax
struct netent *v7; // rax
int *v8; // rbx

a2->s_addr = 2;
if ( !strcmp(name, "default") )
{
a2[1].s_addr = 0;
return 1;
}
if ( inet_aton(name, a2 + 1) )
return 0LL;
if ( a3 )
{
v6 = gethostbyname(name);
if ( v6 )
{
LABEL_7:
a2[1].s_addr = (*(struct in_addr **)v6->h_addr_list)->s_addr;
return 0LL;
}
v7 = getnetbyname(name);
if ( !v7 )
{
LABEL_12:
v3 = -1;
v8 = _h_errno_location();
*_errno_location() = *v8;
return v3;
}
}
else
{
v7 = getnetbyname(name);
if ( !v7 )
{
v6 = gethostbyname(name);
if ( v6 )
goto LABEL_7;
goto LABEL_12;
}
}
a2[1].s_addr = func3(v7->n_net);
return 1LL;
}

original_code:
static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
{
    struct hostent *hp;
    struct netent *np;
    sin->sin_family = 2;
    sin->sin_port = 0;
    if (!strcmp(name, "default")) {
 sin->sin_addr.s_addr = ((in_addr_t) 0x00000000);
 return (1);
    }
    if (inet_aton(name, &sin->sin_addr)) {
 return 0;
    }
    if (hostfirst &&
 (hp = gethostbyname(name)) != (struct hostent *) ((void *)0)) {
 memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
  sizeof(struct in_addr));
 return 0;
    }
    if ((np = getnetbyname(name)) != (struct netent *) ((void *)0)) {
 sin->sin_addr.s_addr = htonl(np->n_net);
 return 1;
    }
    if (hostfirst) {
 (*__errno_location ()) = (*__h_errno_location ());
 return -1;
    }
    if ((hp = gethostbyname(name)) == (struct hostent *) ((void *)0)) {
 (*__errno_location ()) = (*__h_errno_location ());
 return -1;
    }
    memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
    sizeof(struct in_addr));
    return 0;
}

canonical_original_code:
static int INET_resolve(char *name, struct sockaddr_in *sin, int hostfirst)
{
    struct hostent *hp;
    struct netent *np;
    sin->sin_family = 2;
    sin->sin_port = 0;
    if (!strcmp(name, "default")) {
 sin->sin_addr.s_addr = ((unsigned int) 0x00000000);
 return (1);
    }
    if (inet_aton(name, &sin->sin_addr)) {
 return 0;
    }
    if (hostfirst &&
 (hp = gethostbyname(name)) != (struct hostent *) ((void *)0)) {
 memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
  sizeof(struct in_addr));
 return 0;
    }
    if ((np = getnetbyname(name)) != (struct netent *) ((void *)0)) {
 sin->sin_addr.s_addr = htonl(np->n_net);
 return 1;
    }
    if (hostfirst) {
 (*__errno_location ()) = (*__h_errno_location ());
 return -1;
    }
    if ((hp = gethostbyname(name)) == (struct hostent *) ((void *)0)) {
 (*__errno_location ()) = (*__h_errno_location ());
 return -1;
    }
    memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0],
    sizeof(struct in_addr));
    return 0;
}

variable_types: hostfirst int

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

variable_types: struct netent { char *n_name; char **n_aliases; int n_addrtype; unsigned int n_net; } *


decompiled_code:
__int64 __fastcall INET_input(int a1, char *a2, struct in_addr *a3)
{
if ( a1 == 1 )
return INET_getsock(a2, a3);
if ( a1 == 256 )
return INET_resolve(a2, a3, 1);
return INET_resolve(a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char *a2, struct in_addr *a3)
{
if ( a1 == 1 )
return func6(a2, a3);
if ( a1 == 256 )
return func7(a2, a3, 1);
return func7(a2, a3, 0);
}

original_code:
static int INET_input(int type, char *bufp, struct sockaddr *sap)
{
    switch (type) {
    case 1:
 return (INET_getsock(bufp, sap));
    case 256:
 return (INET_resolve(bufp, (struct sockaddr_in *) sap, 1));
    default:
 return (INET_resolve(bufp, (struct sockaddr_in *) sap, 0));
    }
}

variable_types: type int


decompiled_code:
void *__fastcall INET_sprint(_WORD *a1, __int16 a2)
{
bool v2; // zf
void *result; // rax

if ( (unsigned __int16)(*a1 - 1) > 0xFFFDu )
return (void *)safe_strncpy(&buff_2, "[NONE SET]", 128LL);
v2 = (unsigned int)INET_rresolve_constprop_0(&buff_2, (__int64)a1, a2, -256) == 0;
result = &buff_2;
if ( !v2 )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func11(_WORD *a1, __int16 a2)
{
bool v2; // zf
void *result; // rax

if ( (unsigned __int16)(*a1 - 1) > 0xFFFDu )
return (void *)safe_strncpy(&buff_2, "[NONE SET]", 128LL);
v2 = (unsigned int)func10(&buff_2, (__int64)a1, a2, -256) == 0;
result = &buff_2;
if ( !v2 )
result = 0LL;
return result;
}

original_code:
static char *INET_sprint(struct sockaddr *sap, int numeric)
{
    static char buff[128];
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
 return safe_strncpy(buff, ("[NONE SET]"), sizeof(buff));
    if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap,
        numeric, 0xffffff00) != 0)
 return (((void *)0));
    return (buff);
}

variable_types: numeric int

variable_types:
buff
char [128]


decompiled_code:
void *__fastcall INET_sprintmask(_WORD *a1, __int16 a2, int a3)
{
bool v3; // zf
void *result; // rax

if ( (unsigned __int16)(*a1 - 1) > 0xFFFDu )
return (void *)safe_strncpy(&buff_3, "[NONE SET]", 128LL);
v3 = (unsigned int)INET_rresolve_constprop_0(&buff_3, (__int64)a1, a2, a3) == 0;
result = &buff_3;
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func13(_WORD *a1, __int16 a2, int a3)
{
bool v3; // zf
void *result; // rax

if ( (unsigned __int16)(*a1 - 1) > 0xFFFDu )
return (void *)safe_strncpy(&buff_3, "[NONE SET]", 128LL);
v3 = (unsigned int)func10(&buff_3, (__int64)a1, a2, a3) == 0;
result = &buff_3;
if ( !v3 )
result = 0LL;
return result;
}

original_code:
char *INET_sprintmask(struct sockaddr *sap, int numeric,
        unsigned int netmask)
{
    static char buff[128];
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
 return safe_strncpy(buff, ("[NONE SET]"), sizeof(buff));
    if (INET_rresolve(buff, sizeof(buff), (struct sockaddr_in *) sap,
        numeric, netmask) != 0)
 return (((void *)0));
    return (buff);
}

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

variable_types:
netmask
unsigned int


decompiled_code:
const char *__fastcall get_sname(int a1, const char *a2, int a3)
{
const char *result; // rax
unsigned __int16 v4; // ax
__int64 v5; // rax

result = "*";
if ( a1 )
{
if ( !a3 )
{
if ( !init_0 )
{
read_services_isra_0();
init_0 = 1;
}
buffer_1 = 0;
if ( !strcmp(a2, "tcp") )
{
v5 = searchlist(tcp_name, a1);
if ( !v5 )
goto LABEL_8;
}
else if ( !strcmp(a2, "udp") )
{
v5 = searchlist(udp_name, a1);
if ( !v5 )
goto LABEL_8;
}
else
{
if ( strcmp(a2, "raw") )
goto LABEL_8;
v5 = searchlist(raw_name, a1);
if ( !v5 )
goto LABEL_8;
}
strcpy(&buffer_1, *(const char **)(v5 + 8));
if ( buffer_1 )
return &buffer_1;
}
LABEL_8:
v4 = _bswap_16(a1);
sprintf(&buffer_1, "%d", v4);
result = &buffer_1;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func14(int a1, const char *a2, int a3)
{
const char *result; // rax
unsigned __int16 v4; // ax
__int64 v5; // rax

result = "*";
if ( a1 )
{
if ( !a3 )
{
if ( !init_0 )
{
func12();
init_0 = 1;
}
buffer_1 = 0;
if ( !strcmp(a2, "tcp") )
{
v5 = func1(tcp_name, a1);
if ( !v5 )
goto LABEL_8;
}
else if ( !strcmp(a2, "udp") )
{
v5 = func1(udp_name, a1);
if ( !v5 )
goto LABEL_8;
}
else
{
if ( strcmp(a2, "raw") )
goto LABEL_8;
v5 = func1(raw_name, a1);
if ( !v5 )
goto LABEL_8;
}
strcpy(&buffer_1, *(const char **)(v5 + 8));
if ( buffer_1 )
return &buffer_1;
}
LABEL_8:
v4 = func9(a1);
sprintf(&buffer_1, "%d", v4);
result = &buffer_1;
}
return result;
}

original_code:
char *get_sname(int socknumber, char *proto, int numeric)
{
    static char buffer[64], init = 0;
    struct service *item;
    if (socknumber == 0)
 return ("*");
    if (numeric) {
 sprintf(buffer, "%d", ntohs(socknumber));
 return (buffer);
    }
    if (!init) {
 (void) read_services();
 init = 1;
    }
    buffer[0] = '\0';
    if (!strcmp(proto, "tcp")) {
 if ((item = searchlist(tcp_name, socknumber)) != ((void *)0))
     sprintf(buffer, "%s", item->name);
    } else if (!strcmp(proto, "udp")) {
 if ((item = searchlist(udp_name, socknumber)) != ((void *)0))
     sprintf(buffer, "%s", item->name);
    } else if (!strcmp(proto, "raw")) {
 if ((item = searchlist(raw_name, socknumber)) != ((void *)0))
     sprintf(buffer, "%s", item->name);
    }
    if (!buffer[0])
 sprintf(buffer, "%d", ntohs(socknumber));
    return (buffer);
}

canonical_original_code:
char *get_sname(int socknumber, char *proto, int numeric)
{
    static char buffer[64]; static char init = 0;
    struct service *item;
    if (socknumber == 0)
 return ("*");
    if (numeric) {
 sprintf(buffer, "%d", ntohs(socknumber));
 return (buffer);
    }
    if (!init) {
 (void) read_services();
 init = 1;
    }
    buffer[0] = '\0';
    if (!strcmp(proto, "tcp")) {
 if ((item = searchlist(tcp_name, socknumber)) != ((void *)0))
     sprintf(buffer, "%s", item->name);
    } else if (!strcmp(proto, "udp")) {
 if ((item = searchlist(udp_name, socknumber)) != ((void *)0))
     sprintf(buffer, "%s", item->name);
    } else if (!strcmp(proto, "raw")) {
 if ((item = searchlist(raw_name, socknumber)) != ((void *)0))
     sprintf(buffer, "%s", item->name);
    }
    if (!buffer[0])
 sprintf(buffer, "%d", ntohs(socknumber));
    return (buffer);
}

variable_types: socknumber int

variable_types:
proto
char *

variable_types:
buffer
char [64]

variable_types: init char

variable_types: struct service { int number; char *name; struct service *next; } *


hwinit

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

loop_hwtype[1] = "Local Loopback";
result = 1LL;
unspec_hwtype[1] = "UNSPEC";
ether_hwtype[1] = "Ethernet";
tunnel_hwtype[1] = "IPIP Tunnel";
ppp_hwtype[1] = "Point-to-Point Protocol";
arcnet_hwtype[1] = "ARCnet";
dlci_hwtype[1] = "Frame Relay DLCI";
frad_hwtype[1] = "Frame Relay Access Device";
sVhwinit = 1;
return result;
}

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

loop_hwtype[1] = "Local Loopback";
result = 1LL;
unspec_hwtype[1] = "UNSPEC";
ether_hwtype[1] = "Ethernet";
tunnel_hwtype[1] = "IPIP Tunnel";
ppp_hwtype[1] = "Point-to-Point Protocol";
arcnet_hwtype[1] = "ARCnet";
dlci_hwtype[1] = "Frame Relay DLCI";
frad_hwtype[1] = "Frame Relay Access Device";
sVhwinit = 1;
return result;
}

original_code:
void hwinit()
{
    loop_hwtype.title = ("Local Loopback");
    unspec_hwtype.title = ("UNSPEC");
    ether_hwtype.title = ("Ethernet");
    tunnel_hwtype.title = ("IPIP Tunnel");
    ppp_hwtype.title = ("Point-to-Point Protocol");
    arcnet_hwtype.title = ("ARCnet");
    dlci_hwtype.title = ("Frame Relay DLCI");
    frad_hwtype.title = ("Frame Relay Access Device");
    sVhwinit = 1;
}


decompiled_code:
const char **__fastcall get_hwtype(char *s2)
{
const char **v1; // r12
void **v2; // rbx

if ( !sVhwinit )
hwinit();
v1 = (const char **)hwtypes;
if ( hwtypes )
{
v2 = &hwtypes;
do
{
if ( !strcmp(*v1, s2) )
break;
v1 = (const char **)v2[1];
++v2;
}
while ( v1 );
}
return v1;
}

canonical_decompiled_code:
const char **__fastcall func1(char *s2)
{
const char **v1; // r12
void **v2; // rbx

if ( !sVhwinit )
func0();
v1 = (const char **)hwtypes;
if ( hwtypes )
{
v2 = &hwtypes;
do
{
if ( !strcmp(*v1, s2) )
break;
v1 = (const char **)v2[1];
++v2;
}
while ( v1 );
}
return v1;
}

original_code:
struct hwtype *get_hwtype(const char *name)
{
    struct hwtype **hwp;
    if (!sVhwinit)
 hwinit();
    hwp = hwtypes;
    while (*hwp != ((void *)0)) {
 if (!strcmp((*hwp)->name, name))
     return (*hwp);
 hwp++;
    }
    return (((void *)0));
}

canonical_original_code:
struct hwtype *get_hwtype(char *name)
{
    struct hwtype **hwp;
    if (!sVhwinit)
 hwinit();
    hwp = hwtypes;
    while (*hwp != ((void *)0)) {
 if (!strcmp((*hwp)->name, name))
     return (*hwp);
 hwp++;
    }
    return (((void *)0));
}

variable_types:
name
char *

variable_types: struct hwtype { char *name; char *title; int type; int alen; char *(*print)(unsigned char *); int (*input)(char *, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *); int (*activate)(int fd); int suppress_null_addr; } **

user_defined_types: struct hwtype { char *name; char *title; int type; int alen; char *(*print)(unsigned char *); int (*input)(char *, struct sockaddr *); int (*activate)(int fd); int suppress_null_addr; }


decompiled_code:
int __fastcall print_hwlist(int a1)
{
_DWORD *v1; // rax
void **v2; // rbx
int v3; // ebp
const char *v4; // rsi
__int64 v5; // rax
const char *v6; // rdx

if ( !sVhwinit )
hwinit();
v1 = hwtypes;
if ( hwtypes )
{
v2 = &off_268;
v3 = 0;
do
{
while ( a1 == 1 && !v1[5] )
{
v1 = *v2++;
if ( !v1 )
return fputc(10, stderr);
}
if ( v1[4] != -1 )
{
if ( (unsigned int)(-1431655765 * v3) <= 0x55555555 )
{
v4 = "\n ";
if ( !v3 )
v4 = " ";
fprintf(stderr, v4);
}
v5 = (__int64)*(v2 - 1);
v6 = *(const char **)v5;
if ( !*(_QWORD *)v5 )
v6 = "..";
++v3;
fprintf(stderr, "%s (%s) ", v6, *(_QWORD *)(v5 + 8));
}
v1 = *v2++;
}
while ( v1 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
_DWORD *v1; // rax
void **v2; // rbx
int v3; // ebp
const char *v4; // rsi
__int64 v5; // rax
const char *v6; // rdx

if ( !sVhwinit )
func0();
v1 = hwtypes;
if ( hwtypes )
{
v2 = &off_268;
v3 = 0;
do
{
while ( a1 == 1 && !v1[5] )
{
v1 = *v2++;
if ( !v1 )
return fputc(10, stderr);
}
if ( v1[4] != -1 )
{
if ( (unsigned int)(-1431655765 * v3) <= 0x55555555 )
{
v4 = "\n ";
if ( !v3 )
v4 = " ";
fprintf(stderr, v4);
}
v5 = (__int64)*(v2 - 1);
v6 = *(const char **)v5;
if ( !*(_QWORD *)v5 )
v6 = "..";
++v3;
fprintf(stderr, "%s (%s) ", v6, *(_QWORD *)(v5 + 8));
}
v1 = *v2++;
}
while ( v1 );
}
return fputc(10, stderr);
}

original_code:
void print_hwlist(int type) {
    int count = 0;
    char * txt;
    struct hwtype **hwp;
    if (!sVhwinit)
 hwinit();
    hwp = hwtypes;
    while (*hwp != ((void *)0)) {
 if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) {
  hwp++; continue;
 }
 if ((count % 3) == 0) fprintf(stderr,count?"\n    ":"    ");
        txt = (*hwp)->name; if (!txt) txt = "..";
 fprintf(stderr,"%s (%s) ",txt,(*hwp)->title);
 count++;
 hwp++;
    }
    fprintf(stderr,"\n");
}

canonical_original_code:
void print_hwlist(int type) {
    int count = 0;
    char *txt;
    struct hwtype **hwp;
    if (!sVhwinit)
 hwinit();
    hwp = hwtypes;
    while (*hwp != ((void *)0)) {
 if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) {
  hwp++; continue;
 }
 if ((count % 3) == 0) fprintf(stderr,count?"\n    ":"    ");
        txt = (*hwp)->name; if (!txt) txt = "..";
 fprintf(stderr,"%s (%s) ",txt,(*hwp)->title);
 count++;
 hwp++;
    }
    fprintf(stderr,"\n");
}

variable_types: count int

variable_types:
txt
char *


decompiled_code:
__int64 __fastcall hw_null_address(__int64 a1, _BYTE *a2)
{
int v2; // eax
__int64 v3; // rax

v2 = *(_DWORD *)(a1 + 20);
if ( !v2 )
return 1LL;
v3 = (__int64)&a2[v2 - 1 + 1];
while ( !*a2 )
{
if ( ++a2 == (_BYTE *)v3 )
return 1LL;
}
return 0LL;
}

original_code:
int hw_null_address(struct hwtype *hw, void *ap)
{
    unsigned int i;
    unsigned char *address = (unsigned char *)ap;
    for (i = 0; i < hw->alen; i++)
 if (address[i])
     return 0;
    return 1;
}

variable_types: struct hwtype { char *name; char *title; int type; int alen; char *(*print)(unsigned char *); int (*input)(char *, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *); int (*activate)(int fd); int suppress_null_addr; } *

variable_types:
ap
void *

variable_types:
i
unsigned int

variable_types:
address
unsigned char *


decompiled_code:
char *__fastcall pr_unspec(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
char *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rdx
char *v5; // rdi

v1 = a1 + 16;
v2 = buff_0;
v3 = a1;
do
{
v4 = *v3;
v5 = v2;
++v3;
v2 += 3;
sprintf(v5, "%02X-", v4);
}
while ( v1 != v3 );
*(_BYTE *)(strlen(buff_0) + 223) = 0;
return buff_0;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
char *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rdx
char *v5; // rdi

v1 = a1 + 16;
v2 = buff_0;
v3 = a1;
do
{
v4 = *v3;
v5 = v2;
++v3;
v2 += 3;
sprintf(v5, "%02X-", v4);
}
while ( v1 != v3 );
*(_BYTE *)(strlen(buff_0) + 223) = 0;
return buff_0;
}

original_code:
static char *pr_unspec(unsigned char *ptr)
{
    static char buff[64];
    char *pos;
    unsigned int i;
    pos = buff;
    for (i = 0; i < sizeof(struct sockaddr); i++) {
 pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
    }
    buff[strlen(buff) - 1] = '\0';
    return (buff);
}

variable_types:
ptr
unsigned char *

variable_types:
buff
char [64]

variable_types:
pos
char *


decompiled_code:
__int64 __fastcall sockets_open(int a1)
{
__int64 v2; // rbx
int v3; // er13
_QWORD *v4; // rbp
int v5; // eax
int v6; // edi
int v7; // eax

if ( force_0 < 0 )
{
force_0 = (int)kernel_version() <= 20999;
if ( access("/proc/net", 4) )
force_0 = 1;
}
v2 = aftypes;
v3 = -1;
v4 = &aftypes;
if ( !aftypes )
{
v3 = -1;
goto LABEL_22;
}
do
{
while ( 1 )
{
v6 = *(_DWORD *)(v2 + 16);
if ( !v6 )
goto LABEL_7;
if ( !a1 )
break;
if ( v6 == a1 )
{
v5 = *(_DWORD *)(v2 + 80);
if ( v5 == -1 )
goto LABEL_15;
LABEL_6:
v3 = v5;
}
LABEL_7:
v2 = v4[1];
++v4;
if ( !v2 )
goto LABEL_18;
}
v5 = *(_DWORD *)(v2 + 80);
if ( v5 != -1 )
goto LABEL_6;
if ( force_0 || !*(_QWORD *)(v2 + 88) )
goto LABEL_15;
if ( access(*(const char **)(v2 + 88), 4) )
goto LABEL_7;
v6 = *(_DWORD *)(v2 + 16);
LABEL_15:
v7 = socket(v6, 2, 0);
*(_DWORD *)(v2 + 80) = v7;
if ( v7 >= 0 )
v3 = v7;
v2 = v4[1];
++v4;
}
while ( v2 );
LABEL_18:
if ( v3 >= 0 )
return (unsigned int)v3;
LABEL_22:
fwrite("No usable address families found.\n", 1uLL, 0x22uLL, stderr);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v2; // rbx
int v3; // er13
_QWORD *v4; // rbp
int v5; // eax
int v6; // edi
int v7; // eax

if ( force_0 < 0 )
{
force_0 = (int)kernel_version() <= 20999;
if ( access("/proc/net", 4) )
force_0 = 1;
}
v2 = aftypes;
v3 = -1;
v4 = &aftypes;
if ( !aftypes )
{
v3 = -1;
goto LABEL_22;
}
do
{
while ( 1 )
{
v6 = *(_DWORD *)(v2 + 16);
if ( !v6 )
goto LABEL_7;
if ( !a1 )
break;
if ( v6 == a1 )
{
v5 = *(_DWORD *)(v2 + 80);
if ( v5 == -1 )
goto LABEL_15;
LABEL_6:
v3 = v5;
}
LABEL_7:
v2 = v4[1];
++v4;
if ( !v2 )
goto LABEL_18;
}
v5 = *(_DWORD *)(v2 + 80);
if ( v5 != -1 )
goto LABEL_6;
if ( force_0 || !*(_QWORD *)(v2 + 88) )
goto LABEL_15;
if ( access(*(const char **)(v2 + 88), 4) )
goto LABEL_7;
v6 = *(_DWORD *)(v2 + 16);
LABEL_15:
v7 = socket(v6, 2, 0);
*(_DWORD *)(v2 + 80) = v7;
if ( v7 >= 0 )
v3 = v7;
v2 = v4[1];
++v4;
}
while ( v2 );
LABEL_18:
if ( v3 >= 0 )
return (unsigned int)v3;
LABEL_22:
fwrite("No usable address families found.\n", 1uLL, 0x22uLL, stderr);
return (unsigned int)v3;
}

original_code:
int sockets_open(int family)
{
    struct aftype **aft;
    int sfd = -1;
    static int force = -1;
    if (force < 0) {
 force = 0;
 if (kernel_version() < ((2) * 10000 + (1)*1000 + (0)))
     force = 1;
 if (access("/proc/net", 4))
     force = 1;
    }
    for (aft = aftypes; *aft; aft++) {
 struct aftype *af = *aft;
 int type = SOCK_DGRAM;
 if (af->af == 0)
     continue;
 if (family && family != af->af)
     continue;
 if (af->fd != -1) {
     sfd = af->fd;
     continue;
 }
 if (!family && !force && af->flag_file) {
     if (access(af->flag_file, 4))
  continue;
 }
 af->fd = socket(af->af, type, 0);
 if (af->fd >= 0)
     sfd = af->fd;
    }
    if (sfd < 0)
 fprintf(stderr, ("No usable address families found.\n"));
    return sfd;
}

variable_types: family int

variable_types: struct aftype { char *name; char *title; int af; int alen; char *(*print)(unsigned char *); char *(*sprint)(struct sockaddr { unsigned short sa_family; char sa_data[14]; } *, int numeric); int (*input)(int type, char *bufp, struct sockaddr *); void (*herror)(char *text); int (*rprint)(int options); int (*rinput)(int typ, int ext, char **argv); int (*getmask)(char *src, struct sockaddr *mask, char *name); int fd; char *flag_file; } **

variable_types: sfd int

variable_types: force int

variable_types: type int

user_defined_types: struct aftype { char *name; char *title; int af; int alen; char *(*print)(unsigned char *); char *(*sprint)(struct sockaddr *, int numeric); int (*input)(int type, char *bufp, struct sockaddr *); void (*herror)(char *text); int (*rprint)(int options); int (*rinput)(int typ, int ext, char **argv); int (*getmask)(char *src, struct sockaddr *mask, char *name); int fd; char *flag_file; }


oom

decompiled_code:
void __noreturn oom()
{
fwrite("out of virtual memory\n", 1uLL, 0x16uLL, stderr);
exit(2);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("out of virtual memory\n", 1uLL, 0x16uLL, stderr);
exit(2);
}

original_code:
static void oom(void)
{
    fprintf(stderr, "out of virtual memory\n");
    exit(2);
}

canonical_original_code:
static void oom()
{
    fprintf(stderr, "out of virtual memory\n");
    exit(2);
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
oom();
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1)
{
void *result; // rax

result = calloc(a1, 1uLL);
if ( !result )
func0();
return result;
}

original_code:
void *xmalloc(size_t sz)
{
    void *p = calloc(sz, 1);
    if (!p)
 oom();
    return p;
}

canonical_original_code:
void *xmalloc(unsigned long sz)
{
    void *p = calloc(sz, 1);
    if (!p)
 oom();
    return p;
}

variable_types:
sz
unsigned long

variable_types:
p
void *

return_type: void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
oom();
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
func0();
return result;
}

original_code:
void *xrealloc(void *oldp, size_t sz)
{
    void *p = realloc(oldp, sz);
    if (!p)
 oom();
    return p;
}

canonical_original_code:
void *xrealloc(void *oldp, unsigned long sz)
{
    void *p = realloc(oldp, sz);
    if (!p)
 oom();
    return p;
}

variable_types:
oldp
void *


decompiled_code:
__int64 kernel_version()
{
__int64 result; // rax
int v1; // [rsp+4h] [rbp-1A4h] BYREF
int v2; // [rsp+8h] [rbp-1A0h] BYREF
int v3; // [rsp+Ch] [rbp-19Ch] BYREF
struct utsname name; // [rsp+10h] [rbp-198h] BYREF

if ( uname(&name) >= 0 && (unsigned int)_isoc99_sscanf(name.release, "%d.%d.%d", &v1, &v2, &v3) == 3 )
result = (unsigned int)(v3 + 1000 * v2 + 10000 * v1);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int v1; // [rsp+4h] [rbp-1A4h] BYREF
int v2; // [rsp+8h] [rbp-1A0h] BYREF
int v3; // [rsp+Ch] [rbp-19Ch] BYREF
struct utsname name; // [rsp+10h] [rbp-198h] BYREF

if ( uname(&name) >= 0 && (unsigned int)_isoc99_sscanf(name.release, "%d.%d.%d", &v1, &v2, &v3) == 3 )
result = (unsigned int)(v3 + 1000 * v2 + 10000 * v1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int kernel_version(void)
{
    struct utsname uts;
    int major, minor, patch;
    if (uname(&uts) < 0)
 return -1;
    if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
 return -1;
    return ((major) * 10000 + (minor)*1000 + (patch));
}

canonical_original_code:
int kernel_version()
{
    struct utsname uts;
    int major; int minor; int patch;
    if (uname(&uts) < 0)
 return -1;
    if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
 return -1;
    return ((major) * 10000 + (minor)*1000 + (patch));
}

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

variable_types: major int

variable_types: minor int

variable_types: patch int


decompiled_code:
char *__fastcall safe_strncpy(char *a1, const char *a2, __int64 a3)
{
a1[a3 - 1] = 0;
return strncpy(a1, a2, a3 - 1);
}

canonical_decompiled_code:
char *__fastcall func4(char *a1, const char *a2, __int64 a3)
{
a1[a3 - 1] = 0;
return strncpy(a1, a2, a3 - 1);
}

original_code:
char *safe_strncpy(char *dst, const char *src, size_t size)
{
    dst[size-1] = '\0';
    return strncpy(dst,src,size-1);
}

canonical_original_code:
char *safe_strncpy(char *dst, char *src, unsigned long size)
{
    dst[size-1] = '\0';
    return strncpy(dst,src,size-1);
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
size
unsigned long


decompiled_code:
void *pr_tunnel()
{
return &unk_59;
}

canonical_decompiled_code:
void *func0()
{
return &unk_59;
}

original_code:
static char *pr_tunnel(unsigned char *ptr)
{
    return ("");
}

variable_types:
ptr
unsigned char *


decompiled_code:
__int64 in_tunnel()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0xFFFFFFFFLL;
}

original_code:
static int in_tunnel(char *bufp, struct sockaddr *sap)
{
    return (-1);
}

variable_types:
bufp
char *

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


cutalias

decompiled_code:
const char *__fastcall cutalias(const char *a1)
{
int v2; // eax
__int64 v3; // r13
int v4; // ebx
const unsigned __int16 **v5; // rax
const char *v6; // rdx
const unsigned __int16 *v7; // rcx
__int64 v8; // rax
__int64 v9; // rbp
char *v10; // rdi

v2 = strlen(a1);
if ( v2 > 0 )
{
v3 = v2;
v4 = v2;
v5 = _ctype_b_loc();
v6 = &a1[v3 - 2];
v7 = *v5;
v8 = v4 - 1;
if ( (v7[a1[v3 - 1]] & 0x800) != 0 )
{
while ( (int)v8 > 0 )
{
v9 = *v6;
v10 = (char *)v6--;
if ( (_BYTE)v9 == 58 )
{
*v10 = 0;
return &a1[v8];
}
--v8;
if ( (v7[v9] & 0x800) == 0 )
return 0LL;
}
}
}
return 0LL;
}

original_code:
char* cutalias(char* name)
{
 int digit = 0;
 int pos;
 for(pos=strlen(name); pos>0; pos--)
 {
  if (name[pos-1]==':' && digit)
  {
   name[pos-1]='\0';
   return name+pos;
  }
  if (!((*__ctype_b_loc ())[(int) ((name[pos-1]))] & (unsigned short int) _ISdigit))
   break;
  digit = 1;
 }
 return ((void *)0);
}

canonical_original_code:
char *cutalias(char *name)
{
 int digit = 0;
 int pos;
 for(pos=strlen(name); pos>0; pos--)
 {
  if (name[pos-1]==':' && digit)
  {
   name[pos-1]='\0';
   return name+pos;
  }
  if (!((*__ctype_b_loc ())[(int) ((name[pos-1]))] & (unsigned short) _ISdigit))
   break;
  digit = 1;
 }
 return ((void *)0);
}

variable_types:
name
char *

variable_types: digit int

variable_types: pos int


decompiled_code:
__int64 __fastcall rindex_nondigit(const char *a1)
{
int v1; // eax
int v2; // ebx
const unsigned __int16 *v3; // rcx
__int64 result; // rax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = *_ctype_b_loc();
result = v2;
while ( (v3[a1[result - 1]] & 0x800) != 0 )
{
if ( (int)--result <= 0 )
return 0LL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // eax
int v2; // ebx
const unsigned __int16 *v3; // rcx
__int64 result; // rax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0LL;
v2 = v1;
v3 = *_ctype_b_loc();
result = v2;
while ( (v3[a1[result - 1]] & 0x800) != 0 )
{
if ( (int)--result <= 0 )
return 0LL;
}
return (unsigned int)result;
}

original_code:
int rindex_nondigit(char *name)
{
 int pos = strlen(name);
 for(pos=strlen(name); pos>0; pos--)
 {
  if (!((*__ctype_b_loc ())[(int) ((name[pos-1]))] & (unsigned short int) _ISdigit))
   return pos;
 }
 return 0;
}

canonical_original_code:
int rindex_nondigit(char *name)
{
 int pos = strlen(name);
 for(pos=strlen(name); pos>0; pos--)
 {
  if (!((*__ctype_b_loc ())[(int) ((name[pos-1]))] & (unsigned short) _ISdigit))
   return pos;
 }
 return 0;
}


nstrcmp

decompiled_code:
__int64 __fastcall nstrcmp(const char *a1, const char *a2)
{
char *v2; // r12
char *v3; // r13
const char *v4; // r14
const char *v5; // r15
size_t v6; // rbp
int v7; // eax
__int64 v8; // rbx
size_t v9; // rdx
int v10; // er8
int v11; // ebp
int v12; // eax
int v13; // ebx
int v14; // ebp
unsigned int v15; // er8
unsigned int v17; // [rsp+Ch] [rbp-3Ch]

v2 = strdup(a1);
v3 = strdup(a2);
v4 = cutalias(v2);
v5 = cutalias(v3);
v6 = (int)rindex_nondigit(v2);
v7 = rindex_nondigit(v3);
v8 = v7;
v9 = v7;
if ( (int)v6 <= v7 )
v9 = v6;
v10 = strncmp(v2, v3, v9);
if ( v10 )
goto LABEL_16;
if ( (int)v6 > (int)v8 )
goto LABEL_14;
if ( (int)v6 < (int)v8 || (v11 = atoi(&v2[(int)v6]), v12 = atoi(&v3[v8]), v10 = 0, v11 < v12) )
{
free(v2);
free(v3);
return (unsigned int)-1;
}
if ( v11 > v12 )
{
LABEL_14:
free(v2);
free(v3);
return 1;
}
if ( v4 )
{
v13 = -1;
v14 = atoi(v4);
if ( !v5 )
goto LABEL_11;
goto LABEL_10;
}
v14 = -1;
if ( !v5 )
{
LABEL_16:
v17 = v10;
free(v2);
free(v3);
return v17;
}
LABEL_10:
v13 = atoi(v5);
LABEL_11:
free(v2);
free(v3);
if ( v13 > v14 )
v15 = -1;
else
v15 = v13 < v14;
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
char *v2; // r12
char *v3; // r13
const char *v4; // r14
const char *v5; // r15
size_t v6; // rbp
int v7; // eax
__int64 v8; // rbx
size_t v9; // rdx
int v10; // er8
int v11; // ebp
int v12; // eax
int v13; // ebx
int v14; // ebp
unsigned int v15; // er8
unsigned int v17; // [rsp+Ch] [rbp-3Ch]

v2 = strdup(a1);
v3 = strdup(a2);
v4 = func0(v2);
v5 = func0(v3);
v6 = (int)func1(v2);
v7 = func1(v3);
v8 = v7;
v9 = v7;
if ( (int)v6 <= v7 )
v9 = v6;
v10 = strncmp(v2, v3, v9);
if ( v10 )
goto LABEL_16;
if ( (int)v6 > (int)v8 )
goto LABEL_14;
if ( (int)v6 < (int)v8 || (v11 = atoi(&v2[(int)v6]), v12 = atoi(&v3[v8]), v10 = 0, v11 < v12) )
{
free(v2);
free(v3);
return (unsigned int)-1;
}
if ( v11 > v12 )
{
LABEL_14:
free(v2);
free(v3);
return 1;
}
if ( v4 )
{
v13 = -1;
v14 = atoi(v4);
if ( !v5 )
goto LABEL_11;
goto LABEL_10;
}
v14 = -1;
if ( !v5 )
{
LABEL_16:
v17 = v10;
free(v2);
free(v3);
return v17;
}
LABEL_10:
v13 = atoi(v5);
LABEL_11:
free(v2);
free(v3);
if ( v13 > v14 )
v15 = -1;
else
v15 = v13 < v14;
return v15;
}

original_code:
int nstrcmp(const char *ap, const char *bp)
{
 char *a = (char*)strdup(ap);
 char *b = (char*)strdup(bp);
 char *an, *bn;
 int av = 0, bv = 0;
 char *aalias=cutalias(a);
 char *balias=cutalias(b);
 int aindex=rindex_nondigit(a);
 int bindex=rindex_nondigit(b);
 int complen=(aindex<bindex)?aindex:bindex;
 int res = strncmp(a, b, complen);
 if (res != 0)
  { free(a); free(b); return res; }
 if (aindex > bindex)
  { free(a); free(b); return 1; }
 if (aindex < bindex)
  { free(a); free(b); return -1; }
 an = a+aindex;
 bn = b+bindex;
 av = atoi(an);
 bv = atoi(bn);
 if (av < bv)
  { free(a); free(b); return -1; }
 if (av > bv)
  { free(a); free(b); return 1; }
 av = -1;
 if (aalias != ((void *)0))
  av = atoi(aalias);
 bv = -1;
 if (balias != ((void *)0))
  bv = atoi(balias);
 free(a); free(b);
 if (av < bv)
  return -1;
 if (av > bv)
  return 1;
 return 0;
}

canonical_original_code:
int nstrcmp(char *ap, char *bp)
{
 char *a = (char*)strdup(ap);
 char *b = (char*)strdup(bp);
 char *an; char *bn;
 int av = 0; int bv = 0;
 char *aalias = cutalias(a);
 char *balias = cutalias(b);
 int aindex = rindex_nondigit(a);
 int bindex = rindex_nondigit(b);
 int complen = (aindex<bindex)?aindex:bindex;
 int res = strncmp(a, b, complen);
 if (res != 0)
  { free(a); free(b); return res; }
 if (aindex > bindex)
  { free(a); free(b); return 1; }
 if (aindex < bindex)
  { free(a); free(b); return -1; }
 an = a+aindex;
 bn = b+bindex;
 av = atoi(an);
 bv = atoi(bn);
 if (av < bv)
  { free(a); free(b); return -1; }
 if (av > bv)
  { free(a); free(b); return 1; }
 av = -1;
 if (aalias != ((void *)0))
  av = atoi(aalias);
 bv = -1;
 if (balias != ((void *)0))
  bv = atoi(balias);
 free(a); free(b);
 if (av < bv)
  return -1;
 if (av > bv)
  return 1;
 return 0;
}

variable_types:
ap
char *

variable_types:
bp
char *

variable_types:
a
char *

variable_types:
b
char *

variable_types:
an
char *

variable_types:
bn
char *

variable_types: av int

variable_types: bv int

variable_types:
aalias
char *

variable_types:
balias
char *

variable_types: aindex int

variable_types: bindex int

variable_types: complen int

variable_types: res int


original_code:
static int in_arcnet(char *bufp, struct sockaddr *sap)
{
    unsigned char *ptr;
    char c, *orig;
    int i, val;
    sap->sa_family = arcnet_hwtype.type;
    ptr = sap->sa_data;
    i = 0;
    orig = bufp;
    while ((*bufp != '\0') && (i < 1)) {
 val = 0;
 c = *bufp++;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
     val = c - '0';
 else if (c >= 'a' && c <= 'f')
     val = c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val = c - 'A' + 10;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 val <<= 4;
 c = *bufp++;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
     val |= c - '0';
 else if (c >= 'a' && c <= 'f')
     val |= c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val |= c - 'A' + 10;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 *ptr++ = (unsigned char) (val & 0377);
 i++;
 if (*bufp == ':') {
     if (i == 6) {
      ;
     }
     bufp++;
 }
    }
    if ((i == 6) && (*bufp != '\0')) {
    }
    return (0);
}

canonical_original_code:
static int in_arcnet(char *bufp, struct sockaddr *sap)
{
    unsigned char *ptr;
    char c; char *orig;
    int i; int val;
    sap->sa_family = arcnet_hwtype.type;
    ptr = sap->sa_data;
    i = 0;
    orig = bufp;
    while ((*bufp != '\0') && (i < 1)) {
 val = 0;
 c = *bufp++;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
     val = c - '0';
 else if (c >= 'a' && c <= 'f')
     val = c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val = c - 'A' + 10;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 val <<= 4;
 c = *bufp++;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
     val |= c - '0';
 else if (c >= 'a' && c <= 'f')
     val |= c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val |= c - 'A' + 10;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 *ptr++ = (unsigned char) (val & 0377);
 i++;
 if (*bufp == ':') {
     if (i == 6) {
      ;
     }
     bufp++;
 }
    }
    if ((i == 6) && (*bufp != '\0')) {
    }
    return (0);
}

variable_types:
bufp
char *

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

variable_types:
ptr
unsigned char *

variable_types: c char

variable_types:
orig
char *

variable_types: i int

variable_types: val int


decompiled_code:
char *__fastcall pr_arcnet(unsigned __int8 *a1)
{
snprintf(buff_0, 0x40uLL, "%02X", *a1);
return buff_0;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned __int8 *a1)
{
snprintf(buff_0, 0x40uLL, "%02X", *a1);
return buff_0;
}

original_code:
static char *pr_arcnet(unsigned char *ptr)
{
    static char buff[64];
    snprintf(buff, sizeof(buff), "%02X", (ptr[0] & 0377));
    return (buff);
}

variable_types:
buff
char [64]


decompiled_code:
char *__fastcall pr_dlci(__int16 *a1)
{
snprintf(buf_0, 0xCuLL, "%i", (unsigned int)*a1);
return buf_0;
}

canonical_decompiled_code:
char *__fastcall func0(__int16 *a1)
{
snprintf(buf_0, 0xCuLL, "%i", (unsigned int)*a1);
return buf_0;
}

original_code:
char *pr_dlci(unsigned char *ptr)
{
    static char buf[12];
    snprintf(buf, sizeof(buf), "%i", *(short *) ptr);
    return (buf);
}

variable_types:
buf
char [12]


decompiled_code:
int __fastcall get_integer(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
write(fd, buf, v2);
read(fd, output_2, 0x3FFuLL);
return atoi(output_2);
}

canonical_decompiled_code:
int __fastcall func0(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
write(fd, buf, v2);
read(fd, output_2, 0x3FFuLL);
return atoi(output_2);
}

original_code:
int get_integer(int SD, char *request)
{
    static char output[1024];
    write(SD, request, strlen(request));
    read(SD, output, 1024 -1);
    return atoi(output);
}

variable_types: SD int

variable_types:
request
char *

variable_types:
output
char [1024]


decompiled_code:
char *__fastcall parse_hello(char *s)
{
char *result; // rax
const char *v3; // rbx
char *v4; // rax
char *v5; // rax

while ( 1 )
{
result = strtok(s, " ");
v3 = result;
if ( !result )
break;
if ( !strcmp(result, "wid") )
{
v4 = strtok(0LL, " ");
screen = atoi(v4);
}
s = 0LL;
if ( !strcmp(v3, "hgt") )
{
v5 = strtok(0LL, " ");
*(&screen + 1) = atoi(v5);
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char *result; // rax
const char *v3; // rbx
char *v4; // rax
char *v5; // rax

while ( 1 )
{
result = strtok(s, " ");
v3 = result;
if ( !result )
break;
if ( !strcmp(result, "wid") )
{
v4 = strtok(0LL, " ");
screen = atoi(v4);
}
s = 0LL;
if ( !strcmp(v3, "hgt") )
{
v5 = strtok(0LL, " ");
*(&screen + 1) = atoi(v5);
}
}
return result;
}

original_code:
void parse_hello(char *input)
{
    char *next=input;
    char *retval;
    while (1)
    {
        retval=strtok(next, " ");
        next=((void *)0);
        if (retval==((void *)0))
            break;
        if (strcmp(retval, "wid")==0)
            screen.width=atoi(strtok(next, " "));
        if (strcmp(retval, "hgt")==0)
            screen.height=atoi(strtok(next, " "));
    }
}

canonical_original_code:
void parse_hello(char *input)
{
    char *next = input;
    char *retval;
    while (1)
    {
        retval=strtok(next, " ");
        next=((void *)0);
        if (retval==((void *)0))
            break;
        if (strcmp(retval, "wid")==0)
            screen.width=atoi(strtok(next, " "));
        if (strcmp(retval, "hgt")==0)
            screen.height=atoi(strtok(next, " "));
    }
}

variable_types:
input
char *

variable_types:
next
char *

variable_types:
retval
char *


decompiled_code:
__int64 __fastcall parse_reply(char *dest)
{
char *v1; // r12
int v2; // ebx
int v3; // er13
char *v4; // rax
const char *v5; // rbp
char *v7; // rbp
int v8; // eax
unsigned int v9; // er14

v1 = dest;
v2 = 0;
v3 = strlen(dest);
printf("Eingabe: %s\n", dest);
do
{
v4 = strtok(dest, " \n");
v5 = v4;
if ( !v4 )
{
*v1 = 0;
return 0LL;
}
v2 += strlen(v4) + 1;
dest = 0LL;
}
while ( strcmp(v5, "key") );
v7 = strtok(0LL, " \n");
v8 = strlen(v7);
v9 = strcmp(v7, "Escape") == 0 ? 4 : -1;
if ( !strcmp(v7, "Down") )
v9 = 1;
if ( !strcmp(v7, "Right") )
v9 = 3;
if ( !strcmp(v7, "Enter") )
v9 = 2;
strncpy(v1, &v1[v2 + 1 + v8], v3 - (v2 + v8));
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *dest)
{
char *v1; // r12
int v2; // ebx
int v3; // er13
char *v4; // rax
const char *v5; // rbp
char *v7; // rbp
int v8; // eax
unsigned int v9; // er14

v1 = dest;
v2 = 0;
v3 = strlen(dest);
printf("Eingabe: %s\n", dest);
do
{
v4 = strtok(dest, " \n");
v5 = v4;
if ( !v4 )
{
*v1 = 0;
return 0LL;
}
v2 += strlen(v4) + 1;
dest = 0LL;
}
while ( strcmp(v5, "key") );
v7 = strtok(0LL, " \n");
v8 = strlen(v7);
v9 = strcmp(v7, "Escape") == 0 ? 4 : -1;
if ( !strcmp(v7, "Down") )
v9 = 1;
if ( !strcmp(v7, "Right") )
v9 = 3;
if ( !strcmp(v7, "Enter") )
v9 = 2;
strncpy(v1, &v1[v2 + 1 + v8], v3 - (v2 + v8));
return v9;
}

original_code:
int parse_reply(char *input)
{
    char *next=input;
    char *retstr;
    int retint=-1;
    int inputlen=strlen(input);
    int len=0;
    printf("Eingabe: %s\n", input);
    while (1)
    {
        retstr=strtok(next, " \n");
        next=((void *)0);
        if (retstr==((void *)0))
        {
            input[0]=0;
            break;
        }
        len+=strlen(retstr)+1;
        if (strcmp(retstr, "key")==0)
        {
            retstr=strtok(next, " \n");
            len+=strlen(retstr)+1;
            if (strcmp(retstr, "Escape")==0)
                retint=4;
            if (strcmp(retstr, "Down")==0)
                retint=1;
            if (strcmp(retstr, "Right")==0)
                retint=3;
            if (strcmp(retstr, "Enter")==0)
                retint=2;
            input=strncpy(input, &input[len], inputlen-len+1);
            return retint;
        }
    }
    return 0;
}

canonical_original_code:
int parse_reply(char *input)
{
    char *next = input;
    char *retstr;
    int retint = -1;
    int inputlen = strlen(input);
    int len = 0;
    printf("Eingabe: %s\n", input);
    while (1)
    {
        retstr=strtok(next, " \n");
        next=((void *)0);
        if (retstr==((void *)0))
        {
            input[0]=0;
            break;
        }
        len+=strlen(retstr)+1;
        if (strcmp(retstr, "key")==0)
        {
            retstr=strtok(next, " \n");
            len+=strlen(retstr)+1;
            if (strcmp(retstr, "Escape")==0)
                retint=4;
            if (strcmp(retstr, "Down")==0)
                retint=1;
            if (strcmp(retstr, "Right")==0)
                retint=3;
            if (strcmp(retstr, "Enter")==0)
                retint=2;
            input=strncpy(input, &input[len], inputlen-len+1);
            return retint;
        }
    }
    return 0;
}

variable_types:
retstr
char *

variable_types: retint int

variable_types: inputlen int

variable_types: len int


decompiled_code:
void *__fastcall basic_send(int fd, void *buf)
{
size_t v2; // rax

memset(&answer_1, 0, 0x400uLL);
v2 = strlen((const char *)buf);
write(fd, buf, v2);
write(fd, "\n", 1uLL);
read(fd, &answer_1, 0x400uLL);
return &answer_1;
}

canonical_decompiled_code:
void *__fastcall func3(int fd, void *buf)
{
size_t v2; // rax

memset(&answer_1, 0, 0x400uLL);
v2 = strlen((const char *)buf);
write(fd, buf, v2);
write(fd, "\n", 1uLL);
read(fd, &answer_1, 0x400uLL);
return &answer_1;
}

original_code:
char *basic_send(int SD, char *request)
{
    static char answer[1024];
    if (0)
        printf("Sending command: %s\n", request);
    memset(answer, 0, 1024);
    write(SD, request, strlen(request));
    write(SD, "\n", strlen("\n"));
    read(SD, answer, 1024);
    if (0)
        printf("Answer to command to LCDproc: %s\n", answer);
    return answer;
}

variable_types:
answer
char [1024]


decompiled_code:
void *__fastcall basic_read(int fd)
{
memset(&answer_0, 0, 0x400uLL);
read(fd, &answer_0, 0x400uLL);
return &answer_0;
}

canonical_decompiled_code:
void *__fastcall func4(int fd)
{
memset(&answer_0, 0, 0x400uLL);
read(fd, &answer_0, 0x400uLL);
return &answer_0;
}

original_code:
char *basic_read(int SD)
{
    static char answer[1024];
    memset(answer, 0, 1024);
    if (0)
        printf("Going for read!\n");
    read(SD, answer, 1024);
    if (0)
        printf("Read returned: %s\n", answer);
    return answer;
}


decompiled_code:
__int64 do_ppp()
{
fwrite("You cannot start PPP with this program.\n", 1uLL, 0x28uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
fwrite("You cannot start PPP with this program.\n", 1uLL, 0x28uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int do_ppp(int fd)
{
    fprintf(stderr, ("You cannot start PPP with this program.\n"));
    return -1;
}

variable_types: fd int


decompiled_code:
__int64 __fastcall UNIX_print(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
static char *UNIX_print(unsigned char *ptr)
{
    return (ptr);
}

variable_types:
ptr
unsigned char *


decompiled_code:
__int64 __fastcall UNIX_sprint(_WORD *a1)
{
__int64 result; // rax

if ( (unsigned __int16)(*a1 - 1) > 0xFFFDu )
result = safe_strncpy(&buf_2, "[NONE SET]", 64LL);
else
result = UNIX_print((__int64)(a1 + 1));
return result;
}

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

if ( (unsigned __int16)(*a1 - 1) > 0xFFFDu )
result = safe_strncpy(&buf_2, "[NONE SET]", 64LL);
else
result = func0((__int64)(a1 + 1));
return result;
}

original_code:
static char *UNIX_sprint(struct sockaddr *sap, int numeric)
{
    static char buf[64];
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
 return safe_strncpy(buf, ("[NONE SET]"), sizeof(buf));
    return (UNIX_print(sap->sa_data));
}

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

variable_types: numeric int

variable_types:
buf
char [64]


decompiled_code:
char *__fastcall UNSPEC_print(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
char *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rdx
char *v5; // rdi

v1 = a1 + 16;
v2 = buff_0;
v3 = a1;
do
{
v4 = *v3;
v5 = v2;
++v3;
v2 += 3;
sprintf(v5, "%02X-", v4);
}
while ( v1 != v3 );
byte_17F[strlen(buff_0)] = 0;
return buff_0;
}

canonical_decompiled_code:
char *__fastcall func2(unsigned __int8 *a1)
{
unsigned __int8 *v1; // r12
char *v2; // rbp
unsigned __int8 *v3; // rbx
__int64 v4; // rdx
char *v5; // rdi

v1 = a1 + 16;
v2 = buff_0;
v3 = a1;
do
{
v4 = *v3;
v5 = v2;
++v3;
v2 += 3;
sprintf(v5, "%02X-", v4);
}
while ( v1 != v3 );
byte_17F[strlen(buff_0)] = 0;
return buff_0;
}

original_code:
static char *UNSPEC_print(unsigned char *ptr)
{
    static char buff[64];
    char *pos;
    unsigned int i;
    pos = buff;
    for (i = 0; i < sizeof(struct sockaddr); i++) {
 pos += sprintf(pos, "%02X-", (*ptr++ & 0377));
    }
    buff[strlen(buff) - 1] = '\0';
    return (buff);
}

variable_types:
buff
char [64]

variable_types:
pos
char *

variable_types:
i
unsigned int


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

if ( (unsigned __int16)(*(_WORD *)a1 - 1) > 0xFFFDu )
result = (char *)safe_strncpy(&buf_1, "[NONE SET]", 64LL);
else
result = UNSPEC_print((unsigned __int8 *)(a1 + 2));
return result;
}

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

if ( (unsigned __int16)(*(_WORD *)a1 - 1) > 0xFFFDu )
result = (char *)safe_strncpy(&buf_1, "[NONE SET]", 64LL);
else
result = func2((unsigned __int8 *)(a1 + 2));
return result;
}

original_code:
static char *UNSPEC_sprint(struct sockaddr *sap, int numeric)
{
    static char buf[64];
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
 return safe_strncpy(buf, ("[NONE SET]"), sizeof(buf));
    return (UNSPEC_print(sap->sa_data));
}


original_code:
static int in_ether(char *bufp, struct sockaddr *sap)
{
    unsigned char *ptr;
    char c, *orig;
    int i;
    unsigned val;
    sap->sa_family = ether_hwtype.type;
    ptr = sap->sa_data;
    i = 0;
    orig = bufp;
    while ((*bufp != '\0') && (i < 6)) {
 val = 0;
 c = *bufp++;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
     val = c - '0';
 else if (c >= 'a' && c <= 'f')
     val = c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val = c - 'A' + 10;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 val <<= 4;
 c = *bufp;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
     val |= c - '0';
 else if (c >= 'a' && c <= 'f')
     val |= c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val |= c - 'A' + 10;
 else if (c == ':' || c == 0)
     val >>= 4;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 if (c != 0)
     bufp++;
 *ptr++ = (unsigned char) (val & 0377);
 i++;
 if (*bufp == ':') {
     if (i == 6) {
      ;
     }
     bufp++;
 }
    }
    if ((i == 6) && (*bufp != '\0')) {
    }
    return (0);
}

canonical_original_code:
static int in_ether(char *bufp, struct sockaddr *sap)
{
    unsigned char *ptr;
    char c; char *orig;
    int i;
    unsigned int val;
    sap->sa_family = ether_hwtype.type;
    ptr = sap->sa_data;
    i = 0;
    orig = bufp;
    while ((*bufp != '\0') && (i < 6)) {
 val = 0;
 c = *bufp++;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
     val = c - '0';
 else if (c >= 'a' && c <= 'f')
     val = c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val = c - 'A' + 10;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 val <<= 4;
 c = *bufp;
 if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
     val |= c - '0';
 else if (c >= 'a' && c <= 'f')
     val |= c - 'a' + 10;
 else if (c >= 'A' && c <= 'F')
     val |= c - 'A' + 10;
 else if (c == ':' || c == 0)
     val >>= 4;
 else {
     (*__errno_location ()) = 22;
     return (-1);
 }
 if (c != 0)
     bufp++;
 *ptr++ = (unsigned char) (val & 0377);
 i++;
 if (*bufp == ':') {
     if (i == 6) {
      ;
     }
     bufp++;
 }
    }
    if ((i == 6) && (*bufp != '\0')) {
    }
    return (0);
}

variable_types:
bufp
char *

variable_types: c char

variable_types:
orig
char *

variable_types: i int

variable_types:
val
unsigned int


bset

decompiled_code:
__int64 __fastcall bset(int a1, int a2)
{
double v2; // xmm0_8
__int64 result; // rax

v2 = pow(2.0, (double)(a2 % 8));
result = 120 * (a2 / 8) + a1;
gxbits[result] |= (int)v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
double v2; // xmm0_8
__int64 result; // rax

v2 = pow(2.0, (double)(a2 % 8));
result = 120 * (a2 / 8) + a1;
gxbits[result] |= (int)v2;
return result;
}

original_code:
void bset(int x, int y) {
   int index;
   double theBitcom;
   int theBit;
   index = x + 120 * (y / 8);
   theBitcom = pow(2, (y % 8));
   theBit = theBitcom;
   gxbits[index] = 0+gxbits[index] | theBit;
}

variable_types: x int

variable_types: y int

variable_types: index int

variable_types: theBitcom double

variable_types: theBit int


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
int die(char *str) {
    perror(str);exit(1);
}

variable_types:
str
char *


openRawSerialLine

decompiled_code:
__int64 __fastcall openRawSerialLine(const char *a1, int a2, int a3, int a4)
{
int v6; // eax
unsigned int v7; // er12
tcflag_t v8; // eax
tcflag_t v9; // edx
speed_t v10; // esi
struct termios v12; // [rsp+0h] [rbp-68h] BYREF

v6 = open(a1, a4 | 0x800);
if ( v6 < 0 )
die("failed opening serial port");
v7 = v6;
if ( tcflush(v6, 0) < 0 )
die("failed flushing line");
if ( a3 == 1 )
{
v12.c_iflag = 5121;
v8 = 2096;
}
else
{
v8 = -2147481552;
v12.c_iflag = 1;
if ( a3 != 2 )
v8 = 2096;
}
v9 = v8;
v12.c_lflag = 0;
v12.c_oflag = 0;
if ( (unsigned int)(a4 - 1) < 2 )
{
LOBYTE(v9) = v8 | 0x80;
v8 = v9;
}
v12.c_cflag = v8;
*(_WORD *)&v12.c_cc[5] = 256;
if ( a2 == 600 )
{
v10 = 8;
}
else if ( a2 <= 600 )
{
if ( a2 == 134 )
{
v10 = 4;
}
else if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
v10 = 2;
break;
case 'n':
v10 = 3;
break;
case '2':
v10 = 1;
break;
default:
goto LABEL_45;
}
}
else
{
switch ( a2 )
{
case 200:
v10 = 6;
break;
case 300:
v10 = 7;
break;
case 150:
v10 = 5;
break;
default:
goto LABEL_45;
}
}
}
else if ( a2 == 4800 )
{
v10 = 12;
}
else if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
v10 = 10;
break;
case 2400:
v10 = 11;
break;
case 1200:
v10 = 9;
break;
default:
goto LABEL_45;
}
}
else
{
if ( a2 != 19200 )
{
if ( a2 == 38400 )
{
v10 = 15;
goto LABEL_15;
}
if ( a2 == 9600 )
{
v10 = 13;
goto LABEL_15;
}
LABEL_45:
die("Unknown baud date");
}
v10 = 14;
}
LABEL_15:
if ( cfsetospeed(&v12, v10) < 0 )
die("failed setting output speed");
if ( tcsetattr(v7, 0, &v12) < 0 )
die("failed setting port attribs");
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, int a2, int a3, int a4)
{
int v6; // eax
unsigned int v7; // er12
tcflag_t v8; // eax
tcflag_t v9; // edx
speed_t v10; // esi
struct termios v12; // [rsp+0h] [rbp-68h] BYREF

v6 = open(a1, a4 | 0x800);
if ( v6 < 0 )
func8("failed opening serial port");
v7 = v6;
if ( tcflush(v6, 0) < 0 )
func8("failed flushing line");
if ( a3 == 1 )
{
v12.c_iflag = 5121;
v8 = 2096;
}
else
{
v8 = -2147481552;
v12.c_iflag = 1;
if ( a3 != 2 )
v8 = 2096;
}
v9 = v8;
v12.c_lflag = 0;
v12.c_oflag = 0;
if ( (unsigned int)(a4 - 1) < 2 )
{
LOBYTE(v9) = v8 | 0x80;
v8 = v9;
}
v12.c_cflag = v8;
*(_WORD *)&v12.c_cc[5] = 256;
if ( a2 == 600 )
{
v10 = 8;
}
else if ( a2 <= 600 )
{
if ( a2 == 134 )
{
v10 = 4;
}
else if ( a2 <= 134 )
{
switch ( a2 )
{
case 'K':
v10 = 2;
break;
case 'n':
v10 = 3;
break;
case '2':
v10 = 1;
break;
default:
goto LABEL_45;
}
}
else
{
switch ( a2 )
{
case 200:
v10 = 6;
break;
case 300:
v10 = 7;
break;
case 150:
v10 = 5;
break;
default:
goto LABEL_45;
}
}
}
else if ( a2 == 4800 )
{
v10 = 12;
}
else if ( a2 <= 4800 )
{
switch ( a2 )
{
case 1800:
v10 = 10;
break;
case 2400:
v10 = 11;
break;
case 1200:
v10 = 9;
break;
default:
goto LABEL_45;
}
}
else
{
if ( a2 != 19200 )
{
if ( a2 == 38400 )
{
v10 = 15;
goto LABEL_15;
}
if ( a2 == 9600 )
{
v10 = 13;
goto LABEL_15;
}
LABEL_45:
func8("Unknown baud date");
}
v10 = 14;
}
LABEL_15:
if ( cfsetospeed(&v12, v10) < 0 )
func8("failed setting output speed");
if ( tcsetattr(v7, 0, &v12) < 0 )
func8("failed setting port attribs");
return v7;
}

original_code:
int openRawSerialLine(char *port,int speed,int flow_control,int wrmode) {
  struct termios flags;
  speed_t tioc_speed;
  int fd, softwareFlow;
  softwareFlow= (flow_control==1) ? 1 : 0;
  ((fd=open(port,wrmode|04000))>=0) || die("failed opening serial port");
  ((tcflush(fd, 0))>=0) || die("failed flushing line");
  flags.c_iflag= 0000001 | ((flow_control==1) ? (0010000|0002000) : 0);
  flags.c_cflag= 0004000 | 0000060 | ((flow_control==2) ? 020000000000 : 0)
        | ((wrmode==01 || wrmode==02) ? 0000200 : 0);
  flags.c_oflag= flags.c_lflag= 0;
  flags.c_cc[6] = 1; flags.c_cc[5] = 0;
  switch(speed) {
  case 50: tioc_speed=0000001; break; case 75: tioc_speed=0000002; break;
  case 110: tioc_speed=0000003; break; case 134: tioc_speed=0000004; break;
  case 150: tioc_speed=0000005; break; case 200: tioc_speed=0000006; break;
  case 300: tioc_speed=0000007; break; case 600: tioc_speed=0000010; break;
  case 1200: tioc_speed=0000011; break; case 1800: tioc_speed=0000012; break;
  case 2400: tioc_speed=0000013; break; case 4800: tioc_speed=0000014; break;
  case 9600: tioc_speed=0000015; break; case 19200: tioc_speed=0000016; break;
  case 38400: tioc_speed=0000017; break;
  default:
    die("Unknown baud date"); break;
  }
  ((cfsetospeed(&flags,tioc_speed))>=0) || die("failed setting output speed");
  ((tcsetattr(fd,0,&flags))>=0) || die("failed setting port attribs");
  return(fd);
}

canonical_original_code:
int openRawSerialLine(char *port, int speed, int flow_control, int wrmode) {
  struct termios flags;
  unsigned int tioc_speed;
  int fd; int softwareFlow;
  softwareFlow= (flow_control==1) ? 1 : 0;
  ((fd=open(port,wrmode|04000))>=0) || die("failed opening serial port");
  ((tcflush(fd, 0))>=0) || die("failed flushing line");
  flags.c_iflag= 0000001 | ((flow_control==1) ? (0010000|0002000) : 0);
  flags.c_cflag= 0004000 | 0000060 | ((flow_control==2) ? 020000000000 : 0)
        | ((wrmode==01 || wrmode==02) ? 0000200 : 0);
  flags.c_oflag= flags.c_lflag= 0;
  flags.c_cc[6] = 1; flags.c_cc[5] = 0;
  switch(speed) {
  case 50: tioc_speed=0000001; break; case 75: tioc_speed=0000002; break;
  case 110: tioc_speed=0000003; break; case 134: tioc_speed=0000004; break;
  case 150: tioc_speed=0000005; break; case 200: tioc_speed=0000006; break;
  case 300: tioc_speed=0000007; break; case 600: tioc_speed=0000010; break;
  case 1200: tioc_speed=0000011; break; case 1800: tioc_speed=0000012; break;
  case 2400: tioc_speed=0000013; break; case 4800: tioc_speed=0000014; break;
  case 9600: tioc_speed=0000015; break; case 19200: tioc_speed=0000016; break;
  case 38400: tioc_speed=0000017; break;
  default:
    die("Unknown baud date"); break;
  }
  ((cfsetospeed(&flags,tioc_speed))>=0) || die("failed setting output speed");
  ((tcsetattr(fd,0,&flags))>=0) || die("failed setting port attribs");
  return(fd);
}

variable_types:
port
char *

variable_types: speed int

variable_types: wrmode int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: fd int

variable_types: softwareFlow int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
unsigned int v4; // eax
char *v5; // r12
int v6; // ebp
int v7; // edi
unsigned int v8; // ebp
char *v9; // rbx
unsigned int v10; // er15
char v11; // al
char *v12; // rax
int fd; // [rsp+Ch] [rbp-67Ch]
char buf[512]; // [rsp+10h] [rbp-678h] BYREF
char v15; // [rsp+210h] [rbp-478h] BYREF
char s[1080]; // [rsp+250h] [rbp-438h] BYREF

if ( argc != 5 )
{
printf("usage: %s port speed file mode\n", *argv);
puts("where...");
puts(" port is the port device name");
puts(" speed is the port speed");
puts(" file is the filename of bitmap image");
puts(" mode is 0 for normal and 1 for reverse");
exit(0);
}
v3 = argv[2];
if ( !strcmp(v3, "-") )
{
fd = open(argv[1], 1026);
}
else
{
v4 = atoi(v3);
fd = openRawSerialLine(argv[1], v4, 0LL, 2LL);
}
v5 = buf;
v6 = open(argv[3], 2);
read(v6, buf, 0x3EuLL);
read(v6, buf, 0x200uLL);
v7 = v6;
v8 = 31;
close(v7);
LABEL_5:
v9 = v5;
v10 = 0;
while ( 1 )
{
v11 = *v9;
if ( *v9 < 0 )
{
bset(v10, v8);
v11 = *v9;
}
if ( (v11 & 0x40) != 0 )
{
bset(v10 + 1, v8);
v11 = *v9;
if ( (*v9 & 0x20) == 0 )
{
LABEL_7:
if ( (v11 & 0x10) == 0 )
goto LABEL_8;
goto LABEL_18;
}
}
else if ( (v11 & 0x20) == 0 )
{
goto LABEL_7;
}
bset(v10 + 2, v8);
v11 = *v9;
if ( (*v9 & 0x10) == 0 )
{
LABEL_8:
if ( (v11 & 8) == 0 )
goto LABEL_9;
goto LABEL_19;
}
LABEL_18:
bset(v10 + 3, v8);
v11 = *v9;
if ( (*v9 & 8) == 0 )
{
LABEL_9:
if ( (v11 & 4) == 0 )
goto LABEL_10;
goto LABEL_20;
}
LABEL_19:
bset(v10 + 4, v8);
v11 = *v9;
if ( (*v9 & 4) == 0 )
{
LABEL_10:
if ( (v11 & 2) == 0 )
goto LABEL_11;
goto LABEL_21;
}
LABEL_20:
bset(v10 + 5, v8);
v11 = *v9;
if ( (*v9 & 2) == 0 )
{
LABEL_11:
if ( (v11 & 1) != 0 )
goto LABEL_22;
goto LABEL_12;
}
LABEL_21:
bset(v10 + 6, v8);
if ( (*v9 & 1) != 0 )
LABEL_22:
bset(v10 + 7, v8);
LABEL_12:
v10 += 8;
++v9;
if ( v10 == 128 )
{
v5 += 16;
--v8;
if ( v5 == &v15 )
{
sprintf(s, "%cDG", 27LL);
if ( !atoi(argv[4]) )
{
v12 = &gxbits;
do
{
*v12 = ~*v12;
++v12;
}
while ( &end != (_UNKNOWN *)v12 );
}
write(fd, s, 3uLL);
write(fd, &gxbits, 0x1E0uLL);
close(fd);
exit(0);
}
goto LABEL_5;
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
unsigned int v4; // eax
char *v5; // r12
int v6; // ebp
int v7; // edi
unsigned int v8; // ebp
char *v9; // rbx
unsigned int v10; // er15
char v11; // al
char *v12; // rax
int fd; // [rsp+Ch] [rbp-67Ch]
char buf[512]; // [rsp+10h] [rbp-678h] BYREF
char v15; // [rsp+210h] [rbp-478h] BYREF
char s[1080]; // [rsp+250h] [rbp-438h] BYREF

if ( argc != 5 )
{
printf("usage: %s port speed file mode\n", *argv);
puts("where...");
puts(" port is the port device name");
puts(" speed is the port speed");
puts(" file is the filename of bitmap image");
puts(" mode is 0 for normal and 1 for reverse");
exit(0);
}
v3 = argv[2];
if ( !strcmp(v3, "-") )
{
fd = open(argv[1], 1026);
}
else
{
v4 = atoi(v3);
fd = func9(argv[1], v4, 0LL, 2LL);
}
v5 = buf;
v6 = open(argv[3], 2);
read(v6, buf, 0x3EuLL);
read(v6, buf, 0x200uLL);
v7 = v6;
v8 = 31;
close(v7);
LABEL_5:
v9 = v5;
v10 = 0;
while ( 1 )
{
v11 = *v9;
if ( *v9 < 0 )
{
func7(v10, v8);
v11 = *v9;
}
if ( (v11 & 0x40) != 0 )
{
func7(v10 + 1, v8);
v11 = *v9;
if ( (*v9 & 0x20) == 0 )
{
LABEL_7:
if ( (v11 & 0x10) == 0 )
goto LABEL_8;
goto LABEL_18;
}
}
else if ( (v11 & 0x20) == 0 )
{
goto LABEL_7;
}
func7(v10 + 2, v8);
v11 = *v9;
if ( (*v9 & 0x10) == 0 )
{
LABEL_8:
if ( (v11 & 8) == 0 )
goto LABEL_9;
goto LABEL_19;
}
LABEL_18:
func7(v10 + 3, v8);
v11 = *v9;
if ( (*v9 & 8) == 0 )
{
LABEL_9:
if ( (v11 & 4) == 0 )
goto LABEL_10;
goto LABEL_20;
}
LABEL_19:
func7(v10 + 4, v8);
v11 = *v9;
if ( (*v9 & 4) == 0 )
{
LABEL_10:
if ( (v11 & 2) == 0 )
goto LABEL_11;
goto LABEL_21;
}
LABEL_20:
func7(v10 + 5, v8);
v11 = *v9;
if ( (*v9 & 2) == 0 )
{
LABEL_11:
if ( (v11 & 1) != 0 )
goto LABEL_22;
goto LABEL_12;
}
LABEL_21:
func7(v10 + 6, v8);
if ( (*v9 & 1) != 0 )
LABEL_22:
func7(v10 + 7, v8);
LABEL_12:
v10 += 8;
++v9;
if ( v10 == 128 )
{
v5 += 16;
--v8;
if ( v5 == &v15 )
{
sprintf(s, "%cDG", 27LL);
if ( !atoi(argv[4]) )
{
v12 = &gxbits;
do
{
*v12 = ~*v12;
++v12;
}
while ( &end != (_UNKNOWN *)v12 );
}
write(fd, s, 3uLL);
write(fd, &gxbits, 0x1E0uLL);
close(fd);
exit(0);
}
goto LABEL_5;
}
}
}

original_code:
int main(int ac,char **av) {
  int fd, idx, j, i, x, y;
  char bmpin[574];
  char str[1024];
  int filein;
  if (ac!=5) {
    printf("usage: %s port speed file mode\n",av[0]);
    printf("where...\n");
    printf("  port is the port device name\n");
    printf("  speed is the port speed\n");
    printf("  file is the filename of bitmap image\n");
    printf("  mode is 0 for normal and 1 for reverse\n");
    exit(0);
  }
  if (! strcmp(av[2], "-" )) {
    fd=open(av[1], 02|02000);
  } else {
    fd=openRawSerialLine(av[1],atoi(av[2]),0,02);
  }
  filein=open(av[3], 02);
  read(filein, bmpin, 62);
  read(filein, bmpin, 512);
  close(filein);
  idx=0;
  for(j=31;j>-1;j--) {
     for(i=0;i<16;i++) {
 if (bmpin[idx] & 128) bset((i * 8), j);
 if (bmpin[idx] & 64) bset(((i * 8)+ 1), j);
 if (bmpin[idx] & 32) bset(((i * 8)+ 2), j);
 if (bmpin[idx] & 16) bset(((i * 8)+ 3), j);
 if (bmpin[idx] & 8) bset(((i * 8)+ 4), j);
 if (bmpin[idx] & 4) bset(((i * 8)+ 5), j);
 if (bmpin[idx] & 2) bset(((i * 8)+ 6), j);
 if (bmpin[idx] & 1) bset(((i * 8)+ 7), j);
 idx++;
     }
  }
  sprintf(str,"%cDG", 27);
  if(atoi(av[4])==0) {
    for (idx=0;idx<480;idx++) {
       gxbits[idx]=gxbits[idx] ^ 255;
    }
  }
  write(fd,str,3);
  write(fd,&gxbits,480);
  close(fd);
  exit(0);
}

canonical_original_code:
int main(int ac, char **av) {
  int fd; int idx; int j; int i; int x; int y;
  char bmpin[574];
  char str[1024];
  int filein;
  if (ac!=5) {
    printf("usage: %s port speed file mode\n",av[0]);
    printf("where...\n");
    printf("  port is the port device name\n");
    printf("  speed is the port speed\n");
    printf("  file is the filename of bitmap image\n");
    printf("  mode is 0 for normal and 1 for reverse\n");
    exit(0);
  }
  if (! strcmp(av[2], "-" )) {
    fd=open(av[1], 02|02000);
  } else {
    fd=openRawSerialLine(av[1],atoi(av[2]),0,02);
  }
  filein=open(av[3], 02);
  read(filein, bmpin, 62);
  read(filein, bmpin, 512);
  close(filein);
  idx=0;
  for(j=31;j>-1;j--) {
     for(i=0;i<16;i++) {
 if (bmpin[idx] & 128) bset((i * 8), j);
 if (bmpin[idx] & 64) bset(((i * 8)+ 1), j);
 if (bmpin[idx] & 32) bset(((i * 8)+ 2), j);
 if (bmpin[idx] & 16) bset(((i * 8)+ 3), j);
 if (bmpin[idx] & 8) bset(((i * 8)+ 4), j);
 if (bmpin[idx] & 4) bset(((i * 8)+ 5), j);
 if (bmpin[idx] & 2) bset(((i * 8)+ 6), j);
 if (bmpin[idx] & 1) bset(((i * 8)+ 7), j);
 idx++;
     }
  }
  sprintf(str,"%cDG", 27);
  if(atoi(av[4])==0) {
    for (idx=0;idx<480;idx++) {
       gxbits[idx]=gxbits[idx] ^ 255;
    }
  }
  write(fd,str,3);
  write(fd,&gxbits,480);
  close(fd);
  exit(0);
}

variable_types: ac int

variable_types:
av
char **

variable_types: idx int

variable_types: j int

variable_types:
bmpin
char [574]

variable_types:
str
char [1024]

variable_types: filein int


afinit

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

unspec_aftype[1] = "UNSPEC";
result = 1LL;
unix_aftype[1] = "UNIX Domain";
inet_aftype[1] = "DARPA Internet";
sVafinit = 1;
return result;
}

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

unspec_aftype[1] = "UNSPEC";
result = 1LL;
unix_aftype[1] = "UNIX Domain";
inet_aftype[1] = "DARPA Internet";
sVafinit = 1;
return result;
}

original_code:
void afinit()
{
    unspec_aftype.title = ("UNSPEC");
    unix_aftype.title = ("UNIX Domain");
    inet_aftype.title = ("DARPA Internet");
    sVafinit = 1;
}


decompiled_code:
char *__fastcall get_aftype(char *s)
{
char *v1; // r12
void **v2; // rbx

if ( !sVafinit )
afinit();
v1 = (char *)aftypes;
if ( aftypes )
{
v2 = &aftypes;
while ( strcmp(*(const char **)v1, s) )
{
v1 = (char *)v2[1];
++v2;
if ( !v1 )
goto LABEL_8;
}
return v1;
}
LABEL_8:
v1 = index(s, 44);
if ( !v1 )
return v1;
fwrite("Please don't supply more than one address family.\n", 1uLL, 0x32uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char *v1; // r12
void **v2; // rbx

if ( !sVafinit )
func0();
v1 = (char *)aftypes;
if ( aftypes )
{
v2 = &aftypes;
while ( strcmp(*(const char **)v1, s) )
{
v1 = (char *)v2[1];
++v2;
if ( !v1 )
goto LABEL_8;
}
return v1;
}
LABEL_8:
v1 = index(s, 44);
if ( !v1 )
return v1;
fwrite("Please don't supply more than one address family.\n", 1uLL, 0x32uLL, stderr);
return 0LL;
}

original_code:
struct aftype *get_aftype(const char *name)
{
    struct aftype **afp;
    if (!sVafinit)
 afinit();
    afp = aftypes;
    while (*afp != ((void *)0)) {
 if (!strcmp((*afp)->name, name))
     return (*afp);
 afp++;
    }
    if (index(name, ','))
 fprintf(stderr, ("Please don't supply more than one address family.\n"));
    return (((void *)0));
}

canonical_original_code:
struct aftype *get_aftype(char *name)
{
    struct aftype **afp;
    if (!sVafinit)
 afinit();
    afp = aftypes;
    while (*afp != ((void *)0)) {
 if (!strcmp((*afp)->name, name))
     return (*afp);
 afp++;
    }
    if (index(name, ','))
 fprintf(stderr, ("Please don't supply more than one address family.\n"));
    return (((void *)0));
}

variable_types:
name
char *

variable_types: struct aftype { char *name; char *title; int af; int alen; char *(*print)(unsigned char *); char *(*sprint)(struct sockaddr { unsigned short sa_family; char sa_data[14]; } *, int numeric); int (*input)(int type, char *bufp, struct sockaddr *); void (*herror)(char *text); int (*rprint)(int options); int (*rinput)(int typ, int ext, char **argv); int (*getmask)(char *src, struct sockaddr *mask, char *name); int fd; char *flag_file; } **


decompiled_code:
__int64 __fastcall get_socket_for_af(int a1)
{
_DWORD *v1; // rax
void **v2; // rdx

if ( !sVafinit )
afinit();
v1 = aftypes;
if ( !aftypes )
return 0xFFFFFFFFLL;
v2 = &aftypes;
while ( v1[4] != a1 )
{
v1 = v2[1];
++v2;
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v1[20];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
_DWORD *v1; // rax
void **v2; // rdx

if ( !sVafinit )
func0();
v1 = aftypes;
if ( !aftypes )
return 0xFFFFFFFFLL;
v2 = &aftypes;
while ( v1[4] != a1 )
{
v1 = v2[1];
++v2;
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v1[20];
}

original_code:
int get_socket_for_af(int af)
{
    struct aftype **afp;
    if (!sVafinit)
 afinit();
    afp = aftypes;
    while (*afp != ((void *)0)) {
 if ((*afp)->af == af)
     return (*afp)->fd;
 afp++;
    }
    return -1;
}

variable_types: af int


decompiled_code:
__int64 __fastcall aftrans_opt(__int64 a1)
{
const char *v1; // r13
char *v2; // rbp
const char *v3; // r15
size_t v4; // r13
char *v5; // rax
const char *v6; // r14
char *v7; // rax
const char *v8; // rsi
char **v9; // rbx
unsigned int v10; // er12
_BYTE v12[312]; // [rsp+0h] [rbp-138h] BYREF

v1 = v12;
safe_strncpy(v12, a1, 256LL);
v2 = aftrans;
while ( 1 )
{
v6 = 0LL;
v7 = index(v1, 44);
if ( v7 )
{
*v7 = 0;
v6 = v7 + 1;
}
if ( !v2 )
{
LABEL_15:
v10 = 1;
fprintf(stderr, "Unknown address family `%s'.\n", v1);
return v10;
}
v8 = v2;
v9 = &aftrans;
while ( 1 )
{
v10 = strcmp(v1, v8);
if ( !v10 )
break;
v8 = v9[3];
v9 += 3;
if ( !v8 )
goto LABEL_15;
}
v3 = v9[1];
v4 = strlen(v3);
if ( v4 + strlen(afname) + 1 > 0xFF )
break;
v5 = v9[2];
if ( v5 )
++*(_DWORD *)v5;
if ( afname[0] )
*(_WORD *)&afname[strlen(afname)] = 44;
strcat(afname, v3);
if ( !v6 )
return v10;
v1 = v6;
}
fwrite("Too much address family arguments.\n", 1uLL, 0x23uLL, stderr);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char *v1; // r13
char *v2; // rbp
const char *v3; // r15
size_t v4; // r13
char *v5; // rax
const char *v6; // r14
char *v7; // rax
const char *v8; // rsi
char **v9; // rbx
unsigned int v10; // er12
_BYTE v12[312]; // [rsp+0h] [rbp-138h] BYREF

v1 = v12;
safe_strncpy(v12, a1, 256LL);
v2 = aftrans;
while ( 1 )
{
v6 = 0LL;
v7 = index(v1, 44);
if ( v7 )
{
*v7 = 0;
v6 = v7 + 1;
}
if ( !v2 )
{
LABEL_15:
v10 = 1;
fprintf(stderr, "Unknown address family `%s'.\n", v1);
return v10;
}
v8 = v2;
v9 = &aftrans;
while ( 1 )
{
v10 = strcmp(v1, v8);
if ( !v10 )
break;
v8 = v9[3];
v9 += 3;
if ( !v8 )
goto LABEL_15;
}
v3 = v9[1];
v4 = strlen(v3);
if ( v4 + strlen(afname) + 1 > 0xFF )
break;
v5 = v9[2];
if ( v5 )
++*(_DWORD *)v5;
if ( afname[0] )
*(_WORD *)&afname[strlen(afname)] = 44;
strcat(afname, v3);
if ( !v6 )
return v10;
v1 = v6;
}
fwrite("Too much address family arguments.\n", 1uLL, 0x23uLL, stderr);
return v10;
}

original_code:
int aftrans_opt(const char *arg)
{
    struct aftrans_t *paft;
    char *tmp1, *tmp2;
    char buf[256];
    safe_strncpy(buf, arg, sizeof(buf));
    tmp1 = buf;
    while (tmp1) {
 tmp2 = index(tmp1, ',');
 if (tmp2)
     *(tmp2++) = '\0';
 paft = aftrans;
 for (paft = aftrans; paft->alias; paft++) {
     if (strcmp(tmp1, paft->alias))
  continue;
     if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) {
  fprintf(stderr, ("Too much address family arguments.\n"));
  return (0);
     }
     if (paft->flag)
  (*paft->flag)++;
     if (afname[0])
  strcat(afname, ",");
     strcat(afname, paft->name);
     break;
 }
 if (!paft->alias) {
     fprintf(stderr, ("Unknown address family `%s'.\n"), tmp1);
     return (1);
 }
 tmp1 = tmp2;
    }
    return (0);
}

canonical_original_code:
int aftrans_opt(char *arg)
{
    struct aftrans_t *paft;
    char *tmp1; char *tmp2;
    char buf[256];
    safe_strncpy(buf, arg, sizeof(buf));
    tmp1 = buf;
    while (tmp1) {
 tmp2 = index(tmp1, ',');
 if (tmp2)
     *(tmp2++) = '\0';
 paft = aftrans;
 for (paft = aftrans; paft->alias; paft++) {
     if (strcmp(tmp1, paft->alias))
  continue;
     if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) {
  fprintf(stderr, ("Too much address family arguments.\n"));
  return (0);
     }
     if (paft->flag)
  (*paft->flag)++;
     if (afname[0])
  strcat(afname, ",");
     strcat(afname, paft->name);
     break;
 }
 if (!paft->alias) {
     fprintf(stderr, ("Unknown address family `%s'.\n"), tmp1);
     return (1);
 }
 tmp1 = tmp2;
    }
    return (0);
}

variable_types:
arg
char *

variable_types: struct aftrans_t { char *alias; char *name; int *flag; } *

variable_types:
buf
char [256]


decompiled_code:
void __fastcall aftrans_def(char *s, char *a2, char *src)
{
char *v3; // rbp
char *v4; // rax
char *v5; // rax
char *v6; // r13
size_t v7; // rbx
size_t v8; // rax
const char *v9; // rbx
char *v10; // rax

v3 = a2;
strcpy(afname, src);
v4 = strrchr(a2, 47);
if ( v4 )
v3 = v4 + 1;
v5 = strdup(v3);
if ( v5 )
{
v6 = v5;
v7 = strlen(s);
v8 = strlen(v3);
if ( v7 < v8 )
{
v9 = &v6[v8 - v7];
if ( !strcmp(v9, s) )
{
*v9 = 0;
v10 = strchr(v6, 95);
if ( v10 )
*v10 = 0;
afname[0] = 0;
if ( (unsigned int)aftrans_opt((__int64)v6) )
strcpy(afname, v6);
}
}
free(v6);
}
}

canonical_decompiled_code:
void __fastcall func4(char *s, char *a2, char *src)
{
char *v3; // rbp
char *v4; // rax
char *v5; // rax
char *v6; // r13
size_t v7; // rbx
size_t v8; // rax
const char *v9; // rbx
char *v10; // rax

v3 = a2;
strcpy(afname, src);
v4 = strrchr(a2, 47);
if ( v4 )
v3 = v4 + 1;
v5 = strdup(v3);
if ( v5 )
{
v6 = v5;
v7 = strlen(s);
v8 = strlen(v3);
if ( v7 < v8 )
{
v9 = &v6[v8 - v7];
if ( !strcmp(v9, s) )
{
*v9 = 0;
v10 = strchr(v6, 95);
if ( v10 )
*v10 = 0;
afname[0] = 0;
if ( (unsigned int)func3((__int64)v6) )
strcpy(afname, v6);
}
}
free(v6);
}
}

original_code:
void aftrans_def(char *tool, char *argv0, char *dflt)
{
    char *tmp;
    char *buf;
    strcpy(afname, dflt);
    if (!(tmp = strrchr(argv0, '/')))
 tmp = argv0;
    else
 tmp++;
    if (!(buf = strdup(tmp)))
 return;
    if (strlen(tool) >= strlen(tmp)) {
 free(buf);
 return;
    }
    tmp = buf + (strlen(tmp) - strlen(tool));
    if (strcmp(tmp, tool) != 0) {
 free(buf);
 return;
    }
    *tmp = '\0';
    if ((tmp = strchr(buf, '_')))
 *tmp = '\0';
    afname[0] = '\0';
    if (aftrans_opt(buf))
 strcpy(afname, buf);
    free(buf);
}

variable_types:
tool
char *

variable_types:
dflt
char *

variable_types:
tmp
char *

variable_types:
buf
char *