main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v5; // er12
unsigned int v6; // ebx
_BYTE v7[10240]; // [rsp+0h] [rbp-2848h] BYREF
char v8[72]; // [rsp+2800h] [rbp-48h] BYREF

v3 = (unsigned int)tar_init(v8, 0LL, &workspace, 2048LL);
printf("tar_init returned %d\n", v3);
if ( (_DWORD)v3 )
{
LODWORD(v3) = 1;
}
else
{
v5 = open("t.tar", 0);
if ( v5 < 0 )
{
printf("Could not open %s.\n", "t.tar");
LODWORD(v3) = 1;
}
else
{
while ( 1 )
{
v6 = read(v5, v7, 0x2800uLL);
if ( (int)v6 <= 0 )
break;
printf("read %d bytes.\n", v6);
if ( (int)tar_new_data(v8, v7, v6) < 0 )
return v3;
}
printf("Read returned %d\n", v6);
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v5; // er12
unsigned int v6; // ebx
_BYTE v7[10240]; // [rsp+0h] [rbp-2848h] BYREF
char v8[72]; // [rsp+2800h] [rbp-48h] BYREF

v3 = (unsigned int)func14(v8, 0LL, &workspace, 2048LL);
printf("tar_init returned %d\n", v3);
if ( (_DWORD)v3 )
{
LODWORD(v3) = 1;
}
else
{
v5 = open("t.tar", 0);
if ( v5 < 0 )
{
printf("Could not open %s.\n", "t.tar");
LODWORD(v3) = 1;
}
else
{
while ( 1 )
{
v6 = read(v5, v7, 0x2800uLL);
if ( (int)v6 <= 0 )
break;
printf("read %d bytes.\n", v6);
if ( (int)func15(v8, v7, v6) < 0 )
return v3;
}
printf("Read returned %d\n", v6);
}
}
return v3;
}

original_code:
int main(int c, char **v) {
 tar_t t;
 int res = tar_init(&t, ((void *)0), workspace, 2048);
 printf("tar_init returned %d\n", res);
 if (res != 0) return 1;
 int f = open("t.tar", 00);
 if (f < 0) {
  printf("Could not open %s.\n", "t.tar");
  return 1;
 }
 char buf[10240];
 for(;;) {
  int r = read(f, buf, 10240);
  if (r <= 0) {
   printf("Read returned %d\n", r);
   break;
  }
  printf("read %d bytes.\n", r);
  r = tar_new_data(&t, buf, r);
  if (r < 0) break;
 }
 return 0;
}

canonical_original_code:
int main(int c, char **v) {
 struct tar_ctx t;
 int res = tar_init(&t, ((void *)0), workspace, 2048);
 printf("tar_init returned %d\n", res);
 if (res != 0) return 1;
 int f = open("t.tar", 00);
 if (f < 0) {
  printf("Could not open %s.\n", "t.tar");
  return 1;
 }
 char buf[10240];
 for(;;) {
  int r = read(f, buf, 10240);
  if (r <= 0) {
   printf("Read returned %d\n", r);
   break;
  }
  printf("read %d bytes.\n", r);
  r = tar_new_data(&t, buf, r);
  if (r < 0) break;
 }
 return 0;
}

variable_types: c int

variable_types:
v
char **

variable_types: struct tar_ctx { enum { HEADER=0, DATA=1, PADDING=2, ABORT=3 } parsing_state; unsigned int state_size; unsigned int state_left; char *workspace; unsigned int workspacesize; unsigned int pos; void *cls; char numempty; }

variable_types: res int

variable_types: f int

variable_types:
buf
char [10240]

variable_types: r int


repo: tofujimo/coverity

decompiled_code:
void resource_leak()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void resource_leak(void)
        {
                char *p = malloc(4);
                p[0] = 12;
        }

canonical_original_code:
void resource_leak()
        {
                char *p = malloc(4);
                p[0] = 12;
        }

variable_types:
p
char *

return_type: void


decompiled_code:
void resource_leak_2()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void resource_leak_2(void)
        {
                char *p = malloc(4);
                char *q = malloc(12);
                if (!p || !q)
                        return;
        }

canonical_original_code:
void resource_leak_2()
        {
                char *p = malloc(4);
                char *q = malloc(12);
                if (!p || !q)
                        return;
        }

variable_types:
q
char *


decompiled_code:
void use_after_free()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void use_after_free(void)
        {
                char *p = malloc(4);
                *p = 'a';
                free(p);
        }

canonical_original_code:
void use_after_free()
        {
                char *p = malloc(4);
                *p = 'a';
                free(p);
        }


decompiled_code:
void size_check()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void size_check(void)
        {
                struct bigger_than_ptr *p;
                p = malloc(sizeof(struct bigger_than_ptr *));
        }

canonical_original_code:
void size_check()
        {
                struct bigger_than_ptr *p;
                p = malloc(sizeof(struct bigger_than_ptr *));
        }

variable_types: struct bigger_than_ptr { int a; int b; int c; int d; } *


decompiled_code:
__int64 dead_code()
{
return some_func();
}

canonical_decompiled_code:
__int64 func5()
{
return some_func();
}

original_code:
void dead_code(void)
        {
                int x = some_func();
                if (x) {
                        if (!x) {
                                x++;
                                return;
                        }
                }
        }

canonical_original_code:
void dead_code()
        {
                int x = some_func();
                if (x) {
                        if (!x) {
                                x++;
                                return;
                        }
                }
        }

variable_types: x int


decompiled_code:
ssize_t negative_returns()
{
char buf[18]; // [rsp+6h] [rbp-12h] BYREF

return read(1, buf, 8uLL);
}

canonical_decompiled_code:
ssize_t func6()
{
char buf[18]; // [rsp+6h] [rbp-12h] BYREF

return read(1, buf, 8uLL);
}

original_code:
void negative_returns(void)
        {
                char buf[10];
                int j = read(1, buf, 8);
                buf[j] = '\0';
        }

canonical_original_code:
void negative_returns()
        {
                char buf[10];
                int j = read(1, buf, 8);
                buf[j] = '\0';
        }

variable_types:
buf
char [10]

variable_types: j int


decompiled_code:
__int64 reverse_negative()
{
return some_func();
}

canonical_decompiled_code:
__int64 func7()
{
return some_func();
}

original_code:
void reverse_negative(void)
        {
                int j = some_func();
                char buf[10];
                buf[j] = '\0';
                if (j < 0)
                        return;
        }

canonical_original_code:
void reverse_negative()
        {
                int j = some_func();
                char buf[10];
                buf[j] = '\0';
                if (j < 0)
                        return;
        }


uninit

decompiled_code:
// write access to const memory has been detected, the output may be wrong!
void uninit()
{
*(_BYTE *)forward_null = 97;
}

canonical_decompiled_code:
void func8()
{
*(_BYTE *)forward_null = 97;
}

original_code:
void uninit(void)
        {
                char* p = 0;
                *p = 'a';
        }

canonical_original_code:
void uninit()
        {
                char *p = 0;
                *p = 'a';
        }


decompiled_code:
void overrun_static()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
void overrun_static(void)
        {
                char buf[10];
                int i;
                for (i = 0; i < 10; i++)
                        buf[i] = '\0';
        }

canonical_original_code:
void overrun_static()
        {
                char buf[10];
                int i;
                for (i = 0; i < 10; i++)
                        buf[i] = '\0';
        }

variable_types: i int


paths

decompiled_code:
__int64 paths()
{
void *v0; // rax
void *v1; // rbx
__int64 result; // rax

v0 = malloc(0xCuLL);
if ( !v0 )
return 0xFFFFFFFFLL;
v1 = v0;
if ( (unsigned int)some_other_function() )
{
if ( (unsigned int)yet_another_function() )
{
do_some_things(v1);
free(v1);
result = 0LL;
}
else
{
result = 4294967294LL;
}
}
else
{
free(v1);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
void *v0; // rax
void *v1; // rbx
__int64 result; // rax

v0 = malloc(0xCuLL);
if ( !v0 )
return 0xFFFFFFFFLL;
v1 = v0;
if ( (unsigned int)some_other_function() )
{
if ( (unsigned int)yet_another_function() )
{
do_some_things(v1);
free(v1);
result = 0LL;
}
else
{
result = 4294967294LL;
}
}
else
{
free(v1);
result = 4294967294LL;
}
return result;
}

original_code:
int paths() {
  char *p = malloc(12);
  if (!p)
    return -1;
  if (!some_other_function()) {
    free(p);
    return -2;
  }
  if (!yet_another_function()) {
    return -2;
  }
  do_some_things(p);
  free(p);
  return 0;
}

return_type: int


die

repo: tomarus/nntpswitch

decompiled_code:
void __noreturn die(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
char *v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v6; // [rsp+0h] [rbp-4F8h] BYREF
char s[1032]; // [rsp+20h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+428h] [rbp-D0h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
v1 = _errno_location();
if ( *v1 )
{
v2 = strerror(*v1);
syslog(3, "died: %s (%s)", s, v2);
v3 = strerror(*v1);
v4 = getpid();
fprintf(stderr, "%d: died: %s (%s)\n", v4, s, v3);
}
else
{
syslog(3, "died: %s", s);
v5 = getpid();
fprintf(stderr, "%d: died: %s\n", v5, s);
}
syslog_close(&v6);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(char *format, ...)
{
int *v1; // rbx
char *v2; // rax
char *v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v6; // [rsp+0h] [rbp-4F8h] BYREF
char s[1032]; // [rsp+20h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+428h] [rbp-D0h] BYREF

va_start(arg, format);
vsprintf(s, format, arg);
v1 = _errno_location();
if ( *v1 )
{
v2 = strerror(*v1);
syslog(3, "died: %s (%s)", s, v2);
v3 = strerror(*v1);
v4 = getpid();
fprintf(stderr, "%d: died: %s (%s)\n", v4, s, v3);
}
else
{
syslog(3, "died: %s", s);
v5 = getpid();
fprintf(stderr, "%d: died: %s\n", v5, s);
}
syslog_close(&v6);
exit(1);
}

original_code:
void die(const char *str, ...)
{
 va_list ap;
 char s[1024];
 __builtin_va_start(ap,str);
 vsprintf(s, str, ap);
 if ( (*__errno_location ()) )
 {
  syslog(3, "died: %s (%s)", s, strerror((*__errno_location ())));
  fprintf(stderr, "%d: died: %s (%s)\n", getpid (), s, strerror((*__errno_location ())));
 } else {
  syslog(3, "died: %s", s);
  fprintf(stderr, "%d: died: %s\n", getpid (), s);
 }
 __builtin_va_end(ap);
 syslog_close ();
 exit(1);
}

canonical_original_code:
void die(char *str, ...)
{
 __builtin_va_list ap;
 char s[1024];
 __builtin_va_start(ap,str);
 vsprintf(s, str, ap);
 if ( (*__errno_location ()) )
 {
  syslog(3, "died: %s (%s)", s, strerror((*__errno_location ())));
  fprintf(stderr, "%d: died: %s (%s)\n", getpid (), s, strerror((*__errno_location ())));
 } else {
  syslog(3, "died: %s", s);
  fprintf(stderr, "%d: died: %s\n", getpid (), s);
 }
 __builtin_va_end(ap);
 syslog_close ();
 exit(1);
}

variable_types:
str
char *


info

decompiled_code:
void info(char *format, ...)
{
char v1[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(v1, 0x400uLL, format, arg);
syslog(5, "%s", v1);
}

canonical_decompiled_code:
void func1(char *format, ...)
{
char v1[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(v1, 0x400uLL, format, arg);
syslog(5, "%s", v1);
}

original_code:
void info(const char *str, ...)
{
 va_list ap;
 char s[1024];
 __builtin_va_start(ap,str);
 vsnprintf(s, sizeof(s), str, ap);
 syslog(5, "%s", s);
 __builtin_va_end(ap);
}

canonical_original_code:
void info(char *str, ...)
{
 __builtin_va_list ap;
 char s[1024];
 __builtin_va_start(ap,str);
 vsnprintf(s, sizeof(s), str, ap);
 syslog(5, "%s", s);
 __builtin_va_end(ap);
}


error

decompiled_code:
int error(char *format, ...)
{
unsigned int v1; // eax
char v3[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(v3, 0x400uLL, format, arg);
syslog(3, "%s", v3);
v1 = getpid();
return fprintf(stderr, "%d: error: %s\n", v1, v3);
}

canonical_decompiled_code:
int func2(char *format, ...)
{
unsigned int v1; // eax
char v3[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(v3, 0x400uLL, format, arg);
syslog(3, "%s", v3);
v1 = getpid();
return fprintf(stderr, "%d: error: %s\n", v1, v3);
}

original_code:
void error(const char *str, ...)
{
 va_list ap;
 char s[1024];
 __builtin_va_start(ap,str);
 vsnprintf(s, sizeof (s), str, ap);
 syslog(3, "%s", s);
 fprintf(stderr, "%d: error: %s\n", getpid (), s);
 __builtin_va_end(ap);
}

canonical_original_code:
void error(char *str, ...)
{
 __builtin_va_list ap;
 char s[1024];
 __builtin_va_start(ap,str);
 vsnprintf(s, sizeof (s), str, ap);
 syslog(3, "%s", s);
 fprintf(stderr, "%d: error: %s\n", getpid (), s);
 __builtin_va_end(ap);
}


strtolower

decompiled_code:
char *__fastcall strtolower(char *a1)
{
char v1; // bl
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( *a1 )
{
v2 = _ctype_tolower_loc();
v3 = a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( *v3 );
}
return a1;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
char v1; // bl
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( *a1 )
{
v2 = _ctype_tolower_loc();
v3 = a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( *v3 );
}
return a1;
}

original_code:
char* strtolower(char *str)
{
 int i=0;
 while(str[i])
 {
  str[i] = tolower(str[i]);
  i++;
 }
 return str;
}

canonical_original_code:
char *strtolower(char *str)
{
 int i = 0;
 while(str[i])
 {
  str[i] = tolower(str[i]);
  i++;
 }
 return str;
}

return_type: char *


striprn

decompiled_code:
char *__fastcall striprn(const char *a1)
{
char *v1; // rbx
char *v2; // rax

v1 = strdup(a1);
v2 = &v1[strlen(v1) - 1];
if ( *v2 == 13 || *v2 == 10 )
{
do
{
do
*v2-- = 0;
while ( *v2 == 13 );
}
while ( *v2 == 10 );
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1)
{
char *v1; // rbx
char *v2; // rax

v1 = strdup(a1);
v2 = &v1[strlen(v1) - 1];
if ( *v2 == 13 || *v2 == 10 )
{
do
{
do
*v2-- = 0;
while ( *v2 == 13 );
}
while ( *v2 == 10 );
}
return v1;
}

original_code:
char* striprn(const char *s)
{
 char *str, *end;
 str = strdup(s);
 end = str;
 str += strlen(end) - 1;
 while( *str == '\r' || *str == '\n' )
 {
  *str = '\0';
  str--;
 }
 return end;
}

canonical_original_code:
char *striprn(char *s)
{
 char *str; char *end;
 str = strdup(s);
 end = str;
 str += strlen(end) - 1;
 while( *str == '\r' || *str == '\n' )
 {
  *str = '\0';
  str--;
 }
 return end;
}

variable_types:
s
char *

variable_types:
end
char *


replacern

decompiled_code:
char *__fastcall replacern(const char *a1, char a2)
{
char *v2; // rbx
char *i; // rax

v2 = strdup(a1);
for ( i = &v2[strlen(v2) - 1]; v2 != i; --i )
{
if ( *i == 13 || *i == 10 )
*i = a2;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1, char a2)
{
char *v2; // rbx
char *i; // rax

v2 = strdup(a1);
for ( i = &v2[strlen(v2) - 1]; v2 != i; --i )
{
if ( *i == 13 || *i == 10 )
*i = a2;
}
return v2;
}

original_code:
char* replacern(char *s, char r)
{
 char *str, *end;
 str = strdup(s);
 end = str;
 str += strlen(end) - 1;
 while( str != end )
 {
  if ( *str == '\r' || *str == '\n' )
  {
   *str = r;
  }
  str--;
 }
 return end;
}

canonical_original_code:
char *replacern(char *s, char r)
{
 char *str; char *end;
 str = strdup(s);
 end = str;
 str += strlen(end) - 1;
 while( str != end )
 {
  if ( *str == '\r' || *str == '\n' )
  {
   *str = r;
  }
  str--;
 }
 return end;
}

variable_types: r char


nullstr

decompiled_code:
_BOOL8 __fastcall nullstr(_BYTE *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 == 0;
else
result = 1LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_BYTE *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 == 0;
else
result = 1LL;
return result;
}

original_code:
int nullstr(const char *s)
{
 if ( s == ((void *)0) ) return 1;
 if ( s[0] == '\0' ) return 1;
 return 0;
}

canonical_original_code:
int nullstr(char *s)
{
 if ( s == ((void *)0) ) return 1;
 if ( s[0] == '\0' ) return 1;
 return 0;
}


chop

decompiled_code:
const char *__fastcall chop(const char *a1)
{
const char *result; // rax
unsigned __int64 v2; // rdx
__int64 v3; // rcx
unsigned __int64 v4; // rdx

result = &a1[strlen(a1) - 1];
v2 = *(unsigned __int8 *)result;
if ( (unsigned __int8)v2 <= 0x20u )
{
v3 = 0x100002400LL;
if ( _bittest64(&v3, v2) )
{
do
{
*result-- = 0;
v4 = *(unsigned __int8 *)result;
}
while ( (unsigned __int8)v4 <= 0x20u && _bittest64(&v3, v4) );
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1)
{
const char *result; // rax
unsigned __int64 v2; // rdx
__int64 v3; // rcx
unsigned __int64 v4; // rdx

result = &a1[strlen(a1) - 1];
v2 = *(unsigned __int8 *)result;
if ( (unsigned __int8)v2 <= 0x20u )
{
v3 = 0x100002400LL;
if ( _bittest64(&v3, v2) )
{
do
{
*result-- = 0;
v4 = *(unsigned __int8 *)result;
}
while ( (unsigned __int8)v4 <= 0x20u && _bittest64(&v3, v4) );
}
}
return result;
}

variable_types:
buf
char *


strippat

original_code:
char* strippat(char *buf, char *pat)
{
 char *s;
 int l = strlen(buf)-1;
 int j = strlen(pat)-1;
 if ( pat[0] == '*' )
 {
  s = strdup(buf);
  while( pat[j] != '*' && l > 0 )
  {
   s[l] = 0;
   j--;
   l--;
  }
  return s;
 }
 else if ( pat[j] == '*' )
 {
  s = strdup(buf);
  while( *pat++ != '*' )
   s++;
  return s;
 }
 return ((void *)0);
}

canonical_original_code:
char *strippat(char *buf, char *pat)
{
 char *s;
 int l = strlen(buf)-1;
 int j = strlen(pat)-1;
 if ( pat[0] == '*' )
 {
  s = strdup(buf);
  while( pat[j] != '*' && l > 0 )
  {
   s[l] = 0;
   j--;
   l--;
  }
  return s;
 }
 else if ( pat[j] == '*' )
 {
  s = strdup(buf);
  while( *pat++ != '*' )
   s++;
  return s;
 }
 return ((void *)0);
}

variable_types:
pat
char *

variable_types: l int


original_code:
int checkbuf_isend(char *buf, char *rcvbuf, int bread)
{
 char chkbuf[5];
 int j, k;
 if ( bread < 5 )
 {
  k=0;
  for (j=0; j<5-bread; j++ )
   chkbuf[k++] = buf[j+bread];
  for (j=0; j<bread; j++)
   chkbuf[k++] = rcvbuf[j];
  if (
   chkbuf[0] == '\r' &&
   chkbuf[1] == '\n' &&
   chkbuf[2] == '.' &&
   chkbuf[3] == '\r' &&
   chkbuf[4] == '\n'
  )
   return 1;
 } else {
  if (
   rcvbuf[bread-5] == '\r' &&
   rcvbuf[bread-4] == '\n' &&
   rcvbuf[bread-3] == '.' &&
   rcvbuf[bread-2] == '\r' &&
   rcvbuf[bread-1] == '\n'
  )
   return 1;
  for (j=0; j<5; j++)
   buf[j] = rcvbuf[bread-5+j];
 }
 return 0;
}

canonical_original_code:
int checkbuf_isend(char *buf, char *rcvbuf, int bread)
{
 char chkbuf[5];
 int j; int k;
 if ( bread < 5 )
 {
  k=0;
  for (j=0; j<5-bread; j++ )
   chkbuf[k++] = buf[j+bread];
  for (j=0; j<bread; j++)
   chkbuf[k++] = rcvbuf[j];
  if (
   chkbuf[0] == '\r' &&
   chkbuf[1] == '\n' &&
   chkbuf[2] == '.' &&
   chkbuf[3] == '\r' &&
   chkbuf[4] == '\n'
  )
   return 1;
 } else {
  if (
   rcvbuf[bread-5] == '\r' &&
   rcvbuf[bread-4] == '\n' &&
   rcvbuf[bread-3] == '.' &&
   rcvbuf[bread-2] == '\r' &&
   rcvbuf[bread-1] == '\n'
  )
   return 1;
  for (j=0; j<5; j++)
   buf[j] = rcvbuf[bread-5+j];
 }
 return 0;
}

variable_types:
rcvbuf
char *

variable_types: bread int

variable_types:
chkbuf
char [5]

variable_types: k int


original_code:
char * str_escape(char *instr)
{
 char buf[256];
 char *p;
 int i = 0;
 for( p=instr; *p!=0; p++ )
 {
  if ( *p == '\'' )
   buf[i++] = '\\';
  if ( *p == '\\' )
   buf[i++] = '\\';
  buf[i++] = *p;
 }
 buf[i++] = 0;
 return strdup(buf);
}

canonical_original_code:
char *str_escape(char *instr)
{
 char buf[256];
 char *p;
 int i = 0;
 for( p=instr; *p!=0; p++ )
 {
  if ( *p == '\'' )
   buf[i++] = '\\';
  if ( *p == '\\' )
   buf[i++] = '\\';
  buf[i++] = *p;
 }
 buf[i++] = 0;
 return strdup(buf);
}

variable_types:
instr
char *

variable_types:
buf
char [256]

variable_types:
p
char *


decompiled_code:
__int64 __fastcall check_email(char *a1)
{
char v1; // al
int v2; // edx
int v3; // esi

v1 = *a1;
if ( *a1 )
{
v2 = 0;
v3 = 0;
do
{
if ( v1 == 46 )
{
v3 = 1;
}
else if ( v1 == 64 )
{
v2 = 1;
}
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
v3 = 0;
}
return v2 & (unsigned int)v3;
}

original_code:
int check_email(const char *addr)
{
    const char *c;
    int dot=0, ap=0;
    for (c=addr; *c; c++)
    {
        if ( *c == '.' )
            dot=1;
        else if ( *c == '@' )
            ap=1;
    }
    return dot & ap;
}

canonical_original_code:
int check_email(char *addr)
{
    char *c;
    int dot = 0; int ap = 0;
    for (c=addr; *c; c++)
    {
        if ( *c == '.' )
            dot=1;
        else if ( *c == '@' )
            ap=1;
    }
    return dot & ap;
}

variable_types:
addr
char *

variable_types:
c
char *

variable_types: dot int

variable_types: ap int


original_code:
int check_message_id(const char *addr)
{
    const char *c;
    int ap=0;
    if ( *addr != '<' )
        return 0;
    for (c=addr; *c; c++)
        if ( *c == '@' )
            ap=1;
    c--;
    if ( *c != '>' )
        return 0;
    return ap;
}

canonical_original_code:
int check_message_id(char *addr)
{
    char *c;
    int ap = 0;
    if ( *addr != '<' )
        return 0;
    for (c=addr; *c; c++)
        if ( *c == '@' )
            ap=1;
    c--;
    if ( *c != '>' )
        return 0;
    return ap;
}


decompiled_code:
char *__fastcall get_args_value(char *s1, int a2, const char *a3)
{
char *v4; // rbx

if ( a2 <= 0 )
return 0LL;
v4 = s1;
while ( strcmp(v4, a3) )
{
v4 += 512;
if ( v4 == &s1[512 * (unsigned __int64)(unsigned int)(a2 - 1) + 512] )
return 0LL;
}
return v4 + 256;
}

canonical_decompiled_code:
char *__fastcall func1(char *s1, int a2, const char *a3)
{
char *v4; // rbx

if ( a2 <= 0 )
return 0LL;
v4 = s1;
while ( strcmp(v4, a3) )
{
v4 += 512;
if ( v4 == &s1[512 * (unsigned __int64)(unsigned int)(a2 - 1) + 512] )
return 0LL;
}
return v4 + 256;
}

original_code:
static char *get_args_value(ARGS *args, int numargs, const char *name)
{
        int i;
        for (i=0; i<numargs; i++)
                if ( strcmp((args+i)->name, name) == 0 )
                        return (args+i)->args;
        return ((void *)0);
}

canonical_original_code:
static char *get_args_value(struct ARGS *args, int numargs, char *name)
{
        int i;
        for (i=0; i<numargs; i++)
                if ( strcmp((args+i)->name, name) == 0 )
                        return (args+i)->args;
        return ((void *)0);
}

variable_types: struct ARGS { char name[256]; char args[256]; } *

variable_types: numargs int

variable_types:
name
char *

variable_types: i int


decompiled_code:
char *__fastcall get_module_config_val(const char *a1, const char *a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

get_module_config_arg(a1, a2, v3);
return get_args_value((char *)(master + 16799856LL), *(_DWORD *)(master + 8LL), v3);
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, const char *a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

func0(a1, a2, v3);
return func1((char *)(master + 16799856LL), *(_DWORD *)(master + 8LL), v3);
}

original_code:
char *get_module_config_val(char *confargs, const char *var)
{
        char argval[32];
        get_module_config_arg(confargs, var, argval);
        return get_args_value(master->args, master->numargs, argval);
}

canonical_original_code:
char *get_module_config_val(char *confargs, char *var)
{
        char argval[32];
        get_module_config_arg(confargs, var, argval);
        return get_args_value(master->args, master->numargs, argval);
}

variable_types:
confargs
char *

variable_types:
var
char *

variable_types:
argval
char [32]


decompiled_code:
__int64 __fastcall parse_prefix(const char *a1, const char *a2, __int64 a3)
{
unsigned __int64 v4; // rbx
__int64 result; // rax
unsigned __int64 v6; // rdx
struct in_addr inp; // [rsp+Ch] [rbp-1Ch] BYREF

inet_aton(a1, &inp);
v4 = (unsigned int)_bswap_32(inp.s_addr) >> 8;
result = atol(a2);
if ( 1 << (32 - result) >> 8 )
{
v6 = v4 + (1 << (32 - result) >> 8);
do
{
result = (unsigned int)(v4 >> 3);
*(_BYTE *)(a3 + result) |= 1 << (v4++ & 7);
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, __int64 a3)
{
unsigned __int64 v4; // rbx
__int64 result; // rax
unsigned __int64 v6; // rdx
struct in_addr inp; // [rsp+Ch] [rbp-1Ch] BYREF

inet_aton(a1, &inp);
v4 = (unsigned int)func0(inp.s_addr) >> 8;
result = atol(a2);
if ( 1 << (32 - result) >> 8 )
{
v6 = v4 + (1 << (32 - result) >> 8);
do
{
result = (unsigned int)(v4 >> 3);
*(_BYTE *)(a3 + result) |= 1 << (v4++ & 7);
}
while ( v4 != v6 );
}
return result;
}

original_code:
void parse_prefix(char *ip, char *pfx, char *ptr)
{
 struct in_addr inaddr;
 unsigned long ipstart;
 unsigned long size;
 unsigned long i;
 inet_aton(ip, &inaddr);
 ipstart = ntohl(inaddr.s_addr) >> 8;
 size = (1 << (32-atol(pfx))) >> 8;
 for (i=0; i<size; i++)
 {
  unsigned int offset = (ipstart + i) >> 3;
  unsigned int bit = ( ipstart + i ) & 7;
  ptr[offset] |= 1<<bit;
 }
}

variable_types:
ip
char *

variable_types:
pfx
char *

variable_types:
ptr
char *

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }

variable_types:
ipstart
unsigned long

variable_types:
size
unsigned long

variable_types:
i
unsigned long

variable_types:
offset
unsigned int

variable_types:
bit
unsigned int


getpfxmap

decompiled_code:
const char *__fastcall getpfxmap(char *s2)
{
int v1; // edx
const char *v2; // rbx
__int64 v3; // r13
const char *v4; // r12

v1 = *(_DWORD *)(master + 16953368LL);
if ( !v1 )
return 0LL;
v2 = (const char *)(master + 16953372LL);
v3 = master + 4194335LL * (unsigned int)(v1 - 1) + 21147707;
while ( 1 )
{
v4 = v2;
if ( !strcmp(v2, s2) )
break;
v2 += 4194335;
if ( v2 == (const char *)v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func3(char *s2)
{
int v1; // edx
const char *v2; // rbx
__int64 v3; // r13
const char *v4; // r12

v1 = *(_DWORD *)(master + 16953368LL);
if ( !v1 )
return 0LL;
v2 = (const char *)(master + 16953372LL);
v3 = master + 4194335LL * (unsigned int)(v1 - 1) + 21147707;
while ( 1 )
{
v4 = v2;
if ( !strcmp(v2, s2) )
break;
v2 += 4194335;
if ( v2 == (const char *)v3 )
return 0LL;
}
return v4;
}

original_code:
PFXMAP* getpfxmap(const char *name)
{
        int i;
        for (i=0; i<master->num_pfxmaps; i++)
                if ( strcmp((master->prefixmap+i)->name, name) == 0 )
                        return master->prefixmap+i;
        return ((void *)0);
}

canonical_original_code:
struct PFXMAP *getpfxmap(char *name)
{
        int i;
        for (i=0; i<master->num_pfxmaps; i++)
                if ( strcmp((master->prefixmap+i)->name, name) == 0 )
                        return master->prefixmap+i;
        return ((void *)0);
}

return_type: struct PFXMAP { char name[32]; char map[4194303]; } *


decompiled_code:
_BOOL8 __fastcall pfx_iplookup(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax

v2 = _bswap_32(a1);
return (*(char *)(a2 + (v2 >> 11) + 32) & (1 << (BYTE1(v2) & 7))) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned int a1, __int64 a2)
{
unsigned int v2; // eax

v2 = func0(a1);
return (*(char *)(a2 + (v2 >> 11) + 32) & (1 << (BYTE1(v2) & 7))) != 0;
}

original_code:
int pfx_iplookup(struct in_addr inaddr, PFXMAP *map)
{
 unsigned long offset;
 unsigned char bit;
 offset = ntohl(inaddr.s_addr) >> 11;
 bit = 1 << (ntohl(inaddr.s_addr) >> 8 & 7);
 if ( map->map[offset] & bit )
  return 1;
 else
  return 0;
}

canonical_original_code:
int pfx_iplookup(struct in_addr inaddr, struct PFXMAP *map)
{
 unsigned long offset;
 unsigned char bit;
 offset = ntohl(inaddr.s_addr) >> 11;
 bit = 1 << (ntohl(inaddr.s_addr) >> 8 & 7);
 if ( map->map[offset] & bit )
  return 1;
 else
  return 0;
}

variable_types: struct PFXMAP { char name[32]; char map[4194303]; } *

variable_types:
offset
unsigned long

variable_types:
bit
unsigned char


decompiled_code:
__int64 __fastcall prof_iplookup(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 4488);
if ( result )
{
if ( pfx_iplookup(a2, result) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 4496);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 4488);
if ( result )
{
if ( func5(a2, result) )
result = 0LL;
else
result = *(_QWORD *)(a1 + 4496);
}
return result;
}

original_code:
struct _profile * prof_iplookup(struct _profile *p, struct in_addr inaddr)
{
 if ( p->PrefixMap == ((void *)0) )
  return ((void *)0);
 if ( pfx_iplookup(inaddr, p->PrefixMap) )
  return ((void *)0);
 return p->FailProfile;
}

canonical_original_code:
struct _profile *prof_iplookup(struct _profile *p, struct in_addr inaddr)
{
 if ( p->PrefixMap == ((void *)0) )
  return ((void *)0);
 if ( pfx_iplookup(inaddr, p->PrefixMap) )
  return ((void *)0);
 return p->FailProfile;
}

variable_types:
p
struct _profile *

return_type: struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS { char name[256]; char lib[256]; char args[256]; } *Accounting; char AccountingPrefix[256]; struct LIMITS { int gb; int kbit; } Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval { long tv_sec; long tv_usec; } rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP { char name[32]; char map[4194303]; } *PrefixMap; struct _profile *FailProfile; } *

user_defined_types: struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS *Accounting; char AccountingPrefix[256]; struct LIMITS Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP *PrefixMap; struct _profile *FailProfile; }


decompiled_code:
void __fastcall auth_iplookup(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rsi

v1 = getprofile(*(_QWORD *)(a1 + 72));
if ( v1 )
{
v2 = v1;
v3 = *(_QWORD *)(v1 + 4488);
if ( v3 )
{
if ( !pfx_iplookup(*(_DWORD *)(a1 + 40), v3) )
*(_QWORD *)(a1 + 72) = strdup(*(const char **)(v2 + 4496));
}
}
else
{
syslog(3, "Cant find profile in auth_iplookup (profile=%s)", *(const char **)(a1 + 72));
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rsi

v1 = getprofile(*(_QWORD *)(a1 + 72));
if ( v1 )
{
v2 = v1;
v3 = *(_QWORD *)(v1 + 4488);
if ( v3 )
{
if ( !func5(*(_DWORD *)(a1 + 40), v3) )
*(_QWORD *)(a1 + 72) = strdup(*(const char **)(v2 + 4496));
}
}
else
{
syslog(3, "Cant find profile in auth_iplookup (profile=%s)", *(const char **)(a1 + 72));
}
}

original_code:
void auth_iplookup(AUTHRESULT * authres)
{
 struct _profile *p;
 p = getprofile(authres->profile);
 if ( p == ((void *)0) )
 {
  syslog(3, "Cant find profile in auth_iplookup (profile=%s)", authres->profile);
  return;
 }
 if ( p->PrefixMap != ((void *)0) )
 {
  if ( pfx_iplookup(authres->in_addr, p->PrefixMap) )
   return;
  else
   authres->profile = strdup(p->FailProfile->Name);
 }
}

canonical_original_code:
void auth_iplookup(struct AUTHRESULT *authres)
{
 struct _profile *p;
 p = getprofile(authres->profile);
 if ( p == ((void *)0) )
 {
  syslog(3, "Cant find profile in auth_iplookup (profile=%s)", authres->profile);
  return;
 }
 if ( p->PrefixMap != ((void *)0) )
 {
  if ( pfx_iplookup(authres->in_addr, p->PrefixMap) )
   return;
  else
   authres->profile = strdup(p->FailProfile->Name);
 }
}

variable_types: struct AUTHRESULT { char *username; char *password; char *username_s; int port; char *hostname; struct in_addr { unsigned int s_addr; } in_addr; struct ARGS { char name[256]; char args[256]; } *args; int numargs; unsigned char authenticated; char *message; char *profile; unsigned char posting; unsigned long long bytes; int userkbit; char *logname; char *readpat; char *postpat; int timeleft; unsigned char overquota; unsigned char disabled; char *posthost; char *postabuse; char *postorg; } *

variable_types: struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS { char name[256]; char lib[256]; char args[256]; } *Accounting; char AccountingPrefix[256]; struct LIMITS { int gb; int kbit; } Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval { long tv_sec; long tv_usec; } rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP { char name[32]; char map[4194303]; } *PrefixMap; struct _profile *FailProfile; } *

user_defined_types: struct AUTHRESULT { char *username; char *password; char *username_s; int port; char *hostname; struct in_addr in_addr; struct ARGS *args; int numargs; unsigned char authenticated; char *message; char *profile; unsigned char posting; unsigned long long bytes; int userkbit; char *logname; char *readpat; char *postpat; int timeleft; unsigned char overquota; unsigned char disabled; char *posthost; char *postabuse; char *postorg; }


original_code:
static int
utf8_length(const unsigned char *start, const unsigned char *end)
{
    unsigned char mask = 0x80;
    const unsigned char *p;
    int length = 0;
    int left;
    for (; mask > 0 && (*start & mask) == mask; mask >>= 1)
        length++;
    if (length < 2 || length > 6)
        return 1;
    if (end != ((void *)0) && (end - start + 1) < length)
        return 1;
    left = length - 1;
    p = start + 1;
    for (p = start + 1; left > 0 && (*p & 0xc0) == 0x80; p++)
        left--;
    return (left == 0) ? length : 1;
}

canonical_original_code:
static int utf8_length(unsigned char *start, unsigned char *end)
{
    unsigned char mask = 0x80;
    unsigned char *p;
    int length = 0;
    int left;
    for (; mask > 0 && (*start & mask) == mask; mask >>= 1)
        length++;
    if (length < 2 || length > 6)
        return 1;
    if (end != ((void *)0) && (end - start + 1) < length)
        return 1;
    left = length - 1;
    p = start + 1;
    for (p = start + 1; left > 0 && (*p & 0xc0) == 0x80; p++)
        left--;
    return (left == 0) ? length : 1;
}

variable_types:
start
unsigned char *

variable_types:
end
unsigned char *

variable_types:
mask
unsigned char

variable_types:
p
unsigned char *

variable_types: length int

variable_types: left int


original_code:
static int
utf8_decode(const unsigned char *start, const unsigned char *end,
            uint32_t *result)
{
    uint32_t value = 0;
    int length, i;
    const unsigned char *p = start;
    unsigned char mask;
    length = utf8_length(start, end);
    if (length < 2) {
        *result = *start;
        return 1;
    }
    mask = (1 << (7 - length)) - 1;
    value = *p & mask;
    p++;
    for (i = length - 1; i > 0; i--) {
        value = (value << 6) | (*p & 0x3f);
        p++;
    }
    *result = value;
    return length;
}

canonical_original_code:
static int utf8_decode(unsigned char *start, unsigned char *end, unsigned int *result)
{
    unsigned int value = 0;
    int length; int i;
    unsigned char *p = start;
    unsigned char mask;
    length = utf8_length(start, end);
    if (length < 2) {
        *result = *start;
        return 1;
    }
    mask = (1 << (7 - length)) - 1;
    value = *p & mask;
    p++;
    for (i = length - 1; i > 0; i--) {
        value = (value << 6) | (*p & 0x3f);
        p++;
    }
    *result = value;
    return length;
}

variable_types:
result
unsigned int *

variable_types:
value
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall match_class(unsigned int a1, char *a2, unsigned __int64 a3)
{
unsigned int v3; // er14
char v4; // r13
char *v5; // rbx
char v7; // al
unsigned int v9; // [rsp+8h] [rbp-30h] BYREF
unsigned int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = *a2;
LOBYTE(v3) = *a2 == 94;
v5 = &a2[(unsigned __int8)v3];
if ( a3 >= (unsigned __int64)v5 )
{
v7 = 0;
do
{
if ( v7 && *v5 == 45 && a3 > (unsigned __int64)v5 )
{
v5 += (int)utf8_decode(v5 + 1, a3, (int *)&v9) + 1;
if ( v10[0] > a1 )
{
v7 = 0;
}
else
{
if ( v9 >= a1 )
{
LOBYTE(v3) = v4 != 94;
return v3;
}
v7 = 0;
}
}
else
{
v5 += (int)utf8_decode(v5, a3, (int *)v10);
if ( v10[0] == a1 )
{
LOBYTE(v3) = v4 != 94;
return v3;
}
v7 = 1;
}
}
while ( (unsigned __int64)v5 <= a3 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, char *a2, unsigned __int64 a3)
{
unsigned int v3; // er14
char v4; // r13
char *v5; // rbx
char v7; // al
unsigned int v9; // [rsp+8h] [rbp-30h] BYREF
unsigned int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = *a2;
LOBYTE(v3) = *a2 == 94;
v5 = &a2[(unsigned __int8)v3];
if ( a3 >= (unsigned __int64)v5 )
{
v7 = 0;
do
{
if ( v7 && *v5 == 45 && a3 > (unsigned __int64)v5 )
{
v5 += (int)func1(v5 + 1, a3, (int *)&v9) + 1;
if ( v10[0] > a1 )
{
v7 = 0;
}
else
{
if ( v9 >= a1 )
{
LOBYTE(v3) = v4 != 94;
return v3;
}
v7 = 0;
}
}
else
{
v5 += (int)func1(v5, a3, (int *)v10);
if ( v10[0] == a1 )
{
LOBYTE(v3) = v4 != 94;
return v3;
}
v7 = 1;
}
}
while ( (unsigned __int64)v5 <= a3 );
}
return v3;
}

original_code:
static unsigned char
match_class(uint32_t text, const unsigned char *start,
            const unsigned char *end)
{
    unsigned char reversed, allowrange;
    const unsigned char *p = start;
    uint32_t first, last;
    reversed = (*p == '^');
    if (reversed)
        p++;
    allowrange = 0;
    while (p <= end) {
        if (allowrange && *p == '-' && p < end) {
            p++;
            p += utf8_decode(p, end, &last);
            if (text >= first && text <= last)
                return !reversed;
            allowrange = 0;
        } else {
            p += utf8_decode(p, end, &first);
            if (text == first)
                return !reversed;
            allowrange = 1;
        }
    }
    return reversed;
}

canonical_original_code:
static unsigned char match_class(unsigned int text, unsigned char *start, unsigned char *end)
{
    unsigned char reversed; unsigned char allowrange;
    unsigned char *p = start;
    unsigned int first; unsigned int last;
    reversed = (*p == '^');
    if (reversed)
        p++;
    allowrange = 0;
    while (p <= end) {
        if (allowrange && *p == '-' && p < end) {
            p++;
            p += utf8_decode(p, end, &last);
            if (text >= first && text <= last)
                return !reversed;
            allowrange = 0;
        } else {
            p += utf8_decode(p, end, &first);
            if (text == first)
                return !reversed;
            allowrange = 1;
        }
    }
    return reversed;
}

variable_types:
text
unsigned int

variable_types:
reversed
unsigned char

variable_types:
allowrange
unsigned char

variable_types:
first
unsigned int

variable_types:
last
unsigned int

return_type: unsigned char


decompiled_code:
__int64 __fastcall match_pattern(char *a1, _BYTE *a2, unsigned __int64 a3)
{
_BYTE *v4; // rbp
unsigned int v6; // edx
unsigned __int8 v7; // al
char v8; // dl
char *v9; // r12
char v10; // al
bool v11; // bp
int v12; // eax
char v13; // dl
char v14; // al
char *v16; // r14
_BYTE *v17; // rdi
_BYTE *v18; // r12
unsigned int v19[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = a2;
if ( (unsigned __int64)a2 > a3 )
return *a1 == 0;
while ( 1 )
{
v8 = *a1;
if ( !*a1 )
break;
v7 = *v4;
if ( *v4 == 91 )
{
v16 = v4 + 1;
v17 = &v4[(v4[1] == 94) + 2];
if ( a3 < (unsigned __int64)v17 )
return (unsigned int)-1;
v18 = memchr(v17, 93, a3 - (_QWORD)v17 + 1);
v4 = v18;
if ( !v18 )
return (unsigned int)-1;
a1 += (int)utf8_decode(a1, 0LL, (int *)v19);
if ( !(unsigned __int8)match_class(v19[0], v16, (unsigned __int64)(v18 - 1)) )
return 0;
}
else
{
if ( v7 <= 0x5Bu )
{
if ( v7 == 42 )
goto LABEL_12;
if ( v7 == 63 )
{
v12 = 1;
if ( (v8 & 0xC0) == 0xC0 )
v12 = utf8_length(a1, 0LL);
a1 += v12;
goto LABEL_9;
}
}
else if ( v7 == 92 )
{
if ( !v4[1] )
return (unsigned int)-1;
++v4;
}
++a1;
if ( v8 != *v4 )
return 0;
}
LABEL_9:
if ( a3 < (unsigned __int64)++v4 )
return *a1 == 0;
}
if ( *v4 != 42 )
return (unsigned int)-1;
LABEL_12:
v9 = v4 + 1;
v10 = v4[1];
if ( v10 == 42 )
{
do
v10 = *++v9;
while ( *v9 == 42 );
}
v6 = 1;
if ( a3 >= (unsigned __int64)v9 )
{
v11 = v10 == 63 || (unsigned __int8)(v10 - 91) <= 1u;
do
{
v14 = *a1;
if ( !*a1 )
return (unsigned int)-1;
if ( v11 )
{
v6 = match_pattern(a1++, v9, a3);
}
else
{
v13 = *v9;
while ( v13 != v14 )
{
v14 = *++a1;
if ( !*a1 )
return (unsigned int)-1;
}
if ( !v13 )
return (unsigned int)-1;
v6 = match_pattern(++a1, v9 + 1, a3);
}
}
while ( !v6 );
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _BYTE *a2, unsigned __int64 a3)
{
_BYTE *v4; // rbp
unsigned int v6; // edx
unsigned __int8 v7; // al
char v8; // dl
char *v9; // r12
char v10; // al
bool v11; // bp
int v12; // eax
char v13; // dl
char v14; // al
char *v16; // r14
_BYTE *v17; // rdi
_BYTE *v18; // r12
unsigned int v19[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = a2;
if ( (unsigned __int64)a2 > a3 )
return *a1 == 0;
while ( 1 )
{
v8 = *a1;
if ( !*a1 )
break;
v7 = *v4;
if ( *v4 == 91 )
{
v16 = v4 + 1;
v17 = &v4[(v4[1] == 94) + 2];
if ( a3 < (unsigned __int64)v17 )
return (unsigned int)-1;
v18 = memchr(v17, 93, a3 - (_QWORD)v17 + 1);
v4 = v18;
if ( !v18 )
return (unsigned int)-1;
a1 += (int)func1(a1, 0LL, (int *)v19);
if ( !(unsigned __int8)func2(v19[0], v16, (unsigned __int64)(v18 - 1)) )
return 0;
}
else
{
if ( v7 <= 0x5Bu )
{
if ( v7 == 42 )
goto LABEL_12;
if ( v7 == 63 )
{
v12 = 1;
if ( (v8 & 0xC0) == 0xC0 )
v12 = func0(a1, 0LL);
a1 += v12;
goto LABEL_9;
}
}
else if ( v7 == 92 )
{
if ( !v4[1] )
return (unsigned int)-1;
++v4;
}
++a1;
if ( v8 != *v4 )
return 0;
}
LABEL_9:
if ( a3 < (unsigned __int64)++v4 )
return *a1 == 0;
}
if ( *v4 != 42 )
return (unsigned int)-1;
LABEL_12:
v9 = v4 + 1;
v10 = v4[1];
if ( v10 == 42 )
{
do
v10 = *++v9;
while ( *v9 == 42 );
}
v6 = 1;
if ( a3 >= (unsigned __int64)v9 )
{
v11 = v10 == 63 || (unsigned __int8)(v10 - 91) <= 1u;
do
{
v14 = *a1;
if ( !*a1 )
return (unsigned int)-1;
if ( v11 )
{
v6 = func3(a1++, v9, a3);
}
else
{
v13 = *v9;
while ( v13 != v14 )
{
v14 = *++a1;
if ( !*a1 )
return (unsigned int)-1;
}
if ( !v13 )
return (unsigned int)-1;
v6 = func3(++a1, v9 + 1, a3);
}
}
while ( !v6 );
}
return v6;
}

original_code:
static int
match_pattern(const unsigned char *text, const unsigned char *start,
              const unsigned char *end)
{
    const unsigned char *q, *endclass;
    const unsigned char *p = start;
    unsigned char ismeta;
    int matched;
    uint32_t c;
    for (; p <= end; p++) {
        if (!*text && *p != '*')
            return -1;
        switch (*p) {
        case '\\':
            if (!*++p)
                return -1;
        default:
            if (*text++ != *p)
                return 0;
            break;
        case '?':
            text += (((*text) & 0xc0) == 0xc0) ? utf8_length(text, ((void *)0)) : 1;
            break;
        case '*':
            for (++p; *p == '*'; p++)
                ;
            if (p > end)
                return 1;
            ismeta = (*p == '[' || *p == '?' || *p == '\\');
            while (*text) {
                if (ismeta) {
                    matched = match_pattern(text++, p, end);
                } else {
                    while (*text && *text != *p)
                        text++;
                    if (!*text)
                        return -1;
                    matched = match_pattern(++text, p + 1, end);
                }
                if (matched != 0)
                    return matched;
            }
            return -1;
        case '[':
            p++;
            q = p + (*p == '^') + 1;
            if (q > end)
                return -1;
            endclass = memchr(q, ']', (size_t) (end - q + 1));
            if (!endclass)
                return -1;
            text += utf8_decode(text, ((void *)0), &c);
            if (!match_class(c, p, endclass - 1))
                return 0;
            p = endclass;
            break;
        }
    }
    return (*text == '\0');
}

canonical_original_code:
static int match_pattern(unsigned char *text, unsigned char *start, unsigned char *end)
{
    unsigned char *q; unsigned char *endclass;
    unsigned char *p = start;
    unsigned char ismeta;
    int matched;
    unsigned int c;
    for (; p <= end; p++) {
        if (!*text && *p != '*')
            return -1;
        switch (*p) {
        case '\\':
            if (!*++p)
                return -1;
        default:
            if (*text++ != *p)
                return 0;
            break;
        case '?':
            text += (((*text) & 0xc0) == 0xc0) ? utf8_length(text, ((void *)0)) : 1;
            break;
        case '*':
            for (++p; *p == '*'; p++)
                ;
            if (p > end)
                return 1;
            ismeta = (*p == '[' || *p == '?' || *p == '\\');
            while (*text) {
                if (ismeta) {
                    matched = match_pattern(text++, p, end);
                } else {
                    while (*text && *text != *p)
                        text++;
                    if (!*text)
                        return -1;
                    matched = match_pattern(++text, p + 1, end);
                }
                if (matched != 0)
                    return matched;
            }
            return -1;
        case '[':
            p++;
            q = p + (*p == '^') + 1;
            if (q > end)
                return -1;
            endclass = memchr(q, ']', (unsigned long) (end - q + 1));
            if (!endclass)
                return -1;
            text += utf8_decode(text, ((void *)0), &c);
            if (!match_class(c, p, endclass - 1))
                return 0;
            p = endclass;
            break;
        }
    }
    return (*text == '\0');
}

variable_types:
text
unsigned char *

variable_types:
q
unsigned char *

variable_types:
endclass
unsigned char *

variable_types:
ismeta
unsigned char

variable_types: matched int

variable_types:
c
unsigned int


original_code:
int match_expression(const unsigned char *text, const unsigned char *start, unsigned char allowpoison)
{
    const unsigned char *end, *split;
    const unsigned char *p = start;
    unsigned char reverse, escaped;
    unsigned char match = 0;
    unsigned char poison = 0;
    unsigned char poisoned = 0;
    if (!*p)
        return !*text ? UWILDMAT_MATCH : UWILDMAT_FAIL;
    end = start + strlen((const char *) start) - 1;
    for (; p <= end + 1; p = split + 1) {
        if (allowpoison)
            poison = (*p == '@');
        reverse = (*p == '!') || poison;
        if (reverse)
            p++;
        for (escaped = 0, split = p; split <= end; split++) {
            if (*split == '[') {
                split++;
                if (*split == ']')
                    split++;
                while (split <= end && *split != ']')
                    split++;
            }
            if (*split == ',' && !escaped)
                break;
            escaped = (*split == '\\') ? !escaped : 0;
        }
        if (match == !reverse && poison == poisoned)
            continue;
        if (match_pattern(text, p, split - 1) == 1) {
            poisoned = poison;
            match = !reverse;
        }
    }
    if (poisoned)
        return UWILDMAT_POISON;
    return match ? UWILDMAT_MATCH : UWILDMAT_FAIL;
}

canonical_original_code:
int match_expression(unsigned char *text, unsigned char *start, unsigned char allowpoison)
{
    unsigned char *end; unsigned char *split;
    unsigned char *p = start;
    unsigned char reverse; unsigned char escaped;
    unsigned char match = 0;
    unsigned char poison = 0;
    unsigned char poisoned = 0;
    if (!*p)
        return !*text ? UWILDMAT_MATCH : UWILDMAT_FAIL;
    end = start + strlen((char *) start) - 1;
    for (; p <= end + 1; p = split + 1) {
        if (allowpoison)
            poison = (*p == '@');
        reverse = (*p == '!') || poison;
        if (reverse)
            p++;
        for (escaped = 0, split = p; split <= end; split++) {
            if (*split == '[') {
                split++;
                if (*split == ']')
                    split++;
                while (split <= end && *split != ']')
                    split++;
            }
            if (*split == ',' && !escaped)
                break;
            escaped = (*split == '\\') ? !escaped : 0;
        }
        if (match == !reverse && poison == poisoned)
            continue;
        if (match_pattern(text, p, split - 1) == 1) {
            poisoned = poison;
            match = !reverse;
        }
    }
    if (poisoned)
        return UWILDMAT_POISON;
    return match ? UWILDMAT_MATCH : UWILDMAT_FAIL;
}

variable_types:
start
unsigned char *

variable_types:
allowpoison
unsigned char

variable_types:
end
unsigned char *

variable_types:
split
unsigned char *

variable_types:
p
unsigned char *

variable_types:
reverse
unsigned char

variable_types:
escaped
unsigned char

variable_types:
match
unsigned char

variable_types:
poison
unsigned char

variable_types:
poisoned
unsigned char


uwildmat

decompiled_code:
bool __fastcall uwildmat(char *a1, __int64 a2)
{
bool result; // al

if ( *(_BYTE *)a2 != 42 || (result = 1, *(_BYTE *)(a2 + 1)) )
result = (unsigned int)match_expression(a1, (const char *)a2, 0) == 1;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(char *a1, __int64 a2)
{
bool result; // al

if ( *(_BYTE *)a2 != 42 || (result = 1, *(_BYTE *)(a2 + 1)) )
result = (unsigned int)func4(a1, (const char *)a2, 0) == 1;
return result;
}

original_code:
unsigned char
uwildmat(const char *text, const char *pat)
{
    const unsigned char *utext = (const unsigned char *) text;
    const unsigned char *upat = (const unsigned char *) pat;
    if (upat[0] == '*' && upat[1] == '\0')
        return 1;
    else
        return (match_expression(utext, upat, 0) == UWILDMAT_MATCH);
}

canonical_original_code:
unsigned char uwildmat(char *text, char *pat)
{
    unsigned char *utext = (const unsigned char *) text;
    unsigned char *upat = (const unsigned char *) pat;
    if (upat[0] == '*' && upat[1] == '\0')
        return 1;
    else
        return (match_expression(utext, upat, 0) == UWILDMAT_MATCH);
}

variable_types:
text
char *

variable_types:
pat
char *

variable_types:
utext
unsigned char *

variable_types:
upat
unsigned char *


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

if ( *(_BYTE *)a2 != 42 || (result = 1LL, *(_BYTE *)(a2 + 1)) )
result = match_expression(a1, (const char *)a2, 1);
return result;
}

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

if ( *(_BYTE *)a2 != 42 || (result = 1LL, *(_BYTE *)(a2 + 1)) )
result = func4(a1, (const char *)a2, 1);
return result;
}

original_code:
enum uwildmat
uwildmat_poison(const char *text, const char *pat)
{
    const unsigned char *utext = (const unsigned char *) text;
    const unsigned char *upat = (const unsigned char *) pat;
    if (upat[0] == '*' && upat[1] == '\0')
        return UWILDMAT_MATCH;
    else
        return match_expression(utext, upat, 1);
}

canonical_original_code:
enum uwildmat uwildmat_poison(char *text, char *pat)
{
    unsigned char *utext = (const unsigned char *) text;
    unsigned char *upat = (const unsigned char *) pat;
    if (upat[0] == '*' && upat[1] == '\0')
        return UWILDMAT_MATCH;
    else
        return match_expression(utext, upat, 1);
}

return_type: enum uwildmat { UWILDMAT_FAIL=0, UWILDMAT_MATCH=1, UWILDMAT_POISON=2 }


decompiled_code:
_BOOL8 __fastcall uwildmat_simple(char *a1, __int64 a2)
{
_BOOL8 result; // rax
size_t v3; // rax

if ( *(_BYTE *)a2 != 42 || (result = 1LL, *(_BYTE *)(a2 + 1)) )
{
v3 = strlen((const char *)a2);
result = (unsigned int)match_pattern(a1, (_BYTE *)a2, a2 + v3 - 1) == 1;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char *a1, __int64 a2)
{
_BOOL8 result; // rax
size_t v3; // rax

if ( *(_BYTE *)a2 != 42 || (result = 1LL, *(_BYTE *)(a2 + 1)) )
{
v3 = strlen((const char *)a2);
result = (unsigned int)func3(a1, (_BYTE *)a2, a2 + v3 - 1) == 1;
}
return result;
}

original_code:
int uwildmat_simple(const char *text, const char *pat)
{
    const unsigned char *utext = (const unsigned char *) text;
    const unsigned char *upat = (const unsigned char *) pat;
    size_t length;
    if (upat[0] == '*' && upat[1] == '\0')
        return 1;
    else {
        length = strlen(pat);
        return (match_pattern(utext, upat, upat + length - 1) == 1);
    }
}

canonical_original_code:
int uwildmat_simple(char *text, char *pat)
{
    unsigned char *utext = (const unsigned char *) text;
    unsigned char *upat = (const unsigned char *) pat;
    unsigned long length;
    if (upat[0] == '*' && upat[1] == '\0')
        return 1;
    else {
        length = strlen(pat);
        return (match_pattern(utext, upat, upat + length - 1) == 1);
    }
}

variable_types:
length
unsigned long


decompiled_code:
int __fastcall cmp_getgroup(const void *a1, const void *a2)
{
return strcmp((const char *)a1 + 33, (const char *)a2 + 33);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp((const char *)a1 + 33, (const char *)a2 + 33);
}

original_code:
int cmp_getgroup(const void *a, const void *b)
{
 const ACTIVE *s1 = (const ACTIVE *) a;
 const ACTIVE *s2 = (const ACTIVE *) b;
 return strcmp(s1->newsgroup, s2->newsgroup);
}

canonical_original_code:
int cmp_getgroup(void *a, void *b)
{
 struct ACTIVE *s1 = (const ACTIVE *) a;
 struct ACTIVE *s2 = (const ACTIVE *) b;
 return strcmp(s1->newsgroup, s2->newsgroup);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct ACTIVE { unsigned long hi; unsigned long lo; unsigned long times; unsigned long id; char mode; char newsgroup[160]; char server[32]; } *


isinoverviewfmt

decompiled_code:
__int64 __fastcall isinoverviewfmt(char *s1)
{
const char *v1; // rbx
size_t v2; // r13
__int64 v3; // rbp

v1 = overviewfmt;
if ( !overviewfmt )
return 0LL;
v2 = strlen(s1);
v3 = (unsigned int)((_DWORD)&overviewfmt + 8);
while ( strncasecmp(s1, v1, v2) )
{
v3 += 8LL;
v1 = *(const char **)(v3 - 8);
if ( !v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
const char *v1; // rbx
size_t v2; // r13
__int64 v3; // rbp

v1 = overviewfmt;
if ( !overviewfmt )
return 0LL;
v2 = strlen(s1);
v3 = (unsigned int)((_DWORD)&overviewfmt + 8);
while ( strncasecmp(s1, v1, v2) )
{
v3 += 8LL;
v1 = *(const char **)(v3 - 8);
if ( !v1 )
return 0LL;
}
return 1LL;
}

original_code:
int isinoverviewfmt(const char *hdr)
{
 int i=0;
 while(overviewfmt[i] != ((void *)0))
 {
  if ( strncasecmp(hdr, overviewfmt[i], strlen(hdr)) == 0 )
   return 1;
  i++;
 }
 return 0;
}

canonical_original_code:
int isinoverviewfmt(char *hdr)
{
 int i = 0;
 while(overviewfmt[i] != ((void *)0))
 {
  if ( strncasecmp(hdr, overviewfmt[i], strlen(hdr)) == 0 )
   return 1;
  i++;
 }
 return 0;
}

variable_types:
hdr
char *

variable_types: i int


clearactive

decompiled_code:
__int64 clearactive()
{
memunmap(newsgroups, 29696000LL);
*master = 0;
return info("Active file freed");
}

canonical_decompiled_code:
__int64 func5()
{
memunmap(newsgroups, 29696000LL);
*master = 0;
return info("Active file freed");
}

original_code:
void clearactive(void)
{
 memunmap(newsgroups, sizeof(ACTIVE) * 128000);
 master->numgroups = 0;
 info("Active file freed");
}

canonical_original_code:
void clearactive()
{
 memunmap(newsgroups, sizeof(ACTIVE) * 128000);
 master->numgroups = 0;
 info("Active file freed");
}


reloadactive

decompiled_code:
__int64 reloadactive()
{
__int64 result; // rax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( stat(*((const char **)&cfg + 11), &v1) == -1 )
die("Can't stat active file %s", *((const char **)&cfg + 11));
result = 0LL;
if ( *(_QWORD *)(master + 40LL) < v1.st_mtim.tv_sec )
{
clearactive();
result = loadactive();
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( stat(*((const char **)&cfg + 11), &v1) == -1 )
die("Can't stat active file %s", *((const char **)&cfg + 11));
result = 0LL;
if ( *(_QWORD *)(master + 40LL) < v1.st_mtim.tv_sec )
{
func5();
result = func4();
}
return result;
}

original_code:
int reloadactive(void)
{
 struct stat _stat;
 if ( stat(cfg.ActiveFile,&_stat) == -1 )
  die("Can't stat active file %s", cfg.ActiveFile);
 if ( master->laststatactive < _stat.st_mtim.tv_sec )
 {
  clearactive();
  return loadactive();
 }
 return 0;
}

canonical_original_code:
int reloadactive()
{
 struct stat _stat;
 if ( stat(cfg.ActiveFile,&_stat) == -1 )
  die("Can't stat active file %s", cfg.ActiveFile);
 if ( master->laststatactive < _stat.st_mtim.tv_sec )
 {
  clearactive();
  return loadactive();
 }
 return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


getgroup

decompiled_code:
void *__fastcall getgroup(char *src)
{
char v2[248]; // [rsp+0h] [rbp-F8h] BYREF

memset(v2, 0, 0xE8uLL);
strncpy(&v2[33], src, 0xA0uLL);
return bsearch(v2, newsgroups, (int)*master, 0xE8uLL, cmp_getgroup);
}

canonical_decompiled_code:
void *__fastcall func7(char *src)
{
char v2[248]; // [rsp+0h] [rbp-F8h] BYREF

memset(v2, 0, 0xE8uLL);
strncpy(&v2[33], src, 0xA0uLL);
return bsearch(v2, newsgroups, (int)*master, 0xE8uLL, cmp_getgroup);
}

original_code:
ACTIVE* getgroup(const char *groupname)
{
 ACTIVE ng;
 memset(&ng, 0, sizeof(ACTIVE));
 strncpy(ng.newsgroup, groupname, 160);
 return bsearch(&ng, newsgroups, master->numgroups, sizeof(ACTIVE), cmp_getgroup);
}

canonical_original_code:
struct ACTIVE *getgroup(char *groupname)
{
 struct ACTIVE ng;
 memset(&ng, 0, sizeof(ACTIVE));
 strncpy(ng.newsgroup, groupname, 160);
 return bsearch(&ng, newsgroups, master->numgroups, sizeof(ACTIVE), cmp_getgroup);
}

variable_types:
groupname
char *

return_type: struct ACTIVE { unsigned long hi; unsigned long lo; unsigned long times; unsigned long id; char mode; char newsgroup[160]; char server[32]; } *


curlRealloc

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

if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
return result;
}

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

if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
return result;
}

original_code:
static void * curlRealloc(void *ptr, size_t size)
{
    if (ptr)
        return realloc(ptr, size);
    else
        return malloc(size);
}

canonical_original_code:
static void *curlRealloc(void *ptr, unsigned long size)
{
    if (ptr)
        return realloc(ptr, size);
    else
        return malloc(size);
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

return_type: void *


curlWriteCallback

decompiled_code:
size_t __fastcall curlWriteCallback(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
char *v6; // rax
size_t v7; // rax

v5 = a3 * a2;
v6 = (char *)curlRealloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_QWORD *)(a4 + 8) + v5;
*(_QWORD *)(a4 + 8) = v7;
*(_BYTE *)(*(_QWORD *)a4 + v7) = 0;
}
return v5;
}

original_code:
size_t curlWriteCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
    size_t realsize = size * nmemb;
    struct curlMemStruct *mem = (struct curlMemStruct *)data;
    mem->mem = curlRealloc(mem->mem, mem->size + realsize + 1);
    if (mem->mem) {
        memcpy( &(mem->mem[mem->size]), ptr, realsize );
        mem->size += realsize;
        mem->mem[mem->size] = 0;
    }
    return realsize;
}

canonical_original_code:
unsigned long curlWriteCallback(void *ptr, unsigned long size, unsigned long nmemb, void *data)
{
    unsigned long realsize = size * nmemb;
    struct curlMemStruct *mem = (struct curlMemStruct *)data;
    mem->mem = curlRealloc(mem->mem, mem->size + realsize + 1);
    if (mem->mem) {
        memcpy( &(mem->mem[mem->size]), ptr, realsize );
        mem->size += realsize;
        mem->mem[mem->size] = 0;
    }
    return realsize;
}

variable_types:
nmemb
unsigned long

variable_types:
data
void *

variable_types:
realsize
unsigned long

variable_types: struct curlMemStruct { char *mem; unsigned long size; } *

return_type: unsigned long


curlGetURL

decompiled_code:
__int64 __fastcall curlGetURL(__int64 a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rbp

curl_global_init(3LL);
v2 = curl_easy_init();
v3 = v2;
if ( v2 )
{
v4 = curlGetCurlURL(a1, a2, v2);
curl_easy_cleanup(v3);
curl_global_cleanup();
}
else
{
syslog(3, "curlGetURL: cant initialize curl!");
v4 = 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rbp

curl_global_init(3LL);
v2 = curl_easy_init();
v3 = v2;
if ( v2 )
{
v4 = func2(a1, a2, v2);
curl_easy_cleanup(v3);
curl_global_cleanup();
}
else
{
syslog(3, "curlGetURL: cant initialize curl!");
v4 = 0LL;
}
return v4;
}

original_code:
char * curlGetURL(const char *url, struct curlMemStruct *curlData)
{
    CURL * curl;
    curl_global_init(((1<<0)|(1<<1)));
    curl = curl_easy_init();
    if ( !curl ) {
        syslog(3, "curlGetURL: cant initialize curl!");
        return ((void *)0);
    }
    char * memptr = curlGetCurlURL(url, curlData, curl);
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    return memptr;
}

canonical_original_code:
char *curlGetURL(char *url, struct curlMemStruct *curlData)
{
    void *curl;
    curl_global_init(((1<<0)|(1<<1)));
    curl = curl_easy_init();
    if ( !curl ) {
        syslog(3, "curlGetURL: cant initialize curl!");
        return ((void *)0);
    }
    char *memptr = curlGetCurlURL(url, curlData, curl);
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    return memptr;
}

variable_types:
url
char *

variable_types:
curl
void *

variable_types:
memptr
char *

user_defined_types: struct curlMemStruct { char *mem; unsigned long size; }


hash

decompiled_code:
__int64 __fastcall hash(__int64 a1, __int64 a2, __int64 a3)
{
__pid_t v5; // [rsp+Ch] [rbp-9Ch] BYREF
char v6[96]; // [rsp+10h] [rbp-98h] BYREF
struct timeval tv; // [rsp+70h] [rbp-38h] BYREF
char v8[40]; // [rsp+80h] [rbp-28h] BYREF

MD5_Init(v6);
gettimeofday(&tv, 0LL);
v5 = getpid();
MD5_Update(v6, &tv, 8LL);
MD5_Update(v6, &tv.tv_usec, 8LL);
MD5_Update(v6, &v5, 4LL);
MD5_Update(v6, a1, a2);
MD5_Final(v8, v6);
return md5_bytes2digest(a3, v8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__pid_t v5; // [rsp+Ch] [rbp-9Ch] BYREF
char v6[96]; // [rsp+10h] [rbp-98h] BYREF
struct timeval tv; // [rsp+70h] [rbp-38h] BYREF
char v8[40]; // [rsp+80h] [rbp-28h] BYREF

MD5_Init(v6);
gettimeofday(&tv, 0LL);
v5 = getpid();
MD5_Update(v6, &tv, 8LL);
MD5_Update(v6, &tv.tv_usec, 8LL);
MD5_Update(v6, &v5, 4LL);
MD5_Update(v6, a1, a2);
MD5_Final(v8, v6);
return md5_bytes2digest(a3, v8);
}

original_code:
static const char *hash (const char *str, unsigned long len
  , char digest[16 * 2 + 1])
{
 unsigned char md5_bytes[16];
 struct timeval now;
 MD5_CTX md5_ctx;
 MD5_Init(&md5_ctx);
 gettimeofday(&now, 0);
 pid_t pid = getpid();
 MD5_Update(&md5_ctx, &now.tv_sec, sizeof (now.tv_sec));
 MD5_Update(&md5_ctx, &now.tv_usec, sizeof (now.tv_usec));
 MD5_Update(&md5_ctx, &pid, sizeof (pid));
 MD5_Update(&md5_ctx, (const unsigned char *)str, len);
 MD5_Final(md5_bytes, &md5_ctx);
 return md5_bytes2digest(digest, md5_bytes);
}

canonical_original_code:
static char *hash(char *str, unsigned long len, char digest[-1])
{
 unsigned char md5_bytes[16];
 struct timeval now;
 struct MD5state_st md5_ctx;
 MD5_Init(&md5_ctx);
 gettimeofday(&now, 0);
 int pid = getpid();
 MD5_Update(&md5_ctx, &now.tv_sec, sizeof (now.tv_sec));
 MD5_Update(&md5_ctx, &now.tv_usec, sizeof (now.tv_usec));
 MD5_Update(&md5_ctx, &pid, sizeof (pid));
 MD5_Update(&md5_ctx, (unsigned char *)str, len);
 MD5_Final(md5_bytes, &md5_ctx);
 return md5_bytes2digest(digest, md5_bytes);
}

variable_types:
str
char *

variable_types:
len
unsigned long

variable_types:
digest
char [-1]

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

variable_types: struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; }

variable_types: pid int


decompiled_code:
const char *__fastcall handshake_pop3(__int64 a1, const char *a2)
{
int v2; // eax
const char *v3; // rdx

v2 = read_socket();
v3 = "Connection Failed: %m";
if ( v2 > 0 )
{
a2[v2] = 0;
if ( *a2 == 43 )
{
v3 = 0LL;
}
else if ( a2[1] == 79 )
{
v3 = 0LL;
}
else
{
v3 = 0LL;
if ( a2[2] != 75 )
v3 = a2;
}
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1, const char *a2)
{
int v2; // eax
const char *v3; // rdx

v2 = read_socket();
v3 = "Connection Failed: %m";
if ( v2 > 0 )
{
a2[v2] = 0;
if ( *a2 == 43 )
{
v3 = 0LL;
}
else if ( a2[1] == 79 )
{
v3 = 0LL;
}
else
{
v3 = 0LL;
if ( a2[2] != 75 )
v3 = a2;
}
}
return v3;
}

original_code:
char* handshake_pop3(int sock, char *buf, int size, int timeout)
{
 int n;
 if ( (n=read_socket(sock, buf, size, timeout)) <= 0 )
  return("Connection Failed: %m");
 buf[n] = 0;
 if ( buf[0] != '+' && buf[1] != 'O' && buf[2] != 'K' )
  return buf;
 return ((void *)0);
}

canonical_original_code:
char *handshake_pop3(int sock, char *buf, int size, int timeout)
{
 int n;
 if ( (n=read_socket(sock, buf, size, timeout)) <= 0 )
  return("Connection Failed: %m");
 buf[n] = 0;
 if ( buf[0] != '+' && buf[1] != 'O' && buf[2] != 'K' )
  return buf;
 return ((void *)0);
}

variable_types: sock int

variable_types:
buf
char *

variable_types: size int

variable_types: timeout int

variable_types: n int


decompiled_code:
char *__fastcall auth_pop3(__int64 a1, __int64 a2, const char *a3)
{
char *result; // rax
unsigned int v5; // eax
unsigned int v6; // ebx
const char *v7; // rax
size_t v8; // rax
size_t v9; // rax
size_t v10; // rax
unsigned int v11; // [rsp+Ch] [rbp-19Ch] BYREF
char v12[128]; // [rsp+10h] [rbp-198h] BYREF
char s[280]; // [rsp+90h] [rbp-118h] BYREF

if ( (unsigned int)_isoc99_sscanf(a3, "%128[^:]:%d", v12, &v11) == 2 )
{
v5 = connect_socket(v12, v11);
v6 = v5;
if ( v5 == -1 )
{
syslog(3, "auth_pop3: Could not connect to POP3 server %s", v12);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
v7 = handshake_pop3(v5, s);
if ( v7 )
{
syslog(3, "auth_pop3: Server %s failed: %s", v12, v7);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
sprintf(s, "USER %s\r\n", *(const char **)(a1 + 16));
v8 = strlen(s);
write_socket(v6, s, v8, *(unsigned int *)(a2 + 104));
if ( read_socket(v6, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0
|| (sprintf(s, "PASS %s\r\n", *(const char **)(a1 + 8)),
v9 = strlen(s),
write_socket(v6, s, v9, *(unsigned int *)(a2 + 104)),
read_socket(v6, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0) )
{
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
if ( !strncasecmp("+OK", s, 3uLL) )
{
strcpy(s, "QUIT\r\n");
v10 = strlen(s);
write_socket(v6, s, v10, *(unsigned int *)(a2 + 104));
close(v6);
*(_BYTE *)(a1 + 60) = 1;
result = strdup("281 Authentication Accepted\r\n");
}
else
{
result = strdup("482 Authentication Rejected\r\n");
}
*(_QWORD *)(a1 + 64) = result;
}
}
}
}
else
{
syslog(3, "auth_pop3: Wrong argument syntax \"%s\"", a3);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, __int64 a2, const char *a3)
{
char *result; // rax
unsigned int v5; // eax
unsigned int v6; // ebx
const char *v7; // rax
size_t v8; // rax
size_t v9; // rax
size_t v10; // rax
unsigned int v11; // [rsp+Ch] [rbp-19Ch] BYREF
char v12[128]; // [rsp+10h] [rbp-198h] BYREF
char s[280]; // [rsp+90h] [rbp-118h] BYREF

if ( (unsigned int)_isoc99_sscanf(a3, "%128[^:]:%d", v12, &v11) == 2 )
{
v5 = connect_socket(v12, v11);
v6 = v5;
if ( v5 == -1 )
{
syslog(3, "auth_pop3: Could not connect to POP3 server %s", v12);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
v7 = func0(v5, s);
if ( v7 )
{
syslog(3, "auth_pop3: Server %s failed: %s", v12, v7);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
sprintf(s, "USER %s\r\n", *(const char **)(a1 + 16));
v8 = strlen(s);
write_socket(v6, s, v8, *(unsigned int *)(a2 + 104));
if ( read_socket(v6, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0
|| (sprintf(s, "PASS %s\r\n", *(const char **)(a1 + 8)),
v9 = strlen(s),
write_socket(v6, s, v9, *(unsigned int *)(a2 + 104)),
read_socket(v6, s, 256LL, *(unsigned int *)(a2 + 104)) <= 0) )
{
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
else
{
if ( !strncasecmp("+OK", s, 3uLL) )
{
strcpy(s, "QUIT\r\n");
v10 = strlen(s);
write_socket(v6, s, v10, *(unsigned int *)(a2 + 104));
close(v6);
*(_BYTE *)(a1 + 60) = 1;
result = strdup("281 Authentication Accepted\r\n");
}
else
{
result = strdup("482 Authentication Rejected\r\n");
}
*(_QWORD *)(a1 + 64) = result;
}
}
}
}
else
{
syslog(3, "auth_pop3: Wrong argument syntax \"%s\"", a3);
result = strdup("482 Authentication Temporarily Unavailable\r\n");
*(_QWORD *)(a1 + 64) = result;
}
return result;
}

original_code:
void auth_pop3(AUTHRESULT *authres, struct config *cf, char *args)
{
 char tmp[256];
 char server[128];
 int port;
 int sock;
 char *err;
 if ( sscanf(args, "%128[^:]:%d", server, &port) != 2 )
 {
  syslog(3, "auth_pop3: Wrong argument syntax \"%s\"", args);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( (sock=connect_socket(server, port)) == -1 )
 {
  syslog(3, "auth_pop3: Could not connect to POP3 server %s", server);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( (err=handshake_pop3(sock, tmp, 256, cf->ServerReadTimeout)) != ((void *)0) )
 {
  syslog(3, "auth_pop3: Server %s failed: %s", server, err);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "USER %s\r\n", authres->username_s);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "PASS %s\r\n", authres->password);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( strncasecmp("+OK", tmp, 3) == 0 )
 {
  sprintf(tmp, "QUIT\r\n");
  write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
  close(sock);
  authres->authenticated = 1;
  authres->message = strdup("281 Authentication Accepted\r\n");
  return;
 }
 authres->message = strdup("482 Authentication Rejected\r\n");
 return;
}

canonical_original_code:
void auth_pop3(struct AUTHRESULT *authres, struct config *cf, char *args)
{
 char tmp[256];
 char server[128];
 int port;
 int sock;
 char *err;
 if ( sscanf(args, "%128[^:]:%d", server, &port) != 2 )
 {
  syslog(3, "auth_pop3: Wrong argument syntax \"%s\"", args);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( (sock=connect_socket(server, port)) == -1 )
 {
  syslog(3, "auth_pop3: Could not connect to POP3 server %s", server);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( (err=handshake_pop3(sock, tmp, 256, cf->ServerReadTimeout)) != ((void *)0) )
 {
  syslog(3, "auth_pop3: Server %s failed: %s", server, err);
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "USER %s\r\n", authres->username_s);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 sprintf(tmp, "PASS %s\r\n", authres->password);
 write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
 if ( read_socket(sock, tmp, 256, cf->ServerReadTimeout) <= 0 )
 {
  authres->message = strdup("482 Authentication Temporarily Unavailable\r\n");
  return;
 }
 if ( strncasecmp("+OK", tmp, 3) == 0 )
 {
  sprintf(tmp, "QUIT\r\n");
  write_socket(sock, tmp, strlen(tmp), cf->ServerReadTimeout);
  close(sock);
  authres->authenticated = 1;
  authres->message = strdup("281 Authentication Accepted\r\n");
  return;
 }
 authres->message = strdup("482 Authentication Rejected\r\n");
 return;
}

variable_types: struct AUTHRESULT { char *username; char *password; char *username_s; int port; char *hostname; struct in_addr { unsigned int s_addr; } in_addr; struct ARGS { char name[256]; char args[256]; } *args; int numargs; unsigned char authenticated; char *message; char *profile; unsigned char posting; unsigned long long bytes; int userkbit; char *logname; char *readpat; char *postpat; int timeleft; unsigned char overquota; unsigned char disabled; char *posthost; char *postabuse; char *postorg; } *

variable_types: struct config { char *ListenPorts; char *BindAddress; char *RunAsUser; char *PidFile; char *StatsFile; int StatsFilePeriod; char *ConnDumpFile; char *BasePath; char *AccessFile; char *ServerFile; char *OverviewFmtFile; char *ActiveFile; char *NewsgroupsFile; int ServerReadTimeout; int ServerConnectTimeout; int ClientReadTimeout; int MaxConnections; int LogWriteclient; int LogReadserver; int LogWriteserver; int LogCommands; int LogMissing; int LogAuthInfo; char *PostServer; int PostServerPort; int PostXTraceHeader; char *ModeratorDomain; char *MailerPath; int BufSize; int SockBufSize; int ListenBackLog; int DenyNoIndexField; int DownDelay; int RetryDelay; int AccountingDelay; int RatePeriod; int DNSLookups; int DropUnknown; char *DisableFile; char *DisableText; int NoSuchArticleRetries; int LocalDreader; int CoreBind; int EnableSSL; char *ListenSSLPorts; char *AsLoginURL; char *AsLogoutURL; int RemoteConfig; char *WildmatURL; int JSONACL; char *ACLURL; int JSONRL; char *RLURL; char *null; } *

variable_types:
args
char *

variable_types:
tmp
char [256]

variable_types:
server
char [128]

variable_types: port int

variable_types:
err
char *


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

result = master;
*(_DWORD *)(master + 16953364LL) = 0;
return result;
}

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

result = master;
*(_DWORD *)(master + 16953364LL) = 0;
return result;
}

original_code:
static void dl_unlock(void)
{
 master->dllock = 0;
}

canonical_original_code:
static void dl_unlock()
{
 master->dllock = 0;
}


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

result = master;
if ( *(_DWORD *)(master + 16953364LL) )
{
do
{
usleep(0xC8u);
result = master;
}
while ( *(_DWORD *)(master + 16953364LL) );
*(_DWORD *)(master + 16953364LL) = 1;
}
else
{
*(_DWORD *)(master + 16953364LL) = 1;
}
return result;
}

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

result = master;
if ( *(_DWORD *)(master + 16953364LL) )
{
do
{
usleep(0xC8u);
result = master;
}
while ( *(_DWORD *)(master + 16953364LL) );
*(_DWORD *)(master + 16953364LL) = 1;
}
else
{
*(_DWORD *)(master + 16953364LL) = 1;
}
return result;
}

original_code:
static void dl_waitlock(void)
{
 while(master->dllock > 0){usleep(200);};
 master->dllock++;
}

canonical_original_code:
static void dl_waitlock()
{
 while(master->dllock > 0){usleep(200);};
 master->dllock++;
}


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

LODWORD(v2) = *(_DWORD *)(a2 + 3064) - 1;
if ( (int)v2 < 0 )
{
LABEL_5:
syslog(3, "get_kbit_from_gb: GB used is not configured (%d gb)", a1);
result = 0LL;
}
else
{
v2 = (int)v2;
while ( *(_DWORD *)(a2 + 8 * v2 + 2936) > (signed int)a1 )
{
if ( (int)--v2 < 0 )
goto LABEL_5;
}
result = *(unsigned int *)(a2 + 8LL * (int)v2 + 2940);
}
return result;
}

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

LODWORD(v2) = *(_DWORD *)(a2 + 3064) - 1;
if ( (int)v2 < 0 )
{
LABEL_5:
syslog(3, "get_kbit_from_gb: GB used is not configured (%d gb)", a1);
result = 0LL;
}
else
{
v2 = (int)v2;
while ( *(_DWORD *)(a2 + 8 * v2 + 2936) > (signed int)a1 )
{
if ( (int)--v2 < 0 )
goto LABEL_5;
}
result = *(unsigned int *)(a2 + 8LL * (int)v2 + 2940);
}
return result;
}

original_code:
int get_kbit_from_gb(int gb, struct _profile *pf)
{
 int i;
 for (i=pf->NumLimits-1; i>=0; i--)
  if ( gb >= pf->Limits[i].gb )
   return pf->Limits[i].kbit;
 syslog(3, "get_kbit_from_gb: GB used is not configured (%d gb)", gb);
 return 0;
}

variable_types: gb int

variable_types: struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS { char name[256]; char lib[256]; char args[256]; } *Accounting; char AccountingPrefix[256]; struct LIMITS { int gb; int kbit; } Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval { long tv_sec; long tv_usec; } rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP { char name[32]; char map[4194303]; } *PrefixMap; struct _profile *FailProfile; } *

variable_types: i int


decompiled_code:
void __noreturn timer_loop()
{
int *v0; // r12
int i; // ebx
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

v0 = _errno_location();
for ( i = 0; ; ++i )
{
while ( 1 )
{
v3.tv_sec = 10LL;
v3.tv_usec = 0LL;
*v0 = 0;
if ( select(0, 0LL, 0LL, 0LL, &v3) != -1 )
break;
syslog(7, "timer error: errno=%m");
}
if ( i % 6 == 0 )
{
cmdstatistics_writestats();
cmdstatistics_write();
if ( cfg[76] )
cmdstatistics_write_bytes_json();
}
}
}

canonical_decompiled_code:
void __noreturn func1()
{
int *v0; // r12
int i; // ebx
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

v0 = _errno_location();
for ( i = 0; ; ++i )
{
while ( 1 )
{
v3.tv_sec = 10LL;
v3.tv_usec = 0LL;
*v0 = 0;
if ( select(0, 0LL, 0LL, 0LL, &v3) != -1 )
break;
syslog(7, "timer error: errno=%m");
}
if ( i % 6 == 0 )
{
cmdstatistics_writestats();
cmdstatistics_write();
if ( cfg[76] )
cmdstatistics_write_bytes_json();
}
}
}

original_code:
static void timer_loop(void)
{
        struct timeval tv;
 int scount = 0;
 for (;;)
 {
         tv.tv_sec = 10;
         tv.tv_usec = 0;
  (*__errno_location ()) = 0;
  if ( (select(0, ((void *)0), ((void *)0), ((void *)0), &tv)) == -1)
   syslog(7, "timer error: errno=%m");
  else {
   if ( scount++ % 6 == 0 ) {
    cmdstatistics_writestats();
    cmdstatistics_write();
    if ( cfg.JSONRL )
     cmdstatistics_write_bytes_json();
   }
  }
 }
}

canonical_original_code:
static void timer_loop()
{
        struct timeval tv;
 int scount = 0;
 for (;;)
 {
         tv.tv_sec = 10;
         tv.tv_usec = 0;
  (*__errno_location ()) = 0;
  if ( (select(0, ((void *)0), ((void *)0), ((void *)0), &tv)) == -1)
   syslog(7, "timer error: errno=%m");
  else {
   if ( scount++ % 6 == 0 ) {
    cmdstatistics_writestats();
    cmdstatistics_write();
    if ( cfg.JSONRL )
     cmdstatistics_write_bytes_json();
   }
  }
 }
}

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

variable_types: scount int


decompiled_code:
__int64 run_timer_loop()
{
__pid_t v0; // eax
unsigned int v1; // ebx
__int64 v3; // rcx
__sigset_t *v4; // rdi
int *v5; // rax
char *v6; // rax
struct sigaction v7; // [rsp+0h] [rbp-A8h] BYREF

info("Launching statistics timer..");
v0 = fork();
v1 = v0;
if ( v0 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
die("couldnt fork timer child %s", v6);
}
else if ( !v0 )
{
syslog_open("nntpswitch-timer", 1LL, 56LL);
setproctitle("nntpswitchd: timer polling each %u seconds", (unsigned int)cfg[10]);
v3 = 36LL;
v4 = &v7.sa_mask;
while ( v3 )
{
LODWORD(v4->__val[0]) = 0;
v4 = (__sigset_t *)((char *)v4 + 4);
--v3;
}
v7.sa_handler = (__sighandler_t)term_handler;
sigaction(15, &v7, 0LL);
timer_loop();
}
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
__pid_t v0; // eax
unsigned int v1; // ebx
__int64 v3; // rcx
__sigset_t *v4; // rdi
int *v5; // rax
char *v6; // rax
struct sigaction v7; // [rsp+0h] [rbp-A8h] BYREF

info("Launching statistics timer..");
v0 = fork();
v1 = v0;
if ( v0 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
die("couldnt fork timer child %s", v6);
}
else if ( !v0 )
{
syslog_open("nntpswitch-timer", 1LL, 56LL);
setproctitle("nntpswitchd: timer polling each %u seconds", (unsigned int)cfg[10]);
v3 = 36LL;
v4 = &v7.sa_mask;
while ( v3 )
{
LODWORD(v4->__val[0]) = 0;
v4 = (__sigset_t *)((char *)v4 + 4);
--v3;
}
v7.sa_handler = (__sighandler_t)term_handler;
sigaction(15, &v7, 0LL);
func1();
}
return v1;
}

original_code:
pid_t run_timer_loop(void)
{
        struct sigaction sigterm;
 pid_t pid;
 info("Launching statistics timer..");
        switch ( (pid=fork()) )
 {
        case 0:
                syslog_open ("nntpswitch-timer", 0x01, (7<<3));
  setproctitle("nntpswitchd: timer polling each %u seconds", cfg.StatsFilePeriod );
  memset(&sigterm, 0, sizeof (sigterm));
  sigterm.__sigaction_handler.sa_handler = &term_handler;
  sigaction(15, &sigterm, ((void *)0));
                timer_loop();
                syslog_close();
                _exit (0);
        case -1:
                die("couldnt fork timer child %s", strerror ((*__errno_location ())));
        default:
  return pid;
        }
}

canonical_original_code:
int run_timer_loop()
{
        struct sigaction sigterm;
 int pid;
 info("Launching statistics timer..");
        switch ( (pid=fork()) )
 {
        case 0:
                syslog_open ("nntpswitch-timer", 0x01, (7<<3));
  setproctitle("nntpswitchd: timer polling each %u seconds", cfg.StatsFilePeriod );
  memset(&sigterm, 0, sizeof (sigterm));
  sigterm.__sigaction_handler.sa_handler = &term_handler;
  sigaction(15, &sigterm, ((void *)0));
                timer_loop();
                syslog_close();
                _exit (0);
        case -1:
                die("couldnt fork timer child %s", strerror ((*__errno_location ())));
        default:
  return pid;
        }
}

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

variable_types: pid int

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

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


decompiled_code:
void __noreturn term_handler()
{
syslog(5, "sigterm received");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
syslog(5, "sigterm received");
exit(0);
}

original_code:
static void term_handler(int sig)
{
        syslog(5, "sigterm received");
 exit(0);
}

variable_types: sig int


decompiled_code:
__int64 __fastcall free_client(int a1)
{
_QWORD *v1; // rcx
__int64 result; // rax

v1 = (_QWORD *)(master + 720LL * a1 + 104);
*v1 = 0LL;
v1[89] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 720) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
_QWORD *v1; // rcx
__int64 result; // rax

v1 = (_QWORD *)(master + 720LL * a1 + 104);
*v1 = 0LL;
v1[89] = 0LL;
result = 0LL;
memset(
(void *)((unsigned __int64)(v1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v1 - (((_DWORD)v1 + 8) & 0xFFFFFFF8) + 720) >> 3));
return result;
}

original_code:
void free_client(int clientid)
{
 memset(master->clients+clientid, '\0', sizeof(CLIENT));
}

variable_types: clientid int


decompiled_code:
__int64 __fastcall get_ip_from_user(__int64 a1)
{
__int64 v1; // rax

v1 = master + 104LL;
while ( *(_QWORD *)(v1 + 376) != a1 )
{
v1 += 720LL;
if ( v1 == master + 5898344LL )
return 0LL;
}
return *(_QWORD *)(v1 + 320);
}

original_code:
unsigned long get_ip_from_user(USER *user)
{
 int i;
 for (i=0; i<8192; i++) {
  if ( (master->clients+i)->user == user ) {
   return (master->clients+i)->ip4addr;
  }
 }
 return 0;
}

canonical_original_code:
unsigned long get_ip_from_user(struct USER *user)
{
 int i;
 for (i=0; i<8192; i++) {
  if ( (master->clients+i)->user == user ) {
   return (master->clients+i)->ip4addr;
  }
 }
 return 0;
}

variable_types: struct USER { char key[128]; unsigned int id; unsigned int MaxUserBPS; long long bytesleft; unsigned int connections; unsigned int realuser; char readpat[256]; char postpat[256]; int timeleft; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval { long tv_sec; long tv_usec; } rl_start; double rl_curbps; } *

user_defined_types: struct USER { char key[128]; unsigned int id; unsigned int MaxUserBPS; long long bytesleft; unsigned int connections; unsigned int realuser; char readpat[256]; char postpat[256]; int timeleft; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval rl_start; double rl_curbps; }


original_code:
USER* find_user(char *ky, struct _profile *prf)
{
 int i, id = -1;
 USER *u;
 for (i=0; i<8192; i++)
  if ( strcmp((master->users+i)->key, ky) == 0 ) {
   ((master->users)+i)->connections++;
   return (master->users+i);
  }
 for (i=0; i<8192; i++)
  if ( (master->users+i)->key[0] == 0 ) {
   id = i;
   break;
  }
 if ( id == -1 )
  return ((void *)0);
 u = (master->users)+id;
 memset(u, '\0', sizeof(USER));
 strcpy(u->key, ky);
 u->connections++;
 u->id = id;
 u->bytesleft = prf->MaxSessionBytes;
 strcpy(u->readpat, prf->ReadPat);
 strcpy(u->postpat, prf->PostPat);
 u->timeleft = prf->MaxSessionTime;
 prf->numusers++;
 master->numusers++;
 return u;
}

canonical_original_code:
struct USER *find_user(char *ky, struct _profile *prf)
{
 int i; int id = -1;
 struct USER *u;
 for (i=0; i<8192; i++)
  if ( strcmp((master->users+i)->key, ky) == 0 ) {
   ((master->users)+i)->connections++;
   return (master->users+i);
  }
 for (i=0; i<8192; i++)
  if ( (master->users+i)->key[0] == 0 ) {
   id = i;
   break;
  }
 if ( id == -1 )
  return ((void *)0);
 u = (master->users)+id;
 memset(u, '\0', sizeof(USER));
 strcpy(u->key, ky);
 u->connections++;
 u->id = id;
 u->bytesleft = prf->MaxSessionBytes;
 strcpy(u->readpat, prf->ReadPat);
 strcpy(u->postpat, prf->PostPat);
 u->timeleft = prf->MaxSessionTime;
 prf->numusers++;
 master->numusers++;
 return u;
}

variable_types:
ky
char *

variable_types: struct _profile { char Name[32]; char ReadPat[256]; char PostPat[256]; int MaxConnections; int MaxUserConcurrent; int MaxHostConcurrent; int Slave; int ASMaxConns; int ASMaxHosts; int MaxUsers; int MaxSessionTime; unsigned long long MaxSessionBytes; unsigned int MaxUserBPS; unsigned int MaxProfileBPS; char XComplaintsTo[256]; char Organization[256]; int ForceOrganization; int AddNNTPPostingHost; int MaxCross; char Hostname[256]; char FooterFile[256]; char Footer[1024]; int FooterSize; int NoControl; int ArticleSearch; int ClientReadTimeout; struct ALIAS { char name[256]; char lib[256]; char args[256]; } *Accounting; char AccountingPrefix[256]; struct LIMITS { int gb; int kbit; } Limits[16]; int NumLimits; char Disabled[256]; int AllowSSL; unsigned int connections; unsigned int numusers; unsigned int realusers; unsigned long long bytes; unsigned long long rbytes; unsigned long articles; unsigned long long postbytes; unsigned long postarticles; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval rl_start; double rl_curbps; double UserRLFactorU; double UserRLFactorD; double ProfileRLFactorU; double ProfileRLFactorD; unsigned int Retention; char XHeaderSSLUpload[1024]; struct PFXMAP { char name[32]; char map[4194303]; } *PrefixMap; struct _profile *FailProfile; } *

variable_types: id int

return_type: struct USER { char key[128]; unsigned int id; unsigned int MaxUserBPS; long long bytesleft; unsigned int connections; unsigned int realuser; char readpat[256]; char postpat[256]; int timeleft; unsigned int rl_curbytes; unsigned int rl_lastbytes; double rl_sleep; struct timeval { long tv_sec; long tv_usec; } rl_start; double rl_curbps; } *


decompiled_code:
__int64 __fastcall drop_user(unsigned int a1, __int64 a2)
{
__int64 v2; // rdi
_QWORD *v3; // rcx
__int64 result; // rax

v2 = 712LL * a1;
v3 = (_QWORD *)(master + v2 + 5898352);
result = (unsigned int)(*(_DWORD *)(master + v2 + 5898496) - 1);
if ( *(_DWORD *)(master + v2 + 5898496) == 1 )
{
*v3 = 0LL;
v3[88] = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 712) >> 3));
--*(_DWORD *)(a2 + 3332);
result = master;
--*(_DWORD *)(master + 5898344LL);
}
else
{
*(_DWORD *)(master + v2 + 5898496) = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2)
{
__int64 v2; // rdi
_QWORD *v3; // rcx
__int64 result; // rax

v2 = 712LL * a1;
v3 = (_QWORD *)(master + v2 + 5898352);
result = (unsigned int)(*(_DWORD *)(master + v2 + 5898496) - 1);
if ( *(_DWORD *)(master + v2 + 5898496) == 1 )
{
*v3 = 0LL;
v3[88] = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 712) >> 3));
--*(_DWORD *)(a2 + 3332);
result = master;
--*(_DWORD *)(master + 5898344LL);
}
else
{
*(_DWORD *)(master + v2 + 5898496) = result;
}
return result;
}

original_code:
void drop_user(uint id, struct _profile *prf)
{
 USER *u;
 u = (master->users+id);
 u->connections--;
 if ( u->connections == 0 ) {
  memset(u, '\0', sizeof(USER));
  prf->numusers--;
  master->numusers--;
 }
}

canonical_original_code:
void drop_user(unsigned int id, struct _profile *prf)
{
 struct USER *u;
 u = (master->users+id);
 u->connections--;
 if ( u->connections == 0 ) {
  memset(u, '\0', sizeof(USER));
  prf->numusers--;
  master->numusers--;
 }
}

variable_types:
id
unsigned int

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

user_defined_types: struct ALIAS { char name[256]; char lib[256]; char args[256]; }

user_defined_types: struct PFXMAP { char name[32]; char map[4194303]; }