decompiled_code:
__int64 __fastcall futex_release(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

result = atomic_get_and_set_int(a1, 0);
if ( (_DWORD)result == 2 )
{
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(volatile __int32 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp-10h] [rbp-18h]

result = func0(a1, 0);
if ( (_DWORD)result == 2 )
{
syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
result = v2;
}
return result;
}

original_code:
inline static void futex_release(futex_lock_t* lock)
{
 int v;
 do {} while(0);
 v=atomic_get_and_set_int(&(lock)->val, 0);
 if (__builtin_expect(!!(v==2), 0)){
  syscall(202 , (&(lock)->val), (1), (1), (0), (0), (0));
 }
}

canonical_original_code:
inline static void futex_release(struct atomic_t *lock)
{
 int v;
 do {} while(0);
 v=atomic_get_and_set_int(&(lock)->val, 0);
 if (__builtin_expect(!!(v==2), 0)){
  syscall(202 , (&(lock)->val), (1), (1), (0), (0), (0));
 }
}

variable_types:
lock
struct atomic_t { int val; } *


repo: virtualolson/who

decompiled_code:
__int64 __fastcall futex_get(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ecx

result = atomic_cmpxchg_int_constprop_0(a1);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
{
do
{
LABEL_24:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = atomic_get_and_set_int(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = atomic_cmpxchg_int_constprop_0(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
if ( v2 == 7 )
{
for ( result = atomic_get_and_set_int(a1, 2); (_DWORD)result; result = atomic_get_and_set_int(a1, 2) )
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
return result;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ecx

result = func6(a1);
if ( (_DWORD)result )
{
if ( (_DWORD)result == 2 )
{
do
{
LABEL_24:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = func0(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func6(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
if ( v2 == 7 )
{
for ( result = func0(a1, 2); (_DWORD)result; result = func0(a1, 2) )
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
return result;
}
}
}
}
return result;
}

original_code:
inline static void futex_get(futex_lock_t* lock)
{
 int v;
 register int i=1024;
retry:
 v=atomic_cmpxchg_int(&(lock)->val, 0, 1);
 if (__builtin_expect(!!(v==0), 1)){
  do {} while(0);
  return;
 }else if (__builtin_expect(!!(v==2), 0)){
  do{
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }while(v);
 }else{
  if (i>0){
   i--;
   goto retry;
  }
  v=atomic_get_and_set_int(&(lock)->val, 2);
  while(v){
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }
 }
 do {} while(0);
}

canonical_original_code:
inline static void futex_get(struct atomic_t *lock)
{
 int v;
 register int i = 1024;
retry:
 v=atomic_cmpxchg_int(&(lock)->val, 0, 1);
 if (__builtin_expect(!!(v==0), 1)){
  do {} while(0);
  return;
 }else if (__builtin_expect(!!(v==2), 0)){
  do{
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }while(v);
 }else{
  if (i>0){
   i--;
   goto retry;
  }
  v=atomic_get_and_set_int(&(lock)->val, 2);
  while(v){
   syscall(202 , (&(lock)->val), (0), (2), (0), (0), (0));
   v=atomic_get_and_set_int(&(lock)->val, 2);
  }
 }
 do {} while(0);
}

variable_types: v int

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall create_xpidf_document(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er13
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !a2 )
return (unsigned int)-1;
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( !a3 )
{
if ( a1 )
goto LABEL_5;
return (unsigned int)-1;
}
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
if ( !a1 || (int)str_dup_zt(a3, "application/xpidf+xml;charset=\"UTF-8\"") < 0 )
return (unsigned int)-1;
LABEL_5:
dstr_init(v6, 2048LL);
dstr_append_zt(v6, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
dstr_append_zt(v6, "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\r\n");
doc_add_presentity((__int64)v6, a1);
v4 = dstr_get_str(v6, a2);
dstr_destroy(v6);
if ( v4 )
{
if ( *(int *)(a2 + 8) > 0 && *(_QWORD *)a2 )
{
futex_get(mem_lock);
qm_free(shm_block, *(_QWORD *)a2);
futex_release(mem_lock);
}
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( a3 )
{
if ( *(int *)(a3 + 8) > 0 && *(_QWORD *)a3 )
{
futex_get(mem_lock);
qm_free(shm_block, *(_QWORD *)a3);
futex_release(mem_lock);
}
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er13
_BYTE v6[72]; // [rsp+0h] [rbp-48h] BYREF

if ( !a2 )
return (unsigned int)-1;
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( !a3 )
{
if ( a1 )
goto LABEL_5;
return (unsigned int)-1;
}
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
if ( !a1 || (int)str_dup_zt(a3, "application/xpidf+xml;charset=\"UTF-8\"") < 0 )
return (unsigned int)-1;
LABEL_5:
dstr_init(v6, 2048LL);
dstr_append_zt(v6, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
dstr_append_zt(v6, "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\r\n");
func5((__int64)v6, a1);
v4 = dstr_get_str(v6, a2);
dstr_destroy(v6);
if ( v4 )
{
if ( *(int *)(a2 + 8) > 0 && *(_QWORD *)a2 )
{
func7(mem_lock);
qm_free(shm_block, *(_QWORD *)a2);
func3(mem_lock);
}
*(_DWORD *)(a2 + 8) = 0;
*(_QWORD *)a2 = 0LL;
if ( a3 )
{
if ( *(int *)(a3 + 8) > 0 && *(_QWORD *)a3 )
{
func7(mem_lock);
qm_free(shm_block, *(_QWORD *)a3);
func3(mem_lock);
}
*(_DWORD *)(a3 + 8) = 0;
*(_QWORD *)a3 = 0LL;
}
}
return v4;
}

original_code:
int create_xpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type)
{
 dstring_t buf;
 int err = 0;
 if (!dst) return -1;
 do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
 if (dst_content_type) do { if (dst_content_type != ((void *)0)) { (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 if (!p) return -1;
 if (dst_content_type)
  if (str_dup_zt(dst_content_type, "application/xpidf+xml;charset=\"UTF-8\"") < 0) {
   return -1;
  }
 dstr_init(&buf, 2048);
 dstr_append_zt(&buf, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
 dstr_append_zt(&buf, "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\r\n");
 doc_add_presentity(&buf, p);
 err = dstr_get_str(&buf, dst);
 dstr_destroy(&buf);
 if (err != 0) {
  do { if (dst != ((void *)0)) { if (((dst)->len > 0) && ((dst)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst)->s)); futex_release(mem_lock); }while(0); (dst)->len = 0; (dst)->s = 0; } } while (0);
  if (dst_content_type) do { if (dst_content_type != ((void *)0)) { if (((dst_content_type)->len > 0) && ((dst_content_type)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst_content_type)->s)); futex_release(mem_lock); }while(0); (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 }
 return err;
}

canonical_original_code:
int create_xpidf_document(struct presentity_info_t *p, struct _str *dst, struct _str *dst_content_type)
{
 struct _dstring_t buf;
 int err = 0;
 if (!dst) return -1;
 do { if (dst != ((void *)0)) { (dst)->len = 0; (dst)->s = 0; } } while (0);
 if (dst_content_type) do { if (dst_content_type != ((void *)0)) { (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 if (!p) return -1;
 if (dst_content_type)
  if (str_dup_zt(dst_content_type, "application/xpidf+xml;charset=\"UTF-8\"") < 0) {
   return -1;
  }
 dstr_init(&buf, 2048);
 dstr_append_zt(&buf, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
 dstr_append_zt(&buf, "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\r\n");
 doc_add_presentity(&buf, p);
 err = dstr_get_str(&buf, dst);
 dstr_destroy(&buf);
 if (err != 0) {
  do { if (dst != ((void *)0)) { if (((dst)->len > 0) && ((dst)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst)->s)); futex_release(mem_lock); }while(0); (dst)->len = 0; (dst)->s = 0; } } while (0);
  if (dst_content_type) do { if (dst_content_type != ((void *)0)) { if (((dst_content_type)->len > 0) && ((dst_content_type)->s)) do { futex_get(mem_lock); qm_free(shm_block, ((dst_content_type)->s)); futex_release(mem_lock); }while(0); (dst_content_type)->len = 0; (dst_content_type)->s = 0; } } while (0);
 }
 return err;
}

variable_types: struct presentity_info_t { struct _str { char *s; int len; } uri; struct _presence_tuple_info_t { struct _str contact; struct _str id; double priority; struct presence_tuple_status_t { enum basic_tuple_status_t { presence_tuple_open=0, presence_tuple_closed=1, presence_tuple_undefined_status=2 } basic; struct _extension_element_t { struct _str element; struct _extension_element_t *next; } *first_unknown_element; } status; struct _extension_element_t *first_unknown_element; struct _presence_tuple_info_t *next; struct _presence_note_t { struct _str value; struct _str lang; struct _presence_note_t *prev; } *first_note; } *first_tuple; struct _presence_note_t *first_note; struct _extension_element_t *first_unknown_element; char presentity_data[1]; } *

variable_types:
dst
struct _str *

variable_types: struct _dstring_t { struct _dstr_buff_t { int len; int used; struct _dstr_buff_t *next; char data[1]; } *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

variable_types: err int

return_type: int

user_defined_types: struct _dstring_t { struct _dstr_buff_t *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: struct presentity_info_t { struct _str uri; struct _presence_tuple_info_t *first_tuple; struct _presence_note_t *first_note; struct _extension_element_t *first_unknown_element; char presentity_data[1]; }

user_defined_types: struct _presence_tuple_info_t { struct _str contact; struct _str id; double priority; struct presence_tuple_status_t status; struct _extension_element_t *first_unknown_element; struct _presence_tuple_info_t *next; struct _presence_note_t *first_note; }

user_defined_types: struct presence_tuple_status_t { enum basic_tuple_status_t basic; struct _extension_element_t *first_unknown_element; }


original_code:
static inline void trim_leading(str* _s)
{
 for(; _s->len > 0; _s->len--, _s->s++) {
  switch(*(_s->s)) { case ' ': case '\t': case '\r': case '\n': break; default: return; };
 }
}

canonical_original_code:
static inline void trim_leading(struct _str *_s)
{
 for(; _s->len > 0; _s->len--, _s->s++) {
  switch(*(_s->s)) { case ' ': case '\t': case '\r': case '\n': break; default: return; };
 }
}


original_code:
static inline void trim_trailing(str* _s)
{
 for(; _s->len > 0; _s->len--) {
  switch(_s->s[_s->len - 1]) { case ' ': case '\t': case '\r': case '\n': break; default: return; };
 }
}

canonical_original_code:
static inline void trim_trailing(struct _str *_s)
{
 for(; _s->len > 0; _s->len--) {
  switch(_s->s[_s->len - 1]) { case ' ': case '\t': case '\r': case '\n': break; default: return; };
 }
}


original_code:
static inline int parse_quoted(str* _s, str* _r)
{
 char* end_quote;
 if (_s->len < 2) {
  return -1;
 }
 _s->s++;
 _s->len--;
 end_quote = q_memchr(_s->s, '\"', _s->len);
 if (!end_quote) {
  return -2;
 }
 _r->s = _s->s;
 _r->len = end_quote - _s->s;
 _s->len -= (end_quote - _s->s + 1);
 _s->s = end_quote + 1;
 return 0;
}

canonical_original_code:
static inline int parse_quoted(struct _str *_s, struct _str *_r)
{
 char *end_quote;
 if (_s->len < 2) {
  return -1;
 }
 _s->s++;
 _s->len--;
 end_quote = q_memchr(_s->s, '\"', _s->len);
 if (!end_quote) {
  return -2;
 }
 _r->s = _s->s;
 _r->len = end_quote - _s->s;
 _s->len -= (end_quote - _s->s + 1);
 _s->s = end_quote + 1;
 return 0;
}


original_code:
static inline int parse_token(str* _s, str* _r)
{
 int i;
 _r->s = _s->s;
 for(i = 0; i < _s->len; i++) {
  switch(_s->s[i]) {
  case ' ':
  case '\t':
  case '\r':
  case '\n':
  case ',':
   goto out;
  }
 }
 out:
 if (i == 0) {
         return -2;
 }
        _r->len = i;
 _s->s = _s->s + i;
 _s->len -= i;
 return 0;
}

canonical_original_code:
static inline int parse_token(struct _str *_s, struct _str *_r)
{
 int i;
 _r->s = _s->s;
 for(i = 0; i < _s->len; i++) {
  switch(_s->s[i]) {
  case ' ':
  case '\t':
  case '\r':
  case '\n':
  case ',':
   goto out;
  }
 }
 out:
 if (i == 0) {
         return -2;
 }
        _r->len = i;
 _s->s = _s->s + i;
 _s->len -= i;
 return 0;
}


original_code:
static inline void parse_username(struct username* _u)
{
 char* d;
 _u->user = _u->whole;
 if (_u->whole.len <= 2) return;
 d = q_memchr(_u->whole.s, '@', _u->whole.len);
 if (d) {
  _u->domain.s = d + 1;
  _u->domain.len = _u->whole.len - (d - _u->whole.s) - 1;
  _u->user.len = d - _u->user.s;
 }
}

canonical_original_code:
static inline void parse_username(struct username *_u)
{
 char *d;
 _u->user = _u->whole;
 if (_u->whole.len <= 2) return;
 d = q_memchr(_u->whole.s, '@', _u->whole.len);
 if (d) {
  _u->domain.s = d + 1;
  _u->domain.len = _u->whole.len - (d - _u->whole.s) - 1;
  _u->user.len = d - _u->user.s;
 }
}

variable_types: struct username { struct _str { char *s; int len; } whole; struct _str user; struct _str domain; } *

variable_types:
d
char *

user_defined_types: struct username { struct _str whole; struct _str user; struct _str domain; }


decompiled_code:
void __fastcall parse_algorithm(__int64 a1)
{
int v1; // edx
char *s1; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+8h] [rbp-10h]

v1 = *(_DWORD *)(a1 + 8);
s1 = *(char **)a1;
v3 = v1;
trim((__int64 *)&s1);
if ( v3 != 3 )
{
if ( v3 == 8 && !strncasecmp(s1, "MD5-sess", 8uLL) )
{
*(_DWORD *)(a1 + 16) = 2;
return;
}
LABEL_3:
*(_DWORD *)(a1 + 16) = 4;
return;
}
if ( strncasecmp(s1, "MD5", 3uLL) )
goto LABEL_3;
*(_DWORD *)(a1 + 16) = 1;
}

original_code:
static inline void parse_algorithm(struct algorithm* _a)
{
 str s;
 s.s = _a->alg_str.s;
 s.len = _a->alg_str.len;
 trim(&s);
 if ((s.len == 3) &&
     !strncasecmp(s.s, "MD5", 3)) {
  _a->alg_parsed = ALG_MD5;
 } else if ((s.len == 8) &&
     !strncasecmp(s.s, "MD5-sess", 8)) {
  _a->alg_parsed = ALG_MD5SESS;
 } else {
  _a->alg_parsed = ALG_OTHER;
 }
}

canonical_original_code:
static inline void parse_algorithm(struct algorithm *_a)
{
 struct _str s;
 s.s = _a->alg_str.s;
 s.len = _a->alg_str.len;
 trim(&s);
 if ((s.len == 3) &&
     !strncasecmp(s.s, "MD5", 3)) {
  _a->alg_parsed = ALG_MD5;
 } else if ((s.len == 8) &&
     !strncasecmp(s.s, "MD5-sess", 8)) {
  _a->alg_parsed = ALG_MD5SESS;
 } else {
  _a->alg_parsed = ALG_OTHER;
 }
}

variable_types: struct algorithm { struct _str { char *s; int len; } alg_str; enum alg { ALG_UNSPEC=0, ALG_MD5=1, ALG_MD5SESS=2, ALG_OTHER=4 } alg_parsed; } *

variable_types:
s
struct _str { char *s; int len; }

user_defined_types: struct algorithm { struct _str alg_str; enum alg alg_parsed; }


decompiled_code:
__int64 __fastcall parse_digest_param(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (int)parse_param_name(a1, v3) < 0 )
return 0xFFFFFFFFLL;
++*(_QWORD *)a1;
--*(_DWORD *)(a1 + 8);
trim_leading(a1);
if ( !*(_DWORD *)(a1 + 8) )
return 4294967294LL;
switch ( v3[0] )
{
case 0:
break;
case 1:
a2 += 48LL;
break;
case 2:
a2 += 64LL;
break;
case 3:
a2 += 80LL;
break;
case 4:
a2 += 96LL;
break;
case 5:
a2 += 136LL;
break;
case 6:
a2 += 152LL;
break;
case 7:
a2 += 168LL;
break;
case 8:
a2 += 192LL;
break;
case 9:
a2 += 112LL;
break;
default:
JUMPOUT(0xA63LL);
}
if ( **(_BYTE **)a1 == 34 )
{
if ( (int)parse_quoted((__int64 *)a1, a2) >= 0 )
return 0LL;
result = 4294967293LL;
}
else
{
if ( (int)parse_token(a1, a2) >= 0 )
return 0LL;
result = 4294967292LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v3[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( (int)parse_param_name(a1, v3) < 0 )
return 0xFFFFFFFFLL;
++*(_QWORD *)a1;
--*(_DWORD *)(a1 + 8);
func0(a1);
if ( !*(_DWORD *)(a1 + 8) )
return 4294967294LL;
switch ( v3[0] )
{
case 0:
break;
case 1:
a2 += 48LL;
break;
case 2:
a2 += 64LL;
break;
case 3:
a2 += 80LL;
break;
case 4:
a2 += 96LL;
break;
case 5:
a2 += 136LL;
break;
case 6:
a2 += 152LL;
break;
case 7:
a2 += 168LL;
break;
case 8:
a2 += 192LL;
break;
case 9:
a2 += 112LL;
break;
default:
JUMPOUT(0xA63LL);
}
if ( **(_BYTE **)a1 == 34 )
{
if ( (int)func4((__int64 *)a1, a2) >= 0 )
return 0LL;
result = 4294967293LL;
}
else
{
if ( (int)func5(a1, a2) >= 0 )
return 0LL;
result = 4294967292LL;
}
return result;
}

original_code:
static inline int parse_digest_param(str* _s, dig_cred_t* _c)
{
 dig_par_t t;
 str* ptr;
 str dummy;
 if (parse_param_name(_s, &t) < 0) {
  return -1;
 }
 _s->s++;
 _s->len--;
 trim_leading(_s);
 if (_s->len == 0) {
  return -2;
 }
 switch(t) {
 case PAR_USERNAME: ptr = &_c->username.whole; break;
 case PAR_REALM: ptr = &_c->realm; break;
 case PAR_NONCE: ptr = &_c->nonce; break;
 case PAR_URI: ptr = &_c->uri; break;
 case PAR_RESPONSE: ptr = &_c->response; break;
 case PAR_CNONCE: ptr = &_c->cnonce; break;
 case PAR_OPAQUE: ptr = &_c->opaque; break;
 case PAR_QOP: ptr = &_c->qop.qop_str; break;
 case PAR_NC: ptr = &_c->nc; break;
 case PAR_ALGORITHM: ptr = &_c->alg.alg_str; break;
 case PAR_OTHER: ptr = &dummy; break;
 default: ptr = &dummy; break;
 }
 if (_s->s[0] == '\"') {
  if (parse_quoted(_s, ptr) < 0) {
   return -3;
  }
 } else {
  if (parse_token(_s, ptr) < 0) {
   return -4;
  }
 }
 return 0;
}

canonical_original_code:
static inline int parse_digest_param(struct _str *_s, struct dig_cred *_c)
{
 enum dig_par t;
 struct _str *ptr;
 struct _str dummy;
 if (parse_param_name(_s, &t) < 0) {
  return -1;
 }
 _s->s++;
 _s->len--;
 trim_leading(_s);
 if (_s->len == 0) {
  return -2;
 }
 switch(t) {
 case PAR_USERNAME: ptr = &_c->username.whole; break;
 case PAR_REALM: ptr = &_c->realm; break;
 case PAR_NONCE: ptr = &_c->nonce; break;
 case PAR_URI: ptr = &_c->uri; break;
 case PAR_RESPONSE: ptr = &_c->response; break;
 case PAR_CNONCE: ptr = &_c->cnonce; break;
 case PAR_OPAQUE: ptr = &_c->opaque; break;
 case PAR_QOP: ptr = &_c->qop.qop_str; break;
 case PAR_NC: ptr = &_c->nc; break;
 case PAR_ALGORITHM: ptr = &_c->alg.alg_str; break;
 case PAR_OTHER: ptr = &dummy; break;
 default: ptr = &dummy; break;
 }
 if (_s->s[0] == '\"') {
  if (parse_quoted(_s, ptr) < 0) {
   return -3;
  }
 } else {
  if (parse_token(_s, ptr) < 0) {
   return -4;
  }
 }
 return 0;
}

variable_types: struct dig_cred { struct username { struct _str whole; struct _str user; struct _str domain; } username; struct _str realm; struct _str nonce; struct _str uri; struct _str response; struct algorithm { struct _str alg_str; enum alg { ALG_UNSPEC=0, ALG_MD5=1, ALG_MD5SESS=2, ALG_OTHER=4 } alg_parsed; } alg; struct _str cnonce; struct _str opaque; struct qp { struct _str qop_str; enum qop_type { QOP_UNSPEC=0, QOP_AUTH=1, QOP_AUTHINT=2, QOP_OTHER=4 } qop_parsed; } qop; struct _str nc; } *

variable_types: enum dig_par { PAR_USERNAME=0, PAR_REALM=1, PAR_NONCE=2, PAR_URI=3, PAR_RESPONSE=4, PAR_CNONCE=5, PAR_OPAQUE=6, PAR_QOP=7, PAR_NC=8, PAR_ALGORITHM=9, PAR_OTHER=10 }

variable_types:
ptr
struct _str { char *s; int len; } *

variable_types:
dummy
struct _str { char *s; int len; }

user_defined_types: struct dig_cred { struct username username; struct _str realm; struct _str nonce; struct _str uri; struct _str response; struct algorithm alg; struct _str cnonce; struct _str opaque; struct qp qop; struct _str nc; }

user_defined_types: struct qp { struct _str qop_str; enum qop_type qop_parsed; }


decompiled_code:
void __fastcall parse_qop(__int64 a1)
{
int v1; // edx
char *s1; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+8h] [rbp-10h]

v1 = *(_DWORD *)(a1 + 8);
s1 = *(char **)a1;
v3 = v1;
trim((__int64 *)&s1);
if ( !v3 )
{
*(_DWORD *)(a1 + 16) = 0;
return;
}
if ( v3 == 4 )
{
if ( !strncasecmp(s1, "auth", 4uLL) )
{
*(_DWORD *)(a1 + 16) = 1;
return;
}
LABEL_5:
*(_DWORD *)(a1 + 16) = 4;
return;
}
if ( v3 != 8 || strncasecmp(s1, "auth-int", 8uLL) )
goto LABEL_5;
*(_DWORD *)(a1 + 16) = 2;
}

original_code:
void parse_qop(struct qp* _q)
{
 str s;
 s.s = _q->qop_str.s;
 s.len = _q->qop_str.len;
 trim(&s);
 if (s.len == 0) {
     _q->qop_parsed = QOP_UNSPEC;
 } else if ((s.len == 4) &&
     !strncasecmp(s.s, "auth", 4)) {
  _q->qop_parsed = QOP_AUTH;
 } else if ((s.len == 8) &&
     !strncasecmp(s.s, "auth-int", 8)) {
  _q->qop_parsed = QOP_AUTHINT;
 } else {
  _q->qop_parsed = QOP_OTHER;
 }
}

canonical_original_code:
void parse_qop(struct qp *_q)
{
 struct _str s;
 s.s = _q->qop_str.s;
 s.len = _q->qop_str.len;
 trim(&s);
 if (s.len == 0) {
     _q->qop_parsed = QOP_UNSPEC;
 } else if ((s.len == 4) &&
     !strncasecmp(s.s, "auth", 4)) {
  _q->qop_parsed = QOP_AUTH;
 } else if ((s.len == 8) &&
     !strncasecmp(s.s, "auth-int", 8)) {
  _q->qop_parsed = QOP_AUTHINT;
 } else {
  _q->qop_parsed = QOP_OTHER;
 }
}

variable_types: struct qp { struct _str { char *s; int len; } qop_str; enum qop_type { QOP_UNSPEC=0, QOP_AUTH=1, QOP_AUTHINT=2, QOP_OTHER=4 } qop_parsed; } *


decompiled_code:
__int64 __fastcall parse_digest_params(__int64 a1, const __m128i *a2)
{
int v2; // ebp
char *v3; // r13
char *v4; // rax
unsigned int v5; // ebx

if ( (int)parse_digest_param(a1, (__int64)a2) < 0 )
return (unsigned int)-1;
while ( 1 )
{
v2 = *(_DWORD *)(a1 + 8);
v3 = *(char **)a1;
v4 = q_memchr(*(char **)a1, 44, v2);
if ( !v4 )
break;
*(_QWORD *)a1 = v4 + 1;
*(_DWORD *)(a1 + 8) = v2 - 1 - ((_DWORD)v4 - (_DWORD)v3);
trim_leading(a1);
if ( (int)parse_digest_param(a1, (__int64)a2) < 0 )
return (unsigned int)-1;
}
if ( a2[10].m128i_i64[1] )
parse_qop((__int64)&a2[10].m128i_i64[1]);
if ( a2[7].m128i_i64[0] )
parse_algorithm((__int64)a2[7].m128i_i64);
v5 = 0;
if ( !a2->m128i_i64[0] )
return v5;
parse_username(a2);
return 0LL;
}

original_code:
static inline int parse_digest_params(str* _s, dig_cred_t* _c)
{
 char* comma;
 do {
  if (parse_digest_param(_s, _c) < 0) {
   return -1;
  }
  comma = q_memchr(_s->s, ',', _s->len);
  if (comma) {
   _s->len -= comma - _s->s + 1;
   _s->s = comma + 1;
   trim_leading(_s);
  }
 } while(comma);
 if (_c->qop.qop_str.s != 0) {
  parse_qop(&_c->qop);
 }
 if (_c->alg.alg_str.s != 0) {
  parse_algorithm(&_c->alg);
 }
 if (_c->username.whole.s != 0) {
  parse_username(&_c->username);
 }
 return 0;
}

canonical_original_code:
static inline int parse_digest_params(struct _str *_s, struct dig_cred *_c)
{
 char *comma;
 do {
  if (parse_digest_param(_s, _c) < 0) {
   return -1;
  }
  comma = q_memchr(_s->s, ',', _s->len);
  if (comma) {
   _s->len -= comma - _s->s + 1;
   _s->s = comma + 1;
   trim_leading(_s);
  }
 } while(comma);
 if (_c->qop.qop_str.s != 0) {
  parse_qop(&_c->qop);
 }
 if (_c->alg.alg_str.s != 0) {
  parse_algorithm(&_c->alg);
 }
 if (_c->username.whole.s != 0) {
  parse_username(&_c->username);
 }
 return 0;
}

variable_types:
comma
char *

user_defined_types: enum alg { ALG_UNSPEC=0, ALG_MD5=1, ALG_MD5SESS=2, ALG_OTHER=4 }

user_defined_types: enum qop_type { QOP_UNSPEC=0, QOP_AUTH=1, QOP_AUTHINT=2, QOP_OTHER=4 }


decompiled_code:
__int64 __fastcall parse_digest_cred(__int64 a1, const __m128i *a2)
{
unsigned int v2; // er12
int v4; // edx
int v5; // ebx
char *v6; // r14
unsigned __int64 v7; // rcx
__int64 v8; // rsi
char *s1; // [rsp+0h] [rbp-38h] BYREF
int v11; // [rsp+8h] [rbp-30h]

v2 = 1;
v4 = *(_DWORD *)(a1 + 8);
s1 = *(char **)a1;
v11 = v4;
trim_leading((__int64)&s1);
v5 = v11;
if ( v11 > 6 )
{
v6 = s1;
if ( !strncasecmp(s1, "digest", 6uLL) )
{
v7 = (unsigned __int8)v6[6];
if ( (unsigned __int8)v7 <= 0x2Cu )
{
v8 = 0x100100002600LL;
if ( _bittest64(&v8, v7) )
{
v2 = -2;
s1 = v6 + 7;
v11 = v5 - 7;
trim_leading((__int64)&s1);
if ( (int)parse_digest_params((__int64)&s1, a2) >= 0 )
v2 = 0;
}
}
}
}
return v2;
}

original_code:
int parse_digest_cred(str* _s, dig_cred_t* _c)
{
 str tmp;
 tmp.s = _s->s;
 tmp.len = _s->len;
 trim_leading(&tmp);
 if (tmp.len < (6 + 1)) return 1;
 if (!strncasecmp(tmp.s, "digest", 6) &&
     ((tmp.s[6] == ' ') ||
      (tmp.s[6] == '\r') ||
      (tmp.s[6] == '\n') ||
      (tmp.s[6] == '\t') ||
      (tmp.s[6] == ','))) {
  tmp.s += 6 + 1;
  tmp.len -= 6 + 1;
  trim_leading(&tmp);
  if (parse_digest_params(&tmp, _c) < 0) {
   return -2;
  } else {
   return 0;
  }
 } else {
  return 1;
 }
}

canonical_original_code:
int parse_digest_cred(struct _str *_s, struct dig_cred *_c)
{
 struct _str tmp;
 tmp.s = _s->s;
 tmp.len = _s->len;
 trim_leading(&tmp);
 if (tmp.len < (6 + 1)) return 1;
 if (!strncasecmp(tmp.s, "digest", 6) &&
     ((tmp.s[6] == ' ') ||
      (tmp.s[6] == '\r') ||
      (tmp.s[6] == '\n') ||
      (tmp.s[6] == '\t') ||
      (tmp.s[6] == ','))) {
  tmp.s += 6 + 1;
  tmp.len -= 6 + 1;
  trim_leading(&tmp);
  if (parse_digest_params(&tmp, _c) < 0) {
   return -2;
  } else {
   return 0;
  }
 } else {
  return 1;
 }
}

variable_types:
tmp
struct _str { char *s; int len; }


decompiled_code:
__int64 __fastcall init_dig_cred(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0LL;
result = 0LL;
a1[25] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 208) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 result; // rax

*a1 = 0LL;
result = 0LL;
a1[25] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 208) >> 3));
return result;
}

original_code:
void init_dig_cred(dig_cred_t* _c)
{
 memset(_c, 0, sizeof(dig_cred_t));
}

canonical_original_code:
void init_dig_cred(struct dig_cred *_c)
{
 memset(_c, 0, sizeof(dig_cred_t));
}

variable_types: struct dig_cred { struct username { struct _str { char *s; int len; } whole; struct _str user; struct _str domain; } username; struct _str realm; struct _str nonce; struct _str uri; struct _str response; struct algorithm { struct _str alg_str; enum alg { ALG_UNSPEC=0, ALG_MD5=1, ALG_MD5SESS=2, ALG_OTHER=4 } alg_parsed; } alg; struct _str cnonce; struct _str opaque; struct qp { struct _str qop_str; enum qop_type { QOP_UNSPEC=0, QOP_AUTH=1, QOP_AUTHINT=2, QOP_OTHER=4 } qop_parsed; } qop; struct _str nc; } *


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

result = *a1 >> 1;
if ( (*a1 & 1) != 0 )
result = a2 ^ (unsigned int)result;
*a1 = result;
return result;
}

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

result = *a1 >> 1;
if ( (*a1 & 1) != 0 )
result = a2 ^ (unsigned int)result;
*a1 = result;
return result;
}

original_code:
int shift_lfsr(unsigned int *lfsr, unsigned int mask){
 int feedback;
 feedback = *lfsr & 0x1;
 *lfsr >>=1;
 if (feedback == 1)
  *lfsr ^= mask;
 return *lfsr;
}

variable_types:
lfsr
unsigned int *

variable_types:
mask
unsigned int

variable_types: feedback int


decompiled_code:
__pid_t init_lfsr()
{
__pid_t result; // eax

lfsr32 = time(0LL);
result = getpid();
lfsr31 = result;
return result;
}

canonical_decompiled_code:
__pid_t func1()
{
__pid_t result; // eax

lfsr32 = time(0LL);
result = getpid();
lfsr31 = result;
return result;
}

original_code:
void init_lfsr(void){
 lfsr32 = (unsigned int)time(((void *)0));
 lfsr31 = (unsigned int)getpid();
}

canonical_original_code:
void init_lfsr(){
 lfsr32 = (unsigned int)time(((void *)0));
 lfsr31 = (unsigned int)getpid();
}


decompiled_code:
__int64 get_random()
{
int v0; // ebx

v0 = shift_lfsr(&lfsr32, -1262693540);
return v0 ^ (unsigned int)shift_lfsr(&lfsr31, 2052834019);
}

original_code:
int get_random(){
 return (shift_lfsr(&lfsr32, 0xb4bcd35c) ^ shift_lfsr(&lfsr31, 0x7a5bc2e3)) & 0xffffffff;
}


decompiled_code:
__int64 __fastcall sruid_init(__int64 a1, char a2, _BYTE *a3, int a4)
{
char v6; // cl
char v7; // di
char v8; // dl
__int64 v9; // rbp
unsigned int v10; // er15
time_t v11; // rax
int v12; // eax
__int64 v13; // rbp
unsigned int v14; // er12
__int64 v16; // r15
unsigned int v17; // eax
__int64 v18; // r14
const char *v19; // r15
const char *v20; // rbx
unsigned int v21; // eax

if ( !a1 )
return (unsigned int)-1;
*(_QWORD *)(a1 + 64) = 0LL;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_DWORD *)a1 = 1684632179;
*(_OWORD *)(a1 + 32) = 0LL;
*(_OWORD *)(a1 + 48) = 0LL;
if ( a3 )
{
if ( *a3 )
{
*(_BYTE *)a1 = *a3;
v6 = a3[1];
if ( v6 )
{
*(_BYTE *)(a1 + 1) = v6;
v7 = a3[2];
if ( v7 )
{
*(_BYTE *)(a1 + 2) = v7;
v8 = a3[3];
if ( v8 )
*(_BYTE *)(a1 + 3) = v8;
}
}
}
}
*(_BYTE *)(a1 + 4) = a2;
v9 = (unsigned int)a2;
if ( server_id )
{
v16 = (unsigned int)my_pid();
v17 = time(0LL);
v12 = snprintf(
(char *)(a1 + 5),
0x1BuLL,
"%x%c%x%c%x%c",
server_id,
(unsigned int)v9,
v17,
v9,
v16,
(unsigned int)a2);
}
else
{
v10 = my_pid();
v11 = time(0LL);
v12 = snprintf((char *)(a1 + 5), 0x1BuLL, "%x%c%x%c", v11, (unsigned int)v9, v10, (unsigned int)a2);
}
v13 = (unsigned int)(v12 + 5);
*(_QWORD *)(a1 + 48) = a1;
*(_DWORD *)(a1 + 68) = a4;
*(_QWORD *)(a1 + 40) = a1 + (int)v13;
if ( (int)get_debug_level("core", 4LL) <= 2 || (v14 = dprint_crit) != 0 )
return 0;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v18 = *(unsigned int *)(a1 + 64);
v19 = *(const char **)(a1 + 48);
v20 = (const char *)*((_QWORD *)&log_level_info + 16);
v21 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): root for sruid is [%.*s] (%u / %d)\n",
process_no,
v21,
v20,
"<core> [sruid.c:99]: ",
"sruid_init",
v13,
v19,
v18,
v13);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): root for sruid is [%.*s] (%u / %d)\n",
*((_QWORD *)&log_level_info + 16),
"<core> [sruid.c:99]: ",
"sruid_init",
(unsigned int)v13,
*(_QWORD *)(a1 + 48),
*(unsigned int *)(a1 + 64),
v13);
}
--dprint_crit;
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2, _BYTE *a3, int a4)
{
char v6; // cl
char v7; // di
char v8; // dl
__int64 v9; // rbp
unsigned int v10; // er15
time_t v11; // rax
int v12; // eax
__int64 v13; // rbp
unsigned int v14; // er12
__int64 v16; // r15
unsigned int v17; // eax
__int64 v18; // r14
const char *v19; // r15
const char *v20; // rbx
unsigned int v21; // eax

if ( !a1 )
return (unsigned int)-1;
*(_QWORD *)(a1 + 64) = 0LL;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_DWORD *)a1 = 1684632179;
*(_OWORD *)(a1 + 32) = 0LL;
*(_OWORD *)(a1 + 48) = 0LL;
if ( a3 )
{
if ( *a3 )
{
*(_BYTE *)a1 = *a3;
v6 = a3[1];
if ( v6 )
{
*(_BYTE *)(a1 + 1) = v6;
v7 = a3[2];
if ( v7 )
{
*(_BYTE *)(a1 + 2) = v7;
v8 = a3[3];
if ( v8 )
*(_BYTE *)(a1 + 3) = v8;
}
}
}
}
*(_BYTE *)(a1 + 4) = a2;
v9 = (unsigned int)a2;
if ( server_id )
{
v16 = (unsigned int)my_pid();
v17 = time(0LL);
v12 = snprintf(
(char *)(a1 + 5),
0x1BuLL,
"%x%c%x%c%x%c",
server_id,
(unsigned int)v9,
v17,
v9,
v16,
(unsigned int)a2);
}
else
{
v10 = my_pid();
v11 = time(0LL);
v12 = snprintf((char *)(a1 + 5), 0x1BuLL, "%x%c%x%c", v11, (unsigned int)v9, v10, (unsigned int)a2);
}
v13 = (unsigned int)(v12 + 5);
*(_QWORD *)(a1 + 48) = a1;
*(_DWORD *)(a1 + 68) = a4;
*(_QWORD *)(a1 + 40) = a1 + (int)v13;
if ( (int)get_debug_level("core", 4LL) <= 2 || (v14 = dprint_crit) != 0 )
return 0;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v18 = *(unsigned int *)(a1 + 64);
v19 = *(const char **)(a1 + 48);
v20 = (const char *)*((_QWORD *)&log_level_info + 16);
v21 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): root for sruid is [%.*s] (%u / %d)\n",
process_no,
v21,
v20,
"<core> [sruid.c:99]: ",
"sruid_init",
v13,
v19,
v18,
v13);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): root for sruid is [%.*s] (%u / %d)\n",
*((_QWORD *)&log_level_info + 16),
"<core> [sruid.c:99]: ",
"sruid_init",
(unsigned int)v13,
*(_QWORD *)(a1 + 48),
*(unsigned int *)(a1 + 64),
v13);
}
--dprint_crit;
return v14;
}

