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

if ( argc != 4 )
exit(0);
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
puts("x, y, and c's range : -2147483648 ~ 2147483647");
printf("x:%d, y:%d, c:%d\n", (unsigned int)v3, (unsigned int)v4, v5);
v6 = detect_overflow_signed_add(v3, v4, v5);
printf("detect signed overflow x+y+c :%d\n", v6);
v7 = detect_overflow_signed_sub(v3, v4, v5);
printf("detect signed overflow x-y-c :%d\n", v7);
v8 = detect_overflow_unsigned_add(v3, v4, v5);
printf("detect unsigned overflow x+y+c :%d\n", v8);
v9 = detect_overflow_unsigned_sub(v3, v4, v5);
printf("detect unsigned overflow x-y-c :%d\n", v9);
v10 = detect_overflow_signed_mul(v3, v4);
printf("detect signed overflow x*y :%d\n", v10);
v11 = detect_overflow_unsigned_mul(v3, v4);
printf("detect unsigned overflow x*y :%d\n", v11);
return 0;
}

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

if ( argc != 4 )
exit(0);
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = atoi(argv[3]);
puts("x, y, and c's range : -2147483648 ~ 2147483647");
printf("x:%d, y:%d, c:%d\n", (unsigned int)v3, (unsigned int)v4, v5);
v6 = func7(v3, v4, v5);
printf("detect signed overflow x+y+c :%d\n", v6);
v7 = func8(v3, v4, v5);
printf("detect signed overflow x-y-c :%d\n", v7);
v8 = func9(v3, v4, v5);
printf("detect unsigned overflow x+y+c :%d\n", v8);
v9 = func10(v3, v4, v5);
printf("detect unsigned overflow x-y-c :%d\n", v9);
v10 = func11(v3, v4);
printf("detect signed overflow x*y :%d\n", v10);
v11 = func12(v3, v4);
printf("detect unsigned overflow x*y :%d\n", v11);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 4)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  int c = atoi(argv[3]);
  printf("x, y, and c's range : -2147483648 ~ 2147483647\n");
  printf("x:%d, y:%d, c:%d\n", x, y, c);
  printf("detect signed   overflow x+y+c :%d\n", detect_overflow_signed_add(x, y, c));
  printf("detect signed   overflow x-y-c :%d\n", detect_overflow_signed_sub(x, y, c));
  printf("detect unsigned overflow x+y+c :%d\n", detect_overflow_unsigned_add(x, y, c));
  printf("detect unsigned overflow x-y-c :%d\n", detect_overflow_unsigned_sub(x, y, c));
  printf("detect signed   overflow x*y   :%d\n", detect_overflow_signed_mul(x, y));
  printf("detect unsigned overflow x*y   :%d\n", detect_overflow_unsigned_mul(x, y));
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 4)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  int c = atoi(argv[3]);
  printf("x, y, and c's range : -2147483648 ~ 2147483647\n");
  printf("x:%d, y:%d, c:%d\n", x, y, c);
  printf("detect signed   overflow x+y+c :%d\n", detect_overflow_signed_add(x, y, c));
  printf("detect signed   overflow x-y-c :%d\n", detect_overflow_signed_sub(x, y, c));
  printf("detect unsigned overflow x+y+c :%d\n", detect_overflow_unsigned_add(x, y, c));
  printf("detect unsigned overflow x-y-c :%d\n", detect_overflow_unsigned_sub(x, y, c));
  printf("detect signed   overflow x*y   :%d\n", detect_overflow_signed_mul(x, y));
  printf("detect unsigned overflow x*y   :%d\n", detect_overflow_unsigned_mul(x, y));
}

variable_types: argc int

variable_types:
argv
char **

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall abs1(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return abs32(a1);
}

original_code:
int abs1(int x)
{
  int y = x >> 31;
  return (x ^ y) - y;
}

return_type: int


decompiled_code:
__int64 __fastcall abs2(int a1)
{
return (a1 >> 31) ^ (unsigned int)(a1 + (a1 >> 31));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (a1 >> 31) ^ (unsigned int)(a1 + (a1 >> 31));
}

original_code:
int abs2(int x)
{
  int y = x >> 31;
  return (x + y) ^ y;
}


decompiled_code:
__int64 __fastcall abs3(int a1)
{
return a1 - ((a1 >> 31) & (unsigned int)(2 * a1));
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
return a1 - ((a1 >> 31) & (unsigned int)(2 * a1));
}

