decompiled_code:
__int64 __fastcall gbk_cn_string(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er8

v1 = *a1;
v2 = a1[1];
if ( (unsigned int)(v1 - 176) > 0x47 )
{
if ( (unsigned int)(v1 - 129) <= 0x1F )
return ((unsigned int)(v2 - 128) <= 0x7E) | (unsigned __int8)((unsigned int)(v2 - 64) <= 0x3E);
v3 = 0;
if ( (unsigned int)(v1 - 170) > 0x54 )
return v3;
}
else
{
v3 = 1;
if ( (unsigned int)(v2 - 161) <= 0x5D )
return v3;
}
return (unsigned int)(v2 - 64) <= 0xBE;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er8

v1 = *a1;
v2 = a1[1];
if ( (unsigned int)(v1 - 176) > 0x47 )
{
if ( (unsigned int)(v1 - 129) <= 0x1F )
return ((unsigned int)(v2 - 128) <= 0x7E) | (unsigned __int8)((unsigned int)(v2 - 64) <= 0x3E);
v3 = 0;
if ( (unsigned int)(v1 - 170) > 0x54 )
return v3;
}
else
{
v3 = 1;
if ( (unsigned int)(v2 - 161) <= 0x5D )
return v3;
}
return (unsigned int)(v2 - 64) <= 0xBE;
}


repo: Travis-Sun/friso

decompiled_code:
_BOOL8 __fastcall gbk_halfwidth_en_char(unsigned __int8 a1)
{
return (unsigned int)a1 - 32 <= 0x5E;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned __int8 a1)
{
return (unsigned int)a1 - 32 <= 0x5E;
}

original_code:
extern int gbk_halfwidth_en_char( char c )
{
    int u = (uchar_t) c;
    return ( u >= 32 && u <= 126 );
}

canonical_original_code:
extern int gbk_halfwidth_en_char(char c)
{
    int u = (uchar_t) c;
    return ( u >= 32 && u <= 126 );
}

variable_types: c char

variable_types: u int

return_type: int


decompiled_code:
__int64 __fastcall gbk_fullwidth_en_char(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 == 0xA3 )
result = ((unsigned int)(unsigned __int8)a1[1] - 176 <= 9) | (unsigned __int8)((unsigned __int8)((a1[1] & 0xDF) + 63) <= 0x19u);
return result;
}

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

result = 0LL;
if ( *a1 == 0xA3 )
result = ((unsigned int)(unsigned __int8)a1[1] - 176 <= 9) | (unsigned __int8)((unsigned __int8)((a1[1] & 0xDF) + 63) <= 0x19u);
return result;
}

original_code:
extern int gbk_fullwidth_en_char( char *str )
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    return ( (c1 == 0xA3)
     && ( (c2 >= 0xB0 && c2 <= 0xB9)
        || ( c2 >= 0xC1 && c2 <= 0xDA )
        || ( c2 >= 0xE1 && c2 <= 0xFA) ) );
}

canonical_original_code:
extern int gbk_fullwidth_en_char(char *str)
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    return ( (c1 == 0xA3)
     && ( (c2 >= 0xB0 && c2 <= 0xB9)
        || ( c2 >= 0xC1 && c2 <= 0xDA )
        || ( c2 >= 0xE1 && c2 <= 0xFA) ) );
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall gbk_uppercase_letter(unsigned __int8 *a1)
{
unsigned int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( v1 <= 0x80 )
return v1 - 65 <= 0x19;
v2 = 0;
if ( v1 != 163 )
return v2;
return (unsigned int)a1[1] - 193 <= 0x19;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1)
{
unsigned int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( v1 <= 0x80 )
return v1 - 65 <= 0x19;
v2 = 0;
if ( v1 != 163 )
return v2;
return (unsigned int)a1[1] - 193 <= 0x19;
}

original_code:
extern int gbk_uppercase_letter( char *str )
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 )
 return ( c1 >= 65 && c1 <= 90 );
    else
 return ( c1 == 0xa3 && ( c2 >= 0xc1 && c2 <= 0xda ) );
}

canonical_original_code:
extern int gbk_uppercase_letter(char *str)
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 )
 return ( c1 >= 65 && c1 <= 90 );
    else
 return ( c1 == 0xa3 && ( c2 >= 0xc1 && c2 <= 0xda ) );
}


decompiled_code:
__int64 __fastcall gbk_lowercase_letter(unsigned __int8 *a1)
{
unsigned int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( v1 <= 0x80 )
return v1 - 97 <= 0x19;
v2 = 0;
if ( v1 != 163 )
return v2;
return (unsigned int)a1[1] - 225 <= 0x19;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
unsigned int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( v1 <= 0x80 )
return v1 - 97 <= 0x19;
v2 = 0;
if ( v1 != 163 )
return v2;
return (unsigned int)a1[1] - 225 <= 0x19;
}

original_code:
extern int gbk_lowercase_letter( char *str )
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 )
 return ( c1 >= 97 && c1 <= 122 );
    else
 return ( c1 == 0xa3 && ( c2 >= 0xe1 && c2 <= 0xfa ) );
}

canonical_original_code:
extern int gbk_lowercase_letter(char *str)
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 )
 return ( c1 >= 97 && c1 <= 122 );
    else
 return ( c1 == 0xa3 && ( c2 >= 0xe1 && c2 <= 0xfa ) );
}


decompiled_code:
__int64 __fastcall gbk_numeric_letter(unsigned __int8 *a1)
{
unsigned int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( v1 <= 0x80 )
return v1 - 48 <= 9;
v2 = 0;
if ( v1 != 163 )
return v2;
return (unsigned int)a1[1] - 176 <= 9;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 *a1)
{
unsigned int v1; // eax
unsigned int v2; // er8

v1 = *a1;
if ( v1 <= 0x80 )
return v1 - 48 <= 9;
v2 = 0;
if ( v1 != 163 )
return v2;
return (unsigned int)a1[1] - 176 <= 9;
}

original_code:
extern int gbk_numeric_letter( char *str )
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 )
 return ( c1 >= 48 && c1 <= 57 );
    else
 return ( ( c1 == 0xa3 ) && ( c2 >= 0xb0 && c2 <= 0xb9 ) );
}

canonical_original_code:
extern int gbk_numeric_letter(char *str)
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 )
 return ( c1 >= 48 && c1 <= 57 );
    else
 return ( ( c1 == 0xa3 ) && ( c2 >= 0xb0 && c2 <= 0xb9 ) );
}


decompiled_code:
__int64 __fastcall gbk_numeric_string(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
int v2; // edx
unsigned __int8 *v3; // rcx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0;
while ( 1 )
{
while ( v1 > 0x80u )
{
if ( v1 != 0xA3 )
return 0LL;
v2 = a1[1];
v3 = a1 + 2;
if ( (unsigned int)(v2 - 176) > 9 )
return 0LL;
a1 += 2;
v1 = *v3;
if ( !*v3 )
return 1LL;
}
if ( v1 <= 0x2Fu || v2 > 57 )
break;
v1 = *++a1;
if ( !v1 )
return 1LL;
}
return 0LL;
}

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

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0;
while ( 1 )
{
while ( v1 > 0x80u )
{
if ( v1 != 0xA3 )
return 0LL;
v2 = a1[1];
v3 = a1 + 2;
if ( (unsigned int)(v2 - 176) > 9 )
return 0LL;
a1 += 2;
v1 = *v3;
if ( !*v3 )
return 1LL;
}
if ( v1 <= 0x2Fu || v2 > 57 )
break;
v1 = *++a1;
if ( !v1 )
return 1LL;
}
return 0LL;
}

original_code:
extern int gbk_numeric_string( char *str )
{
    char *s = str;
    int c1 = 0;
    int c2 = 0;
    while ( *s != '\0' )
    {
 c1 = (uchar_t) (*s++);
 if ( c1 <= 0x80 )
 {
     if ( c1 < 48 || c2 > 57 ) return 0;
 }
 else
 {
     if ( c1 != 0xa3 ) return 0;
     c2 = (uchar_t) (*s++);
     if ( c2 < 0xb0 || c2 > 0xb9 ) return 0;
 }
    }
    return 1;
}

canonical_original_code:
extern int gbk_numeric_string(char *str)
{
    char *s = str;
    int c1 = 0;
    int c2 = 0;
    while ( *s != '\0' )
    {
 c1 = (uchar_t) (*s++);
 if ( c1 <= 0x80 )
 {
     if ( c1 < 48 || c2 > 57 ) return 0;
 }
 else
 {
     if ( c1 != 0xa3 ) return 0;
     c2 = (uchar_t) (*s++);
     if ( c2 < 0xb0 || c2 > 0xb9 ) return 0;
 }
    }
    return 1;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall gbk_decimal_string(const char *a1)
{
int v2; // eax
unsigned __int8 v3; // si
unsigned int v4; // er8
int v5; // edi
int v6; // ecx
int v7; // eax
int v8; // ecx

v2 = strlen(a1);
v3 = *a1;
v4 = 0;
if ( *a1 == 46 || a1[v2 - 1] == 46 || v2 <= 0 )
return v4;
v5 = v2;
v6 = 0;
while ( 1 )
{
v7 = v6 + 1;
if ( v3 == 46 )
{
++v4;
goto LABEL_6;
}
if ( v3 <= 0x80u )
{
if ( (unsigned int)v3 - 48 > 9 )
return 0LL;
LABEL_6:
if ( v7 >= v5 )
return v4 == 1;
goto LABEL_7;
}
if ( v3 != 163 )
return 0LL;
v8 = v6 + 2;
if ( (unsigned int)(unsigned __int8)a1[v7] - 176 > 9 )
return 0LL;
v7 = v8;
if ( v8 >= v5 )
return v4 == 1;
LABEL_7:
v6 = v7;
v3 = a1[v7];
}
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
int v2; // eax
unsigned __int8 v3; // si
unsigned int v4; // er8
int v5; // edi
int v6; // ecx
int v7; // eax
int v8; // ecx

v2 = strlen(a1);
v3 = *a1;
v4 = 0;
if ( *a1 == 46 || a1[v2 - 1] == 46 || v2 <= 0 )
return v4;
v5 = v2;
v6 = 0;
while ( 1 )
{
v7 = v6 + 1;
if ( v3 == 46 )
{
++v4;
goto LABEL_6;
}
if ( v3 <= 0x80u )
{
if ( (unsigned int)v3 - 48 > 9 )
return 0LL;
LABEL_6:
if ( v7 >= v5 )
return v4 == 1;
goto LABEL_7;
}
if ( v3 != 163 )
return 0LL;
v8 = v6 + 2;
if ( (unsigned int)(unsigned __int8)a1[v7] - 176 > 9 )
return 0LL;
v7 = v8;
if ( v8 >= v5 )
return v4 == 1;
LABEL_7:
v6 = v7;
v3 = a1[v7];
}
}

original_code:
extern int gbk_decimal_string( char *str )
{
    int c1 = 0;
    int c2 = 0;
    int len = strlen(str), i, p = 0;
    if ( str[0] == '.' || str[len - 1] == '.' ) return 0;
    for ( i = 0; i < len; )
    {
 c1 = (uchar_t) str[i++];
 if ( c1 == 46 )
 {
     p++;
     continue;
 }
 if ( c1 <= 0x80 )
 {
     if ( c1 < 48 || c1 > 57 ) return 0;
 }
 else
 {
     if ( c1 != 0xa3 ) return 0;
     c2 = (uchar_t) str[i++];
     if ( c2 < 0xb0 || c2 > 0xb9 ) return 0;
 }
    }
    return (p == 1);
}

canonical_original_code:
extern int gbk_decimal_string(char *str)
{
    int c1 = 0;
    int c2 = 0;
    int len = strlen(str); int i; int p = 0;
    if ( str[0] == '.' || str[len - 1] == '.' ) return 0;
    for ( i = 0; i < len; )
    {
 c1 = (unsigned char) str[i++];
 if ( c1 == 46 )
 {
     p++;
     continue;
 }
 if ( c1 <= 0x80 )
 {
     if ( c1 < 48 || c1 > 57 ) return 0;
 }
 else
 {
     if ( c1 != 0xa3 ) return 0;
     c2 = (unsigned char) str[i++];
     if ( c2 < 0xb0 || c2 > 0xb9 ) return 0;
 }
    }
    return (p == 1);
}

variable_types: len int

variable_types: i int

variable_types: p int


decompiled_code:
_BOOL8 __fastcall gbk_en_letter(unsigned __int8 *a1)
{
_BOOL8 result; // rax

if ( *a1 <= 0x80u )
return (unsigned __int8)((*a1 & 0xDF) - 65) <= 0x19u;
result = 0LL;
if ( *a1 == 163 )
result = (unsigned __int8)((a1[1] & 0xDF) + 63) <= 0x19u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned __int8 *a1)
{
_BOOL8 result; // rax

if ( *a1 <= 0x80u )
return (unsigned __int8)((*a1 & 0xDF) - 65) <= 0x19u;
result = 0LL;
if ( *a1 == 163 )
result = (unsigned __int8)((a1[1] & 0xDF) + 63) <= 0x19u;
return result;
}


decompiled_code:
__int64 __fastcall gbk_whitespace(unsigned __int8 *a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = *a1;
if ( v1 > 0x80 )
result = (v1 == 163) & (unsigned __int8)(a1[1] == 0xA0);
else
result = v1 == 32;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = *a1;
if ( v1 > 0x80 )
result = (v1 == 163) & (unsigned __int8)(a1[1] == 0xA0);
else
result = v1 == 32;
return result;
}

original_code:
extern int gbk_whitespace( char *str )
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 ) return (c1 == 32);
    else return ( c1 == 0xa3 && c2 == 0xa0 );
}

