repo: dedesite/piscine

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

v1 = len_2;
v2 = (unsigned __int8 *)ptr_buff_0;
if ( !len_2 )
{
v1 = read(a1, &buff_1, 0x40uLL);
v3 = 0;
ptr_buff_0 = (__int64)&buff_1;
len_2 = v1;
if ( !v1 )
return v3;
v2 = (unsigned __int8 *)&buff_1;
}
v3 = *v2;
ptr_buff_0 = (__int64)(v2 + 1);
len_2 = v1 - 1;
return v3;
}

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

v1 = len_2;
v2 = (unsigned __int8 *)ptr_buff_0;
if ( !len_2 )
{
v1 = read(a1, &buff_1, 0x40uLL);
v3 = 0;
ptr_buff_0 = (__int64)&buff_1;
len_2 = v1;
if ( !v1 )
return v3;
v2 = (unsigned __int8 *)&buff_1;
}
v3 = *v2;
ptr_buff_0 = (__int64)(v2 + 1);
len_2 = v1 - 1;
return v3;
}

original_code:
char get_char(const int fd)
{
    static char buff[64];
    static char* ptr_buff;
    static int len = 0;
    char c;
    if(len == 0)
    {
        len = read(fd, buff, 64);
        ptr_buff = (char*)&buff;
        if(len == 0)
            return (0);
    }
    c = *ptr_buff;
    ptr_buff++;
    len--;
    return c;
}

canonical_original_code:
char get_char(int fd)
{
    static char buff[64];
    static char *ptr_buff;
    static int len = 0;
    char c;
    if(len == 0)
    {
        len = read(fd, buff, 64);
        ptr_buff = (char *)&buff;
        if(len == 0)
            return (0);
    }
    c = *ptr_buff;
    ptr_buff++;
    len--;
    return c;
}

variable_types: fd int

variable_types:
buff
char [64]

variable_types: len int

variable_types: c char

return_type: char


eq

decompiled_code:
_BOOL8 __fastcall eq(int a1, int a2)
{
return ((a2 - a1) | (a1 - a2)) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(int a1, int a2)
{
return ((a2 - a1) | (a1 - a2)) >= 0;
}

original_code:
int eq(int x, int y)
{
  return (unsigned int)(~((x-y) | (y-x))) >> 31;
}

variable_types: x int

variable_types: y int

return_type: int


ne

decompiled_code:
__int64 __fastcall ne(int a1, int a2)
{
return ((a1 - a2) | (unsigned int)(a2 - a1)) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
return ((a1 - a2) | (unsigned int)(a2 - a1)) >> 31;
}

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


lt

decompiled_code:
__int64 __fastcall lt(unsigned int a1, int a2)
{
return ((a1 - a2) ^ (a1 ^ a2) & ((a1 - a2) ^ a1)) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
return ((a1 - a2) ^ (a1 ^ a2) & ((a1 - a2) ^ a1)) >> 31;
}

original_code:
int lt(int x, int y)
{
  return (unsigned int)((x-y) ^ ((x^y)&((x-y)^x))) >> 31;
}


le

decompiled_code:
__int64 __fastcall le(int a1, int a2)
{
return ((a1 | ~a2) & (a1 ^ a2 | (unsigned int)~(a2 - a1))) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
return ((a1 | ~a2) & (a1 ^ a2 | (unsigned int)~(a2 - a1))) >> 31;
}

original_code:
int le(int x, int y)
{
  return (unsigned int)((x|~y) & ((x^y) | ~(y-x))) >> 31;
}


decompiled_code:
__int64 __fastcall lt_unsigned(int a1, int a2)
{
return (~a1 & a2 | (a1 - a2) & (a2 | (unsigned int)~a1)) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
return (~a1 & a2 | (a1 - a2) & (a2 | (unsigned int)~a1)) >> 31;
}

original_code:
int lt_unsigned(int x, int y)
{
  return (unsigned int)((~x&y) | ((~x|y)&(x-y))) >> 31;
}


decompiled_code:
__int64 __fastcall le_unsigned(int a1, int a2)
{
return ((a2 | ~a1) & (a2 ^ a1 | (unsigned int)~(a2 - a1))) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
return ((a2 | ~a1) & (a2 ^ a1 | (unsigned int)~(a2 - a1))) >> 31;
}

original_code:
int le_unsigned(int x, int y)
{
  return (unsigned int)((~x|y) & ((x^y) | ~(y-x))) >> 31;
}


main

canonical_name: main

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

if ( argc != 3 )
exit(0);
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
printf("x:%d, y:%d\n", v3, v4);
v5 = eq(v3, (unsigned int)v4);
printf("x = y :%d\n", v5);
v6 = ne(v3, (unsigned int)v4);
printf("x != y :%d\n", v6);
v7 = lt(v3, (unsigned int)v4);
printf("x < y :%d\n", v7);
v8 = le(v3, (unsigned int)v4);
printf("x <= y :%d\n", v8);
v9 = lt_unsigned(v3, (unsigned int)v4);
printf("x u< y :%d\n", v9);
v10 = le_unsigned(v3, (unsigned int)v4);
printf("x u<= y:%d\n", v10);
return 0;
}

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