original_code:
int abs3(int x)
{
  int y = x >> 31;
  return x - ((x<<1) & y);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("argument :%d\n", v3);
v4 = abs1(v3);
printf("abs1 :%d\n", v4);
v5 = abs2(v3);
printf("abs2 :%d\n", v5);
v6 = abs3(v3);
printf("abs3 :%d\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("argument :%d\n", v3);
v4 = func7(v3);
printf("abs1 :%d\n", v4);
v5 = func8(v3);
printf("abs2 :%d\n", v5);
v6 = func9(v3);
printf("abs3 :%d\n", v6);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("argument :%d\n", x);
  printf("abs1     :%d\n", abs1(x));
  printf("abs2     :%d\n", abs2(x));
  printf("abs3     :%d\n", abs3(x));
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("argument :%d\n", x);
  printf("abs1     :%d\n", abs1(x));
  printf("abs2     :%d\n", abs2(x));
  printf("abs3     :%d\n", abs3(x));
}


decompiled_code:
__int64 __fastcall ffstrl1(unsigned int a1, int a2)
{
unsigned int v2; // ebp
int v3; // ebx
int v4; // eax
unsigned int v5; // ebp
unsigned int v6; // ebx
int v7; // eax

if ( !a1 )
return 32;
v2 = a1;
v3 = 0;
while ( 1 )
{
v4 = nlz(v2);
v5 = v2 << v4;
v6 = v4 + v3;
v7 = nlz(~v5);
if ( v7 >= a2 )
break;
v2 = v5 << v7;
v3 = v7 + v6;
if ( !v2 )
return 32;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
unsigned int v2; // ebp
int v3; // ebx
int v4; // eax
unsigned int v5; // ebp
unsigned int v6; // ebx
int v7; // eax

if ( !a1 )
return 32;
v2 = a1;
v3 = 0;
while ( 1 )
{
v4 = func8(v2);
v5 = v2 << v4;
v6 = v4 + v3;
v7 = func8(~v5);
if ( v7 >= a2 )
break;
v2 = v5 << v7;
v3 = v7 + v6;
if ( !v2 )
return 32;
}
return v6;
}

original_code:
int ffstrl1(unsigned int x, int n)
{
  int k, p;
  p = 0;
  while(x != 0){
    k = nlz(x);
    x = x << k;
    p = p + k;
    k = nlz(~x);
    if(k >= n)
      return p;
    x = x << k;
    p = p + k;
  }
  return 32;
}

canonical_original_code:
int ffstrl1(unsigned int x, int n)
{
  int k; int p;
  p = 0;
  while(x != 0){
    k = nlz(x);
    x = x << k;
    p = p + k;
    k = nlz(~x);
    if(k >= n)
      return p;
    x = x << k;
    p = p + k;
  }
  return 32;
}

variable_types:
x
unsigned int

variable_types: n int

variable_types: k int

variable_types: p int


decompiled_code:
__int64 __fastcall ffstrl2(unsigned int a1, int a2)
{
for ( ; a2 > 1; a2 -= a2 >> 1 )
a1 &= a1 << (a2 >> 1);
return nlz(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, int a2)
{
for ( ; a2 > 1; a2 -= a2 >> 1 )
a1 &= a1 << (a2 >> 1);
return func8(a1);
}

original_code:
int ffstrl2(unsigned int x, int n)
{
  int s;
  while(n > 1){
    s = n >> 1;
    x = x & (x<<s);
    n = n - s;
  }
  return nlz(x);
}

variable_types: s int


decompiled_code:
__int64 __fastcall ntz1(int a1)
{
return pop(~a1 & (unsigned int)(a1 - 1));
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return func7(~a1 & (unsigned int)(a1 - 1));
}

original_code:
int ntz1(unsigned int x)
{
  return pop(~x&(x-1));
}


decompiled_code:
__int64 __fastcall ntz2(int a1)
{
unsigned int v1; // edi
__int64 result; // rax

v1 = (a1 - 1) & ~a1;
if ( !v1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v1 >>= 1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
unsigned int v1; // edi
__int64 result; // rax

v1 = (a1 - 1) & ~a1;
if ( !v1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v1 >>= 1;
}
while ( v1 );
return result;
}

original_code:
int ntz2(unsigned int x)
{
  int n;
  x = ~x & (x-1);
  n = 0;
  while(x != 0){
    n++;
    x = x >> 1;
  }
  return n;
}


sign

decompiled_code:
__int64 __fastcall sign(int a1)
{
return (a1 >> 31) | (unsigned int)(a1 > 0);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return (a1 >> 31) | (unsigned int)(a1 > 0);
}

original_code:
int sign(int x)
{
  unsigned int y = x;
  return (x >> 31) | ((-y) >> 31);
}

variable_types:
y
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("argument :%d\n", v3);
v4 = sign(v3);
printf("sign :%d\n", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("argument :%d\n", v3);
v4 = func7(v3);
printf("sign :%d\n", v4);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("argument :%d\n", x);
  printf("sign     :%d\n", sign(x));
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("argument :%d\n", x);
  printf("sign     :%d\n", sign(x));
}


canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
int v1; // eax
int v2; // ecx
int v3; // esi

v1 = 5;
v2 = 16;
v3 = 32;
do
{
if ( a1 >> v2 )
{
v3 -= v2;
a1 >>= v2;
}
v2 >>= 1;
--v1;
}
while ( v1 );
return v3 - a1;
}

original_code:
int nlz1(unsigned int x)
{
  unsigned y;
  int n, c;
  n = 32;
  c = 16;
  do {
    y = x >> c;
    if(y != 0){
      n = n - c;
      x = y;
    }
    c = c >> 1;
  } while(c != 0);
  return n - x;
}

canonical_original_code:
int nlz1(unsigned int x)
{
  unsigned int y;
  int n; int c;
  n = 32;
  c = 16;
  do {
    y = x >> c;
    if(y != 0){
      n = n - c;
      x = y;
    }
    c = c >> 1;
  } while(c != 0);
  return n - x;
}

variable_types: c int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("x:%d\n", v3);
int2binary((unsigned int)v3, v7);
printf("x:%.32s\n", v7);
v4 = parity1(v3);
printf("parity1: %d\n", v4);
v5 = parity2(v3);
printf("parity2: %d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("x:%d\n", v3);
int2binary((unsigned int)v3, v7);
printf("x:%.32s\n", v7);
v4 = func7(v3);
printf("parity1: %d\n", v4);
v5 = func8(v3);
printf("parity2: %d\n", v5);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("x:%d\n", x);
  char c[32];
  int2binary(x, c);
  printf("x:%.32s\n", c);
  printf("parity1: %d\n", parity1(x));
  printf("parity2: %d\n", parity2(x));
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("x:%d\n", x);
  char c[32];
  int2binary(x, c);
  printf("x:%.32s\n", c);
  printf("parity1: %d\n", parity1(x));
  printf("parity2: %d\n", parity2(x));
}

variable_types:
c
char [32]


decompiled_code:
__int64 __fastcall pop2(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
++v1;
a1 &= a1 - 1;
}
while ( a1 );
return v1;
}

original_code:
int pop2(unsigned int x)
{
  int n = 0;
  while(x != 0)
  {
    n++;
    x = x & (x-1);
  }
  return n;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("x:%d\n", v3);
int2binary((unsigned int)v3, v7);
printf("x:%.32s\n", v7);
v4 = pop1(v3);
printf("pop1: %d\n", v4);
v5 = pop2(v3);
printf("pop2: %d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
char v7[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("x:%d\n", v3);
int2binary((unsigned int)v3, v7);
printf("x:%.32s\n", v7);
v4 = func7(v3);
printf("pop1: %d\n", v4);
v5 = func8(v3);
printf("pop2: %d\n", v5);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("x:%d\n", x);
  char c[32];
  int2binary(x, c);
  printf("x:%.32s\n", c);
  printf("pop1: %d\n", pop1(x));
  printf("pop2: %d\n", pop2(x));
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 2)
    exit(0);
  int x = atoi(argv[1]);
  printf("x:%d\n", x);
  char c[32];
  int2binary(x, c);
  printf("x:%.32s\n", c);
  printf("pop1: %d\n", pop1(x));
  printf("pop2: %d\n", pop2(x));
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char v5[32]; // [rsp+0h] [rbp-88h] BYREF
char v6[32]; // [rsp+20h] [rbp-68h] BYREF
char v7[40]; // [rsp+40h] [rbp-48h] BYREF
unsigned int v8; // [rsp+68h] [rbp-20h] BYREF
int v9[7]; // [rsp+6Ch] [rbp-1Ch] BYREF

if ( argc != 4 )
exit(0);
v9[0] = atoi(argv[1]);
v8 = atoi(argv[2]);
v3 = atoi(argv[3]);
printf("before swap x:%d, y:%d\n", (unsigned int)v9[0], v8);
swap(v9, &v8);
printf("after swap x:%d, y:%d\n", (unsigned int)v9[0], v8);
int2binary((unsigned int)v9[0], v7);
int2binary(v8, v6);
int2binary(v3, v5);
printf("mask:%.32s\n", v5);
puts("before mask_swap");
printf(" x:%.32s\n", v7);
printf(" y:%.32s\n", v6);
mask_swap(v9, &v8, v3);
int2binary((unsigned int)v9[0], v7);
int2binary(v8, v6);
puts("after mask_swap");
printf(" x:%.32s\n", v7);
printf(" y:%.32s\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char v5[32]; // [rsp+0h] [rbp-88h] BYREF
char v6[32]; // [rsp+20h] [rbp-68h] BYREF
char v7[40]; // [rsp+40h] [rbp-48h] BYREF
unsigned int v8; // [rsp+68h] [rbp-20h] BYREF
int v9[7]; // [rsp+6Ch] [rbp-1Ch] BYREF

if ( argc != 4 )
exit(0);
v9[0] = atoi(argv[1]);
v8 = atoi(argv[2]);
v3 = atoi(argv[3]);
printf("before swap x:%d, y:%d\n", (unsigned int)v9[0], v8);
func7(v9, &v8);
printf("after swap x:%d, y:%d\n", (unsigned int)v9[0], v8);
int2binary((unsigned int)v9[0], v7);
int2binary(v8, v6);
int2binary(v3, v5);
printf("mask:%.32s\n", v5);
puts("before mask_swap");
printf(" x:%.32s\n", v7);
printf(" y:%.32s\n", v6);
func8(v9, &v8, v3);
int2binary((unsigned int)v9[0], v7);
int2binary(v8, v6);
puts("after mask_swap");
printf(" x:%.32s\n", v7);
printf(" y:%.32s\n", v6);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 4)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  int m = atoi(argv[3]);
  printf("before swap x:%d, y:%d\n", x, y);
  swap(&x, &y);
  printf("after  swap x:%d, y:%d\n", x, y);
  char c_x[32], c_y[32], c_m[32];
  int2binary(x, c_x);
  int2binary(y, c_y);
  int2binary(m, c_m);
  printf("mask:%.32s\n", c_m);
  printf("before mask_swap\n");
  printf("   x:%.32s\n", c_x);
  printf("   y:%.32s\n", c_y);
  mask_swap(&x, &y, m);
  int2binary(x, c_x);
  int2binary(y, c_y);
  printf("after mask_swap\n");
  printf("   x:%.32s\n", c_x);
  printf("   y:%.32s\n", c_y);
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 4)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  int m = atoi(argv[3]);
  printf("before swap x:%d, y:%d\n", x, y);
  swap(&x, &y);
  printf("after  swap x:%d, y:%d\n", x, y);
  char c_x[32]; char c_y[32]; char c_m[32];
  int2binary(x, c_x);
  int2binary(y, c_y);
  int2binary(m, c_m);
  printf("mask:%.32s\n", c_m);
  printf("before mask_swap\n");
  printf("   x:%.32s\n", c_x);
  printf("   y:%.32s\n", c_y);
  mask_swap(&x, &y, m);
  int2binary(x, c_x);
  int2binary(y, c_y);
  printf("after mask_swap\n");
  printf("   x:%.32s\n", c_x);
  printf("   y:%.32s\n", c_y);
}

variable_types: m int


getsenv

repo: deepurple/bbssrc

decompiled_code:
char *__fastcall getsenv(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
result = (char *)"";
return result;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
result = (char *)"";
return result;
}

original_code:
char *
getsenv(char *s)
{
 char *t = getenv(s);
 if (t)
  return t;
 return "";
}

canonical_original_code:
char *getsenv(char *s)
{
 char *t = getenv(s);
 if (t)
  return t;
 return "";
}

variable_types:
s
char *

variable_types:
t
char *

return_type: char *


strsncpy

decompiled_code:
void __fastcall strsncpy(char *dest, char *src, int a3)
{
int v4; // ebx

if ( a3 >= 0 )
{
v4 = strlen(src) + 1;
if ( v4 > a3 )
v4 = a3;
strncpy(dest, src, v4 - 1);
dest[v4 - 1] = 0;
}
}

canonical_decompiled_code:
void __fastcall func10(char *dest, char *src, int a3)
{
int v4; // ebx

if ( a3 >= 0 )
{
v4 = strlen(src) + 1;
if ( v4 > a3 )
v4 = a3;
strncpy(dest, src, v4 - 1);
dest[v4 - 1] = 0;
}
}

original_code:
void
strsncpy(char *s1, char *s2, int n)
{
 int l = strlen(s2);
 if (n < 0)
  return;
 if (n > l + 1)
  n = l + 1;
 strncpy(s1, s2, n - 1);
 s1[n - 1] = 0;
}

variable_types: l int

return_type: void


geturlarg

decompiled_code:
__int64 __fastcall geturlarg(char *a1, char *a2, char *a3, int a4)
{
unsigned __int8 *v6; // rax
char *v7; // rbx
unsigned __int8 *v8; // rax
char *v9; // rbx

*a3 = 0;
*a2 = 0;
v6 = (unsigned __int8 *)strtok(a1, "+");
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (char *)v6;
_unhcode(v6);
strsncpy(a2, v7, a4);
v8 = (unsigned __int8 *)strtok(0LL, "+");
v9 = (char *)v8;
if ( !v8 )
return 0xFFFFFFFFLL;
_unhcode(v8);
strsncpy(a3, v9, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, char *a2, char *a3, int a4)
{
unsigned __int8 *v6; // rax
char *v7; // rbx
unsigned __int8 *v8; // rax
char *v9; // rbx

*a3 = 0;
*a2 = 0;
v6 = (unsigned __int8 *)strtok(a1, "+");
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (char *)v6;
func9(v6);
func10(a2, v7, a4);
v8 = (unsigned __int8 *)strtok(0LL, "+");
v9 = (char *)v8;
if ( !v8 )
return 0xFFFFFFFFLL;
func9(v8);
func10(a3, v9, a4);
return 0LL;
}

original_code:
int
geturlarg(char *buf, char *sec, char *qry, int len)
{
 char *t2;
 qry[0] = 0;
 sec[0] = 0;
 t2 = strtok(buf, "+");
 if (!t2)
  return -1;
 __unhcode(t2);
 strsncpy(sec, t2, len);
 t2 = strtok(((void *)0), "+");
 if (!t2)
  return -1;
 __unhcode(t2);
 strsncpy(qry, t2, len);
 return 0;
}

variable_types:
buf
char *

variable_types:
sec
char *

variable_types:
qry
char *

variable_types: len int


teststr

decompiled_code:
__int64 __fastcall teststr(const char *a1)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

strcpy(v2, "\"'\\`~,:;!@#$%^&*|/? <>()[]{}\t\n\r");
return (unsigned int)-(strpbrk(a1, v2) != 0LL);
}

original_code:
int
teststr(char *str)
{
 char rejectstr[] = "\"'\\`~,:;!@#$%^&*|/? <>()[]{}\t\n\r";
 if (strpbrk(str, rejectstr))
  return -1;
 return 0;
}

variable_types:
str
char *

variable_types:
rejectstr
char []


testarg

decompiled_code:
__int64 __fastcall testarg(char *s1, const char *a2)
{
unsigned int v2; // ebp

if ( (unsigned int)teststr(s1) )
return (unsigned int)-1;
v2 = teststr(a2);
if ( v2 )
return (unsigned int)-1;
if ( !strcasecmp(s1, "any") )
{
*s1 = 0;
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func18(char *s1, const char *a2)
{
unsigned int v2; // ebp

if ( (unsigned int)func17(s1) )
return (unsigned int)-1;
v2 = func17(a2);
if ( v2 )
return (unsigned int)-1;
if ( !strcasecmp(s1, "any") )
{
*s1 = 0;
v2 = 0;
}
return v2;
}

original_code:
int
testarg(char *sec, char *qry)
{
 if (teststr(sec) || teststr(qry))
  return -1;
 if (!strcasecmp(sec, "any"))
  sec[0] = 0;
 return 0;
}


decompiled_code:
__int64 __fastcall runman2html(const char *a1)
{
char v2[2056]; // [rsp+0h] [rbp-808h] BYREF

if ( strstr(a1, ".gz") )
snprintf(
v2,
0x800uLL,
"zcat '%s' | man2html | sed -es/'http:\\/\\/localhost\\/cgi-bin\\/man\\/man2html'/'cgiman'/",
a1);
else
snprintf(v2, 0x800uLL, "man2html %s | sed -es/'http:\\/\\/localhost\\/cgi-bin\\/man\\/man2html'/'cgiman'/", a1);
system(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(const char *a1)
{
char v2[2056]; // [rsp+0h] [rbp-808h] BYREF

if ( strstr(a1, ".gz") )
snprintf(
v2,
0x800uLL,
"zcat '%s' | man2html | sed -es/'http:\\/\\/localhost\\/cgi-bin\\/man\\/man2html'/'cgiman'/",
a1);
else
snprintf(v2, 0x800uLL, "man2html %s | sed -es/'http:\\/\\/localhost\\/cgi-bin\\/man\\/man2html'/'cgiman'/", a1);
system(v2);
return 0LL;
}

original_code:
int
runman2html(char *manfile)
{
 char cmd[2048];
 if (strstr(manfile, ".gz"))
  snprintf(cmd, sizeof (cmd),
    "zcat '%s' | man2html | sed -es/'http:\\/\\/localhost\\/cgi-bin\\/man\\/man2html'/'cgiman'/",
    manfile);
 else
  snprintf(cmd, sizeof (cmd),
    "man2html %s | sed -es/'http:\\/\\/localhost\\/cgi-bin\\/man\\/man2html'/'cgiman'/",
    manfile);
 system(cmd);
 return 0;
}

variable_types:
manfile
char *

variable_types:
cmd
char [2048]


decompiled_code:
__int64 __fastcall bm_cmp(const void *a1, const void *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
int v5; // eax
int v6; // edx

v2 = *((_DWORD *)a2 + 14);
v3 = *((_DWORD *)a1 + 14);
if ( v2 != v3 )
return (unsigned int)(v2 - v3);
v5 = *((_DWORD *)a2 + 13);
v6 = *((_DWORD *)a1 + 13);
if ( v5 == v6 )
result = (unsigned int)(*((_DWORD *)a2 + 15) - *((_DWORD *)a1 + 15));
else
result = (unsigned int)(v5 - v6);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
int v2; // eax
int v3; // edx
__int64 result; // rax
int v5; // eax
int v6; // edx

v2 = *((_DWORD *)a2 + 14);
v3 = *((_DWORD *)a1 + 14);
if ( v2 != v3 )
return (unsigned int)(v2 - v3);
v5 = *((_DWORD *)a2 + 13);
v6 = *((_DWORD *)a1 + 13);
if ( v5 == v6 )
result = (unsigned int)(*((_DWORD *)a2 + 15) - *((_DWORD *)a1 + 15));
else
result = (unsigned int)(v5 - v6);
return result;
}

original_code:
int
bm_cmp(struct bmstat *b, struct bmstat *a)
{
 if (a->stay != b->stay)
  return (a->stay - b->stay);
 if (a->inboard != b->inboard)
  return (a->inboard - b->inboard);
 return a->post - b->post;
}

variable_types: struct bmstat { char board[20]; char class[10]; char userid[20]; char noread; int inboard; int stay; int post; int digest; int mark; int range; int delete; int import; int move; int same; int deny; int unmark; int undigest; int boardscore; } *

variable_types:
a
struct bmstat *


decompiled_code:
__int64 __fastcall bm_posted(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-118h] BYREF
char v7; // [rsp+10h] [rbp-108h] BYREF
char v8[32]; // [rsp+90h] [rbp-88h] BYREF
char s[104]; // [rsp+B0h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 60);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-118h] BYREF
char v7; // [rsp+10h] [rbp-108h] BYREF
char v8[32]; // [rsp+90h] [rbp-88h] BYREF
char s[104]; // [rsp+B0h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 60);
}
return result;
}

original_code:
void
bm_posted(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], title[128];
 char *tmp[2] = { board, title };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->post++;
 }
}

canonical_original_code:
void bm_posted(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char title[128];
 char *tmp[2] = { board, title };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->post++;
 }
}

variable_types: day int

variable_types:
time
char *

variable_types:
user
char *

variable_types:
other
char *

variable_types: struct hword { char str[80]; void *value; struct hword *next; } *

variable_types:
buf
char [80]

variable_types:
board
char [30]

variable_types:
title
char [128]

variable_types:
tmp
char *[2]

variable_types: i int

user_defined_types: struct bmstat { char board[20]; char class[10]; char userid[20]; char noread; int inboard; int stay; int post; int digest; int mark; int range; int delete; int import; int move; int same; int deny; int unmark; int undigest; int boardscore; }


decompiled_code:
__int64 __fastcall bm_import(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 80);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 80);
}
return result;
}

