getconfs

decompiled_code:
char *__fastcall getconfs(char *s2)
{
const char *v1; // rbx
const char *v2; // rsi
unsigned __int64 v3; // rax
char *v4; // rax
char v5; // dl
__int64 v7; // rdx

if ( !s2 )
return 0LL;
if ( !conf_status )
readconf();
v1 = first_match(s2);
if ( !v1 )
return 0LL;
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v7 = 0x2000000100000200LL;
while ( _bittest64(&v7, v3) )
{
v3 = *(unsigned __int8 *)++v2;
if ( (unsigned __int8)v3 > 0x3Du )
goto LABEL_6;
}
if ( !(_BYTE)v3 )
return 0LL;
}
LABEL_6:
strncpy(&buf_line, v2, 0x3FFuLL);
if ( !buf_line || buf_line == 10 )
{
v4 = &buf_line;
}
else
{
v4 = &buf_line;
do
v5 = *++v4;
while ( v5 != 10 && v5 );
}
*v4 = 0;
return &buf_line;
}

canonical_decompiled_code:
char *__fastcall func5(char *s2)
{
const char *v1; // rbx
const char *v2; // rsi
unsigned __int64 v3; // rax
char *v4; // rax
char v5; // dl
__int64 v7; // rdx

if ( !s2 )
return 0LL;
if ( !conf_status )
func1();
v1 = func0(s2);
if ( !v1 )
return 0LL;
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v7 = 0x2000000100000200LL;
while ( _bittest64(&v7, v3) )
{
v3 = *(unsigned __int8 *)++v2;
if ( (unsigned __int8)v3 > 0x3Du )
goto LABEL_6;
}
if ( !(_BYTE)v3 )
return 0LL;
}
LABEL_6:
strncpy(&buf_line, v2, 0x3FFuLL);
if ( !buf_line || buf_line == 10 )
{
v4 = &buf_line;
}
else
{
v4 = &buf_line;
do
v5 = *++v4;
while ( v5 != 10 && v5 );
}
*v4 = 0;
return &buf_line;
}

original_code:
char * getconfs(const char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return ((void *)0);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return ((void *)0);
 strncpy(buf_line, line, 1024 - 1);
 char *temp = buf_line;
 while (*temp != '\n' && *temp != '\0') ++temp;
 *temp = '\0';
 return buf_line;
}

canonical_original_code:
char *getconfs(char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return ((void *)0);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return ((void *)0);
 strncpy(buf_line, line, 1024 - 1);
 char *temp = buf_line;
 while (*temp != '\n' && *temp != '\0') ++temp;
 *temp = '\0';
 return buf_line;
}

variable_types:
line
char *

variable_types:
temp
char *


repo: haipome/fls

decompiled_code:
_BOOL8 __fastcall setconf1(char *s2, __int64 a2)
{
const char *v2; // rbx
char *v3; // rdi
unsigned __int64 v4; // rax
__int64 v5; // rdx

if ( !s2 )
return 0LL;
if ( !conf_status )
{
readconf();
v2 = first_match(s2);
if ( v2 )
goto LABEL_4;
return 0LL;
}
v2 = first_match(s2);
if ( !v2 )
return 0LL;
LABEL_4:
v3 = (char *)&v2[strlen(s2)];
v4 = (unsigned __int8)*v3;
if ( (unsigned __int8)v4 <= 0x3Du )
{
v5 = 0x2000000100000200LL;
do
{
if ( !_bittest64(&v5, v4) )
break;
v4 = (unsigned __int8)*++v3;
}
while ( (unsigned __int8)v4 <= 0x3Du );
}
sprintf(v3, "%ld\n", a2);
return (unsigned int)writeconf() != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(char *s2, __int64 a2)
{
const char *v2; // rbx
char *v3; // rdi
unsigned __int64 v4; // rax
__int64 v5; // rdx

if ( !s2 )
return 0LL;
if ( !conf_status )
{
func1();
v2 = func0(s2);
if ( v2 )
goto LABEL_4;
return 0LL;
}
v2 = func0(s2);
if ( !v2 )
return 0LL;
LABEL_4:
v3 = (char *)&v2[strlen(s2)];
v4 = (unsigned __int8)*v3;
if ( (unsigned __int8)v4 <= 0x3Du )
{
v5 = 0x2000000100000200LL;
do
{
if ( !_bittest64(&v5, v4) )
break;
v4 = (unsigned __int8)*++v3;
}
while ( (unsigned __int8)v4 <= 0x3Du );
}
sprintf(v3, "%ld\n", a2);
return (unsigned int)func2() != 0;
}

original_code:
int setconf1(const char *name, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sprintf(line, "%ld\n", value);
 if (!writeconf())
  return 0;
 return 1;
}

canonical_original_code:
int setconf1(char *name, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sprintf(line, "%ld\n", value);
 if (!writeconf())
  return 0;
 return 1;
}

variable_types:
name
char *

variable_types: value long

return_type: int


decompiled_code:
_BOOL8 __fastcall setconf2(char *s2, int a2, __int64 a3)
{
const char *v4; // rbx
__int64 v5; // rbp
const char *v6; // r13
size_t v7; // r15
char *v8; // r15
unsigned __int64 v9; // r14
const unsigned __int16 *v10; // rdi
__int64 v11; // rax
unsigned __int64 v12; // rax
char nptr[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( s2 )
{
if ( !conf_status )
readconf();
if ( dword_100D40 > 0 )
{
v4 = config;
v5 = 0x2000000100000200LL;
v6 = (char *)&unk_1140 + 1024 * (unsigned __int64)(unsigned int)(dword_100D40 - 1);
while ( 1 )
{
v7 = strlen(s2);
if ( strncmp(v4, s2, v7) )
goto LABEL_6;
v8 = (char *)&v4[v7];
v9 = (unsigned __int8)*v8;
if ( (_BYTE)v9 == 32 )
break;
LABEL_10:
if ( (_BYTE)v9 == 9 )
goto LABEL_9;
v10 = *_ctype_b_loc();
v11 = 0LL;
while ( (v10[(char)v9] & 0x800) != 0 )
{
++v8;
nptr[v11++] = v9;
v9 = (unsigned __int8)*v8;
}
nptr[(int)v11] = 0;
if ( (unsigned __int8)v9 <= 0x3Du && _bittest64(&v5, v9) )
{
do
v12 = (unsigned __int8)*++v8;
while ( (unsigned __int8)v12 <= 0x3Du && _bittest64(&v5, v12) );
}
if ( atoi(nptr) == a2 )
{
sprintf(v8, "%ld\n", a3);
return (unsigned int)writeconf() != 0;
}
LABEL_6:
v4 += 1024;
if ( v6 == v4 )
return 0LL;
}
do
LABEL_9:
v9 = (unsigned __int8)*++v8;
while ( (_BYTE)v9 == 32 );
goto LABEL_10;
}
}
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char *s2, int a2, __int64 a3)
{
const char *v4; // rbx
__int64 v5; // rbp
const char *v6; // r13
size_t v7; // r15
char *v8; // r15
unsigned __int64 v9; // r14
const unsigned __int16 *v10; // rdi
__int64 v11; // rax
unsigned __int64 v12; // rax
char nptr[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( s2 )
{
if ( !conf_status )
func1();
if ( dword_100D40 > 0 )
{
v4 = config;
v5 = 0x2000000100000200LL;
v6 = (char *)&unk_1140 + 1024 * (unsigned __int64)(unsigned int)(dword_100D40 - 1);
while ( 1 )
{
v7 = strlen(s2);
if ( strncmp(v4, s2, v7) )
goto LABEL_6;
v8 = (char *)&v4[v7];
v9 = (unsigned __int8)*v8;
if ( (_BYTE)v9 == 32 )
break;
LABEL_10:
if ( (_BYTE)v9 == 9 )
goto LABEL_9;
v10 = *_ctype_b_loc();
v11 = 0LL;
while ( (v10[(char)v9] & 0x800) != 0 )
{
++v8;
nptr[v11++] = v9;
v9 = (unsigned __int8)*v8;
}
nptr[(int)v11] = 0;
if ( (unsigned __int8)v9 <= 0x3Du && _bittest64(&v5, v9) )
{
do
v12 = (unsigned __int8)*++v8;
while ( (unsigned __int8)v12 <= 0x3Du && _bittest64(&v5, v12) );
}
if ( atoi(nptr) == a2 )
{
sprintf(v8, "%ld\n", a3);
return (unsigned int)func2() != 0;
}
LABEL_6:
v4 += 1024;
if ( v6 == v4 )
return 0LL;
}
do
LABEL_9:
v9 = (unsigned __int8)*++v8;
while ( (_BYTE)v9 == 32 );
goto LABEL_10;
}
}
return 0LL;
}

original_code:
int setconf2(const char *name, int key, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i, j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short int) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
   {
    sprintf(line, "%ld\n", value);
    if (!writeconf())
     return 0;
    return 1;
   }
  }
 }
 return 0;
}

canonical_original_code:
int setconf2(char *name, int key, long value)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i; int j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
   {
    sprintf(line, "%ld\n", value);
    if (!writeconf())
     return 0;
    return 1;
   }
  }
 }
 return 0;
}

variable_types: key int

variable_types: i int

variable_types: j int

variable_types:
num
char [1024]


decompiled_code:
void limit_init()
{
_BYTE *v0; // rbx
int v1; // er13
int v2; // ebp
char v3; // al
_BYTE *v4; // rdi
const char *v5; // rbx
unsigned __int64 v6; // rax
const char *v7; // rdi
__int64 v8; // rdx
unsigned __int16 v9; // [rsp+0h] [rbp-34h] BYREF
unsigned int v10; // [rsp+4h] [rbp-30h] BYREF
unsigned int v11; // [rsp+8h] [rbp-2Ch] BYREF

if ( limit_stat != 1 )
{
if ( !conf_status )
readconf();
if ( dword_100D40 > 0 )
{
v0 = &unk_D4B;
v1 = 0;
v2 = 0;
while ( memcmp(v0 - 11, "serverlimit", 0xBuLL) )
{
LABEL_6:
++v2;
v0 += 1024;
if ( dword_100D40 <= v2 )
{
if ( v1 )
goto LABEL_13;
goto LABEL_25;
}
}
v3 = *v0;
v4 = v0;
if ( *v0 != 32 )
goto LABEL_10;
while ( 1 )
{
do
v3 = *++v4;
while ( v3 == 32 );
LABEL_10:
if ( v3 != 9 )
{
++v1;
_isoc99_sscanf(v4, "%d = %d %d", &v9, &v10, &v11);
addto_limd(v9, v10, v11);
goto LABEL_6;
}
}
}
LABEL_25:
err_exit("In limit_init: No limit data in config");
LABEL_13:
v5 = first_match("timelevel");
if ( !v5 )
err_exit("In limit_init: can not find %s in config file", "timelevel");
v6 = *((unsigned __int8 *)v5 + 9);
v7 = v5 + 9;
if ( (unsigned __int8)v6 <= 0x3Du )
{
v8 = 0x2000000100000200LL;
do
{
if ( !_bittest64(&v8, v6) )
break;
v6 = *(unsigned __int8 *)++v7;
}
while ( (unsigned __int8)v6 <= 0x3Du );
}
_isoc99_sscanf(v7, "%d %d", &timel1, &timel2);
if ( !timel1 || !timel2 )
err_exit("In limit_init: illegal timelevel");
warning_rate = getconf1("warningrate");
if ( !warning_rate )
err_exit("In limit_init: warningrate is illegal");
limit_stat = 1;
}
}

canonical_decompiled_code:
void func8()
{
_BYTE *v0; // rbx
int v1; // er13
int v2; // ebp
char v3; // al
_BYTE *v4; // rdi
const char *v5; // rbx
unsigned __int64 v6; // rax
const char *v7; // rdi
__int64 v8; // rdx
unsigned __int16 v9; // [rsp+0h] [rbp-34h] BYREF
unsigned int v10; // [rsp+4h] [rbp-30h] BYREF
unsigned int v11; // [rsp+8h] [rbp-2Ch] BYREF

if ( limit_stat != 1 )
{
if ( !conf_status )
func1();
if ( dword_100D40 > 0 )
{
v0 = &unk_D4B;
v1 = 0;
v2 = 0;
while ( memcmp(v0 - 11, "serverlimit", 0xBuLL) )
{
LABEL_6:
++v2;
v0 += 1024;
if ( dword_100D40 <= v2 )
{
if ( v1 )
goto LABEL_13;
goto LABEL_25;
}
}
v3 = *v0;
v4 = v0;
if ( *v0 != 32 )
goto LABEL_10;
while ( 1 )
{
do
v3 = *++v4;
while ( v3 == 32 );
LABEL_10:
if ( v3 != 9 )
{
++v1;
_isoc99_sscanf(v4, "%d = %d %d", &v9, &v10, &v11);
addto_limd(v9, v10, v11);
goto LABEL_6;
}
}
}
LABEL_25:
err_exit("In limit_init: No limit data in config");
LABEL_13:
v5 = func0("timelevel");
if ( !v5 )
err_exit("In limit_init: can not find %s in config file", "timelevel");
v6 = *((unsigned __int8 *)v5 + 9);
v7 = v5 + 9;
if ( (unsigned __int8)v6 <= 0x3Du )
{
v8 = 0x2000000100000200LL;
do
{
if ( !_bittest64(&v8, v6) )
break;
v6 = *(unsigned __int8 *)++v7;
}
while ( (unsigned __int8)v6 <= 0x3Du );
}
_isoc99_sscanf(v7, "%d %d", &timel1, &timel2);
if ( !timel1 || !timel2 )
err_exit("In limit_init: illegal timelevel");
warning_rate = func3("warningrate");
if ( !warning_rate )
err_exit("In limit_init: warningrate is illegal");
limit_stat = 1;
}
}