canonical_original_code:
extern int gbk_whitespace(char *str)
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    if ( c1 <= 0x80 ) return (c1 == 32);
    else return ( c1 == 0xa3 && c2 == 0xa0 );
}


decompiled_code:
__int64 __fastcall gbk_letter_number(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 == 0xA2 )
result = ((unsigned int)(unsigned __int8)a1[1] - 240 <= 0xE) | (unsigned __int8)((unsigned int)(unsigned __int8)a1[1]
- 161 <= 0xF);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 == 0xA2 )
result = ((unsigned int)(unsigned __int8)a1[1] - 240 <= 0xE) | (unsigned __int8)((unsigned int)(unsigned __int8)a1[1]
- 161 <= 0xF);
return result;
}

original_code:
extern int gbk_letter_number( char *str )
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    return ( (c1 == 0xa2)
     && ( ( c2 >= 0xa1 && c2 <= 0xb0 )
  || ( c2 >= 0xf0 && c2 <= 0xfe ) ) );
}

canonical_original_code:
extern int gbk_letter_number(char *str)
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    return ( (c1 == 0xa2)
     && ( ( c2 >= 0xa1 && c2 <= 0xb0 )
  || ( c2 >= 0xf0 && c2 <= 0xfe ) ) );
}


decompiled_code:
_BOOL8 __fastcall gbk_other_number(_BYTE *a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( *a1 == 0xA2 )
v1 = (unsigned int)(unsigned __int8)a1[1] - 197 <= 0x29;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_BYTE *a1)
{
_BOOL4 v1; // er8

v1 = 0;
if ( *a1 == 0xA2 )
v1 = (unsigned int)(unsigned __int8)a1[1] - 197 <= 0x29;
return v1;
}

original_code:
extern int gbk_other_number( char *str )
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    return ( ( c1 == 0xa2 ) && ( c2 >= 0xc5 && c2 <= 0xee ) );
}

canonical_original_code:
extern int gbk_other_number(char *str)
{
    int c1 = (uchar_t) str[0];
    int c2 = (uchar_t) str[1];
    return ( ( c1 == 0xa2 ) && ( c2 >= 0xc5 && c2 <= 0xee ) );
}


decompiled_code:
_BOOL8 __fastcall gbk_en_punctuation(int a1)
{
unsigned __int64 v1; // rdx
_BOOL8 result; // rax

if ( (unsigned __int8)(a1 - 33) <= 0x3Fu
&& (v1 = 0xFC000000FE007FFFLL, _bittest64((const __int64 *)&v1, (unsigned int)(a1 - 33))) )
{
result = 1LL;
}
else
{
result = (unsigned int)(unsigned __int8)a1 - 123 <= 3;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int a1)
{
unsigned __int64 v1; // rdx
_BOOL8 result; // rax

if ( (unsigned __int8)(a1 - 33) <= 0x3Fu
&& (v1 = 0xFC000000FE007FFFLL, _bittest64((const __int64 *)&v1, (unsigned int)(a1 - 33))) )
{
result = 1LL;
}
else
{
result = (unsigned int)(unsigned __int8)a1 - 123 <= 3;
}
return result;
}


decompiled_code:
__int64 __fastcall gbk_cn_punctuation(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er8
unsigned __int64 v5; // rcx

v1 = *a1;
v2 = a1[1];
if ( v1 == 163 )
{
if ( (unsigned __int8)(v2 + 95) > 0x3Fu )
return (unsigned int)(v2 - 251) <= 3;
v5 = 0xFC000000FE007FFFLL;
v3 = 1;
if ( !_bittest64((const __int64 *)&v5, (unsigned int)(v2 + 95)) )
return (unsigned int)(v2 - 251) <= 3;
return v3;
}
if ( v1 == 161 )
return ((unsigned int)(v2 - 176) <= 0xF) | (unsigned __int8)((unsigned int)(v2 - 161) <= 0xD);
if ( v1 != 166 )
{
v3 = 0;
if ( v1 == 168 )
return (unsigned int)(v2 - 64) <= 7;
return v3;
}
return (unsigned int)(v2 - 249) <= 5;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 *a1)
{
int v1; // edx
int v2; // eax
unsigned int v3; // er8
unsigned __int64 v5; // rcx

v1 = *a1;
v2 = a1[1];
if ( v1 == 163 )
{
if ( (unsigned __int8)(v2 + 95) > 0x3Fu )
return (unsigned int)(v2 - 251) <= 3;
v5 = 0xFC000000FE007FFFLL;
v3 = 1;
if ( !_bittest64((const __int64 *)&v5, (unsigned int)(v2 + 95)) )
return (unsigned int)(v2 - 251) <= 3;
return v3;
}
if ( v1 == 161 )
return ((unsigned int)(v2 - 176) <= 0xF) | (unsigned __int8)((unsigned int)(v2 - 161) <= 0xD);
if ( v1 != 166 )
{
v3 = 0;
if ( v1 == 168 )
return (unsigned int)(v2 - 64) <= 7;
return v3;
}
return (unsigned int)(v2 - 249) <= 5;
}


decompiled_code:
void *__fastcall create_buffer(size_t nmemb)
{
void *result; // rax

result = calloc((unsigned int)nmemb, 1uLL);
if ( !result )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t nmemb)
{
void *result; // rax

result = calloc((unsigned int)nmemb, 1uLL);
if ( !result )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
return result;
}

original_code:
static inline fstring create_buffer( uint_t length )
{
    fstring buffer = ( fstring ) malloc(length);
    if ( buffer == ((void *)0) ) {
 printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
    }
    memset( buffer, 0x00, length );
    return buffer;
}

canonical_original_code:
static inline char *create_buffer(unsigned int length)
{
    char *buffer = ( fstring ) malloc(length);
    if ( buffer == ((void *)0) ) {
 printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
    }
    memset( buffer, 0x00, length );
    return buffer;
}

variable_types:
length
unsigned int

variable_types:
buffer
char *

return_type: char *


decompiled_code:
__int64 __fastcall resize_buffer(__int64 a1, unsigned int a2)
{
void *v2; // rax
void *v3; // r13
void *v4; // rbp
__int64 result; // rax

v2 = create_buffer(a2);
v3 = *(void **)a1;
v4 = v2;
memcpy(v2, *(const void **)a1, *(unsigned int *)(a1 + 8));
free(v3);
*(_QWORD *)a1 = v4;
result = a1;
*(_DWORD *)(a1 + 12) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
void *v2; // rax
void *v3; // r13
void *v4; // rbp
__int64 result; // rax

v2 = func0(a2);
v3 = *(void **)a1;
v4 = v2;
memcpy(v2, *(const void **)a1, *(unsigned int *)(a1 + 8));
free(v3);
*(_QWORD *)a1 = v4;
result = a1;
*(_DWORD *)(a1 + 12) = a2;
return result;
}

original_code:
static inline string_buffer_t resize_buffer(
 string_buffer_t sb, uint_t __allocs )
{
    fstring str = create_buffer( __allocs );
    memcpy( str, sb->buffer, sb->length );
    free( sb->buffer );
    sb->buffer = str;
    sb->allocs = __allocs;
    return sb;
}

canonical_original_code:
static inline struct string_buffer_entry *resize_buffer(struct string_buffer_entry *sb, unsigned int __allocs)
{
    char *str = create_buffer( __allocs );
    memcpy( str, sb->buffer, sb->length );
    free( sb->buffer );
    sb->buffer = str;
    sb->allocs = __allocs;
    return sb;
}

variable_types:
sb
struct string_buffer_entry *

return_type: struct string_buffer_entry { char *buffer; unsigned int length; unsigned int allocs; } *


decompiled_code:
void *__fastcall string_buffer_append(__int64 a1, const char *a2)
{
__int64 v2; // rbp
unsigned int v3; // eax
__int64 v4; // rdi
unsigned int v5; // ebx
unsigned int v6; // eax
void *result; // rax
__int64 v8; // rax

v2 = a1;
v3 = strlen(a2);
v4 = *(unsigned int *)(a1 + 8);
v5 = v3;
v6 = v4 + v3;
if ( v6 > *(_DWORD *)(v2 + 12) )
{
v8 = resize_buffer(v2, 2 * v6 + 1);
v4 = *(unsigned int *)(v8 + 8);
v2 = v8;
}
result = memcpy((void *)(*(_QWORD *)v2 + v4), a2, v5);
*(_DWORD *)(v2 + 8) += v5;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, const char *a2)
{
__int64 v2; // rbp
unsigned int v3; // eax
__int64 v4; // rdi
unsigned int v5; // ebx
unsigned int v6; // eax
void *result; // rax
__int64 v8; // rax

v2 = a1;
v3 = strlen(a2);
v4 = *(unsigned int *)(a1 + 8);
v5 = v3;
v6 = v4 + v3;
if ( v6 > *(_DWORD *)(v2 + 12) )
{
v8 = func1(v2, 2 * v6 + 1);
v4 = *(unsigned int *)(v8 + 8);
v2 = v8;
}
result = memcpy((void *)(*(_QWORD *)v2 + v4), a2, v5);
*(_DWORD *)(v2 + 8) += v5;
return result;
}

original_code:
extern void string_buffer_append(
 string_buffer_t sb, fstring __str )
{
    register uint_t __len__ = strlen( __str );
    if ( sb->length + __len__ > sb->allocs ) {
 sb = resize_buffer( sb, ( sb->length + __len__ ) * 2 + 1 );
    }
    memcpy( sb->buffer + sb->length, __str, __len__ );
    sb->length += __len__;
}

canonical_original_code:
extern void string_buffer_append(struct string_buffer_entry *sb, char *__str)
{
    register unsigned int __len__ = strlen( __str );
    if ( sb->length + __len__ > sb->allocs ) {
 sb = resize_buffer( sb, ( sb->length + __len__ ) * 2 + 1 );
    }
    memcpy( sb->buffer + sb->length, __str, __len__ );
    sb->length += __len__;
}

variable_types: struct string_buffer_entry { char *buffer; unsigned int length; unsigned int allocs; } *

return_type: void


decompiled_code:
void string_buffer_insert()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
extern void string_buffer_insert(
 string_buffer_t sb,
 uint_t idx,
 fstring __str )
{
}

canonical_original_code:
extern void string_buffer_insert(struct string_buffer_entry *sb, unsigned int idx, char *__str)
{
}

variable_types:
idx
unsigned int

user_defined_types: struct string_buffer_entry { char *buffer; unsigned int length; unsigned int allocs; }


decompiled_code:
__int64 __fastcall string_buffer_remove(_DWORD *a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er9
unsigned int v4; // er10
__int64 v5; // rax
unsigned int v6; // edx
__int64 v7; // rsi
char v8; // r8
__int64 v9; // rsi
int v10; // eax

v3 = a2;
v4 = a3;
v5 = a2 + a3;
if ( (unsigned int)v5 < a1[2] )
{
v6 = a2;
do
{
v7 = (unsigned int)v5;
v5 = (unsigned int)(v5 + 1);
v8 = *(_BYTE *)(*(_QWORD *)a1 + v7);
v9 = v6++;
*(_BYTE *)(*(_QWORD *)a1 + v9) = v8;
}
while ( a1[2] > (unsigned int)v5 );
}
*(_BYTE *)(*(_QWORD *)a1 + v5) = 0;
v10 = a1[2];
if ( v10 != v3 )
{
if ( v4 > v10 - v3 )
v4 = a1[2] - v3;
v10 -= v4;
a1[2] = v10;
}
*(_BYTE *)(*(_QWORD *)a1 + (unsigned int)(v10 - 1)) = 0;
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er9
unsigned int v4; // er10
__int64 v5; // rax
unsigned int v6; // edx
__int64 v7; // rsi
char v8; // r8
__int64 v9; // rsi
int v10; // eax

v3 = a2;
v4 = a3;
v5 = a2 + a3;
if ( (unsigned int)v5 < a1[2] )
{
v6 = a2;
do
{
v7 = (unsigned int)v5;
v5 = (unsigned int)(v5 + 1);
v8 = *(_BYTE *)(*(_QWORD *)a1 + v7);
v9 = v6++;
*(_BYTE *)(*(_QWORD *)a1 + v9) = v8;
}
while ( a1[2] > (unsigned int)v5 );
}
*(_BYTE *)(*(_QWORD *)a1 + v5) = 0;
v10 = a1[2];
if ( v10 != v3 )
{
if ( v4 > v10 - v3 )
v4 = a1[2] - v3;
v10 -= v4;
a1[2] = v10;
}
*(_BYTE *)(*(_QWORD *)a1 + (unsigned int)(v10 - 1)) = 0;
return *(_QWORD *)a1;
}

original_code:
extern fstring string_buffer_remove(
 string_buffer_t sb,
 uint_t idx,
 uint_t length )
{
    uint_t t;
    for ( t = idx + length; t < sb->length; t++ ) {
 sb->buffer[t - length] = sb->buffer[t];
    }
    sb->buffer[t] = '\0';
    t = sb->length - idx;
    if ( t > 0 ) {
 sb->length -= ( t > length ) ? length : t;
    }
    sb->buffer[sb->length-1] = '\0';
    return sb->buffer;
}

canonical_original_code:
extern char *string_buffer_remove(struct string_buffer_entry *sb, unsigned int idx, unsigned int length)
{
    unsigned int t;
    for ( t = idx + length; t < sb->length; t++ ) {
 sb->buffer[t - length] = sb->buffer[t];
    }
    sb->buffer[t] = '\0';
    t = sb->length - idx;
    if ( t > 0 ) {
 sb->length -= ( t > length ) ? length : t;
    }
    sb->buffer[sb->length-1] = '\0';
    return sb->buffer;
}

variable_types:
t
unsigned int


decompiled_code:
__int64 __fastcall string_buffer_trim(__int64 a1)
{
unsigned int v1; // esi
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
result = a1;
if ( v1 < *(_DWORD *)(a1 + 12) - 1 )
result = resize_buffer(a1, v1 + 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // esi
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 8);
result = a1;
if ( v1 < *(_DWORD *)(a1 + 12) - 1 )
result = func1(a1, v1 + 1);
return result;
}

original_code:
extern string_buffer_t string_buffer_trim( string_buffer_t sb )
{
    if ( sb->length < sb->allocs - 1 ) {
 sb = resize_buffer( sb, sb->length + 1 );
    }
    return sb;
}

canonical_original_code:
extern struct string_buffer_entry *string_buffer_trim(struct string_buffer_entry *sb)
{
    if ( sb->length < sb->allocs - 1 ) {
 sb = resize_buffer( sb, sb->length + 1 );
    }
    return sb;
}


decompiled_code:
__int64 __fastcall string_buffer_devote(__int64 *a1)
{
__int64 v1; // r12

v1 = *a1;
free(a1);
return v1;
}

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

v1 = *a1;
free(a1);
return v1;
}