original_code:
int sruid_init(sruid_t *sid, char sep, char *cid, int mode)
{
 int i;
 if(sid==((void *)0))
  return -1;
 memset(sid, 0, sizeof(sruid_t));
 memcpy(sid->buf, "srid", 4);
 if(cid!=((void *)0))
 {
  for(i=0; i<4 && cid[i]!='\0'; i++)
   sid->buf[i] = cid[i];
 }
 sid->buf[4] = sep;
 if(server_id!=0)
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c%x%c", (unsigned int)server_id, sep,
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 else
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c",
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 if(i<=0 || i>40 -13)
 {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "could not initialize sruid struct - output len: %d\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "could not initialize sruid struct - output len: %d\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not initialize sruid struct - output len: %d\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); } } (dprint_crit--); } } while(0);
  return -1;
 }
 sid->out = sid->buf + i + 5;
 sid->uid.s = sid->buf;
 sid->mode = (sruid_mode_t)mode;
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } (dprint_crit--); } } while(0);
 return 0;
}

canonical_original_code:
int sruid_init(struct sruid *sid, char sep, char *cid, int mode)
{
 int i;
 if(sid==((void *)0))
  return -1;
 memset(sid, 0, sizeof(sruid_t));
 memcpy(sid->buf, "srid", 4);
 if(cid!=((void *)0))
 {
  for(i=0; i<4 && cid[i]!='\0'; i++)
   sid->buf[i] = cid[i];
 }
 sid->buf[4] = sep;
 if(server_id!=0)
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c%x%c", (unsigned int)server_id, sep,
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 else
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c",
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 if(i<=0 || i>40 -13)
 {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "could not initialize sruid struct - output len: %d\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "could not initialize sruid struct - output len: %d\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not initialize sruid struct - output len: %d\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "93" "]: ") , __func__, i); } } (dprint_crit--); } } while(0);
  return -1;
 }
 sid->out = sid->buf + i + 5;
 sid->uid.s = sid->buf;
 sid->mode = (enum sruid_mode_t)mode;
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "99" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } (dprint_crit--); } } while(0);
 return 0;
}