original_code:
void limit_init(void)
{
 if (limit_stat == 1)
  return;
 if (conf_status == 0)
 {
  readconf();
 }
 char *name = "serverlimit";
 char *line;
 int sid, temp[2];
 int i, j = 0;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' '|| *line == '\t') ++line;
   sscanf(line, "%d = %d %d", &sid, temp, temp + 1);
   addto_limd(sid, temp[0], temp[1]);
   ++j;
  }
 }
 if (j == 0)
  err_exit("In limit_init: No limit data in config");
 name = "timelevel";
 if ((line = first_match(name)) == ((void *)0))
  err_exit("In limit_init: can not find %s in config file",name);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sscanf(line, "%d %d", &timel1, &timel2);
 if (timel1 == 0 || timel2 == 0)
  err_exit("In limit_init: illegal timelevel");
 if ((warning_rate = getconf1("warningrate")) == 0)
  err_exit("In limit_init: warningrate is illegal");
 limit_stat = 1;
 return;
}

canonical_original_code:
void limit_init()
{
 if (limit_stat == 1)
  return;
 if (conf_status == 0)
 {
  readconf();
 }
 char *name = "serverlimit";
 char *line;
 int sid; int temp[2];
 int i; int j = 0;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' '|| *line == '\t') ++line;
   sscanf(line, "%d = %d %d", &sid, temp, temp + 1);
   addto_limd(sid, temp[0], temp[1]);
   ++j;
  }
 }
 if (j == 0)
  err_exit("In limit_init: No limit data in config");
 name = "timelevel";
 if ((line = first_match(name)) == ((void *)0))
  err_exit("In limit_init: can not find %s in config file",name);
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 sscanf(line, "%d %d", &timel1, &timel2);
 if (timel1 == 0 || timel2 == 0)
  err_exit("In limit_init: illegal timelevel");
 if ((warning_rate = getconf1("warningrate")) == 0)
  err_exit("In limit_init: warningrate is illegal");
 limit_stat = 1;
 return;
}

variable_types: sid int

variable_types:
temp
int [2]

return_type: void


decompiled_code:
const char *__fastcall first_match(char *s2)
{
int v1; // ebp
const char *v2; // r12
size_t v3; // r13
const char *v4; // rbp

if ( !s2 )
return 0LL;
v1 = dword_100D40;
if ( dword_100D40 <= 0 )
return 0LL;
v2 = config;
v3 = strlen(s2);
v4 = (char *)&unk_1140 + 1024 * (unsigned __int64)(unsigned int)(v1 - 1);
while ( strncmp(v2, s2, v3) )
{
v2 += 1024;
if ( v2 == v4 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func0(char *s2)
{
int v1; // ebp
const char *v2; // r12
size_t v3; // r13
const char *v4; // rbp

if ( !s2 )
return 0LL;
v1 = dword_100D40;
if ( dword_100D40 <= 0 )
return 0LL;
v2 = config;
v3 = strlen(s2);
v4 = (char *)&unk_1140 + 1024 * (unsigned __int64)(unsigned int)(v1 - 1);
while ( strncmp(v2, s2, v3) )
{
v2 += 1024;
if ( v2 == v4 )
return 0LL;
}
return v2;
}

original_code:
static char * first_match(const char *head)
{
 if (((void *)0) == head)
  return ((void *)0);
 int i;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], head, strlen(head)))
   return config.buf[i];
 }
 return ((void *)0);
}

canonical_original_code:
static char *first_match(char *head)
{
 if (((void *)0) == head)
  return ((void *)0);
 int i;
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], head, strlen(head)))
   return config.buf[i];
 }
 return ((void *)0);
}

variable_types:
head
char *

return_type: char *


decompiled_code:
__int64 __fastcall getconf1(char *s2)
{
const char *v1; // rbx
const char *v2; // rdi
unsigned __int64 v3; // rax
__int64 v4; // rdx
__int64 result; // rax

if ( !s2 )
return 0LL;
if ( !conf_status )
readconf();
v1 = first_match(s2);
if ( !v1 )
goto LABEL_11;
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 > 0x3Du )
goto LABEL_9;
v4 = 0x2000000100000200LL;
while ( _bittest64(&v4, v3) )
{
v3 = *(unsigned __int8 *)++v2;
if ( (unsigned __int8)v3 > 0x3Du )
goto LABEL_9;
}
if ( (_BYTE)v3 )
LABEL_9:
result = atol(v2);
else
LABEL_11:
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
const char *v1; // rbx
const char *v2; // rdi
unsigned __int64 v3; // rax
__int64 v4; // rdx
__int64 result; // rax

if ( !s2 )
return 0LL;
if ( !conf_status )
func1();
v1 = func0(s2);
if ( !v1 )
goto LABEL_11;
v2 = &v1[strlen(s2)];
v3 = *(unsigned __int8 *)v2;
if ( (unsigned __int8)v3 > 0x3Du )
goto LABEL_9;
v4 = 0x2000000100000200LL;
while ( _bittest64(&v4, v3) )
{
v3 = *(unsigned __int8 *)++v2;
if ( (unsigned __int8)v3 > 0x3Du )
goto LABEL_9;
}
if ( (_BYTE)v3 )
LABEL_9:
result = atol(v2);
else
LABEL_11:
result = 0LL;
return result;
}

original_code:
long getconf1(const char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return 0;
 return (atol(line));
}

canonical_original_code:
long getconf1(char *name)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 if ((line = first_match(name)) == ((void *)0))
  return 0;
 line += strlen(name);
 while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
 if (strlen(line) == 0)
  return 0;
 return (atol(line));
}

return_type: long


decompiled_code:
__int64 __fastcall getconf2(char *s2, int a2)
{
const char *v3; // rbx
__int64 v4; // r12
const char *v5; // r14
size_t v6; // rbp
const char *v7; // rbp
unsigned __int64 v8; // r15
const unsigned __int16 *v9; // rdi
__int64 v10; // rax
unsigned __int64 v11; // rax
char nptr[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( s2 )
{
if ( !conf_status )
readconf();
if ( dword_100D40 > 0 )
{
v3 = config;
v4 = 0x2000000100000200LL;
v5 = (char *)&unk_1140 + 1024 * (unsigned __int64)(unsigned int)(dword_100D40 - 1);
while ( 1 )
{
v6 = strlen(s2);
if ( strncmp(v3, s2, v6) )
goto LABEL_6;
v7 = &v3[v6];
v8 = *(unsigned __int8 *)v7;
if ( (_BYTE)v8 == 32 )
break;
LABEL_10:
if ( (_BYTE)v8 == 9 )
goto LABEL_9;
v9 = *_ctype_b_loc();
v10 = 0LL;
while ( (v9[(char)v8] & 0x800) != 0 )
{
++v7;
nptr[v10++] = v8;
v8 = *(unsigned __int8 *)v7;
}
nptr[(int)v10] = 0;
if ( (unsigned __int8)v8 <= 0x3Du && _bittest64(&v4, v8) )
{
do
v11 = *(unsigned __int8 *)++v7;
while ( (unsigned __int8)v11 <= 0x3Du && _bittest64(&v4, v11) );
}
if ( atoi(nptr) == a2 )
return atol(v7);
LABEL_6:
v3 += 1024;
if ( v5 == v3 )
return 0LL;
}
do
LABEL_9:
v8 = *(unsigned __int8 *)++v7;
while ( (_BYTE)v8 == 32 );
goto LABEL_10;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2, int a2)
{
const char *v3; // rbx
__int64 v4; // r12
const char *v5; // r14
size_t v6; // rbp
const char *v7; // rbp
unsigned __int64 v8; // r15
const unsigned __int16 *v9; // rdi
__int64 v10; // rax
unsigned __int64 v11; // rax
char nptr[1080]; // [rsp+10h] [rbp-438h] BYREF

if ( s2 )
{
if ( !conf_status )
func1();
if ( dword_100D40 > 0 )
{
v3 = config;
v4 = 0x2000000100000200LL;
v5 = (char *)&unk_1140 + 1024 * (unsigned __int64)(unsigned int)(dword_100D40 - 1);
while ( 1 )
{
v6 = strlen(s2);
if ( strncmp(v3, s2, v6) )
goto LABEL_6;
v7 = &v3[v6];
v8 = *(unsigned __int8 *)v7;
if ( (_BYTE)v8 == 32 )
break;
LABEL_10:
if ( (_BYTE)v8 == 9 )
goto LABEL_9;
v9 = *_ctype_b_loc();
v10 = 0LL;
while ( (v9[(char)v8] & 0x800) != 0 )
{
++v7;
nptr[v10++] = v8;
v8 = *(unsigned __int8 *)v7;
}
nptr[(int)v10] = 0;
if ( (unsigned __int8)v8 <= 0x3Du && _bittest64(&v4, v8) )
{
do
v11 = *(unsigned __int8 *)++v7;
while ( (unsigned __int8)v11 <= 0x3Du && _bittest64(&v4, v11) );
}
if ( atoi(nptr) == a2 )
return atol(v7);
LABEL_6:
v3 += 1024;
if ( v5 == v3 )
return 0LL;
}
do
LABEL_9:
v8 = *(unsigned __int8 *)++v7;
while ( (_BYTE)v8 == 32 );
goto LABEL_10;
}
}
return 0LL;
}

original_code:
long getconf2(const char *name, int key)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i, j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short int) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
    return (atol(line));
  }
 }
 return 0;
}

canonical_original_code:
long getconf2(char *name, int key)
{
 if (((void *)0) == name)
  return 0;
 if (conf_status == 0)
 {
  readconf();
 }
 char *line;
 int i; int j;
 char num[1024];
 for (i = 0; i < config.len; ++i)
 {
  if (!strncmp(config.buf[i], name, strlen(name)))
  {
   line = config.buf[i];
   line += strlen(name);
   while ( *line == ' ' || *line == '\t') ++line;
   j = 0;
   while (((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short) _ISdigit))
   {
    num[j++] = *line;
    ++line;
   }
   num[j] = '\0';
   while ( *line == ' ' || *line == '=' ||*line == '\t') ++line;
   if (atoi(num) == key)
    return (atol(line));
  }
 }
 return 0;
}


rflsucom

decompiled_code:
__int64 __fastcall rflsucom(const void *a1, const void *a2)
{
return *(unsigned __int8 *)a1 - (unsigned int)*(unsigned __int8 *)a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return *(unsigned __int8 *)a1 - (unsigned int)*(unsigned __int8 *)a2;
}

original_code:
static int rflsucom(const void * p1, const void * p2)
{
 return (((flsunit *)p1)->server.id - ((flsunit *)p2)->server.id);
}

canonical_original_code:
static int rflsucom(void *p1, void *p2)
{
 return (((struct flsunit *)p1)->server.id - ((struct flsunit *)p2)->server.id);
}

user_defined_types: struct flsunit { struct addr server; int delaycount; int delaytime; long delaystart; }

user_defined_types: struct addr { unsigned char id; unsigned char zero; unsigned short port; unsigned int ip; }


decompiled_code:
__int64 __fastcall addto_rflsl(unsigned __int8 *a1)
{
unsigned int v1; // er12

v1 = -1;
if ( !a1 )
return v1;
v1 = add_item(a1);
if ( !v1 )
return v1;
v1 = 1;
qsort(&rflsl, *((int *)&rflsl + 768), 0x18uLL, (__compar_fn_t)rflsucom);
if ( (unsigned int)write_rflsl() )
return v1;
run_msg("In addto_rflsl: write_rflsl error");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
unsigned int v1; // er12

v1 = -1;
if ( !a1 )
return v1;
v1 = func1(a1);
if ( !v1 )
return v1;
v1 = 1;
qsort(&rflsl, *((int *)&rflsl + 768), 0x18uLL, (__compar_fn_t)rflsucom);
if ( (unsigned int)func2() )
return v1;
run_msg("In addto_rflsl: write_rflsl error");
return 1LL;
}

original_code:
int addto_rflsl(addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (!add_item(ptr))
  return 0;
 qsort(rflsl.list, rflsl.len, sizeof(flsunit), rflsucom);
 if (!write_rflsl())
  run_msg("In addto_rflsl: write_rflsl error");
 return 1;
}

canonical_original_code:
int addto_rflsl(struct addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (!add_item(ptr))
  return 0;
 qsort(rflsl.list, rflsl.len, sizeof(flsunit), rflsucom);
 if (!write_rflsl())
  run_msg("In addto_rflsl: write_rflsl error");
 return 1;
}

variable_types: struct addr { unsigned char id; unsigned char zero; unsigned short port; unsigned int ip; } *