original_code:
void
bm_import(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], author[20], title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->import++;
 }
}

canonical_original_code:
void bm_import(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char author[20]; char title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->import++;
 }
}

variable_types:
author
char [20]

variable_types:
tmp
char *[3]

user_defined_types: struct hword { char str[80]; void *value; struct hword *next; }


decompiled_code:
__int64 __fastcall bm_move(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-298h] BYREF
char v7; // [rsp+10h] [rbp-288h] BYREF
char v8[32]; // [rsp+210h] [rbp-88h] BYREF
char s[104]; // [rsp+230h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 84);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-298h] BYREF
char v7; // [rsp+10h] [rbp-288h] BYREF
char v8[32]; // [rsp+210h] [rbp-88h] BYREF
char s[104]; // [rsp+230h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 84);
}
return result;
}

original_code:
void
bm_move(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], path[512];
 char *tmp[2] = { board, path };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->move++;
 }
}

canonical_original_code:
void bm_move(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char path[512];
 char *tmp[2] = { board, path };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->move++;
 }
}

variable_types:
path
char [512]


decompiled_code:
__int64 __fastcall bm_undigest(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 100);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 100);
}
return result;
}

original_code:
void
bm_undigest(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], author[20], title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->undigest++;
 }
}

canonical_original_code:
void bm_undigest(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char author[20]; char title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->undigest++;
 }
}


decompiled_code:
__int64 __fastcall bm_digest(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 64);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 64);
}
return result;
}

original_code:
void
bm_digest(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], author[20], title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->digest++;
 }
}

canonical_original_code:
void bm_digest(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char author[20]; char title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->digest++;
 }
}


decompiled_code:
__int64 __fastcall bm_mark(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 68);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 68);
}
return result;
}

original_code:
void
bm_mark(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], author[20], title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->mark++;
 }
}

canonical_original_code:
void bm_mark(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char author[20]; char title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->mark++;
 }
}


decompiled_code:
__int64 __fastcall bm_unmark(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 96);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 96);
}
return result;
}

original_code:
void
bm_unmark(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], author[20], title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->unmark++;
 }
}

canonical_original_code:
void bm_unmark(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char author[20]; char title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->unmark++;
 }
}


decompiled_code:
__int64 __fastcall bm_range(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[3]; // [rsp+0h] [rbp-B8h] BYREF
char v7; // [rsp+1Ch] [rbp-9Ch] BYREF
char v8; // [rsp+26h] [rbp-92h] BYREF
char v9[32]; // [rsp+30h] [rbp-88h] BYREF
char s[104]; // [rsp+50h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 72);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[3]; // [rsp+0h] [rbp-B8h] BYREF
char v7; // [rsp+1Ch] [rbp-9Ch] BYREF
char v8; // [rsp+26h] [rbp-92h] BYREF
char v9[32]; // [rsp+30h] [rbp-88h] BYREF
char s[104]; // [rsp+50h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 72);
}
return result;
}

original_code:
void
bm_range(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], num1[10], num2[10];
 char *tmp[3] = { board, num1, num2 };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->range++;
 }
}

canonical_original_code:
void bm_range(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char num1[10]; char num2[10];
 char *tmp[3] = { board, num1, num2 };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->range++;
 }
}


decompiled_code:
__int64 __fastcall bm_del(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 76);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[4]; // [rsp+0h] [rbp-148h] BYREF
char v7; // [rsp+20h] [rbp-128h] BYREF
char v8; // [rsp+A0h] [rbp-A8h] BYREF
char v9[32]; // [rsp+C0h] [rbp-88h] BYREF
char s[104]; // [rsp+E0h] [rbp-68h] BYREF

v6[0] = (__int64)v9;
v6[1] = (__int64)&v8;
v6[2] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v9, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 76);
}
return result;
}

original_code:
void
bm_del(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], author[20], title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->delete++;
 }
}

canonical_original_code:
void bm_del(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char author[20]; char title[128];
 char *tmp[3] = { board, author, title };
 int i;
 i = mystrtok(other, ' ', tmp, 3);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->delete++;
 }
}


decompiled_code:
__int64 __fastcall bm_deny(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-B8h] BYREF
char v7; // [rsp+10h] [rbp-A8h] BYREF
char v8[32]; // [rsp+30h] [rbp-88h] BYREF
char s[104]; // [rsp+50h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 92);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-B8h] BYREF
char v7; // [rsp+10h] [rbp-A8h] BYREF
char v8[32]; // [rsp+30h] [rbp-88h] BYREF
char s[104]; // [rsp+50h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 92);
}
return result;
}

original_code:
void
bm_deny(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], denyuser[20];
 char *tmp[2] = { board, denyuser };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->deny++;
 }
}

canonical_original_code:
void bm_deny(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char denyuser[20];
 char *tmp[2] = { board, denyuser };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->deny++;
 }
}

variable_types:
denyuser
char [20]


decompiled_code:
__int64 __fastcall bm_same(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-118h] BYREF
char v7; // [rsp+10h] [rbp-108h] BYREF
char v8[32]; // [rsp+90h] [rbp-88h] BYREF
char s[104]; // [rsp+B0h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 88);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-118h] BYREF
char v7; // [rsp+10h] [rbp-108h] BYREF
char v8[32]; // [rsp+90h] [rbp-88h] BYREF
char s[104]; // [rsp+B0h] [rbp-68h] BYREF

v6[0] = (__int64)v8;
v6[1] = (__int64)&v7;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v8, a3);
result = finddic(&bmd, s);
if ( result )
{
result = *(_QWORD *)(result + 80);
++*(_DWORD *)(result + 88);
}
return result;
}

original_code:
void
bm_same(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], title[128];
 char *tmp[2] = { board, title };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->same++;
 }
}

canonical_original_code:
void bm_same(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char title[128];
 char *tmp[2] = { board, title };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->same++;
 }
}


original_code:
void
bm_use(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30], staytime[30];
 char *tmp[2] = { board, staytime };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->inboard++;
  data->stay += atoi(staytime);
 }
}

canonical_original_code:
void bm_use(int day, char *time, char *user, char *other)
{
 struct hword *a;
 struct bmstat *data;
 char buf[80];
 char board[30]; char staytime[30];
 char *tmp[2] = { board, staytime };
 int i;
 i = mystrtok(other, ' ', tmp, 2);
 snprintf(buf, 80 - 1, "%s %s", board, user);
 a = finddic(bmd, buf);
 if (a != ((void *)0)) {
  data = a->value;
  data->inboard++;
  data->stay += atoi(staytime);
 }
}

variable_types:
staytime
char [30]


boardnoread

decompiled_code:
__int64 __fastcall boardnoread(__int64 a1)
{
int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 52);
if ( !v1 || (result = 1LL, (v1 & 0x88000) != 0) )
{
result = *(unsigned int *)(a1 + 48);
if ( (_DWORD)result )
result = ((*(_BYTE *)(a1 + 56) >> 4) ^ 1) & 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 52);
if ( !v1 || (result = 1LL, (v1 & 0x88000) != 0) )
{
result = *(unsigned int *)(a1 + 48);
if ( (_DWORD)result )
result = ((*(_BYTE *)(a1 + 56) >> 4) ^ 1) & 1;
}
return result;
}

original_code:
int
boardnoread(struct boardheader *fptr)
{
 return (((fptr->level != 0)
   && !(fptr->level & 02000000 || fptr->level & 0100000))
  || ((fptr->clubnum != 0) && (!(fptr->flag & 0x10))));
}

variable_types: struct boardheader { char filename[24]; char title[24]; int clubnum; unsigned int level; char flag; char secnumber1; char secnumber2; char type[5]; char bm[16][-1]; int hiretime[16]; int board_ctime; int board_mtime; char sec1[4]; char sec2[4]; char keyword[64]; char unused[96]; } *


initbdata

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

if ( !brdshm )
result = resolveshm();
return result;
}

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

if ( !brdshm )
result = func1();
return result;
}

original_code:
void
initbdata()
{
 if (brdshm == ((void *)0))
  resolveshm();
}


