decompiled_code:
__int64 __fastcall add_lump_rpl2(__int64 a1, const void *a2, int a3, unsigned int a4)
{
__int64 v4; // rbp
_QWORD *v6; // rax
_QWORD *v7; // r12
__int64 v8; // rcx
__int64 v9; // rax
__int64 result; // rax
size_t v11; // r15
_QWORD *v12; // rax
__int64 v13; // rbx
unsigned int v14; // eax
__int64 v15; // rdx
const char *v16; // r9
__int64 v17; // rcx
__int64 v18; // r8
const char *v19; // rsi
struct _IO_FILE *v20; // rdi
__int64 v21; // rdx
__int64 v22; // rcx
const char *v23; // rbp
unsigned int v24; // eax
struct _IO_FILE *v25; // rdi
__int64 v26; // rcx
const char *v27; // r8
const char *v28; // r9
__int64 v29; // r13
unsigned int v30; // eax
__int64 v31; // rbp
unsigned int v32; // eax
__int64 v33; // r11
__int64 v34; // [rsp-10h] [rbp-48h]
__int64 v35; // [rsp-8h] [rbp-40h]
const char *v36; // [rsp+0h] [rbp-38h]

v4 = a4;
if ( (a4 & 6) == 6 || (a4 & 6) == 0 || (a4 & 0x20) != 0 )
{
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl: bad flags combination (%d)!\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:63]: ",
"add_lump_rpl2",
(unsigned int)v4);
LABEL_29:
result = 0LL;
--dprint_crit;
return result;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = *((_QWORD *)&log_level_info + 8);
v14 = my_pid();
v35 = v4;
v15 = process_no;
v16 = "<core> [data_lump_rpl.c:63]: ";
v17 = v14;
v18 = v13;
v19 = "%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: bad flags combination (%d)!\n";
LABEL_43:
v20 = stderr;
fprintf(stderr, v19, v15, v17, v18, v16, "add_lump_rpl2");
if ( log_color )
dprint_color_reset(v20, v19, v21, v22, v34, v35);
goto LABEL_29;
}
return 0LL;
}
if ( a3 <= 0 || !a2 )
{
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl: I won't add an empty lump!\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:67]: ",
"add_lump_rpl2");
goto LABEL_29;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v29 = *((_QWORD *)&log_level_info + 8);
v30 = my_pid();
v15 = process_no;
v16 = "<core> [data_lump_rpl.c:67]: ";
v17 = v30;
v18 = v29;
v19 = "%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: I won't add an empty lump!\n";
goto LABEL_43;
}
return 0LL;
}
if ( (a4 & 8) != 0 )
{
v6 = (_QWORD *)qm_malloc(mem_block, 32LL);
v7 = v6;
if ( v6 )
{
*v6 = a2;
goto LABEL_9;
}
LABEL_31:
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl : no free pkg memory !\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:75]: ",
"add_lump_rpl2");
goto LABEL_29;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v31 = *((_QWORD *)&log_level_info + 8);
v32 = my_pid();
v15 = process_no;
v16 = "<core> [data_lump_rpl.c:75]: ";
v19 = "%2d(%d) %s: %s%s(): ERROR:add_lump_rpl : no free pkg memory !\n";
v35 = v33;
v17 = v32;
v18 = v31;
goto LABEL_43;
}
return 0LL;
}
v11 = a3;
v12 = (_QWORD *)qm_malloc(mem_block, a3 + 32LL);
v7 = v12;
if ( !v12 )
goto LABEL_31;
*v12 = v12 + 4;
memcpy(v12 + 4, a2, v11);
LABEL_9:
v8 = *(_QWORD *)(a1 + 1456);
*((_DWORD *)v7 + 2) = a3;
*((_DWORD *)v7 + 4) = v4;
v7[3] = 0LL;
if ( !v8 )
{
*(_QWORD *)(a1 + 1456) = v7;
return a1 + 1456;
}
if ( (v4 & 4) != 0 )
{
while ( (*(_BYTE *)(v8 + 16) & 4) == 0 )
{
if ( !*(_QWORD *)(v8 + 24) )
{
v9 = v8;
goto LABEL_12;
}
v8 = *(_QWORD *)(v8 + 24);
}
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v23 = (const char *)*((_QWORD *)&log_level_info + 8);
v24 = my_pid();
v25 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: LUMP_RPL_BODY already added!\n",
process_no,
v24,
v23,
"<core> [data_lump_rpl.c:99]: ",
"add_lump_rpl2");
if ( log_color )
dprint_color_reset(
v25,
"%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: LUMP_RPL_BODY already added!\n",
v35,
v26,
v27,
v28,
v36);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl: LUMP_RPL_BODY already added!\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:99]: ",
"add_lump_rpl2");
}
--dprint_crit;
}
qm_free(mem_block, v7);
return 0LL;
}
do
{
v9 = v8;
v8 = *(_QWORD *)(v8 + 24);
}
while ( v8 );
LABEL_12:
*(_QWORD *)(v9 + 24) = v7;
return v9 + 24;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const void *a2, int a3, unsigned int a4)
{
__int64 v4; // rbp
_QWORD *v6; // rax
_QWORD *v7; // r12
__int64 v8; // rcx
__int64 v9; // rax
__int64 result; // rax
size_t v11; // r15
_QWORD *v12; // rax
__int64 v13; // rbx
unsigned int v14; // eax
__int64 v15; // rdx
const char *v16; // r9
__int64 v17; // rcx
__int64 v18; // r8
const char *v19; // rsi
struct _IO_FILE *v20; // rdi
__int64 v21; // rdx
__int64 v22; // rcx
const char *v23; // rbp
unsigned int v24; // eax
struct _IO_FILE *v25; // rdi
__int64 v26; // rcx
const char *v27; // r8
const char *v28; // r9
__int64 v29; // r13
unsigned int v30; // eax
__int64 v31; // rbp
unsigned int v32; // eax
__int64 v33; // r11
__int64 v34; // [rsp-10h] [rbp-48h]
__int64 v35; // [rsp-8h] [rbp-40h]
const char *v36; // [rsp+0h] [rbp-38h]

v4 = a4;
if ( (a4 & 6) == 6 || (a4 & 6) == 0 || (a4 & 0x20) != 0 )
{
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl: bad flags combination (%d)!\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:63]: ",
"add_lump_rpl2",
(unsigned int)v4);
LABEL_29:
result = 0LL;
--dprint_crit;
return result;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = *((_QWORD *)&log_level_info + 8);
v14 = my_pid();
v35 = v4;
v15 = process_no;
v16 = "<core> [data_lump_rpl.c:63]: ";
v17 = v14;
v18 = v13;
v19 = "%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: bad flags combination (%d)!\n";
LABEL_43:
v20 = stderr;
fprintf(stderr, v19, v15, v17, v18, v16, "add_lump_rpl2");
if ( log_color )
dprint_color_reset(v20, v19, v21, v22, v34, v35);
goto LABEL_29;
}
return 0LL;
}
if ( a3 <= 0 || !a2 )
{
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl: I won't add an empty lump!\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:67]: ",
"add_lump_rpl2");
goto LABEL_29;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v29 = *((_QWORD *)&log_level_info + 8);
v30 = my_pid();
v15 = process_no;
v16 = "<core> [data_lump_rpl.c:67]: ";
v17 = v30;
v18 = v29;
v19 = "%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: I won't add an empty lump!\n";
goto LABEL_43;
}
return 0LL;
}
if ( (a4 & 8) != 0 )
{
v6 = (_QWORD *)qm_malloc(mem_block, 32LL);
v7 = v6;
if ( v6 )
{
*v6 = a2;
goto LABEL_9;
}
LABEL_31:
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( !log_stderr )
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl : no free pkg memory !\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:75]: ",
"add_lump_rpl2");
goto LABEL_29;
}
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v31 = *((_QWORD *)&log_level_info + 8);
v32 = my_pid();
v15 = process_no;
v16 = "<core> [data_lump_rpl.c:75]: ";
v19 = "%2d(%d) %s: %s%s(): ERROR:add_lump_rpl : no free pkg memory !\n";
v35 = v33;
v17 = v32;
v18 = v31;
goto LABEL_43;
}
return 0LL;
}
v11 = a3;
v12 = (_QWORD *)qm_malloc(mem_block, a3 + 32LL);
v7 = v12;
if ( !v12 )
goto LABEL_31;
*v12 = v12 + 4;
memcpy(v12 + 4, a2, v11);
LABEL_9:
v8 = *(_QWORD *)(a1 + 1456);
*((_DWORD *)v7 + 2) = a3;
*((_DWORD *)v7 + 4) = v4;
v7[3] = 0LL;
if ( !v8 )
{
*(_QWORD *)(a1 + 1456) = v7;
return a1 + 1456;
}
if ( (v4 & 4) != 0 )
{
while ( (*(_BYTE *)(v8 + 16) & 4) == 0 )
{
if ( !*(_QWORD *)(v8 + 24) )
{
v9 = v8;
goto LABEL_12;
}
v8 = *(_QWORD *)(v8 + 24);
}
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v23 = (const char *)*((_QWORD *)&log_level_info + 8);
v24 = my_pid();
v25 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: LUMP_RPL_BODY already added!\n",
process_no,
v24,
v23,
"<core> [data_lump_rpl.c:99]: ",
"add_lump_rpl2");
if ( log_color )
dprint_color_reset(
v25,
"%2d(%d) %s: %s%s(): ERROR:add_lump_rpl: LUMP_RPL_BODY already added!\n",
v35,
v26,
v27,
v28,
v36);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR:add_lump_rpl: LUMP_RPL_BODY already added!\n",
*((const char **)&log_level_info + 8),
"<core> [data_lump_rpl.c:99]: ",
"add_lump_rpl2");
}
--dprint_crit;
}
qm_free(mem_block, v7);
return 0LL;
}
do
{
v9 = v8;
v8 = *(_QWORD *)(v8 + 24);
}
while ( v8 );
LABEL_12:
*(_QWORD *)(v9 + 24) = v7;
return v9 + 24;
}

