decompiled_code:
int __fastcall pole_kola(double a1)
{
podaj("r");
return printf(aPoleKo, 3.141592653589793 * a1 * a1);
}

canonical_decompiled_code:
int __fastcall func9(double a1)
{
func7("r");
return printf(aPoleKo, 3.141592653589793 * a1 * a1);
}

variable_types: r double


decompiled_code:
int __fastcall pole_trojkata(double a1)
{
podaj("a");
podaj("h");
return printf(aPoleTr, a1 * 0.5 * a1);
}

canonical_decompiled_code:
int __fastcall func10(double a1)
{
func7("a");
func7("h");
return printf(aPoleTr, a1 * 0.5 * a1);
}

original_code:
void pole_trojkata()
{
  double a = podaj("a");
  double h = podaj("h");
  printf("Pole trójkąta wynosi: %f\n", 0.5*a*h);
}

variable_types: a double

variable_types: h double

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
char i; // al
char v5; // [rsp+Fh] [rbp-9h] BYREF

while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v5 = 10;
puts(&s);
puts(aSiemankoCoChce);
puts(a1PoleProstok);
puts(a2PoleKo);
puts(a3PoleTr);
puts(a4Chc);
v3 = "> ";
printf("> ");
for ( i = v5; v5 == 10; i = v5 )
{
argv = (const char **)&v5;
v3 = "%c";
__isoc99_scanf();
}
if ( i != 51 )
break;
pole_trojkata(v3, argv);
}
if ( i <= 51 )
break;
if ( i == 52 )
{
puts("Do zobaczyska!");
exit(0);
}
LABEL_11:
puts("Nie kumam. Wybierz jeszcze raz.");
}
if ( i == 49 )
{
pole_prostokata(v3, argv);
}
else
{
if ( i != 50 )
goto LABEL_11;
pole_kola(v3, argv);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
char i; // al
char v5; // [rsp+Fh] [rbp-9h] BYREF

while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v5 = 10;
puts(&s);
puts(aSiemankoCoChce);
puts(a1PoleProstok);
puts(a2PoleKo);
puts(a3PoleTr);
puts(a4Chc);
v3 = "> ";
printf("> ");
for ( i = v5; v5 == 10; i = v5 )
{
argv = (const char **)&v5;
v3 = "%c";
__isoc99_scanf();
}
if ( i != 51 )
break;
func10(v3, argv);
}
if ( i <= 51 )
break;
if ( i == 52 )
{
puts("Do zobaczyska!");
exit(0);
}
LABEL_11:
puts("Nie kumam. Wybierz jeszcze raz.");
}
if ( i == 49 )
{
func8(v3, argv);
}
else
{
if ( i != 50 )
goto LABEL_11;
func9(v3, argv);
}
}
}

original_code:
int main(void)
{
  for (;;) {
    char selection = '\n';
    puts("");
    puts("Siemanko. Co chcesz obliczyć?");
    puts("  1. Pole prostokąta");
    puts("  2. Pole koła");
    puts("  3. Pole trójkąta");
    puts("  4. Chcę wyjść z programu");
    printf("> ");
    while (selection == '\n')
      scanf("%c", &selection);
    switch (selection) {
    case '1':
      pole_prostokata();
      break;
    case '2':
      pole_kola();
      break;
    case '3':
      pole_trojkata();
      break;
    case '4':
      puts("Do zobaczyska!");
      exit(0);
    default:
      puts("Nie kumam. Wybierz jeszcze raz.");
      break;
    }
  }
  return 0;
}

canonical_original_code:
int main()
{
  for (;;) {
    char selection = '\n';
    puts("");
    puts("Siemanko. Co chcesz obliczyć?");
    puts("  1. Pole prostokąta");
    puts("  2. Pole koła");
    puts("  3. Pole trójkąta");
    puts("  4. Chcę wyjść z programu");
    printf("> ");
    while (selection == '\n')
      scanf("%c", &selection);
    switch (selection) {
    case '1':
      pole_prostokata();
      break;
    case '2':
      pole_kola();
      break;
    case '3':
      pole_trojkata();
      break;
    case '4':
      puts("Do zobaczyska!");
      exit(0);
    default:
      puts("Nie kumam. Wybierz jeszcze raz.");
      break;
    }
  }
  return 0;
}

variable_types: selection char

return_type: int


podaj

decompiled_code:
double podaj()
{
double v1; // [rsp+10h] [rbp-10h]
char v2; // [rsp+1Fh] [rbp-1h]

do
{
v2 = 0;
std::operator<<<char>();
std::istream::operator>>();
if ( (unsigned __int8)std::ios::fail() )
{
v2 = 1;
std::ios::clear();
std::istream::ignore((std::istream *)&std::cin, 80LL, 10);
}
else if ( v1 <= 0.0 )
{
v2 = 1;
}
if ( v2 )
std::operator<<<std::char_traits<char>>();
}
while ( v2 );
return v1;
}

canonical_decompiled_code:
double func7()
{
double v1; // [rsp+10h] [rbp-10h]
char v2; // [rsp+1Fh] [rbp-1h]

do
{
v2 = 0;
std::operator<<<char>();
std::istream::operator>>();
if ( (unsigned __int8)std::ios::fail() )
{
v2 = 1;
std::ios::clear();
std::istream::ignore((std::istream *)&std::cin, 80LL, 10);
}
else if ( v1 <= 0.0 )
{
v2 = 1;
}
if ( v2 )
std::operator<<<std::char_traits<char>>();
}
while ( v2 );
return v1;
}

original_code:
double podaj(char *nazwa)
{
  int poprawnie_odczytane = 0;
  double wartosc;
  do {
    printf("Podaj %s: ", nazwa);
    poprawnie_odczytane = scanf("%lf", &wartosc);
    getchar();
  } while (poprawnie_odczytane != 1 || wartosc <= 0);
  return wartosc;
}

variable_types:
nazwa
char *

variable_types: wartosc double

return_type: double


decompiled_code:
__int64 pole_prostokata(void)
{
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
podaj();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
podaj();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
return std::ostream::operator<<();
}

canonical_decompiled_code:
__int64 func8(void)
{
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
func7();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
func7();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
return std::ostream::operator<<();
}

original_code:
void pole_prostokata()
{
  double a = podaj("a");
  double b = podaj("b");
  printf("Pole prostokąta wynosi: %f\n", a*b);
}

variable_types: b double


decompiled_code:
__int64 pole_kola(void)
{
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
podaj();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
return std::ostream::operator<<();
}

canonical_decompiled_code:
__int64 func9(void)
{
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
func7();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
return std::ostream::operator<<();
}


decompiled_code:
__int64 pole_trojkata(void)
{
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
podaj();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
podaj();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
return std::ostream::operator<<();
}

canonical_decompiled_code:
__int64 func10(void)
{
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
func7();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
func7();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
return std::ostream::operator<<();
}

