reservedLookup

decompiled_code:
__int64 __fastcall reservedLookup(char *s1)
{
int v1; // er13
int v2; // ebp
int v3; // ebx
char **v4; // r14
int v5; // eax

if ( !s1 )
_assert_fail("str != NULL", "lexical.c", 0x21u, "reservedLookup");
v1 = 14;
v2 = 0;
while ( 1 )
{
v3 = (v2 + v1) >> 1;
v4 = &(&reservedWords)[2 * v3];
v5 = strcmp(s1, *v4);
if ( !v5 )
break;
if ( v5 >= 0 )
{
v2 = v3 + 1;
if ( v3 + 1 > v1 )
return 18LL;
}
else
{
v1 = v3 - 1;
if ( v2 > v3 - 1 )
return 18LL;
}
}
return *((unsigned int *)v4 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
int v1; // er13
int v2; // ebp
int v3; // ebx
char **v4; // r14
int v5; // eax

if ( !s1 )
_assert_fail("str != NULL", "lexical.c", 0x21u, "reservedLookup");
v1 = 14;
v2 = 0;
while ( 1 )
{
v3 = (v2 + v1) >> 1;
v4 = &(&reservedWords)[2 * v3];
v5 = strcmp(s1, *v4);
if ( !v5 )
break;
if ( v5 >= 0 )
{
v2 = v3 + 1;
if ( v3 + 1 > v1 )
return 18LL;
}
else
{
v1 = v3 - 1;
if ( v2 > v3 - 1 )
return 18LL;
}
}
return *((unsigned int *)v4 + 2);
}

original_code:
TokenType reservedLookup(const char* str)
{
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "lexical.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    int low = 0;
    int high = 15 - 1;
    while (low <= high)
    {
 int mid = (low + high) / 2;
 if (strcmp(str, reservedWords[mid].str) == 0)
 {
     return reservedWords[mid].tok;
 }
 else if (strcmp(str, reservedWords[mid].str) < 0)
 {
     high = mid - 1;
 }
 else if (strcmp(str, reservedWords[mid].str) > 0)
 {
     low = mid + 1;
 }
    }
    return ID;
}

canonical_original_code:
enum TokenType reservedLookup(char *str)
{
    ((void) sizeof ((str != ((void *)0)) ? 1 : 0), __extension__ ({ if (str != ((void *)0)) ; else __assert_fail ("str != NULL", "lexical.c", 33, __extension__ __PRETTY_FUNCTION__); }));
    int low = 0;
    int high = 15 - 1;
    while (low <= high)
    {
 int mid = (low + high) / 2;
 if (strcmp(str, reservedWords[mid].str) == 0)
 {
     return reservedWords[mid].tok;
 }
 else if (strcmp(str, reservedWords[mid].str) < 0)
 {
     high = mid - 1;
 }
 else if (strcmp(str, reservedWords[mid].str) > 0)
 {
     low = mid + 1;
 }
    }
    return ID;
}

variable_types:
str
char *

variable_types: low int

variable_types: high int

variable_types: mid int

return_type: enum TokenType { ENDFILE=0, ERROR=1, PROGRAM_K=2, CONST_K=3, VAR_K=4, PROCEDURE_K=5, BEGIN_K=6, END_K=7, IF_K=8, WHILE_K=9, CALL_K=10, DO_K=11, ELSE_K=12, THEN_K=13, WRITE_K=14, ODD_K=15, READ_K=16, NUM=17, ID=18, ASSIGN=19, EQ=20, LT=21, GT=22, PLUS=23, MINUS=24, TIMES=25, OVER=26, LPAREN=27, RPAREN=28, SEMI=29, COMM=30, LTEQ=31, GTEQ=32, NOEQ=33 }


getNextChar

decompiled_code:
__int64 getNextChar()
{
__int64 result; // rax
int v1; // eax

if ( linepos < buffersize )
return (unsigned int)lineBuf[linepos++];
++lineno;
if ( fgets(lineBuf, 127, source) )
{
printf("%4d: %s", (unsigned int)lineno, lineBuf);
v1 = strlen(lineBuf);
linepos = 1;
buffersize = v1;
result = (unsigned int)lineBuf[0];
}
else
{
EOF_Flag = 1;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // eax

if ( linepos < buffersize )
return (unsigned int)lineBuf[linepos++];
++lineno;
if ( fgets(lineBuf, 127, source) )
{
printf("%4d: %s", (unsigned int)lineno, lineBuf);
v1 = strlen(lineBuf);
linepos = 1;
buffersize = v1;
result = (unsigned int)lineBuf[0];
}
else
{
EOF_Flag = 1;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int getNextChar(void)
{
    if (!(linepos < buffersize))
    {
 lineno++;
 if (fgets(lineBuf, 128 - 1, source))
 {
     printf("%4d: %s", lineno, lineBuf);
     buffersize = strlen(lineBuf);
     linepos = 0;
     return lineBuf[linepos++];
 }
 else
 {
     EOF_Flag = 1;
     return (-1);
 }
    }
    else
    {
 return lineBuf[linepos++];
    }
}

canonical_original_code:
int getNextChar()
{
    if (!(linepos < buffersize))
    {
 lineno++;
 if (fgets(lineBuf, 128 - 1, source))
 {
     printf("%4d: %s", lineno, lineBuf);
     buffersize = strlen(lineBuf);
     linepos = 0;
     return lineBuf[linepos++];
 }
 else
 {
     EOF_Flag = 1;
     return (-1);
 }
    }
    else
    {
 return lineBuf[linepos++];
    }
}

return_type: int


ungetNextChar

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

result = (unsigned int)EOF_Flag;
if ( !EOF_Flag )
--linepos;
return result;
}

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

result = (unsigned int)EOF_Flag;
if ( !EOF_Flag )
--linepos;
return result;
}

original_code:
void ungetNextChar(void)
{
    if (!EOF_Flag)
    {
 linepos--;
    }
}

canonical_original_code:
void ungetNextChar()
{
    if (!EOF_Flag)
    {
 linepos--;
    }
}

return_type: void


printToken

decompiled_code:
int __fastcall printToken(unsigned int a1, const char *a2)
{
int result; // eax

if ( !a2 )
_assert_fail("tokString != NULL", "lexical.c", 0x11Du, "printToken");
switch ( a1 )
{
case 0u:
result = puts("EOF");
break;
case 1u:
result = printf("ERROR: %s\n", a2);
++lex_error;
break;
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = printf("reserved word: %s\n", a2);
break;
case 0x11u:
result = printf("NUM, val = %s\n", a2);
break;
case 0x12u:
result = printf("ID, name = %s\n", a2);
break;
case 0x13u:
result = puts(":=");
break;
case 0x14u:
result = puts("=");
break;
case 0x15u:
result = puts("<");
break;
case 0x16u:
result = puts(asc_8E0);
break;
case 0x17u:
result = puts(&asc_8E0[2]);
break;
case 0x19u:
result = puts(&asc_8E0[4]);
break;
case 0x1Au:
result = puts(&asc_8E0[6]);
break;
case 0x1Bu:
result = puts(asc_8E8);
break;
case 0x1Cu:
result = puts(&asc_8E8[2]);
break;
case 0x1Du:
result = puts(&asc_8E8[4]);
break;
case 0x1Eu:
result = puts(&asc_8E8[6]);
break;
case 0x1Fu:
result = puts("<=");
break;
case 0x20u:
result = puts(">=");
break;
case 0x21u:
result = puts("<>");
break;
default:
result = printf("Unkown token: %d\n", a1);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, const char *a2)
{
int result; // eax

if ( !a2 )
_assert_fail("tokString != NULL", "lexical.c", 0x11Du, "printToken");
switch ( a1 )
{
case 0u:
result = puts("EOF");
break;
case 1u:
result = printf("ERROR: %s\n", a2);
++lex_error;
break;
case 2u:
case 3u:
case 4u:
case 5u:
case 6u:
case 7u:
case 8u:
case 9u:
case 0xAu:
case 0xBu:
case 0xCu:
case 0xDu:
case 0xEu:
case 0xFu:
case 0x10u:
result = printf("reserved word: %s\n", a2);
break;
case 0x11u:
result = printf("NUM, val = %s\n", a2);
break;
case 0x12u:
result = printf("ID, name = %s\n", a2);
break;
case 0x13u:
result = puts(":=");
break;
case 0x14u:
result = puts("=");
break;
case 0x15u:
result = puts("<");
break;
case 0x16u:
result = puts(asc_8E0);
break;
case 0x17u:
result = puts(&asc_8E0[2]);
break;
case 0x19u:
result = puts(&asc_8E0[4]);
break;
case 0x1Au:
result = puts(&asc_8E0[6]);
break;
case 0x1Bu:
result = puts(asc_8E8);
break;
case 0x1Cu:
result = puts(&asc_8E8[2]);
break;
case 0x1Du:
result = puts(&asc_8E8[4]);
break;
case 0x1Eu:
result = puts(&asc_8E8[6]);
break;
case 0x1Fu:
result = puts("<=");
break;
case 0x20u:
result = puts(">=");
break;
case 0x21u:
result = puts("<>");
break;
default:
result = printf("Unkown token: %d\n", a1);
break;
}
return result;
}

original_code:
void printToken(TokenType token, const char* tokString)
{
    ((void) sizeof ((tokString != ((void *)0)) ? 1 : 0), __extension__ ({ if (tokString != ((void *)0)) ; else __assert_fail ("tokString != NULL", "lexical.c", 285, __extension__ __PRETTY_FUNCTION__); }));
    switch (token)
    {
    case PROGRAM_K:
    case CONST_K:
    case VAR_K:
    case PROCEDURE_K:
    case BEGIN_K:
    case END_K:
    case IF_K:
    case WHILE_K:
    case CALL_K:
    case DO_K:
    case ELSE_K:
    case THEN_K:
    case WRITE_K:
    case ODD_K:
    case READ_K:
         printf("reserved word: %s\n", tokString);
  break;
    case ENDFILE:
         printf("EOF\n");
  break;
    case ERROR:
         printf("ERROR: %s\n", tokString);
  ++lex_error;
  break;
    case NUM:
         printf("NUM, val = %s\n", tokString);
  break;
    case ID:
         printf("ID, name = %s\n", tokString);
  break;
    case ASSIGN:
         printf(":=\n");
  break;
    case EQ:
         printf("=\n");
  break;
    case LT:
         printf("<\n");
  break;
    case GT:
         printf(">\n");
  break;
    case PLUS:
         printf("+\n");
  break;
    case TIMES:
         printf("*\n");
         break;
    case OVER:
         printf("/\n");
  break;
    case LPAREN:
         printf("(\n");
  break;
    case RPAREN:
         printf(")\n");
  break;
    case SEMI:
         printf(";\n");
  break;
    case COMM:
         printf(",\n");
  break;
    case LTEQ:
         printf("<=\n");
  break;
    case GTEQ:
         printf(">=\n");
  break;
    case NOEQ:
         printf("<>\n");
  break;
    default:
         printf("Unkown token: %d\n", token);
  break;
    }
}

canonical_original_code:
void printToken(enum TokenType token, char *tokString)
{
    ((void) sizeof ((tokString != ((void *)0)) ? 1 : 0), __extension__ ({ if (tokString != ((void *)0)) ; else __assert_fail ("tokString != NULL", "lexical.c", 285, __extension__ __PRETTY_FUNCTION__); }));
    switch (token)
    {
    case PROGRAM_K:
    case CONST_K:
    case VAR_K:
    case PROCEDURE_K:
    case BEGIN_K:
    case END_K:
    case IF_K:
    case WHILE_K:
    case CALL_K:
    case DO_K:
    case ELSE_K:
    case THEN_K:
    case WRITE_K:
    case ODD_K:
    case READ_K:
         printf("reserved word: %s\n", tokString);
  break;
    case ENDFILE:
         printf("EOF\n");
  break;
    case ERROR:
         printf("ERROR: %s\n", tokString);
  ++lex_error;
  break;
    case NUM:
         printf("NUM, val = %s\n", tokString);
  break;
    case ID:
         printf("ID, name = %s\n", tokString);
  break;
    case ASSIGN:
         printf(":=\n");
  break;
    case EQ:
         printf("=\n");
  break;
    case LT:
         printf("<\n");
  break;
    case GT:
         printf(">\n");
  break;
    case PLUS:
         printf("+\n");
  break;
    case TIMES:
         printf("*\n");
         break;
    case OVER:
         printf("/\n");
  break;
    case LPAREN:
         printf("(\n");
  break;
    case RPAREN:
         printf(")\n");
  break;
    case SEMI:
         printf(";\n");
  break;
    case COMM:
         printf(",\n");
  break;
    case LTEQ:
         printf("<=\n");
  break;
    case GTEQ:
         printf(">=\n");
  break;
    case NOEQ:
         printf("<>\n");
  break;
    default:
         printf("Unkown token: %d\n", token);
  break;
    }
}

variable_types: enum TokenType { ENDFILE=0, ERROR=1, PROGRAM_K=2, CONST_K=3, VAR_K=4, PROCEDURE_K=5, BEGIN_K=6, END_K=7, IF_K=8, WHILE_K=9, CALL_K=10, DO_K=11, ELSE_K=12, THEN_K=13, WRITE_K=14, ODD_K=15, READ_K=16, NUM=17, ID=18, ASSIGN=19, EQ=20, LT=21, GT=22, PLUS=23, MINUS=24, TIMES=25, OVER=26, LPAREN=27, RPAREN=28, SEMI=29, COMM=30, LTEQ=31, GTEQ=32, NOEQ=33 }

variable_types:
tokString
char *


getToken

decompiled_code:
__int64 getToken()
{
int v0; // er12
__int64 v1; // rbp
int v2; // ebx
unsigned int v3; // er13
int v4; // er12
const unsigned __int16 **v6; // r13
unsigned __int16 v7; // ax
int v8; // eax
__int64 i; // r12
__int64 j; // r12
__int64 v11; // rax
int v12; // eax

v0 = 0;
v1 = 0LL;
LABEL_2:
v2 = getNextChar();
switch ( v0 )
{
case 0:
v4 = v1;
break;
case 1:
LABEL_5:
v3 = 19;
if ( v2 == 61 )
goto LABEL_6;
goto LABEL_24;
case 2:
goto LABEL_43;
case 3:
goto LABEL_45;
}
LABEL_12:
v6 = _ctype_b_loc();
while ( 1 )
{
v7 = (*v6)[v2];
if ( (v7 & 0x800) != 0 )
{
if ( (int)v1 > 40 )
{
v2 = getNextChar();
LABEL_43:
v6 = _ctype_b_loc();
}
else
{
tokenString[(int)v1] = v2;
LODWORD(v1) = v1 + 1;
v2 = getNextChar();
}
for ( i = (int)v1; ; ++i )
{
v1 = (int)i;
if ( ((*v6)[v2] & 0x800) == 0 )
break;
if ( (int)i > 40 )
{
v0 = 2;
goto LABEL_2;
}
tokenString[i] = v2;
v2 = getNextChar();
}
ungetNextChar();
v3 = 17;
tokenString[(int)i] = 0;
goto LABEL_10;
}
if ( (v7 & 0x400) != 0 )
{
if ( (int)v1 > 40 )
{
v2 = getNextChar();
LABEL_45:
v6 = _ctype_b_loc();
}
else
{
tokenString[(int)v1] = v2;
LODWORD(v1) = v1 + 1;
v2 = getNextChar();
}
for ( j = (int)v1; ; ++j )
{
v1 = (int)j;
if ( ((*v6)[v2] & 0xC00) == 0 )
break;
if ( (int)j > 40 )
{
v0 = 3;
goto LABEL_2;
}
tokenString[j] = v2;
v2 = getNextChar();
}
ungetNextChar();
tokenString[(int)j] = 0;
goto LABEL_9;
}
if ( v2 == 58 )
break;
if ( (unsigned int)(v2 - 9) > 1 && v2 != 32 )
{
switch ( v2 )
{
case '>':
if ( (int)v1 <= 40 )
{
tokenString[(int)v1] = 62;
LODWORD(v1) = v1 + 1;
v3 = 32;
v8 = getNextChar();
LOBYTE(v2) = v8;
if ( v8 == 61 )
break;
goto LABEL_21;
}
v3 = 32;
if ( (unsigned int)getNextChar() != 61 )
{
LABEL_21:
ungetNextChar();
v3 = 22;
}
LABEL_22:
tokenString[(int)v1] = 0;
goto LABEL_10;
case '<':
if ( (int)v1 > 40 )
{
v2 = getNextChar();
if ( v2 == 61 )
{
v3 = 31;
goto LABEL_22;
}
}
else
{
tokenString[(int)v1] = 60;
LODWORD(v1) = v1 + 1;
v2 = getNextChar();
if ( v2 == 61 )
{
v3 = 31;
break;
}
}
v3 = 33;
if ( v2 != 62 )
{
ungetNextChar();
v3 = 21;
tokenString[(int)v1] = 0;
goto LABEL_10;
}
break;
case '{':
while ( 1 )
{
v12 = getNextChar();
if ( v12 == -1 )
break;
if ( v12 == 125 )
{
v2 = getNextChar();
goto LABEL_12;
}
}
tokenString[v1] = 0;
v3 = 0;
goto LABEL_10;
default:
v11 = (unsigned int)(v2 + 1);
if ( (unsigned int)v11 <= 0x3E )
{
v3 = (unsigned __int8)CSWTCH_19[v11];
if ( (CSWTCH_20[v11] & 1) != 0 && (int)v1 <= 40 )
goto LABEL_7;
goto LABEL_8;
}
v3 = 1;
break;
}
LABEL_6:
if ( (int)v1 > 40 )
goto LABEL_22;
LABEL_7:
v4 = v1 + 1;
tokenString[(int)v1] = v2;
LABEL_8:
tokenString[v4] = 0;
if ( v3 != 18 )
goto LABEL_10;
LABEL_9:
v3 = reservedLookup(tokenString);
goto LABEL_10;
}
v2 = getNextChar();
}
if ( (int)v1 <= 40 )
{
tokenString[(int)v1] = 58;
LODWORD(v1) = v1 + 1;
v2 = getNextChar();
goto LABEL_5;
}
v3 = 19;
if ( (unsigned int)getNextChar() == 61 )
goto LABEL_22;
LABEL_24:
ungetNextChar();
v3 = 1;
tokenString[(int)v1] = 0;
LABEL_10:
printf("\t%d: ", (unsigned int)lineno);
printToken(v3, tokenString);
return v3;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // er12
__int64 v1; // rbp
int v2; // ebx
unsigned int v3; // er13
int v4; // er12
const unsigned __int16 **v6; // r13
unsigned __int16 v7; // ax
int v8; // eax
__int64 i; // r12
__int64 j; // r12
__int64 v11; // rax
int v12; // eax

v0 = 0;
v1 = 0LL;
LABEL_2:
v2 = func1();
switch ( v0 )
{
case 0:
v4 = v1;
break;
case 1:
LABEL_5:
v3 = 19;
if ( v2 == 61 )
goto LABEL_6;
goto LABEL_24;
case 2:
goto LABEL_43;
case 3:
goto LABEL_45;
}
LABEL_12:
v6 = _ctype_b_loc();
while ( 1 )
{
v7 = (*v6)[v2];
if ( (v7 & 0x800) != 0 )
{
if ( (int)v1 > 40 )
{
v2 = func1();
LABEL_43:
v6 = _ctype_b_loc();
}
else
{
tokenString[(int)v1] = v2;
LODWORD(v1) = v1 + 1;
v2 = func1();
}
for ( i = (int)v1; ; ++i )
{
v1 = (int)i;
if ( ((*v6)[v2] & 0x800) == 0 )
break;
if ( (int)i > 40 )
{
v0 = 2;
goto LABEL_2;
}
tokenString[i] = v2;
v2 = func1();
}
func2();
v3 = 17;
tokenString[(int)i] = 0;
goto LABEL_10;
}
if ( (v7 & 0x400) != 0 )
{
if ( (int)v1 > 40 )
{
v2 = func1();
LABEL_45:
v6 = _ctype_b_loc();
}
else
{
tokenString[(int)v1] = v2;
LODWORD(v1) = v1 + 1;
v2 = func1();
}
for ( j = (int)v1; ; ++j )
{
v1 = (int)j;
if ( ((*v6)[v2] & 0xC00) == 0 )
break;
if ( (int)j > 40 )
{
v0 = 3;
goto LABEL_2;
}
tokenString[j] = v2;
v2 = func1();
}
func2();
tokenString[(int)j] = 0;
goto LABEL_9;
}
if ( v2 == 58 )
break;
if ( (unsigned int)(v2 - 9) > 1 && v2 != 32 )
{
switch ( v2 )
{
case '>':
if ( (int)v1 <= 40 )
{
tokenString[(int)v1] = 62;
LODWORD(v1) = v1 + 1;
v3 = 32;
v8 = func1();
LOBYTE(v2) = v8;
if ( v8 == 61 )
break;
goto LABEL_21;
}
v3 = 32;
if ( (unsigned int)func1() != 61 )
{
LABEL_21:
func2();
v3 = 22;
}
LABEL_22:
tokenString[(int)v1] = 0;
goto LABEL_10;
case '<':
if ( (int)v1 > 40 )
{
v2 = func1();
if ( v2 == 61 )
{
v3 = 31;
goto LABEL_22;
}
}
else
{
tokenString[(int)v1] = 60;
LODWORD(v1) = v1 + 1;
v2 = func1();
if ( v2 == 61 )
{
v3 = 31;
break;
}
}
v3 = 33;
if ( v2 != 62 )
{
func2();
v3 = 21;
tokenString[(int)v1] = 0;
goto LABEL_10;
}
break;
case '{':
while ( 1 )
{
v12 = func1();
if ( v12 == -1 )
break;
if ( v12 == 125 )
{
v2 = func1();
goto LABEL_12;
}
}
tokenString[v1] = 0;
v3 = 0;
goto LABEL_10;
default:
v11 = (unsigned int)(v2 + 1);
if ( (unsigned int)v11 <= 0x3E )
{
v3 = (unsigned __int8)CSWTCH_19[v11];
if ( (CSWTCH_20[v11] & 1) != 0 && (int)v1 <= 40 )
goto LABEL_7;
goto LABEL_8;
}
v3 = 1;
break;
}
LABEL_6:
if ( (int)v1 > 40 )
goto LABEL_22;
LABEL_7:
v4 = v1 + 1;
tokenString[(int)v1] = v2;
LABEL_8:
tokenString[v4] = 0;
if ( v3 != 18 )
goto LABEL_10;
LABEL_9:
v3 = func0(tokenString);
goto LABEL_10;
}
v2 = func1();
}
if ( (int)v1 <= 40 )
{
tokenString[(int)v1] = 58;
LODWORD(v1) = v1 + 1;
v2 = func1();
goto LABEL_5;
}
v3 = 19;
if ( (unsigned int)func1() == 61 )
goto LABEL_22;
LABEL_24:
func2();
v3 = 1;
tokenString[(int)v1] = 0;
LABEL_10:
printf("\t%d: ", (unsigned int)lineno);
func3(v3, tokenString);
return v3;
}

original_code:
TokenType getToken(void)
{
    int tokenStringIndex = 0;
    TokenType currentToken;
    StateType state = START;
    int save;
    while (state != DONE)
    {
 int c = getNextChar();
 save = 1;
 switch (state)
 {
 case START:
      if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
      {
   state = INNUM;
      }
      else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha))
      {
   state = INID;
      }
      else if (c == ':')
      {
   state = INASSIGN;
      }
             else if (c == ' ' || c == '\t' || c == '\n')
      {
   save = 0;
      }
      else if (c == '>')
      {
   state = INGT;
      }
             else if (c == '<')
      {
   state = INLT;
      }
      else if (c == '{')
      {
   save = 0;
   state = INCOMMENT;
      }
      else
      {
   state = DONE;
   switch (c)
   {
   case (-1):
        save = 0;
        currentToken = ENDFILE;
        break;
   case '=':
        currentToken = EQ;
        break;
   case '+':
        currentToken = PLUS;
        break;
   case '-':
        currentToken = MINUS;
        break;
   case '*':
        currentToken = TIMES;
        break;
   case '/':
        currentToken = OVER;
        break;
   case ';':
        currentToken = SEMI;
        break;
   case ',':
        currentToken = COMM;
        break;
   case ')':
        currentToken = RPAREN;
        break;
   case '(':
        currentToken = LPAREN;
        break;
   default:
        currentToken = ERROR;
        break;
   }
      }
      break;
 case INLT:
      if (c == '=')
      {
   currentToken = LTEQ;
      }
      else if (c == '>')
      {
   currentToken = NOEQ;
      }
      else
      {
   ungetNextChar();
   save = 0;
   currentToken = LT;
      }
      state = DONE;
      break;
 case INGT:
      if (c == '=')
      {
   currentToken = GTEQ;
      }
      else
      {
   ungetNextChar();
   save = 0;
   currentToken = GT;
      }
      state = DONE;
      break;
 case INASSIGN:
      if (c == '=')
      {
   currentToken = ASSIGN;
      }
      else
      {
   ungetNextChar();
   save = 0;
   currentToken = ERROR;
      }
      state = DONE;
      break;
 case INNUM:
      if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
      {
   ungetNextChar();
   save = 0;
   state = DONE;
   currentToken = NUM;
      }
      break;
 case INID:
      if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha) && !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit))
      {
   ungetNextChar();
   save = 0;
   state = DONE;
   currentToken = ID;
      }
      break;
 case INCOMMENT:
      save = 0;
      if (c == (-1))
      {
   state = DONE;
   currentToken = ENDFILE;
      }
      else if (c == '}')
   state = START;
      break;
 case DONE:
      break;
 default:
      printf("Scanner bug: state = %d\n", state);
      state = DONE;
      currentToken = ERROR;
 }
 if ((save) && (tokenStringIndex <= 40))
 {
     tokenString[tokenStringIndex++] = (char)c;
 }
 if (state == DONE)
 {
     tokenString[tokenStringIndex] = '\0';
     if (currentToken == ID)
     {
  currentToken = reservedLookup(tokenString);
     }
     printf("\t%d: ", lineno);
     printToken(currentToken, tokenString);
 }
    }
    return currentToken;
}