original_code:
extern fstring string_buffer_devote( string_buffer_t sb )
{
    fstring buffer = sb->buffer;
    free( sb );
    return buffer;
}

canonical_original_code:
extern char *string_buffer_devote(struct string_buffer_entry *sb)
{
    char *buffer = sb->buffer;
    free( sb );
    return buffer;
}


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

result = memset(*(void **)a1, 0, *(unsigned int *)(a1 + 8));
*(_DWORD *)(a1 + 8) = 0;
return result;
}

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

result = memset(*(void **)a1, 0, *(unsigned int *)(a1 + 8));
*(_DWORD *)(a1 + 8) = 0;
return result;
}

original_code:
extern void string_buffer_clear( string_buffer_t sb )
{
    memset( sb->buffer, 0x00, sb->length );
    sb->length = 0;
}

canonical_original_code:
extern void string_buffer_clear(struct string_buffer_entry *sb)
{
    memset( sb->buffer, 0x00, sb->length );
    sb->length = 0;
}


decompiled_code:
void __fastcall free_string_buffer(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
extern void free_string_buffer( string_buffer_t sb )
{
    free( sb->buffer );
    free( sb );
}

canonical_original_code:
extern void free_string_buffer(struct string_buffer_entry *sb)
{
    free( sb->buffer );
    free( sb );
}


decompiled_code:
size_t __fastcall string_split_reset(__int64 a1, const char *a2, const char *a3)
{
int v4; // eax
size_t result; // rax

*(_QWORD *)(a1 + 16) = a2;
v4 = strlen(a2);
*(_QWORD *)a1 = a3;
*(_DWORD *)(a1 + 24) = v4;
result = strlen(a3);
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
size_t __fastcall func11(__int64 a1, const char *a2, const char *a3)
{
int v4; // eax
size_t result; // rax

*(_QWORD *)(a1 + 16) = a2;
v4 = strlen(a2);
*(_QWORD *)a1 = a3;
*(_DWORD *)(a1 + 24) = v4;
result = strlen(a3);
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
extern void string_split_reset(
 string_split_t sst,
 fstring delimiter,
 fstring source )
{
    sst->delimiter = delimiter;
    sst->delLen = strlen(delimiter);
    sst->source = source;
    sst->srcLen = strlen(source);
    sst->idx = 0;
}

canonical_original_code:
extern void string_split_reset(struct string_split_entry *sst, char *delimiter, char *source)
{
    sst->delimiter = delimiter;
    sst->delLen = strlen(delimiter);
    sst->source = source;
    sst->srcLen = strlen(source);
    sst->idx = 0;
}

variable_types: struct string_split_entry { char *source; unsigned int srcLen; char *delimiter; unsigned int delLen; unsigned int idx; } *

variable_types:
delimiter
char *

variable_types:
source
char *


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

*(_QWORD *)a1 = a2;
result = strlen(a2);
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 8) = result;
return result;
}

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

*(_QWORD *)a1 = a2;
result = strlen(a2);
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
extern void string_split_set_source(
 string_split_t sst, fstring source )
{
    sst->source = source;
    sst->srcLen = strlen(source);
    sst->idx = 0;
}

canonical_original_code:
extern void string_split_set_source(struct string_split_entry *sst, char *source)
{
    sst->source = source;
    sst->srcLen = strlen(source);
    sst->idx = 0;
}

user_defined_types: struct string_split_entry { char *source; unsigned int srcLen; char *delimiter; unsigned int delLen; unsigned int idx; }


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

*(_QWORD *)(a1 + 16) = a2;
result = strlen(a2);
*(_QWORD *)(a1 + 24) = (unsigned int)result;
return result;
}

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

*(_QWORD *)(a1 + 16) = a2;
result = strlen(a2);
*(_QWORD *)(a1 + 24) = (unsigned int)result;
return result;
}

original_code:
extern void string_split_set_delimiter(
 string_split_t sst, fstring delimiter )
{
    sst->delimiter = delimiter;
    sst->delLen = strlen( delimiter );
    sst->idx = 0;
}

canonical_original_code:
extern void string_split_set_delimiter(struct string_split_entry *sst, char *delimiter)
{
    sst->delimiter = delimiter;
    sst->delLen = strlen( delimiter );
    sst->idx = 0;
}


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

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

original_code:
extern void free_string_split( string_split_t sst )
{
    free( sst );
}

canonical_original_code:
extern void free_string_split(struct string_split_entry *sst)
{
    free( sst );
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char *v4; // r14
int v5; // ebx
__int64 v6; // r12
void *v7; // r13
int v8; // eax
const char *v9; // rdx
__int64 v10; // rbp
int v11; // er14
int v12; // eax
__int128 v14; // [rsp+0h] [rbp-5038h] BYREF
char s[20520]; // [rsp+10h] [rbp-5028h] BYREF

v3 = argv;
v14 = 0LL;
memset(s, 0, 0x4FF0uLL);
if ( argc <= 0 )
goto LABEL_19;
v4 = 0LL;
do
{
if ( !strcasecmp("-init", *v3) )
v4 = v3[1];
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
if ( !v4 )
{
LABEL_19:
puts("Usage: friso -init lexicon path");
exit(0);
}
v5 = clock();
v6 = friso_new();
v7 = (void *)friso_new_config();
if ( (unsigned int)friso_init_from_ifile() == 1 )
{
v8 = clock() - v5;
printf("Initialized in %fsec\n", (double)v8 / 1000000.0);
v9 = "UTF-8";
if ( *(_DWORD *)(v6 + 8) )
v9 = "GBK";
printf("+-Version: %s (%s)\n", "1.6.0", v9);
puts("+-----------------------------------------------------------+");
puts("| friso - a chinese word segmentation writen by c. |");
puts("| bug report email - chenxin619315@gmail.com. |");
puts("| or: visit http://code.google.com/p/friso. |");
puts("| java edition for http://code.google.com/p/jcseg |");
puts("| type 'quit' to exit the program. |");
puts("+-----------------------------------------------------------+");
v10 = friso_new_task();
while ( 1 )
{
printf("%s", "friso>> ");
getLine_isra_0(stdin);
if ( !strcasecmp((const char *)&v14, "quit") )
break;
friso_set_text();
puts(&byte_40206E);
v11 = clock();
while ( friso_next() )
printf("%s/ ", (const char *)(*(_QWORD *)(v10 + 32) + 4LL));
v12 = clock();
printf("\nDone, cost < %fsec\n", (double)(v12 - v11) / 1000000.0);
}
puts("Thanks for trying friso.");
friso_free_task();
}
else
{
printf("fail to initialize friso and config.");
}
free(v7);
friso_free();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char *v4; // r14
int v5; // ebx
__int64 v6; // r12
void *v7; // r13
int v8; // eax
const char *v9; // rdx
__int64 v10; // rbp
int v11; // er14
int v12; // eax
__int128 v14; // [rsp+0h] [rbp-5038h] BYREF
char s[20520]; // [rsp+10h] [rbp-5028h] BYREF

v3 = argv;
v14 = 0LL;
memset(s, 0, 0x4FF0uLL);
if ( argc <= 0 )
goto LABEL_19;
v4 = 0LL;
do
{
if ( !strcasecmp("-init", *v3) )
v4 = v3[1];
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 1) + 1] );
if ( !v4 )
{
LABEL_19:
puts("Usage: friso -init lexicon path");
exit(0);
}
v5 = clock();
v6 = friso_new();
v7 = (void *)friso_new_config();
if ( (unsigned int)friso_init_from_ifile() == 1 )
{
v8 = clock() - v5;
printf("Initialized in %fsec\n", (double)v8 / 1000000.0);
v9 = "UTF-8";
if ( *(_DWORD *)(v6 + 8) )
v9 = "GBK";
printf("+-Version: %s (%s)\n", "1.6.0", v9);
puts("+-----------------------------------------------------------+");
puts("| friso - a chinese word segmentation writen by c. |");
puts("| bug report email - chenxin619315@gmail.com. |");
puts("| or: visit http://code.google.com/p/friso. |");
puts("| java edition for http://code.google.com/p/jcseg |");
puts("| type 'quit' to exit the program. |");
puts("+-----------------------------------------------------------+");
v10 = friso_new_task();
while ( 1 )
{
printf("%s", "friso>> ");
func7(stdin);
if ( !strcasecmp((const char *)&v14, "quit") )
break;
friso_set_text();
puts(&byte_40206E);
v11 = clock();
while ( friso_next() )
printf("%s/ ", (const char *)(*(_QWORD *)(v10 + 32) + 4LL));
v12 = clock();
printf("\nDone, cost < %fsec\n", (double)(v12 - v11) / 1000000.0);
}
puts("Thanks for trying friso.");
friso_free_task();
}
else
{
printf("fail to initialize friso and config.");
}
free(v7);
friso_free();
return 0;
}