variable_types: struct sruid { char buf[40]; char *out; struct _str { char *s; int len; } uid; unsigned int counter; enum sruid_mode_t { SRUID_INC=0, SRUID_LFSR=1 } mode; } *

variable_types: sep char

variable_types:
cid
char *

variable_types: mode int

variable_types: i int

user_defined_types: struct sruid { char buf[40]; char *out; struct _str uid; unsigned int counter; enum sruid_mode_t mode; }

user_defined_types: struct cfg_group_core { int debug; int log_facility; int memdbg; int use_dst_blacklist; unsigned int blst_timeout; unsigned int blst_max_mem; unsigned int blst_udp_imask; unsigned int blst_tcp_imask; unsigned int blst_tls_imask; unsigned int blst_sctp_imask; int dns_try_ipv6; int dns_try_naptr; int dns_udp_pref; int dns_tcp_pref; int dns_tls_pref; int dns_sctp_pref; int dns_retr_time; int dns_retr_no; int dns_servers_no; int dns_search_list; int dns_search_fmatch; int dns_reinit; int use_dns_cache; int dns_cache_flags; int use_dns_failover; int dns_srv_lb; unsigned int dns_neg_cache_ttl; unsigned int dns_cache_min_ttl; unsigned int dns_cache_max_ttl; unsigned int dns_cache_max_mem; int dns_cache_del_nonexp; int dns_cache_rec_pref; int mem_dump_pkg; int mem_dump_shm; int max_while_loops; int udp_mtu; int udp_mtu_try_proto; int udp4_raw; int udp4_raw_mtu; int udp4_raw_ttl; int force_rport; int memlog; int mem_summary; int mem_safety; int mem_join; int corelog; int latency_log; int latency_limit_db; int latency_limit_action; }