original_code:
struct lump_rpl** add_lump_rpl2(struct sip_msg *msg, char *s,
         int len, int flags)
{
 struct lump_rpl *lump = 0;
 struct lump_rpl *foo;
 struct lump_rpl** ret;
 if ( (flags&((1<<1)|(1<<2)))==((1<<1)|(1<<2))
 || (flags&((1<<1)|(1<<2)))==0 || (flags&(1<<5)) ) {
  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(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); 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(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); 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(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (len<=0 || s==0) {
  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(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __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(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __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(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 lump = (struct lump_rpl*) qm_malloc(mem_block, (sizeof(struct lump_rpl) + ((flags&(1<<3))?0:len)));
 if (!lump) {
  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(): " "ERROR:add_lump_rpl : no free pkg memory !\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __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(): " "ERROR:add_lump_rpl : no free pkg memory !\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl : no free pkg memory !\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __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(): " "ERROR:add_lump_rpl : no free pkg memory !\n", ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl : no free pkg memory !\n", ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (flags&(1<<3)) {
  lump->text.s = s;
 } else {
  lump->text.s = ((char*)lump)+sizeof(struct lump_rpl);
  memcpy( lump->text.s, s, len);
 }
 lump->text.len = len;
 lump->flags = flags;
 lump->next = 0;
 if (!msg->reply_lump) {
  msg->reply_lump = lump;
  ret=&msg->reply_lump;
 }else{
  if (!(flags&(1<<2)))
   for(foo=msg->reply_lump;foo->next;foo=foo->next);
  else
   for(foo=msg->reply_lump; ;foo=foo->next) {
    if (foo->flags&(1<<2)) {
     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(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __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(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __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(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __func__); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, (lump));
     goto error;
    }
    if (foo->next==0)
     break;
   }
  foo->next = lump;
  ret= &(foo->next);
 }
 return ret;
error:
 return 0;
}

canonical_original_code:
struct lump_rpl **add_lump_rpl2(struct sip_msg *msg, char *s, int len, int flags)
{
 struct lump_rpl *lump = 0;
 struct lump_rpl *foo;
 struct lump_rpl **ret;
 if ( (flags&((1<<1)|(1<<2)))==((1<<1)|(1<<2))
 || (flags&((1<<1)|(1<<2)))==0 || (flags&(1<<5)) ) {
  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(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); 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(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); 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(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl: bad flags combination (%d)!\n", ("<core> [" "data_lump_rpl.c" ":" "63" "]: ") , __func__,flags); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (len<=0 || s==0) {
  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(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __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(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __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(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl: I won't add an empty lump!\n", ("<core> [" "data_lump_rpl.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 lump = (struct lump_rpl *) qm_malloc(mem_block, (sizeof(struct lump_rpl) + ((flags&(1<<3))?0:len)));
 if (!lump) {
  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(): " "ERROR:add_lump_rpl : no free pkg memory !\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __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(): " "ERROR:add_lump_rpl : no free pkg memory !\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl : no free pkg memory !\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __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(): " "ERROR:add_lump_rpl : no free pkg memory !\n", ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl : no free pkg memory !\n", ("<core> [" "data_lump_rpl.c" ":" "75" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  goto error;
 }
 if (flags&(1<<3)) {
  lump->text.s = s;
 } else {
  lump->text.s = ((char *)lump)+sizeof(struct lump_rpl);
  memcpy( lump->text.s, s, len);
 }
 lump->text.len = len;
 lump->flags = flags;
 lump->next = 0;
 if (!msg->reply_lump) {
  msg->reply_lump = lump;
  ret=&msg->reply_lump;
 }else{
  if (!(flags&(1<<2)))
   for(foo=msg->reply_lump;foo->next;foo=foo->next);
  else
   for(foo=msg->reply_lump; ;foo=foo->next) {
    if (foo->flags&(1<<2)) {
     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(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __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(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", process_no, my_pid(), ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __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(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR:add_lump_rpl: LUMP_RPL_BODY " "already added!\n", ("<core> [" "data_lump_rpl.c" ":" "99" "]: ") , __func__); } } (dprint_crit--); } } while(0);
     qm_free(mem_block, (lump));
     goto error;
    }
    if (foo->next==0)
     break;
   }
  foo->next = lump;
  ret= &(foo->next);
 }
 return ret;
error:
 return 0;
}

variable_types: struct sip_msg { unsigned int id; int pid; struct timeval { long tv_sec; long tv_usec; } tval; struct snd_flags { unsigned char f; unsigned char blst_imask; } fwd_send_flags; struct snd_flags rpl_send_flags; struct msg_start { int type; int len; union { struct { struct _str method; struct _str uri; struct _str version; int method_value; } request; struct { struct _str version; struct _str status; struct _str reason; unsigned int statuscode; } reply; } u; } first_line; struct via_body { int error; struct _str hdr; struct _str name; struct _str version; struct _str transport; struct _str host; short proto; unsigned short port; struct _str port_str; struct _str params; struct _str comment; int bsize; struct via_param { int type; struct _str name; struct _str value; char *start; int size; struct via_param *next; } *param_lst; struct via_param *last_param; struct via_param *branch; struct _str tid; struct via_param *received; struct via_param *rport; struct via_param *i; struct via_param *alias; struct via_body *next; } *via1; struct via_body *via2; struct hdr_field { enum _hdr_types_t { HDR_ERROR_T=-1, HDR_OTHER_T=0, HDR_VIA_T=1, HDR_VIA1_T=1, HDR_VIA2_T=2, HDR_TO_T=3, HDR_FROM_T=4, HDR_CSEQ_T=5, HDR_CALLID_T=6, HDR_CONTACT_T=7, HDR_MAXFORWARDS_T=8, HDR_ROUTE_T=9, HDR_RECORDROUTE_T=10, HDR_CONTENTTYPE_T=11, HDR_CONTENTLENGTH_T=12, HDR_AUTHORIZATION_T=13, HDR_EXPIRES_T=14, HDR_PROXYAUTH_T=15, HDR_SUPPORTED_T=16, HDR_REQUIRE_T=17, HDR_PROXYREQUIRE_T=18, HDR_UNSUPPORTED_T=19, HDR_ALLOW_T=20, HDR_EVENT_T=21, HDR_ACCEPT_T=22, HDR_ACCEPTLANGUAGE_T=23, HDR_ORGANIZATION_T=24, HDR_PRIORITY_T=25, HDR_SUBJECT_T=26, HDR_USERAGENT_T=27, HDR_SERVER_T=28, HDR_CONTENTDISPOSITION_T=29, HDR_DIVERSION_T=30, HDR_RPID_T=31, HDR_REFER_TO_T=32, HDR_SIPIFMATCH_T=33, HDR_SESSIONEXPIRES_T=34, HDR_MIN_SE_T=35, HDR_SUBSCRIPTION_STATE_T=36, HDR_ACCEPTCONTACT_T=37, HDR_ALLOWEVENTS_T=38, HDR_CONTENTENCODING_T=39, HDR_REFERREDBY_T=40, HDR_REJECTCONTACT_T=41, HDR_REQUESTDISPOSITION_T=42, HDR_WWW_AUTHENTICATE_T=43, HDR_PROXY_AUTHENTICATE_T=44, HDR_DATE_T=45, HDR_IDENTITY_T=46, HDR_IDENTITY_INFO_T=47, HDR_RETRY_AFTER_T=48, HDR_PPI_T=49, HDR_PAI_T=50, HDR_PATH_T=51, HDR_PRIVACY_T=52, HDR_REASON_T=53, HDR_EOH_T=54 } type; struct _str name; struct _str body; int len; void *parsed; struct hdr_field *next; } *headers; struct hdr_field *last_header; unsigned long long parsed_flag; struct hdr_field *h_via1; struct hdr_field *h_via2; struct hdr_field *callid; struct hdr_field *to; struct hdr_field *cseq; struct hdr_field *from; struct hdr_field *contact; struct hdr_field *maxforwards; struct hdr_field *route; struct hdr_field *record_route; struct hdr_field *content_type; struct hdr_field *content_length; struct hdr_field *authorization; struct hdr_field *expires; struct hdr_field *proxy_auth; struct hdr_field *supported; struct hdr_field *require; struct hdr_field *proxy_require; struct hdr_field *unsupported; struct hdr_field *allow; struct hdr_field *event; struct hdr_field *accept; struct hdr_field *accept_language; struct hdr_field *organization; struct hdr_field *priority; struct hdr_field *subject; struct hdr_field *user_agent; struct hdr_field *server; struct hdr_field *content_disposition; struct hdr_field *diversion; struct hdr_field *rpid; struct hdr_field *refer_to; struct hdr_field *session_expires; struct hdr_field *min_se; struct hdr_field *sipifmatch; struct hdr_field *subscription_state; struct hdr_field *date; struct hdr_field *identity; struct hdr_field *identity_info; struct hdr_field *pai; struct hdr_field *ppi; struct hdr_field *path; struct hdr_field *privacy; struct msg_body { enum msg_body_type { MSG_BODY_UNKNOWN=0, MSG_BODY_SDP=1 } type; void (*free)(struct msg_body **ptr); } *body; char *eoh; char *unparsed; struct receive_info { struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } src_ip; struct ip_addr dst_ip; unsigned short src_port; unsigned short dst_port; int proto_reserved1; int proto_reserved2; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } src_su; struct socket_info { int socket; struct _str name; struct ip_addr address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *bind_address; char proto; } rcv; char *buf; unsigned int len; struct _str new_uri; struct _str dst_uri; int parsed_uri_ok; struct sip_uri { struct _str user; struct _str passwd; struct _str host; struct _str port; struct _str params; struct _str sip_params; struct _str headers; unsigned short port_no; unsigned short proto; enum _uri_type { ERROR_URI_T=0, SIP_URI_T=1, SIPS_URI_T=2, TEL_URI_T=3, TELS_URI_T=4, URN_URI_T=5 } type; enum _uri_flags { URI_USER_NORMALIZE=1, URI_SIP_USER_PHONE=2 } flags; struct _str transport; struct _str ttl; struct _str user_param; struct _str maddr; struct _str method; struct _str lr; struct _str r2; struct _str gr; struct _str transport_val; struct _str ttl_val; struct _str user_param_val; struct _str maddr_val; struct _str method_val; struct _str lr_val; struct _str r2_val; struct _str gr_val; } parsed_uri; int parsed_orig_ruri_ok; struct sip_uri parsed_orig_ruri; struct lump { enum _hdr_types_t { HDR_ERROR_T=-1, HDR_OTHER_T=0, HDR_VIA_T=1, HDR_VIA1_T=1, HDR_VIA2_T=2, HDR_TO_T=3, HDR_FROM_T=4, HDR_CSEQ_T=5, HDR_CALLID_T=6, HDR_CONTACT_T=7, HDR_MAXFORWARDS_T=8, HDR_ROUTE_T=9, HDR_RECORDROUTE_T=10, HDR_CONTENTTYPE_T=11, HDR_CONTENTLENGTH_T=12, HDR_AUTHORIZATION_T=13, HDR_EXPIRES_T=14, HDR_PROXYAUTH_T=15, HDR_SUPPORTED_T=16, HDR_REQUIRE_T=17, HDR_PROXYREQUIRE_T=18, HDR_UNSUPPORTED_T=19, HDR_ALLOW_T=20, HDR_EVENT_T=21, HDR_ACCEPT_T=22, HDR_ACCEPTLANGUAGE_T=23, HDR_ORGANIZATION_T=24, HDR_PRIORITY_T=25, HDR_SUBJECT_T=26, HDR_USERAGENT_T=27, HDR_SERVER_T=28, HDR_CONTENTDISPOSITION_T=29, HDR_DIVERSION_T=30, HDR_RPID_T=31, HDR_REFER_TO_T=32, HDR_SIPIFMATCH_T=33, HDR_SESSIONEXPIRES_T=34, HDR_MIN_SE_T=35, HDR_SUBSCRIPTION_STATE_T=36, HDR_ACCEPTCONTACT_T=37, HDR_ALLOWEVENTS_T=38, HDR_CONTENTENCODING_T=39, HDR_REFERREDBY_T=40, HDR_REJECTCONTACT_T=41, HDR_REQUESTDISPOSITION_T=42, HDR_WWW_AUTHENTICATE_T=43, HDR_PROXY_AUTHENTICATE_T=44, HDR_DATE_T=45, HDR_IDENTITY_T=46, HDR_IDENTITY_INFO_T=47, HDR_RETRY_AFTER_T=48, HDR_PPI_T=49, HDR_PAI_T=50, HDR_PATH_T=51, HDR_PRIVACY_T=52, HDR_REASON_T=53, HDR_EOH_T=54 } type; enum lump_op { LUMP_NOP=0, LUMP_DEL=1, LUMP_ADD=2, LUMP_ADD_SUBST=3, LUMP_ADD_OPT=4 } op; union { int offset; enum lump_subst { SUBST_NOP=0, SUBST_RCV_IP=1, SUBST_SND_IP=2, SUBST_RCV_PORT=3, SUBST_SND_PORT=4, SUBST_RCV_PROTO=5, SUBST_SND_PROTO=6, SUBST_RCV_ALL=7, SUBST_SND_ALL=8 } subst; enum lump_conditions { COND_FALSE=0, COND_TRUE=1, COND_IF_DIFF_REALMS=2, COND_IF_DIFF_AF=3, COND_IF_DIFF_PROTO=4, COND_IF_DIFF_PORT=5, COND_IF_DIFF_IP=6, COND_IF_RAND=7 } cond; char *value; } u; int len; struct lump *before; struct lump *after; struct lump *next; enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2, LUMPFLAG_BRANCH=4, LUMPFLAG_COND_TRUE=8 } flags; } *add_rm; struct lump *body_lumps; struct lump_rpl *reply_lump; char add_to_branch_s[-1]; int add_to_branch_len; unsigned int hash_index; unsigned int msg_flags; unsigned int flags; struct _str set_global_address; struct _str set_global_port; struct socket_info *force_send_socket; struct _str path_vec; struct _str instance; unsigned int reg_id; struct _str ruid; struct _str location_ua; struct msg_ldata { struct ocd_flow { int decoded; struct receive_info rcv; } flow; } ldv; } *

variable_types:
s
char *

variable_types: len int

variable_types: flags int

variable_types: struct lump_rpl { struct _str { char *s; int len; } text; int flags; struct lump_rpl *next; } **

user_defined_types: struct lump_rpl { struct _str text; int flags; struct lump_rpl *next; }

user_defined_types: struct sip_msg { unsigned int id; int pid; struct timeval tval; struct snd_flags fwd_send_flags; struct snd_flags rpl_send_flags; struct msg_start first_line; struct via_body *via1; struct via_body *via2; struct hdr_field *headers; struct hdr_field *last_header; unsigned long long parsed_flag; struct hdr_field *h_via1; struct hdr_field *h_via2; struct hdr_field *callid; struct hdr_field *to; struct hdr_field *cseq; struct hdr_field *from; struct hdr_field *contact; struct hdr_field *maxforwards; struct hdr_field *route; struct hdr_field *record_route; struct hdr_field *content_type; struct hdr_field *content_length; struct hdr_field *authorization; struct hdr_field *expires; struct hdr_field *proxy_auth; struct hdr_field *supported; struct hdr_field *require; struct hdr_field *proxy_require; struct hdr_field *unsupported; struct hdr_field *allow; struct hdr_field *event; struct hdr_field *accept; struct hdr_field *accept_language; struct hdr_field *organization; struct hdr_field *priority; struct hdr_field *subject; struct hdr_field *user_agent; struct hdr_field *server; struct hdr_field *content_disposition; struct hdr_field *diversion; struct hdr_field *rpid; struct hdr_field *refer_to; struct hdr_field *session_expires; struct hdr_field *min_se; struct hdr_field *sipifmatch; struct hdr_field *subscription_state; struct hdr_field *date; struct hdr_field *identity; struct hdr_field *identity_info; struct hdr_field *pai; struct hdr_field *ppi; struct hdr_field *path; struct hdr_field *privacy; struct msg_body *body; char *eoh; char *unparsed; struct receive_info rcv; char *buf; unsigned int len; struct _str new_uri; struct _str dst_uri; int parsed_uri_ok; struct sip_uri parsed_uri; int parsed_orig_ruri_ok; struct sip_uri parsed_orig_ruri; struct lump *add_rm; struct lump *body_lumps; struct lump_rpl *reply_lump; char add_to_branch_s[-1]; int add_to_branch_len; unsigned int hash_index; unsigned int msg_flags; unsigned int flags; struct _str set_global_address; struct _str set_global_port; struct socket_info *force_send_socket; struct _str path_vec; struct _str instance; unsigned int reg_id; struct _str ruid; struct _str location_ua; struct msg_ldata ldv; }

user_defined_types: struct receive_info { struct ip_addr src_ip; struct ip_addr dst_ip; unsigned short src_port; unsigned short dst_port; int proto_reserved1; int proto_reserved2; union sockaddr_union src_su; struct socket_info *bind_address; char proto; }

user_defined_types: struct msg_ldata { struct ocd_flow flow; }

user_defined_types: struct via_body { int error; struct _str hdr; struct _str name; struct _str version; struct _str transport; struct _str host; short proto; unsigned short port; struct _str port_str; struct _str params; struct _str comment; int bsize; struct via_param *param_lst; struct via_param *last_param; struct via_param *branch; struct _str tid; struct via_param *received; struct via_param *rport; struct via_param *i; struct via_param *alias; struct via_body *next; }

user_defined_types: struct hdr_field { enum _hdr_types_t type; struct _str name; struct _str body; int len; void *parsed; struct hdr_field *next; }

user_defined_types: struct msg_body { enum msg_body_type type; void (*free)(struct msg_body **ptr); }

user_defined_types: union sockaddr_union { struct sockaddr s; struct sockaddr_in sin; struct sockaddr_in6 sin6; }

user_defined_types: struct lump { enum _hdr_types_t type; enum lump_op op; union { int offset; enum lump_subst subst; enum lump_conditions cond; char *value; } u; int len; struct lump *before; struct lump *after; struct lump *next; enum lump_flag flags; }

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

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

user_defined_types: struct socket_info { int socket; struct _str name; struct ip_addr address; struct _str address_str; struct _str port_no_str; enum si_flags flags; union sockaddr_union su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info useinfo; }

user_defined_types: struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; }


repo: virtualolson/who

decompiled_code:
__int64 __fastcall free_lump_rpl(__int64 a1)
{
__int64 result; // rax

if ( a1 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x18) == 8 && *(_QWORD *)a1 )
{
qm_free(mem_block, *(_QWORD *)a1);
result = qm_free(mem_block, a1);
}
else
{
result = qm_free(mem_block, a1);
}
}
return result;
}

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

if ( a1 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x18) == 8 && *(_QWORD *)a1 )
{
qm_free(mem_block, *(_QWORD *)a1);
result = qm_free(mem_block, a1);
}
else
{
result = qm_free(mem_block, a1);
}
}
return result;
}

original_code:
void free_lump_rpl(struct lump_rpl* lump)
{
 if (lump) {
  if (!((lump->flags)&(1<<4)) && ((lump->flags)&(1<<3))
  && lump->text.s)
   qm_free(mem_block, (lump->text.s));
  qm_free(mem_block, (lump));
 }
}

canonical_original_code:
void free_lump_rpl(struct lump_rpl *lump)
{
 if (lump) {
  if (!((lump->flags)&(1<<4)) && ((lump->flags)&(1<<3))
  && lump->text.s)
   qm_free(mem_block, (lump->text.s));
  qm_free(mem_block, (lump));
 }
}

variable_types: struct lump_rpl { struct _str { char *s; int len; } text; int flags; struct lump_rpl *next; } *

return_type: void


original_code:
void unlink_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
{
 struct lump_rpl *foo,*prev;
 foo = msg->reply_lump;
 prev = 0;
 while( foo && foo!=lump ) {
  prev = foo;
  foo = foo->next;
 }
 if (foo) {
  if (prev)
   prev->next = foo->next;
  else
   msg->reply_lump = foo->next;
 }
}

canonical_original_code:
void unlink_lump_rpl(struct sip_msg *msg, struct lump_rpl *lump)
{
 struct lump_rpl *foo; struct lump_rpl *prev;
 foo = msg->reply_lump;
 prev = 0;
 while( foo && foo!=lump ) {
  prev = foo;
  foo = foo->next;
 }
 if (foo) {
  if (prev)
   prev->next = foo->next;
  else
   msg->reply_lump = foo->next;
 }
}

variable_types: struct sip_msg { unsigned int id; int pid; struct timeval { long tv_sec; long tv_usec; } tval; struct snd_flags { unsigned char f; unsigned char blst_imask; } fwd_send_flags; struct snd_flags rpl_send_flags; struct msg_start { int type; int len; union { struct { struct _str { char *s; int len; } method; struct _str uri; struct _str version; int method_value; } request; struct { struct _str version; struct _str status; struct _str reason; unsigned int statuscode; } reply; } u; } first_line; struct via_body { int error; struct _str hdr; struct _str name; struct _str version; struct _str transport; struct _str host; short proto; unsigned short port; struct _str port_str; struct _str params; struct _str comment; int bsize; struct via_param { int type; struct _str name; struct _str value; char *start; int size; struct via_param *next; } *param_lst; struct via_param *last_param; struct via_param *branch; struct _str tid; struct via_param *received; struct via_param *rport; struct via_param *i; struct via_param *alias; struct via_body *next; } *via1; struct via_body *via2; struct hdr_field { enum _hdr_types_t { HDR_ERROR_T=-1, HDR_OTHER_T=0, HDR_VIA_T=1, HDR_VIA1_T=1, HDR_VIA2_T=2, HDR_TO_T=3, HDR_FROM_T=4, HDR_CSEQ_T=5, HDR_CALLID_T=6, HDR_CONTACT_T=7, HDR_MAXFORWARDS_T=8, HDR_ROUTE_T=9, HDR_RECORDROUTE_T=10, HDR_CONTENTTYPE_T=11, HDR_CONTENTLENGTH_T=12, HDR_AUTHORIZATION_T=13, HDR_EXPIRES_T=14, HDR_PROXYAUTH_T=15, HDR_SUPPORTED_T=16, HDR_REQUIRE_T=17, HDR_PROXYREQUIRE_T=18, HDR_UNSUPPORTED_T=19, HDR_ALLOW_T=20, HDR_EVENT_T=21, HDR_ACCEPT_T=22, HDR_ACCEPTLANGUAGE_T=23, HDR_ORGANIZATION_T=24, HDR_PRIORITY_T=25, HDR_SUBJECT_T=26, HDR_USERAGENT_T=27, HDR_SERVER_T=28, HDR_CONTENTDISPOSITION_T=29, HDR_DIVERSION_T=30, HDR_RPID_T=31, HDR_REFER_TO_T=32, HDR_SIPIFMATCH_T=33, HDR_SESSIONEXPIRES_T=34, HDR_MIN_SE_T=35, HDR_SUBSCRIPTION_STATE_T=36, HDR_ACCEPTCONTACT_T=37, HDR_ALLOWEVENTS_T=38, HDR_CONTENTENCODING_T=39, HDR_REFERREDBY_T=40, HDR_REJECTCONTACT_T=41, HDR_REQUESTDISPOSITION_T=42, HDR_WWW_AUTHENTICATE_T=43, HDR_PROXY_AUTHENTICATE_T=44, HDR_DATE_T=45, HDR_IDENTITY_T=46, HDR_IDENTITY_INFO_T=47, HDR_RETRY_AFTER_T=48, HDR_PPI_T=49, HDR_PAI_T=50, HDR_PATH_T=51, HDR_PRIVACY_T=52, HDR_REASON_T=53, HDR_EOH_T=54 } type; struct _str name; struct _str body; int len; void *parsed; struct hdr_field *next; } *headers; struct hdr_field *last_header; unsigned long long parsed_flag; struct hdr_field *h_via1; struct hdr_field *h_via2; struct hdr_field *callid; struct hdr_field *to; struct hdr_field *cseq; struct hdr_field *from; struct hdr_field *contact; struct hdr_field *maxforwards; struct hdr_field *route; struct hdr_field *record_route; struct hdr_field *content_type; struct hdr_field *content_length; struct hdr_field *authorization; struct hdr_field *expires; struct hdr_field *proxy_auth; struct hdr_field *supported; struct hdr_field *require; struct hdr_field *proxy_require; struct hdr_field *unsupported; struct hdr_field *allow; struct hdr_field *event; struct hdr_field *accept; struct hdr_field *accept_language; struct hdr_field *organization; struct hdr_field *priority; struct hdr_field *subject; struct hdr_field *user_agent; struct hdr_field *server; struct hdr_field *content_disposition; struct hdr_field *diversion; struct hdr_field *rpid; struct hdr_field *refer_to; struct hdr_field *session_expires; struct hdr_field *min_se; struct hdr_field *sipifmatch; struct hdr_field *subscription_state; struct hdr_field *date; struct hdr_field *identity; struct hdr_field *identity_info; struct hdr_field *pai; struct hdr_field *ppi; struct hdr_field *path; struct hdr_field *privacy; struct msg_body { enum msg_body_type { MSG_BODY_UNKNOWN=0, MSG_BODY_SDP=1 } type; void (*free)(struct msg_body **ptr); } *body; char *eoh; char *unparsed; struct receive_info { struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } src_ip; struct ip_addr dst_ip; unsigned short src_port; unsigned short dst_port; int proto_reserved1; int proto_reserved2; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } src_su; struct socket_info { int socket; struct _str name; struct ip_addr address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *bind_address; char proto; } rcv; char *buf; unsigned int len; struct _str new_uri; struct _str dst_uri; int parsed_uri_ok; struct sip_uri { struct _str user; struct _str passwd; struct _str host; struct _str port; struct _str params; struct _str sip_params; struct _str headers; unsigned short port_no; unsigned short proto; enum _uri_type { ERROR_URI_T=0, SIP_URI_T=1, SIPS_URI_T=2, TEL_URI_T=3, TELS_URI_T=4, URN_URI_T=5 } type; enum _uri_flags { URI_USER_NORMALIZE=1, URI_SIP_USER_PHONE=2 } flags; struct _str transport; struct _str ttl; struct _str user_param; struct _str maddr; struct _str method; struct _str lr; struct _str r2; struct _str gr; struct _str transport_val; struct _str ttl_val; struct _str user_param_val; struct _str maddr_val; struct _str method_val; struct _str lr_val; struct _str r2_val; struct _str gr_val; } parsed_uri; int parsed_orig_ruri_ok; struct sip_uri parsed_orig_ruri; struct lump { enum _hdr_types_t { HDR_ERROR_T=-1, HDR_OTHER_T=0, HDR_VIA_T=1, HDR_VIA1_T=1, HDR_VIA2_T=2, HDR_TO_T=3, HDR_FROM_T=4, HDR_CSEQ_T=5, HDR_CALLID_T=6, HDR_CONTACT_T=7, HDR_MAXFORWARDS_T=8, HDR_ROUTE_T=9, HDR_RECORDROUTE_T=10, HDR_CONTENTTYPE_T=11, HDR_CONTENTLENGTH_T=12, HDR_AUTHORIZATION_T=13, HDR_EXPIRES_T=14, HDR_PROXYAUTH_T=15, HDR_SUPPORTED_T=16, HDR_REQUIRE_T=17, HDR_PROXYREQUIRE_T=18, HDR_UNSUPPORTED_T=19, HDR_ALLOW_T=20, HDR_EVENT_T=21, HDR_ACCEPT_T=22, HDR_ACCEPTLANGUAGE_T=23, HDR_ORGANIZATION_T=24, HDR_PRIORITY_T=25, HDR_SUBJECT_T=26, HDR_USERAGENT_T=27, HDR_SERVER_T=28, HDR_CONTENTDISPOSITION_T=29, HDR_DIVERSION_T=30, HDR_RPID_T=31, HDR_REFER_TO_T=32, HDR_SIPIFMATCH_T=33, HDR_SESSIONEXPIRES_T=34, HDR_MIN_SE_T=35, HDR_SUBSCRIPTION_STATE_T=36, HDR_ACCEPTCONTACT_T=37, HDR_ALLOWEVENTS_T=38, HDR_CONTENTENCODING_T=39, HDR_REFERREDBY_T=40, HDR_REJECTCONTACT_T=41, HDR_REQUESTDISPOSITION_T=42, HDR_WWW_AUTHENTICATE_T=43, HDR_PROXY_AUTHENTICATE_T=44, HDR_DATE_T=45, HDR_IDENTITY_T=46, HDR_IDENTITY_INFO_T=47, HDR_RETRY_AFTER_T=48, HDR_PPI_T=49, HDR_PAI_T=50, HDR_PATH_T=51, HDR_PRIVACY_T=52, HDR_REASON_T=53, HDR_EOH_T=54 } type; enum lump_op { LUMP_NOP=0, LUMP_DEL=1, LUMP_ADD=2, LUMP_ADD_SUBST=3, LUMP_ADD_OPT=4 } op; union { int offset; enum lump_subst { SUBST_NOP=0, SUBST_RCV_IP=1, SUBST_SND_IP=2, SUBST_RCV_PORT=3, SUBST_SND_PORT=4, SUBST_RCV_PROTO=5, SUBST_SND_PROTO=6, SUBST_RCV_ALL=7, SUBST_SND_ALL=8 } subst; enum lump_conditions { COND_FALSE=0, COND_TRUE=1, COND_IF_DIFF_REALMS=2, COND_IF_DIFF_AF=3, COND_IF_DIFF_PROTO=4, COND_IF_DIFF_PORT=5, COND_IF_DIFF_IP=6, COND_IF_RAND=7 } cond; char *value; } u; int len; struct lump *before; struct lump *after; struct lump *next; enum lump_flag { LUMPFLAG_NONE=0, LUMPFLAG_DUPED=1, LUMPFLAG_SHMEM=2, LUMPFLAG_BRANCH=4, LUMPFLAG_COND_TRUE=8 } flags; } *add_rm; struct lump *body_lumps; struct lump_rpl { struct _str text; int flags; struct lump_rpl *next; } *reply_lump; char add_to_branch_s[-1]; int add_to_branch_len; unsigned int hash_index; unsigned int msg_flags; unsigned int flags; struct _str set_global_address; struct _str set_global_port; struct socket_info *force_send_socket; struct _str path_vec; struct _str instance; unsigned int reg_id; struct _str ruid; struct _str location_ua; struct msg_ldata { struct ocd_flow { int decoded; struct receive_info rcv; } flow; } ldv; } *

variable_types:
lump
struct lump_rpl *

user_defined_types: struct msg_start { int type; int len; union { struct { struct _str method; struct _str uri; struct _str version; int method_value; } request; struct { struct _str version; struct _str status; struct _str reason; unsigned int statuscode; } reply; } u; }

user_defined_types: struct sip_uri { struct _str user; struct _str passwd; struct _str host; struct _str port; struct _str params; struct _str sip_params; struct _str headers; unsigned short port_no; unsigned short proto; enum _uri_type type; enum _uri_flags flags; struct _str transport; struct _str ttl; struct _str user_param; struct _str maddr; struct _str method; struct _str lr; struct _str r2; struct _str gr; struct _str transport_val; struct _str ttl_val; struct _str user_param_val; struct _str maddr_val; struct _str method_val; struct _str lr_val; struct _str r2_val; struct _str gr_val; }


decompiled_code:
__int64 __fastcall del_nonshm_lump_rpl(__int64 *a1)
{
__int64 v1; // rbx
__int64 *v2; // rbp
__int64 result; // rax
__int64 v4; // rdi

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
while ( 1 )
{
result = *(unsigned int *)(v1 + 16);
v4 = v1;
v1 = *(_QWORD *)(v1 + 24);
if ( (result & 0x20) == 0 )
break;
v2 = (__int64 *)(v4 + 24);
if ( !v1 )
return result;
}
*v2 = v1;
result = free_lump_rpl(v4);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // rbx
__int64 *v2; // rbp
__int64 result; // rax
__int64 v4; // rdi

v1 = *a1;
if ( *a1 )
{
v2 = a1;
do
{
while ( 1 )
{
result = *(unsigned int *)(v1 + 16);
v4 = v1;
v1 = *(_QWORD *)(v1 + 24);
if ( (result & 0x20) == 0 )
break;
v2 = (__int64 *)(v4 + 24);
if ( !v1 )
return result;
}
*v2 = v1;
result = func1(v4);
}
while ( v1 );
}
return result;
}

original_code:
void del_nonshm_lump_rpl(struct lump_rpl** list)
{
        struct lump_rpl* it, *tmp;
        struct lump_rpl** pred;
        it = *list;
        pred = list;
        while(it) {
                if (!(it->flags & (1<<5))) {
                        tmp = it;
                        *pred = it->next;
                        it = it->next;
                        free_lump_rpl(tmp);
                        continue;
                }
                pred = &it->next;
                it = it->next;
        }
}

canonical_original_code:
void del_nonshm_lump_rpl(struct lump_rpl **list)
{
        struct lump_rpl *it; struct lump_rpl *tmp;
        struct lump_rpl **pred;
        it = *list;
        pred = list;
        while(it) {
                if (!(it->flags & (1<<5))) {
                        tmp = it;
                        *pred = it->next;
                        it = it->next;
                        free_lump_rpl(tmp);
                        continue;
                }
                pred = &it->next;
                it = it->next;
        }
}


decompiled_code:
__int64 __fastcall atomic_get_and_set_int(volatile __int32 *a1, __int32 a2)
{
return (unsigned int)_InterlockedExchange(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(volatile __int32 *a1, __int32 a2)
{
return (unsigned int)_InterlockedExchange(a1, a2);
}

original_code: inline static int atomic_get_and_set_int(volatile int* var, int v) { asm volatile( "xchgl %1, %0" " \n\t" : "+q"(v), "=m"(*var) : "m"(*var) : "memory" ); return v; }

canonical_original_code: inline static int atomic_get_and_set_int(int *var, int v) { asm volatile( "xchgl %1, %0" " \n\t" : "+q"(v), "=m"(*var) : "m"(*var) : "memory" ); return v; }

variable_types:
var
int *

variable_types: v int

return_type: int


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

if ( !pkg_proc_stats_list || process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
result = 0LL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 8) = a1;
return result;
}

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

if ( !pkg_proc_stats_list || process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
result = 0LL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 8) = a1;
return result;
}

original_code:
static int pkg_proc_update_used(void *data)
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 if(process_no>=_pkg_proc_stats_no)
  return -1;
 _pkg_proc_stats_list[process_no].used = (unsigned int)(long)data;
 return 0;
}

variable_types:
data
void *


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 func2(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; } *


decompiled_code:
__int64 __fastcall pkg_proc_update_real_used(int a1)
{
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 16) = a1;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 12) = qm_available(mem_block);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 16) = a1;
*(_DWORD *)(pkg_proc_stats_list + 20LL * process_no + 12) = qm_available(mem_block);
return 0LL;
}