if ( argc != 3 )
exit(0);
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
printf("x:%d, y:%d\n", v3, v4);
v5 = func7(v3, (unsigned int)v4);
printf("x = y :%d\n", v5);
v6 = func8(v3, (unsigned int)v4);
printf("x != y :%d\n", v6);
v7 = func9(v3, (unsigned int)v4);
printf("x < y :%d\n", v7);
v8 = func10(v3, (unsigned int)v4);
printf("x <= y :%d\n", v8);
v9 = func11(v3, (unsigned int)v4);
printf("x u< y :%d\n", v9);
v10 = func12(v3, (unsigned int)v4);
printf("x u<= y:%d\n", v10);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 3)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  printf("x:%d, y:%d\n", x, y);
  printf("x = y  :%d\n", eq(x, y));
  printf("x != y :%d\n", ne(x, y));
  printf("x < y  :%d\n", lt(x, y));
  printf("x <= y :%d\n", le(x, y));
  printf("x u< y :%d\n", lt_unsigned(x, y));
  printf("x u<= y:%d\n", le_unsigned(x, y));
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 3)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  printf("x:%d, y:%d\n", x, y);
  printf("x = y  :%d\n", eq(x, y));
  printf("x != y :%d\n", ne(x, y));
  printf("x < y  :%d\n", lt(x, y));
  printf("x <= y :%d\n", le(x, y));
  printf("x u< y :%d\n", lt_unsigned(x, y));
  printf("x u<= y:%d\n", le_unsigned(x, y));
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall zbytel1(unsigned int a1)
{
__int64 result; // rax

result = 0LL;
if ( HIBYTE(a1) )
{
result = 1LL;
if ( (a1 & 0xFF0000) != 0 )
{
result = 2LL;
if ( (a1 & 0xFF00) != 0 )
result = 3 - ((unsigned int)((_BYTE)a1 == 0) - 1);
}
}
return result;
}

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

result = 0LL;
if ( HIBYTE(a1) )
{
result = 1LL;
if ( (a1 & 0xFF0000) != 0 )
{
result = 2LL;
if ( (a1 & 0xFF00) != 0 )
result = 3 - ((unsigned int)((_BYTE)a1 == 0) - 1);
}
}
return result;
}

original_code:
int zbytel1(unsigned int x)
{
  if((x>>24) == 0)
    return 0;
  else if((x&0x00FF0000) == 0)
    return 1;
  else if((x&0x0000FF00) == 0)
    return 2;
  else if((x&0x000000FF) == 0)
    return 3;
  else
    return 4;
}

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall zbytel2(int a1)
{
return (unsigned int)((int)nlz(~(a1 | ((a1 & 0x7F7F7F7F) + 2139062143) | 0x7F7F7F7Fu)) >> 3);
}

original_code:
int zbytel2(unsigned int x)
{
  unsigned int y;
  int n;
  y = (x & 0x7F7F7F7F) + 0x7F7F7F7F;
  y = ~(y | x | 0x7F7F7F7F);
  n = nlz(y) >> 3;
  return n;
}

variable_types:
y
unsigned int

variable_types: n int


decompiled_code:
__int64 __fastcall search_word(int a1, int a2)
{
__int64 v2; // rsi

v2 = (unsigned int)(16843009 * a2);
printf("temp hex:0x%x\n", v2);
return zbytel2(a1 ^ (unsigned int)v2);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
__int64 v2; // rsi

v2 = (unsigned int)(16843009 * a2);
printf("temp hex:0x%x\n", v2);
return func10(a1 ^ (unsigned int)v2);
}

original_code:
int search_word(unsigned int x, int word){
  int temp = 0;
  temp += word<<24;
  temp += word<<16;
  temp += word<<8;
  temp += word;
  printf("temp hex:0x%x\n", temp);
  return zbytel2(x^temp);
}

variable_types: word int

variable_types: temp int


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

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

original_code:
int rightmost_bit_1_to_0(int x)
{
  return x & (x-1);
}