decompiled_code:
__int64 __fastcall sruid_reinit(__int64 a1, int a2)
{
__int64 v2; // rbp
char *v3; // r14
unsigned int v4; // er15
time_t v5; // rax
int v6; // eax
__int64 v7; // rbp
unsigned int v8; // er12
__int64 v10; // r15
unsigned int v11; // eax
__int64 v12; // r14
const char *v13; // r15
const char *v14; // rbx
unsigned int v15; // eax

if ( !a1 )
return (unsigned int)-1;
*(_BYTE *)(a1 + 5) = 0;
v2 = (unsigned int)*(char *)(a1 + 4);
v3 = (char *)(a1 + 5);
if ( server_id )
{
v10 = (unsigned int)my_pid();
v11 = time(0LL);
v6 = snprintf(v3, 0x1BuLL, "%x%c%x%c%x%c", server_id, (unsigned int)v2, v11, v2, v10, v2);
}
else
{
v4 = my_pid();
v5 = time(0LL);
v6 = snprintf(v3, 0x1BuLL, "%x%c%x%c", v5, (unsigned int)v2, v4, v2);
}
v7 = (unsigned int)(v6 + 5);
*(_QWORD *)(a1 + 48) = a1;
*(_DWORD *)(a1 + 68) = a2;
*(_QWORD *)(a1 + 40) = a1 + (int)v7;
if ( (int)get_debug_level("core", 4LL) <= 2 || (v8 = dprint_crit) != 0 )
return 0;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = *(unsigned int *)(a1 + 64);
v13 = *(const char **)(a1 + 48);
v14 = (const char *)*((_QWORD *)&log_level_info + 16);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): re-init root for sruid is [%.*s] (%u / %d)\n",
process_no,
v15,
v14,
"<core> [sruid.c:134]: ",
"sruid_reinit",
v7,
v13,
v12,
v7);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): re-init root for sruid is [%.*s] (%u / %d)\n",
*((_QWORD *)&log_level_info + 16),
"<core> [sruid.c:134]: ",
"sruid_reinit",
(unsigned int)v7,
*(_QWORD *)(a1 + 48),
*(unsigned int *)(a1 + 64),
v7);
}
--dprint_crit;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
__int64 v2; // rbp
char *v3; // r14
unsigned int v4; // er15
time_t v5; // rax
int v6; // eax
__int64 v7; // rbp
unsigned int v8; // er12
__int64 v10; // r15
unsigned int v11; // eax
__int64 v12; // r14
const char *v13; // r15
const char *v14; // rbx
unsigned int v15; // eax