decompiled_code:
__int64 __fastcall register_log(char *s2, __int64 a2)
{
const char *v3; // rdi
char **v4; // rbx
char *v6; // rax

v3 = af_table;
if ( !af_table )
return 4294967294LL;
v4 = &af_table;
while ( strcmp(v3, s2) )
{
v4 += 2;
v3 = *v4;
if ( !*v4 )
return 4294967294LL;
}
v6 = (char *)register_fun((__int64)v4[1], a2);
v4[1] = v6;
return (unsigned int)-(v6 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s2, __int64 a2)
{
const char *v3; // rdi
char **v4; // rbx
char *v6; // rax

v3 = af_table;
if ( !af_table )
return 4294967294LL;
v4 = &af_table;
while ( strcmp(v3, s2) )
{
v4 += 2;
v3 = *v4;
if ( !*v4 )
return 4294967294LL;
}
v6 = (char *)register_fun((__int64)v4[1], a2);
v4[1] = v6;
return (unsigned int)-(v6 == 0LL);
}

original_code:
int
register_log(char *action, void (*f) ())
{
 struct s_a *as;
 for (as = af_table; as->action != ((void *)0); as++)
  if (!strcmp(as->action, action)) {
   as->fl = register_fun(as->fl, f);
   if (as->fl == ((void *)0))
    return -1;
   return 0;
  }
 return -2;
}

canonical_original_code:
int register_log(char *action, void (*f)())
{
 struct s_a *as;
 for (as = af_table; as->action != ((void *)0); as++)
  if (!strcmp(as->action, action)) {
   as->fl = register_fun(as->fl, f);
   if (as->fl == ((void *)0))
    return -1;
   return 0;
  }
 return -2;
}

variable_types:
action
char *

variable_types:
f
void (*)()

variable_types: struct s_a { char *action; struct f_link { void (*f)(); struct f_link *next; } *fl; } *

user_defined_types: struct s_a { char *action; struct f_link *fl; }


decompiled_code:
__int64 __fastcall register_stat(char **a1, __int64 a2)
{
char **v2; // rbx
char *v3; // rdi
unsigned int v4; // eax
unsigned int v5; // ebp

v2 = a1;
v3 = *a1;
if ( v3 )
{
while ( 1 )
{
v4 = register_log(v3, (__int64)v2[1]);
v5 = v4;
if ( v4 )
break;
v2 += 2;
v3 = *v2;
if ( !*v2 )
goto LABEL_4;
}
errlog("nbstat.c:%s line %d Can't register %s %d", "register_stat", 136LL, *v2, v4);
}
else
{
LABEL_4:
exit_fl = (__int64)register_fun(exit_fl, a2);
if ( exit_fl )
{
v5 = 0;
}
else
{
errlog("nbstat.c:%s line %d Can't regiester out %d", "register_stat", 142LL, 0LL);
v5 = -3;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(char **a1, __int64 a2)
{
char **v2; // rbx
char *v3; // rdi
unsigned int v4; // eax
unsigned int v5; // ebp

v2 = a1;
v3 = *a1;
if ( v3 )
{
while ( 1 )
{
v4 = func4(v3, (__int64)v2[1]);
v5 = v4;
if ( v4 )
break;
v2 += 2;
v3 = *v2;
if ( !*v2 )
goto LABEL_4;
}
errlog("nbstat.c:%s line %d Can't register %s %d", "register_stat", 136LL, *v2, v4);
}
else
{
LABEL_4:
exit_fl = (__int64)register_fun(exit_fl, a2);
if ( exit_fl )
{
v5 = 0;
}
else
{
errlog("nbstat.c:%s line %d Can't regiester out %d", "register_stat", 142LL, 0LL);
v5 = -3;
}
}
return v5;
}

original_code:
int
register_stat(struct action_f *mod, void (*mod_exit) ())
{
 int ret;
 while (mod->action != ((void *)0)) {
  if (ret = register_log(mod->action, mod->f)) {
   _errlog("nbstat.c" ":%s line %d " "Can't register %s %d", __FUNCTION__,136 , mod->action, ret);
   return ret;
  }
  mod++;
 }
 if ((exit_fl = register_fun(exit_fl, mod_exit)) == ((void *)0)) {
  _errlog("nbstat.c" ":%s line %d " "Can't regiester out %d", __FUNCTION__,142 , ret);
  return -3;
 }
 return 0;
}

canonical_original_code:
int register_stat(struct action_f *mod, void (*mod_exit)())
{
 int ret;
 while (mod->action != ((void *)0)) {
  if (ret = register_log(mod->action, mod->f)) {
   _errlog("nbstat.c" ":%s line %d " "Can't register %s %d", __FUNCTION__,136 , mod->action, ret);
   return ret;
  }
  mod++;
 }
 if ((exit_fl = register_fun(exit_fl, mod_exit)) == ((void *)0)) {
  _errlog("nbstat.c" ":%s line %d " "Can't regiester out %d", __FUNCTION__,142 , ret);
  return -3;
 }
 return 0;
}

variable_types: struct action_f { char *action; void (*f)(int, char *, char *, char *); } *

variable_types: ret int


parse

decompiled_code:
int __fastcall parse(unsigned int a1, const char *a2)
{
const char *v3; // rdi
char **v4; // rbx
int result; // eax
char *i; // rbx
__int64 v7[4]; // [rsp+0h] [rbp-298h] BYREF
char v8[512]; // [rsp+20h] [rbp-278h] BYREF
char s2[32]; // [rsp+220h] [rbp-78h] BYREF
char v10[32]; // [rsp+240h] [rbp-58h] BYREF
char v11[56]; // [rsp+260h] [rbp-38h] BYREF

v7[0] = (__int64)v10;
v7[1] = (__int64)v11;
v7[2] = (__int64)s2;
v7[3] = (__int64)v8;
if ( (int)mystrtok(a2, 32LL, v7, 4LL) <= 2 )
return errlog("nbstat.c:%s line %d Error input %d %s", "parse", 157LL, a1, a2);
v3 = af_table;
v4 = &af_table;
if ( !af_table )
return errlog("nbstat.c:%s line %d Unknown action %s", "parse", 169LL, s2);
while ( 1 )
{
result = strcmp(v3, s2);
if ( !result )
break;
v4 += 2;
v3 = *v4;
if ( !*v4 )
return errlog("nbstat.c:%s line %d Unknown action %s", "parse", 169LL, s2);
}
for ( i = v4[1]; i; i = (char *)*((_QWORD *)i + 1) )
result = (*(__int64 (__fastcall **)(_QWORD, char *, char *, char *))i)(a1, v10, v11, v8);
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1, const char *a2)
{
const char *v3; // rdi
char **v4; // rbx
int result; // eax
char *i; // rbx
__int64 v7[4]; // [rsp+0h] [rbp-298h] BYREF
char v8[512]; // [rsp+20h] [rbp-278h] BYREF
char s2[32]; // [rsp+220h] [rbp-78h] BYREF
char v10[32]; // [rsp+240h] [rbp-58h] BYREF
char v11[56]; // [rsp+260h] [rbp-38h] BYREF

v7[0] = (__int64)v10;
v7[1] = (__int64)v11;
v7[2] = (__int64)s2;
v7[3] = (__int64)v8;
if ( (int)mystrtok(a2, 32LL, v7, 4LL) <= 2 )
return errlog("nbstat.c:%s line %d Error input %d %s", "parse", 157LL, a1, a2);
v3 = af_table;
v4 = &af_table;
if ( !af_table )
return errlog("nbstat.c:%s line %d Unknown action %s", "parse", 169LL, s2);
while ( 1 )
{
result = strcmp(v3, s2);
if ( !result )
break;
v4 += 2;
v3 = *v4;
if ( !*v4 )
return errlog("nbstat.c:%s line %d Unknown action %s", "parse", 169LL, s2);
}
for ( i = v4[1]; i; i = (char *)*((_QWORD *)i + 1) )
result = (*(__int64 (__fastcall **)(_QWORD, char *, char *, char *))i)(a1, v10, v11, v8);
return result;
}

original_code:
void
parse(int day, char *buf)
{
 char user[30], time[30], action[30], other[512];
 char *tmp[4] = { time, user, action, other }, *a;
 int i;
 struct s_a *as;
 i = mystrtok(buf, ' ', tmp, 4);
 if (i < 3) {
  _errlog("nbstat.c" ":%s line %d " "Error input %d %s", __FUNCTION__,157 , day, buf);
  return;
 }
 for (as = af_table; as->action != ((void *)0); as++)
  if (!strcmp(as->action, action)) {
   struct f_link *flist = as->fl;
   while (flist != ((void *)0)) {
    (*(flist->f)) (day, time, user, other);
    flist = flist->next;
   }
   return;
  }
 _errlog("nbstat.c" ":%s line %d " "Unknown action %s", __FUNCTION__,169 , action);
}

canonical_original_code:
void parse(int day, char *buf)
{
 char user[30]; char time[30]; char action[30]; char other[512];
 char *tmp[4] = { time, user, action, other }; char *a;
 int i;
 struct s_a *as;
 i = mystrtok(buf, ' ', tmp, 4);
 if (i < 3) {
  _errlog("nbstat.c" ":%s line %d " "Error input %d %s", __FUNCTION__,157 , day, buf);
  return;
 }
 for (as = af_table; as->action != ((void *)0); as++)
  if (!strcmp(as->action, action)) {
   struct f_link *flist = as->fl;
   while (flist != ((void *)0)) {
    (*(flist->f)) (day, time, user, other);
    flist = flist->next;
   }
   return;
  }
 _errlog("nbstat.c" ":%s line %d " "Unknown action %s", __FUNCTION__,169 , action);
}

variable_types: day int

variable_types:
buf
char *

variable_types:
user
char [30]

variable_types:
time
char [30]

variable_types:
action
char [30]

variable_types:
other
char [512]

variable_types:
tmp
char *[4]

variable_types:
a
char *

variable_types: struct f_link { void (*f)(); struct f_link *next; } *


resolveshm

decompiled_code:
__int64 resolveshm()
{
int v0; // eax
void *v1; // rax

v0 = shmget(7813, 0x70818uLL, 0);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = shmat(v0, 0LL, 0);
brdshm = (__int64)v1;
if ( v1 == (void *)-1LL )
return 0xFFFFFFFFLL;
bcache = (__int64)v1;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
void *v1; // rax

v0 = shmget(7813, 0x70818uLL, 0);
if ( v0 < 0 )
return 0xFFFFFFFFLL;
v1 = shmat(v0, 0LL, 0);
brdshm = (__int64)v1;
if ( v1 == (void *)-1LL )
return 0xFFFFFFFFLL;
bcache = (__int64)v1;
return 0LL;
}

original_code:
int
resolveshm()
{
 int shmid;
 shmid = shmget(7813, ((int)sizeof(*brdshm)), 0);
 if (shmid < 0)
  return -1;
 brdshm = (struct BCACHE *) shmat(shmid, ((void *)0), 0);
 if (brdshm == (struct BCACHE *) -1)
  return -1;
 bcache = brdshm->bcache;
 return 0;
}

variable_types: shmid int

user_defined_types: struct BCACHE { struct boardmem bcache[800]; int number; long uptime; long pollvote; }

user_defined_types: struct boardmem { struct boardheader header; int lastpost; int total; short inboard; short bmonline; short bmcloak; int stocknum; int score; int unused[10]; }

user_defined_types: struct boardheader { char filename[24]; char title[24]; int clubnum; unsigned int level; char flag; char secnumber1; char secnumber2; char type[5]; char bm[16][-1]; int hiretime[16]; int board_ctime; int board_mtime; char sec1[4]; char sec2[4]; char keyword[64]; char unused[96]; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("Usage:\n%s action-string days [endday]\n", a1);
puts("actions:'m' board manager stat");
puts("\t'u' board usage stat");
puts("\t's' calculate board score, must be the unique action");
puts("\t'b' bbslists stat, runs every hour, day must be 1");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
printf("Usage:\n%s action-string days [endday]\n", a1);
puts("actions:'m' board manager stat");
puts("\t'u' board usage stat");
puts("\t's' calculate board score, must be the unique action");
puts("\t'b' bbslists stat, runs every hour, day must be 1");
exit(1);
}

original_code:
void
usage(char *progname)
{
 printf("Usage:\n%s action-string days [endday]\n", progname);
 printf("actions:'m' board manager stat\n");
 printf("	'u' board usage stat\n");
 printf
     ("	's' calculate board score, must be the unique action\n");
 printf("	'b' bbslists stat, runs every hour, day must be 1\n");
 exit(1);
}

variable_types:
progname
char *


decompiled_code:
__int64 __fastcall bu_cmp(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a2 + 1378) - *((_DWORD *)a1 + 1378));
}

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

original_code:
int
bu_cmp(struct buser *b, struct buser *a)
{
 return a->used - b->used;
}

variable_types: struct buser { char board[20]; char expname[80]; struct hword { char str[80]; void *value; struct hword *next; } *user[-1]; int used; int noread; } *

variable_types:
a
struct buser *

user_defined_types: struct buser { char board[20]; char expname[80]; struct hword *user[-1]; int used; int noread; }


decompiled_code:
__int64 __fastcall bu_use(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6; // rbp
char *v7; // r13
__int64 v8[2]; // [rsp+0h] [rbp-68h] BYREF
char v9; // [rsp+16h] [rbp-52h] BYREF
char v10[72]; // [rsp+20h] [rbp-48h] BYREF

v8[0] = (__int64)v10;
v8[1] = (__int64)&v9;
mystrtok(a4, 32LL, v8, 2LL);
result = finddic(&bustat, v10);
if ( result )
{
v6 = *(_QWORD *)(result + 80);
result = finddic(v6 + 104, a3);
if ( !result )
{
v7 = (char *)malloc(0x60uLL);
snprintf(v7, 0x50uLL, "%s", a3);
result = insertdic(v6 + 104, v7);
++*(_DWORD *)(v6 + 5512);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6; // rbp
char *v7; // r13
__int64 v8[2]; // [rsp+0h] [rbp-68h] BYREF
char v9; // [rsp+16h] [rbp-52h] BYREF
char v10[72]; // [rsp+20h] [rbp-48h] BYREF

v8[0] = (__int64)v10;
v8[1] = (__int64)&v9;
mystrtok(a4, 32LL, v8, 2LL);
result = finddic(&bustat, v10);
if ( result )
{
v6 = *(_QWORD *)(result + 80);
result = finddic(v6 + 104, a3);
if ( !result )
{
v7 = (char *)malloc(0x60uLL);
snprintf(v7, 0x50uLL, "%s", a3);
result = insertdic(v6 + 104, v7);
++*(_DWORD *)(v6 + 5512);
}
}
return result;
}

original_code:
void
bu_use(int day, char *time, char *user, char *other)
{
 struct hword *a, *tmp;
 struct buser *data;
 char board[30], staytime[10];
 char *temp[2] = { board, staytime };
 int i;
 i = mystrtok(other, ' ', temp, 2);
 a = finddic(bustat, board);
 if (a != ((void *)0)) {
  data = a->value;
  a = finddic(data->user, user);
  if (a == ((void *)0)) {
   tmp = malloc(((int)sizeof(struct hword)));
   snprintf(tmp->str, 80, "%s", user);
   insertdic(data->user, tmp);
   data->used++;
  }
 }
}

canonical_original_code:
void bu_use(int day, char *time, char *user, char *other)
{
 struct hword *a; struct hword *tmp;
 struct buser *data;
 char board[30]; char staytime[10];
 char *temp[2] = { board, staytime };
 int i;
 i = mystrtok(other, ' ', temp, 2);
 a = finddic(bustat, board);
 if (a != ((void *)0)) {
  data = a->value;
  a = finddic(data->user, user);
  if (a == ((void *)0)) {
   tmp = malloc(((int)sizeof(struct hword)));
   snprintf(tmp->str, 80, "%s", user);
   insertdic(data->user, tmp);
   data->used++;
  }
 }
}

variable_types:
time
char *

variable_types:
user
char *

variable_types:
other
char *

variable_types: struct hword { char str[80]; void *value; struct hword *next; } *

variable_types:
board
char [30]

variable_types:
staytime
char [10]

variable_types:
temp
char *[2]

variable_types: i int


decompiled_code:
__int64 bu_init()
{
int v0; // eax
__int64 v1; // r13
__int64 v2; // rbx
const char *v3; // r12
char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // r12
__int64 v8; // r12

v0 = *(_DWORD *)(brdshm + 460800LL);
if ( v0 > 0 )
{
v1 = 576LL * (unsigned int)v0;
v2 = 0LL;
do
{
v3 = (const char *)(bcache + v2);
if ( *(_BYTE *)(bcache + v2) )
{
v4 = (char *)malloc(0x60uLL);
v5 = v4;
if ( !v4 )
{
errlog("boardstat2.c:%s line %d Can't malloc in board_init!", "bu_init", 110LL);
exit(-1);
}
snprintf(v4, 0x14uLL, "%s", v3);
v6 = (char *)calloc(1uLL, 0x1590uLL);
v7 = v6;
*((_QWORD *)v5 + 10) = v6;
if ( !v6 )
{
errlog("boardstat2.c:%s line %d Can't malloc value in board_init!", "bu_init", 116LL);
exit(-1);
}
strcpy(v6, v5);
snprintf(v7 + 20, 0x50uLL, "%s", (const char *)(bcache + v2 + 24));
v8 = *((_QWORD *)v5 + 10);
*(_DWORD *)(v8 + 5516) = boardnoread(bcache + v2);
insertdic(&bustat, v5);
}
v2 += 576LL;
}
while ( v2 != v1 );
}
return register_stat(&bu, bu_exit);
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
__int64 v1; // r13
__int64 v2; // rbx
const char *v3; // r12
char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // r12
__int64 v8; // r12

v0 = *(_DWORD *)(brdshm + 460800LL);
if ( v0 > 0 )
{
v1 = 576LL * (unsigned int)v0;
v2 = 0LL;
do
{
v3 = (const char *)(bcache + v2);
if ( *(_BYTE *)(bcache + v2) )
{
v4 = (char *)malloc(0x60uLL);
v5 = v4;
if ( !v4 )
{
errlog("boardstat2.c:%s line %d Can't malloc in board_init!", "bu_init", 110LL);
exit(-1);
}
snprintf(v4, 0x14uLL, "%s", v3);
v6 = (char *)calloc(1uLL, 0x1590uLL);
v7 = v6;
*((_QWORD *)v5 + 10) = v6;
if ( !v6 )
{
errlog("boardstat2.c:%s line %d Can't malloc value in board_init!", "bu_init", 116LL);
exit(-1);
}
strcpy(v6, v5);
snprintf(v7 + 20, 0x50uLL, "%s", (const char *)(bcache + v2 + 24));
v8 = *((_QWORD *)v5 + 10);
*(_DWORD *)(v8 + 5516) = boardnoread(bcache + v2);
insertdic(&bustat, v5);
}
v2 += 576LL;
}
while ( v2 != v1 );
}
return register_stat(&bu, bu_exit);
}

original_code:
void
bu_init()
{
 int i, j, k;
 struct hword *tmp;
 char *p;
 int numboards;
 numboards = brdshm->number;
 for (i = 0; i < numboards; i++) {
  if (!bcache[i].header.filename[0])
   continue;
  tmp = malloc(((int)sizeof(struct hword)));
  if (tmp == ((void *)0)) {
   _errlog("boardstat2.c" ":%s line %d " "Can't malloc in board_init!", __FUNCTION__,110);
   exit(-1);
  }
  snprintf(tmp->str, 20, "%s", bcache[i].header.filename);
  tmp->value = calloc(1, ((int)sizeof(struct buser)));
  if (tmp->value == ((void *)0)) {
   _errlog("boardstat2.c" ":%s line %d " "Can't malloc value in board_init!", __FUNCTION__,116);
   exit(-1);
  }
  strcpy(((struct buser *) (tmp->value))->board, tmp->str);
  snprintf(((struct buser *) (tmp->value))->expname, 80, "%s",
    bcache[i].header.title);
  ((struct buser *) (tmp->value))->noread =
      boardnoread(&(bcache[i].header));
  insertdic(bustat, tmp);
 }
 register_stat(bu, bu_exit);
}

canonical_original_code:
void bu_init()
{
 int i; int j; int k;
 struct hword *tmp;
 char *p;
 int numboards;
 numboards = brdshm->number;
 for (i = 0; i < numboards; i++) {
  if (!bcache[i].header.filename[0])
   continue;
  tmp = malloc(((int)sizeof(struct hword)));
  if (tmp == ((void *)0)) {
   _errlog("boardstat2.c" ":%s line %d " "Can't malloc in board_init!", __FUNCTION__,110);
   exit(-1);
  }
  snprintf(tmp->str, 20, "%s", bcache[i].header.filename);
  tmp->value = calloc(1, ((int)sizeof(struct buser)));
  if (tmp->value == ((void *)0)) {
   _errlog("boardstat2.c" ":%s line %d " "Can't malloc value in board_init!", __FUNCTION__,116);
   exit(-1);
  }
  strcpy(((struct buser *) (tmp->value))->board, tmp->str);
  snprintf(((struct buser *) (tmp->value))->expname, 80, "%s",
    bcache[i].header.title);
  ((struct buser *) (tmp->value))->noread =
      boardnoread(&(bcache[i].header));
  insertdic(bustat, tmp);
 }
 register_stat(bu, bu_exit);
}

variable_types: j int

variable_types: k int

variable_types:
p
char *

variable_types: numboards int


decompiled_code:
void yftpdutmp_init()
{
FILE *v0; // rax
FILE *v1; // rdi

v0 = fopen64("/home/bbs/ftphome/yftpdutmp", "a");
yftpdutmp = v0;
if ( v0 )
fclose(v0);
v1 = fopen64("/home/bbs/ftphome/yftpdutmp", "r+");
yftpdutmp = v1;
if ( !v1 )
{
prints("421-Could not open UTMPFILE\r\n421 Server disabled for security reasons.");
exit(1);
}
rewind(v1);
}

canonical_decompiled_code:
void func0()
{
FILE *v0; // rax
FILE *v1; // rdi

v0 = fopen64("/home/bbs/ftphome/yftpdutmp", "a");
yftpdutmp = v0;
if ( v0 )
fclose(v0);
v1 = fopen64("/home/bbs/ftphome/yftpdutmp", "r+");
yftpdutmp = v1;
if ( !v1 )
{
prints("421-Could not open UTMPFILE\r\n421 Server disabled for security reasons.");
exit(1);
}
rewind(v1);
}

original_code:
void
yftpdutmp_init()
{
 yftpdutmp = fopen("/home/bbs" "/ftphome" "/yftpdutmp", "a");
 if (yftpdutmp)
  fclose(yftpdutmp);
 if (!(yftpdutmp = fopen("/home/bbs" "/ftphome" "/yftpdutmp", "r+"))) {
  prints("421-Could not open UTMPFILE\r\n"
         "421 Server disabled for security reasons.");
  exit(1);
 }
 rewind(yftpdutmp);
}


decompiled_code:
__int64 __fastcall yftpdutmp_log(char a1)
{
int v1; // ebp
__int64 result; // rax
int v3; // er12
__int64 v4; // rbx
__int64 v5; // rbx
char v6[4]; // [rsp+0h] [rbp-278h] BYREF
__pid_t pid; // [rsp+4h] [rbp-274h]
char v8[31]; // [rsp+8h] [rbp-270h] BYREF
char s1[265]; // [rsp+27h] [rbp-251h] BYREF
time_t ptr[41]; // [rsp+130h] [rbp-148h] BYREF

if ( !yftpdutmp )
return 0xFFFFFFFFLL;
memset(ptr, 0, 0x130uLL);
HIDWORD(ptr[0]) = getpid();
v1 = open64("/home/bbs/ftphome/utmplock", 64, 384LL);
if ( flock(v1, 2) < 0 )
{
flock(v1, 8);
close(v1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a1 )
{
LOBYTE(ptr[0]) = 1;
strncpy((char *)&ptr[1], &user, 0x1FuLL);
strncpy((char *)&ptr[4] + 7, remotehostname, 0x100uLL);
rewind(yftpdutmp);
v3 = 0;
v4 = 0LL;
while ( v4 <= 59 && fread(v6, 0x130uLL, 1uLL, yftpdutmp) )
{
if ( v6[0] && kill(pid, 0) >= 0 )
{
if ( isanonymous || strncmp(v8, (const char *)&ptr[1], 0x1FuLL) )
v3 += strncmp(s1, (const char *)&ptr[4] + 7, 0x100uLL) == 0;
else
++v3;
if ( v3 > 1 )
{
flock(v1, 8);
close(v1);
return 4294967294LL;
}
++v4;
}
}
rewind(yftpdutmp);
v5 = 0LL;
while ( fread(v6, 0x130uLL, 1uLL, yftpdutmp) && v6[0] && kill(pid, 0) >= 0 )
{
if ( ++v5 == 60 )
goto LABEL_25;
}
if ( v5 > 59 )
{
LABEL_25:
flock(v1, 8);
close(v1);
return 4294967293LL;
}
yftpdutmp_offset = 304 * v5;
}
else
{
LOBYTE(ptr[0]) = 0;
}
time(&ptr[37]);
fseek(yftpdutmp, yftpdutmp_offset, 0);
fwrite(ptr, 0x130uLL, 1uLL, yftpdutmp);
fflush(yftpdutmp);
flock(v1, 8);
close(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
int v1; // ebp
__int64 result; // rax
int v3; // er12
__int64 v4; // rbx
__int64 v5; // rbx
char v6[4]; // [rsp+0h] [rbp-278h] BYREF
__pid_t pid; // [rsp+4h] [rbp-274h]
char v8[31]; // [rsp+8h] [rbp-270h] BYREF
char s1[265]; // [rsp+27h] [rbp-251h] BYREF
time_t ptr[41]; // [rsp+130h] [rbp-148h] BYREF

if ( !yftpdutmp )
return 0xFFFFFFFFLL;
memset(ptr, 0, 0x130uLL);
HIDWORD(ptr[0]) = getpid();
v1 = open64("/home/bbs/ftphome/utmplock", 64, 384LL);
if ( flock(v1, 2) < 0 )
{
flock(v1, 8);
close(v1);
result = 0xFFFFFFFFLL;
}
else
{
if ( a1 )
{
LOBYTE(ptr[0]) = 1;
strncpy((char *)&ptr[1], &user, 0x1FuLL);
strncpy((char *)&ptr[4] + 7, remotehostname, 0x100uLL);
rewind(yftpdutmp);
v3 = 0;
v4 = 0LL;
while ( v4 <= 59 && fread(v6, 0x130uLL, 1uLL, yftpdutmp) )
{
if ( v6[0] && kill(pid, 0) >= 0 )
{
if ( isanonymous || strncmp(v8, (const char *)&ptr[1], 0x1FuLL) )
v3 += strncmp(s1, (const char *)&ptr[4] + 7, 0x100uLL) == 0;
else
++v3;
if ( v3 > 1 )
{
flock(v1, 8);
close(v1);
return 4294967294LL;
}
++v4;
}
}
rewind(yftpdutmp);
v5 = 0LL;
while ( fread(v6, 0x130uLL, 1uLL, yftpdutmp) && v6[0] && kill(pid, 0) >= 0 )
{
if ( ++v5 == 60 )
goto LABEL_25;
}
if ( v5 > 59 )
{
LABEL_25:
flock(v1, 8);
close(v1);
return 4294967293LL;
}
yftpdutmp_offset = 304 * v5;
}
else
{
LOBYTE(ptr[0]) = 0;
}
time(&ptr[37]);
fseek(yftpdutmp, yftpdutmp_offset, 0);
fwrite(ptr, 0x130uLL, 1uLL, yftpdutmp);
fflush(yftpdutmp);
flock(v1, 8);
close(v1);
result = 0LL;
}
return result;
}

original_code:
int
yftpdutmp_log(char type)
{
 struct yftpdutmp ut, tmp;
 long i;
 int fd, nlogin = 0;
 if (!yftpdutmp)
  return -1;
 memset((void *) &ut, 0, ((int)sizeof(ut)));
 ut.bu_pid = getpid();
 fd = open("/home/bbs" "/ftphome" "/utmplock", 0100 | 00, 0600);
 if (flock(fd, 2) < 0) {
  flock(fd, 8);
  close(fd);
  return -1;
 }
 if (type) {
  ut.bu_type = 1;
  strncpy(ut.bu_name, user, ((int)sizeof(ut.bu_name)));
  strncpy(ut.bu_host, remotehostname, ((int)sizeof(ut.bu_host)));
  rewind(yftpdutmp);
  i = 0;
  while (i < 60
         && fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
   if (!tmp.bu_type || kill(tmp.bu_pid, 0) < 0)
    continue;
   if (!isanonymous && !strncmp
       (tmp.bu_name, ut.bu_name, ((int)sizeof(ut.bu_name))))
    nlogin++;
   else
       if (!strncmp
    (tmp.bu_host, ut.bu_host,
     ((int)sizeof(ut.bu_host)))) nlogin++;
   if (nlogin >= 2) {
    flock(fd, 8);
    close(fd);
    return -2;
   }
   i++;
  }
  rewind(yftpdutmp);
  i = 0;
  while (i < 60
         && fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
   if (!tmp.bu_type || kill(tmp.bu_pid, 0) < 0)
    break;
   i++;
  }
  if (i >= 60) {
   flock(fd, 8);
   close(fd);
   return -3;
  }
  yftpdutmp_offset = i * ((int)sizeof(tmp));
 } else
  ut.bu_type = 0;
 time(&(ut.bu_time));
 fseek(yftpdutmp, yftpdutmp_offset, 0);
 fwrite((void *) &ut, ((int)sizeof(ut)), 1, yftpdutmp);
 fflush(yftpdutmp);
 flock(fd, 8);
 close(fd);
 return 0;
}

canonical_original_code:
int yftpdutmp_log(char type)
{
 struct yftpdutmp ut; struct yftpdutmp tmp;
 long i;
 int fd; int nlogin = 0;
 if (!yftpdutmp)
  return -1;
 memset((void *) &ut, 0, ((int)sizeof(ut)));
 ut.bu_pid = getpid();
 fd = open("/home/bbs" "/ftphome" "/utmplock", 0100 | 00, 0600);
 if (flock(fd, 2) < 0) {
  flock(fd, 8);
  close(fd);
  return -1;
 }
 if (type) {
  ut.bu_type = 1;
  strncpy(ut.bu_name, user, ((int)sizeof(ut.bu_name)));
  strncpy(ut.bu_host, remotehostname, ((int)sizeof(ut.bu_host)));
  rewind(yftpdutmp);
  i = 0;
  while (i < 60
         && fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
   if (!tmp.bu_type || kill(tmp.bu_pid, 0) < 0)
    continue;
   if (!isanonymous && !strncmp
       (tmp.bu_name, ut.bu_name, ((int)sizeof(ut.bu_name))))
    nlogin++;
   else
       if (!strncmp
    (tmp.bu_host, ut.bu_host,
     ((int)sizeof(ut.bu_host)))) nlogin++;
   if (nlogin >= 2) {
    flock(fd, 8);
    close(fd);
    return -2;
   }
   i++;
  }
  rewind(yftpdutmp);
  i = 0;
  while (i < 60
         && fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
   if (!tmp.bu_type || kill(tmp.bu_pid, 0) < 0)
    break;
   i++;
  }
  if (i >= 60) {
   flock(fd, 8);
   close(fd);
   return -3;
  }
  yftpdutmp_offset = i * ((int)sizeof(tmp));
 } else
  ut.bu_type = 0;
 time(&(ut.bu_time));
 fseek(yftpdutmp, yftpdutmp_offset, 0);
 fwrite((void *) &ut, ((int)sizeof(ut)), 1, yftpdutmp);
 fflush(yftpdutmp);
 flock(fd, 8);
 close(fd);
 return 0;
}

variable_types: type char

variable_types: struct yftpdutmp { char bu_type; int bu_pid; char bu_name[-1]; char bu_host[256]; long bu_time; }

variable_types: i long

variable_types: fd int

variable_types: nlogin int


decompiled_code:
int yftpdutmp_end()
{
int result; // eax

if ( yftpdutmp )
{
if ( yftpdutmp_offset != -1 )
yftpdutmp_log(0);
result = fclose(yftpdutmp);
yftpdutmp = 0LL;
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

if ( yftpdutmp )
{
if ( yftpdutmp_offset != -1 )
func1(0);
result = fclose(yftpdutmp);
yftpdutmp = 0LL;
}
return result;
}

original_code:
void
yftpdutmp_end()
{
 if (yftpdutmp) {
  if (yftpdutmp_offset != -1)
   yftpdutmp_log(0);
  fclose(yftpdutmp);
  yftpdutmp = ((void *)0);
 }
}


decompiled_code:
size_t __fastcall yftpdutmp_pidexists(int a1)
{
size_t result; // rax
_DWORD v2[78]; // [rsp+0h] [rbp-138h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( v2[1] == a1 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(int a1)
{
size_t result; // rax
_DWORD v2[78]; // [rsp+0h] [rbp-138h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( v2[1] == a1 )
return 1LL;
}
return result;
}

original_code:
char
yftpdutmp_pidexists(pid_t pid)
{
 struct yftpdutmp tmp;
 rewind(yftpdutmp);
 while (fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
  if (tmp.bu_pid == pid)
   return 1;
 }
 return 0;
}

canonical_original_code:
char yftpdutmp_pidexists(int pid)
{
 struct yftpdutmp tmp;
 rewind(yftpdutmp);
 while (fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
  if (tmp.bu_pid == pid)
   return 1;
 }
 return 0;
}

variable_types: pid int

return_type: char

user_defined_types: struct yftpdutmp { char bu_type; int bu_pid; char bu_name[-1]; char bu_host[256]; long bu_time; }


decompiled_code:
size_t __fastcall yftpdutmp_userexists(char *s2)
{
size_t result; // rax
__int64 v2; // [rsp+0h] [rbp-138h] BYREF
char s1[304]; // [rsp+8h] [rbp-130h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(&v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( !strcmp(s1, s2) )
return 1LL;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(char *s2)
{
size_t result; // rax
__int64 v2; // [rsp+0h] [rbp-138h] BYREF
char s1[304]; // [rsp+8h] [rbp-130h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(&v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( !strcmp(s1, s2) )
return 1LL;
}
return result;
}

original_code:
char
yftpdutmp_userexists(char *username)
{
 struct yftpdutmp tmp;
 rewind(yftpdutmp);
 while (fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
  if (!strcmp(tmp.bu_name, username))
   return 1;
 }
 return 0;
}

variable_types:
username
char *


getnum

decompiled_code:
__int64 __fastcall getnum(__int64 a1, int *a2, int a3)
{
__int64 v3; // rdi
__int64 v4; // rax
unsigned int v5; // er8

if ( a3 <= 0 )
return 0;
v3 = a1 - *a2;
if ( v3 <= 0 )
return 0;
v4 = 1LL;
do
{
v5 = v4;
if ( v4 == a3 )
break;
v3 -= a2[v4++];
}
while ( v3 > 0 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2, int a3)
{
__int64 v3; // rdi
__int64 v4; // rax
unsigned int v5; // er8

if ( a3 <= 0 )
return 0;
v3 = a1 - *a2;
if ( v3 <= 0 )
return 0;
v4 = 1LL;
do
{
v5 = v4;
if ( v4 == a3 )
break;
v3 -= a2[v4++];
}
while ( v3 > 0 );
return v5;
}

original_code:
int
getnum(long residue, int score[1000], int count)
{
 int i;
 for (i = 0; i < count; i++) {
  residue -= score[i];
  if (residue <= 0)
   break;
 }
 return i;
}

variable_types: residue long

variable_types:
score
int [1000]

variable_types: count int


decompiled_code:
FILE *log_init()
{
FILE *result; // rax

result = fopen64("/home/bbs/ftphome/log", "a");
logfile = result;
if ( !result )
{
prints("421-Could not open log file.\r\n421 Server disabled for security reasons.");
exit(1);
}
return result;
}

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

result = fopen64("/home/bbs/ftphome/log", "a");
logfile = result;
if ( !result )
{
prints("421-Could not open log file.\r\n421 Server disabled for security reasons.");
exit(1);
}
return result;
}

original_code:
void
log_init()
{
 if (!(logfile = fopen("/home/bbs" "/ftphome" "/log", "a"))) {
  prints("421-Could not open log file.\r\n"
         "421 Server disabled for security reasons.");
  exit(1);
 }
}


decompiled_code:
int yftpd_log(char *format, ...)
{
int result; // eax
char *v2; // rax
unsigned int v3; // eax
time_t timer; // [rsp+8h] [rbp-510h] BYREF
char dest[48]; // [rsp+10h] [rbp-508h] BYREF
char s[1032]; // [rsp+40h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+448h] [rbp-D0h] BYREF

va_start(arg, format);
result = vsnprintf(s, 0x400uLL, format, arg);
if ( logfile )
{
fseek(logfile, 0LL, 2);
time(&timer);
v2 = ctime(&timer);
strcpy(dest, v2);
*((_BYTE *)&timer + strlen(dest) + 7) = 0;
v3 = getpid();
fprintf(logfile, "%s yftpd[%i]: %s", dest, v3, s);
result = fflush(logfile);
}
return result;
}

canonical_decompiled_code:
int func1(char *format, ...)
{
int result; // eax
char *v2; // rax
unsigned int v3; // eax
time_t timer; // [rsp+8h] [rbp-510h] BYREF
char dest[48]; // [rsp+10h] [rbp-508h] BYREF
char s[1032]; // [rsp+40h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+448h] [rbp-D0h] BYREF

va_start(arg, format);
result = vsnprintf(s, 0x400uLL, format, arg);
if ( logfile )
{
fseek(logfile, 0LL, 2);
time(&timer);
v2 = ctime(&timer);
strcpy(dest, v2);
*((_BYTE *)&timer + strlen(dest) + 7) = 0;
v3 = getpid();
fprintf(logfile, "%s yftpd[%i]: %s", dest, v3, s);
result = fflush(logfile);
}
return result;
}

original_code:
void
yftpd_log(char *format, ...)
{
 va_list val;
 char buffer[1024], timestr[40];
 time_t t;
 __builtin_va_start(val,format);
 vsnprintf(buffer, ((int)sizeof(buffer)), format, val);
 __builtin_va_end(val);
 if (logfile) {
  fseek(logfile, 0, 2);
  time(&t);
  strcpy(timestr, (char *) ctime(&t));
  timestr[strlen(timestr) - 1] = '\0';
  fprintf(logfile, "%s yftpd[%i]: %s", timestr,
   (int) getpid(), buffer);
  fflush(logfile);
 }
}

canonical_original_code:
void yftpd_log(char *format, ...)
{
 __builtin_va_list val;
 char buffer[1024]; char timestr[40];
 long t;
 __builtin_va_start(val,format);
 vsnprintf(buffer, ((int)sizeof(buffer)), format, val);
 __builtin_va_end(val);
 if (logfile) {
  fseek(logfile, 0, 2);
  time(&t);
  strcpy(timestr, (char *) ctime(&t));
  timestr[strlen(timestr) - 1] = '\0';
  fprintf(logfile, "%s yftpd[%i]: %s", timestr,
   (int) getpid(), buffer);
  fflush(logfile);
 }
}

variable_types:
format
char *

variable_types:
buffer
char [1024]

variable_types:
timestr
char [40]

variable_types: t long


decompiled_code:
int log_end()
{
int result; // eax

if ( logfile )
{
result = fclose(logfile);
logfile = 0LL;
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

if ( logfile )
{
result = fclose(logfile);
logfile = 0LL;
}
return result;
}

original_code:
void
log_end()
{
 if (logfile) {
  fclose(logfile);
  logfile = ((void *)0);
 }
}


decompiled_code:
__int64 shm_init()
{
shm_utmp = try_get_shm(3785LL, 7495048LL, 0LL);
if ( !shm_utmp )
return 0xFFFFFFFFLL;
uindexshm = try_get_shm(3787LL, 2400000LL, 0LL);
if ( !uindexshm )
return 0xFFFFFFFFLL;
shm_bcache = try_get_shm(7813LL, 460824LL, 0LL);
if ( !shm_bcache )
return 0xFFFFFFFFLL;
shm_ucache = try_get_shm(7912LL, 1300056LL, 0LL);
return (unsigned int)-(shm_ucache == 0);
}

canonical_decompiled_code:
__int64 func0()
{
shm_utmp = try_get_shm(3785LL, 7495048LL, 0LL);
if ( !shm_utmp )
return 0xFFFFFFFFLL;
uindexshm = try_get_shm(3787LL, 2400000LL, 0LL);
if ( !uindexshm )
return 0xFFFFFFFFLL;
shm_bcache = try_get_shm(7813LL, 460824LL, 0LL);
if ( !shm_bcache )
return 0xFFFFFFFFLL;
shm_ucache = try_get_shm(7912LL, 1300056LL, 0LL);
return (unsigned int)-(shm_ucache == 0);
}

original_code:
int
shm_init()
{
 shm_utmp =
     (struct UTMPFILE *) try_get_shm(3785,((int)sizeof(struct UTMPFILE)),0);
 if (shm_utmp == ((void *)0))
  return -1;
 uindexshm =
     (struct UINDEX *) try_get_shm(3787,((int)sizeof(struct UINDEX)),0);
 if (uindexshm == ((void *)0))
  return -1;
 shm_bcache =
     (struct BCACHE *) try_get_shm(7813,((int)sizeof(struct BCACHE)),0);
 if (shm_bcache == ((void *)0))
  return -1;
 shm_ucache =
     (struct UCACHE *) try_get_shm(7912,((int)sizeof(struct UCACHE)),0);
 if (shm_ucache == ((void *)0))
  return -1;
 return 0;
}

user_defined_types: struct UTMPFILE { struct user_info uinfo[-1]; long uptime; unsigned short activeuser; unsigned short maxuser; unsigned short maxtoday; unsigned short wwwguest; long activetime; int ave_score; int allprize; long watchman; unsigned int unlock; int nouse[5]; struct moneyCenter mc; }

user_defined_types: struct UCACHE { char userid[100000][-1]; int number; int usersum; long uptime; int nouse[10]; }

user_defined_types: struct moneyCenter { int ave_score; int prize777; int prize367; int prizeSoccer; unsigned char transfer_rate; unsigned char deposit_rate; unsigned char lend_rate; unsigned char isSalaryTime; }

user_defined_types: struct user_info { int active; int uid; int pid; int invisible; int sockactive; int sockaddr; int destuid; int mode; int pager; int in_chat; int fnum; short ext_idle; short isssh; long lasttime; unsigned int userlevel; int nouse1; char chatid[10]; char from[20]; char sessionid[40]; char userid[20]; char realname[20]; char username[40]; unsigned int unreadmsg; int nouse2; short curboard; int nouse3; int clubrights[4]; unsigned int friend[-1]; unsigned int reject[-1]; struct wwwsession wwwinfo; struct onebrc brc; char user_state_temp[16]; }

user_defined_types: struct wwwsession { unsigned char used; unsigned char link_mode; char iskicked; char unused; long login_start_time; long lastposttime; long lastinboardtime; }

user_defined_types: struct onebrc { short num; short cur; short changed; char board[15]; int list[60]; int notetime; }


decompiled_code:
__int64 __fastcall add_uindex(int a1, int a2)
{
__int64 result; // rax
int v3; // er11
__int64 v4; // rdx
int v5; // eax

result = (unsigned int)(a1 - 1);
if ( (unsigned int)result <= 0x1869F )
{
result = 0LL;
v3 = a1 - 1;
while ( *(_DWORD *)(uindexshm + 24LL * a1 + 4 * result - 24) != a2 )
{
if ( ++result == 6 )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(_DWORD *)(uindexshm + 24LL * v3 + 4 * v4);
if ( v5 <= 0 )
break;
result = shm_utmp + 1496LL * v5;
if ( !*(_DWORD *)(result - 1496) || *(_DWORD *)(result - 1492) != a1 )
break;
if ( ++v4 == 6 )
return result;
}
result = (int)v4 + 6LL * v3;
*(_DWORD *)(uindexshm + 4 * result) = a2;
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 result; // rax
int v3; // er11
__int64 v4; // rdx
int v5; // eax

result = (unsigned int)(a1 - 1);
if ( (unsigned int)result <= 0x1869F )
{
result = 0LL;
v3 = a1 - 1;
while ( *(_DWORD *)(uindexshm + 24LL * a1 + 4 * result - 24) != a2 )
{
if ( ++result == 6 )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(_DWORD *)(uindexshm + 24LL * v3 + 4 * v4);
if ( v5 <= 0 )
break;
result = shm_utmp + 1496LL * v5;
if ( !*(_DWORD *)(result - 1496) || *(_DWORD *)(result - 1492) != a1 )
break;
if ( ++v4 == 6 )
return result;
}
result = (int)v4 + 6LL * v3;
*(_DWORD *)(uindexshm + 4 * result) = a2;
return result;
}
}
}
return result;
}

original_code:
void
add_uindex(int uid, int utmpent)
{
 int i, uent;
 if (uid <= 0 || uid > 100000)
  return;
 for (i = 0; i < 6; i++)
  if (uindexshm->user[uid - 1][i] == utmpent)
   return;
 for (i = 0; i < 6; i++) {
  uent = uindexshm->user[uid - 1][i];
  if (uent <= 0 || !shm_utmp->uinfo[uent - 1].active ||
      shm_utmp->uinfo[uent - 1].uid != uid) {
   uindexshm->user[uid - 1][i] = utmpent;
   return;
  }
 }
}

canonical_original_code:
void add_uindex(int uid, int utmpent)
{
 int i; int uent;
 if (uid <= 0 || uid > 100000)
  return;
 for (i = 0; i < 6; i++)
  if (uindexshm->user[uid - 1][i] == utmpent)
   return;
 for (i = 0; i < 6; i++) {
  uent = uindexshm->user[uid - 1][i];
  if (uent <= 0 || !shm_utmp->uinfo[uent - 1].active ||
      shm_utmp->uinfo[uent - 1].uid != uid) {
   uindexshm->user[uid - 1][i] = utmpent;
   return;
  }
 }
}

variable_types: uid int

variable_types: utmpent int

variable_types: i int

variable_types: uent int


decompiled_code:
__int64 syn_uindxexshm()
{
int i; // ebx
_DWORD *v1; // rax
int j; // ebx
__int64 result; // rax

for ( i = 0; i != 5010; ++i )
{
v1 = (_DWORD *)(shm_utmp + 1496LL * i);
if ( *v1 )
add_uindex(v1[1], i + 1);
}
for ( j = 0; j != 100000; result = rmdup_uindex(j) )
++j;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int i; // ebx
_DWORD *v1; // rax
int j; // ebx
__int64 result; // rax

for ( i = 0; i != 5010; ++i )
{
v1 = (_DWORD *)(shm_utmp + 1496LL * i);
if ( *v1 )
func1(v1[1], i + 1);
}
for ( j = 0; j != 100000; result = func2(j) )
++j;
return result;
}

original_code:
void
syn_uindxexshm()
{
 int i;
 for (i = 0; i < (5000 + 10); i++) {
  if (shm_utmp->uinfo[i].active) {
   add_uindex(shm_utmp->uinfo[i].uid, i + 1);
  }
 }
 for (i = 0; i < 100000; i++)
  rmdup_uindex(i + 1);
}


bonlinesync

decompiled_code:
__int64 bonlinesync()
{
__int64 v0; // r8
int v1; // edx
_WORD *v2; // rax
__int64 v3; // rdx
__int64 result; // rax
__int64 v5; // rcx
__int16 v6; // dx

v0 = shm_bcache;
v1 = *(_DWORD *)(shm_bcache + 460800);
if ( v1 > 0 )
{
v2 = (_WORD *)(shm_bcache + 520);
v3 = shm_bcache + 576LL * (unsigned int)(v1 - 1) + 1096;
do
{
*v2 = 0;
v2 += 288;
}
while ( v2 != (_WORD *)v3 );
}
result = shm_utmp;
v5 = shm_utmp + 7494960;
do
{
if ( *(_DWORD *)result && *(_DWORD *)(result + 8) )
{
v6 = *(_WORD *)(result + 224);
if ( v6 )
++*(_WORD *)(v0 + 576LL * (v6 - 1) + 520);
}
result += 1496LL;
}
while ( result != v5 );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // r8
int v1; // edx
_WORD *v2; // rax
__int64 v3; // rdx
__int64 result; // rax
__int64 v5; // rcx
__int16 v6; // dx

v0 = shm_bcache;
v1 = *(_DWORD *)(shm_bcache + 460800);
if ( v1 > 0 )
{
v2 = (_WORD *)(shm_bcache + 520);
v3 = shm_bcache + 576LL * (unsigned int)(v1 - 1) + 1096;
do
{
*v2 = 0;
v2 += 288;
}
while ( v2 != (_WORD *)v3 );
}
result = shm_utmp;
v5 = shm_utmp + 7494960;
do
{
if ( *(_DWORD *)result && *(_DWORD *)(result + 8) )
{
v6 = *(_WORD *)(result + 224);
if ( v6 )
++*(_WORD *)(v0 + 576LL * (v6 - 1) + 520);
}
result += 1496LL;
}
while ( result != v5 );
return result;
}

original_code:
void
bonlinesync()
{
 int i, numboards;
 struct user_info *uentp;
 numboards = shm_bcache->number;
 for (i = 0; i < numboards; i++)
  shm_bcache->bcache[i].inboard = 0;
 for (i = 0; i < (5000 + 10); i++) {
  uentp = &(shm_utmp->uinfo[i]);
  if (uentp->active && uentp->pid && uentp->curboard)
   shm_bcache->bcache[uentp->curboard - 1].inboard++;
 }
}

canonical_original_code:
void bonlinesync()
{
 int i; int numboards;
 struct user_info *uentp;
 numboards = shm_bcache->number;
 for (i = 0; i < numboards; i++)
  shm_bcache->bcache[i].inboard = 0;
 for (i = 0; i < (5000 + 10); i++) {
  uentp = &(shm_utmp->uinfo[i]);
  if (uentp->active && uentp->pid && uentp->curboard)
   shm_bcache->bcache[uentp->curboard - 1].inboard++;
 }
}

variable_types: numboards int

variable_types: struct user_info { int active; int uid; int pid; int invisible; int sockactive; int sockaddr; int destuid; int mode; int pager; int in_chat; int fnum; short ext_idle; short isssh; long lasttime; unsigned int userlevel; int nouse1; char chatid[10]; char from[20]; char sessionid[40]; char userid[20]; char realname[20]; char username[40]; unsigned int unreadmsg; int nouse2; short curboard; int nouse3; int clubrights[4]; unsigned int friend[-1]; unsigned int reject[-1]; struct wwwsession { unsigned char used; unsigned char link_mode; char iskicked; char unused; long login_start_time; long lastposttime; long lastinboardtime; } wwwinfo; struct onebrc { short num; short cur; short changed; char board[15]; int list[60]; int notetime; } brc; char user_state_temp[16]; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
__int64 v4; // r9
struct tm *v5; // rax
struct tm *v6; // rbx
int v7; // ebp

if ( (int)shm_init(argc, argv, envp) >= 0 )
{
item = time(0LL);
get_load((_DWORD *)(unsigned int)((_DWORD)&item + 8));
*((_DWORD *)&item + 12) = get_netflow();
*((_DWORD *)&item + 5) = *(_DWORD *)(shm_ucache + 1300000);
v3 = (const char *)(shm_utmp + 74);
v4 = shm_utmp + 7495034;
do
{
if ( *(_DWORD *)(v3 - 74) )
{
++*((_DWORD *)&item + 6);
if ( *(_DWORD *)(v3 - 66) == 1 )
{
if ( !strcmp(v3 + 60, "guest") )
++*((_DWORD *)&item + 11);
else
++*((_DWORD *)&item + 8);
}
else
{
++*((_DWORD *)&item + 7);
}
if ( !memcmp("162.105", v3, 7uLL) )
{
++*((_DWORD *)&item + 9);
if ( *(_DWORD *)(v3 - 66) != 1 )
++*((_DWORD *)&item + 10);
}
}
v3 += 1496;
}
while ( v3 != (const char *)v4 );
v5 = localtime(&item);
v6 = v5;
if ( !v5->tm_hour && v5->tm_min <= 5 )
*(_WORD *)(shm_utmp + 7494972) = *((_DWORD *)&item + 6);
v7 = open("/home/bbs/reclog/bbsstat.log", 65, 384LL);
if ( v7 >= 0 )
{
lseek(v7, (v6->tm_min / 6 + 10 * (v6->tm_hour + 24 * v6->tm_mday)) << 7, 0);
write(v7, &item, 0x80uLL);
close(v7);
}
syn_uindxexshm();
bonlinesync();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
__int64 v4; // r9
struct tm *v5; // rax
struct tm *v6; // rbx
int v7; // ebp

if ( (int)func0(argc, argv, envp) >= 0 )
{
item = time(0LL);
func5((_DWORD *)(unsigned int)((_DWORD)&item + 8));
*((_DWORD *)&item + 12) = func6();
*((_DWORD *)&item + 5) = *(_DWORD *)(shm_ucache + 1300000);
v3 = (const char *)(shm_utmp + 74);
v4 = shm_utmp + 7495034;
do
{
if ( *(_DWORD *)(v3 - 74) )
{
++*((_DWORD *)&item + 6);
if ( *(_DWORD *)(v3 - 66) == 1 )
{
if ( !strcmp(v3 + 60, "guest") )
++*((_DWORD *)&item + 11);
else
++*((_DWORD *)&item + 8);
}
else
{
++*((_DWORD *)&item + 7);
}
if ( !memcmp("162.105", v3, 7uLL) )
{
++*((_DWORD *)&item + 9);
if ( *(_DWORD *)(v3 - 66) != 1 )
++*((_DWORD *)&item + 10);
}
}
v3 += 1496;
}
while ( v3 != (const char *)v4 );
v5 = localtime(&item);
v6 = v5;
if ( !v5->tm_hour && v5->tm_min <= 5 )
*(_WORD *)(shm_utmp + 7494972) = *((_DWORD *)&item + 6);
v7 = open("/home/bbs/reclog/bbsstat.log", 65, 384LL);
if ( v7 >= 0 )
{
lseek(v7, (v6->tm_min / 6 + 10 * (v6->tm_hour + 24 * v6->tm_mday)) << 7, 0);
write(v7, &item, 0x80uLL);
close(v7);
}
func3();
func4();
}
return 0;
}

original_code:
int
main()
{
 int i, fd;
 struct user_info *p;
 struct tm *ptm;
 if (shm_init() < 0)
  return 0;
 item.time = time(((void *)0));
 get_load(item.load);
 item.netflow = get_netflow();
 item.naccount = shm_ucache->number;
 for (i = 0; i < (5000 + 10); i++) {
  p = &shm_utmp->uinfo[i];
  if (!p->active)
   continue;
  item.nonline++;
  if (p->pid == 1 && strcmp(p->userid, "guest"))
   item.nwww++;
  else if (p->pid == 1)
   item.nwwwguest++;
  else
   item.ntelnet++;
  if (!strncmp("162.105", p->from, 7)) {
   item.n162105++;
   if (p->pid != 1)
    item.n162105telnet++;
  }
 }
 ptm = localtime(&item.time);
 if (ptm->tm_hour == 0 && ptm->tm_min < 6)
  shm_utmp->maxtoday = item.nonline;
 fd = open("/home/bbs""/reclog/bbsstat.log", 01 | 0100, 0600);
 if (fd >= 0) {
  lseek(fd,
        ((ptm->tm_mday * 24 + ptm->tm_hour) * 10 +
         ptm->tm_min / 6) * ((int)sizeof(item)), 0);
  write(fd, &item, ((int)sizeof(item)));
  close(fd);
 }
 syn_uindxexshm();
 bonlinesync();
}

canonical_original_code:
int main()
{
 int i; int fd;
 struct user_info *p;
 struct tm *ptm;
 if (shm_init() < 0)
  return 0;
 item.time = time(((void *)0));
 get_load(item.load);
 item.netflow = get_netflow();
 item.naccount = shm_ucache->number;
 for (i = 0; i < (5000 + 10); i++) {
  p = &shm_utmp->uinfo[i];
  if (!p->active)
   continue;
  item.nonline++;
  if (p->pid == 1 && strcmp(p->userid, "guest"))
   item.nwww++;
  else if (p->pid == 1)
   item.nwwwguest++;
  else
   item.ntelnet++;
  if (!strncmp("162.105", p->from, 7)) {
   item.n162105++;
   if (p->pid != 1)
    item.n162105telnet++;
  }
 }
 ptm = localtime(&item.time);
 if (ptm->tm_hour == 0 && ptm->tm_min < 6)
  shm_utmp->maxtoday = item.nonline;
 fd = open("/home/bbs""/reclog/bbsstat.log", 01 | 0100, 0600);
 if (fd >= 0) {
  lseek(fd,
        ((ptm->tm_mday * 24 + ptm->tm_hour) * 10 +
         ptm->tm_min / 6) * ((int)sizeof(item)), 0);
  write(fd, &item, ((int)sizeof(item)));
  close(fd);
 }
 syn_uindxexshm();
 bonlinesync();
}

variable_types: fd int

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


getusernum

decompiled_code:
__int64 __fastcall getusernum(char *s2)
{
__int64 v1; // rax
const void *v2; // r13
const char *v3; // rbp
unsigned int v4; // ebx

if ( !*s2 )
return (unsigned int)-1;
v1 = try_get_shm(7912LL, 1300056LL, 0LL);
v2 = (const void *)v1;
if ( !v1 )
return (unsigned int)-1;
v3 = (const char *)v1;
v4 = 0;
while ( strcasecmp(v3, s2) )
{
++v4;
v3 += 13;
if ( v4 == 100000 )
{
shmdt(v2);
return (unsigned int)-1;
}
}
shmdt(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
__int64 v1; // rax
const void *v2; // r13
const char *v3; // rbp
unsigned int v4; // ebx

if ( !*s2 )
return (unsigned int)-1;
v1 = try_get_shm(7912LL, 1300056LL, 0LL);
v2 = (const void *)v1;
if ( !v1 )
return (unsigned int)-1;
v3 = (const char *)v1;
v4 = 0;
while ( strcasecmp(v3, s2) )
{
++v4;
v3 += 13;
if ( v4 == 100000 )
{
shmdt(v2);
return (unsigned int)-1;
}
}
shmdt(v2);
return v4;
}

original_code:
int
getusernum(char *id)
{
 int i;
 struct UCACHE *shm_ucache;
 if (id[0] == 0)
  return -1;
 shm_ucache =
     (struct UCACHE *) try_get_shm(7912,((int)sizeof(struct UCACHE)),0);
 if (shm_ucache == ((void *)0))
  return -1;
 for (i = 0; i < 100000; i++) {
  if (!strcasecmp(shm_ucache->userid[i], id)) {
   shmdt(shm_ucache);
   return i;
  }
 }
 shmdt(shm_ucache);
 return -1;
}

variable_types:
id
char *

variable_types: struct UCACHE { char userid[100000][-1]; int number; int usersum; long uptime; int nouse[10]; } *


getuser

decompiled_code:
__int64 __fastcall getuser(int a1, _QWORD *a2)
{
int v2; // eax
int v3; // ebp
__int64 result; // rax

if ( a1 < 0 )
return 0xFFFFFFFFLL;
v2 = open64("/home/bbs/.PASSWDS", 0);
v3 = v2;
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( lseek64(v2, 480 * a1, 0) == -1
|| (*a2 = 0LL,
a2[59] = 0LL,
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 480) >> 3)),
read(v3, a2, 0x1E0uLL) != 480) )
{
close(v3);
result = 0xFFFFFFFFLL;
}
else
{
close(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _QWORD *a2)
{
int v2; // eax
int v3; // ebp
__int64 result; // rax

if ( a1 < 0 )
return 0xFFFFFFFFLL;
v2 = open64("/home/bbs/.PASSWDS", 0);
v3 = v2;
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( lseek64(v2, 480 * a1, 0) == -1
|| (*a2 = 0LL,
a2[59] = 0LL,
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 480) >> 3)),
read(v3, a2, 0x1E0uLL) != 480) )
{
close(v3);
result = 0xFFFFFFFFLL;
}
else
{
close(v3);
result = 0LL;
}
return result;
}

original_code:
int
getuser(int uid, struct userec *userec1)
{
 int fd;
 if (uid < 0)
  return -1;
 fd = open("/home/bbs" "/" ".PASSWDS", 00);
 if (fd < 0)
  return -1;
 if ((off_t) - 1 == lseek(fd, uid * ((int)sizeof(struct userec)), 0)) {
  close(fd);
  return -1;
 }
 bzero(userec1, ((int)sizeof(struct userec)));
 if (((int)sizeof(struct userec)) != read(fd, userec1, ((int)sizeof(struct userec)))) {
  close(fd);
  return -1;
 }
 close(fd);
 return 0;
}

variable_types: struct userec { char userid[-1]; long firstlogin; char lasthost[16]; unsigned int numlogins; unsigned int numposts; char flags[2]; char passwd[14]; char username[40]; unsigned short numdays; char unuse[30]; long dietime; long lastlogout; char ip[16]; char realmail[-1]; unsigned int userlevel; long lastlogin; long stay; char realname[40]; char address[80]; char email[80]; int signature; unsigned int userdefine; long notedate_nouse; int noteline_nouse; int notemode_nouse; } *


checkuser

decompiled_code:
__int64 __fastcall checkuser(char *s1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
time_t v5; // rax

v2 = getusernum(s1);
v3 = 0;
if ( v2 >= 0 && (int)getuser(v2, currentuser) >= 0 )
{
v3 = strcasecmp(s1, currentuser);
if ( v3 )
{
v3 = 0;
}
else if ( !(unsigned int)userbansite(currentuser, remotehostname) )
{
v3 = isanonymous;
if ( isanonymous )
{
v3 = 1;
}
else if ( (currentuser[232] & 1) != 0 )
{
v3 = checkpasswd((unsigned int)((_DWORD)currentuser + 50), a2);
if ( v3 )
{
v3 = 1;
}
else
{
v5 = time(0LL);
logattempt(currentuser, remotehostname, "FTP", v5);
}
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
time_t v5; // rax

v2 = func0(s1);
v3 = 0;
if ( v2 >= 0 && (int)func1(v2, currentuser) >= 0 )
{
v3 = strcasecmp(s1, currentuser);
if ( v3 )
{
v3 = 0;
}
else if ( !(unsigned int)userbansite(currentuser, remotehostname) )
{
v3 = isanonymous;
if ( isanonymous )
{
v3 = 1;
}
else if ( (currentuser[232] & 1) != 0 )
{
v3 = checkpasswd((unsigned int)((_DWORD)currentuser + 50), a2);
if ( v3 )
{
v3 = 1;
}
else
{
v5 = time(0LL);
logattempt(currentuser, remotehostname, "FTP", v5);
}
}
}
}
return v3;
}

original_code:
int
checkuser(char *id, char *pw)
{
 int currentuid;
 if ((currentuid = getusernum(id)) < 0)
  return 0;
 if (getuser(currentuid, &currentuser) < 0)
  return 0;
 if (strcasecmp(id, currentuser.userid))
  return 0;
 if (userbansite(currentuser.userid, remotehostname))
  return 0;
 if (isanonymous)
  return 1;
 if (!(((000001)&0100000000)?(currentuser.dietime):((000001)?currentuser.userlevel&(000001):1)))
  return 0;
 if (!checkpasswd(currentuser.passwd, pw)) {
  time_t t = time(((void *)0));
  logattempt(currentuser.userid, remotehostname, "FTP", t);
  return 0;
 }
 return 1;
}

canonical_original_code:
int checkuser(char *id, char *pw)
{
 int currentuid;
 if ((currentuid = getusernum(id)) < 0)
  return 0;
 if (getuser(currentuid, &currentuser) < 0)
  return 0;
 if (strcasecmp(id, currentuser.userid))
  return 0;
 if (userbansite(currentuser.userid, remotehostname))
  return 0;
 if (isanonymous)
  return 1;
 if (!(((000001)&0100000000)?(currentuser.dietime):((000001)?currentuser.userlevel&(000001):1)))
  return 0;
 if (!checkpasswd(currentuser.passwd, pw)) {
  long t = time(((void *)0));
  logattempt(currentuser.userid, remotehostname, "FTP", t);
  return 0;
 }
 return 1;
}

variable_types:
pw
char *

variable_types: currentuid int