decompiled_code:
__int64 __fastcall rightmost_bit_0_to_1(int a1)
{
return a1 | (unsigned int)(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return a1 | (unsigned int)(a1 + 1);
}

original_code:
int rightmost_bit_0_to_1(int x)
{
  return x | (x+1);
}


decompiled_code:
__int64 __fastcall get_rightmost_bit_1(int a1)
{
return a1 & (unsigned int)-a1;
}

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

original_code:
int get_rightmost_bit_1(int x)
{
  return x & (-x);
}


decompiled_code:
__int64 __fastcall get_rightmost_bit_0(int a1)
{
return ~a1 & (unsigned int)(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return ~a1 & (unsigned int)(a1 + 1);
}

original_code:
int get_rightmost_bit_0(int x)
{
  return (~x) & (x+1);
}


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

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

original_code:
int get_mask_last_line_0(int x)
{
  return (~x) & (x-1);
}


decompiled_code:
__int64 __fastcall rightmost_bit_1_propagate(int a1)
{
return a1 | (unsigned int)(a1 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
return a1 | (unsigned int)(a1 - 1);
}

original_code:
int rightmost_bit_1_propagate(int x)
{
  return x | (x-1);
}


decompiled_code:
__int64 __fastcall rightmost_line_1_to_0(int a1)
{
return a1 & ((a1 | (unsigned int)(a1 - 1)) + 1);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
return a1 & ((a1 | (unsigned int)(a1 - 1)) + 1);
}

original_code:
int rightmost_line_1_to_0(int x)
{
  return ((x | (x-1)) + 1) & x;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
char v12[16]; // [rsp+8h] [rbp-10h] BYREF

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
int2binary(v3, v12);
printf("argument :%.8s\n", v12);
v4 = rightmost_bit_1_to_0((unsigned int)v3, v12);
int2binary(v4, v12);
printf("rightmost_bit_1_to_0 :%.8s\n", v12);
v5 = rightmost_bit_0_to_1((unsigned int)v3, v12);
int2binary(v5, v12);
printf("rightmost_bit_0_to_1 :%.8s\n", v12);
v6 = get_rightmost_bit_1((unsigned int)v3, v12);
int2binary(v6, v12);
printf("get_rightmost_bit_1 :%.8s\n", v12);
v7 = get_rightmost_bit_0((unsigned int)v3, v12);
int2binary(v7, v12);
printf("get_rightmost_bit_0 :%.8s\n", v12);
v8 = get_mask_last_line_0((unsigned int)v3, v12);
int2binary(v8, v12);
printf("get_mask_last_line_0 :%.8s\n", v12);
v9 = rightmost_bit_1_propagate((unsigned int)v3, v12);
int2binary(v9, v12);
printf("rightmost_bit_1_propagate:%.8s\n", v12);
v10 = rightmost_line_1_to_0((unsigned int)v3, v12);
int2binary(v10, v12);
printf("rightmost_line_1_to_0 :%.8s\n", v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax
unsigned int v9; // eax
unsigned int v10; // eax
char v12[16]; // [rsp+8h] [rbp-10h] BYREF

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
int2binary(v3, v12);
printf("argument :%.8s\n", v12);
v4 = func7((unsigned int)v3, v12);
int2binary(v4, v12);
printf("rightmost_bit_1_to_0 :%.8s\n", v12);
v5 = func8((unsigned int)v3, v12);
int2binary(v5, v12);
printf("rightmost_bit_0_to_1 :%.8s\n", v12);
v6 = func9((unsigned int)v3, v12);
int2binary(v6, v12);
printf("get_rightmost_bit_1 :%.8s\n", v12);
v7 = func10((unsigned int)v3, v12);
int2binary(v7, v12);
printf("get_rightmost_bit_0 :%.8s\n", v12);
v8 = func11((unsigned int)v3, v12);
int2binary(v8, v12);
printf("get_mask_last_line_0 :%.8s\n", v12);
v9 = func12((unsigned int)v3, v12);
int2binary(v9, v12);
printf("rightmost_bit_1_propagate:%.8s\n", v12);
v10 = func13((unsigned int)v3, v12);
int2binary(v10, v12);
printf("rightmost_line_1_to_0 :%.8s\n", v12);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 2)
    exit(0);
  int x, y;
  char c[8];
  x = atoi(argv[1]);
  int2binary(x, c);
  printf("argument                 :%.8s\n", c);
  y = rightmost_bit_1_to_0(x);
  int2binary(y, c);
  printf("rightmost_bit_1_to_0     :%.8s\n", c);
  y = rightmost_bit_0_to_1(x);
  int2binary(y, c);
  printf("rightmost_bit_0_to_1     :%.8s\n", c);
  y = get_rightmost_bit_1(x);
  int2binary(y, c);
  printf("get_rightmost_bit_1      :%.8s\n", c);
  y = get_rightmost_bit_0(x);
  int2binary(y, c);
  printf("get_rightmost_bit_0      :%.8s\n", c);
  y = get_mask_last_line_0(x);
  int2binary(y, c);
  printf("get_mask_last_line_0     :%.8s\n", c);
  y = rightmost_bit_1_propagate(x);
  int2binary(y, c);
  printf("rightmost_bit_1_propagate:%.8s\n", c);
  y = rightmost_line_1_to_0(x);
  int2binary(y, c);
  printf("rightmost_line_1_to_0    :%.8s\n", c);
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 2)
    exit(0);
  int x; int y;
  char c[8];
  x = atoi(argv[1]);
  int2binary(x, c);
  printf("argument                 :%.8s\n", c);
  y = rightmost_bit_1_to_0(x);
  int2binary(y, c);
  printf("rightmost_bit_1_to_0     :%.8s\n", c);
  y = rightmost_bit_0_to_1(x);
  int2binary(y, c);
  printf("rightmost_bit_0_to_1     :%.8s\n", c);
  y = get_rightmost_bit_1(x);
  int2binary(y, c);
  printf("get_rightmost_bit_1      :%.8s\n", c);
  y = get_rightmost_bit_0(x);
  int2binary(y, c);
  printf("get_rightmost_bit_0      :%.8s\n", c);
  y = get_mask_last_line_0(x);
  int2binary(y, c);
  printf("get_mask_last_line_0     :%.8s\n", c);
  y = rightmost_bit_1_propagate(x);
  int2binary(y, c);
  printf("rightmost_bit_1_propagate:%.8s\n", c);
  y = rightmost_line_1_to_0(x);
  int2binary(y, c);
  printf("rightmost_line_1_to_0    :%.8s\n", c);
}

variable_types:
c
char [8]


max

decompiled_code:
__int64 __fastcall max(int a1, int a2)
{
int v2; // eax
int v3; // ecx

v2 = doz(a1, a2);
return (unsigned int)(v3 + v2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2)
{
int v2; // eax
int v3; // ecx

v2 = func7(a1, a2);
return (unsigned int)(v3 + v2);
}

original_code:
int max(int x, int y)
{
  return y + doz(x, y);
}


min

decompiled_code:
__int64 __fastcall min(int a1, int a2)
{
return a1 - (unsigned int)doz(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
return a1 - (unsigned int)func7(a1, a2);
}

original_code:
int min(int x, int y)
{
  return x - doz(x, y);
}


dozu

decompiled_code:
__int64 __fastcall dozu(int a1, int a2)
{
return (a1 - a2) & (unsigned int)~((a2 & ~a1 | (a1 - a2) & ~(a2 ^ a1)) >> 31);
}

original_code:
unsigned int dozu(unsigned int x, unsigned int y)
{
  int d = x - y;
  return d & ~((int)(((~x&y) | (~(x^y) & d))) >> 31);
}

variable_types: d int

return_type: unsigned int


maxu

decompiled_code:
__int64 __fastcall maxu(int a1, int a2)
{
return a2 + (unsigned int)dozu(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
return a2 + (unsigned int)func10(a1, a2);
}

original_code:
unsigned int maxu(unsigned int x, unsigned int y)
{
  return y + dozu(x, y);
}


minu

decompiled_code:
__int64 __fastcall minu(int a1, int a2)
{
int v2; // eax
int v3; // ecx

v2 = dozu(a1, a2);
return (unsigned int)(v3 - v2);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
int v2; // eax
int v3; // ecx

v2 = func10(a1, a2);
return (unsigned int)(v3 - v2);
}

original_code:
unsigned int minu(unsigned int x, unsigned int y)
{
  return x - dozu(x, y);
}


main

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

if ( argc != 3 )
exit(0);
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
printf("x:%d, y:%d\n", v3, v4);
v5 = doz(v3, (unsigned int)v4);
printf("doz :%d\n", v5);
v6 = max(v3, (unsigned int)v4);
printf("max :%d\n", v6);
v7 = min(v3, (unsigned int)v4);
printf("min :%d\n", v7);
v8 = dozu(v3, (unsigned int)v4);
printf("dozu:%u\n", v8);
v9 = maxu(v3, (unsigned int)v4);
printf("maxu:%u\n", v9);
v10 = minu(v3, (unsigned int)v4);
printf("minu:%u\n", v10);
return 0;
}

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

if ( argc != 3 )
exit(0);
v3 = atoi(argv[1]);
v4 = (unsigned int)atoi(argv[2]);
printf("x:%d, y:%d\n", v3, v4);
v5 = func7(v3, (unsigned int)v4);
printf("doz :%d\n", v5);
v6 = func8(v3, (unsigned int)v4);
printf("max :%d\n", v6);
v7 = func9(v3, (unsigned int)v4);
printf("min :%d\n", v7);
v8 = func10(v3, (unsigned int)v4);
printf("dozu:%u\n", v8);
v9 = func11(v3, (unsigned int)v4);
printf("maxu:%u\n", v9);
v10 = func12(v3, (unsigned int)v4);
printf("minu:%u\n", v10);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 3)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  printf("x:%d, y:%d\n", x, y);
  printf("doz :%d\n", doz(x, y));
  printf("max :%d\n", max(x, y));
  printf("min :%d\n", min(x, y));
  printf("dozu:%u\n", dozu(x, y));
  printf("maxu:%u\n", maxu(x, y));
  printf("minu:%u\n", minu(x, y));
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 3)
    exit(0);
  int x = atoi(argv[1]);
  int y = atoi(argv[2]);
  printf("x:%d, y:%d\n", x, y);
  printf("doz :%d\n", doz(x, y));
  printf("max :%d\n", max(x, y));
  printf("min :%d\n", min(x, y));
  printf("dozu:%u\n", dozu(x, y));
  printf("maxu:%u\n", maxu(x, y));
  printf("minu:%u\n", minu(x, y));
}


decompiled_code:
__int64 __fastcall cyclic_left_shift(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
return (unsigned int)__ROL4__(a1, a2);
}

original_code:
int cyclic_left_shift(int x, unsigned int n)
{
  return (x << n) | ((unsigned int)x >> (32-n));
}

variable_types:
n
unsigned int


decompiled_code:
__int64 __fastcall cyclic_right_shift(int a1, char a2)
{
return (unsigned int)__ROR4__(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char a2)
{
return (unsigned int)__ROR4__(a1, a2);
}

original_code:
int cyclic_right_shift(int x, unsigned int n)
{
  return ((unsigned int)x >> n) | (x << (32-n));
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // r12
unsigned int v5; // eax
unsigned int v6; // eax
char v8[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc != 3 || (v3 = atoi(argv[2]), v3 > 0x20) )
exit(0);
v4 = (unsigned int)atoi(argv[1]);
printf("x:%d, n:%d\n", v4, v3);
int2binary((unsigned int)v4, v8);
printf("before shift :%.32s\n", v8);
v5 = cyclic_left_shift((unsigned int)v4, v3);
int2binary(v5, v8);
printf("after left shift :%.32s\n", v8);
v6 = cyclic_right_shift((unsigned int)v4, v3);
int2binary(v6, v8);
printf("after right shift :%.32s\n", v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int64 v4; // r12
unsigned int v5; // eax
unsigned int v6; // eax
char v8[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc != 3 || (v3 = atoi(argv[2]), v3 > 0x20) )
exit(0);
v4 = (unsigned int)atoi(argv[1]);
printf("x:%d, n:%d\n", v4, v3);
int2binary((unsigned int)v4, v8);
printf("before shift :%.32s\n", v8);
v5 = func7((unsigned int)v4, v3);
int2binary(v5, v8);
printf("after left shift :%.32s\n", v8);
v6 = func8((unsigned int)v4, v3);
int2binary(v6, v8);
printf("after right shift :%.32s\n", v8);
return 0;
}

original_code:
int main(int argc, char** argv)
{
  if(argc != 3)
    exit(0);
  int x = atoi(argv[1]);
  int y;
  int n = atoi(argv[2]);
  if(n > 32 || n < 0)
    exit(0);
  char c[32];
  printf("x:%d, n:%d\n", x, n);
  int2binary(x, c);
  printf("before shift      :%.32s\n", c);
  y = cyclic_left_shift(x, n);
  int2binary(y, c);
  printf("after left shift  :%.32s\n", c);
  y = cyclic_right_shift(x, n);
  int2binary(y, c);
  printf("after right shift :%.32s\n", c);
}

canonical_original_code:
int main(int argc, char **argv)
{
  if(argc != 3)
    exit(0);
  int x = atoi(argv[1]);
  int y;
  int n = atoi(argv[2]);
  if(n > 32 || n < 0)
    exit(0);
  char c[32];
  printf("x:%d, n:%d\n", x, n);
  int2binary(x, c);
  printf("before shift      :%.32s\n", c);
  y = cyclic_left_shift(x, n);
  int2binary(y, c);
  printf("after left shift  :%.32s\n", c);
  y = cyclic_right_shift(x, n);
  int2binary(y, c);
  printf("after right shift :%.32s\n", c);
}

variable_types:
c
char [32]


decompiled_code:
__int64 __fastcall detect_overflow_signed_add(int a1, int a2, int a3)
{
return (~(a2 ^ a1) & (a1 ^ (unsigned int)(a3 + a1 + a2))) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, int a3)
{
return (~(a2 ^ a1) & (a1 ^ (unsigned int)(a3 + a1 + a2))) >> 31;
}

original_code:
int detect_overflow_signed_add(int x, int y, int c)
{
  return (unsigned int)(~(x^y) & ((x+y+c)^x)) >> 31;
}

variable_types: c int


decompiled_code:
__int64 __fastcall detect_overflow_signed_sub(int a1, int a2, int a3)
{
return ((a2 ^ a1) & (a1 ^ (unsigned int)(a1 - a2 - a3))) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3)
{
return ((a2 ^ a1) & (a1 ^ (unsigned int)(a1 - a2 - a3))) >> 31;
}

original_code:
int detect_overflow_signed_sub(int x, int y, int c)
{
  return (unsigned int)((x^y) & ((x-y-c)^x)) >> 31;
}


decompiled_code:
__int64 __fastcall detect_overflow_unsigned_add(int a1, int a2, int a3)
{
return (a2 & a1 | (a2 | a1) & (unsigned int)~(a2 + a3 + a1)) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2, int a3)
{
return (a2 & a1 | (a2 | a1) & (unsigned int)~(a2 + a3 + a1)) >> 31;
}

original_code:
int detect_overflow_unsigned_add(unsigned int x, unsigned int y, unsigned int c)
{
   return (unsigned int)((x&y) | ((x|y) & ~(x+y+c))) >> 31;
}

variable_types:
c
unsigned int


decompiled_code:
__int64 __fastcall detect_overflow_unsigned_sub(int a1, int a2, int a3)
{
return ((a2 | ~a1) & (a1 - a2 - a3) | a2 & (unsigned int)~a1) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2, int a3)
{
return ((a2 | ~a1) & (a1 - a2 - a3) | a2 & (unsigned int)~a1) >> 31;
}

original_code:
int detect_overflow_unsigned_sub(unsigned int x, unsigned int y, unsigned int c)
{
  return (unsigned int)((~x&y) | ((~x|y) & (x-y-c))) >> 31;
}


decompiled_code:
__int64 __fastcall detect_overflow_signed_mul(__int64 a1, __int64 a2)
{
return ((unsigned int)(((unsigned __int64)(a2 * a1) >> 32) - (((int)a2 * (int)a1) >> 31)) | (unsigned int)((((int)a2 * (int)a1) >> 31) - ((unsigned __int64)(a2 * a1) >> 32))) >> 31;
}

original_code:
int detect_overflow_signed_mul(long x, long y)
{
  int hi = (x * y) >> 32;
  int lo = x * y;
  int sign_lo = lo >> 31;
  return (unsigned int)((hi - sign_lo) | (sign_lo - hi)) >> 31;
}

variable_types: x long

variable_types: y long

variable_types: hi int

variable_types: lo int


decompiled_code:
unsigned __int64 __fastcall detect_overflow_unsigned_mul(__int64 a1, __int64 a2)
{
return (-((unsigned __int64)(a2 * a1) >> 32) | ((unsigned __int64)(a2 * a1) >> 32)) >> 31;
}

original_code:
int detect_overflow_unsigned_mul(unsigned long x, unsigned long y)
{
  long hi = (x * y) >> 32;
  return (unsigned int)(hi | -hi) >> 31;
}

variable_types:
x
unsigned long

variable_types:
y
unsigned long

variable_types: hi long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rbp
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", v3, (unsigned int)v4, v5);
v6 = detect_overflow_signed_add(v3, (unsigned int)v4, v5);
printf("detect signed overflow x+y+c :%d\n", v6);
v7 = detect_overflow_signed_sub(v3, (unsigned int)v4, v5);
printf("detect signed overflow x-y-c :%d\n", v7);
v8 = detect_overflow_unsigned_add(v3, (unsigned int)v4, v5);
printf("detect unsigned overflow x+y+c :%d\n", v8);
v9 = detect_overflow_unsigned_sub(v3, (unsigned int)v4, v5);
printf("detect unsigned overflow x-y-c :%d\n", v9);
v10 = detect_overflow_signed_mul((int)v3, v4);
printf("detect signed overflow x*y :%d\n", v10);
v11 = detect_overflow_unsigned_mul((int)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)
{
unsigned int v3; // ebx
__int64 v4; // rbp
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", v3, (unsigned int)v4, v5);
v6 = func7(v3, (unsigned int)v4, v5);
printf("detect signed overflow x+y+c :%d\n", v6);
v7 = func8(v3, (unsigned int)v4, v5);
printf("detect signed overflow x-y-c :%d\n", v7);
v8 = func9(v3, (unsigned int)v4, v5);
printf("detect unsigned overflow x+y+c :%d\n", v8);
v9 = func10(v3, (unsigned int)v4, v5);
printf("detect unsigned overflow x-y-c :%d\n", v9);
v10 = func11((int)v3, v4);
printf("detect signed overflow x*y :%d\n", v10);
v11 = func12((int)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;
}


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);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
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((unsigned int)v3);
printf("abs1 :%d\n", v4);
v5 = abs2((unsigned int)v3);
printf("abs2 :%d\n", v5);
v6 = abs3((unsigned int)v3);
printf("abs3 :%d\n", v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
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((unsigned int)v3);
printf("abs1 :%d\n", v4);
v5 = func8((unsigned int)v3);
printf("abs2 :%d\n", v5);
v6 = func9((unsigned int)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; // er9
char v3; // al
int v4; // er9
int v5; // eax
int v6; // er9
unsigned int v7; // er10

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

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, int a2)
{
unsigned int v2; // er9
char v3; // al
int v4; // er9
int v5; // eax
int v6; // er9
unsigned int v7; // er10

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

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)
{
int v2; // ecx

while ( a2 > 1 )
{
v2 = a2 >> 1;
a2 -= a2 >> 1;
a1 &= a1 << v2;
}
return nlz(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, int a2)
{
int v2; // ecx

while ( a2 > 1 )
{
v2 = a2 >> 1;
a2 -= a2 >> 1;
a1 &= a1 << v2;
}
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;
for ( result = 0LL; v1; v1 >>= 1 )
result = (unsigned int)(result + 1);
return result;
}

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

v1 = (a1 - 1) & ~a1;
for ( result = 0LL; v1; v1 >>= 1 )
result = (unsigned int)(result + 1);
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; // rbp
unsigned int v4; // eax

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

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

if ( argc != 2 )
exit(0);
v3 = (unsigned int)atoi(argv[1]);
printf("argument :%d\n", v3);
v4 = func7((unsigned int)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; // rbp
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((unsigned int)v3);
printf("parity1: %d\n", v4);
v5 = parity2((unsigned int)v3);
printf("parity2: %d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
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((unsigned int)v3);
printf("parity1: %d\n", v4);
v5 = func8((unsigned int)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 i; // er8

for ( i = 0; a1; a1 &= a1 - 1 )
++i;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int i; // er8

for ( i = 0; a1; a1 &= a1 - 1 )
++i;
return i;
}

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; // rbp
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((unsigned int)v3);
printf("pop1: %d\n", v4);
v5 = pop2((unsigned int)v3);
printf("pop2: %d\n", v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
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((unsigned int)v3);
printf("pop1: %d\n", v4);
v5 = func8((unsigned int)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)
{
int v3; // eax
const char *v4; // rdi
unsigned int v5; // ebp
int v6; // eax
const char *v7; // rdi
unsigned int v8; // er13
unsigned int v9; // er12
unsigned int v11; // [rsp+8h] [rbp-90h] BYREF
unsigned int v12; // [rsp+Ch] [rbp-8Ch] BYREF
char v13[32]; // [rsp+10h] [rbp-88h] BYREF
char v14[32]; // [rsp+30h] [rbp-68h] BYREF
char v15[72]; // [rsp+50h] [rbp-48h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rdi
unsigned int v5; // ebp
int v6; // eax
const char *v7; // rdi
unsigned int v8; // er13
unsigned int v9; // er12
unsigned int v11; // [rsp+8h] [rbp-90h] BYREF
unsigned int v12; // [rsp+Ch] [rbp-8Ch] BYREF
char v13[32]; // [rsp+10h] [rbp-88h] BYREF
char v14[32]; // [rsp+30h] [rbp-68h] BYREF
char v15[72]; // [rsp+50h] [rbp-48h] BYREF

if ( argc != 4 )
exit(0);
v3 = atoi(argv[1]);
v4 = argv[2];
v5 = v3;
v11 = v3;
v6 = atoi(v4);
v7 = argv[3];
v8 = v6;
v12 = v6;
v9 = atoi(v7);
printf("before swap x:%d, y:%d\n", v5, v8);
func7(&v11, &v12);
printf("after swap x:%d, y:%d\n", v11, v12);
int2binary(v11, v13);
int2binary(v12, v14);
int2binary(v9, v15);
printf("mask:%.32s\n", v15);
puts("before mask_swap");
printf(" x:%.32s\n", v13);
printf(" y:%.32s\n", v14);
func8(&v11, &v12, v9);
int2binary(v11, v13);
int2binary(v12, v14);
puts("after mask_swap");
printf(" x:%.32s\n", v13);
printf(" y:%.32s\n", v14);
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; // r10
unsigned __int8 *v8; // rax
char *v9; // r10

*a3 = 0;
*a2 = 0;
v6 = (unsigned __int8 *)strtok(a1, "+");
if ( !v6 )
return 0xFFFFFFFFLL;
_unhcode(v6);
strsncpy(a2, v7, a4);
v8 = (unsigned __int8 *)strtok(0LL, "+");
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; // r10
unsigned __int8 *v8; // rax
char *v9; // r10

*a3 = 0;
*a2 = 0;
v6 = (unsigned __int8 *)strtok(a1, "+");
if ( !v6 )
return 0xFFFFFFFFLL;
func9(v6);
func10(a2, v7, a4);
v8 = (unsigned __int8 *)strtok(0LL, "+");
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)
{
__int128 v2[2]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402490);
v2[1] = (__int128)_mm_load_si128((const __m128i *)&xmmword_4024A0);
return (unsigned int)-(strpbrk(a1, (const char *)v2) != 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1)
{
__int128 v2[2]; // [rsp+0h] [rbp-28h] BYREF

v2[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402490);
v2[1] = (__int128)_mm_load_si128((const __m128i *)&xmmword_4024A0);
return (unsigned int)-(strpbrk(a1, (const char *)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; // er12

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

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

if ( (unsigned int)func17(s1) || (v2 = func17(a2)) != 0 )
return (unsigned int)-1;
if ( !strcasecmp(s1, "any") )
*s1 = 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[2072]; // [rsp+0h] [rbp-818h] 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[2072]; // [rsp+0h] [rbp-818h] 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

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

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

v2 = *((_DWORD *)a2 + 14);
v3 = *((_DWORD *)a1 + 14);
if ( v2 == v3 && (v2 = *((_DWORD *)a2 + 13), v3 = *((_DWORD *)a1 + 13), v2 == v3) )
result = (unsigned int)(*((_DWORD *)a2 + 15) - *((_DWORD *)a1 + 15));
else
result = (unsigned int)(v2 - v3);
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[32]; // [rsp+10h] [rbp-108h] BYREF
char s[80]; // [rsp+30h] [rbp-E8h] BYREF
char v9; // [rsp+80h] [rbp-98h] BYREF

v6[0] = (__int64)v7;
v6[1] = (__int64)&v9;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v7, 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[32]; // [rsp+10h] [rbp-108h] BYREF
char s[80]; // [rsp+30h] [rbp-E8h] BYREF
char v9; // [rsp+80h] [rbp-98h] BYREF

v6[0] = (__int64)v7;
v6[1] = (__int64)&v9;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v7, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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[32]; // [rsp+10h] [rbp-288h] BYREF
char s[80]; // [rsp+30h] [rbp-268h] BYREF
char v9; // [rsp+80h] [rbp-218h] BYREF

v6[0] = (__int64)v7;
v6[1] = (__int64)&v9;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v7, 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[32]; // [rsp+10h] [rbp-288h] BYREF
char s[80]; // [rsp+30h] [rbp-268h] BYREF
char v9; // [rsp+80h] [rbp-218h] BYREF

v6[0] = (__int64)v7;
v6[1] = (__int64)&v9;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v7, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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
char v6; // [rsp+Ch] [rbp-BCh] BYREF
char v7; // [rsp+16h] [rbp-B2h] BYREF
__int64 v8[4]; // [rsp+20h] [rbp-A8h] BYREF
char v9[32]; // [rsp+40h] [rbp-88h] BYREF
char s[104]; // [rsp+60h] [rbp-68h] BYREF

v8[1] = (__int64)&v6;
v8[0] = (__int64)v9;
v8[2] = (__int64)&v7;
mystrtok(a4, 32LL, v8, 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
char v6; // [rsp+Ch] [rbp-BCh] BYREF
char v7; // [rsp+16h] [rbp-B2h] BYREF
__int64 v8[4]; // [rsp+20h] [rbp-A8h] BYREF
char v9[32]; // [rsp+40h] [rbp-88h] BYREF
char s[104]; // [rsp+60h] [rbp-68h] BYREF

v8[1] = (__int64)&v6;
v8[0] = (__int64)v9;
v8[2] = (__int64)&v7;
mystrtok(a4, 32LL, v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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; // [rsp+0h] [rbp-148h] BYREF
__int64 v7[4]; // [rsp+20h] [rbp-128h] BYREF
char v8[32]; // [rsp+40h] [rbp-108h] BYREF
char s[80]; // [rsp+60h] [rbp-E8h] BYREF
char v10; // [rsp+B0h] [rbp-98h] BYREF

v7[1] = (__int64)&v6;
v7[0] = (__int64)v8;
v7[2] = (__int64)&v10;
mystrtok(a4, 32LL, v7, 3LL);
snprintf(s, 0x4FuLL, "%s %s", v8, 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[32]; // [rsp+10h] [rbp-108h] BYREF
char s[80]; // [rsp+30h] [rbp-E8h] BYREF
char v9; // [rsp+80h] [rbp-98h] BYREF

v6[0] = (__int64)v7;
v6[1] = (__int64)&v9;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v7, 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[32]; // [rsp+10h] [rbp-108h] BYREF
char s[80]; // [rsp+30h] [rbp-E8h] BYREF
char v9; // [rsp+80h] [rbp-98h] BYREF

v6[0] = (__int64)v7;
v6[1] = (__int64)&v9;
mystrtok(a4, 32LL, v6, 2LL);
snprintf(s, 0x4FuLL, "%s %s", v7, 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++;
 }
}


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

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

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

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

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 *v5; // rax

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

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

v3 = af_table;
if ( !af_table )
return 4294967294LL;
v4 = &af_table;
while ( strcmp(v3, s2) )
{
v3 = v4[2];
v4 += 2;
if ( !v3 )
return 4294967294LL;
}
v5 = (char *)register_fun((__int64)v4[1], a2);
v4[1] = v5;
return (unsigned int)-(v5 == 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; // er12
__int64 result; // rax
unsigned int v7; // er12

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

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

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

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
_BYTE v7[32]; // [rsp+0h] [rbp-2A8h] BYREF
char v8[32]; // [rsp+20h] [rbp-288h] BYREF
char s2[32]; // [rsp+40h] [rbp-268h] BYREF
__int64 v10[4]; // [rsp+60h] [rbp-248h] BYREF
char v11[552]; // [rsp+80h] [rbp-228h] BYREF

v10[1] = (__int64)v7;
v10[0] = (__int64)v8;
v10[2] = (__int64)s2;
v10[3] = (__int64)v11;
if ( (int)mystrtok(a2, 32LL, v10, 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;
v3 = v4[2];
v4 += 2;
if ( !v3 )
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 *, _BYTE *, char *))i)(a1, v8, v7, v11);
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
_BYTE v7[32]; // [rsp+0h] [rbp-2A8h] BYREF
char v8[32]; // [rsp+20h] [rbp-288h] BYREF
char s2[32]; // [rsp+40h] [rbp-268h] BYREF
__int64 v10[4]; // [rsp+60h] [rbp-248h] BYREF
char v11[552]; // [rsp+80h] [rbp-228h] BYREF

v10[1] = (__int64)v7;
v10[0] = (__int64)v8;
v10[2] = (__int64)s2;
v10[3] = (__int64)v11;
if ( (int)mystrtok(a2, 32LL, v10, 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;
v3 = v4[2];
v4 += 2;
if ( !v3 )
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 *, _BYTE *, char *))i)(a1, v8, v7, v11);
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; // r14
char v8; // [rsp+6h] [rbp-62h] BYREF
__int64 v9[2]; // [rsp+10h] [rbp-58h] BYREF
char v10[72]; // [rsp+20h] [rbp-48h] BYREF

v9[0] = (__int64)v10;
v9[1] = (__int64)&v8;
mystrtok(a4, 32LL, v9, 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; // r14
char v8; // [rsp+6h] [rbp-62h] BYREF
__int64 v9[2]; // [rsp+10h] [rbp-58h] BYREF
char v10[72]; // [rsp+20h] [rbp-48h] BYREF

v9[0] = (__int64)v10;
v9[1] = (__int64)&v8;
mystrtok(a4, 32LL, v9, 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()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 v2; // rbx
const char *v3; // r13
char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // rax
__int64 v8; // r13

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

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

v0 = *(int *)(brdshm + 460800LL);
if ( (int)v0 > 0 )
{
v1 = 576 * v0;
v2 = 0LL;
do
{
v3 = (const char *)(v2 + bcache);
if ( *(_BYTE *)(v2 + bcache) )
{
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);
*((_QWORD *)v5 + 10) = v6;
if ( !v6 )
{
errlog("boardstat2.c:%s line %d Can't malloc value in board_init!", "bu_init", 116LL);
exit(-1);
}
v7 = strcpy(v6, v5);
snprintf(v7 + 20, 0x50uLL, "%s", (const char *)(v2 + bcache + 24));
v8 = *((_QWORD *)v5 + 10);
*(_DWORD *)(v8 + 5516) = boardnoread(v2 + bcache);
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

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

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

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

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
__int64 v3; // rbx
int v4; // er13
FILE *v5; // rcx
__int64 v6; // rbx
time_t v7[38]; // [rsp+0h] [rbp-288h] BYREF
char ptr[4]; // [rsp+130h] [rbp-158h] BYREF
__pid_t pid; // [rsp+134h] [rbp-154h]
char s1[31]; // [rsp+138h] [rbp-150h] BYREF
char v11[305]; // [rsp+157h] [rbp-131h] BYREF

if ( !yftpdutmp )
return 0xFFFFFFFFLL;
memset(v7, 0, sizeof(v7));
HIDWORD(v7[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(v7[0]) = 1;
v3 = 0LL;
v4 = 0;
strncpy((char *)&v7[1], &user, 0x1FuLL);
strncpy((char *)&v7[4] + 7, remotehostname, 0x100uLL);
rewind(yftpdutmp);
LABEL_7:
v5 = yftpdutmp;
do
{
if ( !fread(ptr, 0x130uLL, 1uLL, v5) )
break;
if ( !ptr[0] || kill(pid, 0) < 0 )
goto LABEL_7;
if ( !isanonymous && !strncmp(s1, (const char *)&v7[1], 0x1FuLL)
|| !strncmp(v11, (const char *)&v7[4] + 7, 0x100uLL) )
{
if ( v4 == 1 )
{
flock(v1, 8);
close(v1);
return 4294967294LL;
}
v4 = 1;
}
++v3;
v5 = yftpdutmp;
}
while ( v3 <= 59 );
v6 = 0LL;
rewind(yftpdutmp);
do
{
if ( !fread(ptr, 0x130uLL, 1uLL, yftpdutmp) || !ptr[0] || kill(pid, 0) < 0 )
{
yftpdutmp_offset = 304 * v6;
goto LABEL_5;
}
++v6;
}
while ( v6 != 60 );
flock(v1, 8);
close(v1);
result = 4294967293LL;
}
else
{
LOBYTE(v7[0]) = 0;
LABEL_5:
time(&v7[37]);
fseek(yftpdutmp, yftpdutmp_offset, 0);
fwrite(v7, 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
__int64 v3; // rbx
int v4; // er13
FILE *v5; // rcx
__int64 v6; // rbx
time_t v7[38]; // [rsp+0h] [rbp-288h] BYREF
char ptr[4]; // [rsp+130h] [rbp-158h] BYREF
__pid_t pid; // [rsp+134h] [rbp-154h]
char s1[31]; // [rsp+138h] [rbp-150h] BYREF
char v11[305]; // [rsp+157h] [rbp-131h] BYREF

if ( !yftpdutmp )
return 0xFFFFFFFFLL;
memset(v7, 0, sizeof(v7));
HIDWORD(v7[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(v7[0]) = 1;
v3 = 0LL;
v4 = 0;
strncpy((char *)&v7[1], &user, 0x1FuLL);
strncpy((char *)&v7[4] + 7, remotehostname, 0x100uLL);
rewind(yftpdutmp);
LABEL_7:
v5 = yftpdutmp;
do
{
if ( !fread(ptr, 0x130uLL, 1uLL, v5) )
break;
if ( !ptr[0] || kill(pid, 0) < 0 )
goto LABEL_7;
if ( !isanonymous && !strncmp(s1, (const char *)&v7[1], 0x1FuLL)
|| !strncmp(v11, (const char *)&v7[4] + 7, 0x100uLL) )
{
if ( v4 == 1 )
{
flock(v1, 8);
close(v1);
return 4294967294LL;
}
v4 = 1;
}
++v3;
v5 = yftpdutmp;
}
while ( v3 <= 59 );
v6 = 0LL;
rewind(yftpdutmp);
do
{
if ( !fread(ptr, 0x130uLL, 1uLL, yftpdutmp) || !ptr[0] || kill(pid, 0) < 0 )
{
yftpdutmp_offset = 304 * v6;
goto LABEL_5;
}
++v6;
}
while ( v6 != 60 );
flock(v1, 8);
close(v1);
result = 4294967293LL;
}
else
{
LOBYTE(v7[0]) = 0;
LABEL_5:
time(&v7[37]);
fseek(yftpdutmp, yftpdutmp_offset, 0);
fwrite(v7, 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()
{
FILE *v0; // rdi
int result; // eax

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

canonical_decompiled_code:
int func2()
{
FILE *v0; // rdi
int result; // eax

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

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