original_code:
int main(int argc, char **argv) {
    clock_t s_time, e_time;
    char line[20480] = {0};
    int i;
    fstring __path__ = ((void *)0);
    friso_t friso;
    friso_config_t config;
    friso_task_t task;
    for ( i = 0; i < argc; i++ ) {
 if ( strcasecmp( "-init", argv[i] ) == 0 ) {
     __path__ = argv[i+1];
 }
    }
    if ( __path__ == ((void *)0) ) {
 printf("%s\n", "Usage: friso -init lexicon path" );
 exit(0);
    }
    s_time = clock();
    friso = friso_new();
    config = friso_new_config();
    if ( friso_init_from_ifile(friso, config, __path__) != 1 ) {
 printf("fail to initialize friso and config.");
 goto err;
    }
    e_time = clock();
    printf("Initialized in %fsec\n", (double) ( e_time - s_time ) / ((__clock_t) 1000000) );
    printf("+-Version: %s (%s)\n", "1.6.0", friso->charset == FRISO_UTF8 ? "UTF-8" : "GBK" );
    printf("%s\n", "+-----------------------------------------------------------+" ); printf("%s\n", "| friso - a chinese word segmentation writen by c.          |" ); printf("%s\n", "| bug report email - chenxin619315@gmail.com.               |" ); printf("%s\n", "| or: visit http://code.google.com/p/friso.                 |" ); printf("%s\n", "|     java edition for http://code.google.com/p/jcseg       |" ); printf("%s\n", "| type 'quit' to exit the program.                          |" ); printf("%s\n", "+-----------------------------------------------------------+" );;
    task = friso_new_task();
    while ( 1 ) {
 printf("%s", "friso>> " );
 getLine( stdin, line );
 if ( strcasecmp( line, "quit" ) == 0 ) {
     printf("%s\n", "Thanks for trying friso." ); break;
 }
 friso_set_text( task, line );
 printf("%s\n", "分词结果:" );
 s_time = clock();
 while ( ( friso_next( friso, config, task ) ) != ((void *)0) ) {
     printf("%s/ ", task->hits->word );
 }
 e_time = clock();
 printf("\nDone, cost < %fsec\n", ( (double)(e_time - s_time) ) / ((__clock_t) 1000000) );
    }
    friso_free_task( task );
err:
    free( config );
    friso_free(friso);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    long s_time; long e_time;
    char line[20480] = {0};
    int i;
    char *__path__ = ((void *)0);
    struct friso_entry *friso;
    struct friso_config_entry *config;
    struct friso_task_entry *task;
    for ( i = 0; i < argc; i++ ) {
 if ( strcasecmp( "-init", argv[i] ) == 0 ) {
     __path__ = argv[i+1];
 }
    }
    if ( __path__ == ((void *)0) ) {
 printf("%s\n", "Usage: friso -init lexicon path" );
 exit(0);
    }
    s_time = clock();
    friso = friso_new();
    config = friso_new_config();
    if ( friso_init_from_ifile(friso, config, __path__) != 1 ) {
 printf("fail to initialize friso and config.");
 goto err;
    }
    e_time = clock();
    printf("Initialized in %fsec\n", (double) ( e_time - s_time ) / ((long) 1000000) );
    printf("+-Version: %s (%s)\n", "1.6.0", friso->charset == FRISO_UTF8 ? "UTF-8" : "GBK" );
    printf("%s\n", "+-----------------------------------------------------------+" ); printf("%s\n", "| friso - a chinese word segmentation writen by c.          |" ); printf("%s\n", "| bug report email - chenxin619315@gmail.com.               |" ); printf("%s\n", "| or: visit http://code.google.com/p/friso.                 |" ); printf("%s\n", "|     java edition for http://code.google.com/p/jcseg       |" ); printf("%s\n", "| type 'quit' to exit the program.                          |" ); printf("%s\n", "+-----------------------------------------------------------+" );;
    task = friso_new_task();
    while ( 1 ) {
 printf("%s", "friso>> " );
 getLine( stdin, line );
 if ( strcasecmp( line, "quit" ) == 0 ) {
     printf("%s\n", "Thanks for trying friso." ); break;
 }
 friso_set_text( task, line );
 printf("%s\n", "分词结果:" );
 s_time = clock();
 while ( ( friso_next( friso, config, task ) ) != ((void *)0) ) {
     printf("%s/ ", task->hits->word );
 }
 e_time = clock();
 printf("\nDone, cost < %fsec\n", ( (double)(e_time - s_time) ) / ((long) 1000000) );
    }
    friso_free_task( task );
err:
    free( config );
    friso_free(friso);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
line
char [20480]

variable_types: struct friso_entry { struct friso_hash_cdt { unsigned int length; unsigned int size; float factor; unsigned int threshold; struct hash_entry { char *_key; void *_val; struct hash_entry *_next; } **table; } **dic; enum friso_charset_t { FRISO_UTF8=0, FRISO_GBK=1 } charset; } *

variable_types: struct friso_config_entry { unsigned short max_len; unsigned short r_name; unsigned short mix_len; unsigned short lna_len; unsigned short add_syn; unsigned short clr_stw; unsigned short keep_urec; unsigned short spx_out; unsigned int nthreshold; enum friso_mode_t { __FRISO_SIMPLE_MODE__=1, __FRISO_COMPLEX_MODE__=2 } mode; } *

variable_types: struct friso_task_entry { char *text; unsigned int idx; unsigned int length; unsigned int bytes; unsigned int unicode; struct friso_link_entry { struct friso_link_node { void *value; struct friso_link_node *prev; struct friso_link_node *next; } *head; struct friso_link_node *tail; unsigned int size; } *pool; struct friso_hits_entry { int offset; char word[128]; } *hits; char buffer[7]; } *

user_defined_types: struct friso_entry { struct friso_hash_cdt **dic; enum friso_charset_t charset; }

user_defined_types: struct friso_config_entry { unsigned short max_len; unsigned short r_name; unsigned short mix_len; unsigned short lna_len; unsigned short add_syn; unsigned short clr_stw; unsigned short keep_urec; unsigned short spx_out; unsigned int nthreshold; enum friso_mode_t mode; }

user_defined_types: struct friso_task_entry { char *text; unsigned int idx; unsigned int length; unsigned int bytes; unsigned int unicode; struct friso_link_entry *pool; struct friso_hits_entry *hits; char buffer[7]; }

user_defined_types: struct friso_link_entry { struct friso_link_node *head; struct friso_link_node *tail; unsigned int size; }

user_defined_types: struct friso_hash_cdt { unsigned int length; unsigned int size; float factor; unsigned int threshold; struct hash_entry **table; }


repo: TripleChocPi/LIRC

decompiled_code:
int display_welcome()
{
printf("LIRC Server v%s starting...\n", "0.01");
puts("Developed by TripleChocPi 2013.\n");
puts("LIRC is an open-source project released under the GPL v3.");
puts("Pull requests are welcome. For more information on LIRC's");
puts("design philosophy and goals please visit our GitHub repo");
return printf("at %s\n\n", "https://github.com/TripleChocPi/LIRC/");
}

canonical_decompiled_code:
int func0()
{
printf("LIRC Server v%s starting...\n", "0.01");
puts("Developed by TripleChocPi 2013.\n");
puts("LIRC is an open-source project released under the GPL v3.");
puts("Pull requests are welcome. For more information on LIRC's");
puts("design philosophy and goals please visit our GitHub repo");
return printf("at %s\n\n", "https://github.com/TripleChocPi/LIRC/");
}

original_code:
void
display_welcome()
{
  printf("LIRC Server v%s starting...\n", "0.01");
  printf("Developed by TripleChocPi 2013.\n\n");
  printf("LIRC is an open-source project released under the GPL v3.\n");
  printf("Pull requests are welcome. For more information on LIRC's\n");
  printf("design philosophy and goals please visit our GitHub repo\n");
  printf("at %s\n\n", "https://github.com/TripleChocPi/LIRC/");
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_BYTE v3[32]; // [rsp+0h] [rbp-58h] BYREF
char v4[56]; // [rsp+20h] [rbp-38h] BYREF

display_welcome();
lirc_server_init(v4, v3);
while ( 1 )
lirc_server_main_loop(v4, v3);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_BYTE v3[32]; // [rsp+0h] [rbp-58h] BYREF
char v4[56]; // [rsp+20h] [rbp-38h] BYREF

func0();
lirc_server_init(v4, v3);
while ( 1 )
lirc_server_main_loop(v4, v3);
}

original_code:
int
main(int argc, char *argv[])
{
  LIRCServer lirc_server;
  LIRCSettings lirc_settings;
  display_welcome();
  lirc_server_init(&lirc_server, &lirc_settings);
  while (TRUE)
  {
    lirc_server_main_loop(&lirc_server, &lirc_settings);
  }
  printf ("Server is shutting down.\n");
  lirc_server_close(&lirc_server);
  lirc_settings_destroy(&lirc_settings);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  struct LIRCServer_struct lirc_server;
  struct LIRCSettings_struct lirc_settings;
  display_welcome();
  lirc_server_init(&lirc_server, &lirc_settings);
  while (TRUE)
  {
    lirc_server_main_loop(&lirc_server, &lirc_settings);
  }
  printf ("Server is shutting down.\n");
  lirc_server_close(&lirc_server);
  lirc_settings_destroy(&lirc_settings);
  return 0;
}

variable_types:
argv
char *[]

variable_types: struct LIRCServer_struct { int epoll; int l_socket; 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]; } l_socket_addr; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *client_list; struct dlist_t *channel_list; }

variable_types: struct LIRCSettings_struct { int port; char *server_name; char *motd; }

user_defined_types: struct LIRCServer_struct { int epoll; int l_socket; struct sockaddr_in l_socket_addr; struct dlist_t *client_list; struct dlist_t *channel_list; }

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

user_defined_types: struct dlist_t { struct dlnode *head; struct dlnode *foot; int list_len; int size; }


decompiled_code:
__int64 __fastcall lirc_server_bind(__int64 a1)
{
int v1; // er8
__int64 result; // rax

v1 = bind(*(_DWORD *)(a1 + 4), (const struct sockaddr *)(a1 + 8), 0x10u);
result = 0LL;
if ( v1 >= 0 )
{
make_socket_non_blocking(*(unsigned int *)(a1 + 4));
result = 1LL;
}
return result;
}

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

v1 = bind(*(_DWORD *)(a1 + 4), (const struct sockaddr *)(a1 + 8), 0x10u);
result = 0LL;
if ( v1 >= 0 )
{
make_socket_non_blocking(*(unsigned int *)(a1 + 4));
result = 1LL;
}
return result;
}

original_code:
static BOOL
lirc_server_bind(LIRCServer* server)
{
  if (bind(server->l_socket, (const struct sockaddr *)&(server->l_socket_addr),
           sizeof (server->l_socket_addr)) < 0)
    return FALSE;
  else
  {
    make_socket_non_blocking(server->l_socket);
    return TRUE;
  }
}

canonical_original_code:
static enum BOOL lirc_server_bind(struct LIRCServer_struct *server)
{
  if (bind(server->l_socket, (struct sockaddr *)&(server->l_socket_addr),
           sizeof (server->l_socket_addr)) < 0)
    return FALSE;
  else
  {
    make_socket_non_blocking(server->l_socket);
    return TRUE;
  }
}

variable_types: struct LIRCServer_struct { int epoll; int l_socket; 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]; } l_socket_addr; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *client_list; struct dlist_t *channel_list; } *

return_type: enum BOOL { FALSE=0, TRUE=1 }

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