canonical_original_code:
void pole_trojkata()
{
  double a = podaj("a");
  double h = podaj("h");
  printf("Pole trójkąta wynosi: %f\n", 0.5*a*h);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3[43]; // [rsp+0h] [rbp-40h] BYREF
int v4; // [rsp+2Ch] [rbp-14h]

while ( 1 )
{
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
v4 = (int)podaj(v3, &unk_40208C);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
if ( v4 == 4 )
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
exit(0);
}
if ( v4 > 4 )
{
LABEL_11:
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
}
else
{
switch ( v4 )
{
case 3:
pole_trojkata();
break;
case 1:
pole_prostokata();
break;
case 2:
pole_kola();
break;
default:
goto LABEL_11;
}
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3[43]; // [rsp+0h] [rbp-40h] BYREF
int v4; // [rsp+2Ch] [rbp-14h]

while ( 1 )
{
std::ostream::operator<<();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
std::allocator<char>::allocator();
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string();
v4 = (int)func7(v3, &unk_40208C);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string();
std::allocator<char>::~allocator();
if ( v4 == 4 )
{
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
exit(0);
}
if ( v4 > 4 )
{
LABEL_11:
std::operator<<<std::char_traits<char>>();
std::ostream::operator<<();
}
else
{
switch ( v4 )
{
case 3:
func10();
break;
case 1:
func8();
break;
case 2:
func9();
break;
default:
goto LABEL_11;
}
}
}
}


repo: kadavris/aps-toolkit

decompiled_code:
__int64 __fastcall ap_net_set_str_addr(unsigned int a1, _WORD *a2, const char *a3, __int64 a4, __int64 a5)
{
void *v6; // rdx
int v7; // er9
int v8; // er8
__int64 result; // rax

if ( a1 != 10 )
{
if ( a1 != 2 )
{
ap_error_set_custom("ap_net_set_str_addr()", "bad address family: %d", a1);
return 0LL;
}
if ( (unsigned int)a4 > 0xF )
{
*a2 = 2;
a2[1] = _bswap_16(a5);
goto LABEL_5;
}
LABEL_10:
ap_error_set_custom("ap_net_set_str_addr()", "bad address buffer length", a3, a4, a5, a1);
return 0LL;
}
if ( (unsigned int)a4 <= 0x1B )
goto LABEL_10;
*a2 = 10;
a2[1] = _bswap_16(a5);
LABEL_5:
v8 = inet_pton(v7, a3, v6);
result = 1LL;
if ( v8 == -1 )
{
ap_error_set_custom("ap_net_set_str_addr()", "bad address: %s", a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, _WORD *a2, const char *a3, __int64 a4, __int64 a5)
{
void *v6; // rdx
int v7; // er9
int v8; // er8
__int64 result; // rax

if ( a1 != 10 )
{
if ( a1 != 2 )
{
ap_error_set_custom("ap_net_set_str_addr()", "bad address family: %d", a1);
return 0LL;
}
if ( (unsigned int)a4 > 0xF )
{
*a2 = 2;
a2[1] = func0(a5);
goto LABEL_5;
}
LABEL_10:
ap_error_set_custom("ap_net_set_str_addr()", "bad address buffer length", a3, a4, a5, a1);
return 0LL;
}
if ( (unsigned int)a4 <= 0x1B )
goto LABEL_10;
*a2 = 10;
a2[1] = func0(a5);
LABEL_5:
v8 = inet_pton(v7, a3, v6);
result = 1LL;
if ( v8 == -1 )
{
ap_error_set_custom("ap_net_set_str_addr()", "bad address: %s", a3);
result = 0LL;
}
return result;
}

original_code:
int ap_net_set_str_addr(int af, void *destination, const char *address_str, socklen_t addr_len, int port)
{
 const char *_func_name = "ap_net_set_str_addr()";
    if ( af == 10 )
    {
     if ( addr_len < sizeof(struct sockaddr_in6))
     {
      ap_error_set_custom(_func_name, (char*)err_bad_buf_len);
            return 0;
     }
     ((struct sockaddr_in6 *)destination)->sin6_family = 10;
     ((struct sockaddr_in6 *)destination)->sin6_port = htons(port);
     destination = &(((struct sockaddr_in6 *)destination)->sin6_addr);
    }
    else if ( af == 2 )
    {
     if ( addr_len < sizeof(struct sockaddr_in))
     {
      ap_error_set_custom(_func_name, (char*)err_bad_buf_len);
            return 0;
     }
     ((struct sockaddr_in *)destination)->sin_family = 2;
     ((struct sockaddr_in *)destination)->sin_port = htons(port);
     destination = &(((struct sockaddr_in *)destination)->sin_addr);
    }
    else
    {
        ap_error_set_custom(_func_name, "bad address family: %d", af);
        return 0;
    }
    if ( -1 == inet_pton(af, address_str, destination) )
    {
         ap_error_set_custom(_func_name, "bad address: %s", address_str);
         return 0;
    }
    return 1;
}

canonical_original_code:
int ap_net_set_str_addr(int af, void *destination, char *address_str, unsigned int addr_len, int port)
{
 char *_func_name = "ap_net_set_str_addr()";
    if ( af == 10 )
    {
     if ( addr_len < sizeof(struct sockaddr_in6))
     {
      ap_error_set_custom(_func_name, (char *)err_bad_buf_len);
            return 0;
     }
     ((struct sockaddr_in6 *)destination)->sin6_family = 10;
     ((struct sockaddr_in6 *)destination)->sin6_port = htons(port);
     destination = &(((struct sockaddr_in6 *)destination)->sin6_addr);
    }
    else if ( af == 2 )
    {
     if ( addr_len < sizeof(struct sockaddr_in))
     {
      ap_error_set_custom(_func_name, (char *)err_bad_buf_len);
            return 0;
     }
     ((struct sockaddr_in *)destination)->sin_family = 2;
     ((struct sockaddr_in *)destination)->sin_port = htons(port);
     destination = &(((struct sockaddr_in *)destination)->sin_addr);
    }
    else
    {
        ap_error_set_custom(_func_name, "bad address family: %d", af);
        return 0;
    }
    if ( -1 == inet_pton(af, address_str, destination) )
    {
         ap_error_set_custom(_func_name, "bad address: %s", address_str);
         return 0;
    }
    return 1;
}

variable_types: af int

variable_types:
destination
void *

variable_types: port int

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

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

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall ap_net_set_ip4_addr(_WORD *a1, unsigned int a2, __int64 a3)
{
__int16 v3; // ax
__int64 v4; // rcx
int v5; // eax
__int64 v6; // rcx
__int64 result; // rax

if ( (unsigned int)(a3 - 1) > 0xFFFE )
{
ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", "bad port: %d", a3);
result = 0LL;
}
else
{
*a1 = 2;
v3 = _bswap_16(a3);
*(_WORD *)(v4 + 2) = v3;
v5 = _bswap_32(a2);
*(_DWORD *)(v6 + 4) = v5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_WORD *a1, unsigned int a2, __int64 a3)
{
__int16 v3; // ax
__int64 v4; // rcx
int v5; // eax
__int64 v6; // rcx
__int64 result; // rax

if ( (unsigned int)(a3 - 1) > 0xFFFE )
{
ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", "bad port: %d", a3);
result = 0LL;
}
else
{
*a1 = 2;
v3 = func0(a3);
*(_WORD *)(v4 + 2) = v3;
v5 = func1(a2);
*(_DWORD *)(v6 + 4) = v5;
result = 1LL;
}
return result;
}

original_code:
int ap_net_set_ip4_addr(struct sockaddr_in *destination, in_addr_t address4, int port)
{
 if ( port <= 0 || port > 65535 )
    {
         ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", (char*)err_bad_port, port);
         return 0;
    }
 destination->sin_family = 2;
 destination->sin_port = htons(port);
 destination->sin_addr.s_addr = htonl(address4);
    return 1;
}

canonical_original_code:
int ap_net_set_ip4_addr(struct sockaddr_in *destination, unsigned int address4, int port)
{
 if ( port <= 0 || port > 65535 )
    {
         ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", (char *)err_bad_port, port);
         return 0;
    }
 destination->sin_family = 2;
 destination->sin_port = htons(port);
 destination->sin_addr.s_addr = htonl(address4);
    return 1;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *


decompiled_code:
__int64 __fastcall ap_net_set_ip6_addr(_WORD *a1, const __m128i *a2, __int64 a3)
{
__int16 v3; // ax
__int64 v4; // rcx
__int64 result; // rax

if ( (unsigned int)(a3 - 1) > 0xFFFE )
{
ap_error_set_custom("ap_net_conn_pool_set_ip6_addr()", "bad port: %d", a3);
result = 0LL;
}
else
{
*a1 = 10;
v3 = _bswap_16(a3);
*(_WORD *)(v4 + 2) = v3;
result = 1LL;
*(__m128i *)(v4 + 8) = _mm_loadu_si128(a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_WORD *a1, const __m128i *a2, __int64 a3)
{
__int16 v3; // ax
__int64 v4; // rcx
__int64 result; // rax

if ( (unsigned int)(a3 - 1) > 0xFFFE )
{
ap_error_set_custom("ap_net_conn_pool_set_ip6_addr()", "bad port: %d", a3);
result = 0LL;
}
else
{
*a1 = 10;
v3 = func0(a3);
*(_WORD *)(v4 + 2) = v3;
result = 1LL;
*(__m128i *)(v4 + 8) = _mm_loadu_si128(a2);
}
return result;
}

original_code:
int ap_net_set_ip6_addr(struct sockaddr_in6 *destination, struct in6_addr *address6, int port)
{
 if ( port <= 0 || port > 65535 )
    {
         ap_error_set_custom("ap_net_conn_pool_set_ip6_addr()", (char*)err_bad_port, port);
         return 0;
    }
 destination->sin6_family = 10;
    destination->sin6_port = htons(port);
    memcpy(&destination->sin6_addr, address6, sizeof(struct in6_addr));
    return 1;
}

canonical_original_code:
int ap_net_set_ip6_addr(struct sockaddr_in6 *destination, struct in6_addr *address6, int port)
{
 if ( port <= 0 || port > 65535 )
    {
         ap_error_set_custom("ap_net_conn_pool_set_ip6_addr()", (char *)err_bad_port, port);
         return 0;
    }
 destination->sin6_family = 10;
    destination->sin6_port = htons(port);
    memcpy(&destination->sin6_addr, address6, sizeof(struct in6_addr));
    return 1;
}

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *


decompiled_code:
__int64 __fastcall ap_net_conn_pool_set_str_addr(__int64 a1, const char *a2, unsigned int a3)
{
return ap_net_set_str_addr(
(*(_DWORD *)(a1 + 16) & 4) == 0 ? 2 : 10,
(_WORD *)(a1 + 52),
a2,
(*(_DWORD *)(a1 + 16) & 4) == 0 ? 16 : 28,
a3);
}

original_code:
int ap_net_conn_pool_set_str_addr(struct ap_net_conn_pool_t *pool, const char *address_str, int port)
{
    int ip6;
    ip6 = (((pool->flags) & (4)) != 0);
    return ap_net_set_str_addr( (ip6 ? 10 : 2), (ip6 ? (void*)&pool->listener.addr6 : (void*)&pool->listener.addr4),
                                 address_str, (ip6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)), port);
}

canonical_original_code:
int ap_net_conn_pool_set_str_addr(struct ap_net_conn_pool_t *pool, char *address_str, int port)
{
    int ip6;
    ip6 = (((pool->flags) & (4)) != 0);
    return ap_net_set_str_addr( (ip6 ? 10 : 2), (ip6 ? (void *)&pool->listener.addr6 : (void *)&pool->listener.addr4),
                                 address_str, (ip6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)), port);
}

variable_types: struct ap_net_conn_pool_t { struct ap_net_connection_t { struct ap_net_conn_pool_t *parent; int idx; int fd; unsigned int flags; union { unsigned short af; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec { long tv_sec; long tv_nsec; } created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *poller; struct timespec max_conn_ttl; struct { int sock; union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *

user_defined_types: struct ap_net_conn_pool_t { struct ap_net_connection_t *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t *poller; struct timespec max_conn_ttl; struct { int sock; union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t stat; }

user_defined_types: struct ap_net_connection_t { struct ap_net_conn_pool_t *parent; int idx; int fd; unsigned int flags; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; }

user_defined_types: struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; }

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


decompiled_code:
__int64 __fastcall ap_net_conn_pool_set_ip4_addr(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (*(_BYTE *)(a1 + 16) & 4) == 0 )
return ap_net_set_ip4_addr((_WORD *)(a1 + 52), a2, a3);
ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", "Pool is set to IPv6 mode");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (*(_BYTE *)(a1 + 16) & 4) == 0 )
return func3((_WORD *)(a1 + 52), a2, a3);
ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", "Pool is set to IPv6 mode");
return 0LL;
}

original_code:
int ap_net_conn_pool_set_ip4_addr(struct ap_net_conn_pool_t *pool, in_addr_t address4, int port)
{
    if ( (((pool->flags) & (4)) != 0) )
    {
        ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", "Pool is set to IPv6 mode");
        return 0;
    }
    return ap_net_set_ip4_addr(&pool->listener.addr4, address4, port);
}

canonical_original_code:
int ap_net_conn_pool_set_ip4_addr(struct ap_net_conn_pool_t *pool, unsigned int address4, int port)
{
    if ( (((pool->flags) & (4)) != 0) )
    {
        ap_error_set_custom("ap_net_conn_pool_set_ip4_addr()", "Pool is set to IPv6 mode");
        return 0;
    }
    return ap_net_set_ip4_addr(&pool->listener.addr4, address4, port);
}

user_defined_types: struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }


decompiled_code:
__int64 __fastcall ap_net_conn_pool_set_ip6_addr(__int64 a1, const __m128i *a2, __int64 a3)
{
if ( (*(_BYTE *)(a1 + 16) & 4) != 0 )
return ap_net_set_ip6_addr((_WORD *)(a1 + 52), a2, a3);
ap_error_set_custom("ap_net_conn_pool_set_ip6_addr()", "Pool is set to IPv4 mode");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const __m128i *a2, __int64 a3)
{
if ( (*(_BYTE *)(a1 + 16) & 4) != 0 )
return func4((_WORD *)(a1 + 52), a2, a3);
ap_error_set_custom("ap_net_conn_pool_set_ip6_addr()", "Pool is set to IPv4 mode");
return 0LL;
}

original_code:
int ap_net_conn_pool_set_ip6_addr(struct ap_net_conn_pool_t *pool, struct in6_addr *address6, int port)
{
    if ( ! (((pool->flags) & (4)) != 0) )
    {
        ap_error_set_custom("ap_net_conn_pool_set_ip6_addr()", "Pool is set to IPv4 mode");
        return 0;
    }
    return ap_net_set_ip6_addr(&pool->listener.addr6, address6, port);
}


decompiled_code:
__int64 __fastcall ap_str_makestr(void **a1, const char *a2)
{
void *v3; // rdi
size_t v4; // rax
char *v5; // rax

v3 = *a1;
if ( v3 )
free(v3);
*a1 = 0LL;
if ( !a2 )
return 0LL;
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
*a1 = v5;
if ( !v5 )
return 0LL;
strcpy(v5, a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void **a1, const char *a2)
{
void *v3; // rdi
size_t v4; // rax
char *v5; // rax

v3 = *a1;
if ( v3 )
free(v3);
*a1 = 0LL;
if ( !a2 )
return 0LL;
v4 = strlen(a2);
v5 = (char *)malloc(v4 + 1);
*a1 = v5;
if ( !v5 )
return 0LL;
strcpy(v5, a2);
return 1LL;
}

original_code:
int ap_str_makestr(char **d, const char *s)
{
    if ( *d != ((void *)0) )
        free(*d);
    *d = ((void *)0);
    if ( s == ((void *)0) )
        return 0;
    if ( ((void *)0) == (*d = (char*)malloc(strlen(s) + 1) ) )
        return 0;
    strcpy( (char*)(*d), s );
    return 1;
}

canonical_original_code:
int ap_str_makestr(char **d, char *s)
{
    if ( *d != ((void *)0) )
        free(*d);
    *d = ((void *)0);
    if ( s == ((void *)0) )
        return 0;
    if ( ((void *)0) == (*d = (char *)malloc(strlen(s) + 1) ) )
        return 0;
    strcpy( (char *)(*d), s );
    return 1;
}

variable_types:
d
char **

variable_types:
s
char *


decompiled_code:
void *__fastcall ap_str_getmem(int a1, __int64 a2)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a2 )
ap_log_do_syslog(3LL, a2);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1, __int64 a2)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
if ( a2 )
ap_log_do_syslog(3LL, a2);
exit(1);
}
return result;
}

original_code:
void *ap_str_getmem(int size, char *errmsg)
{
    void *ptr;
    ptr = malloc(size);
    if ( ptr == ((void *)0) )
    {
        if (errmsg != ((void *)0))
            ap_log_do_syslog(3, errmsg);
        exit(1);
    }
    return ptr;
}

variable_types: size int

variable_types:
errmsg
char *

variable_types:
ptr
void *

return_type: void *


decompiled_code:
__int64 __fastcall ap_str_fix_buf_size(void **a1, _DWORD *a2, int *a3, int a4)
{
unsigned int v4; // er12
int v5; // edx
int v7; // ebp

v4 = 1;
v5 = *a3;
if ( *a2 - v5 >= a4 )
return v4;
v7 = v5 + a4;
if ( !realloc(*a1, v5 + a4) )
return 0;
*a2 = v7;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void **a1, _DWORD *a2, int *a3, int a4)
{
unsigned int v4; // er12
int v5; // edx
int v7; // ebp

v4 = 1;
v5 = *a3;
if ( *a2 - v5 >= a4 )
return v4;
v7 = v5 + a4;
if ( !realloc(*a1, v5 + a4) )
return 0;
*a2 = v7;
return 1LL;
}

original_code:
int ap_str_fix_buf_size(char **dst_buf, int *dst_buf_size, int *dst_buf_pos, int need_bytes)
{
    int n;
    if ( *dst_buf_size - *dst_buf_pos < need_bytes )
    {
        n = *dst_buf_size + need_bytes - (*dst_buf_size - *dst_buf_pos);
        if ( ((void *)0) == realloc(*dst_buf, n) )
            return 0;
        *dst_buf_size = n;
    }
    return 1;
}

variable_types: n int


decompiled_code:
__int64 __fastcall ap_str_put_to_buf(void **a1, _DWORD *a2, int *a3, const void *a4, int a5)
{
__int64 result; // rax

result = ap_str_fix_buf_size(a1, a2, a3, a5);
if ( (_DWORD)result )
{
memcpy((char *)*a1 + *a3, a4, a5);
*a3 += a5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void **a1, _DWORD *a2, int *a3, const void *a4, int a5)
{
__int64 result; // rax

result = func2(a1, a2, a3, a5);
if ( (_DWORD)result )
{
memcpy((char *)*a1 + *a3, a4, a5);
*a3 += a5;
result = 1LL;
}
return result;
}

original_code:
int ap_str_put_to_buf(char **dst_buf, int *dst_buf_size, int *dst_buf_fill, void *src_buf, int src_len)
{
    if ( ! ap_str_fix_buf_size(dst_buf, dst_buf_size, dst_buf_fill, src_len) )
        return 0;
    memcpy(*dst_buf + *dst_buf_fill, src_buf, src_len);
    *dst_buf_fill += src_len;
    return 1;
}


decompiled_code:
void **__fastcall ap_str_parse_init(void *src, const char *a2)
{
const char *v2; // rbp
void **v3; // rax
void **v4; // r12
size_t v5; // rbp
void *v6; // rax
void *v7; // rax
const char *v8; // rsi

v2 = a2;
v3 = (void **)malloc(0x28uLL);
v4 = v3;
if ( !v3 )
return v4;
v3[4] = 0LL;
if ( !a2 )
v2 = (const char *)&unk_39B;
if ( (unsigned int)ap_str_makestr(v3 + 4, v2) )
{
v5 = strlen((const char *)src);
*((_DWORD *)v4 + 4) = v5 + 1;
v6 = malloc((int)v5 + 1);
*v4 = v6;
if ( v6 )
{
v7 = memcpy(v6, src, v5 + 1);
v8 = (const char *)v4[4];
v4[1] = v7;
v4[3] = strsep((char **)v4 + 1, v8);
return v4;
}
}
free(v4);
return 0LL;
}

canonical_decompiled_code:
void **__fastcall func4(void *src, const char *a2)
{
const char *v2; // rbp
void **v3; // rax
void **v4; // r12
size_t v5; // rbp
void *v6; // rax
void *v7; // rax
const char *v8; // rsi

v2 = a2;
v3 = (void **)malloc(0x28uLL);
v4 = v3;
if ( !v3 )
return v4;
v3[4] = 0LL;
if ( !a2 )
v2 = (const char *)&unk_39B;
if ( (unsigned int)func0(v3 + 4, v2) )
{
v5 = strlen((const char *)src);
*((_DWORD *)v4 + 4) = v5 + 1;
v6 = malloc((int)v5 + 1);
*v4 = v6;
if ( v6 )
{
v7 = memcpy(v6, src, v5 + 1);
v8 = (const char *)v4[4];
v4[1] = v7;
v4[3] = strsep((char **)v4 + 1, v8);
return v4;
}
}
free(v4);
return 0LL;
}

original_code:
ap_str_parse_rec_t *ap_str_parse_init(char *in_str, char *user_separators)
{
    ap_str_parse_rec_t *r;
    if( ((void *)0) == (r = malloc(sizeof(ap_str_parse_rec_t))) )
        return ((void *)0);
    r->separators = ((void *)0);
    if ( ! ap_str_makestr(&r->separators, ( user_separators != ((void *)0) ) ? user_separators : " \t" ) )
    {
        free(r);
        return ((void *)0);
    }
    r->buf_len = strlen(in_str) + 1;
    if( ((void *)0) == (r->buf = malloc(r->buf_len)) )
    {
        free(r);
        return ((void *)0);
    }
    strcpy(r->buf, in_str);
    r->buf_pos = r->buf;
    r->curr = strsep(&r->buf_pos, r->separators);
    return r;
}

canonical_original_code:
struct ap_str_parse_rec *ap_str_parse_init(char *in_str, char *user_separators)
{
    struct ap_str_parse_rec *r;
    if( ((void *)0) == (r = malloc(sizeof(ap_str_parse_rec_t))) )
        return ((void *)0);
    r->separators = ((void *)0);
    if ( ! ap_str_makestr(&r->separators, ( user_separators != ((void *)0) ) ? user_separators : " \t" ) )
    {
        free(r);
        return ((void *)0);
    }
    r->buf_len = strlen(in_str) + 1;
    if( ((void *)0) == (r->buf = malloc(r->buf_len)) )
    {
        free(r);
        return ((void *)0);
    }
    strcpy(r->buf, in_str);
    r->buf_pos = r->buf;
    r->curr = strsep(&r->buf_pos, r->separators);
    return r;
}

variable_types: struct ap_str_parse_rec { char *buf; int buf_len; char *curr; char *separators; } *


decompiled_code:
void __fastcall ap_str_parse_end(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 4));
free(ptr);
}

original_code:
void ap_str_parse_end(ap_str_parse_rec_t *r)
{
    free(r->buf);
    free(r->separators);
    free(r);
}

canonical_original_code:
void ap_str_parse_end(struct ap_str_parse_rec *r)
{
    free(r->buf);
    free(r->separators);
    free(r);
}

user_defined_types: struct ap_str_parse_rec { char *buf; int buf_len; char *curr; char *separators; }


decompiled_code:
char *__fastcall ap_str_parse_next_arg(__int64 a1)
{
char *result; // rax

result = strsep((char **)(a1 + 8), *(const char **)(a1 + 32));
*(_QWORD *)(a1 + 24) = result;
return result;
}

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

result = strsep((char **)(a1 + 8), *(const char **)(a1 + 32));
*(_QWORD *)(a1 + 24) = result;
return result;
}

original_code:
char *ap_str_parse_next_arg(ap_str_parse_rec_t *r)
{
    return (r->curr = strsep(&r->buf_pos, r->separators));
}

canonical_original_code:
char *ap_str_parse_next_arg(struct ap_str_parse_rec *r)
{
    return (r->curr = strsep(&r->buf_pos, r->separators));
}

return_type: char *


decompiled_code:
__int64 __fastcall ap_str_parse_get_remaining(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
char *ap_str_parse_get_remaining(ap_str_parse_rec_t *r)
{
    return r->buf_pos;
}

canonical_original_code:
char *ap_str_parse_get_remaining(struct ap_str_parse_rec *r)
{
    return r->buf_pos;
}


decompiled_code:
char *__fastcall ap_str_parse_rollback(__int64 a1, int a2)
{
_BYTE *v2; // rdx
_BYTE *v3; // rax

if ( a2 > 0 )
{
v2 = *(_BYTE **)a1;
while ( 1 )
{
v3 = *(_BYTE **)(a1 + 8);
if ( v3 == v2 )
return ap_str_parse_next_arg(a1);
if ( *v3 )
{
*(v3 - 1) = **(_BYTE **)(a1 + 32);
v3 = *(_BYTE **)(a1 + 8);
v2 = *(_BYTE **)a1;
if ( (unsigned __int64)v3 > *(_QWORD *)a1 )
{
while ( *v3 )
{
*(_QWORD *)(a1 + 8) = --v3;
if ( v3 == v2 )
goto LABEL_8;
}
goto LABEL_11;
}
LABEL_8:
if ( !--a2 )
return ap_str_parse_next_arg(a1);
}
else
{
if ( v3 <= v2 )
goto LABEL_8;
LABEL_11:
*(_QWORD *)(a1 + 8) = v3 + 1;
if ( !--a2 )
return ap_str_parse_next_arg(a1);
}
}
}
return *(char **)(a1 + 24);
}

original_code:
char *ap_str_parse_rollback(ap_str_parse_rec_t *r, int roll_count)
{
    if ( roll_count <= 0 )
        return r->curr;
    for(; roll_count; --roll_count)
    {
        if( r->buf_pos == r->buf )
            break;
        if ( *(r->buf_pos) )
            *(r->buf_pos - 1) = *(r->separators);
        for(; r->buf_pos > r->buf; r->buf_pos--)
        {
            if( *r->buf_pos == '\0' )
            {
                r->buf_pos++;
                break;
            }
        }
    }
    return ap_str_parse_next_arg(r);
}

canonical_original_code:
char *ap_str_parse_rollback(struct ap_str_parse_rec *r, int roll_count)
{
    if ( roll_count <= 0 )
        return r->curr;
    for(; roll_count; --roll_count)
    {
        if( r->buf_pos == r->buf )
            break;
        if ( *(r->buf_pos) )
            *(r->buf_pos - 1) = *(r->separators);
        for(; r->buf_pos > r->buf; r->buf_pos--)
        {
            if( *r->buf_pos == '\0' )
            {
                r->buf_pos++;
                break;
            }
        }
    }
    return ap_str_parse_next_arg(r);
}


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

result = *(char **)(a1 + 8);
do
{
if ( !a2 )
break;
--a2;
result = ap_str_parse_next_arg(a1);
}
while ( result );
return result;
}

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

result = *(char **)(a1 + 8);
do
{
if ( !a2 )
break;
--a2;
result = func6(a1);
}
while ( result );
return result;
}

original_code:
char *ap_str_parse_skip(ap_str_parse_rec_t *r, int skip_count)
{
    char *s;
    s = r->buf_pos;
    while( skip_count-- && ((void *)0) != (s = ap_str_parse_next_arg(r)) );
    return s;
}

canonical_original_code:
char *ap_str_parse_skip(struct ap_str_parse_rec *r, int skip_count)
{
    char *s;
    s = r->buf_pos;
    while( skip_count-- && ((void *)0) != (s = ap_str_parse_next_arg(r)) );
    return s;
}


decompiled_code:
__int64 __fastcall str_parse_set_separators(__int64 a1, const char *a2)
{
if ( !a2 )
a2 = (const char *)&unk_39B;
return ap_str_makestr((void **)(a1 + 32), a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
if ( !a2 )
a2 = (const char *)&unk_39B;
return func0((void **)(a1 + 32), a2);
}

original_code:
int str_parse_set_separators(ap_str_parse_rec_t *r, char *separators)
{
    return ap_str_makestr(&(r->separators), ( separators != ((void *)0) ) ? separators : " \t" );
}

canonical_original_code:
int str_parse_set_separators(struct ap_str_parse_rec *r, char *separators)
{
    return ap_str_makestr(&(r->separators), ( separators != ((void *)0) ) ? separators : " \t" );
}

variable_types:
separators
char *


decompiled_code:
__int64 __fastcall ap_str_parse_get_bool(__int64 a1)
{
char *v1; // rax
const char *v2; // rbp
__int64 v3; // rbx
const char *i; // rdi

v1 = ap_str_parse_next_arg(a1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = 0LL;
for ( i = (const char *)&unk_39E; strcasecmp(i, v2); i = (const char *)*(&keywords + 2 * v3) )
{
if ( ++v3 == 8 )
return 0xFFFFFFFFLL;
}
return (unsigned int)dword_3E8[4 * (int)v3];
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
char *v1; // rax
const char *v2; // rbp
__int64 v3; // rbx
const char *i; // rdi

v1 = func6(a1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = 0LL;
for ( i = (const char *)&unk_39E; strcasecmp(i, v2); i = (const char *)*(&keywords + 2 * v3) )
{
if ( ++v3 == 8 )
return 0xFFFFFFFFLL;
}
return (unsigned int)dword_3E8[4 * (int)v3];
}

original_code:
int ap_str_parse_get_bool(ap_str_parse_rec_t *r)
{
    char *s;
    int i;
    s = ap_str_parse_next_arg(r);
    if ( s == ((void *)0) )
        return -1;
    for( i = 0; i < 8; ++i )
        if ( 0 == strcasecmp(keywords[i].s, s ) )
            return keywords[i].result;
    return -1;
}

canonical_original_code:
int ap_str_parse_get_bool(struct ap_str_parse_rec *r)
{
    char *s;
    int i;
    s = ap_str_parse_next_arg(r);
    if ( s == ((void *)0) )
        return -1;
    for( i = 0; i < 8; ++i )
        if ( 0 == strcasecmp(keywords[i].s, s ) )
            return keywords[i].result;
    return -1;
}

variable_types: i int


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

v2 = _errno_location();
ap_log_err_errno = a2;
result = (unsigned int)*v2;
ap_log_err_function_name = a1;
ap_log_err_details = 0;
ap_log_syserrno = result;
return result;
}

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

v2 = _errno_location();
ap_log_err_errno = a2;
result = (unsigned int)*v2;
ap_log_err_function_name = a1;
ap_log_err_details = 0;
ap_log_syserrno = result;
return result;
}

original_code:
void ap_error_set(const char *in_function_name, int in_errno)
{
    ap_log_syserrno = (*__errno_location ());
    ap_log_err_errno = in_errno;
    ap_log_err_function_name = (char *)in_function_name;
    *ap_log_err_details = '\0';
}

canonical_original_code:
void ap_error_set(char *in_function_name, int in_errno)
{
    ap_log_syserrno = (*__errno_location ());
    ap_log_err_errno = in_errno;
    ap_log_err_function_name = (char *)in_function_name;
    *ap_log_err_details = '\0';
}


decompiled_code:
void ap_error_clear()
{
ap_log_syserrno = 0;
ap_log_err_errno = 0;
ap_log_err_function_name = (__int64)"no name is set";
ap_log_err_details = 0;
}

canonical_decompiled_code:
void func1()
{
ap_log_syserrno = 0;
ap_log_err_errno = 0;
ap_log_err_function_name = (__int64)"no name is set";
ap_log_err_details = 0;
}

original_code:
void ap_error_clear(void)
{
    ap_log_err_errno = ap_log_syserrno = 0;
    ap_log_err_function_name = "no name is set";
    *ap_log_err_details = '\0';
}

canonical_original_code:
void ap_error_clear()
{
    ap_log_err_errno = ap_log_syserrno = 0;
    ap_log_err_function_name = "no name is set";
    *ap_log_err_details = '\0';
}


decompiled_code:
__int64 ap_error_get()
{
return (unsigned int)ap_log_err_errno;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)ap_log_err_errno;
}

original_code:
int ap_error_get(void)
{
    return ap_log_err_errno;
}

canonical_original_code:
int ap_error_get()
{
    return ap_log_err_errno;
}


decompiled_code:
char *ap_error_get_string()
{
int *v0; // rax
int v1; // edi
unsigned int *v2; // rbx
int v3; // eax
unsigned int v4; // er12
int v5; // ebx
char *result; // rax
char *v7; // rax
char *v8; // rax

if ( ap_log_err_errno )
goto LABEL_4;
v0 = _errno_location();
v1 = *v0;
v2 = (unsigned int *)v0;
if ( !(ap_log_syserrno | *v0) )
{
sprintf(buf_0, ap_log_errno_strings);
return buf_0;
}
if ( v1 )
{
v8 = strerror(v1);
snprintf(
buf_0,
0x400uLL,
"There is no error recorded inside AP's_toolkit functions, but system error is: %d/'%s'. ",
*v2,
v8);
result = buf_0;
}
else
{
LABEL_4:
v3 = snprintf(buf_0, 0x400uLL, "ERROR in AP's_toolkit: in function: %s - ", (const char *)ap_log_err_function_name);
v4 = ap_log_syserrno;
v5 = v3;
if ( ap_log_syserrno )
{
v7 = strerror(ap_log_syserrno);
v5 += snprintf(&buf_0[v5], 1024 - v5, "system error: %d/'%s'. ", v4, v7);
if ( ap_log_err_details )
goto LABEL_6;
if ( ap_log_syserrno )
return buf_0;
}
else if ( ap_log_err_details )
{
LABEL_6:
strncat(&buf_0[v5], &ap_log_err_details, 1024 - v5);
return buf_0;
}
snprintf(
&buf_0[v5],
1024 - v5,
"%d/'%s'. %s",
ap_log_err_errno,
(&ap_log_errno_strings)[ap_log_err_errno],
&ap_log_err_details);
result = buf_0;
}
return result;
}

canonical_decompiled_code:
char *func3()
{
int *v0; // rax
int v1; // edi
unsigned int *v2; // rbx
int v3; // eax
unsigned int v4; // er12
int v5; // ebx
char *result; // rax
char *v7; // rax
char *v8; // rax

if ( ap_log_err_errno )
goto LABEL_4;
v0 = _errno_location();
v1 = *v0;
v2 = (unsigned int *)v0;
if ( !(ap_log_syserrno | *v0) )
{
sprintf(buf_0, ap_log_errno_strings);
return buf_0;
}
if ( v1 )
{
v8 = strerror(v1);
snprintf(
buf_0,
0x400uLL,
"There is no error recorded inside AP's_toolkit functions, but system error is: %d/'%s'. ",
*v2,
v8);
result = buf_0;
}
else
{
LABEL_4:
v3 = snprintf(buf_0, 0x400uLL, "ERROR in AP's_toolkit: in function: %s - ", (const char *)ap_log_err_function_name);
v4 = ap_log_syserrno;
v5 = v3;
if ( ap_log_syserrno )
{
v7 = strerror(ap_log_syserrno);
v5 += snprintf(&buf_0[v5], 1024 - v5, "system error: %d/'%s'. ", v4, v7);
if ( ap_log_err_details )
goto LABEL_6;
if ( ap_log_syserrno )
return buf_0;
}
else if ( ap_log_err_details )
{
LABEL_6:
strncat(&buf_0[v5], &ap_log_err_details, 1024 - v5);
return buf_0;
}
snprintf(
&buf_0[v5],
1024 - v5,
"%d/'%s'. %s",
ap_log_err_errno,
(&ap_log_errno_strings)[ap_log_err_errno],
&ap_log_err_details);
result = buf_0;
}
return result;
}

original_code:
const char *ap_error_get_string(void)
{
    static char buf[1024 + 1];
    int bufpos;
    if ( ap_log_err_errno == 0 && ap_log_syserrno == 0 && (*__errno_location ()) == 0 )
    {
     sprintf(buf, ap_log_errno_strings[ap_log_err_errno]);
     return buf;
    }
    if ( ap_log_err_errno == 0 && (*__errno_location ()) != 0 )
    {
        snprintf(buf, 1024, "There is no error recorded inside AP's_toolkit functions, but system error is: %d/'%s'. ", (*__errno_location ()), strerror((*__errno_location ())));
        return (const char *)buf;
    }
    bufpos = 0;
    bufpos += snprintf(buf + bufpos, 1024 - bufpos, "ERROR in AP's_toolkit: in function: %s - ", ap_log_err_function_name);
    if ( ap_log_syserrno )
        bufpos += snprintf(buf + bufpos, 1024 - bufpos, "system error: %d/'%s'. ", ap_log_syserrno, strerror(ap_log_syserrno));
 if ( *ap_log_err_details )
     strncat(buf + bufpos, ap_log_err_details, 1024 - bufpos);
    else if ( ! ap_log_syserrno )
     bufpos += snprintf(buf + bufpos, 1024 - bufpos, "%d/'%s'. %s", ap_log_err_errno, ap_log_errno_strings[ap_log_err_errno], ap_log_err_details);
    return (const char *)buf;
}

canonical_original_code:
char *ap_error_get_string()
{
    static char buf[-1];
    int bufpos;
    if ( ap_log_err_errno == 0 && ap_log_syserrno == 0 && (*__errno_location ()) == 0 )
    {
     sprintf(buf, ap_log_errno_strings[ap_log_err_errno]);
     return buf;
    }
    if ( ap_log_err_errno == 0 && (*__errno_location ()) != 0 )
    {
        snprintf(buf, 1024, "There is no error recorded inside AP's_toolkit functions, but system error is: %d/'%s'. ", (*__errno_location ()), strerror((*__errno_location ())));
        return (char *)buf;
    }
    bufpos = 0;
    bufpos += snprintf(buf + bufpos, 1024 - bufpos, "ERROR in AP's_toolkit: in function: %s - ", ap_log_err_function_name);
    if ( ap_log_syserrno )
        bufpos += snprintf(buf + bufpos, 1024 - bufpos, "system error: %d/'%s'. ", ap_log_syserrno, strerror(ap_log_syserrno));
 if ( *ap_log_err_details )
     strncat(buf + bufpos, ap_log_err_details, 1024 - bufpos);
    else if ( ! ap_log_syserrno )
     bufpos += snprintf(buf + bufpos, 1024 - bufpos, "%d/'%s'. %s", ap_log_err_errno, ap_log_errno_strings[ap_log_err_errno], ap_log_err_details);
    return (char *)buf;
}

variable_types:
buf
char [-1]

variable_types: bufpos int


decompiled_code:
__int64 ap_error_set_detailed(__int64 a1, int a2, const char *a3, ...)
{
__int64 result; // rax
int v5; // eax
char *v6; // rbp
size_t v7; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

result = ap_log_get_lock();
if ( (_DWORD)result )
{
v5 = *_errno_location();
ap_log_err_errno = a2;
ap_log_err_function_name = a1;
ap_log_syserrno = v5;
va_start(arg, a3);
vsnprintf(&ap_log_err_details, 0x400uLL, a3, arg);
if ( ap_log_debug_level )
{
v6 = ap_error_get_string();
v7 = strlen(v6);
ap_log_debug_log_raw(v6, v7);
}
result = ap_log_release_lock();
}
return result;
}

canonical_decompiled_code:
__int64 func4(__int64 a1, int a2, const char *a3, ...)
{
__int64 result; // rax
int v5; // eax
char *v6; // rbp
size_t v7; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

result = ap_log_get_lock();
if ( (_DWORD)result )
{
v5 = *_errno_location();
ap_log_err_errno = a2;
ap_log_err_function_name = a1;
ap_log_syserrno = v5;
va_start(arg, a3);
vsnprintf(&ap_log_err_details, 0x400uLL, a3, arg);
if ( ap_log_debug_level )
{
v6 = func3();
v7 = strlen(v6);
ap_log_debug_log_raw(v6, v7);
}
result = ap_log_release_lock();
}
return result;
}

original_code:
void ap_error_set_detailed(const char *in_function_name, int in_errno, char *fmt, ...)
{
    va_list vl;
    char *debug_msg;
    if ( ! ap_log_get_lock() )
        return;
    ap_log_syserrno = (*__errno_location ());
    ap_log_err_errno = in_errno;
    ap_log_err_function_name = (char *)in_function_name;
    __builtin_va_start(vl,fmt);
    vsnprintf(ap_log_err_details, 1024, fmt, vl);
    __builtin_va_end(vl);
    if (ap_log_debug_level)
    {
        debug_msg = (char *)ap_error_get_string();
        ap_log_debug_log_raw(debug_msg, strlen(debug_msg));
    }
    ap_log_release_lock();
}

canonical_original_code:
void ap_error_set_detailed(char *in_function_name, int in_errno, char *fmt, ...)
{
    __builtin_va_list vl;
    char *debug_msg;
    if ( ! ap_log_get_lock() )
        return;
    ap_log_syserrno = (*__errno_location ());
    ap_log_err_errno = in_errno;
    ap_log_err_function_name = (char *)in_function_name;
    __builtin_va_start(vl,fmt);
    vsnprintf(ap_log_err_details, 1024, fmt, vl);
    __builtin_va_end(vl);
    if (ap_log_debug_level)
    {
        debug_msg = (char *)ap_error_get_string();
        ap_log_debug_log_raw(debug_msg, strlen(debug_msg));
    }
    ap_log_release_lock();
}

variable_types:
fmt
char *


decompiled_code:
__int64 ap_error_set_custom(__int64 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return ap_error_set_detailed(a1, 2, a2, va);
}

canonical_decompiled_code:
__int64 func5(__int64 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func4(a1, 2, a2, va);
}

original_code:
void ap_error_set_custom(const char *in_function_name, char *fmt, ...)
{
    va_list vl;
    __builtin_va_start(vl,fmt);
    ap_error_set_detailed(in_function_name, 2, fmt, vl);
    __builtin_va_end(vl);
}

canonical_original_code:
void ap_error_set_custom(char *in_function_name, char *fmt, ...)
{
    __builtin_va_list vl;
    __builtin_va_start(vl,fmt);
    ap_error_set_detailed(in_function_name, 2, fmt, vl);
    __builtin_va_end(vl);
}


lock

original_code:
static int lock(unsigned int *state)
{
    int lock_try;
    for ( lock_try = 1; *state & 4; ++lock_try )
    {
        if ( lock_try == 10000 / 50 )
            return 0;
        usleep(50 * 1000);
    }
    *state |= 4;
    return 1;
}

variable_types:
state
unsigned int *


decompiled_code:
__int64 __fastcall ap_net_connection_lock(__int64 a1)
{
return lock((int *)(a1 + 132));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return func0((int *)(a1 + 132));
}

original_code:
int ap_net_connection_lock(struct ap_net_connection_t *conn)
{
 return lock(&conn->state);
}

variable_types: struct ap_net_connection_t { struct ap_net_conn_pool_t { struct ap_net_connection_t *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *poller; struct timespec { long tv_sec; long tv_nsec; } max_conn_ttl; struct { int sock; union { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *parent; int idx; int fd; unsigned int flags; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *


decompiled_code:
void __fastcall ap_net_connection_unlock(__int64 a1)
{
*(_DWORD *)(a1 + 132) &= 0xFFFFFFFB;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
*(_DWORD *)(a1 + 132) &= 0xFFFFFFFB;
}

original_code:
void ap_net_connection_unlock(struct ap_net_connection_t *conn)
{
    ((conn->state) &= ~(4));
}


decompiled_code:
__int64 __fastcall ap_net_conn_pool_lock(__int64 a1)
{
return lock((int *)(a1 + 20));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return func0((int *)(a1 + 20));
}

original_code:
int ap_net_conn_pool_lock(struct ap_net_conn_pool_t *pool)
{
 return lock(&pool->state);
}


decompiled_code:
void __fastcall ap_net_conn_pool_unlock(__int64 a1)
{
*(_DWORD *)(a1 + 20) &= 0xFFFFFFFB;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
*(_DWORD *)(a1 + 20) &= 0xFFFFFFFB;
}

original_code:
void ap_net_conn_pool_unlock(struct ap_net_conn_pool_t *pool)
{
    ((pool->state) &= ~(4));
}


decompiled_code:
__int64 __fastcall ap_net_conn_pool_get_conn_by_fd(__int64 *a1, int a2)
{
int v2; // edx
__int64 result; // rax
__int64 v4; // rdx

v2 = *((_DWORD *)a1 + 2);
if ( v2 <= 0 )
return 0LL;
result = *a1;
v4 = *a1 + 144LL * (unsigned int)(v2 - 1) + 144;
while ( *(_DWORD *)(result + 12) != a2 )
{
result += 144LL;
if ( result == v4 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, int a2)
{
int v2; // edx
__int64 result; // rax
__int64 v4; // rdx

v2 = *((_DWORD *)a1 + 2);
if ( v2 <= 0 )
return 0LL;
result = *a1;
v4 = *a1 + 144LL * (unsigned int)(v2 - 1) + 144;
while ( *(_DWORD *)(result + 12) != a2 )
{
result += 144LL;
if ( result == v4 )
return 0LL;
}
return result;
}

original_code:
struct ap_net_connection_t *ap_net_conn_pool_get_conn_by_fd(struct ap_net_conn_pool_t *pool, int fd)
{
    int i;
    for ( i = 0; i < pool->max_connections; ++i)
        if ( pool->conns[i].fd == fd )
            return &pool->conns[i];
    return ((void *)0);
}

variable_types:
pool
struct ap_net_conn_pool_t *

variable_types: fd int

return_type: struct ap_net_connection_t { struct ap_net_conn_pool_t { struct ap_net_connection_t *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *poller; struct timespec { long tv_sec; long tv_nsec; } max_conn_ttl; struct { int sock; union { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *parent; int idx; int fd; unsigned int flags; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *


original_code:
struct ap_net_connection_t *ap_net_conn_pool_get_conn_by_port(struct ap_net_conn_pool_t *pool, in_port_t port, int is_local)
{
    int i;
    int ip6;
    for ( i = 0; i < pool->max_connections; ++i)
    {
        ip6 = (is_local ? pool->conns[i].local.af : pool->conns[i].remote.af) == 10;
        if ( port == (is_local ? (ip6 ? pool->conns[i].local.addr6.sin6_port : pool->conns[i].local.addr4.sin_port)
                : (ip6 ? pool->conns[i].remote.addr6.sin6_port : pool->conns[i].remote.addr4.sin_port)) )
            return &pool->conns[i];
    }
    return ((void *)0);
}

canonical_original_code:
struct ap_net_connection_t *ap_net_conn_pool_get_conn_by_port(struct ap_net_conn_pool_t *pool, unsigned short port, int is_local)
{
    int i;
    int ip6;
    for ( i = 0; i < pool->max_connections; ++i)
    {
        ip6 = (is_local ? pool->conns[i].local.af : pool->conns[i].remote.af) == 10;
        if ( port == (is_local ? (ip6 ? pool->conns[i].local.addr6.sin6_port : pool->conns[i].local.addr4.sin_port)
                : (ip6 ? pool->conns[i].remote.addr6.sin6_port : pool->conns[i].remote.addr4.sin_port)) )
            return &pool->conns[i];
    }
    return ((void *)0);
}

variable_types:
port
unsigned short


original_code:
struct ap_net_connection_t *ap_net_conn_pool_get_conn_by_address(struct ap_net_conn_pool_t *pool, struct sockaddr_storage *ss, int is_local)
{
 struct ap_net_connection_t *conn;
 void *address;
 int port, ip6;
 int i;
    ip6 = (ss->ss_family == 10);
 address = (ip6 ? (void*)&((struct sockaddr_in6 *)ss)->sin6_addr : (void*)&((struct sockaddr_in *)ss)->sin_addr);
 port = (ip6 ? ((struct sockaddr_in6 *)ss)->sin6_port : ((struct sockaddr_in *)ss)->sin_port);
    for ( i = 0; i < pool->max_connections; ++i)
    {
     conn = &pool->conns[i];
        if ( port == (is_local ? (ip6 ? conn->local.addr6.sin6_port : conn->local.addr4.sin_port)
                      : (ip6 ? conn->remote.addr6.sin6_port : conn->remote.addr4.sin_port)
            )
             && 0 == memcmp(address,
                     (is_local ? (ip6 ? (void*)&conn->local.addr6.sin6_addr : (void*)&conn->local.addr4.sin_addr)
                         : (ip6 ? (void*)&conn->remote.addr6.sin6_addr : (void*)&conn->remote.addr4.sin_addr)
                     ),
                     ip6 ? sizeof(struct in6_addr) : sizeof(struct in_addr)
                  )
         )
            return conn;
    }
    return ((void *)0);
}

canonical_original_code:
struct ap_net_connection_t *ap_net_conn_pool_get_conn_by_address(struct ap_net_conn_pool_t *pool, struct sockaddr_storage *ss, int is_local)
{
 struct ap_net_connection_t *conn;
 void *address;
 int port; int ip6;
 int i;
    ip6 = (ss->ss_family == 10);
 address = (ip6 ? (void *)&((struct sockaddr_in6 *)ss)->sin6_addr : (void *)&((struct sockaddr_in *)ss)->sin_addr);
 port = (ip6 ? ((struct sockaddr_in6 *)ss)->sin6_port : ((struct sockaddr_in *)ss)->sin_port);
    for ( i = 0; i < pool->max_connections; ++i)
    {
     conn = &pool->conns[i];
        if ( port == (is_local ? (ip6 ? conn->local.addr6.sin6_port : conn->local.addr4.sin_port)
                      : (ip6 ? conn->remote.addr6.sin6_port : conn->remote.addr4.sin_port)
            )
             && 0 == memcmp(address,
                     (is_local ? (ip6 ? (void *)&conn->local.addr6.sin6_addr : (void *)&conn->local.addr4.sin_addr)
                         : (ip6 ? (void *)&conn->remote.addr6.sin6_addr : (void *)&conn->remote.addr4.sin_addr)
                     ),
                     ip6 ? sizeof(struct in6_addr) : sizeof(struct in_addr)
                  )
         )
            return conn;
    }
    return ((void *)0);
}

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } *

variable_types:
address
void *

variable_types: port int


decompiled_code:
void __fastcall ap_net_connection_destroy(void *ptr, int a2)
{
void (__fastcall *v2)(void *, __int64); // rax

if ( *(_QWORD *)ptr )
{
v2 = *(void (__fastcall **)(void *, __int64))(*(_QWORD *)ptr + 80LL);
if ( v2 )
v2(ptr, 1LL);
}
free(*((void **)ptr + 14));
if ( a2 )
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr, int a2)
{
void (__fastcall *v2)(void *, __int64); // rax

if ( *(_QWORD *)ptr )
{
v2 = *(void (__fastcall **)(void *, __int64))(*(_QWORD *)ptr + 80LL);
if ( v2 )
v2(ptr, 1LL);
}
free(*((void **)ptr + 14));
if ( a2 )
free(ptr);
}

original_code:
void ap_net_connection_destroy(struct ap_net_connection_t *conn, int free_this)
{
 if (conn->parent != ((void *)0) && conn->parent->callback_func != ((void *)0) )
  conn->parent->callback_func(conn, 1 );
 free(conn->buf);
 if ( free_this )
     free(conn);
}


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

*(_QWORD *)(a1 + 124) = 0LL;
if ( a2 <= 0xFF )
result = memset(*(void **)(a1 + 112), a2, *(int *)(a1 + 120));
return result;
}

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

*(_QWORD *)(a1 + 124) = 0LL;
if ( a2 <= 0xFF )
result = memset(*(void **)(a1 + 112), a2, *(int *)(a1 + 120));
return result;
}

original_code:
void ap_net_connection_buf_clear(struct ap_net_connection_t *conn, int fill_char)
{
 conn->buffill = conn->bufpos = 0;
 if ( fill_char >= 0 && fill_char < 256 )
  memset(conn->buf, fill_char, conn->bufsize);
}


decompiled_code:
void __fastcall ap_net_conn_pool_destroy(void *ptr, int a2)
{
int v3; // edi
__int64 i; // rbx
_BYTE *v5; // rdi

v3 = *((_DWORD *)ptr + 12);
if ( v3 != -1 )
close(v3);
if ( *((_QWORD *)ptr + 3) )
ap_net_poller_destroy();
for ( i = 0LL; *((_DWORD *)ptr + 2) > (int)i; ++i )
{
v5 = (_BYTE *)(144 * i + *(_QWORD *)ptr);
if ( (v5[132] & 2) != 0 )
{
ap_net_conn_pool_close_connection(ptr, (unsigned int)i);
v5 = (_BYTE *)(144 * i + *(_QWORD *)ptr);
}
ap_net_connection_destroy(v5, 0);
}
free(*(void **)ptr);
if ( a2 )
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr, int a2)
{
int v3; // edi
__int64 i; // rbx
_BYTE *v5; // rdi

v3 = *((_DWORD *)ptr + 12);
if ( v3 != -1 )
close(v3);
if ( *((_QWORD *)ptr + 3) )
ap_net_poller_destroy();
for ( i = 0LL; *((_DWORD *)ptr + 2) > (int)i; ++i )
{
v5 = (_BYTE *)(144 * i + *(_QWORD *)ptr);
if ( (v5[132] & 2) != 0 )
{
ap_net_conn_pool_close_connection(ptr, (unsigned int)i);
v5 = (_BYTE *)(144 * i + *(_QWORD *)ptr);
}
func8(v5, 0);
}
free(*(void **)ptr);
if ( a2 )
free(ptr);
}

original_code:
void ap_net_conn_pool_destroy(struct ap_net_conn_pool_t *pool, int free_this)
{
    int i;
    if ( pool->listener.sock != -1 )
     close(pool->listener.sock);
    if ( pool->poller != ((void *)0) )
     ap_net_poller_destroy(pool->poller);
    for ( i = 0; i < pool->max_connections; ++i)
    {
        if ( pool->conns[i].state & 2 )
             ap_net_conn_pool_close_connection(pool, i);
        ap_net_connection_destroy(&pool->conns[i], 0);
    }
    free(pool->conns);
    if ( free_this )
     free(pool);
}

variable_types: struct ap_net_conn_pool_t { struct ap_net_connection_t { struct ap_net_conn_pool_t *parent; int idx; int fd; unsigned int flags; union { unsigned short af; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr4; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } addr6; } local; union { unsigned short af; struct sockaddr_in addr4; struct sockaddr_in6 addr6; } remote; struct timespec { long tv_sec; long tv_nsec; } created_time; struct timespec expire; char *buf; int bufsize; unsigned int state; void *user_data; } *conns; int max_connections; int used_slots; unsigned int flags; unsigned int state; struct ap_net_poll_t { struct ap_net_conn_pool_t *parent; struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *events; int max_events; int last_event_index; int events_count; int epoll_fd; int listen_socket_fd; int listen_socket_flags; int debug; int emit_old_data_signal; } *poller; struct timespec max_conn_ttl; struct { int sock; union { struct sockaddr_in addr4; struct sockaddr_in6 addr6; }; } listener; int (*callback_func)(struct ap_net_connection_t *conn, int signal_type); struct ap_net_stat_t { unsigned int conn_count; unsigned int timedout; unsigned int queue_full_count; unsigned int active_conn_count; struct timespec total_time; } stat; } *


decompiled_code:
__int64 __fastcall ap_net_conn_pool_find_free_slot(__int64 *a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // rdx

v1 = *((_DWORD *)a1 + 2);
if ( *((_DWORD *)a1 + 3) == v1 )
{
++*((_DWORD *)a1 + 24);
ap_error_set("ap_net_conn_pool_find_free_slot()", 4LL);
result = 0LL;
}
else if ( v1 <= 0 )
{
LABEL_7:
result = 0LL;
}
else
{
result = *a1;
v3 = *a1 + 144LL * (unsigned int)(v1 - 1) + 144;
while ( (*(_BYTE *)(result + 132) & 2) != 0 )
{
result += 144LL;
if ( result == v3 )
goto LABEL_7;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1)
{
int v1; // edx
__int64 result; // rax
__int64 v3; // rdx

v1 = *((_DWORD *)a1 + 2);
if ( *((_DWORD *)a1 + 3) == v1 )
{
++*((_DWORD *)a1 + 24);
ap_error_set("ap_net_conn_pool_find_free_slot()", 4LL);
result = 0LL;
}
else if ( v1 <= 0 )
{
LABEL_7:
result = 0LL;
}
else
{
result = *a1;
v3 = *a1 + 144LL * (unsigned int)(v1 - 1) + 144;
while ( (*(_BYTE *)(result + 132) & 2) != 0 )
{
result += 144LL;
if ( result == v3 )
goto LABEL_7;
}
}
return result;
}

original_code:
struct ap_net_connection_t *ap_net_conn_pool_find_free_slot(struct ap_net_conn_pool_t *pool)
{
    struct ap_net_connection_t *conn;
    int conn_idx;
    if (pool->used_slots == pool->max_connections)
    {
        pool->stat.queue_full_count++;
        ap_error_set("ap_net_conn_pool_find_free_slot()", 4);
        return ((void *)0);
    }
    conn = ((void *)0);
    for ( conn_idx = 0; conn_idx < pool->max_connections; ++conn_idx )
        if ( ! (pool->conns[conn_idx].state & 2) )
        {
            conn = &pool->conns[conn_idx];
            break;
        }
    return conn;
}


decompiled_code:
__int64 __fastcall ap_net_recv(int fd, void *buf, int a3, int a4)
{
int v6; // er12

ap_error_clear();
if ( fcntl(fd, 3) == -1 )
{
v6 = -1;
}
else
{
v6 = recv(fd, buf, a3, a4 == 0 ? 0x4000 : 16448);
if ( v6 >= 0 )
return (unsigned int)v6;
}
ap_error_set_detailed("ap_net_recv", 1LL, "sock %d", (unsigned int)fd);
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func12(int fd, void *buf, int a3, int a4)
{
int v6; // er12

ap_error_clear();
if ( fcntl(fd, 3) == -1 )
{
v6 = -1;
}
else
{
v6 = recv(fd, buf, a3, a4 == 0 ? 0x4000 : 16448);
if ( v6 >= 0 )
return (unsigned int)v6;
}
ap_error_set_detailed("ap_net_recv", 1LL, "sock %d", (unsigned int)fd);
return (unsigned int)v6;
}

original_code:
int ap_net_recv(int sh, void *buf, int size, int non_blocking)
{
    int retval;
    int flags;
    ap_error_clear();
    retval = fcntl(sh, 3);
    if ( retval != -1 )
    {
     flags = (non_blocking ? MSG_DONTWAIT : 0) | MSG_NOSIGNAL;
        retval = recv(sh, buf, size, flags);
    }
    if ( retval < 0 )
        ap_error_set_detailed("ap_net_recv", 1, "sock %d", sh);
    return retval;
}

variable_types: sh int

variable_types:
buf
void *

variable_types: size int

variable_types: retval int

variable_types: flags int


decompiled_code:
__int64 __fastcall ap_net_send(int fd, void *buf, int a3, int a4)
{
int v6; // er12

ap_error_clear();
if ( fcntl(fd, 3) == -1 )
{
v6 = -1;
}
else
{
v6 = send(fd, buf, a3, a4 == 0 ? 0x4000 : 16448);
if ( v6 > 0 )
return (unsigned int)v6;
}
ap_error_set_detailed("ap_net_send", 1LL, "sock %d", (unsigned int)fd);
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func13(int fd, void *buf, int a3, int a4)
{
int v6; // er12

ap_error_clear();
if ( fcntl(fd, 3) == -1 )
{
v6 = -1;
}
else
{
v6 = send(fd, buf, a3, a4 == 0 ? 0x4000 : 16448);
if ( v6 > 0 )
return (unsigned int)v6;
}
ap_error_set_detailed("ap_net_send", 1LL, "sock %d", (unsigned int)fd);
return (unsigned int)v6;
}

original_code:
int ap_net_send(int sh, void *buf, int size, int non_blocking)
{
    int retval;
    int flags;
    ap_error_clear();
    retval = fcntl(sh, 3);
    if ( retval != -1 )
    {
     flags = (non_blocking ? MSG_DONTWAIT : 0) | MSG_NOSIGNAL;
        retval = send(sh, buf, size, flags);
    }
    if ( retval <= 0 )
        ap_error_set_detailed("ap_net_send", 1, "sock %d", sh);
    return retval;
}


decompiled_code:
__int64 __fastcall ap_net_conn_pool_accept_connection(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // r12
int v4; // edi
int v5; // eax
int v6; // eax
int v7; // ebx
unsigned int v8; // eax
unsigned int (__fastcall *v9)(__int64, __int64); // rax
int v11; // edi
__int64 v12; // rax
__int64 v13; // rdi
unsigned __int16 v14; // ax
__int64 v15; // rdx
unsigned int (__fastcall *v16)(__int64, __int64); // rax
void (__fastcall *v17)(__int64, __int64); // rax
unsigned int v18; // eax
__int64 v19; // rdi
__int64 v20; // rsi
int buf; // [rsp+8h] [rbp-A0h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

ap_error_clear();
if ( (*(_BYTE *)(a1 + 16) & 1) == 0 )
{
v11 = *(_DWORD *)(a1 + 48);
addr_len = 128;
buf = recvfrom(v11, &buf, 1uLL, 66, &addr, &addr_len);
if ( buf == -1 )
{
v3 = 0LL;
ap_error_set("ap_net_conn_pool_accept_connection()", 1LL);
}
else
{
v12 = ap_net_conn_pool_get_conn_by_address(a1, &addr, 0LL);
if ( v12 )
{
v3 = v12;
}
else
{
v13 = a1 + 32;
if ( addr.sa_family == 2 )
{
ap_utils_timespec_to_milliseconds(v13);
_bswap_16(*(__int16 *)addr.sa_data);
v18 = _bswap_32(*(unsigned int *)&addr.sa_data[2]);
v3 = ap_net_conn_pool_connect_ip4(a1, 1LL, v18);
}
else
{
ap_utils_timespec_to_milliseconds(v13);
v14 = _bswap_16(*(__int16 *)addr.sa_data);
v3 = ap_net_conn_pool_connect_ip6(a1, 1LL, v15, v14);
}
if ( !v3 )
return 0LL;
v16 = *(unsigned int (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v16 && !v16(v3, 3LL) )
goto LABEL_22;
}
buf = ap_net_conn_pool_recv(a1, *(unsigned int *)(v3 + 8));
if ( buf > 0 )
{
v17 = *(void (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v17 )
{
v17(v3, 7LL);
return v3;
}
}
}
return v3;
}
v2 = ap_net_conn_pool_find_free_slot(a1);
v3 = v2;
if ( v2 )
{
ap_net_conn_pool_connection_pre_connect(a1, *(unsigned int *)(v2 + 8), 0LL);
v4 = *(_DWORD *)(a1 + 48);
v5 = -((*(_DWORD *)(a1 + 16) & 4) == 0);
*(_WORD *)(v3 + 48) = (*(_DWORD *)(a1 + 16) & 4) == 0 ? 2 : 10;
addr_len = (v5 & 0xFFFFFFF4) + 28;
v6 = accept(v4, (struct sockaddr *)(v3 + 48), &addr_len);
v7 = v6;
if ( v6 == -1 )
{
ap_error_set_detailed("ap_net_conn_pool_accept_connection()", 1LL, "accept()");
v19 = v3;
v3 = 0LL;
ap_net_connection_unlock(v19);
}
else
{
v8 = fcntl(v6, 3);
BYTE1(v8) |= 8u;
fcntl(v7, 4, v8);
*(_DWORD *)(v3 + 12) = v7;
if ( (unsigned int)ap_net_conn_pool_poller_add_conn(a1, *(unsigned int *)(v3 + 8)) )
{
v9 = *(unsigned int (__fastcall **)(__int64, __int64))(a1 + 80);
if ( !v9 || v9(v3, 3LL) )
{
if ( ap_log_debug_level )
ap_log_debug_log("* Got connected at #%d\n", *(unsigned int *)(v3 + 8));
ap_net_connection_unlock(v3);
return v3;
}
LABEL_22:
ap_net_conn_pool_close_connection(a1, *(unsigned int *)(v3 + 8));
ap_error_set("ap_net_conn_pool_accept_connection()", 8LL);
return 0LL;
}
v20 = *(unsigned int *)(v3 + 8);
v3 = 0LL;
ap_net_conn_pool_close_connection(a1, v20);
}
return v3;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // r12
int v4; // edi
int v5; // eax
int v6; // eax
int v7; // ebx
unsigned int v8; // eax
unsigned int (__fastcall *v9)(__int64, __int64); // rax
int v11; // edi
__int64 v12; // rax
__int64 v13; // rdi
unsigned __int16 v14; // ax
__int64 v15; // rdx
unsigned int (__fastcall *v16)(__int64, __int64); // rax
void (__fastcall *v17)(__int64, __int64); // rax
unsigned int v18; // eax
__int64 v19; // rdi
__int64 v20; // rsi
int buf; // [rsp+8h] [rbp-A0h] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-9Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-98h] BYREF

ap_error_clear();
if ( (*(_BYTE *)(a1 + 16) & 1) == 0 )
{
v11 = *(_DWORD *)(a1 + 48);
addr_len = 128;
buf = recvfrom(v11, &buf, 1uLL, 66, &addr, &addr_len);
if ( buf == -1 )
{
v3 = 0LL;
ap_error_set("ap_net_conn_pool_accept_connection()", 1LL);
}
else
{
v12 = ap_net_conn_pool_get_conn_by_address(a1, &addr, 0LL);
if ( v12 )
{
v3 = v12;
}
else
{
v13 = a1 + 32;
if ( addr.sa_family == 2 )
{
ap_utils_timespec_to_milliseconds(v13);
func1(*(__int16 *)addr.sa_data);
v18 = func0(*(unsigned int *)&addr.sa_data[2]);
v3 = ap_net_conn_pool_connect_ip4(a1, 1LL, v18);
}
else
{
ap_utils_timespec_to_milliseconds(v13);
v14 = func1(*(__int16 *)addr.sa_data);
v3 = ap_net_conn_pool_connect_ip6(a1, 1LL, v15, v14);
}
if ( !v3 )
return 0LL;
v16 = *(unsigned int (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v16 && !v16(v3, 3LL) )
goto LABEL_22;
}
buf = ap_net_conn_pool_recv(a1, *(unsigned int *)(v3 + 8));
if ( buf > 0 )
{
v17 = *(void (__fastcall **)(__int64, __int64))(a1 + 80);
if ( v17 )
{
v17(v3, 7LL);
return v3;
}
}
}
return v3;
}
v2 = ap_net_conn_pool_find_free_slot(a1);
v3 = v2;
if ( v2 )
{
ap_net_conn_pool_connection_pre_connect(a1, *(unsigned int *)(v2 + 8), 0LL);
v4 = *(_DWORD *)(a1 + 48);
v5 = -((*(_DWORD *)(a1 + 16) & 4) == 0);
*(_WORD *)(v3 + 48) = (*(_DWORD *)(a1 + 16) & 4) == 0 ? 2 : 10;
addr_len = (v5 & 0xFFFFFFF4) + 28;
v6 = accept(v4, (struct sockaddr *)(v3 + 48), &addr_len);
v7 = v6;
if ( v6 == -1 )
{
ap_error_set_detailed("ap_net_conn_pool_accept_connection()", 1LL, "accept()");
v19 = v3;
v3 = 0LL;
ap_net_connection_unlock(v19);
}
else
{
v8 = fcntl(v6, 3);
BYTE1(v8) |= 8u;
fcntl(v7, 4, v8);
*(_DWORD *)(v3 + 12) = v7;
if ( (unsigned int)ap_net_conn_pool_poller_add_conn(a1, *(unsigned int *)(v3 + 8)) )
{
v9 = *(unsigned int (__fastcall **)(__int64, __int64))(a1 + 80);
if ( !v9 || v9(v3, 3LL) )
{
if ( ap_log_debug_level )
ap_log_debug_log("* Got connected at #%d\n", *(unsigned int *)(v3 + 8));
ap_net_connection_unlock(v3);
return v3;
}
LABEL_22:
ap_net_conn_pool_close_connection(a1, *(unsigned int *)(v3 + 8));
ap_error_set("ap_net_conn_pool_accept_connection()", 8LL);
return 0LL;
}
v20 = *(unsigned int *)(v3 + 8);
v3 = 0LL;
ap_net_conn_pool_close_connection(a1, v20);
}
return v3;
}
return 0LL;
}

original_code:
struct ap_net_connection_t *ap_net_conn_pool_accept_connection(struct ap_net_conn_pool_t *pool)
{
    int n;
    socklen_t addr_len;
    int new_sock;
    struct ap_net_connection_t *conn;
    struct sockaddr_storage addr;
    struct sockaddr *remote_addr;
    ap_error_clear();
    if ( (((pool->flags) & (1)) != 0) )
    {
     conn = ap_net_conn_pool_find_free_slot(pool);
     if ( conn == ((void *)0) )
      return ((void *)0);
     ap_net_conn_pool_connection_pre_connect(pool, conn->idx, 0);
     conn->remote.af = (((pool->flags) & (4)) != 0) ? 10 : 2;
        remote_addr = (((pool->flags) & (4)) != 0) ? (struct sockaddr *)&conn->remote.addr6 : (struct sockaddr *)&conn->remote.addr4;
        addr_len = (((pool->flags) & (4)) != 0) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
        new_sock = accept(pool->listener.sock, remote_addr, &addr_len);
        if ( new_sock == -1 )
        {
            ap_error_set_detailed(_func_name, 1, "accept()");
            ap_net_connection_unlock(conn);
            return ((void *)0);
        }
        fcntl(new_sock, 4, fcntl(new_sock, 3) | 04000);
        conn->fd = new_sock;
        if ( ! ap_net_conn_pool_poller_add_conn(pool, conn->idx) )
        {
         ap_net_conn_pool_close_connection(pool, conn->idx);
         return ((void *)0);
        }
     if (pool->callback_func != ((void *)0) && ! pool->callback_func(conn, 3) )
        {
           ap_net_conn_pool_close_connection(pool, conn->idx);
           ap_error_set(_func_name, 8);
            return ((void *)0);
        }
    }
    else
    {
     addr_len = sizeof(addr);
     n = recvfrom(pool->listener.sock, &n, 1, MSG_DONTWAIT | MSG_PEEK, (struct sockaddr *)&addr, &addr_len);
        if ( n == -1 )
        {
            ap_error_set(_func_name, 1);
            return ((void *)0);
        }
        conn = ap_net_conn_pool_get_conn_by_address(pool, &addr, 0);
        if ( conn == ((void *)0) )
        {
         if ( addr.ss_family == 2 )
         {
                conn = ap_net_conn_pool_connect_ip4(pool, 1,
                   ntohl(((struct sockaddr_in*)&addr)->sin_addr.s_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port),
                   ap_utils_timespec_to_milliseconds(&pool->max_conn_ttl));
         }
         else
         {
                conn = ap_net_conn_pool_connect_ip6(pool, 1,
                   &((struct sockaddr_in6*)&addr)->sin6_addr, ntohs(((struct sockaddr_in6*)&addr)->sin6_port),
                   ap_utils_timespec_to_milliseconds(&pool->max_conn_ttl));
         }
            if( conn == ((void *)0) )
                return ((void *)0);
            if (pool->callback_func != ((void *)0) && ! pool->callback_func(conn, 3) )
            {
                ap_net_conn_pool_close_connection(pool, conn->idx);
                ap_error_set(_func_name, 8);
                return ((void *)0);
            }
        }
     n = ap_net_conn_pool_recv(pool, conn->idx);
     if ( n > 0 && pool->callback_func != ((void *)0) )
             pool->callback_func(conn, 7);
        return conn;
    }
    if (ap_log_debug_level)
        ap_log_debug_log("* Got connected at #%d\n", conn->idx);
    ap_net_connection_unlock(conn);
    return conn;
}

canonical_original_code:
struct ap_net_connection_t *ap_net_conn_pool_accept_connection(struct ap_net_conn_pool_t *pool)
{
    int n;
    unsigned int addr_len;
    int new_sock;
    struct ap_net_connection_t *conn;
    struct sockaddr_storage addr;
    struct sockaddr *remote_addr;
    ap_error_clear();
    if ( (((pool->flags) & (1)) != 0) )
    {
     conn = ap_net_conn_pool_find_free_slot(pool);
     if ( conn == ((void *)0) )
      return ((void *)0);
     ap_net_conn_pool_connection_pre_connect(pool, conn->idx, 0);
     conn->remote.af = (((pool->flags) & (4)) != 0) ? 10 : 2;
        remote_addr = (((pool->flags) & (4)) != 0) ? (struct sockaddr *)&conn->remote.addr6 : (struct sockaddr *)&conn->remote.addr4;
        addr_len = (((pool->flags) & (4)) != 0) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
        new_sock = accept(pool->listener.sock, remote_addr, &addr_len);
        if ( new_sock == -1 )
        {
            ap_error_set_detailed(_func_name, 1, "accept()");
            ap_net_connection_unlock(conn);
            return ((void *)0);
        }
        fcntl(new_sock, 4, fcntl(new_sock, 3) | 04000);
        conn->fd = new_sock;
        if ( ! ap_net_conn_pool_poller_add_conn(pool, conn->idx) )
        {
         ap_net_conn_pool_close_connection(pool, conn->idx);
         return ((void *)0);
        }
     if (pool->callback_func != ((void *)0) && ! pool->callback_func(conn, 3) )
        {
           ap_net_conn_pool_close_connection(pool, conn->idx);
           ap_error_set(_func_name, 8);
            return ((void *)0);
        }
    }
    else
    {
     addr_len = sizeof(addr);
     n = recvfrom(pool->listener.sock, &n, 1, MSG_DONTWAIT | MSG_PEEK, (struct sockaddr *)&addr, &addr_len);
        if ( n == -1 )
        {
            ap_error_set(_func_name, 1);
            return ((void *)0);
        }
        conn = ap_net_conn_pool_get_conn_by_address(pool, &addr, 0);
        if ( conn == ((void *)0) )
        {
         if ( addr.ss_family == 2 )
         {
                conn = ap_net_conn_pool_connect_ip4(pool, 1,
                   ntohl(((struct sockaddr_in *)&addr)->sin_addr.s_addr), ntohs(((struct sockaddr_in *)&addr)->sin_port),
                   ap_utils_timespec_to_milliseconds(&pool->max_conn_ttl));
         }
         else
         {
                conn = ap_net_conn_pool_connect_ip6(pool, 1,
                   &((struct sockaddr_in6 *)&addr)->sin6_addr, ntohs(((struct sockaddr_in6 *)&addr)->sin6_port),
                   ap_utils_timespec_to_milliseconds(&pool->max_conn_ttl));
         }
            if( conn == ((void *)0) )
                return ((void *)0);
            if (pool->callback_func != ((void *)0) && ! pool->callback_func(conn, 3) )
            {
                ap_net_conn_pool_close_connection(pool, conn->idx);
                ap_error_set(_func_name, 8);
                return ((void *)0);
            }
        }
     n = ap_net_conn_pool_recv(pool, conn->idx);
     if ( n > 0 && pool->callback_func != ((void *)0) )
             pool->callback_func(conn, 7);
        return conn;
    }
    if (ap_log_debug_level)
        ap_log_debug_log("* Got connected at #%d\n", conn->idx);
    ap_net_connection_unlock(conn);
    return conn;
}

variable_types: n int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

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


decompiled_code:
__int64 __fastcall ap_utils_timeval_cmp_to_now(_QWORD *a1)
{
bool v1; // sf
bool v2; // of
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
v2 = __OFSUB__(*a1, v4.tv_sec);
v1 = *a1 - v4.tv_sec < 0;
result = 1LL;
if ( *a1 == v4.tv_sec )
{
v2 = __OFSUB__(a1[1], v4.tv_usec);
v1 = a1[1] - v4.tv_usec < 0;
if ( a1[1] > v4.tv_usec )
return result;
}
else if ( *a1 > v4.tv_sec )
{
return result;
}
return (unsigned int)-(v1 ^ v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
bool v1; // sf
bool v2; // of
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
v2 = __OFSUB__(*a1, v4.tv_sec);
v1 = *a1 - v4.tv_sec < 0;
result = 1LL;
if ( *a1 == v4.tv_sec )
{
v2 = __OFSUB__(a1[1], v4.tv_usec);
v1 = a1[1] - v4.tv_usec < 0;
if ( a1[1] > v4.tv_usec )
return result;
}
else if ( *a1 > v4.tv_sec )
{
return result;
}
return (unsigned int)-(v1 ^ v2);
}

original_code:
int ap_utils_timeval_cmp_to_now(struct timeval *tv)
{
    struct timeval now;
    gettimeofday(&now, ((void *)0));
    if ( (((tv)->tv_sec == (&now)->tv_sec) ? ((tv)->tv_usec > (&now)->tv_usec) : ((tv)->tv_sec > (&now)->tv_sec)) )
        return 1;
    else if ( (((tv)->tv_sec == (&now)->tv_sec) ? ((tv)->tv_usec < (&now)->tv_usec) : ((tv)->tv_sec < (&now)->tv_sec)) )
        return -1;
    return 0;
}

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


original_code:
int ap_utils_timeval_set(struct timeval *tv, int mode, int msec)
{
   struct timeval tmp;
   if ( msec < 1 )
    return 0;
   switch( mode )
   {
    case 0:
     tmp.tv_sec = msec / 1000;
     tmp.tv_usec = 1000 * (msec % 1000);
     do { (tv)->tv_sec = (tv)->tv_sec + (&tmp)->tv_sec; (tv)->tv_usec = (tv)->tv_usec + (&tmp)->tv_usec; if ((tv)->tv_usec >= 1000000) { ++(tv)->tv_sec; (tv)->tv_usec -= 1000000; } } while (0);
     break;
    case 1:
     tmp.tv_sec = msec / 1000;
     tmp.tv_usec = 1000 * (msec % 1000);
     do { (tv)->tv_sec = (tv)->tv_sec - (&tmp)->tv_sec; (tv)->tv_usec = (tv)->tv_usec - (&tmp)->tv_usec; if ((tv)->tv_usec < 0) { --(tv)->tv_sec; (tv)->tv_usec += 1000000; } } while (0);
     break;
    case 2:
     gettimeofday(tv, ((void *)0));
     tmp.tv_sec = msec / 1000;
     tmp.tv_usec = 1000 * (msec % 1000);
     do { (tv)->tv_sec = (tv)->tv_sec + (&tmp)->tv_sec; (tv)->tv_usec = (tv)->tv_usec + (&tmp)->tv_usec; if ((tv)->tv_usec >= 1000000) { ++(tv)->tv_sec; (tv)->tv_usec -= 1000000; } } while (0);
     break;
    case 3:
     tv->tv_sec = msec / 1000;
     tv->tv_usec = 1000 * (msec % 1000);
     break;
    default:
     return 0;
   }
   return 1;
}

variable_types: mode int

variable_types: msec int

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


decompiled_code:
__int64 __fastcall ap_utils_timespec_cmp_to_now(__time_t *a1)
{
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v2);
result = 1LL;
if ( *a1 <= v2.tv_sec )
{
result = 0xFFFFFFFFLL;
if ( *a1 >= v2.tv_sec )
{
result = 1LL;
if ( a1[1] <= v2.tv_nsec )
result = (unsigned int)-(a1[1] < v2.tv_nsec);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__time_t *a1)
{
__int64 result; // rax
struct timespec v2; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(4, &v2);
result = 1LL;
if ( *a1 <= v2.tv_sec )
{
result = 0xFFFFFFFFLL;
if ( *a1 >= v2.tv_sec )
{
result = 1LL;
if ( a1[1] <= v2.tv_nsec )
result = (unsigned int)-(a1[1] < v2.tv_nsec);
}
}
return result;
}

original_code:
int ap_utils_timespec_cmp_to_now(struct timespec *ts)
{
    struct timespec now;
 clock_gettime(4, &now);
    if ( ts->tv_sec > now.tv_sec )
        return 1;
    if ( ts->tv_sec < now.tv_sec )
     return -1;
    if ( ts->tv_nsec > now.tv_nsec )
        return 1;
    if ( ts->tv_nsec < now.tv_nsec )
        return -1;
    return 0;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *


decompiled_code:
__int64 __fastcall ap_utils_timespec_set(struct timespec *tp, int a2, int a3)
{
unsigned int v3; // er8
__int64 v4; // rbx
__syscall_slong_t v5; // rbx
__int64 result; // rax
unsigned __int64 v7; // rdx

v3 = 0;
v4 = a3;
if ( a3 < 0 )
return v3;
if ( a2 == 2 )
{
clock_gettime(4, tp);
goto LABEL_13;
}
if ( a2 > 2 )
{
if ( a2 == 3 )
{
tp->tv_sec = a3 / 1000;
result = 1LL;
tp->tv_nsec = 1000000000LL * (a3 % 1000);
return result;
}
return v3;
}
if ( !a2 )
{
LABEL_13:
v5 = tp->tv_nsec + 1000000 * v4;
tp->tv_nsec = v5;
if ( v5 <= 999999999 )
{
LABEL_7:
v3 = 1;
if ( v5 < 0 )
{
v7 = -v5 / 0x3B9ACA00uLL;
tp->tv_sec -= v7;
tp->tv_nsec = v5 + 1000000000 * v7 + 1000000000;
}
return v3;
}
goto LABEL_14;
}
if ( a2 != 1 )
return v3;
v5 = tp->tv_nsec - 1000000LL * a3;
tp->tv_nsec = v5;
if ( v5 <= 999999999 )
goto LABEL_7;
LABEL_14:
tp->tv_sec += v5 / 1000000000;
result = 1LL;
tp->tv_nsec = v5 % 1000000000;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(struct timespec *tp, int a2, int a3)
{
unsigned int v3; // er8
__int64 v4; // rbx
__syscall_slong_t v5; // rbx
__int64 result; // rax
unsigned __int64 v7; // rdx

v3 = 0;
v4 = a3;
if ( a3 < 0 )
return v3;
if ( a2 == 2 )
{
clock_gettime(4, tp);
goto LABEL_13;
}
if ( a2 > 2 )
{
if ( a2 == 3 )
{
tp->tv_sec = a3 / 1000;
result = 1LL;
tp->tv_nsec = 1000000000LL * (a3 % 1000);
return result;
}
return v3;
}
if ( !a2 )
{
LABEL_13:
v5 = tp->tv_nsec + 1000000 * v4;
tp->tv_nsec = v5;
if ( v5 <= 999999999 )
{
LABEL_7:
v3 = 1;
if ( v5 < 0 )
{
v7 = -v5 / 0x3B9ACA00uLL;
tp->tv_sec -= v7;
tp->tv_nsec = v5 + 1000000000 * v7 + 1000000000;
}
return v3;
}
goto LABEL_14;
}
if ( a2 != 1 )
return v3;
v5 = tp->tv_nsec - 1000000LL * a3;
tp->tv_nsec = v5;
if ( v5 <= 999999999 )
goto LABEL_7;
LABEL_14:
tp->tv_sec += v5 / 1000000000;
result = 1LL;
tp->tv_nsec = v5 % 1000000000;
return result;
}

original_code:
int ap_utils_timespec_set(struct timespec *ts, int mode, int msec)
{
 long tmp;
 if ( msec < 0 )
  return 0;
 switch( mode )
 {
  case 0:
   ts->tv_nsec += msec * 1000000l;
   break;
  case 1:
   ts->tv_nsec -= msec * 1000000l;
   break;
     case 2:
      clock_gettime(4, ts);
      ts->tv_nsec += msec * 1000000l;
      break;
     case 3:
      ts->tv_sec = msec / 1000;
      ts->tv_nsec = 1000000000l * (msec % 1000l);
      return 1;
     default:
      return 0;
 }
    if ( ts->tv_nsec >= 1000000000l )
    {
     tmp = ts->tv_nsec / 1000000000l;
        ts->tv_nsec -= tmp * 1000000000l;
        ts->tv_sec += tmp;
    }
    else if ( ts->tv_nsec < 0l )
    {
     tmp = labs(ts->tv_nsec) / 1000000000l;
        ts->tv_nsec = 1000000000l + ts->tv_nsec + tmp * 1000000000l;
        ts->tv_sec -= tmp;
    }
    return 1;
}

variable_types: tmp long


decompiled_code:
_BOOL8 __fastcall ap_utils_timespec_is_set(__int64 *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( *a1 <= 0 )
result = a1[1] > 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( *a1 <= 0 )
result = a1[1] > 0;
return result;
}

original_code:
int ap_utils_timespec_is_set(struct timespec *ts)
{
 return (ts->tv_sec > 0 || ts->tv_nsec > 0l);
}


original_code:
void ap_utils_timespec_add(struct timespec *a, struct timespec *b, struct timespec *destination)
{
 long tmp;
 destination->tv_sec = a->tv_sec + b->tv_sec;
 destination->tv_nsec = a->tv_nsec + b->tv_nsec;
 if ( destination->tv_nsec >= 1000000000l )
    {
     tmp = destination->tv_nsec / 1000000000l;
     destination->tv_nsec -= tmp * 1000000000l;
     destination->tv_sec += tmp;
    }
}

variable_types:
b
struct timespec *

variable_types:
destination
struct timespec *


original_code:
void ap_utils_timespec_sub(struct timespec *a, struct timespec *b, struct timespec *destination)
{
 long tmp;
 destination->tv_sec = a->tv_sec - b->tv_sec;
 destination->tv_nsec = a->tv_nsec - b->tv_nsec;
    if ( destination->tv_nsec <= -1000000000l )
    {
     tmp = destination->tv_nsec / 1000000000l;
     destination->tv_nsec = destination->tv_nsec + tmp * 1000000000l;
     destination->tv_sec += tmp;
    }
}


decompiled_code:
__int64 __fastcall ap_utils_timespec_elapsed(__int128 a1, struct timespec *a2)
{
struct timespec *v2; // r12
struct timespec *v3; // rbp
struct timespec v6[2]; // [rsp-28h] [rbp-28h] BYREF

if ( a1 == 0 )
return 0LL;
v2 = (struct timespec *)*((_QWORD *)&a1 + 1);
v3 = (struct timespec *)a1;
if ( (_QWORD)a1 )
{
if ( !*((_QWORD *)&a1 + 1) )
{
v2 = v6;
clock_gettime(4, v6);
}
}
else
{
v3 = v6;
clock_gettime(4, v6);
}
if ( !a2 )
a2 = v6;
ap_utils_timespec_sub(v2, v3, a2);
return 1000 * a2->tv_sec + a2->tv_nsec / 1000000;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int128 a1, struct timespec *a2)
{
struct timespec *v2; // r12
struct timespec *v3; // rbp
struct timespec v6[2]; // [rsp-28h] [rbp-28h] BYREF

if ( a1 == 0 )
return 0LL;
v2 = (struct timespec *)*((_QWORD *)&a1 + 1);
v3 = (struct timespec *)a1;
if ( (_QWORD)a1 )
{
if ( !*((_QWORD *)&a1 + 1) )
{
v2 = v6;
clock_gettime(4, v6);
}
}
else
{
v3 = v6;
clock_gettime(4, v6);
}
if ( !a2 )
a2 = v6;
func7(v2, v3, a2);
return 1000 * a2->tv_sec + a2->tv_nsec / 1000000;
}

original_code:
long ap_utils_timespec_elapsed(struct timespec *begin, struct timespec *end, struct timespec *destination)
{
 struct timespec now;
 if ( begin == ((void *)0) && end == ((void *)0) )
  return 0;
 if ( begin == ((void *)0) )
 {
  clock_gettime(4, &now);
  begin = &now;
 }
 else if ( end == ((void *)0) )
 {
  clock_gettime(4, &now);
  end = &now;
 }
 if ( destination == ((void *)0) )
  destination = &now;
 ap_utils_timespec_sub(end, begin, destination);
 return destination->tv_sec * 1000l + destination->tv_nsec / 1000000l;
}

variable_types:
end
struct timespec *

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: long


decompiled_code:
__int64 __fastcall ap_utils_timespec_to_milliseconds(_QWORD *a1)
{
__int64 v1; // r8

v1 = 1000LL * *a1;
if ( (__int64)a1[1] > 0 )
v1 += a1[1] / 1000000LL;
return v1;
}

original_code:
long ap_utils_timespec_to_milliseconds(struct timespec *ts)
{
 long retval;
 retval = ts->tv_sec * 1000l;
    if ( ts->tv_nsec > 0l )
     retval += ts->tv_nsec / 1000000l;
    return retval;
}

variable_types: retval long


decompiled_code:
__int64 __fastcall count_crc16(unsigned __int8 *a1, int a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rsi
int v4; // edx
int v5; // edx
unsigned __int8 v6; // al

if ( !a2 )
return 0LL;
LODWORD(result) = 0;
v3 = &a1[a2];
do
{
v4 = *a1++;
v5 = result ^ v4;
v6 = v5 ^ (16 * v5);
LOWORD(v5) = BYTE1(v5);
result = (v6 << 8) ^ (v6 >> 4) ^ v5 ^ (8 * (unsigned int)v6);
}
while ( a1 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1, int a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rsi
int v4; // edx
int v5; // edx
unsigned __int8 v6; // al

if ( !a2 )
return 0LL;
LODWORD(result) = 0;
v3 = &a1[a2];
do
{
v4 = *a1++;
v5 = result ^ v4;
v6 = v5 ^ (16 * v5);
LOWORD(v5) = BYTE1(v5);
result = (v6 << 8) ^ (v6 >> 4) ^ v5 ^ (8 * (unsigned int)v6);
}
while ( a1 != v3 );
return result;
}

original_code:
uint16_t count_crc16(void *mem, int len)
{
  uint16_t a, crc16;
  uint8_t *pch;
  pch = (uint8_t *)mem;
  crc16 = 0;
  while(len--)
  {
    crc16 ^= *pch;
    a = (crc16 ^ (crc16 << 4)) & 0x00FF;
    crc16 = (crc16 >> 8) ^ (a << 8) ^ (a << 3) ^ (a >> 4);
    ++pch;
  }
  return(crc16);
}

canonical_original_code:
unsigned short count_crc16(void *mem, int len)
{
  unsigned short a; unsigned short crc16;
  unsigned char *pch;
  pch = (unsigned char *)mem;
  crc16 = 0;
  while(len--)
  {
    crc16 ^= *pch;
    a = (crc16 ^ (crc16 << 4)) & 0x00FF;
    crc16 = (crc16 >> 8) ^ (a << 8) ^ (a << 3) ^ (a >> 4);
    ++pch;
  }
  return(crc16);
}

variable_types:
mem
void *

variable_types: len int

variable_types:
a
unsigned short

variable_types:
pch
unsigned char *

return_type: unsigned short


decompiled_code:
__int64 __fastcall is_debug_handle_internal(int a1)
{
int *v1; // rax

if ( debug_handles_count <= 0 )
return 0LL;
v1 = &debug_handles;
while ( *v1 != a1 )
{
v1 += 38;
if ( v1 == (int *)((char *)&unk_FD8 + 152 * (unsigned int)(debug_handles_count - 1)) )
return 0LL;
}
return 1LL;
}

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

if ( debug_handles_count <= 0 )
return 0LL;
v1 = &debug_handles;
while ( *v1 != a1 )
{
v1 += 38;
if ( v1 == (int *)((char *)&unk_FD8 + 152 * (unsigned int)(debug_handles_count - 1)) )
return 0LL;
}
return 1LL;
}

original_code:
static int is_debug_handle_internal(int fd)
{
    int i;
    for ( i = 0; i < debug_handles_count; ++i )
        if ( debug_handles[i].fd == fd )
            return 1;
    return 0;
}

variable_types: fd int

variable_types: i int


decompiled_code:
__int64 __fastcall remove_debug_handle_internal(int a1)
{
int *v1; // rax
int v2; // edx
int v3; // ecx
int *v4; // rax
int *v5; // rdi
__m128i *v6; // rdx
__m128i v7; // xmm0

if ( debug_handles_count <= 0 )
return 0LL;
v1 = debug_handles;
v2 = 0;
while ( 1 )
{
++v2;
if ( *v1 == a1 )
break;
v1 += 38;
if ( debug_handles_count == v2 )
return 0LL;
}
if ( debug_handles_count <= v2 )
{
v3 = debug_handles_count - 1;
}
else
{
v3 = debug_handles_count - 1;
v4 = (int *)((char *)&unk_EA8 + 152 * v2);
v5 = &debug_handles[38 * (unsigned int)(debug_handles_count - 1 - v2) + 38 * (__int64)v2];
do
{
v6 = (__m128i *)v4;
v7 = _mm_loadu_si128((const __m128i *)(v4 + 38));
v4 += 38;
*v6 = v7;
v6[1] = _mm_loadu_si128((const __m128i *)v4 + 1);
v6[2] = _mm_loadu_si128((const __m128i *)v4 + 2);
v6[3] = _mm_loadu_si128((const __m128i *)v4 + 3);
v6[4] = _mm_loadu_si128((const __m128i *)v4 + 4);
v6[5] = _mm_loadu_si128((const __m128i *)v4 + 5);
v6[6] = _mm_loadu_si128((const __m128i *)v4 + 6);
v6[7] = _mm_loadu_si128((const __m128i *)v4 + 7);
v6[8] = _mm_loadu_si128((const __m128i *)v4 + 8);
v6[9].m128i_i64[0] = *((_QWORD *)v4 + 18);
}
while ( v4 != v5 );
}
debug_handles_count = v3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int *v1; // rax
int v2; // edx
int v3; // ecx
int *v4; // rax
int *v5; // rdi
__m128i *v6; // rdx
__m128i v7; // xmm0

if ( debug_handles_count <= 0 )
return 0LL;
v1 = debug_handles;
v2 = 0;
while ( 1 )
{
++v2;
if ( *v1 == a1 )
break;
v1 += 38;
if ( debug_handles_count == v2 )
return 0LL;
}
if ( debug_handles_count <= v2 )
{
v3 = debug_handles_count - 1;
}
else
{
v3 = debug_handles_count - 1;
v4 = (int *)((char *)&unk_EA8 + 152 * v2);
v5 = &debug_handles[38 * (unsigned int)(debug_handles_count - 1 - v2) + 38 * (__int64)v2];
do
{
v6 = (__m128i *)v4;
v7 = _mm_loadu_si128((const __m128i *)(v4 + 38));
v4 += 38;
*v6 = v7;
v6[1] = _mm_loadu_si128((const __m128i *)v4 + 1);
v6[2] = _mm_loadu_si128((const __m128i *)v4 + 2);
v6[3] = _mm_loadu_si128((const __m128i *)v4 + 3);
v6[4] = _mm_loadu_si128((const __m128i *)v4 + 4);
v6[5] = _mm_loadu_si128((const __m128i *)v4 + 5);
v6[6] = _mm_loadu_si128((const __m128i *)v4 + 6);
v6[7] = _mm_loadu_si128((const __m128i *)v4 + 7);
v6[8] = _mm_loadu_si128((const __m128i *)v4 + 8);
v6[9].m128i_i64[0] = *((_QWORD *)v4 + 18);
}
while ( v4 != v5 );
}
debug_handles_count = v3;
return 1LL;
}

original_code:
static int remove_debug_handle_internal(int fd)
{
    int i, ii;
    for ( i = 0; i < debug_handles_count; ++i )
    {
        if ( debug_handles[i].fd == fd )
        {
            for ( ii = i+1; ii < debug_handles_count; ++ii )
             memcpy(&debug_handles[ii - 1], &debug_handles[ii], sizeof(debug_handles_t));
            --debug_handles_count;
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
static int remove_debug_handle_internal(int fd)
{
    int i; int ii;
    for ( i = 0; i < debug_handles_count; ++i )
    {
        if ( debug_handles[i].fd == fd )
        {
            for ( ii = i+1; ii < debug_handles_count; ++ii )
             memcpy(&debug_handles[ii - 1], &debug_handles[ii], sizeof(debug_handles_t));
            --debug_handles_count;
            return 1;
        }
    }
    return 0;
}

variable_types: ii int


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

if ( debug_mutex )
{
v0 = 3;
usleep(0x186A0u);
while ( debug_mutex )
{
usleep(0x186A0u);
if ( !--v0 )
{
result = (unsigned int)ap_log_debug_to_tty;
if ( ap_log_debug_to_tty )
{
fwrite("? ap_log: WARNING! stale debug mutex!\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}
}
}
debug_mutex = 1;
return 1LL;
}

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

if ( debug_mutex )
{
v0 = 3;
usleep(0x186A0u);
while ( debug_mutex )
{
usleep(0x186A0u);
if ( !--v0 )
{
result = (unsigned int)ap_log_debug_to_tty;
if ( ap_log_debug_to_tty )
{
fwrite("? ap_log: WARNING! stale debug mutex!\n", 1uLL, 0x26uLL, stderr);
result = 0LL;
}
return result;
}
}
}
debug_mutex = 1;
return 1LL;
}

original_code:
int ap_log_get_lock(void)
{
    int i;
    for(i = 0; debug_mutex; ++i)
    {
        usleep(100000);
        if (i == 3)
        {
            if ( ap_log_debug_to_tty )
                fputs("? ap_log: WARNING! stale debug mutex!\n", stderr);
            return 0;
        }
    }
    ++debug_mutex;
    return 1;
}

canonical_original_code:
int ap_log_get_lock()
{
    int i;
    for(i = 0; debug_mutex; ++i)
    {
        usleep(100000);
        if (i == 3)
        {
            if ( ap_log_debug_to_tty )
                fputs("? ap_log: WARNING! stale debug mutex!\n", stderr);
            return 0;
        }
    }
    ++debug_mutex;
    return 1;
}


decompiled_code:
void ap_log_release_lock()
{
debug_mutex = 0;
}

canonical_decompiled_code:
void func3()
{
debug_mutex = 0;
}

original_code:
void ap_log_release_lock(void)
{
    debug_mutex = 0;
}