if ( !a1 )
return (unsigned int)-1;
*(_BYTE *)(a1 + 5) = 0;
v2 = (unsigned int)*(char *)(a1 + 4);
v3 = (char *)(a1 + 5);
if ( server_id )
{
v10 = (unsigned int)my_pid();
v11 = time(0LL);
v6 = snprintf(v3, 0x1BuLL, "%x%c%x%c%x%c", server_id, (unsigned int)v2, v11, v2, v10, v2);
}
else
{
v4 = my_pid();
v5 = time(0LL);
v6 = snprintf(v3, 0x1BuLL, "%x%c%x%c", v5, (unsigned int)v2, v4, v2);
}
v7 = (unsigned int)(v6 + 5);
*(_QWORD *)(a1 + 48) = a1;
*(_DWORD *)(a1 + 68) = a2;
*(_QWORD *)(a1 + 40) = a1 + (int)v7;
if ( (int)get_debug_level("core", 4LL) <= 2 || (v8 = dprint_crit) != 0 )
return 0;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = *(unsigned int *)(a1 + 64);
v13 = *(const char **)(a1 + 48);
v14 = (const char *)*((_QWORD *)&log_level_info + 16);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): re-init root for sruid is [%.*s] (%u / %d)\n",
process_no,
v15,
v14,
"<core> [sruid.c:134]: ",
"sruid_reinit",
v7,
v13,
v12,
v7);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): re-init root for sruid is [%.*s] (%u / %d)\n",
*((_QWORD *)&log_level_info + 16),
"<core> [sruid.c:134]: ",
"sruid_reinit",
(unsigned int)v7,
*(_QWORD *)(a1 + 48),
*(unsigned int *)(a1 + 64),
v7);
}
--dprint_crit;
return v8;
}