decompiled_code:
_BOOL8 __fastcall lirc_server_init_epoll(int *a1)
{
int v2; // edi
_BOOL8 result; // rax
int v4; // edx
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v2 = epoll_create1(0);
*a1 = v2;
result = 0LL;
if ( v2 != -1 )
{
v4 = a1[1];
event.events = -2147483647;
event.data.fd = v4;
result = epoll_ctl(v2, 1, v4, &event) != -1;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int *a1)
{
int v2; // edi
_BOOL8 result; // rax
int v4; // edx
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v2 = epoll_create1(0);
*a1 = v2;
result = 0LL;
if ( v2 != -1 )
{
v4 = a1[1];
event.events = -2147483647;
event.data.fd = v4;
result = epoll_ctl(v2, 1, v4, &event) != -1;
}
return result;
}

original_code:
static BOOL
lirc_server_init_epoll(LIRCServer* server)
{
  struct epoll_event event;
  server->epoll = epoll_create1(0);
  if (server->epoll == -1)
    return FALSE;
  event.data.fd = server->l_socket;
  event.events = EPOLLIN | EPOLLET;
  return (epoll_ctl(server->epoll, 1,
                    server->l_socket, &event) != -1)
         ? TRUE : FALSE;
}

canonical_original_code:
static enum BOOL lirc_server_init_epoll(struct LIRCServer_struct *server)
{
  struct epoll_event event;
  server->epoll = epoll_create1(0);
  if (server->epoll == -1)
    return FALSE;
  event.data.fd = server->l_socket;
  event.events = EPOLLIN | EPOLLET;
  return (epoll_ctl(server->epoll, 1,
                    server->l_socket, &event) != -1)
         ? TRUE : FALSE;
}

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

user_defined_types: struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; }


original_code:
static BOOL
lirc_server_socket_init(LIRCServer* server, LIRCSettings* settings)
{
  if ((server->l_socket = socket(2, SOCK_STREAM, 0)) < 0)
    return FALSE;
  server->l_socket_addr.sin_family = 2;
  server->l_socket_addr.sin_port = htons(settings->port);
  server->l_socket_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  return TRUE;
}

canonical_original_code:
static enum BOOL lirc_server_socket_init(struct LIRCServer_struct *server, struct LIRCSettings_struct *settings)
{
  if ((server->l_socket = socket(2, SOCK_STREAM, 0)) < 0)
    return FALSE;
  server->l_socket_addr.sin_family = 2;
  server->l_socket_addr.sin_port = htons(settings->port);
  server->l_socket_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  return TRUE;
}

variable_types: struct LIRCSettings_struct { int port; char *server_name; char *motd; } *


decompiled_code:
int __fastcall lirc_server_close(__int64 a1)
{
return close(*(_DWORD *)(a1 + 4));
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
return close(*(_DWORD *)(a1 + 4));
}

original_code:
void
lirc_server_close(LIRCServer* server)
{
  close(server->l_socket);
}

canonical_original_code:
void lirc_server_close(struct LIRCServer_struct *server)
{
  close(server->l_socket);
}


decompiled_code:
int __fastcall lirc_server_init(__int64 a1, __int16 *a2)
{
__int64 v3; // rax
__int64 v4; // rsi
size_t v6; // rdx
const char *v7; // rdi
FILE *v8; // rcx

if ( !(unsigned int)lirc_init_settings(a2, "./settings.cfg") )
{
LABEL_10:
lirc_settings_destroy(a2);
exit(1);
}
printf("Settings loaded from %s.\n", "./settings.cfg");
if ( !(unsigned int)lirc_server_socket_init(a1, a2) )
{
perror("Creating the server socket failed");
lirc_settings_destroy(a2);
}
puts("Server socket created...");
if ( !(unsigned int)lirc_server_bind(a1) )
{
fwrite("LIRC could not bind to the port specified.\n", 1uLL, 0x2BuLL, stderr);
goto LABEL_10;
}
if ( !lirc_server_listen_isra_0(*(_DWORD *)(a1 + 4)) )
{
v6 = 47LL;
v7 = "LIRC could not listen on the socket specified.\n";
v8 = stderr;
goto LABEL_9;
}
if ( !lirc_server_init_epoll((int *)a1) )
{
v6 = 43LL;
v7 = "LIRC could not initiate an epoll instance.\n";
v8 = stderr;
LABEL_9:
fwrite(v7, 1uLL, v6, v8);
lirc_server_close(a1);
goto LABEL_10;
}
*(_QWORD *)(a1 + 24) = make_empty_list();
v3 = make_empty_list();
v4 = *(unsigned int *)a2;
*(_QWORD *)(a1 + 32) = v3;
return printf("Server socket bound and listening on port %d.\n", v4);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int16 *a2)
{
__int64 v3; // rax
__int64 v4; // rsi
size_t v6; // rdx
const char *v7; // rdi
FILE *v8; // rcx

if ( !(unsigned int)lirc_init_settings(a2, "./settings.cfg") )
{
LABEL_10:
lirc_settings_destroy(a2);
exit(1);
}
printf("Settings loaded from %s.\n", "./settings.cfg");
if ( !(unsigned int)func4(a1, a2) )
{
perror("Creating the server socket failed");
lirc_settings_destroy(a2);
}
puts("Server socket created...");
if ( !(unsigned int)func1(a1) )
{
fwrite("LIRC could not bind to the port specified.\n", 1uLL, 0x2BuLL, stderr);
goto LABEL_10;
}
if ( !func5(*(_DWORD *)(a1 + 4)) )
{
v6 = 47LL;
v7 = "LIRC could not listen on the socket specified.\n";
v8 = stderr;
goto LABEL_9;
}
if ( !func2((int *)a1) )
{
v6 = 43LL;
v7 = "LIRC could not initiate an epoll instance.\n";
v8 = stderr;
LABEL_9:
fwrite(v7, 1uLL, v6, v8);
func6(a1);
goto LABEL_10;
}
*(_QWORD *)(a1 + 24) = make_empty_list();
v3 = make_empty_list();
v4 = *(unsigned int *)a2;
*(_QWORD *)(a1 + 32) = v3;
return printf("Server socket bound and listening on port %d.\n", v4);
}