canonical_original_code:
enum TokenType getToken()
{
    int tokenStringIndex = 0;
    enum TokenType currentToken;
    enum StateType state = START;
    int save;
    while (state != DONE)
    {
 int c = getNextChar();
 save = 1;
 switch (state)
 {
 case START:
      if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
      {
   state = INNUM;
      }
      else if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha))
      {
   state = INID;
      }
      else if (c == ':')
      {
   state = INASSIGN;
      }
             else if (c == ' ' || c == '\t' || c == '\n')
      {
   save = 0;
      }
      else if (c == '>')
      {
   state = INGT;
      }
             else if (c == '<')
      {
   state = INLT;
      }
      else if (c == '{')
      {
   save = 0;
   state = INCOMMENT;
      }
      else
      {
   state = DONE;
   switch (c)
   {
   case (-1):
        save = 0;
        currentToken = ENDFILE;
        break;
   case '=':
        currentToken = EQ;
        break;
   case '+':
        currentToken = PLUS;
        break;
   case '-':
        currentToken = MINUS;
        break;
   case '*':
        currentToken = TIMES;
        break;
   case '/':
        currentToken = OVER;
        break;
   case ';':
        currentToken = SEMI;
        break;
   case ',':
        currentToken = COMM;
        break;
   case ')':
        currentToken = RPAREN;
        break;
   case '(':
        currentToken = LPAREN;
        break;
   default:
        currentToken = ERROR;
        break;
   }
      }
      break;
 case INLT:
      if (c == '=')
      {
   currentToken = LTEQ;
      }
      else if (c == '>')
      {
   currentToken = NOEQ;
      }
      else
      {
   ungetNextChar();
   save = 0;
   currentToken = LT;
      }
      state = DONE;
      break;
 case INGT:
      if (c == '=')
      {
   currentToken = GTEQ;
      }
      else
      {
   ungetNextChar();
   save = 0;
   currentToken = GT;
      }
      state = DONE;
      break;
 case INASSIGN:
      if (c == '=')
      {
   currentToken = ASSIGN;
      }
      else
      {
   ungetNextChar();
   save = 0;
   currentToken = ERROR;
      }
      state = DONE;
      break;
 case INNUM:
      if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
      {
   ungetNextChar();
   save = 0;
   state = DONE;
   currentToken = NUM;
      }
      break;
 case INID:
      if (!((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha) && !((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit))
      {
   ungetNextChar();
   save = 0;
   state = DONE;
   currentToken = ID;
      }
      break;
 case INCOMMENT:
      save = 0;
      if (c == (-1))
      {
   state = DONE;
   currentToken = ENDFILE;
      }
      else if (c == '}')
   state = START;
      break;
 case DONE:
      break;
 default:
      printf("Scanner bug: state = %d\n", state);
      state = DONE;
      currentToken = ERROR;
 }
 if ((save) && (tokenStringIndex <= 40))
 {
     tokenString[tokenStringIndex++] = (char)c;
 }
 if (state == DONE)
 {
     tokenString[tokenStringIndex] = '\0';
     if (currentToken == ID)
     {
  currentToken = reservedLookup(tokenString);
     }
     printf("\t%d: ", lineno);
     printToken(currentToken, tokenString);
 }
    }
    return currentToken;
}

variable_types: tokenStringIndex int