original_code:
int sruid_reinit(sruid_t *sid, int mode)
{
 int i;
 char sep;
 if(sid==((void *)0))
  return -1;
 sep = sid->buf[4];
 sid->buf[5] = '\0';
 if(server_id!=0)
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c%x%c", (unsigned int)server_id, sep,
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 else
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c",
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 if(i<=0 || i>40 -13)
 {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); } } (dprint_crit--); } } while(0);
  return -1;
 }
 sid->out = sid->buf + i + 5;
 sid->uid.s = sid->buf;
 sid->mode = (sruid_mode_t)mode;
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } (dprint_crit--); } } while(0);
 return 0;
}

canonical_original_code:
int sruid_reinit(struct sruid *sid, int mode)
{
 int i;
 char sep;
 if(sid==((void *)0))
  return -1;
 sep = sid->buf[4];
 sid->buf[5] = '\0';
 if(server_id!=0)
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c%x%c", (unsigned int)server_id, sep,
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 else
  i = snprintf(sid->buf+5, 40 - 5 - 8 ,
   "%x%c%x%c",
   (unsigned int)time(((void *)0)), sep, (unsigned int)my_pid(), sep);
 if(i<=0 || i>40 -13)
 {
  do { if (get_debug_level("core", (sizeof("core")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "could not re-initialize sruid struct - output len: %d\n", ("<core> [" "sruid.c" ":" "128" "]: ") , __func__, i); } } (dprint_crit--); } } while(0);
  return -1;
 }
 sid->out = sid->buf + i + 5;
 sid->uid.s = sid->buf;
 sid->mode = (enum sruid_mode_t)mode;
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "re-init root for sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "134" "]: ") , __func__, i+5, sid->uid.s, sid->counter, i+5); } } (dprint_crit--); } } while(0);
 return 0;
}

user_defined_types: enum sruid_mode_t { SRUID_INC=0, SRUID_LFSR=1 }


decompiled_code:
__int64 __fastcall sruid_next(__int64 a1)
{
bool v1; // zf
int v2; // edx
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // r10
int v6; // er8
unsigned __int16 v7; // si
char v8; // cl
unsigned int v9; // er12
__int64 v11; // r14
__int64 v12; // r13
const char *v13; // r15
const char *v14; // rbx
unsigned int v15; // eax

if ( !a1 )
return (unsigned int)-1;
v1 = (*(_DWORD *)(a1 + 64))++ == -1;
v2 = *(_DWORD *)(a1 + 68);
if ( v1 )
{
if ( v2 )
goto LABEL_17;
if ( (int)sruid_reinit(a1, 0) >= 0 )
{
v2 = *(_DWORD *)(a1 + 68);
LABEL_17:
*(_DWORD *)(a1 + 64) = 1;
if ( v2 != 1 )
goto LABEL_4;
LABEL_18:
v3 = get_random();
goto LABEL_5;
}
return (unsigned int)-1;
}
if ( v2 == 1 )
goto LABEL_18;
LABEL_4:
v3 = *(_DWORD *)(a1 + 64);
LABEL_5:
v4 = 0LL;
v5 = 0LL;
if ( v3 )
{
do
{
v6 = v4 + 1;
v7 = v3 & 0xF;
v8 = v7 + 48;
if ( v7 >= 0xAu )
v8 = v7 + 87;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v4++) = v8;
v3 >>= 4;
}
while ( v3 );
v5 = v6;
}
v9 = 0;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v5) = 0;
*(_DWORD *)(a1 + 56) = *(_DWORD *)(a1 + 40) + v5 - a1;
if ( (int)get_debug_level("core", 4LL) > 2 )
{
v9 = dprint_crit;
if ( dprint_crit )
{
v9 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v11 = *(unsigned int *)(a1 + 56);
v12 = *(unsigned int *)(a1 + 64);
v13 = *(const char **)(a1 + 48);
v14 = (const char *)*((_QWORD *)&log_level_info + 16);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): new sruid is [%.*s] (%u / %d)\n",
process_no,
v15,
v14,
"<core> [sruid.c:175]: ",
"sruid_next",
v11,
v13,
v12,
v11);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): new sruid is [%.*s] (%u / %d)\n",
*((_QWORD *)&log_level_info + 16),
"<core> [sruid.c:175]: ",
"sruid_next");
}
--dprint_crit;
}
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
bool v1; // zf
int v2; // edx
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // r10
int v6; // er8
unsigned __int16 v7; // si
char v8; // cl
unsigned int v9; // er12
__int64 v11; // r14
__int64 v12; // r13
const char *v13; // r15
const char *v14; // rbx
unsigned int v15; // eax