decompiled_code:
__int64 __fastcall remove_rflsl(char *a1)
{
char v1; // si
__int64 result; // rax
int v3; // ecx
__int64 v4; // rdx
char *v5; // rdx
__m128i *v6; // rcx
__m128i v7; // xmm1
__int64 v8; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
result = 0LL;
if ( *a1 != localaddr )
{
v3 = *((_DWORD *)&rflsl + 768);
if ( v1 != (_BYTE)rflsl )
{
v4 = (unsigned int)((_DWORD)&rflsl + 24);
while ( (int)result < v3 )
{
v4 += 24LL;
LODWORD(result) = result + 1;
if ( v1 == *(_BYTE *)(v4 - 24) )
goto LABEL_10;
}
return 1LL;
}
LODWORD(result) = 0;
LABEL_10:
if ( (int)result >= v3 )
return 1LL;
if ( (int)result < v3 - 1 )
{
v5 = (char *)&rflsl + 24 * (int)result;
do
{
v6 = (__m128i *)v5;
v7 = _mm_loadu_si128((const __m128i *)(v5 + 24));
LODWORD(result) = result + 1;
v5 += 24;
*v6 = v7;
v6[1].m128i_i64[0] = *((_QWORD *)v5 + 2);
}
while ( *((_DWORD *)&rflsl + 768) - 1 > (int)result );
}
v8 = 24LL * (int)result;
*(_QWORD *)((char *)&rflsl + v8 + 16) = 0LL;
*(__int128 *)((char *)&rflsl + v8) = 0LL;
--*((_DWORD *)&rflsl + 768);
if ( !(unsigned int)write_rflsl() )
run_msg("In remove_rflsl: write_rflsl error");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
char v1; // si
__int64 result; // rax
int v3; // ecx
__int64 v4; // rdx
char *v5; // rdx
__m128i *v6; // rcx
__m128i v7; // xmm1
__int64 v8; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
result = 0LL;
if ( *a1 != localaddr )
{
v3 = *((_DWORD *)&rflsl + 768);
if ( v1 != (_BYTE)rflsl )
{
v4 = (unsigned int)((_DWORD)&rflsl + 24);
while ( (int)result < v3 )
{
v4 += 24LL;
LODWORD(result) = result + 1;
if ( v1 == *(_BYTE *)(v4 - 24) )
goto LABEL_10;
}
return 1LL;
}
LODWORD(result) = 0;
LABEL_10:
if ( (int)result >= v3 )
return 1LL;
if ( (int)result < v3 - 1 )
{
v5 = (char *)&rflsl + 24 * (int)result;
do
{
v6 = (__m128i *)v5;
v7 = _mm_loadu_si128((const __m128i *)(v5 + 24));
LODWORD(result) = result + 1;
v5 += 24;
*v6 = v7;
v6[1].m128i_i64[0] = *((_QWORD *)v5 + 2);
}
while ( *((_DWORD *)&rflsl + 768) - 1 > (int)result );
}
v8 = 24LL * (int)result;
*(_QWORD *)((char *)&rflsl + v8 + 16) = 0LL;
*(__int128 *)((char *)&rflsl + v8) = 0LL;
--*((_DWORD *)&rflsl + 768);
if ( !(unsigned int)func2() )
run_msg("In remove_rflsl: write_rflsl error");
result = 1LL;
}
return result;
}

original_code:
int remove_rflsl(addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 int i = 0;
 if (ptr->id == localaddr.id)
  return 0;
 while (ptr->id != rflsl.list[i].server.id && i < rflsl.len)
  ++i;
 if (i >= rflsl.len)
  return 1;
 for ( ; i < (rflsl.len - 1); ++i)
  memcpy(rflsl.list + i, rflsl.list + i + 1, sizeof(flsunit));
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 --rflsl.len;
 if (!write_rflsl())
  run_msg("In remove_rflsl: write_rflsl error");
 return 1;
}

canonical_original_code:
int remove_rflsl(struct addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 int i = 0;
 if (ptr->id == localaddr.id)
  return 0;
 while (ptr->id != rflsl.list[i].server.id && i < rflsl.len)
  ++i;
 if (i >= rflsl.len)
  return 1;
 for ( ; i < (rflsl.len - 1); ++i)
  memcpy(rflsl.list + i, rflsl.list + i + 1, sizeof(flsunit));
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 --rflsl.len;
 if (!write_rflsl())
  run_msg("In remove_rflsl: write_rflsl error");
 return 1;
}


decompiled_code:
__int16 manage_fls_init()
{
int v0; // ebx
char v1; // al
char v2; // dl
const char *v3; // rsi
__int16 v4; // ax
__int16 v5; // di
__int16 result; // ax
struct in_addr inp; // [rsp+Ch] [rbp-40Ch] BYREF
char dest[1032]; // [rsp+10h] [rbp-408h] BYREF

v0 = getconf1("manageflsid");
if ( (unsigned int)(v0 - 1) > 0xFE )
err_exit("In manage_fls_init: manageflsid is illegal");
v1 = localaddr;
manage_fls_addr = v0;
v2 = v0;
if ( !localaddr )
{
err_exit("In manage_fls_init: localaddr id is illegal");
v2 = manage_fls_addr;
v1 = localaddr;
}
manage_switch = v2 == v1;
v3 = (const char *)getconfs("manageflsip");
if ( !strncpy(dest, v3, 0x3FFuLL) )
err_exit("In manage_fls_init: get manageflsip error");
inet_aton(dest, &inp);
*((struct in_addr *)&manage_fls_addr + 1) = inp;
v4 = getconf1("manageflsport");
*((_WORD *)&manage_fls_addr + 1) = v4;
v5 = v4;
if ( !v4 )
{
err_exit("In manage_fls_init: manageflsport is illegal");
v5 = *((_WORD *)&manage_fls_addr + 1);
}
result = _bswap_16(v5);
*((_WORD *)&manage_fls_addr + 1) = result;
return result;
}

canonical_decompiled_code:
__int16 func9()
{
int v0; // ebx
char v1; // al
char v2; // dl
const char *v3; // rsi
__int16 v4; // ax
__int16 v5; // di
__int16 result; // ax
struct in_addr inp; // [rsp+Ch] [rbp-40Ch] BYREF
char dest[1032]; // [rsp+10h] [rbp-408h] BYREF

v0 = getconf1("manageflsid");
if ( (unsigned int)(v0 - 1) > 0xFE )
err_exit("In manage_fls_init: manageflsid is illegal");
v1 = localaddr;
manage_fls_addr = v0;
v2 = v0;
if ( !localaddr )
{
err_exit("In manage_fls_init: localaddr id is illegal");
v2 = manage_fls_addr;
v1 = localaddr;
}
manage_switch = v2 == v1;
v3 = (const char *)getconfs("manageflsip");
if ( !strncpy(dest, v3, 0x3FFuLL) )
err_exit("In manage_fls_init: get manageflsip error");
inet_aton(dest, &inp);
*((struct in_addr *)&manage_fls_addr + 1) = inp;
v4 = getconf1("manageflsport");
*((_WORD *)&manage_fls_addr + 1) = v4;
v5 = v4;
if ( !v4 )
{
err_exit("In manage_fls_init: manageflsport is illegal");
v5 = *((_WORD *)&manage_fls_addr + 1);
}
result = func3(v5);
*((_WORD *)&manage_fls_addr + 1) = result;
return result;
}

original_code:
void manage_fls_init(void)
{
 int id_temp = getconf1("manageflsid");
 if (id_temp <= 0 || id_temp > 255)
  err_exit("In manage_fls_init: manageflsid is illegal");
 manage_fls_addr.id = id_temp;
 if (localaddr.id == 0)
  err_exit("In manage_fls_init: localaddr id is illegal");
 if (manage_fls_addr.id == localaddr.id)
 {
  manage_switch = 1;
 }
 else
 {
  manage_switch = 0;
 }
 char ip_string[1024];
 struct in_addr inaddr;
 if (strncpy(ip_string, getconfs("manageflsip"), 1024 - 1) == 0)
  err_exit("In manage_fls_init: get manageflsip error");
 inet_aton(ip_string, &(inaddr));
 manage_fls_addr.ip = inaddr.s_addr;
 if ((manage_fls_addr.port = (uint16_t)getconf1("manageflsport")) == 0)
  err_exit("In manage_fls_init: manageflsport is illegal");
 manage_fls_addr.port = htons(manage_fls_addr.port);
}

canonical_original_code:
void manage_fls_init()
{
 int id_temp = getconf1("manageflsid");
 if (id_temp <= 0 || id_temp > 255)
  err_exit("In manage_fls_init: manageflsid is illegal");
 manage_fls_addr.id = id_temp;
 if (localaddr.id == 0)
  err_exit("In manage_fls_init: localaddr id is illegal");
 if (manage_fls_addr.id == localaddr.id)
 {
  manage_switch = 1;
 }
 else
 {
  manage_switch = 0;
 }
 char ip_string[1024];
 struct in_addr inaddr;
 if (strncpy(ip_string, getconfs("manageflsip"), 1024 - 1) == 0)
  err_exit("In manage_fls_init: get manageflsip error");
 inet_aton(ip_string, &(inaddr));
 manage_fls_addr.ip = inaddr.s_addr;
 if ((manage_fls_addr.port = (unsigned short)getconf1("manageflsport")) == 0)
  err_exit("In manage_fls_init: manageflsport is illegal");
 manage_fls_addr.port = htons(manage_fls_addr.port);
}

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }


decompiled_code:
__int64 inform_start()
{
int v0; // ebx
__int64 result; // rax

if ( manage_fls_addr )
{
v0 = 3;
if ( localaddr != manage_fls_addr )
goto LABEL_3;
goto LABEL_8;
}
manage_fls_init();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
LABEL_8:
addto_rflsl((unsigned __int8 *)&localaddr);
return 1LL;
}
LABEL_3:
while ( 1 )
{
send_net7(&manage_fls_addr, 1LL);
result = recv_netpt_constprop_0();
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // ebx
__int64 result; // rax

if ( manage_fls_addr )
{
v0 = 3;
if ( localaddr != manage_fls_addr )
goto LABEL_3;
goto LABEL_8;
}
func9();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
LABEL_8:
func7((unsigned __int8 *)&localaddr);
return 1LL;
}
LABEL_3:
while ( 1 )
{
send_net7(&manage_fls_addr, 1LL);
result = func5();
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
return result;
}

original_code:
int inform_start(void)
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  addto_rflsl(&(localaddr));
  return 1;
 }
 int i, stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 1);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}

canonical_original_code:
int inform_start()
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  addto_rflsl(&(localaddr));
  return 1;
 }
 int i; int stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 1);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}

variable_types: stat int


decompiled_code:
__int64 inform_close()
{
int v0; // ebx
__int64 result; // rax

if ( manage_fls_addr )
{
v0 = 3;
if ( localaddr != manage_fls_addr )
goto LABEL_3;
goto LABEL_8;
}
manage_fls_init();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
LABEL_8:
remove_rflsl((char *)&localaddr);
return 1LL;
}
LABEL_3:
while ( 1 )
{
send_net7(&manage_fls_addr, 2LL);
result = recv_netpt_constprop_0();
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // ebx
__int64 result; // rax

if ( manage_fls_addr )
{
v0 = 3;
if ( localaddr != manage_fls_addr )
goto LABEL_3;
goto LABEL_8;
}
func9();
v0 = 3;
if ( localaddr == manage_fls_addr )
{
LABEL_8:
func8((char *)&localaddr);
return 1LL;
}
LABEL_3:
while ( 1 )
{
send_net7(&manage_fls_addr, 2LL);
result = func5();
if ( (_DWORD)result == 1 )
break;
if ( !--v0 )
return 0LL;
}
return result;
}

original_code:
int inform_close(void)
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  remove_rflsl(&(localaddr));
  return 1;
 }
 int i, stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 2);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}

canonical_original_code:
int inform_close()
{
 if (manage_fls_addr.id == 0)
 {
  manage_fls_init();
 }
 if (localaddr.id == manage_fls_addr.id)
 {
  remove_rflsl(&(localaddr));
  return 1;
 }
 int i; int stat = 0;
 for (i = 0; i < 3; ++i)
 {
  send_net7(&(manage_fls_addr), 2);
  stat = recv_netpt(1);
  if (stat == 1)
  {
   return 1;
  }
  else
  {
   continue;
  }
 }
 return 0;
}