variable_types: enum StateType { START=0, INASSIGN=1, INNUM=2, INID=3, DONE=4, INLT=5, INGT=6, INCOMMENT=7 }

variable_types: save int

variable_types: c int

user_defined_types: enum TokenType { ENDFILE=0, ERROR=1, PROGRAM_K=2, CONST_K=3, VAR_K=4, PROCEDURE_K=5, BEGIN_K=6, END_K=7, IF_K=8, WHILE_K=9, CALL_K=10, DO_K=11, ELSE_K=12, THEN_K=13, WRITE_K=14, ODD_K=15, READ_K=16, NUM=17, ID=18, ASSIGN=19, EQ=20, LT=21, GT=22, PLUS=23, MINUS=24, TIMES=25, OVER=26, LPAREN=27, RPAREN=28, SEMI=29, COMM=30, LTEQ=31, GTEQ=32, NOEQ=33 }


gen

decompiled_code:
char *__fastcall gen(int a1, int a2, int a3)
{
__int64 v6; // r15
int v7; // ebx
char *v8; // r14
char *result; // rax
void *v10; // rdi
char *v11; // rax
char *v12; // rdx
char *v13; // rsi
int v14; // ecx

v6 = (unsigned int)dword_294;
v7 = ++dword_294;
if ( !cs_length )
{
code = malloc(0x78uLL);
v8 = (char *)code;
if ( code )
{
cs_length = 10;
goto LABEL_4;
}
goto LABEL_12;
}
if ( v7 != cs_length )
{
v8 = (char *)code;
goto LABEL_4;
}
cs_length = 2 * v7;
v8 = (char *)malloc(24LL * v7);
if ( !v8 )
{
LABEL_12:
puts(&s);
exit(1);
}
v10 = code;
if ( v7 > 0 )
{
v11 = (char *)code;
v12 = v8;
v13 = (char *)code + 12 * v6 + 12;
do
{
v14 = *(_DWORD *)v11;
v11 += 12;
v12 += 12;
*((_DWORD *)v12 - 3) = v14;
*((_DWORD *)v12 - 2) = *((_DWORD *)v11 - 2);
*((_DWORD *)v12 - 1) = *((_DWORD *)v11 - 1);
}
while ( v11 != v13 );
}
free(v10);
code = v8;
v7 = dword_294;
LABEL_4:
result = &v8[12 * v7];
*(_DWORD *)result = a1;
*((_DWORD *)result + 1) = a2;
*((_DWORD *)result + 2) = a3;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1, int a2, int a3)
{
__int64 v6; // r15
int v7; // ebx
char *v8; // r14
char *result; // rax
void *v10; // rdi
char *v11; // rax
char *v12; // rdx
char *v13; // rsi
int v14; // ecx

v6 = (unsigned int)dword_294;
v7 = ++dword_294;
if ( !cs_length )
{
code = malloc(0x78uLL);
v8 = (char *)code;
if ( code )
{
cs_length = 10;
goto LABEL_4;
}
goto LABEL_12;
}
if ( v7 != cs_length )
{
v8 = (char *)code;
goto LABEL_4;
}
cs_length = 2 * v7;
v8 = (char *)malloc(24LL * v7);
if ( !v8 )
{
LABEL_12:
puts(&s);
exit(1);
}
v10 = code;
if ( v7 > 0 )
{
v11 = (char *)code;
v12 = v8;
v13 = (char *)code + 12 * v6 + 12;
do
{
v14 = *(_DWORD *)v11;
v11 += 12;
v12 += 12;
*((_DWORD *)v12 - 3) = v14;
*((_DWORD *)v12 - 2) = *((_DWORD *)v11 - 2);
*((_DWORD *)v12 - 1) = *((_DWORD *)v11 - 1);
}
while ( v11 != v13 );
}
free(v10);
code = v8;
v7 = dword_294;
LABEL_4:
result = &v8[12 * v7];
*(_DWORD *)result = a1;
*((_DWORD *)result + 1) = a2;
*((_DWORD *)result + 2) = a3;
return result;
}

original_code:
void gen(InstructionType cmd, int lev, int offset)
{
    cx = cx + 1;
    if (cs_length == 0)
    {
 code = (struct objCode *)malloc(sizeof(struct objCode) * 10);
 if (code == ((void *)0))
 {
     printf("内存空间分配失败!\n");
     exit(1);
 }
 cs_length = 10;
    }
    else if (cx == cs_length)
    {
 int i;
 cs_length = 2 * cs_length;
 struct objCode *newBase = (struct objCode *)malloc(sizeof (struct objCode) * (cs_length));
 if (newBase == ((void *)0))
 {
     printf("内存空间分配失败!\n");
     exit(1);
 }
 for (i = 0; i < cx; ++i)
 {
     newBase[i].cmd = code[i].cmd;
     newBase[i].lev = code[i].lev;
     newBase[i].offset = code[i].offset;
 }
 free(code);
 code = newBase;
    }
    code[cx].cmd = cmd;
    code[cx].lev = lev;
    code[cx].offset = offset;
}

canonical_original_code:
void gen(enum InstructionType cmd, int lev, int offset)
{
    cx = cx + 1;
    if (cs_length == 0)
    {
 code = (struct objCode *)malloc(sizeof(struct objCode) * 10);
 if (code == ((void *)0))
 {
     printf("内存空间分配失败!\n");
     exit(1);
 }
 cs_length = 10;
    }
    else if (cx == cs_length)
    {
 int i;
 cs_length = 2 * cs_length;
 struct objCode *newBase = (struct objCode *)malloc(sizeof (struct objCode) * (cs_length));
 if (newBase == ((void *)0))
 {
     printf("内存空间分配失败!\n");
     exit(1);
 }
 for (i = 0; i < cx; ++i)
 {
     newBase[i].cmd = code[i].cmd;
     newBase[i].lev = code[i].lev;
     newBase[i].offset = code[i].offset;
 }
 free(code);
 code = newBase;
    }
    code[cx].cmd = cmd;
    code[cx].lev = lev;
    code[cx].offset = offset;
}

variable_types: lev int

variable_types: offset int

variable_types: i int

variable_types: struct objCode { enum InstructionType { LIT=0, OPR=1, LOD=2, STO=3, CAL=4, INT=5, JMP=6, JPC=7, RED=8, WRT=9 } cmd; int lev; int offset; } *

user_defined_types: struct objCode { enum InstructionType cmd; int lev; int offset; }


printCode