if ( !a1 )
return (unsigned int)-1;
v1 = (*(_DWORD *)(a1 + 64))++ == -1;
v2 = *(_DWORD *)(a1 + 68);
if ( v1 )
{
if ( v2 )
goto LABEL_17;
if ( (int)func4(a1, 0) >= 0 )
{
v2 = *(_DWORD *)(a1 + 68);
LABEL_17:
*(_DWORD *)(a1 + 64) = 1;
if ( v2 != 1 )
goto LABEL_4;
LABEL_18:
v3 = func2();
goto LABEL_5;
}
return (unsigned int)-1;
}
if ( v2 == 1 )
goto LABEL_18;
LABEL_4:
v3 = *(_DWORD *)(a1 + 64);
LABEL_5:
v4 = 0LL;
v5 = 0LL;
if ( v3 )
{
do
{
v6 = v4 + 1;
v7 = v3 & 0xF;
v8 = v7 + 48;
if ( v7 >= 0xAu )
v8 = v7 + 87;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v4++) = v8;
v3 >>= 4;
}
while ( v3 );
v5 = v6;
}
v9 = 0;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + v5) = 0;
*(_DWORD *)(a1 + 56) = *(_DWORD *)(a1 + 40) + v5 - a1;
if ( (int)get_debug_level("core", 4LL) > 2 )
{
v9 = dprint_crit;
if ( dprint_crit )
{
v9 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v11 = *(unsigned int *)(a1 + 56);
v12 = *(unsigned int *)(a1 + 64);
v13 = *(const char **)(a1 + 48);
v14 = (const char *)*((_QWORD *)&log_level_info + 16);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): new sruid is [%.*s] (%u / %d)\n",
process_no,
v15,
v14,
"<core> [sruid.c:175]: ",
"sruid_next",
v11,
v13,
v12,
v11);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): new sruid is [%.*s] (%u / %d)\n",
*((_QWORD *)&log_level_info + 16),
"<core> [sruid.c:175]: ",
"sruid_next");
}
--dprint_crit;
}
}
return v9;
}

original_code:
int sruid_next(sruid_t *sid)
{
 unsigned short digit;
 int i;
 unsigned int val;
 if(sid==((void *)0))
  return -1;
 sid->counter++;
 if(sid->counter==0) {
  if(sid->mode == SRUID_INC)
  {
   if(sruid_reinit(sid, SRUID_INC)<0)
    return -1;
  }
  sid->counter=1;
 }
 if(sid->mode == SRUID_LFSR)
  val = get_random();
 else
  val = sid->counter;
 i = 0;
 while(val!=0)
 {
  digit = val & 0x0f;
  sid->out[i++] = (digit >= 10) ? digit + 'a' - 10 : digit + '0';
  val >>= 4;
 }
 sid->out[i] = '\0';
 sid->uid.len = sid->out + i - sid->buf;
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); } } (dprint_crit--); } } while(0);
 return 0;
}

canonical_original_code:
int sruid_next(struct sruid *sid)
{
 unsigned short digit;
 int i;
 unsigned int val;
 if(sid==((void *)0))
  return -1;
 sid->counter++;
 if(sid->counter==0) {
  if(sid->mode == SRUID_INC)
  {
   if(sruid_reinit(sid, SRUID_INC)<0)
    return -1;
  }
  sid->counter=1;
 }
 if(sid->mode == SRUID_LFSR)
  val = get_random();
 else
  val = sid->counter;
 i = 0;
 while(val!=0)
 {
  digit = val & 0x0f;
  sid->out[i++] = (digit >= 10) ? digit + 'a' - 10 : digit + '0';
  val >>= 4;
 }
 sid->out[i] = '\0';
 sid->uid.len = sid->out + i - sid->buf;
 do { if (get_debug_level("core", (sizeof("core")-1)) >= ((3)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((3)) >= -5) && (((3)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((3)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", (log_level_info[((3)) - (-5)].name), ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", process_no, my_pid(), ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((3))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "new sruid is [%.*s] (%u / %d)\n", ("<core> [" "sruid.c" ":" "175" "]: ") , __func__, sid->uid.len, sid->uid.s, sid->counter, sid->uid.len); } } (dprint_crit--); } } while(0);
 return 0;
}

variable_types:
digit
unsigned short

variable_types:
val
unsigned int


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

if ( carrierroute_dbh )
{
result = carrierroute_dbf[4]();
carrierroute_dbh = 0LL;
}
return result;
}

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

if ( carrierroute_dbh )
{
result = carrierroute_dbf[4]();
carrierroute_dbh = 0LL;
}
return result;
}

original_code:
void carrierroute_db_close(void) {
 if (carrierroute_dbh) {
  carrierroute_dbf.close(carrierroute_dbh);
  carrierroute_dbh = ((void *)0);
 }
}

canonical_original_code:
void carrierroute_db_close() {
 if (carrierroute_dbh) {
  carrierroute_dbf.close(carrierroute_dbh);
  carrierroute_dbh = ((void *)0);
 }
}


decompiled_code:
__int64 carrierroute_db_init()
{
__int64 v0; // rsi
__int64 result; // rax
const char *v2; // rbx
unsigned int v3; // eax
struct _IO_FILE *v4; // rdi
const char *v5; // r8
const char *v6; // r9
__int64 v7; // rbx
__int64 v8; // rax
const char *v9; // r9
__int64 v10; // rcx
__int64 v11; // r8
const char *v12; // rsi
__int64 v13; // rdx
struct _IO_FILE *v14; // rdi
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // rbx
unsigned int v18; // eax
__int64 v19; // r10
__int64 v20; // rbx
__int64 v21; // rax
__int64 v22; // [rsp-10h] [rbp-28h]
__int64 v23; // [rsp-8h] [rbp-20h]
__int64 v24; // [rsp-8h] [rbp-20h]
const char *v25; // [rsp+0h] [rbp-18h]

if ( !carrierroute_db_url || !*((_DWORD *)&carrierroute_db_url + 2) )
{
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): you have to set the db_url module parameter.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:103]: ",
"carrierroute_db_init");
LABEL_20:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = *((_QWORD *)&log_level_info + 8);
v8 = my_pid();
v9 = "carrierroute [db_carrierroute.c:103]: ";
v10 = (unsigned int)v8;
v24 = v8;
v11 = v7;
v12 = "%2d(%d) %s: %s%s(): you have to set the db_url module parameter.\n";
v13 = process_no;
LABEL_37:
v14 = stderr;
fprintf(stderr, v12, v13, v10, v11, v9, "carrierroute_db_init");
if ( log_color )
dprint_color_reset(v14, v12, v15, v16, v22, v24);
goto LABEL_20;
}
if ( (int)db_bind_mod(&carrierroute_db_url, carrierroute_dbf) < 0 )
{
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't bind database module.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:107]: ",
"carrierroute_db_init");
goto LABEL_20;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v20 = *((_QWORD *)&log_level_info + 8);
v21 = my_pid();
v9 = "carrierroute [db_carrierroute.c:107]: ";
v10 = (unsigned int)v21;
v11 = v20;
v12 = "%2d(%d) %s: %s%s(): can't bind database module.\n";
v24 = v21;
v13 = process_no;
goto LABEL_37;
}
v0 = ((__int64 (__fastcall *)(void *))carrierroute_dbf[2])(&carrierroute_db_url);
carrierroute_dbh = v0;
if ( !v0 )
{
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't connect to database.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:111]: ",
"carrierroute_db_init");
goto LABEL_20;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = *((_QWORD *)&log_level_info + 8);
v18 = my_pid();
v9 = "carrierroute [db_carrierroute.c:111]: ";
v24 = v19;
v10 = v18;
v11 = v17;
v12 = "%2d(%d) %s: %s%s(): can't connect to database.\n";
v13 = process_no;
goto LABEL_37;
}
if ( (int)db_check_table_version(carrierroute_dbf, v0, &carrierroute_table, 3LL) < 0
|| (int)db_check_table_version(carrierroute_dbf, carrierroute_dbh, &carrierfailureroute_table, 2LL) < 0
|| (int)db_check_table_version(carrierroute_dbf, carrierroute_dbh, &carrier_name_table, 1LL) < 0
|| (int)db_check_table_version(carrierroute_dbf, carrierroute_dbh, &domain_name_table, 1LL) < 0 )
{
if ( (int)get_debug_level("carrierroute", 12LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v3 = my_pid();
v4 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): during table version check.\n",
process_no,
v3,
v2,
"carrierroute [db_carrierroute.c:120]: ",
"carrierroute_db_init");
if ( log_color )
dprint_color_reset(v4, "%2d(%d) %s: %s%s(): during table version check.\n", v23, log_color, v5, v6, v25);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): during table version check.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:120]: ",
"carrierroute_db_init");
}
--dprint_crit;
}
carrierroute_db_close();
result = 0xFFFFFFFFLL;
}
else
{
carrierroute_db_close();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rsi
__int64 result; // rax
const char *v2; // rbx
unsigned int v3; // eax
struct _IO_FILE *v4; // rdi
const char *v5; // r8
const char *v6; // r9
__int64 v7; // rbx
__int64 v8; // rax
const char *v9; // r9
__int64 v10; // rcx
__int64 v11; // r8
const char *v12; // rsi
__int64 v13; // rdx
struct _IO_FILE *v14; // rdi
__int64 v15; // rdx
__int64 v16; // rcx
__int64 v17; // rbx
unsigned int v18; // eax
__int64 v19; // r10
__int64 v20; // rbx
__int64 v21; // rax
__int64 v22; // [rsp-10h] [rbp-28h]
__int64 v23; // [rsp-8h] [rbp-20h]
__int64 v24; // [rsp-8h] [rbp-20h]
const char *v25; // [rsp+0h] [rbp-18h]

if ( !carrierroute_db_url || !*((_DWORD *)&carrierroute_db_url + 2) )
{
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): you have to set the db_url module parameter.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:103]: ",
"carrierroute_db_init");
LABEL_20:
--dprint_crit;
return 0xFFFFFFFFLL;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v7 = *((_QWORD *)&log_level_info + 8);
v8 = my_pid();
v9 = "carrierroute [db_carrierroute.c:103]: ";
v10 = (unsigned int)v8;
v24 = v8;
v11 = v7;
v12 = "%2d(%d) %s: %s%s(): you have to set the db_url module parameter.\n";
v13 = process_no;
LABEL_37:
v14 = stderr;
fprintf(stderr, v12, v13, v10, v11, v9, "carrierroute_db_init");
if ( log_color )
dprint_color_reset(v14, v12, v15, v16, v22, v24);
goto LABEL_20;
}
if ( (int)db_bind_mod(&carrierroute_db_url, carrierroute_dbf) < 0 )
{
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't bind database module.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:107]: ",
"carrierroute_db_init");
goto LABEL_20;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v20 = *((_QWORD *)&log_level_info + 8);
v21 = my_pid();
v9 = "carrierroute [db_carrierroute.c:107]: ";
v10 = (unsigned int)v21;
v11 = v20;
v12 = "%2d(%d) %s: %s%s(): can't bind database module.\n";
v24 = v21;
v13 = process_no;
goto LABEL_37;
}
v0 = ((__int64 (__fastcall *)(void *))carrierroute_dbf[2])(&carrierroute_db_url);
carrierroute_dbh = v0;
if ( !v0 )
{
if ( (int)get_debug_level("carrierroute", 12LL) < -1 || dprint_crit )
return 0xFFFFFFFFLL;
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't connect to database.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:111]: ",
"carrierroute_db_init");
goto LABEL_20;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = *((_QWORD *)&log_level_info + 8);
v18 = my_pid();
v9 = "carrierroute [db_carrierroute.c:111]: ";
v24 = v19;
v10 = v18;
v11 = v17;
v12 = "%2d(%d) %s: %s%s(): can't connect to database.\n";
v13 = process_no;
goto LABEL_37;
}
if ( (int)db_check_table_version(carrierroute_dbf, v0, &carrierroute_table, 3LL) < 0
|| (int)db_check_table_version(carrierroute_dbf, carrierroute_dbh, &carrierfailureroute_table, 2LL) < 0
|| (int)db_check_table_version(carrierroute_dbf, carrierroute_dbh, &carrier_name_table, 1LL) < 0
|| (int)db_check_table_version(carrierroute_dbf, carrierroute_dbh, &domain_name_table, 1LL) < 0 )
{
if ( (int)get_debug_level("carrierroute", 12LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v3 = my_pid();
v4 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): during table version check.\n",
process_no,
v3,
v2,
"carrierroute [db_carrierroute.c:120]: ",
"carrierroute_db_init");
if ( log_color )
dprint_color_reset(v4, "%2d(%d) %s: %s%s(): during table version check.\n", v23, log_color, v5, v6, v25);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): during table version check.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:120]: ",
"carrierroute_db_init");
}
--dprint_crit;
}
func0();
result = 0xFFFFFFFFLL;
}
else
{
func0();
result = 0LL;
}
return result;
}