original_code:
void
lirc_server_init(LIRCServer* lirc_server, LIRCSettings* lirc_settings)
{
  if(!(lirc_init_settings(lirc_settings, "./settings.cfg")))
  {
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  printf("Settings loaded from %s.\n", "./settings.cfg");
  if(!(lirc_server_socket_init(lirc_server, lirc_settings)))
  {
    perror("Creating the server socket failed");
    lirc_settings_destroy(lirc_settings);
  }
  printf("Server socket created...\n");
  if(!(lirc_server_bind(lirc_server)))
  {
    fprintf(stderr, "LIRC could not bind to the port specified.\n");
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  if(!(lirc_server_listen(lirc_server)))
  {
    fprintf(stderr, "LIRC could not listen on the socket specified.\n");
    lirc_server_close(lirc_server);
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  if(!(lirc_server_init_epoll(lirc_server)))
  {
    fprintf(stderr, "LIRC could not initiate an epoll instance.\n");
    lirc_server_close(lirc_server);
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  lirc_server->client_list = make_empty_list();
  lirc_server->channel_list = make_empty_list();
  printf("Server socket bound and listening on port %d.\n",
         lirc_settings->port);
}

canonical_original_code:
void lirc_server_init(struct LIRCServer_struct *lirc_server, struct LIRCSettings_struct *lirc_settings)
{
  if(!(lirc_init_settings(lirc_settings, "./settings.cfg")))
  {
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  printf("Settings loaded from %s.\n", "./settings.cfg");
  if(!(lirc_server_socket_init(lirc_server, lirc_settings)))
  {
    perror("Creating the server socket failed");
    lirc_settings_destroy(lirc_settings);
  }
  printf("Server socket created...\n");
  if(!(lirc_server_bind(lirc_server)))
  {
    fprintf(stderr, "LIRC could not bind to the port specified.\n");
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  if(!(lirc_server_listen(lirc_server)))
  {
    fprintf(stderr, "LIRC could not listen on the socket specified.\n");
    lirc_server_close(lirc_server);
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  if(!(lirc_server_init_epoll(lirc_server)))
  {
    fprintf(stderr, "LIRC could not initiate an epoll instance.\n");
    lirc_server_close(lirc_server);
    lirc_settings_destroy(lirc_settings);
    exit(1);
  }
  lirc_server->client_list = make_empty_list();
  lirc_server->channel_list = make_empty_list();
  printf("Server socket bound and listening on port %d.\n",
         lirc_settings->port);
}

user_defined_types: struct LIRCSettings_struct { int port; char *server_name; char *motd; }


decompiled_code:
void __fastcall lirc_server_main_loop(int *a1, __int64 a2)
{
int v3; // eax
epoll_data_t *v4; // rbx
int v5; // edx
int v6; // eax
int v7; // edi
int v8; // edi
unsigned int v9; // eax
int v10; // er14
ssize_t v11; // rax
char *i; // r15
epoll_data_t *v13; // [rsp+8h] [rbp-860h]
socklen_t addr_len; // [rsp+1Ch] [rbp-84Ch] BYREF
struct epoll_event event; // [rsp+20h] [rbp-848h] BYREF
struct sockaddr addr[32]; // [rsp+30h] [rbp-838h] BYREF
struct epoll_event events[132]; // [rsp+230h] [rbp-638h] BYREF

memset(events, 0, 0x600uLL);
v3 = epoll_wait(*a1, events, 128, -1);
if ( v3 > 0 )
{
v4 = &events[0].data;
v13 = &events[(unsigned int)(v3 - 1) + 1].data;
while ( 1 )
{
v5 = HIDWORD(v4[-1].u64);
v6 = v4->fd;
v7 = a1[1];
if ( (v5 & 0x18) == 0 && (v5 & 1) != 0 )
break;
if ( v7 == v6 )
goto LABEL_8;
fwrite("Error on a client's socket. Connection closed.", 1uLL, 0x2EuLL, stderr);
close(v4->fd);
LABEL_11:
v4 = (epoll_data_t *)((char *)v4 + 12);
if ( v4 == v13 )
return;
}
if ( v7 != v6 )
{
while ( 1 )
{
memset(addr, 0, sizeof(addr));
v11 = read(v4->fd, addr, 0x200uLL);
if ( v11 == -1 )
break;
if ( !v11 )
goto LABEL_22;
for ( i = strtok_r((char *)addr, "\r\n", (char **)&event); i; i = strtok_r(0LL, "\r\n", (char **)&event) )
{
printf("Message recieved: %s\n", i);
lirc_client_parse(a1, a2, v4->u32, i);
}
}
if ( *_errno_location() == 11 )
goto LABEL_11;
perror("Read error");
LABEL_22:
puts("Disconnected a client.");
close(v4->fd);
goto LABEL_11;
}
LABEL_8:
while ( 1 )
{
addr_len = 16;
v9 = accept(v7, addr, &addr_len);
v10 = v9;
if ( v9 == -1 )
break;
make_socket_non_blocking(v9);
v8 = *a1;
event.data.fd = v10;
event.events = -2147483647;
if ( epoll_ctl(v8, 1, v10, &event) == -1 )
{
perror("epoll_ctl add client error");
lirc_server_close((__int64)a1);
lirc_settings_destroy(a2);
exit(1);
}
puts("Client connected.");
v7 = a1[1];
}
if ( *_errno_location() != 11 )
perror("Error accepting connection");
goto LABEL_11;
}
}

canonical_decompiled_code:
void __fastcall func8(int *a1, __int64 a2)
{
int v3; // eax
epoll_data_t *v4; // rbx
int v5; // edx
int v6; // eax
int v7; // edi
int v8; // edi
unsigned int v9; // eax
int v10; // er14
ssize_t v11; // rax
char *i; // r15
epoll_data_t *v13; // [rsp+8h] [rbp-860h]
socklen_t addr_len; // [rsp+1Ch] [rbp-84Ch] BYREF
struct epoll_event event; // [rsp+20h] [rbp-848h] BYREF
struct sockaddr addr[32]; // [rsp+30h] [rbp-838h] BYREF
struct epoll_event events[132]; // [rsp+230h] [rbp-638h] BYREF

memset(events, 0, 0x600uLL);
v3 = epoll_wait(*a1, events, 128, -1);
if ( v3 > 0 )
{
v4 = &events[0].data;
v13 = &events[(unsigned int)(v3 - 1) + 1].data;
while ( 1 )
{
v5 = HIDWORD(v4[-1].u64);
v6 = v4->fd;
v7 = a1[1];
if ( (v5 & 0x18) == 0 && (v5 & 1) != 0 )
break;
if ( v7 == v6 )
goto LABEL_8;
fwrite("Error on a client's socket. Connection closed.", 1uLL, 0x2EuLL, stderr);
close(v4->fd);
LABEL_11:
v4 = (epoll_data_t *)((char *)v4 + 12);
if ( v4 == v13 )
return;
}
if ( v7 != v6 )
{
while ( 1 )
{
memset(addr, 0, sizeof(addr));
v11 = read(v4->fd, addr, 0x200uLL);
if ( v11 == -1 )
break;
if ( !v11 )
goto LABEL_22;
for ( i = strtok_r((char *)addr, "\r\n", (char **)&event); i; i = strtok_r(0LL, "\r\n", (char **)&event) )
{
printf("Message recieved: %s\n", i);
lirc_client_parse(a1, a2, v4->u32, i);
}
}
if ( *_errno_location() == 11 )
goto LABEL_11;
perror("Read error");
LABEL_22:
puts("Disconnected a client.");
close(v4->fd);
goto LABEL_11;
}
LABEL_8:
while ( 1 )
{
addr_len = 16;
v9 = accept(v7, addr, &addr_len);
v10 = v9;
if ( v9 == -1 )
break;
make_socket_non_blocking(v9);
v8 = *a1;
event.data.fd = v10;
event.events = -2147483647;
if ( epoll_ctl(v8, 1, v10, &event) == -1 )
{
perror("epoll_ctl add client error");
func6((__int64)a1);
lirc_settings_destroy(a2);
exit(1);
}
puts("Client connected.");
v7 = a1[1];
}
if ( *_errno_location() != 11 )
perror("Error accepting connection");
goto LABEL_11;
}
}

original_code:
void
lirc_server_main_loop(LIRCServer* server, LIRCSettings* settings)
{
  int i, event_count;
  struct epoll_event events[128];
  memset(events, '\0', sizeof (struct epoll_event) * 128);
  event_count = epoll_wait(server->epoll, events, 128, -1);
  for (i = 0; i < event_count; i++)
  {
    if ((
          (events[i].events & EPOLLERR) ||
          (events[i].events & EPOLLHUP) ||
          (!(events[i].events & EPOLLIN))
        )
        && (events[i].data.fd != server->l_socket))
    {
      fprintf(stderr, "Error on a client's socket. Connection closed.");
      close(events[i].data.fd);
      continue;
    }
    else if (events[i].data.fd == server->l_socket)
    {
      while (TRUE)
      {
        struct epoll_event event;
        struct sockaddr in_addr;
        socklen_t in_len;
        int socket;
        in_len = sizeof (in_addr);
        socket = accept(server->l_socket, &in_addr, &in_len);
        if (socket == -1)
        {
          if (((*__errno_location ()) != 11) && ((*__errno_location ()) != 11))
            perror ("Error accepting connection");
          break;
        }
        make_socket_non_blocking(socket);
        event.data.fd = socket;
        event.events = EPOLLIN | EPOLLET;
        if ((epoll_ctl(server->epoll, 1, socket, &event)) == -1)
        {
          perror("epoll_ctl add client error");
          lirc_server_close(server);
          lirc_settings_destroy(settings);
          exit(1);
        }
        printf("Client connected.\n");
      }
    }
    else
    {
      BOOL disconnect = FALSE;
      while (TRUE)
      {
        ssize_t count;
        char buffer[512];
        char* saveptr;
        char* command;
        memset(buffer, '\0', sizeof(char) * 512);
        count = read(events[i].data.fd, buffer, sizeof(buffer));
        if (count == -1)
        {
          if ((*__errno_location ()) != 11)
          {
            perror("Read error");
            disconnect = TRUE;
          }
          break;
        }
        else if (count == 0)
        {
          disconnect = TRUE;
          break;
        }
        command = strtok_r(buffer, "\r\n", &saveptr);
        while (command)
        {
          printf("Message recieved: %s\n", command);
          lirc_client_parse(server, settings, events[i].data.fd, command);
          command = strtok_r(((void *)0), "\r\n", &saveptr);
        }
      }
      if (disconnect)
      {
        printf("Disconnected a client.\n");
        close(events[i].data.fd);
      }
    }
  }
}

canonical_original_code:
void lirc_server_main_loop(struct LIRCServer_struct *server, struct LIRCSettings_struct *settings)
{
  int i; int event_count;
  struct epoll_event events[128];
  memset(events, '\0', sizeof (struct epoll_event) * 128);
  event_count = epoll_wait(server->epoll, events, 128, -1);
  for (i = 0; i < event_count; i++)
  {
    if ((
          (events[i].events & EPOLLERR) ||
          (events[i].events & EPOLLHUP) ||
          (!(events[i].events & EPOLLIN))
        )
        && (events[i].data.fd != server->l_socket))
    {
      fprintf(stderr, "Error on a client's socket. Connection closed.");
      close(events[i].data.fd);
      continue;
    }
    else if (events[i].data.fd == server->l_socket)
    {
      while (TRUE)
      {
        struct epoll_event event;
        struct sockaddr in_addr;
        unsigned int in_len;
        int socket;
        in_len = sizeof (in_addr);
        socket = accept(server->l_socket, &in_addr, &in_len);
        if (socket == -1)
        {
          if (((*__errno_location ()) != 11) && ((*__errno_location ()) != 11))
            perror ("Error accepting connection");
          break;
        }
        make_socket_non_blocking(socket);
        event.data.fd = socket;
        event.events = EPOLLIN | EPOLLET;
        if ((epoll_ctl(server->epoll, 1, socket, &event)) == -1)
        {
          perror("epoll_ctl add client error");
          lirc_server_close(server);
          lirc_settings_destroy(settings);
          exit(1);
        }
        printf("Client connected.\n");
      }
    }
    else
    {
      enum BOOL disconnect = FALSE;
      while (TRUE)
      {
        long count;
        char buffer[512];
        char *saveptr;
        char *command;
        memset(buffer, '\0', sizeof(char) * 512);
        count = read(events[i].data.fd, buffer, sizeof(buffer));
        if (count == -1)
        {
          if ((*__errno_location ()) != 11)
          {
            perror("Read error");
            disconnect = TRUE;
          }
          break;
        }
        else if (count == 0)
        {
          disconnect = TRUE;
          break;
        }
        command = strtok_r(buffer, "\r\n", &saveptr);
        while (command)
        {
          printf("Message recieved: %s\n", command);
          lirc_client_parse(server, settings, events[i].data.fd, command);
          command = strtok_r(((void *)0), "\r\n", &saveptr);
        }
      }
      if (disconnect)
      {
        printf("Disconnected a client.\n");
        close(events[i].data.fd);
      }
    }
  }
}

variable_types: i int

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } [128]

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

variable_types: socket int

variable_types:
disconnect
enum BOOL { FALSE=0, TRUE=1 }

variable_types: count long

variable_types:
buffer
char [512]

variable_types:
saveptr
char *

variable_types:
command
char *


decompiled_code:
int __fastcall lirc_channel_cmp(const char **a1, const char *a2)
{
return strcmp(*a1, a2);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, const char *a2)
{
return strcmp(*a1, a2);
}

original_code:
static int lirc_channel_cmp(const void *channel, const void *c_str)
{
  LIRCChannelData* chan = (LIRCChannelData*)channel;
  char *c = (char *)c_str;
  return strcmp(chan->name, c);
}

canonical_original_code:
static int lirc_channel_cmp(void *channel, void *c_str)
{
  struct LIRCChannelData_struct *chan = (LIRCChannelData*)channel;
  char *c = (char *)c_str;
  return strcmp(chan->name, c);
}

variable_types:
channel
void *

variable_types: struct LIRCChannelData_struct { char *name; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *client_list; } *

variable_types:
c
char *

user_defined_types: struct LIRCChannelData_struct { char *name; struct dlist_t *client_list; }


decompiled_code:
_QWORD *lirc_channel_new_metadata()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = (_QWORD *)safe_malloc(16LL);
*v0 = 0LL;
v1 = v0;
v0[1] = make_empty_list();
return v1;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = (_QWORD *)safe_malloc(16LL);
*v0 = 0LL;
v1 = v0;
v0[1] = make_empty_list();
return v1;
}

original_code:
static LIRCChannelData* lirc_channel_new_metadata()
{
  LIRCChannelData* channel = safe_malloc(sizeof(LIRCChannelData));
  channel->name = ((void *)0);
  channel->client_list = make_empty_list();
  return channel;
}

canonical_original_code:
static struct LIRCChannelData_struct *lirc_channel_new_metadata()
{
  struct LIRCChannelData_struct *channel = safe_malloc(sizeof(LIRCChannelData));
  channel->name = ((void *)0);
  channel->client_list = make_empty_list();
  return channel;
}

return_type: struct LIRCChannelData_struct { char *name; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *client_list; } *


decompiled_code:
int __fastcall lirc_channel_join(__int64 a1, __int64 a2, const char *a3)
{
_QWORD *v4; // rbx
__int64 v5; // rbx
int result; // eax
size_t v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
char v10[552]; // [rsp+0h] [rbp-228h] BYREF

v4 = (_QWORD *)find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
if ( !v4 )
{
v4 = lirc_channel_new_metadata();
v8 = safe_strdup(a3);
v9 = *(_QWORD *)(a1 + 32);
*v4 = v8;
insert_at_front(v9, v4, 8LL);
}
insert_at_front(v4[1], a2, 8LL);
insert_at_front(*(_QWORD *)(a2 + 24), v4, 8LL);
v5 = *(_QWORD *)v4[1];
for ( result = sprintf(v10, ":%s!~%s@anon.com JOIN %s\r\n", *(const char **)(a2 + 8), *(const char **)(a2 + 16), a3);
v5;
v5 = *(_QWORD *)(v5 + 16) )
{
v7 = strlen(v10);
result = send(**(_DWORD **)(v5 + 8), v10, v7, 0);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2, const char *a3)
{
_QWORD *v4; // rbx
__int64 v5; // rbx
int result; // eax
size_t v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
char v10[552]; // [rsp+0h] [rbp-228h] BYREF

v4 = (_QWORD *)find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
if ( !v4 )
{
v4 = func2();
v8 = safe_strdup(a3);
v9 = *(_QWORD *)(a1 + 32);
*v4 = v8;
insert_at_front(v9, v4, 8LL);
}
insert_at_front(v4[1], a2, 8LL);
insert_at_front(*(_QWORD *)(a2 + 24), v4, 8LL);
v5 = *(_QWORD *)v4[1];
for ( result = sprintf(v10, ":%s!~%s@anon.com JOIN %s\r\n", *(const char **)(a2 + 8), *(const char **)(a2 + 16), a3);
v5;
v5 = *(_QWORD *)(v5 + 16) )
{
v7 = strlen(v10);
result = send(**(_DWORD **)(v5 + 8), v10, v7, 0);
}
return result;
}

original_code:
void lirc_channel_join(struct LIRCServer_struct* server,
                       struct LIRCClientData_struct* client,
                       char *channel)
{
  char temp[512];
  dlnode_t* client_node;
  LIRCChannelData* c =
    (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  if (c == ((void *)0))
  {
    c = lirc_channel_new_metadata();
    c->name = safe_strdup(channel);
    insert_at_front(server->channel_list, c, sizeof(c));
  }
  insert_at_front(c->client_list, client,
                  sizeof(client));
  insert_at_front(client->channel_list, c, sizeof(c));
  client_node = c->client_list->head;
  sprintf(temp, ":%s!~%s@anon.com JOIN %s\r\n", client->nick, client->user,
          channel);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct *client_node_data =
      (struct LIRCClientData_struct *)client_node->data;
    send(client_node_data->socket, temp, strlen(temp), 0);
    client_node = client_node->next;
  }
}

canonical_original_code:
void lirc_channel_join(struct LIRCServer_struct *server, struct LIRCClientData_struct *client, char *channel)
{
  char temp[512];
  struct dlnode *client_node;
  struct LIRCChannelData_struct *c = (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  if (c == ((void *)0))
  {
    c = lirc_channel_new_metadata();
    c->name = safe_strdup(channel);
    insert_at_front(server->channel_list, c, sizeof(c));
  }
  insert_at_front(c->client_list, client,
                  sizeof(client));
  insert_at_front(client->channel_list, c, sizeof(c));
  client_node = c->client_list->head;
  sprintf(temp, ":%s!~%s@anon.com JOIN %s\r\n", client->nick, client->user,
          channel);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct *client_node_data = (struct LIRCClientData_struct *)client_node->data;
    send(client_node_data->socket, temp, strlen(temp), 0);
    client_node = client_node->next;
  }
}

variable_types: struct LIRCClientData_struct { int socket; char *nick; struct dlist_t *channel_list; } *

variable_types:
channel
char *

variable_types:
temp
char [512]

variable_types: struct LIRCClientData_struct { int socket; char *nick; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *channel_list; } *


decompiled_code:
ssize_t __fastcall lirc_channel_who(__int64 a1, __int64 a2, const char *a3)
{
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rbx
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
char dest[552]; // [rsp+0h] [rbp+0h] BYREF

v4 = find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
v5 = *(_QWORD *)(a2 + 8);
v6 = **(_QWORD **)(v4 + 8);
memset(dest, 0, 0x200uLL);
sprintf(dest, ":lirc.org 353 %s = %s :", v5, a3);
for ( ; v6; v6 = *(_QWORD *)(v6 + 16) )
{
v7 = strlen(dest);
*(_WORD *)stpcpy(&dest[v7], *(const char **)(*(_QWORD *)(v6 + 8) + 8LL)) = 32;
}
v8 = strlen(dest);
strcpy(&dest[v8], "\r\n");
send(*(_DWORD *)a2, dest, v8 + 2, 0);
memset(dest, 0, 0x200uLL);
sprintf(dest, ":lirc.org 366 %s %s :End of /NAMES list\r\n", *(const char **)(a2 + 8), a3);
v9 = strlen(dest);
return send(*(_DWORD *)a2, dest, v9, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func4(__int64 a1, __int64 a2, const char *a3)
{
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rbx
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
char dest[552]; // [rsp+0h] [rbp+0h] BYREF

v4 = find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
v5 = *(_QWORD *)(a2 + 8);
v6 = **(_QWORD **)(v4 + 8);
memset(dest, 0, 0x200uLL);
sprintf(dest, ":lirc.org 353 %s = %s :", v5, a3);
for ( ; v6; v6 = *(_QWORD *)(v6 + 16) )
{
v7 = strlen(dest);
*(_WORD *)stpcpy(&dest[v7], *(const char **)(*(_QWORD *)(v6 + 8) + 8LL)) = 32;
}
v8 = strlen(dest);
strcpy(&dest[v8], "\r\n");
send(*(_DWORD *)a2, dest, v8 + 2, 0);
memset(dest, 0, 0x200uLL);
sprintf(dest, ":lirc.org 366 %s %s :End of /NAMES list\r\n", *(const char **)(a2 + 8), a3);
v9 = strlen(dest);
return send(*(_DWORD *)a2, dest, v9, 0);
}

original_code:
void lirc_channel_who(struct LIRCServer_struct* server,
                        struct LIRCClientData_struct* client,
                        char *channel)
{
  int size = 0;
  char temp[512];
  LIRCChannelData* c;
  dlnode_t* client_node;
  c = (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  client_node = c->client_list->head;
  memset(temp, '\0', sizeof (char) * 512);
  sprintf(temp, ":lirc.org 353 %s = %s :", client->nick, channel);
  size += strlen(temp);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct* chan_client =
      ((struct LIRCClientData_struct*)(client_node->data));
    strcat(temp, chan_client->nick);
    strcat(temp, " ");
    client_node = client_node->next;
  }
  strcat(temp, "\r\n");
  send(client->socket, temp, strlen(temp), 0);
  memset(temp, '\0', sizeof (char) * 512);
  sprintf(temp, ":lirc.org 366 %s %s :End of /NAMES list\r\n",
          client->nick, channel);
  send(client->socket, temp, strlen(temp), 0);
}

canonical_original_code:
void lirc_channel_who(struct LIRCServer_struct *server, struct LIRCClientData_struct *client, char *channel)
{
  int size = 0;
  char temp[512];
  struct LIRCChannelData_struct *c;
  struct dlnode *client_node;
  c = (struct LIRCChannelData_struct *)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  client_node = c->client_list->head;
  memset(temp, '\0', sizeof (char) * 512);
  sprintf(temp, ":lirc.org 353 %s = %s :", client->nick, channel);
  size += strlen(temp);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct *chan_client = ((struct LIRCClientData_struct*)(client_node->data));
    strcat(temp, chan_client->nick);
    strcat(temp, " ");
    client_node = client_node->next;
  }
  strcat(temp, "\r\n");
  send(client->socket, temp, strlen(temp), 0);
  memset(temp, '\0', sizeof (char) * 512);
  sprintf(temp, ":lirc.org 366 %s %s :End of /NAMES list\r\n",
          client->nick, channel);
  send(client->socket, temp, strlen(temp), 0);
}

variable_types: struct LIRCServer_struct { int epoll; int l_socket; 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]; } l_socket_addr; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *client_list; struct dlist_t *channel_list; } *

variable_types: size int

user_defined_types: struct LIRCClientData_struct { int socket; char *nick; struct dlist_t *channel_list; }


decompiled_code:
int __fastcall lirc_channel_message(__int64 a1, __int64 a2, const char *a3, const char *a4)
{
__int64 v6; // rax
__int64 v7; // rbx
int *v8; // rbp
size_t v9; // rax
char v11[552]; // [rsp+0h] [rbp-228h] BYREF

v6 = find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
if ( v6 )
{
v7 = **(_QWORD **)(v6 + 8);
LODWORD(v6) = sprintf(
v11,
":%s!~%s@anon.com PRIVMSG %s %s\r\n",
*(const char **)(a2 + 8),
*(const char **)(a2 + 16),
a3,
a4);
while ( v7 )
{
v8 = *(int **)(v7 + 8);
if ( (int *)a2 != v8 )
{
v9 = strlen(v11);
LODWORD(v6) = send(*v8, v11, v9, 0);
}
v7 = *(_QWORD *)(v7 + 16);
}
}
return v6;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2, const char *a3, const char *a4)
{
__int64 v6; // rax
__int64 v7; // rbx
int *v8; // rbp
size_t v9; // rax
char v11[552]; // [rsp+0h] [rbp-228h] BYREF

v6 = find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
if ( v6 )
{
v7 = **(_QWORD **)(v6 + 8);
LODWORD(v6) = sprintf(
v11,
":%s!~%s@anon.com PRIVMSG %s %s\r\n",
*(const char **)(a2 + 8),
*(const char **)(a2 + 16),
a3,
a4);
while ( v7 )
{
v8 = *(int **)(v7 + 8);
if ( (int *)a2 != v8 )
{
v9 = strlen(v11);
LODWORD(v6) = send(*v8, v11, v9, 0);
}
v7 = *(_QWORD *)(v7 + 16);
}
}
return v6;
}

original_code:
void lirc_channel_message(struct LIRCServer_struct* server,
                        struct LIRCClientData_struct* client,
                        char *channel, char *message)
{
  char temp[512];
  dlnode_t* client_node;
  LIRCChannelData* c =
    (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  if (c == ((void *)0))
  {
    return;
  }
  client_node = c->client_list->head;
  sprintf(temp, ":%s!~%s@anon.com PRIVMSG %s %s\r\n",
          client->nick, client->user, channel, message);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct *client_node_data =
      (struct LIRCClientData_struct *)client_node->data;
    if (client_node_data == client)
    {
      client_node = client_node->next;
      continue;
    }
    send(client_node_data->socket, temp, strlen(temp), 0);
    client_node = client_node->next;
  }
}

canonical_original_code:
void lirc_channel_message(struct LIRCServer_struct *server, struct LIRCClientData_struct *client, char *channel, char *message)
{
  char temp[512];
  struct dlnode *client_node;
  struct LIRCChannelData_struct *c = (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  if (c == ((void *)0))
  {
    return;
  }
  client_node = c->client_list->head;
  sprintf(temp, ":%s!~%s@anon.com PRIVMSG %s %s\r\n",
          client->nick, client->user, channel, message);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct *client_node_data = (struct LIRCClientData_struct *)client_node->data;
    if (client_node_data == client)
    {
      client_node = client_node->next;
      continue;
    }
    send(client_node_data->socket, temp, strlen(temp), 0);
    client_node = client_node->next;
  }
}

variable_types:
message
char *

variable_types: struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *


decompiled_code:
ssize_t __fastcall lirc_channel_leave(__int64 a1, __int64 a2, const char *a3)
{
ssize_t result; // rax
ssize_t v5; // rbx
__int64 v6; // rbx
size_t v7; // rax
size_t v8; // rax
char v9[536]; // [rsp+0h] [rbp-218h] BYREF

result = find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
if ( result )
{
v5 = result;
remove_element(*(_QWORD *)(a2 + 24), result, lirc_channel_cmp);
remove_element(*(_QWORD *)(v5 + 8), a2, lirc_client_cmp);
v6 = **(_QWORD **)(v5 + 8);
sprintf(v9, ":%s!~%s@anon.com PART %s\r\n", *(const char **)(a2 + 8), *(const char **)(a2 + 16), a3);
for ( ; v6; v6 = *(_QWORD *)(v6 + 16) )
{
v7 = strlen(v9);
send(**(_DWORD **)(v6 + 8), v9, v7, 0);
}
v8 = strlen(v9);
result = send(*(_DWORD *)a2, v9, v8, 0);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func6(__int64 a1, __int64 a2, const char *a3)
{
ssize_t result; // rax
ssize_t v5; // rbx
__int64 v6; // rbx
size_t v7; // rax
size_t v8; // rax
char v9[536]; // [rsp+0h] [rbp-218h] BYREF

result = find_element(*(_QWORD *)(a1 + 32), a3, lirc_channel_cmp);
if ( result )
{
v5 = result;
remove_element(*(_QWORD *)(a2 + 24), result, lirc_channel_cmp);
remove_element(*(_QWORD *)(v5 + 8), a2, lirc_client_cmp);
v6 = **(_QWORD **)(v5 + 8);
sprintf(v9, ":%s!~%s@anon.com PART %s\r\n", *(const char **)(a2 + 8), *(const char **)(a2 + 16), a3);
for ( ; v6; v6 = *(_QWORD *)(v6 + 16) )
{
v7 = strlen(v9);
send(**(_DWORD **)(v6 + 8), v9, v7, 0);
}
v8 = strlen(v9);
result = send(*(_DWORD *)a2, v9, v8, 0);
}
return result;
}

original_code:
void lirc_channel_leave(struct LIRCServer_struct* server,
                        struct LIRCClientData_struct* client,
                        char *channel)
{
  char temp[512];
  dlnode_t* client_node;
  LIRCChannelData* c =
    (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  if (c == ((void *)0))
  {
    return;
  }
  remove_element(client->channel_list, c, lirc_channel_cmp);
  remove_element(c->client_list, client, lirc_client_cmp);
  client_node = c->client_list->head;
  sprintf(temp, ":%s!~%s@anon.com PART %s\r\n", client->nick, client->user,
          channel);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct *client_node_data =
      (struct LIRCClientData_struct *)client_node->data;
    send(client_node_data->socket, temp, strlen(temp), 0);
    client_node = client_node->next;
  }
  send(client->socket, temp, strlen(temp), 0);
}

canonical_original_code:
void lirc_channel_leave(struct LIRCServer_struct *server, struct LIRCClientData_struct *client, char *channel)
{
  char temp[512];
  struct dlnode *client_node;
  struct LIRCChannelData_struct *c = (LIRCChannelData*)find_element(server->channel_list,
                                   channel, lirc_channel_cmp);
  if (c == ((void *)0))
  {
    return;
  }
  remove_element(client->channel_list, c, lirc_channel_cmp);
  remove_element(c->client_list, client, lirc_client_cmp);
  client_node = c->client_list->head;
  sprintf(temp, ":%s!~%s@anon.com PART %s\r\n", client->nick, client->user,
          channel);
  while (client_node != ((void *)0))
  {
    struct LIRCClientData_struct *client_node_data = (struct LIRCClientData_struct *)client_node->data;
    send(client_node_data->socket, temp, strlen(temp), 0);
    client_node = client_node->next;
  }
  send(client->socket, temp, strlen(temp), 0);
}


decompiled_code:
__int64 __fastcall lirc_client_cmp(__int64 a1, __int64 a2)
{
return (unsigned int)-(a2 != a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return (unsigned int)-(a2 != a1);
}

original_code:
static int lirc_client_cmp(const void *client1, const void *client2)
{
  return (client1 == client2) ? 0 : -1;
}

canonical_original_code:
static int lirc_client_cmp(void *client1, void *client2)
{
  return (client1 == client2) ? 0 : -1;
}


decompiled_code:
__int64 lirc_client_new_metadata()
{
__int64 v0; // rax
__int64 v1; // r12

v0 = safe_malloc(32LL);
*(_DWORD *)v0 = 0;
v1 = v0;
*(_QWORD *)(v0 + 8) = 0LL;
*(_QWORD *)(v0 + 16) = "anon";
*(_QWORD *)(v0 + 24) = make_empty_list();
return v1;
}

original_code:
static LIRCClientData* lirc_client_new_metadata()
{
  LIRCClientData* client = safe_malloc(sizeof(LIRCClientData));
  client->socket = 0;
  client->nick = ((void *)0);
  client->user = "anon";
  client->channel_list = make_empty_list();
  return client;
}

canonical_original_code:
static struct LIRCClientData_struct *lirc_client_new_metadata()
{
  struct LIRCClientData_struct *client = safe_malloc(sizeof(LIRCClientData));
  client->socket = 0;
  client->nick = ((void *)0);
  client->user = "anon";
  client->channel_list = make_empty_list();
  return client;
}

return_type: struct LIRCClientData_struct { int socket; char *nick; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *channel_list; } *


decompiled_code:
int __fastcall lirc_client_connect(__int64 a1, __int64 a2, int a3, const char *a4)
{
int *v6; // rax
int *v7; // r12
__int64 v8; // rax
__int64 v9; // rdi
size_t v10; // rax
size_t v11; // rax
size_t v12; // rax
time_t v13; // rax
size_t v14; // rax
size_t v15; // rax
char v17[552]; // [rsp+0h] [rbp-228h] BYREF

v6 = (int *)lirc_client_new_metadata();
*v6 = a3;
v7 = v6;
v8 = safe_strdup(a4);
v9 = *(_QWORD *)(a1 + 24);
*((_QWORD *)v7 + 1) = v8;
insert_at_front(v9, v7, 8LL);
sprintf(v17, ":lirc.org 001 %s :Welcome to %s\r\n", a4, *(const char **)(a2 + 8));
v10 = strlen(v17);
send(a3, v17, v10, 0);
sprintf(v17, ":lirc.org 372 %s :%s\r\n", a4, *(const char **)(a2 + 16));
v11 = strlen(v17);
send(a3, v17, v11, 0);
sprintf(v17, ":lirc.org 376 %s :%s\r\n", a4, "End of /MOTD command.");
v12 = strlen(v17);
send(a3, v17, v12, 0);
v13 = time(0LL);
sprintf(v17, "PING :%d\r\n", v13);
v14 = strlen(v17);
send(a3, v17, v14, 0);
sprintf(v17, ":lirc.org 221 %s +i\r\n", a4);
v15 = strlen(v17);
send(a3, v17, v15, 0);
return sprintf(v17, ":%s!~%s@anon.com MODE %s +i\r\n", *((const char **)v7 + 1), *((const char **)v7 + 2), a4);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2, int a3, const char *a4)
{
int *v6; // rax
int *v7; // r12
__int64 v8; // rax
__int64 v9; // rdi
size_t v10; // rax
size_t v11; // rax
size_t v12; // rax
time_t v13; // rax
size_t v14; // rax
size_t v15; // rax
char v17[552]; // [rsp+0h] [rbp-228h] BYREF

v6 = (int *)func1();
*v6 = a3;
v7 = v6;
v8 = safe_strdup(a4);
v9 = *(_QWORD *)(a1 + 24);
*((_QWORD *)v7 + 1) = v8;
insert_at_front(v9, v7, 8LL);
sprintf(v17, ":lirc.org 001 %s :Welcome to %s\r\n", a4, *(const char **)(a2 + 8));
v10 = strlen(v17);
send(a3, v17, v10, 0);
sprintf(v17, ":lirc.org 372 %s :%s\r\n", a4, *(const char **)(a2 + 16));
v11 = strlen(v17);
send(a3, v17, v11, 0);
sprintf(v17, ":lirc.org 376 %s :%s\r\n", a4, "End of /MOTD command.");
v12 = strlen(v17);
send(a3, v17, v12, 0);
v13 = time(0LL);
sprintf(v17, "PING :%d\r\n", v13);
v14 = strlen(v17);
send(a3, v17, v14, 0);
sprintf(v17, ":lirc.org 221 %s +i\r\n", a4);
v15 = strlen(v17);
send(a3, v17, v15, 0);
return sprintf(v17, ":%s!~%s@anon.com MODE %s +i\r\n", *((const char **)v7 + 1), *((const char **)v7 + 2), a4);
}

original_code:
void lirc_client_connect(struct LIRCServer_struct* server,
                         LIRCSettings* settings, int socket,
                         char* nick)
{
  char temp[512];
  LIRCClientData* client = lirc_client_new_metadata();
  client->socket = socket;
  client->nick = safe_strdup(nick);
  insert_at_front(server->client_list, client, sizeof(client));
  sprintf(temp, ":lirc.org 001 %s :Welcome to %s\r\n", nick,
          settings->server_name);
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":lirc.org 372 %s :%s\r\n", nick, settings->motd);
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":lirc.org 376 %s :%s\r\n", nick, "End of /MOTD command.");
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, "PING :%d\r\n", (int)time(((void *)0)));
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":lirc.org 221 %s +i\r\n", nick);
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":%s!~%s@anon.com MODE %s +i\r\n", client->nick,
          client->user, nick);
}

canonical_original_code:
void lirc_client_connect(struct LIRCServer_struct *server, struct LIRCSettings_struct *settings, int socket, char *nick)
{
  char temp[512];
  struct LIRCClientData_struct *client = lirc_client_new_metadata();
  client->socket = socket;
  client->nick = safe_strdup(nick);
  insert_at_front(server->client_list, client, sizeof(client));
  sprintf(temp, ":lirc.org 001 %s :Welcome to %s\r\n", nick,
          settings->server_name);
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":lirc.org 372 %s :%s\r\n", nick, settings->motd);
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":lirc.org 376 %s :%s\r\n", nick, "End of /MOTD command.");
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, "PING :%d\r\n", (int)time(((void *)0)));
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":lirc.org 221 %s +i\r\n", nick);
  send(socket, temp, strlen(temp), 0);
  sprintf(temp, ":%s!~%s@anon.com MODE %s +i\r\n", client->nick,
          client->user, nick);
}