decompiled_code:
int printCode()
{
char *v0; // rax
__int64 v1; // rbp
unsigned int v2; // ebx
__int64 v3; // rcx

LODWORD(v0) = dword_294;
if ( dword_294 >= 0 )
{
v1 = 0LL;
v2 = 0;
do
{
v0 = (char *)code + v1;
v3 = *(unsigned int *)((char *)code + v1 + 8);
switch ( *(_DWORD *)((char *)code + v1) )
{
case 0:
LODWORD(v0) = printf("%4d: LIT %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 1:
LODWORD(v0) = printf("%4d: OPR %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 2:
LODWORD(v0) = printf("%4d: LOD %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 3:
LODWORD(v0) = printf("%4d: STO %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 4:
LODWORD(v0) = printf("%4d: CAL %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 5:
LODWORD(v0) = printf("%4d: INT %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 6:
LODWORD(v0) = printf("%4d: JMP %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 7:
LODWORD(v0) = printf("%4d: JPC %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 8:
LODWORD(v0) = printf("%4d: RED %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 9:
LODWORD(v0) = printf("%4d: WRT %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
default:
break;
}
++v2;
v1 += 12LL;
}
while ( dword_294 >= (int)v2 );
}
return (int)v0;
}

canonical_decompiled_code:
int func1()
{
char *v0; // rax
__int64 v1; // rbp
unsigned int v2; // ebx
__int64 v3; // rcx

LODWORD(v0) = dword_294;
if ( dword_294 >= 0 )
{
v1 = 0LL;
v2 = 0;
do
{
v0 = (char *)code + v1;
v3 = *(unsigned int *)((char *)code + v1 + 8);
switch ( *(_DWORD *)((char *)code + v1) )
{
case 0:
LODWORD(v0) = printf("%4d: LIT %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 1:
LODWORD(v0) = printf("%4d: OPR %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 2:
LODWORD(v0) = printf("%4d: LOD %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 3:
LODWORD(v0) = printf("%4d: STO %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 4:
LODWORD(v0) = printf("%4d: CAL %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 5:
LODWORD(v0) = printf("%4d: INT %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 6:
LODWORD(v0) = printf("%4d: JMP %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 7:
LODWORD(v0) = printf("%4d: JPC %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 8:
LODWORD(v0) = printf("%4d: RED %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
case 9:
LODWORD(v0) = printf("%4d: WRT %d %d\n", v2, *((unsigned int *)v0 + 1), v3);
break;
default:
break;
}
++v2;
v1 += 12LL;
}
while ( dword_294 >= (int)v2 );
}
return (int)v0;
}

original_code:
void printCode()
{
    int i;
    for (i = 0; i <= cx; ++i)
    {
 switch (code[i].cmd)
 {
 case LIT:
      printf("%4d: LIT %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case OPR:
      printf("%4d: OPR %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case LOD:
      printf("%4d: LOD %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case STO:
      printf("%4d: STO %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case CAL:
      printf("%4d: CAL %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case INT:
      printf("%4d: INT %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case JMP:
      printf("%4d: JMP %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case JPC:
      printf("%4d: JPC %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case RED:
      printf("%4d: RED %d %d\n", i, code[i].lev, code[i].offset);
      break;
 case WRT:
      printf("%4d: WRT %d %d\n", i, code[i].lev, code[i].offset);
      break;
 default:
      break;
 }
    }
}


original_code:
void fill_the_eth(ETHERNET_HEAD *eth, unsigned char *dst_mac, unsigned char *src_mac, int type)
{
 int i;
 for(i = 0; i < 6; i++)
 {
  eth->dst_mac[i] = dst_mac[i];
  eth->src_mac[i] = src_mac[i];
 }
 eth->type = htons(type);
 return;
}

canonical_original_code:
void fill_the_eth(struct eth_head *eth, unsigned char *dst_mac, unsigned char *src_mac, int type)
{
 int i;
 for(i = 0; i < 6; i++)
 {
  eth->dst_mac[i] = dst_mac[i];
  eth->src_mac[i] = src_mac[i];
 }
 eth->type = htons(type);
 return;
}

variable_types: struct eth_head { unsigned char dst_mac[6]; unsigned char src_mac[6]; unsigned short type; } *

variable_types: type int


decompiled_code:
__int64 __fastcall fill_the_arp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, const char *a5)
{
const char *v7; // rdx
__int64 result; // rax

*(_WORD *)a1 = _bswap_16(1);
*(_WORD *)(a1 + 2) = _bswap_16(2048);
*(_WORD *)(a1 + 4) = 1030;
*(_WORD *)(a1 + 6) = _bswap_16(2);
*(_DWORD *)(a1 + 14) = inet_addr(v7);
*(_DWORD *)(a1 + 24) = inet_addr(a5);
for ( result = 0LL; result != 6; ++result )
{
*(_BYTE *)(a1 + result + 8) = *(_BYTE *)(a2 + result);
*(_BYTE *)(a1 + result + 18) = *(_BYTE *)(a4 + result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, const char *a5)
{
const char *v7; // rdx
__int64 result; // rax

*(_WORD *)a1 = func0(1);
*(_WORD *)(a1 + 2) = func0(2048);
*(_WORD *)(a1 + 4) = 1030;
*(_WORD *)(a1 + 6) = func0(2);
*(_DWORD *)(a1 + 14) = inet_addr(v7);
*(_DWORD *)(a1 + 24) = inet_addr(a5);
for ( result = 0LL; result != 6; ++result )
{
*(_BYTE *)(a1 + result + 8) = *(_BYTE *)(a2 + result);
*(_BYTE *)(a1 + result + 18) = *(_BYTE *)(a4 + result);
}
return result;
}

original_code:
void fill_the_arp(ARP_HEAD *arp, unsigned char *sender_mac, unsigned char *sender_ip, unsigned char *target_mac, unsigned char *target_ip)
{
 int i;
 arp->H_type = htons(0x0001);
 arp->P_type = htons(0x0800);
 arp->H_size = 0x6;
 arp->P_size = 0x4;
 arp->opcode = htons(0x2);
 arp->sender_ip = inet_addr(sender_ip);
 arp->target_ip = inet_addr(target_ip);
 for (i = 0; i < 6; i++)
 {
  arp->sender_mac[i] = sender_mac[i];
  arp->target_mac[i] = target_mac[i];
 }
 return;
}

canonical_original_code:
void fill_the_arp(struct arp_head *arp, unsigned char *sender_mac, unsigned char *sender_ip, unsigned char *target_mac, unsigned char *target_ip)
{
 int i;
 arp->H_type = htons(0x0001);
 arp->P_type = htons(0x0800);
 arp->H_size = 0x6;
 arp->P_size = 0x4;
 arp->opcode = htons(0x2);
 arp->sender_ip = inet_addr(sender_ip);
 arp->target_ip = inet_addr(target_ip);
 for (i = 0; i < 6; i++)
 {
  arp->sender_mac[i] = sender_mac[i];
  arp->target_mac[i] = target_mac[i];
 }
 return;
}

variable_types: struct arp_head { unsigned short H_type; unsigned short P_type; unsigned char H_size; unsigned char P_size; unsigned short opcode; unsigned char sender_mac[6]; unsigned int sender_ip; unsigned char target_mac[6]; unsigned int target_ip; } *


decompiled_code:
__int64 __fastcall get_my_mac_addr(char *dest, char *src)
{
int v2; // eax
int v3; // ebp
__int64 result; // rax
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
char srca[16]; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+20h] [rbp-28h]

v7 = 0LL;
v5 = 0LL;
*(_OWORD *)srca = 0LL;
v2 = socket(2, 1, 0);
if ( v2 == -1 )
{
perror("get_my_mac_addr --> socket");
exit(1);
}
v3 = v2;
strcpy((char *)&v5, src);
if ( ioctl(v3, 0x8927uLL, &v5) == -1 )
{
perror("ioctl");
result = 0LL;
}
else
{
strncpy(dest, &srca[2], 6uLL);
dest[6] = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *dest, char *src)
{
int v2; // eax
int v3; // ebp
__int64 result; // rax
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
char srca[16]; // [rsp+10h] [rbp-38h] BYREF
__int64 v7; // [rsp+20h] [rbp-28h]

v7 = 0LL;
v5 = 0LL;
*(_OWORD *)srca = 0LL;
v2 = socket(2, 1, 0);
if ( v2 == -1 )
{
perror("get_my_mac_addr --> socket");
exit(1);
}
v3 = v2;
strcpy((char *)&v5, src);
if ( ioctl(v3, 0x8927uLL, &v5) == -1 )
{
perror("ioctl");
result = 0LL;
}
else
{
strncpy(dest, &srca[2], 6uLL);
dest[6] = 0;
result = 1LL;
}
return result;
}

original_code:
int get_my_mac_addr(char *my_mac, unsigned char *device_name)
{
 struct ifreq ifreq = {0};
 int sock;
 if ((sock = socket(2, SOCK_STREAM, 0)) == -1)
 {
  perror("get_my_mac_addr --> socket");
  exit(1);
 }
 strcpy(ifreq.ifr_ifrn.ifrn_name, device_name);
 if((ioctl(sock, 0x8927, &ifreq)) == -1)
 {
  perror("ioctl");
  return (0);
 }
 strncpy(my_mac, ifreq.ifr_ifru.ifru_hwaddr.sa_data, 6);
 my_mac[6] = '\0';
 return 1;
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

variable_types: sock int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
__int64 __fastcall get_gateway_mac(_BYTE *a1)
{
int v1; // ebp
char *v2; // rdx
char v3; // al
char v4; // si
unsigned __int8 v5; // cl
unsigned __int8 v6; // si
__int64 v8; // [rsp+0h] [rbp-A8h] BYREF
char v9; // [rsp+78h] [rbp-30h] BYREF
char v10; // [rsp+8Ah] [rbp-1Eh] BYREF

while ( 1 )
{
v1 = open("/proc/net/arp", 0);
if ( read(v1, &v8, 0x89uLL) > 136 )
break;
puts("read: cannot get the gateway mac address.try later.");
sleep(2u);
close(v1);
}
v2 = &v9;
do
{
v3 = 16 * (*v2 - 87);
v4 = v2[1];
if ( (unsigned __int8)(*v2 - 48) <= 9u )
v3 = 16 * *v2;
v5 = v4 - 48;
v6 = v4 - 87;
if ( v5 > 9u )
v5 = v6;
v2 += 3;
*a1++ = v5 + v3;
}
while ( &v10 != v2 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
int v1; // ebp
char *v2; // rdx
char v3; // al
char v4; // si
unsigned __int8 v5; // cl
unsigned __int8 v6; // si
__int64 v8; // [rsp+0h] [rbp-A8h] BYREF
char v9; // [rsp+78h] [rbp-30h] BYREF
char v10; // [rsp+8Ah] [rbp-1Eh] BYREF

while ( 1 )
{
v1 = open("/proc/net/arp", 0);
if ( read(v1, &v8, 0x89uLL) > 136 )
break;
puts("read: cannot get the gateway mac address.try later.");
sleep(2u);
close(v1);
}
v2 = &v9;
do
{
v3 = 16 * (*v2 - 87);
v4 = v2[1];
if ( (unsigned __int8)(*v2 - 48) <= 9u )
v3 = 16 * *v2;
v5 = v4 - 48;
v6 = v4 - 87;
if ( v5 > 9u )
v5 = v6;
v2 += 3;
*a1++ = v5 + v3;
}
while ( &v10 != v2 );
return 1LL;
}

original_code:
int get_gateway_mac (unsigned char *gateway_mac)
{
 int fd, i = 0, k = 0;
 char buf[138], *ptr;
 while (1)
 {
  fd = open("/proc/net/arp", 00);
  if(read(fd, buf, 137) < 137)
  {
   printf("read: cannot get the gateway mac address.try later.\n");
   sleep(2);
   close(fd);
   continue;
  }
  else
  {
   break;
  }
  i++;
  if (i > 10)
  {
   break;
  }
 }
 ptr = &buf[120];
 for (i = 0; i < 6; i++)
 {
  gateway_mac[i] = ((ptr[k] >= 48 && ptr[k] <= 57) ? ((ptr[k]-48)<<4) : ((ptr[k]-87)<<4)) + ((ptr[k+1] >= 48 && ptr[k+1] <= 57) ? (ptr[k+1]-48) : (ptr[k+1]-87));
  k += 3;
 }
 return 1;
}

canonical_original_code:
int get_gateway_mac(unsigned char *gateway_mac)
{
 int fd; int i = 0; int k = 0;
 char buf[138]; char *ptr;
 while (1)
 {
  fd = open("/proc/net/arp", 00);
  if(read(fd, buf, 137) < 137)
  {
   printf("read: cannot get the gateway mac address.try later.\n");
   sleep(2);
   close(fd);
   continue;
  }
  else
  {
   break;
  }
  i++;
  if (i > 10)
  {
   break;
  }
 }
 ptr = &buf[120];
 for (i = 0; i < 6; i++)
 {
  gateway_mac[i] = ((ptr[k] >= 48 && ptr[k] <= 57) ? ((ptr[k]-48)<<4) : ((ptr[k]-87)<<4)) + ((ptr[k+1] >= 48 && ptr[k+1] <= 57) ? (ptr[k+1]-48) : (ptr[k+1]-87));
  k += 3;
 }
 return 1;
}

variable_types: fd int

variable_types: k int

variable_types:
buf
char [138]

variable_types:
ptr
char *


decompiled_code:
__int16 __fastcall print_eth(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 v2; // rsi
unsigned __int8 *v3; // rbx
__int64 v4; // rsi
__int16 result; // ax

v1 = a1;
printf("Destnation mac address:");
do
{
v2 = *v1++;
printf("%02x:", v2);
}
while ( v1 != a1 + 5 );
v3 = a1 + 6;
printf("%02x\n", a1[5]);
printf("Source mac address:");
do
{
v4 = *v3++;
printf("%02x:", v4);
}
while ( v3 != a1 + 11 );
printf("%02x\n", a1[11]);
result = _bswap_16(*((_WORD *)a1 + 6));
if ( result == 2048 )
return printf("Upper layer protocol is %s (0x%04x)\n", "IP", 2048LL);
if ( result == 2054 )
result = printf("Upper layer protocol is %s (0x%04x)\n", "ARP", 2054LL);
return result;
}

canonical_decompiled_code:
__int16 __fastcall func5(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
__int64 v2; // rsi
unsigned __int8 *v3; // rbx
__int64 v4; // rsi
__int16 result; // ax

v1 = a1;
printf("Destnation mac address:");
do
{
v2 = *v1++;
printf("%02x:", v2);
}
while ( v1 != a1 + 5 );
v3 = a1 + 6;
printf("%02x\n", a1[5]);
printf("Source mac address:");
do
{
v4 = *v3++;
printf("%02x:", v4);
}
while ( v3 != a1 + 11 );
printf("%02x\n", a1[11]);
result = func0(*((_WORD *)a1 + 6));
if ( result == 2048 )
return printf("Upper layer protocol is %s (0x%04x)\n", "IP", 2048LL);
if ( result == 2054 )
result = printf("Upper layer protocol is %s (0x%04x)\n", "ARP", 2054LL);
return result;
}

original_code:
void print_eth(ETHERNET_HEAD *eth)
{
 int i;
 printf("Destnation mac address:");
 for (i = 0; i < 5; i++)
 {
  printf("%02x:", eth->dst_mac[i]);
 }
 printf("%02x\n",eth->dst_mac[i]);
 printf("Source mac address:");
 for (i = 0; i < 5; i++)
 {
  printf("%02x:", eth->src_mac[i]);
 }
 printf("%02x\n",eth->src_mac[i]);
 switch (ntohs(eth->type))
 {
  case 0x0806: printf("Upper layer protocol is %s (0x%04x)\n", "ARP", ntohs(eth->type));
      break;
  case 0x0800: printf("Upper layer protocol is %s (0x%04x)\n", "IP", ntohs(eth->type));
 }
}

canonical_original_code:
void print_eth(struct eth_head *eth)
{
 int i;
 printf("Destnation mac address:");
 for (i = 0; i < 5; i++)
 {
  printf("%02x:", eth->dst_mac[i]);
 }
 printf("%02x\n",eth->dst_mac[i]);
 printf("Source mac address:");
 for (i = 0; i < 5; i++)
 {
  printf("%02x:", eth->src_mac[i]);
 }
 printf("%02x\n",eth->src_mac[i]);
 switch (ntohs(eth->type))
 {
  case 0x0806: printf("Upper layer protocol is %s (0x%04x)\n", "ARP", ntohs(eth->type));
      break;
  case 0x0800: printf("Upper layer protocol is %s (0x%04x)\n", "IP", ntohs(eth->type));
 }
}

user_defined_types: struct eth_head { unsigned char dst_mac[6]; unsigned char src_mac[6]; unsigned short type; }


decompiled_code:
int print_arp()
{
return puts("in the ARP package");
}

canonical_decompiled_code:
int func6()
{
return puts("in the ARP package");
}

original_code:
void print_arp(ARP_HEAD *arp)
{
 printf("in the ARP package\n");
}

canonical_original_code:
void print_arp(struct arp_head *arp)
{
 printf("in the ARP package\n");
}

user_defined_types: struct arp_head { unsigned short H_type; unsigned short P_type; unsigned char H_size; unsigned char P_size; unsigned short opcode; unsigned char sender_mac[6]; unsigned int sender_ip; unsigned char target_mac[6]; unsigned int target_ip; }


decompiled_code:
int print_ip()
{
return puts("in the IP package");
}

canonical_decompiled_code:
int func7()
{
return puts("in the IP package");
}

original_code:
void print_ip(IP_HEAD *ip)
{
 printf("in the IP package\n");
}

canonical_original_code:
void print_ip(struct ip_head *ip)
{
 printf("in the IP package\n");
}

variable_types: struct ip_head { unsigned char ip_v; unsigned char ip_hl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_flag_offset; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr { unsigned int s_addr; } ip_src; } *

user_defined_types: struct ip_head { unsigned char ip_v; unsigned char ip_hl; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_flag_offset; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; }


decompiled_code:
void __fastcall print_PAR(int a1, const char **a2)
{
int i; // ebx
int v3; // eax

if ( a1 > 0 )
{
for ( i = 0; a1 != i; ++i )
{
while ( 1 )
{
v3 = (1 << i) & *(unsigned __int8 *)a2;
if ( v3 != 4 )
break;
puts(a2[2]);
LABEL_5:
if ( a1 == ++i )
return;
}
if ( v3 > 4 )
{
if ( v3 == 8 )
puts(a2[3]);
goto LABEL_5;
}
if ( v3 != 1 )
{
if ( v3 == 2 )
puts(a2[1]);
goto LABEL_5;
}
print_help(78LL);
}
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, const char **a2)
{
int i; // ebx
int v3; // eax

if ( a1 > 0 )
{
for ( i = 0; a1 != i; ++i )
{
while ( 1 )
{
v3 = (1 << i) & *(unsigned __int8 *)a2;
if ( v3 != 4 )
break;
puts(a2[2]);
LABEL_5:
if ( a1 == ++i )
return;
}
if ( v3 > 4 )
{
if ( v3 == 8 )
puts(a2[3]);
goto LABEL_5;
}
if ( v3 != 1 )
{
if ( v3 == 2 )
puts(a2[1]);
goto LABEL_5;
}
print_help(78LL);
}
}
}

original_code:
void print_PAR(int argc, const struct parameter *par)
{
 int i;
 for (i = 0; i < argc; i++)
 {
  switch (par->par & 1<<i)
  {
   case 0x1:
    print_help('N');
    break;
   case 0x2:
    printf("%s\n", par->device_name);
    break;
   case 0x4:
    printf("%s\n", par->ip);
    break;
   case 0x8:
    printf("%s\n", par->protocol);
    break;
  }
 }
}

canonical_original_code:
void print_PAR(int argc, struct parameter *par)
{
 int i;
 for (i = 0; i < argc; i++)
 {
  switch (par->par & 1<<i)
  {
   case 0x1:
    print_help('N');
    break;
   case 0x2:
    printf("%s\n", par->device_name);
    break;
   case 0x4:
    printf("%s\n", par->ip);
    break;
   case 0x8:
    printf("%s\n", par->protocol);
    break;
  }
 }
}

variable_types: argc int

variable_types: struct parameter { unsigned char par; char *device_name; char *ip; char *protocol; int broadcast; } *


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // rax
const char **v4; // rbp
unsigned __int16 v5; // ax
int v6; // ebx
__int16 v7; // ax
__int128 v8; // [rsp+0h] [rbp-848h] BYREF
__int128 v9; // [rsp+10h] [rbp-838h]
__int64 v10; // [rsp+20h] [rbp-828h]
char buf[8]; // [rsp+30h] [rbp-818h] BYREF
char v12[4]; // [rsp+38h] [rbp-810h] BYREF
__int16 v13; // [rsp+3Ch] [rbp-80Ch]

v10 = 0LL;
v8 = 0LL;
v9 = 0LL;
v3 = (_BYTE *)resolve_parameter(argc, argv, envp);
v4 = (const char **)v3;
if ( (*v3 & 4) != 0 )
thread_cheat(v3);
v5 = _bswap_16(3);
v6 = socket(17, 3, v5);
if ( v6 != -1 )
{
strncpy((char *)&v8, v4[1], 0x10uLL);
if ( ioctl(v6, 0x8913uLL, &v8) != -1 )
{
LOWORD(v9) = v9 | 0x100;
if ( ioctl(v6, 0x8914uLL, &v8) != -1 )
{
while ( 1 )
{
while ( (int)recvfrom(v6, buf, 0x800uLL, 0, 0LL, 0LL) <= 41 )
;
print_eth(buf);
v7 = _bswap_16(v13);
if ( v7 == 2048 )
{
print_ip(v12);
}
else if ( v7 == 2054 )
{
print_arp(v12);
}
}
}
perror("ioctl set");
exit(1);
}
perror("ioctl get");
exit(1);
}
perror("Create sniffer socket");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_BYTE *v3; // rax
const char **v4; // rbp
unsigned __int16 v5; // ax
int v6; // ebx
__int16 v7; // ax
__int128 v8; // [rsp+0h] [rbp-848h] BYREF
__int128 v9; // [rsp+10h] [rbp-838h]
__int64 v10; // [rsp+20h] [rbp-828h]
char buf[8]; // [rsp+30h] [rbp-818h] BYREF
char v12[4]; // [rsp+38h] [rbp-810h] BYREF
__int16 v13; // [rsp+3Ch] [rbp-80Ch]

v10 = 0LL;
v8 = 0LL;
v9 = 0LL;
v3 = (_BYTE *)resolve_parameter(argc, argv, envp);
v4 = (const char **)v3;
if ( (*v3 & 4) != 0 )
thread_cheat(v3);
v5 = func0(3);
v6 = socket(17, 3, v5);
if ( v6 != -1 )
{
strncpy((char *)&v8, v4[1], 0x10uLL);
if ( ioctl(v6, 0x8913uLL, &v8) != -1 )
{
LOWORD(v9) = v9 | 0x100;
if ( ioctl(v6, 0x8914uLL, &v8) != -1 )
{
while ( 1 )
{
while ( (int)recvfrom(v6, buf, 0x800uLL, 0, 0LL, 0LL) <= 41 )
;
print_eth(buf);
v7 = func0(v13);
if ( v7 == 2048 )
{
print_ip(v12);
}
else if ( v7 == 2054 )
{
print_arp(v12);
}
}
}
perror("ioctl set");
exit(1);
}
perror("ioctl get");
exit(1);
}
perror("Create sniffer socket");
exit(1);
}

original_code:
void main(int argc, char **argv)
{
 struct parameter *par;
 const char **PAR = (const char **)argv;
 struct ifreq setpro = {0};
 int lenth;
 int snif_sock;
 unsigned char buf[2048];
 ETHERNET_HEAD *eth;
 ARP_HEAD *arp;
 IP_HEAD *ip;
 par = resolve_parameter(argc, PAR);
 if (par->par & 0x4)
 {
  thread_cheat(par);
 }
 if ((snif_sock = socket(17, SOCK_RAW, htons(0x0003))) == -1)
 {
  perror("Create sniffer socket");
  exit(1);
 }
 strncpy(setpro.ifr_ifrn.ifrn_name, par->device_name, 16);
 if (ioctl(snif_sock, 0x8913, &setpro) == -1)
 {
  perror("ioctl get");
  exit(1);
 }
 setpro.ifr_ifru.ifru_flags |= IFF_PROMISC;
 if(ioctl(snif_sock, 0x8914, &setpro) == -1)
 {
  perror("ioctl set");
  exit(1);
 }
 while (1)
 {
  lenth = recvfrom(snif_sock, buf, 2048, 0, ((void *)0), ((void *)0));
  if (lenth < 42)
  {
   continue;
  }
  eth = (ETHERNET_HEAD *)&buf[0];
  print_eth (eth);
  switch (ntohs(eth->type))
  {
   case 0x0806: arp = (ARP_HEAD *)&buf[sizeof(eth)];
       print_arp(arp);
       break;
   case 0x0800: ip = (IP_HEAD *)&buf[sizeof(eth)];
      print_ip(ip);
      break;
  }
 }
}

canonical_original_code:
void main(int argc, char **argv)
{
 struct parameter *par;
 char **PAR = (const char **)argv;
 struct ifreq setpro = {0};
 int lenth;
 int snif_sock;
 unsigned char buf[2048];
 struct eth_head *eth;
 struct arp_head *arp;
 struct ip_head *ip;
 par = resolve_parameter(argc, PAR);
 if (par->par & 0x4)
 {
  thread_cheat(par);
 }
 if ((snif_sock = socket(17, SOCK_RAW, htons(0x0003))) == -1)
 {
  perror("Create sniffer socket");
  exit(1);
 }
 strncpy(setpro.ifr_ifrn.ifrn_name, par->device_name, 16);
 if (ioctl(snif_sock, 0x8913, &setpro) == -1)
 {
  perror("ioctl get");
  exit(1);
 }
 setpro.ifr_ifru.ifru_flags |= IFF_PROMISC;
 if(ioctl(snif_sock, 0x8914, &setpro) == -1)
 {
  perror("ioctl set");
  exit(1);
 }
 while (1)
 {
  lenth = recvfrom(snif_sock, buf, 2048, 0, ((void *)0), ((void *)0));
  if (lenth < 42)
  {
   continue;
  }
  eth = (struct eth_head *)&buf[0];
  print_eth (eth);
  switch (ntohs(eth->type))
  {
   case 0x0806: arp = (struct arp_head *)&buf[sizeof(eth)];
       print_arp(arp);
       break;
   case 0x0800: ip = (struct ip_head *)&buf[sizeof(eth)];
      print_ip(ip);
      break;
  }
 }
}

variable_types:
argv
char **

variable_types:
PAR
char **

variable_types: lenth int

variable_types:
buf
unsigned char [2048]

user_defined_types: struct parameter { unsigned char par; char *device_name; char *ip; char *protocol; int broadcast; }

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }


decompiled_code:
void __fastcall __noreturn cheat_target(void *a1)
{
const char *v2; // rdi
int v3; // eax
int v4; // eax
int v5; // ebx
char v6[6]; // [rsp+0h] [rbp-84h] BYREF
int v7; // [rsp+6h] [rbp-7Eh] BYREF
__int16 v8; // [rsp+Ah] [rbp-7Ah]
struct sockaddr addr; // [rsp+Ch] [rbp-78h] BYREF
int v10; // [rsp+1Ch] [rbp-68h]
char buf[14]; // [rsp+2Ch] [rbp-58h] BYREF
char v12[74]; // [rsp+3Ah] [rbp-4Ah] BYREF

v2 = (const char *)*((_QWORD *)a1 + 1);
addr = 0LL;
addr.sa_family = 17;
v10 = 0;
*(_DWORD *)&addr.sa_data[2] = if_nametoindex(v2);
puts("in the thread,print the parameter.");
v3 = _bswap_32_constprop_0(17LL, 3LL);
v4 = socket(17, 3, v3);
if ( v4 != -1 )
{
v5 = v4;
if ( (unsigned int)get_my_mac_addr(v6, *((_QWORD *)a1 + 1)) )
{
if ( *(_DWORD *)a1 == 1 )
{
v7 = -1;
v8 = -1;
}
else
{
get_gateway_mac(&v7);
}
fill_the_eth(buf, &v7, v6, 2054LL);
fill_the_arp(v12, v6, *((_QWORD *)a1 + 2), &v7, *((_QWORD *)a1 + 3));
while ( 1 )
{
sendto(v5, buf, 0x2AuLL, 0, &addr, 0x14u);
putchar(62);
sleep(1u);
}
}
printf("Cannot get %s device mac address.Please cheack your network connection.\n", *((const char **)a1 + 1));
pthread_exit(0LL);
}
perror("socket");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
const char *v2; // rdi
int v3; // eax
int v4; // eax
int v5; // ebx
char v6[6]; // [rsp+0h] [rbp-84h] BYREF
int v7; // [rsp+6h] [rbp-7Eh] BYREF
__int16 v8; // [rsp+Ah] [rbp-7Ah]
struct sockaddr addr; // [rsp+Ch] [rbp-78h] BYREF
int v10; // [rsp+1Ch] [rbp-68h]
char buf[14]; // [rsp+2Ch] [rbp-58h] BYREF
char v12[74]; // [rsp+3Ah] [rbp-4Ah] BYREF

v2 = (const char *)*((_QWORD *)a1 + 1);
addr = 0LL;
addr.sa_family = 17;
v10 = 0;
*(_DWORD *)&addr.sa_data[2] = if_nametoindex(v2);
puts("in the thread,print the parameter.");
v3 = func0(17LL, 3LL);
v4 = socket(17, 3, v3);
if ( v4 != -1 )
{
v5 = v4;
if ( (unsigned int)get_my_mac_addr(v6, *((_QWORD *)a1 + 1)) )
{
if ( *(_DWORD *)a1 == 1 )
{
v7 = -1;
v8 = -1;
}
else
{
get_gateway_mac(&v7);
}
fill_the_eth(buf, &v7, v6, 2054LL);
fill_the_arp(v12, v6, *((_QWORD *)a1 + 2), &v7, *((_QWORD *)a1 + 3));
while ( 1 )
{
sendto(v5, buf, 0x2AuLL, 0, &addr, 0x14u);
putchar(62);
sleep(1u);
}
}
printf("Cannot get %s device mac address.Please cheack your network connection.\n", *((const char **)a1 + 1));
pthread_exit(0LL);
}
perror("socket");
exit(1);
}

original_code:
void cheat_target (void *argv)
{
 int cheat_socket;
 const struct cheat_argv *par = (struct cheat_argv *)argv;
 ARP_PACKAGE arp;
 int i;
 unsigned char src_mac[6], dst_mac[6];
 struct sockaddr_ll to = {0};
 to.sll_family = 17;
 to.sll_ifindex = if_nametoindex(par->device_name);
 printf("in the thread,print the parameter.\n");
 if ((cheat_socket = socket(17, SOCK_RAW, htonl(0x0806))) == -1)
 {
  perror("socket");
  exit(1);
 }
 if (!get_my_mac_addr(src_mac, par->device_name))
 {
  printf("Cannot get %s device mac address.Please cheack your network connection.\n", par->device_name);
  pthread_exit(((void *)0));
 }
 if (par->broad == 1)
 {
  for (i = 0; i < 6; i++)
  {
   dst_mac[i] = 0xff;
  }
   fill_the_eth(&arp.eth, dst_mac, src_mac, 0x0806);
 }
 else
 {
  get_gateway_mac(dst_mac);
  fill_the_eth(&arp.eth, dst_mac, src_mac, 0x0806);
 }
 fill_the_arp(&arp.arp, src_mac, par->sender_ip, dst_mac, par->target_ip);
 while (1)
 {
  sendto(cheat_socket, (char *)&arp, sizeof(arp), 0, (struct sockaddr *)&to, sizeof(to));
  printf(">");
  sleep(1);
 }
}

canonical_original_code:
void cheat_target(void *argv)
{
 int cheat_socket;
 struct cheat_argv *par = (struct cheat_argv *)argv;
 struct arp_package arp;
 int i;
 unsigned char src_mac[6]; unsigned char dst_mac[6];
 struct sockaddr_ll to = {0};
 to.sll_family = 17;
 to.sll_ifindex = if_nametoindex(par->device_name);
 printf("in the thread,print the parameter.\n");
 if ((cheat_socket = socket(17, SOCK_RAW, htonl(0x0806))) == -1)
 {
  perror("socket");
  exit(1);
 }
 if (!get_my_mac_addr(src_mac, par->device_name))
 {
  printf("Cannot get %s device mac address.Please cheack your network connection.\n", par->device_name);
  pthread_exit(((void *)0));
 }
 if (par->broad == 1)
 {
  for (i = 0; i < 6; i++)
  {
   dst_mac[i] = 0xff;
  }
   fill_the_eth(&arp.eth, dst_mac, src_mac, 0x0806);
 }
 else
 {
  get_gateway_mac(dst_mac);
  fill_the_eth(&arp.eth, dst_mac, src_mac, 0x0806);
 }
 fill_the_arp(&arp.arp, src_mac, par->sender_ip, dst_mac, par->target_ip);
 while (1)
 {
  sendto(cheat_socket, (char *)&arp, sizeof(arp), 0, (struct sockaddr *)&to, sizeof(to));
  printf(">");
  sleep(1);
 }
}

variable_types:
argv
void *

variable_types: struct cheat_argv { int broad; char *device_name; char *sender_ip; char *target_ip; } *

variable_types: struct arp_package { struct eth_head { unsigned char dst_mac[6]; unsigned char src_mac[6]; unsigned short type; } eth; struct arp_head { unsigned short H_type; unsigned short P_type; unsigned char H_size; unsigned char P_size; unsigned short opcode; unsigned char sender_mac[6]; unsigned int sender_ip; unsigned char target_mac[6]; unsigned int target_ip; } arp; }

variable_types: i int

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

user_defined_types: struct arp_package { struct eth_head eth; struct arp_head arp; }


decompiled_code:
int __fastcall thread_cheat(__int64 a1)
{
_QWORD *v1; // rcx
int v2; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = malloc(0x20uLL);
v2 = *(_DWORD *)(a1 + 32);
v1[2] = "192.168.200.1";
*(_DWORD *)v1 = v2;
v1[1] = *(_QWORD *)(a1 + 8);
v1[3] = *(_QWORD *)(a1 + 16);
return pthread_create(newthread, 0LL, (void *(*)(void *))cheat_target, v1);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
_QWORD *v1; // rcx
int v2; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = malloc(0x20uLL);
v2 = *(_DWORD *)(a1 + 32);
v1[2] = "192.168.200.1";
*(_DWORD *)v1 = v2;
v1[1] = *(_QWORD *)(a1 + 8);
v1[3] = *(_QWORD *)(a1 + 16);
return pthread_create(newthread, 0LL, (void *(*)(void *))cheat_target, v1);
}

original_code:
void thread_cheat(const struct parameter *par)
{
 pthread_t tidp;
 struct cheat_argv *argv = (struct cheat_argv *)malloc(sizeof(struct cheat_argv));
 argv->broad = par->broadcast;
 argv->device_name = (char *)par->device_name;
 argv->sender_ip = "192.168.200.1";
 argv->target_ip = (char *)par->ip;
 pthread_create(&tidp, ((void *)0), (void *(*)(void *))cheat_target, (void *)argv);
 return;
}

canonical_original_code:
void thread_cheat(struct parameter *par)
{
 unsigned long tidp;
 struct cheat_argv *argv = (struct cheat_argv *)malloc(sizeof(struct cheat_argv));
 argv->broad = par->broadcast;
 argv->device_name = (char *)par->device_name;
 argv->sender_ip = "192.168.200.1";
 argv->target_ip = (char *)par->ip;
 pthread_create(&tidp, ((void *)0), (void *(*)(void *))cheat_target, (void *)argv);
 return;
}

variable_types:
tidp
unsigned long

user_defined_types: struct cheat_argv { int broad; char *device_name; char *sender_ip; char *target_ip; }


decompiled_code:
int __fastcall print_help(char a1)
{
if ( a1 != 78 )
printf("sniffer: invalid option --%c\n", (unsigned int)a1);
puts("Usage: sniffer [OPTION]...");
puts("Listen packages form the netcard.\nTell a lie to the gateway.\nTake the target IP host's packages.\n");
puts(" -h\tList the help infomation.");
puts(" -d\tSpecify the net device.");
puts(" -c\tSpecify the IP you want to cheat.");
return puts(" -p\tSpecify the protocol of the package you want to get.\n");
}

canonical_decompiled_code:
int __fastcall func0(char a1)
{
if ( a1 != 78 )
printf("sniffer: invalid option --%c\n", (unsigned int)a1);
puts("Usage: sniffer [OPTION]...");
puts("Listen packages form the netcard.\nTell a lie to the gateway.\nTake the target IP host's packages.\n");
puts(" -h\tList the help infomation.");
puts(" -d\tSpecify the net device.");
puts(" -c\tSpecify the IP you want to cheat.");
return puts(" -p\tSpecify the protocol of the package you want to get.\n");
}

original_code:
void print_help(char par)
{
 if(par != 'N')
 {
  printf("sniffer: invalid option --%c\n", par);
 }
 printf("Usage: sniffer [OPTION]...\n");
 printf("Listen packages form the netcard.\nTell a lie to the gateway.\nTake the target IP host's packages.\n\n");
 printf("    -h\tList the help infomation.\n");
 printf("    -d\tSpecify the net device.\n");
 printf("    -c\tSpecify the IP you want to cheat.\n");
 printf("    -p\tSpecify the protocol of the package you want to get.\n\n");
 return;
}

variable_types: par char


repo: yangxks/Model

decompiled_code:
int __fastcall set_socket_reuse(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 2, optval, 4u);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 2, optval, 4u);
}

original_code:
static int set_socket_reuse(int fd)
{
 int on = 1;
 return setsockopt(fd, 1, 2, &on, sizeof(on));
}

variable_types: fd int

variable_types: on int


decompiled_code:
int __fastcall set_socket_linger(int a1)
{
__int64 optval; // [rsp+8h] [rbp-10h] BYREF

optval = 1LL;
return setsockopt(a1, 1, 13, &optval, 8u);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
__int64 optval; // [rsp+8h] [rbp-10h] BYREF

optval = 1LL;
return setsockopt(a1, 1, 13, &optval, 8u);
}

original_code:
static int set_socket_linger(int fd)
{
 struct linger l = {1, 0};
 return setsockopt(fd, 1, 13, &l, sizeof(l));
}

variable_types: struct linger { int l_onoff; int l_linger; }


decompiled_code:
__int64 __fastcall tcp_bind(int fd, const char *a2, __int16 a3)
{
__int16 v5; // di
__int16 v6; // ax
socklen_t v7; // edx
__int64 result; // rax
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

if ( inet_pton(2, a2, &v9[0].sa_data[2]) <= 0 )
{
perror("inet_pton");
result = 0xFFFFFFFFLL;
}
else if ( set_socket_reuse(fd) )
{
perror("setsockopt");
result = 0xFFFFFFFFLL;
}
else
{
v5 = a3;
if ( !a3 )
{
v5 = lport_0;
v6 = lport_0 + 1;
if ( (unsigned __int16)lport_0 <= 0x400u )
{
v5 = 1025;
v6 = 1026;
}
lport_0 = v6;
}
v9[0] = 0LL;
v9[0].sa_family = 2;
*(_WORD *)v9[0].sa_data = _bswap_16(v5);
result = (unsigned int)-(bind(fd, v9, v7) == -1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, const char *a2, __int16 a3)
{
__int16 v5; // di
__int16 v6; // ax
socklen_t v7; // edx
__int64 result; // rax
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

if ( inet_pton(2, a2, &v9[0].sa_data[2]) <= 0 )
{
perror("inet_pton");
result = 0xFFFFFFFFLL;
}
else if ( func0(fd) )
{
perror("setsockopt");
result = 0xFFFFFFFFLL;
}
else
{
v5 = a3;
if ( !a3 )
{
v5 = lport_0;
v6 = lport_0 + 1;
if ( (unsigned __int16)lport_0 <= 0x400u )
{
v5 = 1025;
v6 = 1026;
}
lport_0 = v6;
}
v9[0] = 0LL;
v9[0].sa_family = 2;
*(_WORD *)v9[0].sa_data = func2(v5);
result = (unsigned int)-(bind(fd, v9, v7) == -1);
}
return result;
}

original_code:
static int tcp_bind(int fd, const char *ip, unsigned short port)
{
 struct sockaddr_in addr;
 if (inet_pton(2, ip, &addr.sin_addr) <= 0) {
  perror("inet_pton");
  return -1;
 }
 if (set_socket_reuse(fd) != 0) {
  perror("setsockopt");
  return -1;
 }
 if (port == 0) {
  static unsigned short lport = 1025;
  if (lport < 1025) {
   lport = 1025;
  }
  port = lport ++;
 }
 memset(&addr, '\0', sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(port);
 if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
  return -1;
 }
 return 0;
}

canonical_original_code:
static int tcp_bind(int fd, char *ip, unsigned short port)
{
 struct sockaddr_in addr;
 if (inet_pton(2, ip, &addr.sin_addr) <= 0) {
  perror("inet_pton");
  return -1;
 }
 if (set_socket_reuse(fd) != 0) {
  perror("setsockopt");
  return -1;
 }
 if (port == 0) {
  static unsigned short lport = 1025;
  if (lport < 1025) {
   lport = 1025;
  }
  port = lport ++;
 }
 memset(&addr, '\0', sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(port);
 if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
  return -1;
 }
 return 0;
}

variable_types:
ip
char *

variable_types:
port
unsigned short

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

variable_types:
lport
unsigned short

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:
int __fastcall set_nonblock(int fd)
{
int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 < 0 )
return -1;
BYTE1(v1) |= 8u;
return fcntl(fd, 4, (unsigned int)v1);
}

canonical_decompiled_code:
int __fastcall func4(int fd)
{
int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 < 0 )
return -1;
BYTE1(v1) |= 8u;
return fcntl(fd, 4, (unsigned int)v1);
}

original_code:
static int set_nonblock(int fd)
{
 int flag;
 if ((flag = fcntl(fd, 3, 0)) < 0) {
  return -1;
 }
 return fcntl(fd, 4, flag | 04000);
}

variable_types: flag int


decompiled_code:
__int64 __fastcall tcp_listen(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
int v5; // edi

v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 == -1 )
{
perror("socket");
return v3;
}
if ( (unsigned int)tcp_bind(v2, a1, a2) )
goto LABEL_7;
if ( set_nonblock(v3) < 0 )
{
perror("set_nonblock");
LABEL_7:
v5 = v3;
v3 = -1;
close(v5);
return v3;
}
if ( listen(v3, 0x2000) == -1 )
{
perror("listen");
goto LABEL_7;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
int v5; // edi

v2 = socket(2, 1, 6);
v3 = v2;
if ( v2 == -1 )
{
perror("socket");
return v3;
}
if ( (unsigned int)func3(v2, a1, a2) )
goto LABEL_7;
if ( func4(v3) < 0 )
{
perror("set_nonblock");
LABEL_7:
v5 = v3;
v3 = -1;
close(v5);
return v3;
}
if ( listen(v3, 0x2000) == -1 )
{
perror("listen");
goto LABEL_7;
}
return v3;
}

original_code:
int tcp_listen(const char *ip, unsigned short port)
{
 int fd;
 if ((fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) == -1) {
  perror("socket");
  goto out;
 }
 if (tcp_bind(fd, ip, port) != 0) {
  goto err;
 }
 if (set_nonblock(fd) < 0) {
  perror("set_nonblock");
  goto err;
 }
 if (listen(fd, 8192) == -1) {
  perror("listen");
  goto err;
 }
 return fd;
err:
 close(fd);
out:
 return -1;
}

canonical_original_code:
int tcp_listen(char *ip, unsigned short port)
{
 int fd;
 if ((fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) == -1) {
  perror("socket");
  goto out;
 }
 if (tcp_bind(fd, ip, port) != 0) {
  goto err;
 }
 if (set_nonblock(fd) < 0) {
  perror("set_nonblock");
  goto err;
 }
 if (listen(fd, 8192) == -1) {
  perror("listen");
  goto err;
 }
 return fd;
err:
 close(fd);
out:
 return -1;
}


decompiled_code:
__int64 __fastcall tcp_accept(int a1, struct sockaddr *a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // edi
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v2 = accept(a1, a2, addr_len);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
v4 = v2;
if ( set_nonblock(v2) < 0 )
{
close(v4);
v3 = -1;
}
else if ( set_socket_linger(v4) )
{
v3 = -1;
perror("setsockopt");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, struct sockaddr *a2)
{
int v2; // eax
unsigned int v3; // er12
int v4; // edi
socklen_t addr_len[3]; // [rsp+Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
v2 = accept(a1, a2, addr_len);
if ( v2 < 0 )
return (unsigned int)-1;
v3 = v2;
v4 = v2;
if ( func4(v2) < 0 )
{
close(v4);
v3 = -1;
}
else if ( func1(v4) )
{
v3 = -1;
perror("setsockopt");
}
return v3;
}

original_code:
int tcp_accept(int lsnfd, struct sockaddr_in *addr)
{
 int fd;
 socklen_t len = sizeof(struct sockaddr);
 if ((fd = accept(lsnfd, (struct sockaddr *) addr, &len)) < 0) {
  return -1;
 }
 if (set_nonblock(fd) < 0) {
  close(fd);
  return -1;
 }
 if (set_socket_linger(fd) != 0) {
  perror("setsockopt");
  return -1;
 }
 return fd;
}

canonical_original_code:
int tcp_accept(int lsnfd, struct sockaddr_in *addr)
{
 int fd;
 unsigned int len = sizeof(struct sockaddr);
 if ((fd = accept(lsnfd, (struct sockaddr *) addr, &len)) < 0) {
  return -1;
 }
 if (set_nonblock(fd) < 0) {
  close(fd);
  return -1;
 }
 if (set_socket_linger(fd) != 0) {
  perror("setsockopt");
  return -1;
 }
 return fd;
}

variable_types: lsnfd int

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:
len
unsigned int


decompiled_code:
__int64 __fastcall tcp_connect(const char *a1, __int16 a2, const char *a3)
{
unsigned int v4; // er12
int v5; // ebx
int v6; // edi
void *v8; // rdx
struct sockaddr v9; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
if ( v4 == -1 )
{
perror("socket");
return v4;
}
v5 = 5;
while ( a3 && (unsigned int)tcp_bind(v4, a3, 0) )
{
if ( !--v5 )
goto LABEL_6;
}
if ( set_nonblock(v4) < 0 )
{
perror("set_nonblock");
LABEL_6:
v6 = v4;
v4 = -1;
close(v6);
return v4;
}
if ( set_socket_linger(v4) )
{
v4 = -1;
perror("setsockopt");
return v4;
}
v9 = 0LL;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = _bswap_16(a2);
if ( inet_pton(2, a1, v8) <= 0 )
{
perror("inet_pton");
goto LABEL_6;
}
if ( connect(v4, &v9, 0x10u) == -1 && *_errno_location() != 115 )
goto LABEL_6;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, __int16 a2, const char *a3)
{
unsigned int v4; // er12
int v5; // ebx
int v6; // edi
void *v8; // rdx
struct sockaddr v9; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
if ( v4 == -1 )
{
perror("socket");
return v4;
}
v5 = 5;
while ( a3 && (unsigned int)func3(v4, a3, 0) )
{
if ( !--v5 )
goto LABEL_6;
}
if ( func4(v4) < 0 )
{
perror("set_nonblock");
LABEL_6:
v6 = v4;
v4 = -1;
close(v6);
return v4;
}
if ( func1(v4) )
{
v4 = -1;
perror("setsockopt");
return v4;
}
v9 = 0LL;
v9.sa_family = 2;
*(_WORD *)v9.sa_data = func2(a2);
if ( inet_pton(2, a1, v8) <= 0 )
{
perror("inet_pton");
goto LABEL_6;
}
if ( connect(v4, &v9, 0x10u) == -1 && *_errno_location() != 115 )
goto LABEL_6;
return v4;
}

original_code:
int tcp_connect(const char *ip, unsigned short port,
  const char *bind_ip)
{
 struct sockaddr_in addr;
 int fd, tried = 5;
 if ((fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) == -1) {
  perror("socket");
  goto out;
 }
again:
 if (bind_ip && tcp_bind(fd, bind_ip, 0) != 0) {
  if (-- tried > 0) {
   goto again;
  }
  goto err;
 }
 if (set_nonblock(fd) < 0) {
  perror("set_nonblock");
  goto err;
 }
 if (set_socket_linger(fd) != 0) {
  perror("setsockopt");
  return -1;
 }
 memset(&addr, '\0', sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(port);
 if (inet_pton(2, ip, &addr.sin_addr) <= 0) {
  perror("inet_pton");
  goto err;
 }
 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
  if ((*__errno_location ()) != 115) {
   goto err;
  }
 }
 return fd;
err:
 close(fd);
out:
 return -1;
}

canonical_original_code:
int tcp_connect(char *ip, unsigned short port, char *bind_ip)
{
 struct sockaddr_in addr;
 int fd; int tried = 5;
 if ((fd = socket(2, SOCK_STREAM, IPPROTO_TCP)) == -1) {
  perror("socket");
  goto out;
 }
again:
 if (bind_ip && tcp_bind(fd, bind_ip, 0) != 0) {
  if (-- tried > 0) {
   goto again;
  }
  goto err;
 }
 if (set_nonblock(fd) < 0) {
  perror("set_nonblock");
  goto err;
 }
 if (set_socket_linger(fd) != 0) {
  perror("setsockopt");
  return -1;
 }
 memset(&addr, '\0', sizeof(addr));
 addr.sin_family = 2;
 addr.sin_port = htons(port);
 if (inet_pton(2, ip, &addr.sin_addr) <= 0) {
  perror("inet_pton");
  goto err;
 }
 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
  if ((*__errno_location ()) != 115) {
   goto err;
  }
 }
 return fd;
err:
 close(fd);
out:
 return -1;
}

variable_types: tried int


decompiled_code:
__int64 set_nolimit()
{
unsigned int v0; // er12
struct rlimit v2; // [rsp+0h] [rbp-18h] BYREF

if ( getrlimit(RLIMIT_NOFILE, &v2) )
{
v0 = -1;
perror("getrlimit");
}
else
{
v2.rlim_max = 0x100000LL;
v2.rlim_cur = 0x100000LL;
v0 = setrlimit(RLIMIT_NOFILE, &v2);
if ( v0 )
{
v0 = -1;
perror("setrlimit");
}
else
{
write_to_system_config_isra_0("/proc/sys/net/ipv4/ip_local_port_range", "1025 65535");
write_to_system_config_isra_0("/proc/sys/net/ipv4/tcp_fin_timeout", "5");
write_to_system_config_isra_0("/proc/sys/net/ipv4/ip_conntrack_max", "5000000");
write_to_system_config_isra_0("/proc/sys/net/nf_conntrack_max", "5000000");
write_to_system_config_isra_0("/proc/sys/net/ipv4/tcp_max_syn_backlog", "2000000");
write_to_system_config_isra_0("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", "5000000");
}
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er12
struct rlimit v2; // [rsp+0h] [rbp-18h] BYREF

if ( getrlimit(RLIMIT_NOFILE, &v2) )
{
v0 = -1;
perror("getrlimit");
}
else
{
v2.rlim_max = 0x100000LL;
v2.rlim_cur = 0x100000LL;
v0 = setrlimit(RLIMIT_NOFILE, &v2);
if ( v0 )
{
v0 = -1;
perror("setrlimit");
}
else
{
func5("/proc/sys/net/ipv4/ip_local_port_range", "1025 65535");
func5("/proc/sys/net/ipv4/tcp_fin_timeout", "5");
func5("/proc/sys/net/ipv4/ip_conntrack_max", "5000000");
func5("/proc/sys/net/nf_conntrack_max", "5000000");
func5("/proc/sys/net/ipv4/tcp_max_syn_backlog", "2000000");
func5("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", "5000000");
}
}
return v0;
}

original_code:
int set_nolimit(void)
{
 struct rlimit rlim;
 if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
  perror("getrlimit");
  return -1;
 }
 rlim.rlim_cur = rlim.rlim_max = 1 << 20 ;
 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
  perror("setrlimit");
  return -1;
 }
 write_to_system_config("/proc/sys/net/ipv4/ip_local_port_range", "1025 65535");
 write_to_system_config("/proc/sys/net/ipv4/tcp_fin_timeout", "5");
 write_to_system_config("/proc/sys/net/ipv4/ip_conntrack_max", "5000000");
 write_to_system_config("/proc/sys/net/nf_conntrack_max", "5000000");
 write_to_system_config("/proc/sys/net/ipv4/tcp_max_syn_backlog", "2000000");
 write_to_system_config("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", "5000000");
 return 0;
}

canonical_original_code:
int set_nolimit()
{
 struct rlimit rlim;
 if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
  perror("getrlimit");
  return -1;
 }
 rlim.rlim_cur = rlim.rlim_max = 1 << 20 ;
 if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
  perror("setrlimit");
  return -1;
 }
 write_to_system_config("/proc/sys/net/ipv4/ip_local_port_range", "1025 65535");
 write_to_system_config("/proc/sys/net/ipv4/tcp_fin_timeout", "5");
 write_to_system_config("/proc/sys/net/ipv4/ip_conntrack_max", "5000000");
 write_to_system_config("/proc/sys/net/nf_conntrack_max", "5000000");
 write_to_system_config("/proc/sys/net/ipv4/tcp_max_syn_backlog", "2000000");
 write_to_system_config("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", "5000000");
 return 0;
}

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


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

v2 = spec_get();
if ( *(_DWORD *)(a2 + 4) )
--*v2;
else
--v2[1];
close(*(_DWORD *)a2);
event_destroy(*(_QWORD *)(a2 + 24));
free((void *)a2);
return 123LL;
}

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

v2 = func0();
if ( *(_DWORD *)(a2 + 4) )
--*v2;
else
--v2[1];
close(*(_DWORD *)a2);
event_destroy(*(_QWORD *)(a2 + 24));
free((void *)a2);
return 123LL;
}

original_code:
int client_timeout(int fd, void *priv)
{
 struct thread_spec *s = spec_get();
 struct node *n = priv;
 if (max_sec_requests == 0) {
  if (n->state == 0) {
   s->cur_connecting_connections --;
  } else {
   s->cur_connected_connections --;
  }
  close(n->fd);
  event_destroy(n->handle);
  free(n);
  return 123;
 }
 event_mod(n->handle, EPOLLIN | EPOLLOUT);
 return 0;
}

variable_types:
priv
void *

variable_types: struct thread_spec { unsigned int cur_connected_connections; unsigned int cur_connecting_connections; unsigned int cur_sec_connections; unsigned int cur_sec_requests; unsigned int l_connected_connections; unsigned int l_connecting_connections; unsigned int l_sec_connections; unsigned int l_sec_requests; } *

variable_types: struct node { int fd; int state; char *pos_write; int len_write; void *handle; } *


decompiled_code:
int show_thread_spec()
{
unsigned int *v0; // rbx
pthread_t v1; // rax

v0 = (unsigned int *)spec_get();
v1 = pthread_self();
return printf(
"thread: %lu, active: %u, non-active: %u, new connections: %u/s, requests: %u/s\n",
v1,
v0[4],
v0[5],
v0[6],
v0[7]);
}

canonical_decompiled_code:
int func4()
{
unsigned int *v0; // rbx
pthread_t v1; // rax

v0 = (unsigned int *)func0();
v1 = pthread_self();
return printf(
"thread: %lu, active: %u, non-active: %u, new connections: %u/s, requests: %u/s\n",
v1,
v0[4],
v0[5],
v0[6],
v0[7]);
}

original_code:
static void show_thread_spec(void)
{
 struct thread_spec *s = spec_get();
 printf("thread: %lu, active: %u, "
   "non-active: %u, "
   "new connections: %u/s, "
   "requests: %u/s\n",
   pthread_self(),
   s->l_connected_connections,
   s->l_connecting_connections,
   s->l_sec_connections,
   s->l_sec_requests);
}

canonical_original_code:
static void show_thread_spec()
{
 struct thread_spec *s = spec_get();
 printf("thread: %lu, active: %u, "
   "non-active: %u, "
   "new connections: %u/s, "
   "requests: %u/s\n",
   pthread_self(),
   s->l_connected_connections,
   s->l_connecting_connections,
   s->l_sec_connections,
   s->l_sec_requests);
}

user_defined_types: struct thread_spec { unsigned int cur_connected_connections; unsigned int cur_connecting_connections; unsigned int cur_sec_connections; unsigned int cur_sec_requests; unsigned int l_connected_connections; unsigned int l_connecting_connections; unsigned int l_sec_connections; unsigned int l_sec_requests; }


decompiled_code:
__int64 connect_timer()
{
unsigned __int16 v0; // r12
_DWORD *v1; // rbx
unsigned int v2; // edx
_DWORD *v3; // rbp
int v4; // eax
__int64 v5; // rdx
__int64 v6; // rax
int v7; // eax
bool v8; // cf
int v9; // eax
__int64 v10; // rdx
__int64 result; // rax

v0 = atoi(listen_port);
v1 = spec_get();
if ( max_connections > (unsigned int)(*v1 + v1[1]) )
{
v2 = v1[2];
do
{
if ( max_sec_connections <= v2 )
break;
v3 = calloc(1uLL, 0x20uLL);
if ( !v3 )
break;
v4 = tcp_connect(listen_ip, v0, bind_ip);
*v3 = v4;
if ( v4 < 0 )
goto LABEL_12;
v5 = (unsigned int)max_duration_sec;
v3[1] = 0;
v6 = event_set((unsigned int)v4, v3, v5, client_read, client_write, client_timeout);
*((_QWORD *)v3 + 3) = v6;
if ( !v6 )
goto LABEL_11;
if ( (unsigned int)event_add(v6, 5LL) )
{
event_destroy(*((_QWORD *)v3 + 3));
LABEL_11:
close(*v3);
LABEL_12:
free(v3);
break;
}
v7 = v1[1] + 1;
v2 = v1[2] + 1;
v1[1] = v7;
v8 = *v1 + v7 < (unsigned int)max_connections;
v1[2] = v2;
}
while ( v8 );
}
show_thread_spec();
v9 = v1[2];
v10 = *(_QWORD *)v1;
v1[2] = 0;
v1[6] = v9;
result = 0LL;
*((_QWORD *)v1 + 2) = v10;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int16 v0; // r12
_DWORD *v1; // rbx
unsigned int v2; // edx
_DWORD *v3; // rbp
int v4; // eax
__int64 v5; // rdx
__int64 v6; // rax
int v7; // eax
bool v8; // cf
int v9; // eax
__int64 v10; // rdx
__int64 result; // rax

v0 = atoi(listen_port);
v1 = func0();
if ( max_connections > (unsigned int)(*v1 + v1[1]) )
{
v2 = v1[2];
do
{
if ( max_sec_connections <= v2 )
break;
v3 = calloc(1uLL, 0x20uLL);
if ( !v3 )
break;
v4 = tcp_connect(listen_ip, v0, bind_ip);
*v3 = v4;
if ( v4 < 0 )
goto LABEL_12;
v5 = (unsigned int)max_duration_sec;
v3[1] = 0;
v6 = event_set((unsigned int)v4, v3, v5, client_read, client_write, client_timeout);
*((_QWORD *)v3 + 3) = v6;
if ( !v6 )
goto LABEL_11;
if ( (unsigned int)event_add(v6, 5LL) )
{
event_destroy(*((_QWORD *)v3 + 3));
LABEL_11:
close(*v3);
LABEL_12:
free(v3);
break;
}
v7 = v1[1] + 1;
v2 = v1[2] + 1;
v1[1] = v7;
v8 = *v1 + v7 < (unsigned int)max_connections;
v1[2] = v2;
}
while ( v8 );
}
func4();
v9 = v1[2];
v10 = *(_QWORD *)v1;
v1[2] = 0;
v1[6] = v9;
result = 0LL;
*((_QWORD *)v1 + 2) = v10;
return result;
}

original_code:
static int connect_timer(void *priv)
{
 struct node *n;
 unsigned short port = atoi(listen_port);
 struct thread_spec *s = spec_get();
 while (1) {
  if (s->cur_connecting_connections + s->cur_connected_connections
    >= max_connections) {
   goto next;
  }
  if (s->cur_sec_connections >= max_sec_connections) {
   goto next;
  }
  if ((n = calloc(1, sizeof(struct node))) == ((void *)0)) {
   goto next;
  }
  if ((n->fd = tcp_connect(listen_ip, port, bind_ip)) < 0) {
   goto error;
  }
  n->state = 0;
  if ((n->handle = event_set(n->fd, n, max_duration_sec, client_read, client_write,
      client_timeout)) == ((void *)0)) {
   goto error1;
  }
  if (event_add(n->handle, EPOLLIN | EPOLLOUT) != 0) {
   goto error2;
  }
  s->cur_connecting_connections ++;
  s->cur_sec_connections ++;
 }
 if (0) {
error2:
  event_destroy(n->handle);
error1:
  close(n->fd);
error:
  free(n);
next:
  show_thread_spec();
  s->l_connected_connections = s->cur_connected_connections;
  s->l_connecting_connections = s->cur_connecting_connections;
  s->l_sec_connections = s->cur_sec_connections;
  s->cur_sec_connections = 0;
 }
 return 0;
}

user_defined_types: struct node { int fd; int state; char *pos_write; int len_write; void *handle; }


decompiled_code:
void *spec_get()
{
void *result; // rax
void *v1; // rax
void *v2; // r12

pthread_once(&once_control_0, thread_key_create);
result = pthread_getspecific(thread_spec_key);
if ( !result )
{
v1 = calloc(1uLL, 0x20uLL);
v2 = v1;
if ( !v1 )
{
perror("calloc");
exit(-1);
}
pthread_setspecific(thread_spec_key, v1);
result = v2;
}
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax
void *v1; // rax
void *v2; // r12

pthread_once(&once_control_0, thread_key_create);
result = pthread_getspecific(thread_spec_key);
if ( !result )
{
v1 = calloc(1uLL, 0x20uLL);
v2 = v1;
if ( !v1 )
{
perror("calloc");
exit(-1);
}
pthread_setspecific(thread_spec_key, v1);
result = v2;
}
return result;
}

original_code:
static struct thread_spec *spec_get(void)
{
 struct thread_spec *s;
 static pthread_once_t once_control = 0;
 pthread_once(&once_control, thread_key_create);
 if ((s = pthread_getspecific(thread_spec_key)) == ((void *)0)) {
  if ((s = calloc(1, sizeof(struct thread_spec))) == ((void *)0)) {
   do { perror("calloc"); exit(-1); } while (0);
  }
  pthread_setspecific(thread_spec_key, s);
 }
 return s;
}

canonical_original_code:
static struct thread_spec *spec_get()
{
 struct thread_spec *s;
 static int once_control = 0;
 pthread_once(&once_control, thread_key_create);
 if ((s = pthread_getspecific(thread_spec_key)) == ((void *)0)) {
  if ((s = calloc(1, sizeof(struct thread_spec))) == ((void *)0)) {
   do { perror("calloc"); exit(-1); } while (0);
  }
  pthread_setspecific(thread_spec_key, s);
 }
 return s;
}

return_type: struct thread_spec { unsigned int cur_connected_connections; unsigned int cur_connecting_connections; unsigned int cur_sec_connections; unsigned int cur_sec_requests; unsigned int l_connected_connections; unsigned int l_connecting_connections; unsigned int l_sec_connections; unsigned int l_sec_requests; } *


decompiled_code:
__int64 __fastcall client_read(int fd, void *ptr)
{
unsigned int v2; // er12
_DWORD *v3; // rbx
__int64 v5; // [rsp+0h] [rbp-2028h] BYREF

v2 = 0;
v3 = spec_get();
if ( (int)read(fd, &v5, 0x2000uLL) <= 0 && *_errno_location() != 11 )
{
if ( *((_DWORD *)ptr + 1) )
--*v3;
else
--v3[1];
v2 = -1;
close(*(_DWORD *)ptr);
event_destroy(*((_QWORD *)ptr + 3));
free(ptr);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *ptr)
{
unsigned int v2; // er12
_DWORD *v3; // rbx
__int64 v5; // [rsp+0h] [rbp-2028h] BYREF

v2 = 0;
v3 = func0();
if ( (int)read(fd, &v5, 0x2000uLL) <= 0 && *_errno_location() != 11 )
{
if ( *((_DWORD *)ptr + 1) )
--*v3;
else
--v3[1];
v2 = -1;
close(*(_DWORD *)ptr);
event_destroy(*((_QWORD *)ptr + 3));
free(ptr);
}
return v2;
}

original_code:
int client_read(int fd, void *priv)
{
 int ret;
 char buff[8192];
 struct node *n = priv;
 struct thread_spec *s = spec_get();
 if ((ret = read(fd, buff, 8192)) <= 0) {
  if ((*__errno_location ()) == 11) {
   goto out;
  }
  goto close_connection;
 }
out:
 return 0;
close_connection:
 if (n->state == 0) {
  s->cur_connecting_connections --;
 } else {
  s->cur_connected_connections --;
 }
 close(n->fd);
 event_destroy(n->handle);
 free(n);
 return -1;
}

variable_types: ret int

variable_types:
buff
char [8192]


decompiled_code:
__int64 __fastcall client_write(int fd, void *ptr)
{
_DWORD *v3; // rax
_DWORD *v4; // rbx
size_t v5; // rdx
char *v6; // rsi
int v7; // eax
int v8; // er12
int v9; // eax
__int64 v10; // rdi
__int64 result; // rax
int v12; // eax

v3 = spec_get();
v4 = v3;
if ( max_duration_sec )
{
if ( !*((_DWORD *)ptr + 1) )
{
--v3[1];
++*v3;
*((_DWORD *)ptr + 1) = 1;
}
v5 = *((int *)ptr + 4);
if ( (_DWORD)v5 )
{
v6 = (char *)*((_QWORD *)ptr + 1);
}
else
{
v12 = request_len;
v6 = request;
*((_DWORD *)ptr + 4) = request_len;
v5 = v12;
*((_QWORD *)ptr + 1) = v6;
}
v7 = write(fd, v6, v5);
v8 = *((_DWORD *)ptr + 4);
if ( v7 > 0 )
{
v8 -= v7;
*((_QWORD *)ptr + 1) += v7;
*((_DWORD *)ptr + 4) = v8;
}
if ( !v8 )
{
v9 = v4[3];
v4[3] = 0;
v10 = *((_QWORD *)ptr + 3);
v4[7] = v9 + 1;
event_mod(v10, 1LL);
}
result = 0LL;
}
else
{
--v3[1];
close(*(_DWORD *)ptr);
event_destroy(*((_QWORD *)ptr + 3));
free(ptr);
result = 123LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *ptr)
{
_DWORD *v3; // rax
_DWORD *v4; // rbx
size_t v5; // rdx
char *v6; // rsi
int v7; // eax
int v8; // er12
int v9; // eax
__int64 v10; // rdi
__int64 result; // rax
int v12; // eax

v3 = func0();
v4 = v3;
if ( max_duration_sec )
{
if ( !*((_DWORD *)ptr + 1) )
{
--v3[1];
++*v3;
*((_DWORD *)ptr + 1) = 1;
}
v5 = *((int *)ptr + 4);
if ( (_DWORD)v5 )
{
v6 = (char *)*((_QWORD *)ptr + 1);
}
else
{
v12 = request_len;
v6 = request;
*((_DWORD *)ptr + 4) = request_len;
v5 = v12;
*((_QWORD *)ptr + 1) = v6;
}
v7 = write(fd, v6, v5);
v8 = *((_DWORD *)ptr + 4);
if ( v7 > 0 )
{
v8 -= v7;
*((_QWORD *)ptr + 1) += v7;
*((_DWORD *)ptr + 4) = v8;
}
if ( !v8 )
{
v9 = v4[3];
v4[3] = 0;
v10 = *((_QWORD *)ptr + 3);
v4[7] = v9 + 1;
event_mod(v10, 1LL);
}
result = 0LL;
}
else
{
--v3[1];
close(*(_DWORD *)ptr);
event_destroy(*((_QWORD *)ptr + 3));
free(ptr);
result = 123LL;
}
return result;
}

original_code:
int client_write(int fd, void *priv)
{
 struct thread_spec *s = spec_get();
 struct node *n = priv;
 int ret;
 if (max_duration_sec == 0) {
  s->cur_connecting_connections --;
  close(n->fd);
  event_destroy(n->handle);
  free(n);
  return 123;
 }
 if (n->state == 0) {
  s->cur_connecting_connections --;
  s->cur_connected_connections ++;
  n->state = 1;
 }
 if (n->len_write == 0) {
  n->len_write = request_len;
  n->pos_write = request;
 }
 if ((ret = write(fd, n->pos_write, n->len_write)) > 0) {
  n->len_write -= ret;
  n->pos_write += ret;
 }
 if (n->len_write == 0) {
  if (++ s->cur_sec_requests >= max_sec_requests) {
   s->l_sec_requests = s->cur_sec_requests;
   s->cur_sec_requests = 0;
   event_mod(n->handle, EPOLLIN);
  }
 }
 return 0;
}

variable_types: fd int


usage

decompiled_code:
void __noreturn usage()
{
puts("\nclient: -D -i ip -p port -b bindip");
puts("\t\t-D: Daemon process");
puts("\t\t-i ip: Server ip to be connected");
puts("\t\t-p port: Server port to be connected");
puts("\t\t-b bindip: Local ip.");
puts("\t\t-n num: New connections per second, default: 4096");
puts("\t\t-m num: Max connections, default: 4096");
puts("\t\t-t sec: life of each connection, default: -1");
puts("\t\t -1: nevel stop");
puts("\t\t 0: close immediate after connected");
puts("\t\t others: close after sec seconds");
puts("\t\t-r num: requests number per second. default: 0");
puts("\t\t-f file: request file.");
puts("\t\t-h: Show this help.");
putchar(10);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func6()
{
puts("\nclient: -D -i ip -p port -b bindip");
puts("\t\t-D: Daemon process");
puts("\t\t-i ip: Server ip to be connected");
puts("\t\t-p port: Server port to be connected");
puts("\t\t-b bindip: Local ip.");
puts("\t\t-n num: New connections per second, default: 4096");
puts("\t\t-m num: Max connections, default: 4096");
puts("\t\t-t sec: life of each connection, default: -1");
puts("\t\t -1: nevel stop");
puts("\t\t 0: close immediate after connected");
puts("\t\t others: close after sec seconds");
puts("\t\t-r num: requests number per second. default: 0");
puts("\t\t-f file: request file.");
puts("\t\t-h: Show this help.");
putchar(10);
exit(-1);
}

original_code:
static void usage(void)
{
 printf("\nclient: -D -i ip -p port -b bindip\n");
 printf("\t\t-D:         Daemon process\n");
 printf("\t\t-i ip:      Server ip to be connected\n");
 printf("\t\t-p port:    Server port to be connected\n");
 printf("\t\t-b bindip:  Local ip.\n");
 printf("\t\t-n num:     New connections per second, default: 4096\n");
 printf("\t\t-m num:     Max connections, default: 4096\n");
 printf("\t\t-t sec:     life of each connection, default: -1\n");
 printf("\t\t                     -1: nevel stop\n");
 printf("\t\t                      0: close immediate after connected\n");
 printf("\t\t                 others: close after sec seconds\n");
 printf("\t\t-r num:     requests number per second. default: 0\n");
 printf("\t\t-f file:    request file.\n");
 printf("\t\t-h:         Show this help.\n");
 printf("\n");
 exit(-1);
}

canonical_original_code:
static void usage()
{
 printf("\nclient: -D -i ip -p port -b bindip\n");
 printf("\t\t-D:         Daemon process\n");
 printf("\t\t-i ip:      Server ip to be connected\n");
 printf("\t\t-p port:    Server port to be connected\n");
 printf("\t\t-b bindip:  Local ip.\n");
 printf("\t\t-n num:     New connections per second, default: 4096\n");
 printf("\t\t-m num:     Max connections, default: 4096\n");
 printf("\t\t-t sec:     life of each connection, default: -1\n");
 printf("\t\t                     -1: nevel stop\n");
 printf("\t\t                      0: close immediate after connected\n");
 printf("\t\t                 others: close after sec seconds\n");
 printf("\t\t-r num:     requests number per second. default: 0\n");
 printf("\t\t-f file:    request file.\n");
 printf("\t\t-h:         Show this help.\n");
 printf("\n");
 exit(-1);
}


decompiled_code:
void thread_key_create(void)
{
load_request_isra_0();
pthread_key_create(&thread_spec_key, 0LL);
}

canonical_decompiled_code:
void func8(void)
{
func7();
pthread_key_create(&thread_spec_key, 0LL);
}

original_code:
static void thread_key_create(void)
{
 load_request();
 pthread_key_create(&thread_spec_key, ((void *)0));
}

canonical_original_code:
static void thread_key_create()
{
 load_request();
 pthread_key_create(&thread_spec_key, ((void *)0));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
char *v5; // r14
unsigned int v6; // er13
unsigned int v7; // eax
char *v8; // r14
unsigned int v9; // er13
unsigned int v10; // eax
int result; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:p:Db:m:n:t:r:f:h");
if ( v4 <= 0 )
break;
switch ( v4 )
{
case 'D':
v3 = 1;
break;
case 'b':
bind_ip = optarg;
break;
case 'f':
request_file = optarg;
break;
case 'i':
listen_ip = optarg;
break;
case 'm':
v8 = optarg;
v9 = (unsigned int)(atoi(optarg) + 3) >> 2;
max_connections = v9;
v10 = atoi(v8);
if ( (v10 & 3) != 0 )
printf("max connections \"%d\" will be aligned to \"%d\"\n", v10, 4 * v9);
break;
case 'n':
v5 = optarg;
v6 = (unsigned int)(atoi(optarg) + 3) >> 2;
max_sec_connections = v6;
v7 = atoi(v5);
if ( (v7 & 3) != 0 )
printf("new connections \"%d\" will be aligned to \"%d\"\n", v7, 4 * v6);
break;
case 'p':
listen_port = optarg;
break;
case 'r':
puts("request is omited now. ");
break;
case 't':
max_duration_sec = atoi(optarg);
break;
default:
usage();
return result;
}
}
if ( v3 )
daemon(1, 1);
if ( !getuid() )
set_nolimit();
if ( (int)event_init() >= 0 )
{
event_dispatch_loop();
event_timer(0LL, connect_timer);
while ( 1 )
sleep(1u);
}
perror("event_init");
exit(-1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
char *v5; // r14
unsigned int v6; // er13
unsigned int v7; // eax
char *v8; // r14
unsigned int v9; // er13
unsigned int v10; // eax
int result; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:p:Db:m:n:t:r:f:h");
if ( v4 <= 0 )
break;
switch ( v4 )
{
case 'D':
v3 = 1;
break;
case 'b':
bind_ip = optarg;
break;
case 'f':
request_file = optarg;
break;
case 'i':
listen_ip = optarg;
break;
case 'm':
v8 = optarg;
v9 = (unsigned int)(atoi(optarg) + 3) >> 2;
max_connections = v9;
v10 = atoi(v8);
if ( (v10 & 3) != 0 )
printf("max connections \"%d\" will be aligned to \"%d\"\n", v10, 4 * v9);
break;
case 'n':
v5 = optarg;
v6 = (unsigned int)(atoi(optarg) + 3) >> 2;
max_sec_connections = v6;
v7 = atoi(v5);
if ( (v7 & 3) != 0 )
printf("new connections \"%d\" will be aligned to \"%d\"\n", v7, 4 * v6);
break;
case 'p':
listen_port = optarg;
break;
case 'r':
puts("request is omited now. ");
break;
case 't':
max_duration_sec = atoi(optarg);
break;
default:
func6();
return result;
}
}
if ( v3 )
daemon(1, 1);
if ( !getuid() )
set_nolimit();
if ( (int)event_init() >= 0 )
{
event_dispatch_loop();
event_timer(0LL, connect_timer);
while ( 1 )
sleep(1u);
}
perror("event_init");
exit(-1);
}

original_code:
int main(int argc, char **argv)
{
 int c;
 int tobe_daemon = 0;
 extern char *optarg;
 while ((c = getopt(argc, argv, "i:p:Db:m:n:t:r:f:h")) > 0) {
  switch (c) {
   case 'i':
    listen_ip = optarg;
    break;
   case 'p':
    listen_port = optarg;
    break;
   case 'b':
    bind_ip = optarg;
    break;
   case 'm':
    max_connections = atoi(optarg);
    max_connections = (max_connections+3)/4;
    if ((atoi(optarg) & 0x3) != 0) {
     printf("max connections \"%d\" will be aligned to \"%d\"\n",
       atoi(optarg), max_connections*4);
    }
    break;
   case 'n':
    max_sec_connections = atoi(optarg);
    max_sec_connections = (max_sec_connections+3)/4;
    if ((atoi(optarg) & 0x3) != 0) {
     printf("new connections \"%d\" will be aligned to \"%d\"\n",
       atoi(optarg), max_sec_connections*4);
    }
    break;
   case 't':
    max_duration_sec = atoi(optarg);
    break;
   case 'r':
    printf("request is omited now. \n");
    break;
    max_sec_requests = atoi(optarg);
    max_sec_requests = (max_sec_requests+3)/4;
    if ((atoi(optarg) & 0x3) != 0) {
     printf("requests number \"%d\" will be aligned to \"%d\"\n",
       atoi(optarg), max_sec_requests*4);
    }
    printf("the life of connection will be ormit.\n");
    max_duration_sec = 1;
    break;
   case 'f':
    request_file = optarg;
    break;
   case 'D':
    tobe_daemon = 1;
    break;
   default:
    usage();
    break;
  }
 }
 if (tobe_daemon) {
  daemon(1, 1);
 }
 if (getuid() == 0) {
  set_nolimit();
 }
 if (event_init() < 0) {
  do { perror("event_init"); exit(-1); } while (0);
 }
 event_dispatch_loop();
 event_timer(((void *)0), connect_timer);
 while (1) {
  sleep(1);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types:
optarg
char *


decompiled_code:
__int64 __fastcall server_accept(int fd)
{
char *v1; // rax
_QWORD *v2; // rbp
int v3; // eax
__int64 v4; // rax
__int64 result; // rax
int v6; // eax

v1 = (char *)calloc(1uLL, 0x230uLL);
if ( v1 )
{
v2 = v1;
v3 = tcp_accept((unsigned int)fd, v1 + 4);
*(_DWORD *)v2 = v3;
if ( v3 >= 0 )
{
v4 = event_set((unsigned int)v3, v2, 0LL, client_read, client_write, 0LL);
v2[69] = v4;
if ( v4 )
{
result = event_add(v4, 1LL);
if ( !(_DWORD)result )
return result;
event_destroy(v2[69]);
}
close(*(_DWORD *)v2);
}
free(v2);
result = 0xFFFFFFFFLL;
}
else
{
v6 = accept(fd, 0LL, 0LL);
close(v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
char *v1; // rax
_QWORD *v2; // rbp
int v3; // eax
__int64 v4; // rax
__int64 result; // rax
int v6; // eax

v1 = (char *)calloc(1uLL, 0x230uLL);
if ( v1 )
{
v2 = v1;
v3 = tcp_accept((unsigned int)fd, v1 + 4);
*(_DWORD *)v2 = v3;
if ( v3 >= 0 )
{
v4 = event_set((unsigned int)v3, v2, 0LL, client_read, client_write, 0LL);
v2[69] = v4;
if ( v4 )
{
result = event_add(v4, 1LL);
if ( !(_DWORD)result )
return result;
event_destroy(v2[69]);
}
close(*(_DWORD *)v2);
}
free(v2);
result = 0xFFFFFFFFLL;
}
else
{
v6 = accept(fd, 0LL, 0LL);
close(v6);
result = 0LL;
}
return result;
}

original_code:
static int server_accept(int lsnfd, void *priv)
{
 struct node *n;
 if ((n = calloc(1, sizeof(struct node))) == ((void *)0)) {
  close(accept(lsnfd, ((void *)0), ((void *)0)));
  return 0;
 }
 if ((n->fd = tcp_accept(lsnfd, &n->addr)) < 0) {
  goto error;
 }
 if ((n->handle = event_set(n->fd, n, 0, client_read, client_write,
     ((void *)0))) == ((void *)0)) {
  goto error1;
 }
 if (event_add(n->handle, EPOLLIN) != 0) {
  goto error2;
 }
 return 0;
error2:
 event_destroy(n->handle);
error1:
 close(n->fd);
error:
 free(n);
 return -1;
}

variable_types: struct node { int fd; 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]; } addr; char request[512]; int len_read; char *pos_write; int len_write; void *handle; } *

user_defined_types: struct node { int fd; struct sockaddr_in addr; char request[512]; int len_read; char *pos_write; int len_write; void *handle; }


decompiled_code:
__int64 server_timer()
{
pthread_once(&once_control_0, thread_key_create);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
pthread_once(&once_control_0, thread_key_create);
return 0LL;
}

original_code:
static int server_timer(void *priv)
{
 static pthread_once_t once_control = 0;
 pthread_once(&once_control, thread_key_create);
 return 0;
}

canonical_original_code:
static int server_timer(void *priv)
{
 static int once_control = 0;
 pthread_once(&once_control, thread_key_create);
 return 0;
}