original_code:
int carrierroute_db_init(void) {
 if (!carrierroute_db_url.s || !carrierroute_db_url.len) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "you have to set the db_url module parameter.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "you have to set the db_url module parameter.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "you have to set the db_url module parameter.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "you have to set the db_url module parameter.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "you have to set the db_url module parameter.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (db_bind_mod(&carrierroute_db_url, &carrierroute_dbf) < 0) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't bind database module.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't bind database module.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't bind database module.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't bind database module.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't bind database module.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if ((carrierroute_dbh = carrierroute_dbf.init(&carrierroute_db_url)) == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't connect to database.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrierroute_table, carrierroute_version) < 0) ||
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrierfailureroute_table, carrierfailureroute_version) < 0) ||
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrier_name_table, carrier_name_version) < 0) ||
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &domain_name_table, domain_name_version) < 0)
 ) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "during table version check.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "during table version check.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "during table version check.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "during table version check.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "during table version check.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  carrierroute_db_close();
  return -1;
 }
 carrierroute_db_close();
 return 0;
}

canonical_original_code:
int carrierroute_db_init() {
 if (!carrierroute_db_url.s || !carrierroute_db_url.len) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "you have to set the db_url module parameter.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "you have to set the db_url module parameter.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "you have to set the db_url module parameter.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "you have to set the db_url module parameter.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "you have to set the db_url module parameter.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "103" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (db_bind_mod(&carrierroute_db_url, &carrierroute_dbf) < 0) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't bind database module.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't bind database module.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't bind database module.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't bind database module.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't bind database module.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "107" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if ((carrierroute_dbh = carrierroute_dbf.init(&carrierroute_db_url)) == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't connect to database.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "111" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrierroute_table, carrierroute_version) < 0) ||
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrierfailureroute_table, carrierfailureroute_version) < 0) ||
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &carrier_name_table, carrier_name_version) < 0) ||
 (db_check_table_version(&carrierroute_dbf, carrierroute_dbh, &domain_name_table, domain_name_version) < 0)
 ) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "during table version check.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "during table version check.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "during table version check.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "during table version check.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "during table version check.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "120" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  carrierroute_db_close();
  return -1;
 }
 carrierroute_db_close();
 return 0;
}


decompiled_code:
__int64 carrierroute_db_open()
{
__int64 result; // rax
int v1; // er8
const char *v2; // r12
struct _IO_FILE *v3; // rdi
const char *v4; // r8
const char *v5; // r9
__int64 v6; // [rsp-10h] [rbp-28h]
__int64 v7; // [rsp-8h] [rbp-20h]
const char *v8; // [rsp+0h] [rbp-18h]

if ( carrierroute_dbh )
carrierroute_dbf[4]();
carrierroute_dbh = ((__int64 (__fastcall *)(void *))carrierroute_dbf[2])(&carrierroute_db_url);
if ( carrierroute_dbh )
return 0LL;
v1 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't connect to database.\n",
process_no,
(unsigned int)v7,
v2,
"carrierroute [db_carrierroute.c:141]: ",
"carrierroute_db_open");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): can't connect to database.\n", v6, v7, v4, v5, v8);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't connect to database.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:141]: ",
"carrierroute_db_open");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // er8
const char *v2; // r12
struct _IO_FILE *v3; // rdi
const char *v4; // r8
const char *v5; // r9
__int64 v6; // [rsp-10h] [rbp-28h]
__int64 v7; // [rsp-8h] [rbp-20h]
const char *v8; // [rsp+0h] [rbp-18h]

if ( carrierroute_dbh )
carrierroute_dbf[4]();
carrierroute_dbh = ((__int64 (__fastcall *)(void *))carrierroute_dbf[2])(&carrierroute_db_url);
if ( carrierroute_dbh )
return 0LL;
v1 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v1 >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v2 = (const char *)*((_QWORD *)&log_level_info + 8);
v7 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't connect to database.\n",
process_no,
(unsigned int)v7,
v2,
"carrierroute [db_carrierroute.c:141]: ",
"carrierroute_db_open");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): can't connect to database.\n", v6, v7, v4, v5, v8);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't connect to database.\n",
*((const char **)&log_level_info + 8),
"carrierroute [db_carrierroute.c:141]: ",
"carrierroute_db_open");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
return result;
}

original_code:
int carrierroute_db_open(void) {
 if (carrierroute_dbh) {
  carrierroute_dbf.close(carrierroute_dbh);
 }
 if ((carrierroute_dbh = carrierroute_dbf.init(&carrierroute_db_url)) == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't connect to database.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

canonical_original_code:
int carrierroute_db_open() {
 if (carrierroute_dbh) {
  carrierroute_dbf.close(carrierroute_dbh);
 }
 if ((carrierroute_dbh = carrierroute_dbf.init(&carrierroute_db_url)) == ((void *)0)) {
  do { if (get_debug_level("carrierroute", (sizeof("carrierroute")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't connect to database.\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't connect to database.\n", process_no, my_pid(), ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't connect to database.\n", ("carrierroute" " [" "db_carrierroute.c" ":" "141" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}