original_code:
static int pkg_proc_update_real_used(void *data)
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 if(process_no>=_pkg_proc_stats_no)
  return -1;
 _pkg_proc_stats_list[process_no].real_used = (unsigned int)(long)data;
 _pkg_proc_stats_list[process_no].available = qm_available(mem_block);
 return 0;
}


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 func5(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ecx

result = func4(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 = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func4(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: i int


decompiled_code:
__int64 __fastcall shm_malloc(unsigned int a1)
{
__int64 v1; // r12

futex_get(mem_lock);
v1 = qm_malloc(shm_block, a1);
futex_release(mem_lock);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 v1; // r12

func5(mem_lock);
v1 = qm_malloc(shm_block, a1);
func2(mem_lock);
return v1;
}

original_code:
inline static void* shm_malloc(unsigned int size)
{
 void *p;
 futex_get(mem_lock);
 p=qm_malloc(shm_block, (size));
 futex_release(mem_lock);
  return p;
}

canonical_original_code:
inline static void *shm_malloc(unsigned int size)
{
 void *p;
 futex_get(mem_lock);
 p=qm_malloc(shm_block, (size));
 futex_release(mem_lock);
  return p;
}

variable_types:
size
unsigned int

variable_types:
p
void *

return_type: void *


decompiled_code:
__int64 pkg_proc_stats_init()
{
int v0; // eax

v0 = get_max_procs();
pkg_proc_stats_no = v0;
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
if ( pkg_proc_stats_list )
return 0xFFFFFFFFLL;
pkg_proc_stats_list = shm_malloc(20 * v0);
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
memset((void *)pkg_proc_stats_list, 0, 20LL * pkg_proc_stats_no);
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax

v0 = get_max_procs();
pkg_proc_stats_no = v0;
if ( v0 <= 0 )
return 0xFFFFFFFFLL;
if ( pkg_proc_stats_list )
return 0xFFFFFFFFLL;
pkg_proc_stats_list = func6(20 * v0);
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
memset((void *)pkg_proc_stats_list, 0, 20LL * pkg_proc_stats_no);
return 0LL;
}

original_code:
int pkg_proc_stats_init(void)
{
 _pkg_proc_stats_no = get_max_procs();
 if(_pkg_proc_stats_no<=0)
  return -1;
 if(_pkg_proc_stats_list!=((void *)0))
  return -1;
 _pkg_proc_stats_list = (pkg_proc_stats_t*)shm_malloc(
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 memset(_pkg_proc_stats_list, 0,
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 return 0;
}

canonical_original_code:
int pkg_proc_stats_init()
{
 _pkg_proc_stats_no = get_max_procs();
 if(_pkg_proc_stats_no<=0)
  return -1;
 if(_pkg_proc_stats_list!=((void *)0))
  return -1;
 _pkg_proc_stats_list = (struct pkg_proc_stats *)shm_malloc(
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 memset(_pkg_proc_stats_list, 0,
   _pkg_proc_stats_no*sizeof(pkg_proc_stats_t));
 return 0;
}

user_defined_types: struct pkg_proc_stats { int rank; unsigned int pid; unsigned int used; unsigned int available; unsigned int real_used; }


decompiled_code:
__int64 __fastcall pkg_proc_stats_myinit(int a1)
{
int v2; // eax
_DWORD *v3; // rdi
int v4; // er8
__int64 v5; // rax
_DWORD v7[22]; // [rsp-10h] [rbp-58h] BYREF

if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
v2 = my_pid();
v3 = (_DWORD *)(pkg_proc_stats_list + 20LL * process_no);
v3[1] = v2;
*v3 = a1;
qm_info(mem_block, v7);
v4 = v7[6];
v5 = pkg_proc_stats_list + 20LL * process_no;
*(_DWORD *)(v5 + 8) = v7[4];
*(_DWORD *)(v5 + 16) = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v2; // eax
_DWORD *v3; // rdi
int v4; // er8
__int64 v5; // rax
_DWORD v7[22]; // [rsp-10h] [rbp-58h] BYREF

if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
if ( process_no >= pkg_proc_stats_no )
return 0xFFFFFFFFLL;
v2 = my_pid();
v3 = (_DWORD *)(pkg_proc_stats_list + 20LL * process_no);
v3[1] = v2;
*v3 = a1;
qm_info(mem_block, v7);
v4 = v7[6];
v5 = pkg_proc_stats_list + 20LL * process_no;
*(_DWORD *)(v5 + 8) = v7[4];
*(_DWORD *)(v5 + 16) = v4;
return 0LL;
}

original_code:
int pkg_proc_stats_myinit(int rank)
{
 struct mem_info info;
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 if(process_no>=_pkg_proc_stats_no)
  return -1;
 _pkg_proc_stats_list[process_no].pid = (unsigned int)my_pid();
 _pkg_proc_stats_list[process_no].rank = rank;
 qm_info(mem_block, &info);
 _pkg_proc_stats_list[process_no].used = info.used;
 _pkg_proc_stats_list[process_no].real_used = info.real_used;
 return 0;
}

variable_types: rank int

variable_types: struct mem_info { unsigned long total_size; unsigned long free; unsigned long used; unsigned long real_used; unsigned long max_used; unsigned long min_frag; unsigned long total_frags; }


decompiled_code:
__int64 pkg_proc_stats_destroy()
{
__int64 v0; // rbp
__int64 result; // rax

v0 = pkg_proc_stats_list;
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
futex_get(mem_lock);
qm_free(shm_block, v0);
futex_release(mem_lock);
result = 0LL;
pkg_proc_stats_list = 0LL;
pkg_proc_stats_no = 0;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbp
__int64 result; // rax

v0 = pkg_proc_stats_list;
if ( !pkg_proc_stats_list )
return 0xFFFFFFFFLL;
func5(mem_lock);
qm_free(shm_block, v0);
func2(mem_lock);
result = 0LL;
pkg_proc_stats_list = 0LL;
pkg_proc_stats_no = 0;
return result;
}

original_code:
int pkg_proc_stats_destroy(void)
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 do { futex_get(mem_lock); qm_free(shm_block, (_pkg_proc_stats_list)); futex_release(mem_lock); }while(0);
 _pkg_proc_stats_list = 0;
 _pkg_proc_stats_no = 0;
 return 0;
}

canonical_original_code:
int pkg_proc_stats_destroy()
{
 if(_pkg_proc_stats_list==((void *)0))
  return -1;
 do { futex_get(mem_lock); qm_free(shm_block, (_pkg_proc_stats_list)); futex_release(mem_lock); }while(0);
 _pkg_proc_stats_list = 0;
 _pkg_proc_stats_no = 0;
 return 0;
}


decompiled_code:
__int64 register_pkg_proc_stats()
{
sr_event_register_cb(5LL, pkg_proc_update_used);
sr_event_register_cb(6LL, pkg_proc_update_real_used);
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
sr_event_register_cb(5LL, pkg_proc_update_used);
sr_event_register_cb(6LL, pkg_proc_update_real_used);
return 0LL;
}

original_code:
int register_pkg_proc_stats(void)
{
 sr_event_register_cb(5, pkg_proc_update_used);
 sr_event_register_cb(6, pkg_proc_update_real_used);
 return 0;
}

canonical_original_code:
int register_pkg_proc_stats()
{
 sr_event_register_cb(5, pkg_proc_update_used);
 sr_event_register_cb(6, pkg_proc_update_real_used);
 return 0;
}


decompiled_code:
__int64 __fastcall pkg_proc_get_pid_index(int a1)
{
unsigned int v1; // er8
_DWORD *v2; // rax
int v3; // edx
unsigned int v4; // er9

if ( pkg_proc_stats_no <= 0 )
return (unsigned int)-1;
v1 = 0;
v2 = (_DWORD *)(pkg_proc_stats_list + 4);
v3 = pkg_proc_stats_no & 7;
if ( (pkg_proc_stats_no & 7) == 0 )
{
LABEL_21:
while ( *v2 != a1 )
{
v4 = ++v1;
if ( v2[5] == a1 )
break;
++v1;
if ( v2[10] == a1 )
break;
v1 = v4 + 2;
if ( v2[15] == a1 )
break;
v1 = v4 + 3;
if ( v2[20] == a1 )
break;
v1 = v4 + 4;
if ( v2[25] == a1 )
break;
v1 = v4 + 5;
if ( v2[30] == a1 )
break;
v1 = v4 + 6;
if ( v2[35] == a1 )
break;
v1 = v4 + 7;
v2 += 40;
if ( v4 + 7 == pkg_proc_stats_no )
return (unsigned int)-1;
}
return v1;
}
if ( v3 != 1 )
{
if ( v3 != 2 )
{
if ( v3 != 3 )
{
if ( v3 != 4 )
{
if ( v3 != 5 )
{
if ( v3 != 6 )
{
if ( *v2 == a1 )
return v1;
v1 = 1;
v2 = (_DWORD *)(pkg_proc_stats_list + 24);
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 != a1 )
{
++v1;
v2 += 5;
if ( v1 != pkg_proc_stats_no )
goto LABEL_21;
return (unsigned int)-1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
unsigned int v1; // er8
_DWORD *v2; // rax
int v3; // edx
unsigned int v4; // er9

if ( pkg_proc_stats_no <= 0 )
return (unsigned int)-1;
v1 = 0;
v2 = (_DWORD *)(pkg_proc_stats_list + 4);
v3 = pkg_proc_stats_no & 7;
if ( (pkg_proc_stats_no & 7) == 0 )
{
LABEL_21:
while ( *v2 != a1 )
{
v4 = ++v1;
if ( v2[5] == a1 )
break;
++v1;
if ( v2[10] == a1 )
break;
v1 = v4 + 2;
if ( v2[15] == a1 )
break;
v1 = v4 + 3;
if ( v2[20] == a1 )
break;
v1 = v4 + 4;
if ( v2[25] == a1 )
break;
v1 = v4 + 5;
if ( v2[30] == a1 )
break;
v1 = v4 + 6;
if ( v2[35] == a1 )
break;
v1 = v4 + 7;
v2 += 40;
if ( v4 + 7 == pkg_proc_stats_no )
return (unsigned int)-1;
}
return v1;
}
if ( v3 != 1 )
{
if ( v3 != 2 )
{
if ( v3 != 3 )
{
if ( v3 != 4 )
{
if ( v3 != 5 )
{
if ( v3 != 6 )
{
if ( *v2 == a1 )
return v1;
v1 = 1;
v2 = (_DWORD *)(pkg_proc_stats_list + 24);
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 == a1 )
return v1;
++v1;
v2 += 5;
}
if ( *v2 != a1 )
{
++v1;
v2 += 5;
if ( v1 != pkg_proc_stats_no )
goto LABEL_21;
return (unsigned int)-1;
}
return v1;
}

original_code:
int pkg_proc_get_pid_index(unsigned int pid)
{
 int i;
 for(i=0; i<_pkg_proc_stats_no; i++)
 {
  if(_pkg_proc_stats_list[i].pid == pid)
   return i;
 }
 return -1;
}

variable_types:
pid
unsigned int


decompiled_code:
__int64 __fastcall rpc_pkg_stats(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v5; // er12
int v6; // ebx
__int64 v7; // r14
unsigned int v8; // ebx
__int64 v9; // r15
bool v10; // zf
int v11; // [rsp+Ch] [rbp-5Ch]
int v12; // [rsp+14h] [rbp-54h] BYREF
__int64 v13; // [rsp+18h] [rbp-50h] BYREF
_BYTE *v14; // [rsp+20h] [rbp-48h] BYREF
int v15; // [rsp+28h] [rbp-40h]

if ( !pkg_proc_stats_list )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Not initialized");
v12 = 0;
v11 = pkg_proc_stats_no;
result = (*(__int64 (__fastcall **)(__int64, const char *, _BYTE **))(a1 + 24))(a2, "*S", &v14);
v5 = result;
if ( (_DWORD)result != 1 )
{
v5 = 0;
v6 = 0;
goto LABEL_4;
}
if ( v15 == 3 )
{
if ( *v14 == 112 && v14[1] == 105 && v14[2] == 100 )
{
if ( (*(int (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", &v12) <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
result = pkg_proc_get_pid_index(v12);
v6 = result;
v11 = result + 1;
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "No such pid");
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v15 == 4 )
{
v10 = memcmp(v14, "rank", 4uLL) == 0;
v6 = !v10;
if ( v10 )
{
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", &v12);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v5 = 2;
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v15 != 5 || memcmp(v14, "index", 5uLL) )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", &v12);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v6 = v12;
v5 = 3;
v11 = v12 + 1;
LABEL_4:
if ( v6 >= v11 )
return result;
result = (unsigned int)(v11 - v6);
v7 = 20LL * v6;
if ( (((_BYTE)v11 - (_BYTE)v6) & 1) == 0 )
{
LABEL_18:
while ( 1 )
{
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7) == v12 )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v13) < 0 )
break;
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v13,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(v7 + pkg_proc_stats_list + 4),
"rank",
*(unsigned int *)(v7 + pkg_proc_stats_list),
"used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 8),
"free",
*(unsigned int *)(v7 + pkg_proc_stats_list + 12),
"real_used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 16));
if ( (int)result < 0 )
break;
}
v8 = v6 + 1;
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7 + 20) == v12 )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v13) < 0 )
break;
v9 = v7 + 20;
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v13,
"dddddd",
"entry",
v8,
"pid",
*(unsigned int *)(v9 + pkg_proc_stats_list + 4),
"rank",
*(unsigned int *)(v9 + pkg_proc_stats_list),
"used",
*(unsigned int *)(v9 + pkg_proc_stats_list + 8),
"free",
*(unsigned int *)(v9 + pkg_proc_stats_list + 12),
"real_used",
*(unsigned int *)(v9 + pkg_proc_stats_list + 16));
if ( (int)result < 0 )
break;
}
v6 = v8 + 1;
v7 += 40LL;
if ( v6 == v11 )
return result;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + 20LL * v6) == v12 )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v13) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v13,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(v7 + pkg_proc_stats_list + 4),
"rank",
*(unsigned int *)(v7 + pkg_proc_stats_list),
"used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 8),
"free",
*(unsigned int *)(v7 + pkg_proc_stats_list + 12),
"real_used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 16));
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
++v6;
v7 += 20LL;
if ( v6 != v11 )
goto LABEL_18;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 result; // rax
int v5; // er12
int v6; // ebx
__int64 v7; // r14
unsigned int v8; // ebx
__int64 v9; // r15
bool v10; // zf
int v11; // [rsp+Ch] [rbp-5Ch]
int v12; // [rsp+14h] [rbp-54h] BYREF
__int64 v13; // [rsp+18h] [rbp-50h] BYREF
_BYTE *v14; // [rsp+20h] [rbp-48h] BYREF
int v15; // [rsp+28h] [rbp-40h]

if ( !pkg_proc_stats_list )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Not initialized");
v12 = 0;
v11 = pkg_proc_stats_no;
result = (*(__int64 (__fastcall **)(__int64, const char *, _BYTE **))(a1 + 24))(a2, "*S", &v14);
v5 = result;
if ( (_DWORD)result != 1 )
{
v5 = 0;
v6 = 0;
goto LABEL_4;
}
if ( v15 == 3 )
{
if ( *v14 == 112 && v14[1] == 105 && v14[2] == 100 )
{
if ( (*(int (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", &v12) <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
result = func11(v12);
v6 = result;
v11 = result + 1;
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "No such pid");
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v15 == 4 )
{
v10 = memcmp(v14, "rank", 4uLL) == 0;
v6 = !v10;
if ( v10 )
{
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", &v12);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v5 = 2;
goto LABEL_4;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
}
if ( v15 != 5 || memcmp(v14, "index", 5uLL) )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Invalid filter type");
result = (*(__int64 (__fastcall **)(__int64, const char *, int *))(a1 + 24))(a2, "d", &v12);
if ( (int)result <= 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "One more parameter expected");
v6 = v12;
v5 = 3;
v11 = v12 + 1;
LABEL_4:
if ( v6 >= v11 )
return result;
result = (unsigned int)(v11 - v6);
v7 = 20LL * v6;
if ( (((_BYTE)v11 - (_BYTE)v6) & 1) == 0 )
{
LABEL_18:
while ( 1 )
{
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7) == v12 )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v13) < 0 )
break;
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v13,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(v7 + pkg_proc_stats_list + 4),
"rank",
*(unsigned int *)(v7 + pkg_proc_stats_list),
"used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 8),
"free",
*(unsigned int *)(v7 + pkg_proc_stats_list + 12),
"real_used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 16));
if ( (int)result < 0 )
break;
}
v8 = v6 + 1;
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + v7 + 20) == v12 )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v13) < 0 )
break;
v9 = v7 + 20;
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v13,
"dddddd",
"entry",
v8,
"pid",
*(unsigned int *)(v9 + pkg_proc_stats_list + 4),
"rank",
*(unsigned int *)(v9 + pkg_proc_stats_list),
"used",
*(unsigned int *)(v9 + pkg_proc_stats_list + 8),
"free",
*(unsigned int *)(v9 + pkg_proc_stats_list + 12),
"real_used",
*(unsigned int *)(v9 + pkg_proc_stats_list + 16));
if ( (int)result < 0 )
break;
}
v6 = v8 + 1;
v7 += 40LL;
if ( v6 == v11 )
return result;
}
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
if ( v5 != 2 || *(_DWORD *)(pkg_proc_stats_list + 20LL * v6) == v12 )
{
if ( (*(int (__fastcall **)(__int64, const char *, __int64 *))(a1 + 16))(a2, "{", &v13) < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
result = (*(__int64 (__fastcall **)(__int64, const char *, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD, const char *, _QWORD))(a1 + 40))(
v13,
"dddddd",
"entry",
(unsigned int)v6,
"pid",
*(unsigned int *)(v7 + pkg_proc_stats_list + 4),
"rank",
*(unsigned int *)(v7 + pkg_proc_stats_list),
"used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 8),
"free",
*(unsigned int *)(v7 + pkg_proc_stats_list + 12),
"real_used",
*(unsigned int *)(v7 + pkg_proc_stats_list + 16));
if ( (int)result < 0 )
return (*(__int64 (__fastcall **)(__int64, __int64, const char *))a1)(a2, 500LL, "Internal error creating rpc");
}
++v6;
v7 += 20LL;
if ( v6 != v11 )
goto LABEL_18;
return result;
}

original_code:
static void rpc_pkg_stats(rpc_t* rpc, void* ctx)
{
 int i;
 int limit;
 int cval;
 str cname;
 void* th;
 int mode;
 if(_pkg_proc_stats_list==((void *)0))
 {
  rpc->fault(ctx, 500, "Not initialized");
  return;
 }
 i = 0;
 mode = 0;
 cval = 0;
 limit = _pkg_proc_stats_no;
 if (rpc->scan(ctx, "*S", &cname) == 1)
 {
  if(cname.len==3 && strncmp(cname.s, "pid", 3)==0)
   mode = 1;
  else if(cname.len==4 && strncmp(cname.s, "rank", 4)==0)
   mode = 2;
  else if(cname.len==5 && strncmp(cname.s, "index", 5)==0)
   mode = 3;
  else {
   rpc->fault(ctx, 500, "Invalid filter type");
   return;
  }
  if (rpc->scan(ctx, "d", &cval) < 1)
  {
   rpc->fault(ctx, 500, "One more parameter expected");
   return;
  }
  if(mode==1)
  {
   i = pkg_proc_get_pid_index((unsigned int)cval);
   if(i<0)
   {
    rpc->fault(ctx, 500, "No such pid");
    return;
   }
   limit = i + 1;
  } else if(mode==3) {
   i=cval;
   limit = i + 1;
  }
 }
 for(; i<limit; i++)
 {
  if(mode!=2 || _pkg_proc_stats_list[i].rank==cval)
  {
   if (rpc->add(ctx, "{", &th) < 0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
   if(rpc->struct_add(th, "dddddd",
       "entry", i,
       "pid", _pkg_proc_stats_list[i].pid,
       "rank", _pkg_proc_stats_list[i].rank,
       "used", _pkg_proc_stats_list[i].used,
       "free", _pkg_proc_stats_list[i].available,
       "real_used", _pkg_proc_stats_list[i].real_used
      )<0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
  }
 }
}

canonical_original_code:
static void rpc_pkg_stats(struct rpc *rpc, void *ctx)
{
 int i;
 int limit;
 int cval;
 struct _str cname;
 void *th;
 int mode;
 if(_pkg_proc_stats_list==((void *)0))
 {
  rpc->fault(ctx, 500, "Not initialized");
  return;
 }
 i = 0;
 mode = 0;
 cval = 0;
 limit = _pkg_proc_stats_no;
 if (rpc->scan(ctx, "*S", &cname) == 1)
 {
  if(cname.len==3 && strncmp(cname.s, "pid", 3)==0)
   mode = 1;
  else if(cname.len==4 && strncmp(cname.s, "rank", 4)==0)
   mode = 2;
  else if(cname.len==5 && strncmp(cname.s, "index", 5)==0)
   mode = 3;
  else {
   rpc->fault(ctx, 500, "Invalid filter type");
   return;
  }
  if (rpc->scan(ctx, "d", &cval) < 1)
  {
   rpc->fault(ctx, 500, "One more parameter expected");
   return;
  }
  if(mode==1)
  {
   i = pkg_proc_get_pid_index((unsigned int)cval);
   if(i<0)
   {
    rpc->fault(ctx, 500, "No such pid");
    return;
   }
   limit = i + 1;
  } else if(mode==3) {
   i=cval;
   limit = i + 1;
  }
 }
 for(; i<limit; i++)
 {
  if(mode!=2 || _pkg_proc_stats_list[i].rank==cval)
  {
   if (rpc->add(ctx, "{", &th) < 0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
   if(rpc->struct_add(th, "dddddd",
       "entry", i,
       "pid", _pkg_proc_stats_list[i].pid,
       "rank", _pkg_proc_stats_list[i].rank,
       "used", _pkg_proc_stats_list[i].used,
       "free", _pkg_proc_stats_list[i].available,
       "real_used", _pkg_proc_stats_list[i].real_used
      )<0)
   {
    rpc->fault(ctx, 500, "Internal error creating rpc");
    return;
   }
  }
 }
}

variable_types: struct rpc { void (*fault)(void *ctx, int code, char *fmt, ...); int (*send)(void *ctx); int (*add)(void *ctx, char *fmt, ...); int (*scan)(void *ctx, char *fmt, ...); int (*printf)(void *ctx, char *fmt, ...); int (*struct_add)(void *ctx, char *fmt, ...); int (*struct_scan)(void *ctx, char *fmt, ...); int (*struct_printf)(void *ctx, char *name, char *fmt, ...); enum rpc_capabilities { RPC_DELAYED_REPLY=expr } (*capabilities)(void *ctx); struct rpc_delayed_ctx { struct rpc rpc; void *reply_ctx; } *(*delayed_ctx_new)(void *ctx); void (*delayed_ctx_close)(struct rpc_delayed_ctx *dctx); } *

variable_types:
ctx
void *

variable_types: limit int

variable_types: cval int

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

variable_types:
th
void *

variable_types: mode int

user_defined_types: struct rpc { void (*fault)(void *ctx, int code, char *fmt, ...); int (*send)(void *ctx); int (*add)(void *ctx, char *fmt, ...); int (*scan)(void *ctx, char *fmt, ...); int (*printf)(void *ctx, char *fmt, ...); int (*struct_add)(void *ctx, char *fmt, ...); int (*struct_scan)(void *ctx, char *fmt, ...); int (*struct_printf)(void *ctx, char *name, char *fmt, ...); enum rpc_capabilities (*capabilities)(void *ctx); struct rpc_delayed_ctx *(*delayed_ctx_new)(void *ctx); void (*delayed_ctx_close)(struct rpc_delayed_ctx *dctx); }


decompiled_code:
__int64 pkg_proc_stats_init_rpc()
{
__int64 result; // rax
int v1; // er8
const char *v2; // r12
struct _IO_FILE *v3; // rdi
__int64 v4; // [rsp-10h] [rbp-28h]
unsigned int v5; // [rsp-8h] [rbp-20h]

result = rpc_register_array(&kex_pkg_rpc);
if ( (_DWORD)result )
{
v1 = get_debug_level("kex", 3LL);
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);
v5 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to register RPC commands\n",
process_no,
v5,
v2,
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): failed to register RPC commands\n", v4);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int v1; // er8
const char *v2; // r12
struct _IO_FILE *v3; // rdi
__int64 v4; // [rsp-10h] [rbp-28h]
unsigned int v5; // [rsp-8h] [rbp-20h]

result = rpc_register_array(&kex_pkg_rpc);
if ( (_DWORD)result )
{
v1 = get_debug_level("kex", 3LL);
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);
v5 = my_pid();
v3 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): failed to register RPC commands\n",
process_no,
v5,
v2,
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
if ( log_color )
dprint_color_reset(v3, "%2d(%d) %s: %s%s(): failed to register RPC commands\n", v4);
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): failed to register RPC commands\n",
*((const char **)&log_level_info + 8),
"kex [pkg_stats.c:272]: ",
"pkg_proc_stats_init_rpc");
}
result = 0xFFFFFFFFLL;
--dprint_crit;
}
}
return result;
}

original_code:
int pkg_proc_stats_init_rpc(void)
{
 if (rpc_register_array(kex_pkg_rpc)!=0)
 {
  do { if (get_debug_level("kex", (sizeof("kex")-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(): " "failed to register RPC commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

canonical_original_code:
int pkg_proc_stats_init_rpc()
{
 if (rpc_register_array(kex_pkg_rpc)!=0)
 {
  do { if (get_debug_level("kex", (sizeof("kex")-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(): " "failed to register RPC commands\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", (log_level_info[((-1)) - (-5)].name), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "failed to register RPC commands\n", process_no, my_pid(), ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __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(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "failed to register RPC commands\n", ("kex" " [" "pkg_stats.c" ":" "272" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 return 0;
}

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


canonical_decompiled_code:
__int64 __fastcall func1(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;
}


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

result = func2(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 = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(a1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_24;
result = func2(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;
}