decompiled_code:
__int64 __fastcall add_item(unsigned __int8 *a1)
{
__int64 v1; // rcx
__int64 result; // rax
__int64 v3; // rsi
__int128 *v4; // rdx
char *v5; // rdx
__int64 v6; // rax
char *v7; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *((int *)&rflsl + 768);
result = 0LL;
if ( (int)v1 <= 127 )
{
if ( (int)v1 <= 0 )
{
LABEL_11:
v6 = 24 * v1;
*(__int128 *)((char *)&rflsl + v6) = 0LL;
v7 = (char *)&rflsl + 24 * v1;
*(_QWORD *)((char *)&rflsl + v6 + 16) = 0LL;
*((_BYTE *)&rflsl + v6) = *a1;
*((_WORD *)v7 + 1) = *((_WORD *)a1 + 1);
LODWORD(v6) = *((_DWORD *)a1 + 1);
++*((_DWORD *)&rflsl + 768);
*((_DWORD *)v7 + 1) = v6;
result = 1LL;
}
else
{
v3 = *a1;
v4 = &rflsl;
while ( (_BYTE)v3 != *(_BYTE *)v4 )
{
LODWORD(result) = result + 1;
v4 = (__int128 *)((char *)v4 + 24);
if ( (_DWORD)v1 == (_DWORD)result )
goto LABEL_11;
}
v5 = (char *)&rflsl + 24 * (int)result;
if ( *((_DWORD *)a1 + 1) != *((_DWORD *)v5 + 1)
|| (v3 = *((unsigned __int16 *)v5 + 1), result = 1LL, *((_WORD *)a1 + 1) != (_WORD)v3) )
{
run_msg("fls id:%d confused!", v3);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1)
{
__int64 v1; // rcx
__int64 result; // rax
__int64 v3; // rsi
__int128 *v4; // rdx
char *v5; // rdx
__int64 v6; // rax
char *v7; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *((int *)&rflsl + 768);
result = 0LL;
if ( (int)v1 <= 127 )
{
if ( (int)v1 <= 0 )
{
LABEL_11:
v6 = 24 * v1;
*(__int128 *)((char *)&rflsl + v6) = 0LL;
v7 = (char *)&rflsl + 24 * v1;
*(_QWORD *)((char *)&rflsl + v6 + 16) = 0LL;
*((_BYTE *)&rflsl + v6) = *a1;
*((_WORD *)v7 + 1) = *((_WORD *)a1 + 1);
LODWORD(v6) = *((_DWORD *)a1 + 1);
++*((_DWORD *)&rflsl + 768);
*((_DWORD *)v7 + 1) = v6;
result = 1LL;
}
else
{
v3 = *a1;
v4 = &rflsl;
while ( (_BYTE)v3 != *(_BYTE *)v4 )
{
LODWORD(result) = result + 1;
v4 = (__int128 *)((char *)v4 + 24);
if ( (_DWORD)v1 == (_DWORD)result )
goto LABEL_11;
}
v5 = (char *)&rflsl + 24 * (int)result;
if ( *((_DWORD *)a1 + 1) != *((_DWORD *)v5 + 1)
|| (v3 = *((unsigned __int16 *)v5 + 1), result = 1LL, *((_WORD *)a1 + 1) != (_WORD)v3) )
{
run_msg("fls id:%d confused!", v3);
result = 1LL;
}
}
}
return result;
}

original_code:
static int add_item(addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (rflsl.len >= 128)
  return 0;
 int i;
 for (i = 0; i < rflsl.len; ++i)
  if (ptr->id == rflsl.list[i].server.id)
  {
   if (ptr->ip != rflsl.list[i].server.ip || ptr->port != rflsl.list[i].server.port)
   {
    run_msg("fls id:%d confused!");
   }
   return 1;
  }
 i = rflsl.len;
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 rflsl.list[i].server.id = ptr->id;
 rflsl.list[i].server.port = ptr->port;
 rflsl.list[i].server.ip = ptr->ip;
 ++rflsl.len;
 return 1;
}

canonical_original_code:
static int add_item(struct addr *ptr)
{
 if (((void *)0) == ptr)
  return -1;
 if (rflsl.len >= 128)
  return 0;
 int i;
 for (i = 0; i < rflsl.len; ++i)
  if (ptr->id == rflsl.list[i].server.id)
  {
   if (ptr->ip != rflsl.list[i].server.ip || ptr->port != rflsl.list[i].server.port)
   {
    run_msg("fls id:%d confused!");
   }
   return 1;
  }
 i = rflsl.len;
 memset(rflsl.list + i, '\0', sizeof(flsunit));
 rflsl.list[i].server.id = ptr->id;
 rflsl.list[i].server.port = ptr->port;
 rflsl.list[i].server.ip = ptr->ip;
 ++rflsl.len;
 return 1;
}


original_code:
static void netpt7_init(netpt7 *send, addr *fls, uint8_t stat, uint16_t sid)
{
 bzero(send, sizeof(netpt7));
 pth_init(&(send->head),7, sizeof(netpt7), 1);
 send->body.stat = stat;
 send->body.sid = sid;
 if (fls != ((void *)0))
  send->body.fls = *fls;
 send->pef = 0X10;
}

canonical_original_code:
static void netpt7_init(struct netpt7 *send, struct addr *fls, unsigned char stat, unsigned short sid)
{
 bzero(send, sizeof(netpt7));
 pth_init(&(send->head),7, sizeof(netpt7), 1);
 send->body.stat = stat;
 send->body.sid = sid;
 if (fls != ((void *)0))
  send->body.fls = *fls;
 send->pef = 0X10;
}

variable_types: struct netpt7 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody7 { unsigned char stat; char zero; unsigned short sid; struct addr { unsigned char id; unsigned char stat; unsigned short port; unsigned int ip; } fls; } body; char zero[3]; char pef; } *

variable_types:
fls
struct addr *

variable_types:
stat
unsigned char

variable_types:
sid
unsigned short

user_defined_types: struct netpt7 { struct phead head; struct pbody7 body; char zero[3]; char pef; }

user_defined_types: struct pbody7 { unsigned char stat; char zero; unsigned short sid; struct addr fls; }


original_code:
static void netpt1_init(netpt1 *send, uint16_t sid, uint32_t uid, uint16_t num)
{
 bzero(send, sizeof(netpt1));
 pth_init(&(send->head),1, sizeof(netpt1), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->body.num = num;
 send->pef = 0X10;
}

canonical_original_code:
static void netpt1_init(struct netpt1 *send, unsigned short sid, unsigned int uid, unsigned short num)
{
 bzero(send, sizeof(netpt1));
 pth_init(&(send->head),1, sizeof(netpt1), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->body.num = num;
 send->pef = 0X10;
}

variable_types: struct netpt1 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody1 { unsigned int uid; unsigned short sid; unsigned short num; } body; char zero[3]; char pef; } *

variable_types:
uid
unsigned int

variable_types:
num
unsigned short

user_defined_types: struct netpt1 { struct phead head; struct pbody1 body; char zero[3]; char pef; }


decompiled_code:
__int64 __fastcall netpt3_init(_QWORD *a1, __int64 a2, int a3)
{
unsigned __int64 v4; // rdi
__int64 result; // rax
__int64 v6; // r8
__int16 v7; // r10
int v8; // er9

*a1 = 0LL;
v4 = (unsigned __int64)(a1 + 1);
*(_QWORD *)(v4 + 60) = 0LL;
memset((void *)(v4 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * (((unsigned int)a1 - (v4 & 0xFFFFFFF8) + 76) >> 3));
result = pth_init((__int64)a1, 3, 76, a3);
*(_WORD *)(v6 + 68) = v7;
*(_DWORD *)(v6 + 64) = v8;
*(_BYTE *)(v6 + 75) = 16;
return result;
}

original_code:
static void netpt3_init(netpt3 *send, uint16_t sid, uint32_t uid)
{
 bzero(send, sizeof(netpt3));
 pth_init(&(send->head),3, sizeof(netpt3), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->pef = 0X10;
}

canonical_original_code:
static void netpt3_init(struct netpt3 *send, unsigned short sid, unsigned int uid)
{
 bzero(send, sizeof(netpt3));
 pth_init(&(send->head),3, sizeof(netpt3), uid);
 send->body.sid = sid;
 send->body.uid = uid;
 send->pef = 0X10;
}

variable_types: struct netpt3 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody3 { unsigned int uid; unsigned short sid; char zero[2]; } body; char zero[3]; char pef; } *

user_defined_types: struct netpt3 { struct phead head; struct pbody3 body; char zero[3]; char pef; }


ntohpch

original_code:
static void ntohpch(phead *ptr)
{
 ptr->len = ntohs(ptr->len);
 ptr->subcmd = ntohs(ptr->subcmd);
 ptr->version = ntohs(ptr->version);
 ptr->uid = ntohl(ptr->uid);
 ptr->fls_id = ntohs(ptr->fls_id);
 ptr->fls_num = ntohs(ptr->fls_num);
}

canonical_original_code:
static void ntohpch(struct phead *ptr)
{
 ptr->len = ntohs(ptr->len);
 ptr->subcmd = ntohs(ptr->subcmd);
 ptr->version = ntohs(ptr->version);
 ptr->uid = ntohl(ptr->uid);
 ptr->fls_id = ntohs(ptr->fls_id);
 ptr->fls_num = ntohs(ptr->fls_num);
}

variable_types: struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } *


original_code:
static void htonpt1(netpt1 *ptr)
{
 htonpch(&(ptr->head));
 ptr->body.uid = htonl(ptr->body.uid);
 ptr->body.sid = htons(ptr->body.sid);
 ptr->body.num = htons(ptr->body.num);
}

canonical_original_code:
static void htonpt1(struct netpt1 *ptr)
{
 htonpch(&(ptr->head));
 ptr->body.uid = htonl(ptr->body.uid);
 ptr->body.sid = htons(ptr->body.sid);
 ptr->body.num = htons(ptr->body.num);
}

user_defined_types: struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; }

user_defined_types: struct pbody1 { unsigned int uid; unsigned short sid; unsigned short num; }


decompiled_code:
__int16 __fastcall htonpt3(__int64 a1)
{
__int64 v1; // rcx
int v2; // eax
__int64 v3; // rcx
__int16 v4; // di
__int16 result; // ax
__int64 v6; // rcx

ntohpch(a1);
v2 = _bswap_32(*(_DWORD *)(v1 + 64));
v4 = *(_WORD *)(v3 + 68);
*(_DWORD *)(v3 + 64) = v2;
result = _bswap_16(v4);
*(_WORD *)(v6 + 68) = result;
return result;
}

original_code:
static void htonpt3(netpt3 *ptr)
{
 htonpch(&(ptr->head));
 ptr->body.uid = htonl(ptr->body.uid);
 ptr->body.sid = htons(ptr->body.sid);
}

canonical_original_code:
static void htonpt3(struct netpt3 *ptr)
{
 htonpch(&(ptr->head));
 ptr->body.uid = htonl(ptr->body.uid);
 ptr->body.sid = htons(ptr->body.sid);
}

user_defined_types: struct pbody3 { unsigned int uid; unsigned short sid; char zero[2]; }


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

send_net7_constprop_0_isra_0();
result = recv_netpt(1);
if ( (_DWORD)result == 1 )
{
ntohpt8_constprop_0();
result = netpt2_check_constprop_0();
if ( !(_DWORD)result )
flsc_error = 15;
}
return result;
}

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

func17();
result = func5(1);
if ( (_DWORD)result == 1 )
{
func12();
result = func11();
if ( !(_DWORD)result )
flsc_error = 15;
}
return result;
}

original_code:
static void inform_disconn(flsunit * unit, uint16_t sid)
{
 send_net7(3, &(unit->server), &(manage_fls), sid);
 int stat = recv_netpt(1);
 if (stat == 1)
 {
  netpt8 *recv = (netpt8 *)readbuf;
  ntohpt8(recv);
  if (!netpt8_check(recv))
  {
   flsc_error = 15;
   return;
  }
  if (recv->head.subcmd == 8 && recv->body.op == 3)
   ;
 }
 return;
}

canonical_original_code:
static void inform_disconn(struct flsunit *unit, unsigned short sid)
{
 send_net7(3, &(unit->server), &(manage_fls), sid);
 int stat = recv_netpt(1);
 if (stat == 1)
 {
  struct netpt8 *recv = (netpt8 *)readbuf;
  ntohpt8(recv);
  if (!netpt8_check(recv))
  {
   flsc_error = 15;
   return;
  }
  if (recv->head.subcmd == 8 && recv->body.op == 3)
   ;
 }
 return;
}

variable_types: struct flsunit { struct addr { unsigned char id; unsigned char stat; unsigned short port; unsigned int ip; } server; int delaycount; int delaytime; long delaystart; } *

variable_types: struct netpt8 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody8 { unsigned char stat; unsigned char op; char zero[2]; } body; char zero[3]; char pef; } *

user_defined_types: struct netpt8 { struct phead head; struct pbody8 body; char zero[3]; char pef; }