variable_types: struct LIRCSettings_struct { int port; char *server_name; char *motd; } *

variable_types: socket int

variable_types:
nick
char *


decompiled_code:
ssize_t __fastcall lirc_client_setnick(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rdi
ssize_t result; // rax
const char *v6; // rdx
ssize_t v7; // rbx
const char *v8; // rax
size_t v9; // rax
size_t v10; // rax
__int64 i; // rbp
__int64 j; // rbx
size_t v13; // rax
int fd; // [rsp+Ch] [rbp-21Ch] BYREF
char s[536]; // [rsp+10h] [rbp-218h] BYREF

v4 = *(_QWORD *)(a1 + 24);
fd = a2;
result = find_element(v4, &fd, lirc_client_cmp);
if ( result )
{
v6 = *(const char **)(result + 8);
v7 = result;
if ( v6 )
{
sprintf(s, ":%s!~%s@anon.com NICK :", v6, *(const char **)(result + 16));
printf("Nickname changed from %s ", *(const char **)(v7 + 8));
free(*(void **)(v7 + 8));
v8 = (const char *)safe_strdup(a3);
*(_QWORD *)(v7 + 8) = v8;
printf("to %s.\n", v8);
v9 = strlen(s);
sprintf(&s[v9], "%s\r\n", *(const char **)(v7 + 8));
v10 = strlen(s);
send(fd, s, v10, 0);
result = *(_QWORD *)(v7 + 24);
for ( i = *(_QWORD *)result; i; i = *(_QWORD *)(i + 16) )
{
result = *(_QWORD *)(*(_QWORD *)(i + 8) + 8LL);
for ( j = *(_QWORD *)result; j; j = *(_QWORD *)(j + 16) )
{
v13 = strlen(s);
result = send(**(_DWORD **)(j + 8), s, v13, 0);
}
}
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rdi
ssize_t result; // rax
const char *v6; // rdx
ssize_t v7; // rbx
const char *v8; // rax
size_t v9; // rax
size_t v10; // rax
__int64 i; // rbp
__int64 j; // rbx
size_t v13; // rax
int fd; // [rsp+Ch] [rbp-21Ch] BYREF
char s[536]; // [rsp+10h] [rbp-218h] BYREF

v4 = *(_QWORD *)(a1 + 24);
fd = a2;
result = find_element(v4, &fd, lirc_client_cmp);
if ( result )
{
v6 = *(const char **)(result + 8);
v7 = result;
if ( v6 )
{
sprintf(s, ":%s!~%s@anon.com NICK :", v6, *(const char **)(result + 16));
printf("Nickname changed from %s ", *(const char **)(v7 + 8));
free(*(void **)(v7 + 8));
v8 = (const char *)safe_strdup(a3);
*(_QWORD *)(v7 + 8) = v8;
printf("to %s.\n", v8);
v9 = strlen(s);
sprintf(&s[v9], "%s\r\n", *(const char **)(v7 + 8));
v10 = strlen(s);
send(fd, s, v10, 0);
result = *(_QWORD *)(v7 + 24);
for ( i = *(_QWORD *)result; i; i = *(_QWORD *)(i + 16) )
{
result = *(_QWORD *)(*(_QWORD *)(i + 8) + 8LL);
for ( j = *(_QWORD *)result; j; j = *(_QWORD *)(j + 16) )
{
v13 = strlen(s);
result = send(**(_DWORD **)(j + 8), s, v13, 0);
}
}
}
}
return result;
}

original_code:
void lirc_client_setnick(struct LIRCServer_struct* server, int socket,
                         char* nick)
{
  LIRCClientData* client =
    (LIRCClientData*)find_element(server->client_list, &socket,
                                  lirc_client_cmp);
  if (client != ((void *)0) && client->nick != ((void *)0))
  {
    dlnode_t* channel_node;
    char temp[512];
    sprintf(temp, ":%s!~%s@anon.com NICK :", client->nick, client->user);
    printf("Nickname changed from %s ", client->nick);
    free(client->nick);
    client->nick = safe_strdup(nick);
    printf("to %s.\n", client->nick);
    sprintf(temp + strlen(temp), "%s\r\n", client->nick);
    send(socket, temp, strlen(temp), 0);
    channel_node = client->channel_list->head;
    while (channel_node != ((void *)0))
    {
      struct LIRCChannelData_struct* c =
        (struct LIRCChannelData_struct*)channel_node->data;
      dlnode_t* client_node = c->client_list->head;
      while (client_node != ((void *)0))
      {
        LIRCClientData* c_data =
          (LIRCClientData*)client_node->data;
        send(c_data->socket, temp, strlen(temp), 0);
        client_node = client_node->next;
      }
      channel_node = channel_node->next;
    }
  }
}

canonical_original_code:
void lirc_client_setnick(struct LIRCServer_struct *server, int socket, char *nick)
{
  struct LIRCClientData_struct *client = (LIRCClientData*)find_element(server->client_list, &socket,
                                  lirc_client_cmp);
  if (client != ((void *)0) && client->nick != ((void *)0))
  {
    struct dlnode *channel_node;
    char temp[512];
    sprintf(temp, ":%s!~%s@anon.com NICK :", client->nick, client->user);
    printf("Nickname changed from %s ", client->nick);
    free(client->nick);
    client->nick = safe_strdup(nick);
    printf("to %s.\n", client->nick);
    sprintf(temp + strlen(temp), "%s\r\n", client->nick);
    send(socket, temp, strlen(temp), 0);
    channel_node = client->channel_list->head;
    while (channel_node != ((void *)0))
    {
      struct LIRCChannelData_struct *c = (struct LIRCChannelData_struct*)channel_node->data;
      struct dlnode *client_node = c->client_list->head;
      while (client_node != ((void *)0))
      {
        struct LIRCClientData_struct *c_data = (LIRCClientData*)client_node->data;
        send(c_data->socket, temp, strlen(temp), 0);
        client_node = client_node->next;
      }
      channel_node = channel_node->next;
    }
  }
}


decompiled_code:
__int64 __fastcall lirc_client_disconnect(__int64 a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
close(a2);
return remove_element(*(_QWORD *)(a1 + 24), v3, lirc_client_cmp);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
close(a2);
return remove_element(*(_QWORD *)(a1 + 24), v3, lirc_client_cmp);
}

original_code:
void lirc_client_disconnect(struct LIRCServer_struct* server, int socket)
{
  close(socket);
  remove_element(server->client_list, &socket, lirc_client_cmp);
}

canonical_original_code:
void lirc_client_disconnect(struct LIRCServer_struct *server, int socket)
{
  close(socket);
  remove_element(server->client_list, &socket, lirc_client_cmp);
}