decompiled_code:
__int64 __fastcall flsc_init(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
socklen_t v4; // edx
int v5; // er8

result = (unsigned int)client_stat;
if ( client_stat != 1 )
{
rflsl = 0LL;
dword_F34 = HIDWORD(a3);
DWORD1(rflsl) = HIDWORD(a3);
dword_2748 = 1;
qword_F70 = 0LL;
WORD1(rflsl) = WORD1(a3);
manage_fls = 0;
word_F32 = WORD1(a3);
sd = socket(2, 2, 0);
if ( sd < 0 )
{
flsc_error = 12;
result = 0LL;
}
else
{
LOWORD(cliaddr) = 2;
HIDWORD(cliaddr) = _bswap_32(0);
WORD1(cliaddr) = WORD1(a1);
if ( bind(v5, (const struct sockaddr *)&cliaddr, v4) < 0 )
{
flsc_error = 13;
result = 0LL;
}
else
{
cliaddr = a1;
result = 1LL;
qword_F28 = a2;
client_stat = 1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
socklen_t v4; // edx
int v5; // er8

result = (unsigned int)client_stat;
if ( client_stat != 1 )
{
rflsl = 0LL;
dword_F34 = HIDWORD(a3);
DWORD1(rflsl) = HIDWORD(a3);
dword_2748 = 1;
qword_F70 = 0LL;
WORD1(rflsl) = WORD1(a3);
manage_fls = 0;
word_F32 = WORD1(a3);
sd = socket(2, 2, 0);
if ( sd < 0 )
{
flsc_error = 12;
result = 0LL;
}
else
{
LOWORD(cliaddr) = 2;
HIDWORD(cliaddr) = func4(0);
WORD1(cliaddr) = WORD1(a1);
if ( bind(v5, (const struct sockaddr *)&cliaddr, v4) < 0 )
{
flsc_error = 13;
result = 0LL;
}
else
{
cliaddr = a1;
result = 1LL;
qword_F28 = a2;
client_stat = 1;
}
}
}
return result;
}

original_code:
int flsc_init(struct sockaddr_in local, struct sockaddr_in server)
{
 if (client_stat == 1)
  return 1;
 rflsl.len = 1;
 bzero(rflsl.list, sizeof(flsunit));
 rflsl.list[0].server.id = 0;
 rflsl.list[0].server.ip = server.sin_addr.s_addr;
 rflsl.list[0].server.port = server.sin_port;
 manage_fls.id = 0;
 manage_fls.ip = server.sin_addr.s_addr;
 manage_fls.port = server.sin_port;
 if ((sd = socket(2, SOCK_DGRAM, 0)) < 0)
 {
  flsc_error = 12;
  return 0;
 }
 cliaddr.sin_family = 2;
 cliaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 cliaddr.sin_port = local.sin_port;
 if (bind(sd, (struct sockaddr *) &cliaddr, sizeof(cliaddr)) < 0)
 {
  flsc_error = 13;
  return 0;
 }
 cliaddr = local;
 client_stat = 1;
 return 1;
}

canonical_original_code:
int flsc_init(struct sockaddr_in local, struct sockaddr_in server)
{
 if (client_stat == 1)
  return 1;
 rflsl.len = 1;
 bzero(rflsl.list, sizeof(flsunit));
 rflsl.list[0].server.id = 0;
 rflsl.list[0].server.ip = server.sin_addr.s_addr;
 rflsl.list[0].server.port = server.sin_port;
 manage_fls.id = 0;
 manage_fls.ip = server.sin_addr.s_addr;
 manage_fls.port = server.sin_port;
 if ((sd = socket(2, SOCK_DGRAM, 0)) < 0)
 {
  flsc_error = 12;
  return 0;
 }
 cliaddr.sin_family = 2;
 cliaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 cliaddr.sin_port = local.sin_port;
 if (bind(sd, (struct sockaddr *) &cliaddr, sizeof(cliaddr)) < 0)
 {
  flsc_error = 13;
  return 0;
 }
 cliaddr = local;
 client_stat = 1;
 return 1;
}

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:
server
struct sockaddr_in

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall flsc_freq_query(unsigned __int16 a1, unsigned int a2, __m128i *a3)
{
__int64 result; // rax

result = (unsigned int)client_stat;
if ( !client_stat )
{
flsc_error = 11;
return result;
}
if ( !*((_DWORD *)&rflsl + 6 * (a2 % dword_2748) + 3) )
{
send_net3_isra_0(a1, a2);
if ( (unsigned int)recv_netpt(a2) == 1 )
{
ntohpt4_constprop_0();
result = netpt2_check_constprop_0();
if ( !(_DWORD)result )
{
flsc_error = 15;
return result;
}
if ( (_BYTE)word_B60 )
{
*a3 = _mm_loadu_si128((const __m128i *)&xmmword_B68);
a3[1].m128i_i64[0] = qword_B78;
return 1LL;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func23(unsigned __int16 a1, unsigned int a2, __m128i *a3)
{
__int64 result; // rax

result = (unsigned int)client_stat;
if ( !client_stat )
{
flsc_error = 11;
return result;
}
if ( !*((_DWORD *)&rflsl + 6 * (a2 % dword_2748) + 3) )
{
func19(a1, a2);
if ( (unsigned int)func5(a2) == 1 )
{
func14();
result = func11();
if ( !(_DWORD)result )
{
flsc_error = 15;
return result;
}
if ( (_BYTE)word_B60 )
{
*a3 = _mm_loadu_si128((const __m128i *)&xmmword_B68);
a3[1].m128i_i64[0] = qword_B78;
return 1LL;
}
}
}
return 0LL;
}

original_code:
int flsc_freq_query(uint16_t sid, uint32_t uid, struct flsc_freqdata * freqd)
{
 if (client_stat == 0)
 {
  flsc_error = 11;
  return 0;
 }
 flsunit *unit = rflsl.list + uid % rflsl.len;
 if (unit->delaytime)
 {
  return 0;
 }
 send_net3(sid, uid, &(unit->server));
 if (recv_netpt(uid) == 1)
 {
  netpt4 *recv = (netpt4 *)readbuf;
  ntohpt4(recv);
  if (!netpt4_check(recv))
  {
   flsc_error = 15;
   return 0;
  }
  if (((netpt4 *)readbuf)->body.stat)
  {
   *freqd = ((netpt4 *)readbuf)->body.freqd;
   return 1;
  }
  else
  {
   return 0;
  }
 }
 else
 {
  return 0;
 }
 return 0;
}

canonical_original_code:
int flsc_freq_query(unsigned short sid, unsigned int uid, struct flsc_freqdata *freqd)
{
 if (client_stat == 0)
 {
  flsc_error = 11;
  return 0;
 }
 struct flsunit *unit = rflsl.list + uid % rflsl.len;
 if (unit->delaytime)
 {
  return 0;
 }
 send_net3(sid, uid, &(unit->server));
 if (recv_netpt(uid) == 1)
 {
  struct netpt4 *recv = (netpt4 *)readbuf;
  ntohpt4(recv);
  if (!netpt4_check(recv))
  {
   flsc_error = 15;
   return 0;
  }
  if (((struct netpt4 *)readbuf)->body.stat)
  {
   *freqd = ((struct netpt4 *)readbuf)->body.freqd;
   return 1;
  }
  else
  {
   return 0;
  }
 }
 else
 {
  return 0;
 }
 return 0;
}

variable_types: struct flsc_freqdata { unsigned int timel1; unsigned int limdl1; unsigned int counterl1; unsigned int timel2; unsigned int limdl2; unsigned int counterl2; } *

variable_types: struct netpt4 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody4 { unsigned char stat; char zero; unsigned short sid; unsigned int uid; struct flsc_freqdata { unsigned int timel1; unsigned int limdl1; unsigned int counterl1; unsigned int timel2; unsigned int limdl2; unsigned int counterl2; } freqd; } body; char zero[3]; char pef; } *

user_defined_types: struct netpt4 { struct phead head; struct pbody4 body; char zero[3]; char pef; }

user_defined_types: struct addr { unsigned char id; unsigned char stat; unsigned short port; unsigned int ip; }

user_defined_types: struct pbody4 { unsigned char stat; char zero; unsigned short sid; unsigned int uid; struct flsc_freqdata freqd; }


decompiled_code:
__int64 __fastcall recv_netpt(int a1)
{
int v1; // er13
int v3; // edi
int v4; // eax
unsigned int v5; // er15
struct timeval v7; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

v1 = 3;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v3 = sd;
v7.tv_sec = 0LL;
v7.tv_usec = 10000LL;
readfds.fds_bits[sd / 64] |= 1LL << (sd % 64);
v4 = select(v3 + 1, &readfds, 0LL, 0LL, &v7);
v5 = v4;
if ( v4 == -1 )
{
flsc_error = 18;
return v5;
}
if ( !v4 )
break;
if ( (readfds.fds_bits[sd / 64] & (1LL << (sd % 64))) == 0 )
return v5;
recvfrom(sd, &readbuf, 0x3E8uLL, 0, &servaddr, &len);
if ( (unsigned int)_bswap_32(dword_B28) == a1 )
return 1;
if ( !--v1 )
return v5;
}
flsc_error = 14;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // er13
int v3; // edi
int v4; // eax
unsigned int v5; // er15
struct timeval v7; // [rsp+0h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-B8h] BYREF

v1 = 3;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v3 = sd;
v7.tv_sec = 0LL;
v7.tv_usec = 10000LL;
readfds.fds_bits[sd / 64] |= 1LL << (sd % 64);
v4 = select(v3 + 1, &readfds, 0LL, 0LL, &v7);
v5 = v4;
if ( v4 == -1 )
{
flsc_error = 18;
return v5;
}
if ( !v4 )
break;
if ( (readfds.fds_bits[sd / 64] & (1LL << (sd % 64))) == 0 )
return v5;
recvfrom(sd, &readbuf, 0x3E8uLL, 0, &servaddr, &len);
if ( (unsigned int)func4(dword_B28) == a1 )
return 1;
if ( !--v1 )
return v5;
}
flsc_error = 14;
return v5;
}

original_code:
static int recv_netpt(uint32_t uid)
{
 fd_set read_set;
 struct timeval timeout;
 int stat;
 int i;
 for (i = 3; i > 0; --i)
 {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_set)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
  timeout.tv_sec = 0;
  timeout.tv_usec = 10000;
  stat = select(sd+1, &read_set, ((void *)0), ((void *)0), &timeout);
  if (stat == -1)
  {
   flsc_error = 18;
   return stat;
  }
  else if (stat == 0)
  {
   flsc_error = 14;
   return stat;
  }
  else if (((((&read_set)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   recvfrom(sd, (void *)readbuf, 1000, 0, (struct sockaddr *)&servaddr, &len);
   uint32_t id = ntohl(*(uint32_t *)(((char *)readbuf + 8)));
   if (id != uid)
   {
    continue;
   }
   else
   {
    return 1;
   }
  }
  else
  {
   break;
  }
 }
 return stat;
}

canonical_original_code:
static int recv_netpt(unsigned int uid)
{
 struct fd_set read_set;
 struct timeval timeout;
 int stat;
 int i;
 for (i = 3; i > 0; --i)
 {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_set)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
  timeout.tv_sec = 0;
  timeout.tv_usec = 10000;
  stat = select(sd+1, &read_set, ((void *)0), ((void *)0), &timeout);
  if (stat == -1)
  {
   flsc_error = 18;
   return stat;
  }
  else if (stat == 0)
  {
   flsc_error = 14;
   return stat;
  }
  else if (((((&read_set)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
  {
   recvfrom(sd, (void *)readbuf, 1000, 0, (struct sockaddr *)&servaddr, &len);
   unsigned int id = ntohl(*(uint32_t *)(((char *)readbuf + 8)));
   if (id != uid)
   {
    continue;
   }
   else
   {
    return 1;
   }
  }
  else
  {
   break;
  }
 }
 return stat;
}

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

variable_types: i int

variable_types:
id
unsigned int


decompiled_code:
__int64 __fastcall is_prime_num(int a1)
{
double v1; // xmm0_8
int v2; // esi
int v3; // ecx
unsigned int v4; // edx
int v6; // esi
int v7; // ecx
unsigned int v8; // edx

v1 = (double)a1;
if ( (double)a1 >= 0.0 )
{
v2 = (int)sqrt(v1);
if ( v2 > 1 )
{
if ( (a1 & 1) == 0 )
return 0;
v3 = 2;
while ( v2 >= ++v3 )
{
v4 = a1 % v3;
if ( !(a1 % v3) )
return v4;
}
}
return 1;
}
v6 = (int)sqrt(v1);
if ( v6 > 1 )
{
if ( (a1 & 1) == 0 )
return 0;
v7 = 2;
while ( v6 >= ++v7 )
{
v8 = a1 % v7;
if ( !(a1 % v7) )
return v8;
}
}
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
double v1; // xmm0_8
int v2; // esi
int v3; // ecx
unsigned int v4; // edx
int v6; // esi
int v7; // ecx
unsigned int v8; // edx

v1 = (double)a1;
if ( (double)a1 >= 0.0 )
{
v2 = (int)sqrt(v1);
if ( v2 > 1 )
{
if ( (a1 & 1) == 0 )
return 0;
v3 = 2;
while ( v2 >= ++v3 )
{
v4 = a1 % v3;
if ( !(a1 % v3) )
return v4;
}
}
return 1;
}
v6 = (int)sqrt(v1);
if ( v6 > 1 )
{
if ( (a1 & 1) == 0 )
return 0;
v7 = 2;
while ( v6 >= ++v7 )
{
v8 = a1 % v7;
if ( !(a1 % v7) )
return v8;
}
}
return 1;
}

original_code:
static int is_prime_num(int x)
{
 int i, s;
 s = (int)sqrt(x * 1.0);
 for (i = 2; i <= s; ++i)
 {
  if (!(x % i))
   return 0;
 }
 return 1;
}

canonical_original_code:
static int is_prime_num(int x)
{
 int i; int s;
 s = (int)sqrt(x * 1.0);
 for (i = 2; i <= s; ++i)
 {
  if (!(x % i))
   return 0;
 }
 return 1;
}

variable_types: x int

variable_types: s int


decompiled_code:
void __fastcall prnum_init(int a1, int a2)
{
__int64 i; // rbp
int v4; // eax
int v5; // edx

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; prime_num[i++] = v5 )
{
do
{
v4 = is_prime_num(a1);
v5 = a1--;
}
while ( !v4 );
}
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
__int64 i; // rbp
int v4; // eax
int v5; // edx

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; prime_num[i++] = v5 )
{
do
{
v4 = func0(a1);
v5 = a1--;
}
while ( !v4 );
}
}
}

original_code:
static void prnum_init(int max, int dimen)
{
 int i, n = max;
 for (i = 0; i < dimen; ++i)
 {
  do
  {
   if (is_prime_num(n))
   {
    prime_num[i] = n;
    --n;
    break;
   }
   --n;
  }
  while (1);
 }
}

canonical_original_code:
static void prnum_init(int max, int dimen)
{
 int i; int n = max;
 for (i = 0; i < dimen; ++i)
 {
  do
  {
   if (is_prime_num(n))
   {
    prime_num[i] = n;
    --n;
    break;
   }
   --n;
  }
  while (1);
 }
}

variable_types: max int

variable_types: dimen int

variable_types: n int


decompiled_code:
void *shamem_creat()
{
int v0; // ebx
void *v1; // r12

v0 = shmget(0, size, 384);
if ( v0 < 0 )
err_exit("In shamem_creat: shmget error");
v1 = shmat(v0, 0LL, 0);
if ( v1 == (void *)-1LL )
err_exit("In shamem_creat: shmat error");
setconf1("shamemsize", size);
setconf2("shamemid", _id_offset, v0);
return v1;
}

canonical_decompiled_code:
void *func2()
{
int v0; // ebx
void *v1; // r12

v0 = shmget(0, size, 384);
if ( v0 < 0 )
err_exit("In shamem_creat: shmget error");
v1 = shmat(v0, 0LL, 0);
if ( v1 == (void *)-1LL )
err_exit("In shamem_creat: shmat error");
setconf1("shamemsize", size);
setconf2("shamemid", _id_offset, v0);
return v1;
}

original_code:
static void *shamem_creat()
{
 void *shmptr;
 int shmid;
 if ((shmid = shmget(((__key_t) 0), shamem.size, 0600)) < 0)
  err_exit("In shamem_creat: shmget error");
 if ((shmptr = shmat(shmid, ((void *)0), 0)) == (void *)-1)
  err_exit("In shamem_creat: shmat error");
 setconf1("shamemsize", shamem.size);
 setconf2("shamemid", __id_offset, shmid);
 return shmptr;
}

canonical_original_code:
static void *shamem_creat()
{
 void *shmptr;
 int shmid;
 if ((shmid = shmget(((int) 0), shamem.size, 0600)) < 0)
  err_exit("In shamem_creat: shmget error");
 if ((shmptr = shmat(shmid, ((void *)0), 0)) == (void *)-1)
  err_exit("In shamem_creat: shmat error");
 setconf1("shamemsize", shamem.size);
 setconf2("shamemid", __id_offset, shmid);
 return shmptr;
}

variable_types:
shmptr
void *

variable_types: shmid int

return_type: void *


decompiled_code:
void *shamem_get()
{
int v0; // eax
int v1; // ebx
void *v2; // r12
struct shmid_ds v4; // [rsp+0h] [rbp-88h] BYREF

v0 = getconf2("shamemid", _id_offset);
if ( !v0 )
return shamem_creat();
v1 = v0;
v2 = shmat(v0, 0LL, 0);
if ( v2 == (void *)-1LL )
return shamem_creat();
shmctl(v1, 2, &v4);
if ( v4.shm_segsz == size )
return v2;
shmctl(v1, 0, 0LL);
return shamem_creat();
}

canonical_decompiled_code:
void *func3()
{
int v0; // eax
int v1; // ebx
void *v2; // r12
struct shmid_ds v4; // [rsp+0h] [rbp-88h] BYREF

v0 = getconf2("shamemid", _id_offset);
if ( !v0 )
return func2();
v1 = v0;
v2 = shmat(v0, 0LL, 0);
if ( v2 == (void *)-1LL )
return func2();
shmctl(v1, 2, &v4);
if ( v4.shm_segsz == size )
return v2;
shmctl(v1, 0, 0LL);
return func2();
}

original_code:
static void *shamem_get()
{
 void *shmptr = ((void *)0);
 int shmid;
 if ((shmid = (int)getconf2("shamemid", __id_offset)) == 0)
 {
  return shamem_creat();
 }
 else if ((shmptr = shmat(shmid, 0, 0)) == (void *)-1)
 {
  return shamem_creat();
 }
 else
 {
  struct shmid_ds buf;
  shmctl(shmid, 2, &buf);
  if (buf.shm_segsz != shamem.size)
  {
   shmctl(shmid, 0, ((void *)0));
   return shamem_creat();
  }
 }
 return shmptr;
}

variable_types: struct shmid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } shm_perm; unsigned long shm_segsz; long shm_atime; long shm_dtime; long shm_ctime; int shm_cpid; int shm_lpid; unsigned long shm_nattch; unsigned long __glibc_reserved4; unsigned long __glibc_reserved5; }

user_defined_types: struct shmid_ds { struct ipc_perm shm_perm; unsigned long shm_segsz; long shm_atime; long shm_dtime; long shm_ctime; int shm_cpid; int shm_lpid; unsigned long shm_nattch; unsigned long __glibc_reserved4; unsigned long __glibc_reserved5; }


decompiled_code:
void __fastcall shamem_init(__int64 a1, __int64 a2)
{
int v2; // ebx
size_t v3; // rdi
__int64 v4; // rax
int v5; // esi
__int64 v6; // rcx
void *v7; // rbx
__int64 v8; // rsi
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rcx

if ( shamem_status == 1 )
return;
dword_A44 = getconf1("hashlinemax");
if ( dword_A44 )
{
if ( dword_A44 > 9999 )
goto LABEL_4;
goto LABEL_18;
}
err_exit("IN shamem_init: the value of hashlinemaxlen is illegal", a2, (unsigned int)dword_A44);
if ( dword_A44 <= 9999 )
LABEL_18:
err_exit("In shamem_init: the value of hashlinemaxlen should bigger than %d", 10000LL);
LABEL_4:
dword_A40 = getconf1("hashdimen");
v2 = dword_A40;
if ( !dword_A40 )
{
err_exit("IN shamem_init: the value of hashdimen is illegal");
v2 = dword_A40;
if ( dword_A40 <= 100 )
goto LABEL_6;
goto LABEL_15;
}
if ( dword_A40 > 100 )
{
LABEL_15:
err_exit("In shamem_init: the value of hashdimen should less than %d", 100LL);
v2 = dword_A40;
}
LABEL_6:
v3 = (unsigned int)dword_A44;
prnum_init(dword_A44, v2);
size = 0LL;
dword_A50 = 0;
if ( v2 > 0 )
{
v4 = 0LL;
v5 = 0;
v3 = 0LL;
do
{
v6 = prime_num[v4++];
v3 += 36 * v6;
v5 += v6;
}
while ( v4 != v2 );
size = v3;
dword_A50 = v5;
}
v7 = shamem_get();
if ( !v7 )
{
v3 = (size_t)"In shamem_init: share memory get error";
err_exit("In shamem_init: share memory get error");
}
v8 = dword_A40;
v9 = 0LL;
v10 = 0LL;
if ( dword_A40 > 0 )
{
do
{
v11 = (int)v10;
v10 = (unsigned int)(prime_num[v9] + v10);
shamem[v9++] = (__int64)v7 + 36 * v11;
}
while ( v8 != v9 );
}
limit_init(v3, v8, v10);
shamem_status = 1;
unit_livet = timel2 + 1;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebx
size_t v3; // rdi
__int64 v4; // rax
int v5; // esi
__int64 v6; // rcx
void *v7; // rbx
__int64 v8; // rsi
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11; // rcx

if ( shamem_status == 1 )
return;
dword_A44 = getconf1("hashlinemax");
if ( dword_A44 )
{
if ( dword_A44 > 9999 )
goto LABEL_4;
goto LABEL_18;
}
err_exit("IN shamem_init: the value of hashlinemaxlen is illegal", a2, (unsigned int)dword_A44);
if ( dword_A44 <= 9999 )
LABEL_18:
err_exit("In shamem_init: the value of hashlinemaxlen should bigger than %d", 10000LL);
LABEL_4:
dword_A40 = getconf1("hashdimen");
v2 = dword_A40;
if ( !dword_A40 )
{
err_exit("IN shamem_init: the value of hashdimen is illegal");
v2 = dword_A40;
if ( dword_A40 <= 100 )
goto LABEL_6;
goto LABEL_15;
}
if ( dword_A40 > 100 )
{
LABEL_15:
err_exit("In shamem_init: the value of hashdimen should less than %d", 100LL);
v2 = dword_A40;
}
LABEL_6:
v3 = (unsigned int)dword_A44;
func1(dword_A44, v2);
size = 0LL;
dword_A50 = 0;
if ( v2 > 0 )
{
v4 = 0LL;
v5 = 0;
v3 = 0LL;
do
{
v6 = prime_num[v4++];
v3 += 36 * v6;
v5 += v6;
}
while ( v4 != v2 );
size = v3;
dword_A50 = v5;
}
v7 = func3();
if ( !v7 )
{
v3 = (size_t)"In shamem_init: share memory get error";
err_exit("In shamem_init: share memory get error");
}
v8 = dword_A40;
v9 = 0LL;
v10 = 0LL;
if ( dword_A40 > 0 )
{
do
{
v11 = (int)v10;
v10 = (unsigned int)(prime_num[v9] + v10);
shamem[v9++] = (__int64)v7 + 36 * v11;
}
while ( v8 != v9 );
}
limit_init(v3, v8, v10);
shamem_status = 1;
unit_livet = timel2 + 1;
}

original_code:
void shamem_init(void)
{
 if (shamem_status == 1)
  return;
 if ((shamem.len = (int)getconf1("hashlinemax")) == 0)
  err_exit("IN shamem_init: the value of hashlinemaxlen is illegal");
 if (shamem.len < 10000)
  err_exit("In shamem_init: the value of hashlinemaxlen should bigger than %d", 10000);
 if ((shamem.dimen = (int)getconf1("hashdimen")) == 0)
  err_exit("IN shamem_init: the value of hashdimen is illegal");
 if (shamem.dimen > 100)
  err_exit("In shamem_init: the value of hashdimen should less than %d", 100);
 prnum_init(shamem.len, shamem.dimen);
 shamem.num = shamem.size = 0;
 int i;
 for (i = 0; i < shamem.dimen; ++i)
 {
  shamem.size += prime_num[i] * sizeof(recunit);
  shamem.num += prime_num[i];
 }
 void *shmptr;
 if ((shmptr = shamem_get()) == ((void *)0))
  err_exit("In shamem_init: share memory get error");
 int sum_pass = 0;
 for (i = 0; i < shamem.dimen; ++i)
 {
  shamem.p[i] = shmptr + sum_pass * sizeof(recunit);
  sum_pass += prime_num[i];
 }
 limit_init();
 unit_livet = timel2 + 1;
 shamem_status = 1;
 return;
}

canonical_original_code:
void shamem_init()
{
 if (shamem_status == 1)
  return;
 if ((shamem.len = (int)getconf1("hashlinemax")) == 0)
  err_exit("IN shamem_init: the value of hashlinemaxlen is illegal");
 if (shamem.len < 10000)
  err_exit("In shamem_init: the value of hashlinemaxlen should bigger than %d", 10000);
 if ((shamem.dimen = (int)getconf1("hashdimen")) == 0)
  err_exit("IN shamem_init: the value of hashdimen is illegal");
 if (shamem.dimen > 100)
  err_exit("In shamem_init: the value of hashdimen should less than %d", 100);
 prnum_init(shamem.len, shamem.dimen);
 shamem.num = shamem.size = 0;
 int i;
 for (i = 0; i < shamem.dimen; ++i)
 {
  shamem.size += prime_num[i] * sizeof(recunit);
  shamem.num += prime_num[i];
 }
 void *shmptr;
 if ((shmptr = shamem_get()) == ((void *)0))
  err_exit("In shamem_init: share memory get error");
 int sum_pass = 0;
 for (i = 0; i < shamem.dimen; ++i)
 {
  shamem.p[i] = shmptr + sum_pass * sizeof(recunit);
  sum_pass += prime_num[i];
 }
 limit_init();
 unit_livet = timel2 + 1;
 shamem_status = 1;
 return;
}


decompiled_code:
__int64 __fastcall hash_search(__int64 a1, __int64 a2, __int64 a3)
{
__int16 v4; // bx
unsigned int v5; // edi
__int64 v6; // rcx
__int64 result; // rax
__int64 v8; // rcx

v4 = a1;
if ( !shamem_status )
shamem_init(a1, a2);
v5 = a2 ^ (unsigned __int16)a1;
if ( dword_A40 <= 0 )
return 0LL;
v6 = 0LL;
while ( 1 )
{
result = shamem[v6] + 36LL * (v5 % prime_num[v6]);
if ( !*(_BYTE *)result || *(_WORD *)(result + 2) == v4 && *(_DWORD *)(result + 4) == (_DWORD)a2 )
break;
if ( dword_A40 == ++v6 )
{
v8 = 0LL;
while ( 1 )
{
result = shamem[v8] + 36LL * (v5 % prime_num[v8]);
if ( a3 - *(_QWORD *)(result + 16) > unit_livet )
break;
if ( dword_A40 == ++v8 )
return 0LL;
}
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int16 v4; // bx
unsigned int v5; // edi
__int64 v6; // rcx
__int64 result; // rax
__int64 v8; // rcx

v4 = a1;
if ( !shamem_status )
func4(a1, a2);
v5 = a2 ^ (unsigned __int16)a1;
if ( dword_A40 <= 0 )
return 0LL;
v6 = 0LL;
while ( 1 )
{
result = shamem[v6] + 36LL * (v5 % prime_num[v6]);
if ( !*(_BYTE *)result || *(_WORD *)(result + 2) == v4 && *(_DWORD *)(result + 4) == (_DWORD)a2 )
break;
if ( dword_A40 == ++v6 )
{
v8 = 0LL;
while ( 1 )
{
result = shamem[v8] + 36LL * (v5 % prime_num[v8]);
if ( a3 - *(_QWORD *)(result + 16) > unit_livet )
break;
if ( dword_A40 == ++v8 )
return 0LL;
}
return result;
}
}
return result;
}

original_code:
recunit *hash_search(uint16_t sid, uint32_t uid, time_t now)
{
 if (shamem_status == 0)
 {
  shamem_init();
 }
 int n = 0;
 recunit * p;
 uint32_t key = sid ^ uid;
 while (n < shamem.dimen)
 {
  p = (shamem.p[n]) + (key % prime_num[n]);
  if (p->sign == 0X00)
  {
   return p;
  }
  else if ((p->sid == sid) && (p->uid == uid))
  {
   return p;
  }
  else
  {
   ++n;
  }
 }
 n = 0;
 while (n < shamem.dimen)
 {
  p = (shamem.p[n]) + (key % prime_num[n]);
  if ((now - p->timel2) > unit_livet)
  {
   return p;
  }
  else
  {
   ++n;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct recunit *hash_search(unsigned short sid, unsigned int uid, long now)
{
 if (shamem_status == 0)
 {
  shamem_init();
 }
 int n = 0;
 struct recunit *p;
 unsigned int key = sid ^ uid;
 while (n < shamem.dimen)
 {
  p = (shamem.p[n]) + (key % prime_num[n]);
  if (p->sign == 0X00)
  {
   return p;
  }
  else if ((p->sid == sid) && (p->uid == uid))
  {
   return p;
  }
  else
  {
   ++n;
  }
 }
 n = 0;
 while (n < shamem.dimen)
 {
  p = (shamem.p[n]) + (key % prime_num[n]);
  if ((now - p->timel2) > unit_livet)
  {
   return p;
  }
  else
  {
   ++n;
  }
 }
 return ((void *)0);
}

variable_types:
sid
unsigned short

variable_types:
uid
unsigned int

variable_types: now long

variable_types: struct recunit { unsigned char sign; unsigned char version; unsigned short sid; unsigned int uid; long timel1; long timel2; unsigned int counterl1; unsigned int counterl2; unsigned int allowedl2; } *

variable_types:
key
unsigned int


decompiled_code:
__int64 memuse_rate()
{
__int64 v0; // rbx
time_t v1; // rax
time_t v2; // r8
int v3; // esi
__int64 v4; // rax
int v5; // edx
float v6; // xmm0_4

v0 = shamem[0];
v1 = time(0LL);
if ( dword_A50 <= 0 )
{
v6 = 0.0;
}
else
{
v2 = v1;
v3 = 0;
v4 = v0;
v5 = 0;
do
{
if ( *(_BYTE *)v4 )
v3 += v2 - *(_QWORD *)(v4 + 16) < unit_livet;
v5 += 100;
v4 += 3600LL;
}
while ( v5 < dword_A50 );
v6 = (float)v3 * 100.0;
}
return run_msg("share memory use rate = %.4f", (float)(v6 / (float)dword_A50));
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
time_t v1; // rax
time_t v2; // r8
int v3; // esi
__int64 v4; // rax
int v5; // edx
float v6; // xmm0_4

v0 = shamem[0];
v1 = time(0LL);
if ( dword_A50 <= 0 )
{
v6 = 0.0;
}
else
{
v2 = v1;
v3 = 0;
v4 = v0;
v5 = 0;
do
{
if ( *(_BYTE *)v4 )
v3 += v2 - *(_QWORD *)(v4 + 16) < unit_livet;
v5 += 100;
v4 += 3600LL;
}
while ( v5 < dword_A50 );
v6 = (float)v3 * 100.0;
}
return run_msg("share memory use rate = %.4f", (float)(v6 / (float)dword_A50));
}

original_code:
void memuse_rate(void)
{
 int samsur = 100;
 recunit *p = shamem.p[0];
 int i, counter = 0;
 time_t now = time(((void *)0));
 for (i = 0; i < shamem.num; i = i + samsur)
  if ((p + i)->sign && (now - (p + i)->timel2) < unit_livet)
   ++counter;
 float userate = ((float)counter * samsur)/ shamem.num;
 run_msg("share memory use rate = %.4f", userate);
 return;
}

canonical_original_code:
void memuse_rate()
{
 int samsur = 100;
 struct recunit *p = shamem.p[0];
 int i; int counter = 0;
 long now = time(((void *)0));
 for (i = 0; i < shamem.num; i = i + samsur)
  if ((p + i)->sign && (now - (p + i)->timel2) < unit_livet)
   ++counter;
 float userate = ((float)counter * samsur)/ shamem.num;
 run_msg("share memory use rate = %.4f", userate);
 return;
}

variable_types: samsur int

variable_types: counter int

variable_types: userate float

user_defined_types: struct recunit { unsigned char sign; unsigned char version; unsigned short sid; unsigned int uid; long timel1; long timel2; unsigned int counterl1; unsigned int counterl2; unsigned int allowedl2; }


getname

decompiled_code:
char *getname()
{
unsigned int v0; // ebx
char *v1; // rax

v0 = _id_offset;
v1 = getenv("HOME");
sprintf(name, "%s%s%s%d%s", v1, "/wb/fls/data/", "flsmemory", v0, ".backup");
return name;
}

canonical_decompiled_code:
char *func0()
{
unsigned int v0; // ebx
char *v1; // rax

v0 = _id_offset;
v1 = getenv("HOME");
sprintf(name, "%s%s%s%d%s", v1, "/wb/fls/data/", "flsmemory", v0, ".backup");
return name;
}

original_code:
char * getname(void)
{
 sprintf(name, "%s%s%s%d%s", getenv("HOME"), location, head, __id_offset, tail);
 return name;
}

canonical_original_code:
char *getname()
{
 sprintf(name, "%s%s%s%d%s", getenv("HOME"), location, head, __id_offset, tail);
 return name;
}


decompiled_code:
void __noreturn err_exit(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
fputs(s, stderr);
putc(10, stderr);
fflush(0LL);
addto_log(1LL, s);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
fputs(s, stderr);
putc(10, stderr);
fflush(0LL);
addto_log(1LL, s);
exit(1);
}

original_code:
void err_exit(const char *fmt, ...)
{
 char buf[1024];
 va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, 1024, fmt, ap);
 __builtin_va_end(ap);
 fputs(buf, stderr);
 putc('\n', stderr);
 fflush(((void *)0));
 addto_log(1, buf);
 exit(1);
}

canonical_original_code:
void err_exit(char *fmt, ...)
{
 char buf[1024];
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, 1024, fmt, ap);
 __builtin_va_end(ap);
 fputs(buf, stderr);
 putc('\n', stderr);
 fflush(((void *)0));
 addto_log(1, buf);
 exit(1);
}

variable_types:
fmt
char *

variable_types:
buf
char [1024]


decompiled_code:
__int64 run_msg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
if ( _msg_stdout_switch )
{
fputs(s, stdout);
putc(10, stdout);
fflush(0LL);
}
return addto_log(1LL, s);
}

canonical_decompiled_code:
__int64 func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4D0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
if ( _msg_stdout_switch )
{
fputs(s, stdout);
putc(10, stdout);
fflush(0LL);
}
return addto_log(1LL, s);
}

original_code:
void run_msg(const char *fmt, ...)
{
 char buf[1024];
 va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, 1024, fmt, ap);
 __builtin_va_end(ap);
 extern int __msg_stdout_switch;
 if (__msg_stdout_switch)
 {
  fputs(buf, stdout);
  putc('\n', stdout);
  fflush(((void *)0));
 }
 addto_log(1, buf);
}

canonical_original_code:
void run_msg(char *fmt, ...)
{
 char buf[1024];
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, 1024, fmt, ap);
 __builtin_va_end(ap);
 extern int __msg_stdout_switch;
 if (__msg_stdout_switch)
 {
  fputs(buf, stdout);
  putc('\n', stdout);
  fflush(((void *)0));
 }
 addto_log(1, buf);
}


limducom

decompiled_code:
__int64 __fastcall limducom(const void *a1, const void *a2)
{
return *(unsigned __int16 *)a1 - (unsigned int)*(unsigned __int16 *)a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return *(unsigned __int16 *)a1 - (unsigned int)*(unsigned __int16 *)a2;
}

original_code:
static int limducom(const void * p1, const void * p2)
{
 return (((struct limit_unit *)p1)->sid - ((struct limit_unit *)p2)->sid);
}

canonical_original_code:
static int limducom(void *p1, void *p2)
{
 return (((struct limit_unit *)p1)->sid - ((struct limit_unit *)p2)->sid);
}

user_defined_types: struct limit_unit { unsigned short sid; unsigned int limit[2]; }


decompiled_code:
__int64 __fastcall addto_limd(__int16 a1, int a2, int a3)
{
__int64 result; // rax
__int16 v4; // [rsp+4h] [rbp-14h] BYREF
int v5; // [rsp+8h] [rbp-10h]
int v6; // [rsp+Ch] [rbp-Ch]

v4 = a1;
v5 = a2;
v6 = a3;
result = add_item((__int64)&v4);
if ( (_DWORD)result )
{
qsort(&limd, dword_30A0, 0xCuLL, (__compar_fn_t)limducom);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, int a2, int a3)
{
__int64 result; // rax
__int16 v4; // [rsp+4h] [rbp-14h] BYREF
int v5; // [rsp+8h] [rbp-10h]
int v6; // [rsp+Ch] [rbp-Ch]

v4 = a1;
v5 = a2;
v6 = a3;
result = func1((__int64)&v4);
if ( (_DWORD)result )
{
qsort(&limd, dword_30A0, 0xCuLL, (__compar_fn_t)limducom);
result = 1LL;
}
return result;
}

original_code:
int addto_limd(uint16_t sid, uint32_t lim1, uint32_t lim2)
{
 struct limit_unit temp;
 temp.sid = sid;
 temp.limit[0] = lim1;
 temp.limit[1] = lim2;
 if (!add_item(&temp))
  return 0;
 qsort(limd.list, limd.len, sizeof(struct limit_unit), limducom);
 return 1;
}

canonical_original_code:
int addto_limd(unsigned short sid, unsigned int lim1, unsigned int lim2)
{
 struct limit_unit temp;
 temp.sid = sid;
 temp.limit[0] = lim1;
 temp.limit[1] = lim2;
 if (!add_item(&temp))
  return 0;
 qsort(limd.list, limd.len, sizeof(struct limit_unit), limducom);
 return 1;
}

variable_types: struct limit_unit { unsigned short sid; unsigned int limit[2]; }


decompiled_code:
char *__fastcall search_limd(unsigned __int16 a1)
{
int v1; // esi
int v2; // edx
int v3; // eax

v1 = dword_30A0 - 1;
if ( dword_30A0 - 1 < 0 )
return 0LL;
v2 = 0;
while ( 1 )
{
v3 = v2 + ((v1 - v2) >> 1);
if ( *((_WORD *)&limd + 6 * v3) == a1 )
break;
if ( *((_WORD *)&limd + 6 * v3) > a1 )
{
v1 = v3 - 1;
if ( v3 - 1 < v2 )
return 0LL;
}
else
{
v2 = v3 + 1;
if ( v1 < v3 + 1 )
return 0LL;
}
}
return (char *)&limd + 12 * v3;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned __int16 a1)
{
int v1; // esi
int v2; // edx
int v3; // eax

v1 = dword_30A0 - 1;
if ( dword_30A0 - 1 < 0 )
return 0LL;
v2 = 0;
while ( 1 )
{
v3 = v2 + ((v1 - v2) >> 1);
if ( *((_WORD *)&limd + 6 * v3) == a1 )
break;
if ( *((_WORD *)&limd + 6 * v3) > a1 )
{
v1 = v3 - 1;
if ( v3 - 1 < v2 )
return 0LL;
}
else
{
v2 = v3 + 1;
if ( v1 < v3 + 1 )
return 0LL;
}
}
return (char *)&limd + 12 * v3;
}

original_code:
struct limit_unit * search_limd(uint16_t sid)
{
 int low = 0;
 int high = limd.len - 1;
 int mid;
 while (low <= high)
 {
  mid = low + ((high - low) / 2);
  if (limd.list[mid].sid == sid)
  {
   return limd.list + mid;
  }
  else if (limd.list[mid].sid > sid)
  {
   high = mid - 1;
  }
  else
  {
   low = mid + 1;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct limit_unit *search_limd(unsigned short sid)
{
 int low = 0;
 int high = limd.len - 1;
 int mid;
 while (low <= high)
 {
  mid = low + ((high - low) / 2);
  if (limd.list[mid].sid == sid)
  {
   return limd.list + mid;
  }
  else if (limd.list[mid].sid > sid)
  {
   high = mid - 1;
  }
  else
  {
   low = mid + 1;
  }
 }
 return ((void *)0);
}

variable_types: low int

variable_types: high int

variable_types: mid int

return_type: struct limit_unit { unsigned short sid; unsigned int limit[2]; } *


decompiled_code:
__int64 __fastcall get_limd(unsigned __int16 a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rax

if ( !a2 )
return 0LL;
if ( a3 )
{
if ( dword_30A0 )
{
v4 = search_limd(a1);
if ( v4 )
{
LABEL_5:
*a2 = *((_DWORD *)v4 + 1);
*a3 = *((_DWORD *)v4 + 2);
return 1LL;
}
}
else
{
limit_init();
v4 = search_limd(a1);
if ( v4 )
goto LABEL_5;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, _DWORD *a2, _DWORD *a3)
{
char *v4; // rax

if ( !a2 )
return 0LL;
if ( a3 )
{
if ( dword_30A0 )
{
v4 = func3(a1);
if ( v4 )
{
LABEL_5:
*a2 = *((_DWORD *)v4 + 1);
*a3 = *((_DWORD *)v4 + 2);
return 1LL;
}
}
else
{
limit_init();
v4 = func3(a1);
if ( v4 )
goto LABEL_5;
}
}
return 0LL;
}

original_code:
int get_limd(const uint16_t sid, uint32_t *lim1, uint32_t *lim2)
{
 if (((void *)0) == lim1 || ((void *)0) == lim2)
  return 0;
 if (limd.len == 0)
 {
  limit_init();
 }
 struct limit_unit * temp;
 if ((temp = search_limd(sid)) == ((void *)0))
  return 0;
 *lim1 = temp->limit[0];
 *lim2 = temp->limit[1];
 return 1;
}

canonical_original_code:
int get_limd(unsigned short sid, unsigned int *lim1, unsigned int *lim2)
{
 if (((void *)0) == lim1 || ((void *)0) == lim2)
  return 0;
 if (limd.len == 0)
 {
  limit_init();
 }
 struct limit_unit *temp;
 if ((temp = search_limd(sid)) == ((void *)0))
  return 0;
 *lim1 = temp->limit[0];
 *lim2 = temp->limit[1];
 return 1;
}

variable_types: struct limit_unit { unsigned short sid; unsigned int limit[2]; } *


original_code:
static int add_item(struct limit_unit * ptr)
{
 if (((void *)0) == ptr)
  return 0;
 if (limd.len >= 1000)
  return 0;
 int i;
 for (i = 0; i < limd.len; ++i)
  if (ptr->sid == limd.list[i].sid)
   return 1;
 i = limd.len;
 memset(limd.list + i, '\0', sizeof(struct limit_unit));
 limd.list[i].sid = ptr->sid;
 limd.list[i].limit[0] = ptr->limit[0];
 limd.list[i].limit[1] = ptr->limit[1];
 ++limd.len;
 return 1;
}

canonical_original_code:
static int add_item(struct limit_unit *ptr)
{
 if (((void *)0) == ptr)
  return 0;
 if (limd.len >= 1000)
  return 0;
 int i;
 for (i = 0; i < limd.len; ++i)
  if (ptr->sid == limd.list[i].sid)
   return 1;
 i = limd.len;
 memset(limd.list + i, '\0', sizeof(struct limit_unit));
 limd.list[i].sid = ptr->sid;
 limd.list[i].limit[0] = ptr->limit[0];
 limd.list[i].limit[1] = ptr->limit[1];
 ++limd.len;
 return 1;
}

variable_types: i int


original_code:
static void unit_init(recunit *unit, const netpt1 *p, time_t now)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 unit->sign = 1;
 unit->version = 1;
 unit->sid = p->body.sid;
 unit->uid = p->body.uid;
 unit->timel1 = now;
 unit->counterl1 = 0;
 unit->timel2 = now;
 unit->counterl2 = 0;
 unit->allowedl2 = 0;
 return;
}

canonical_original_code:
static void unit_init(struct recunit *unit, struct netpt1 *p, long now)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 unit->sign = 1;
 unit->version = 1;
 unit->sid = p->body.sid;
 unit->uid = p->body.uid;
 unit->timel1 = now;
 unit->counterl1 = 0;
 unit->timel2 = now;
 unit->counterl2 = 0;
 unit->allowedl2 = 0;
 return;
}

variable_types: struct netpt1 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody1 { unsigned int uid; unsigned short sid; unsigned short num; } body; char zero[3]; char pef; } *


decompiled_code:
void __fastcall output_log2(__int64 a1, __int64 a2)
{
struct tm *v2; // rax

if ( a1 && a2 && *(_BYTE *)a1 && *(_DWORD *)(a1 + 28) > (unsigned int)limit2 )
{
v2 = localtime((const time_t *)(a1 + 8));
strftime(buf, 0x14uLL, "%H:%M:%S", v2);
sprintf(
msg,
"%10d\t%4d\t%s\t%4d\t%4d\t%4d",
*(unsigned int *)(a2 + 64),
*(unsigned __int16 *)(a2 + 68),
buf,
*(unsigned int *)(a1 + 28),
timel2,
(unsigned int)limit2);
addto_log(3LL, msg);
if ( *(_DWORD *)(a1 + 28) / (unsigned int)limit2 >= warning_rate )
addto_log(4LL, msg);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2)
{
struct tm *v2; // rax

if ( a1 && a2 && *(_BYTE *)a1 && *(_DWORD *)(a1 + 28) > (unsigned int)limit2 )
{
v2 = localtime((const time_t *)(a1 + 8));
strftime(buf, 0x14uLL, "%H:%M:%S", v2);
sprintf(
msg,
"%10d\t%4d\t%s\t%4d\t%4d\t%4d",
*(unsigned int *)(a2 + 64),
*(unsigned __int16 *)(a2 + 68),
buf,
*(unsigned int *)(a1 + 28),
timel2,
(unsigned int)limit2);
addto_log(3LL, msg);
if ( *(_DWORD *)(a1 + 28) / (unsigned int)limit2 >= warning_rate )
addto_log(4LL, msg);
}
}

original_code:
static void output_log2(recunit *unit, const netpt1 *p)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 if (unit->sign == 0)
  return;
 if (unit->counterl2 > limit2)
 {
  struct tm *hour = localtime(&(unit->timel1));
  strftime(buf, 20, "%H:%M:%S", hour);
  sprintf(msg, "%10d\t%4d\t%s\t%4d\t%4d\t%4d",p->body.uid, p->body.sid, buf, unit->counterl2, timel2, limit2);
  addto_log(3, msg);
  if ((unit->counterl2 / limit2) >= warning_rate)
   addto_log(4, msg);
 }
}

canonical_original_code:
static void output_log2(struct recunit *unit, struct netpt1 *p)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 if (unit->sign == 0)
  return;
 if (unit->counterl2 > limit2)
 {
  struct tm *hour = localtime(&(unit->timel1));
  strftime(buf, 20, "%H:%M:%S", hour);
  sprintf(msg, "%10d\t%4d\t%s\t%4d\t%4d\t%4d",p->body.uid, p->body.sid, buf, unit->counterl2, timel2, limit2);
  addto_log(3, msg);
  if ((unit->counterl2 / limit2) >= warning_rate)
   addto_log(4, msg);
 }
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
void __fastcall output_log1(__int64 a1, __int64 a2)
{
struct tm *v2; // rax

if ( a1 && a2 && *(_BYTE *)a1 && *(_DWORD *)(a1 + 24) > (unsigned int)limit1 )
{
v2 = localtime((const time_t *)(a1 + 8));
strftime(buf, 0x14uLL, "%H:%M:%S", v2);
sprintf(
msg,
"%10d %4d %s %4d %4d %4d",
*(unsigned int *)(a2 + 64),
*(unsigned __int16 *)(a2 + 68),
buf,
*(unsigned int *)(a1 + 24),
timel1,
(unsigned int)limit1);
addto_log(3LL, msg);
if ( *(_DWORD *)(a1 + 24) / (unsigned int)limit1 >= warning_rate )
addto_log(4LL, msg);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
struct tm *v2; // rax

if ( a1 && a2 && *(_BYTE *)a1 && *(_DWORD *)(a1 + 24) > (unsigned int)limit1 )
{
v2 = localtime((const time_t *)(a1 + 8));
strftime(buf, 0x14uLL, "%H:%M:%S", v2);
sprintf(
msg,
"%10d %4d %s %4d %4d %4d",
*(unsigned int *)(a2 + 64),
*(unsigned __int16 *)(a2 + 68),
buf,
*(unsigned int *)(a1 + 24),
timel1,
(unsigned int)limit1);
addto_log(3LL, msg);
if ( *(_DWORD *)(a1 + 24) / (unsigned int)limit1 >= warning_rate )
addto_log(4LL, msg);
}
}

original_code:
static void output_log1(recunit *unit, const netpt1 *p)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 if (unit->sign == 0)
  return;
 if (unit->counterl1 > limit1)
 {
  struct tm *hour = localtime(&(unit->timel1));
  strftime(buf, 20, "%H:%M:%S", hour);
  sprintf(msg, "%10d  %4d  %s  %4d  %4d  %4d",p->body.uid, p->body.sid, buf, unit->counterl1, timel1, limit1);
  addto_log(3, msg);
  if ((unit->counterl1 / limit1) >= warning_rate)
   addto_log(4, msg);
 }
}

canonical_original_code:
static void output_log1(struct recunit *unit, struct netpt1 *p)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 if (unit->sign == 0)
  return;
 if (unit->counterl1 > limit1)
 {
  struct tm *hour = localtime(&(unit->timel1));
  strftime(buf, 20, "%H:%M:%S", hour);
  sprintf(msg, "%10d  %4d  %s  %4d  %4d  %4d",p->body.uid, p->body.sid, buf, unit->counterl1, timel1, limit1);
  addto_log(3, msg);
  if ((unit->counterl1 / limit1) >= warning_rate)
   addto_log(4, msg);
 }
}

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


original_code:
static void update_counter(recunit *unit, const netpt1 *p, time_t now)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 int not_use = !(unit->sign);
 int not_same = (unit->sid != p->body.sid) || (unit->uid != p->body.uid);
 int is_old = (now - unit->timel2) >= timel2;
 if (not_use || not_same || is_old)
 {
  output_log1(unit, p);
  output_log2(unit, p);
  unit_init(unit, p, now);
 }
 if ((now - unit->timel1) >= timel1)
 {
  output_log1(unit, p);
  unit->timel1 = now;
  unit->counterl1 = 0;
 }
 unit->counterl1 += p->body.num;
 unit->counterl2 += p->body.num;
 return;
}

canonical_original_code:
static void update_counter(struct recunit *unit, struct netpt1 *p, long now)
{
 if (((void *)0) == unit || ((void *)0) == p)
  return;
 int not_use = !(unit->sign);
 int not_same = (unit->sid != p->body.sid) || (unit->uid != p->body.uid);
 int is_old = (now - unit->timel2) >= timel2;
 if (not_use || not_same || is_old)
 {
  output_log1(unit, p);
  output_log2(unit, p);
  unit_init(unit, p, now);
 }
 if ((now - unit->timel1) >= timel1)
 {
  output_log1(unit, p);
  unit->timel1 = now;
  unit->counterl1 = 0;
 }
 unit->counterl1 += p->body.num;
 unit->counterl2 += p->body.num;
 return;
}


decompiled_code:
__int64 __fastcall access_query(__int64 a1, _BYTE *a2, __int64 a3)
{
__int64 v4; // r13
unsigned int v6; // eax

if ( !a1 )
return 0LL;
if ( a2 )
{
v4 = hash_search(*(unsigned __int16 *)(a1 + 68), *(unsigned int *)(a1 + 64));
if ( v4 && (unsigned int)get_limd(*(unsigned __int16 *)(a1 + 68), &limit1, &limit2) )
{
*a2 = 1;
update_counter(v4, a1, a3);
if ( *(_DWORD *)(v4 + 24) <= (unsigned int)limit1 )
{
v6 = *(_DWORD *)(v4 + 32);
if ( v6 < limit2 )
{
*(_DWORD *)(v4 + 32) = *(unsigned __int16 *)(a1 + 70) + v6;
return 1LL;
}
}
}
else
{
*a2 = 0;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2, __int64 a3)
{
__int64 v4; // r13
unsigned int v6; // eax

if ( !a1 )
return 0LL;
if ( a2 )
{
v4 = hash_search(*(unsigned __int16 *)(a1 + 68), *(unsigned int *)(a1 + 64));
if ( v4 && (unsigned int)get_limd(*(unsigned __int16 *)(a1 + 68), &limit1, &limit2) )
{
*a2 = 1;
func3(v4, a1, a3);
if ( *(_DWORD *)(v4 + 24) <= (unsigned int)limit1 )
{
v6 = *(_DWORD *)(v4 + 32);
if ( v6 < limit2 )
{
*(_DWORD *)(v4 + 32) = *(unsigned __int16 *)(a1 + 70) + v6;
return 1LL;
}
}
}
else
{
*a2 = 0;
}
}
return 0LL;
}

original_code:
uint8_t access_query(const netpt1 *p, uint8_t * stat, time_t now)
{
 if (((void *)0) == p || ((void *)0) == stat)
  return 0;
 recunit *memunit = hash_search(p->body.sid, p->body.uid, now);
 if (memunit == ((void *)0))
 {
  *stat = 0;
  return 0;
 }
 if(!(get_limd(p->body.sid, &limit1, &limit2)))
 {
  *stat = 0;
  return 0;
 }
 *stat = 1;
 update_counter(memunit, p, now);
 if (memunit->counterl1 > limit1)
 {
  return 0;
 }
 else if (memunit->allowedl2 >= limit2)
 {
  return 0;
 }
 else
 {
  memunit->allowedl2 += p->body.num;
  return 1;
 }
 return 1;
}

canonical_original_code:
unsigned char access_query(struct netpt1 *p, unsigned char *stat, long now)
{
 if (((void *)0) == p || ((void *)0) == stat)
  return 0;
 struct recunit *memunit = hash_search(p->body.sid, p->body.uid, now);
 if (memunit == ((void *)0))
 {
  *stat = 0;
  return 0;
 }
 if(!(get_limd(p->body.sid, &limit1, &limit2)))
 {
  *stat = 0;
  return 0;
 }
 *stat = 1;
 update_counter(memunit, p, now);
 if (memunit->counterl1 > limit1)
 {
  return 0;
 }
 else if (memunit->allowedl2 >= limit2)
 {
  return 0;
 }
 else
 {
  memunit->allowedl2 += p->body.num;
  return 1;
 }
 return 1;
}

variable_types:
stat
unsigned char *

return_type: unsigned char


decompiled_code:
_BOOL8 __fastcall netpt1_check(__int64 a1)
{
return search_limd(*(unsigned __int16 *)(a1 + 68)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return search_limd(*(unsigned __int16 *)(a1 + 68)) != 0;
}

original_code:
static int netpt1_check(const netpt1 *ptr)
{
 if (search_limd(ptr->body.sid) == ((void *)0))
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
static int netpt1_check(struct netpt1 *ptr)
{
 if (search_limd(ptr->body.sid) == ((void *)0))
 {
  return 0;
 }
 return 1;
}


decompiled_code:
_BOOL8 __fastcall netpt3_check(__int64 a1)
{
return search_limd(*(unsigned __int16 *)(a1 + 68)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return search_limd(*(unsigned __int16 *)(a1 + 68)) != 0;
}

original_code:
static int netpt3_check(const netpt3 *ptr)
{
 if (search_limd(ptr->body.sid) == ((void *)0))
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
static int netpt3_check(struct netpt3 *ptr)
{
 if (search_limd(ptr->body.sid) == ((void *)0))
 {
  return 0;
 }
 return 1;
}

variable_types: struct netpt3 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody3 { unsigned int uid; unsigned short sid; char zero[2]; } body; char zero[3]; char pef; } *


decompiled_code:
_BOOL8 __fastcall netpt7_check(__int64 a1)
{
__int64 v1; // r8
_BOOL8 result; // rax

v1 = search_limd(*(unsigned __int16 *)(a1 + 66));
result = 1LL;
if ( !v1 )
result = *(_WORD *)(a1 + 66) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1)
{
__int64 v1; // r8
_BOOL8 result; // rax

v1 = search_limd(*(unsigned __int16 *)(a1 + 66));
result = 1LL;
if ( !v1 )
result = *(_WORD *)(a1 + 66) == 0;
return result;
}

original_code:
static int netpt7_check(const netpt7 *ptr)
{
 if (search_limd(ptr->body.sid) == ((void *)0) && ptr->body.sid != 0)
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
static int netpt7_check(struct netpt7 *ptr)
{
 if (search_limd(ptr->body.sid) == ((void *)0) && ptr->body.sid != 0)
 {
  return 0;
 }
 return 1;
}

variable_types: struct netpt7 { struct phead { char psf; char zero1; unsigned short len; unsigned short subcmd; unsigned short version; unsigned int uid; unsigned short fls_id; unsigned short fls_num; unsigned int client_ip; unsigned short client_port; char zero2[2]; char reserve[40]; } head; struct pbody7 { unsigned char stat; char zero; unsigned short sid; struct addr { unsigned char id; unsigned char zero; unsigned short port; unsigned int ip; } fls; } body; char zero[3]; char pef; } *

user_defined_types: struct netpt7 { struct phead head; struct pbody7 body; char zero[3]; char pef; }