decompiled_code:
__int64 __fastcall sdpops_build_ids_list(__int64 a1, const __m128i *a2, _QWORD *a3)
{
char *v4; // r14
const char *v5; // rbx
__int32 v6; // ebp
const char *v7; // r12
unsigned int v8; // eax
__m128i *v9; // r12
__int32 v10; // ebx
char *v11; // r14
const char *v12; // rbx
__int32 v13; // ebp
const char *v14; // r12
unsigned int v15; // eax
unsigned int v16; // ebx
const char *v18; // r15
unsigned int v19; // eax
int v20; // edx
const char *v21; // r14
int v22; // er13
const char *v23; // r12
__int32 v24; // er15
const char *v25; // rbp
unsigned int v26; // eax
unsigned int v27; // [rsp+10h] [rbp-108h]
unsigned int v28; // [rsp+10h] [rbp-108h]
const char *v29; // [rsp+28h] [rbp-F0h]
const char *v30; // [rsp+28h] [rbp-F0h]
__int32 v31; // [rsp+34h] [rbp-E4h]
__int32 v32; // [rsp+34h] [rbp-E4h]
const char *v33; // [rsp+38h] [rbp-E0h]
const char *v34; // [rsp+38h] [rbp-E0h]
__m128i v35; // [rsp+40h] [rbp-D8h] BYREF
__int64 v36; // [rsp+50h] [rbp-C8h]
const char *v37; // [rsp+C0h] [rbp-58h] BYREF
unsigned int v38; // [rsp+C8h] [rbp-50h]
__m128i v39; // [rsp+D0h] [rbp-48h] BYREF

v39 = _mm_loadu_si128(a2);
*((_DWORD *)a3 + 2) = 0;
*a3 = 0LL;
v4 = local_idslist_1;
LABEL_12:
while ( !(unsigned int)str_find_token((__int64)&v39, (__int64)&v37, 44) && (int)v38 > 0 )
{
v39.m128i_i32[2] -= v38;
v39.m128i_i64[0] = (__int64)&v37[v38];
v35.m128i_i64[0] = 0LL;
if ( (unsigned int)sdpops_get_ids_by_name((__int64)&v37, &v35) )
{
if ( !(unsigned int)sdpops_sdp_get_ids_by_name(a1, (__int64)&v37, (__int64)&v35, 8)
&& (int)get_debug_level("sdpops", 6LL) > 2
&& !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = (const char *)v35.m128i_i64[0];
v13 = v35.m128i_i32[2];
v14 = v37;
v28 = v38;
v30 = (const char *)a2->m128i_i64[0];
v32 = a2->m128i_i32[2];
v34 = (const char *)*((_QWORD *)&log_level_info + 16);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n",
process_no,
v15,
v34,
"sdpops [sdpops_data.c:228]: ",
"sdpops_build_ids_list",
v32,
v30,
v28,
v14,
v13,
v12);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sdpops [sdpops_data.c:228]: ",
"sdpops_build_ids_list",
a2->m128i_u32[2],
a2->m128i_i64[0],
v38,
v37,
v35.m128i_u32[2],
v35.m128i_i64[0]);
}
--dprint_crit;
}
}
else
{
if ( (int)get_debug_level("sdpops", 6LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v5 = (const char *)v35.m128i_i64[0];
v6 = v35.m128i_i32[2];
v7 = v37;
v27 = v38;
v29 = (const char *)a2->m128i_i64[0];
v31 = a2->m128i_i32[2];
v33 = (const char *)*((_QWORD *)&log_level_info + 16);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n",
process_no,
v8,
v33,
"sdpops [sdpops_data.c:221]: ",
"sdpops_build_ids_list",
v31,
v29,
v27,
v7,
v6,
v5);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sdpops [sdpops_data.c:221]: ",
"sdpops_build_ids_list",
a2->m128i_u32[2],
a2->m128i_i64[0],
v38,
v37,
v35.m128i_u32[2],
v35.m128i_i64[0]);
}
--dprint_crit;
}
v36 = 0LL;
}
v9 = &v35;
while ( v9->m128i_i64[0] )
{
v10 = v9->m128i_i32[2];
if ( *((_DWORD *)a3 + 2) + v10 > 63 )
{
if ( (int)get_debug_level("sdpops", 6LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v18 = (const char *)*((_QWORD *)&log_level_info + 8);
v19 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): the list with codecs ids is too big\n",
process_no,
v19,
v18,
"sdpops [sdpops_data.c:237]: ",
"sdpops_build_ids_list");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): the list with codecs ids is too big\n",
*((const char **)&log_level_info + 8),
"sdpops [sdpops_data.c:237]: ",
"sdpops_build_ids_list");
}
--dprint_crit;
}
*((_DWORD *)a3 + 2) = 0;
*a3 = 0LL;
return (unsigned int)-1;
}
strncpy(v4, (const char *)v9->m128i_i64[0], v10);
v11 = &v4[v10];
*v11 = 44;
v4 = v11 + 1;
*((_DWORD *)a3 + 2) += v10 + 1;
if ( ++v9 == (__m128i *)&v37 )
goto LABEL_12;
}
}
v20 = *((_DWORD *)a3 + 2);
if ( v20 <= 0 )
return (unsigned int)-1;
*((_DWORD *)a3 + 2) = v20 - 1;
*(v4 - 1) = 0;
*a3 = local_idslist_1;
v16 = 0;
if ( (int)get_debug_level("sdpops", 6LL) > 2 )
{
v16 = dprint_crit;
if ( dprint_crit )
{
v16 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v21 = (const char *)*a3;
v22 = *((_DWORD *)a3 + 2);
v23 = (const char *)a2->m128i_i64[0];
v24 = a2->m128i_i32[2];
v25 = (const char *)*((_QWORD *)&log_level_info + 16);
v26 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): codecs list [%.*s] - ids list [%.*s]\n",
process_no,
v26,
v25,
"sdpops [sdpops_data.c:255]: ",
"sdpops_build_ids_list",
v24,
v23,
v22,
v21);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): codecs list [%.*s] - ids list [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sdpops [sdpops_data.c:255]: ",
"sdpops_build_ids_list",
a2->m128i_u32[2],
a2->m128i_i64[0],
*((unsigned int *)a3 + 2),
*a3);
}
--dprint_crit;
}
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const __m128i *a2, _QWORD *a3)
{
char *v4; // r14
const char *v5; // rbx
__int32 v6; // ebp
const char *v7; // r12
unsigned int v8; // eax
__m128i *v9; // r12
__int32 v10; // ebx
char *v11; // r14
const char *v12; // rbx
__int32 v13; // ebp
const char *v14; // r12
unsigned int v15; // eax
unsigned int v16; // ebx
const char *v18; // r15
unsigned int v19; // eax
int v20; // edx
const char *v21; // r14
int v22; // er13
const char *v23; // r12
__int32 v24; // er15
const char *v25; // rbp
unsigned int v26; // eax
unsigned int v27; // [rsp+10h] [rbp-108h]
unsigned int v28; // [rsp+10h] [rbp-108h]
const char *v29; // [rsp+28h] [rbp-F0h]
const char *v30; // [rsp+28h] [rbp-F0h]
__int32 v31; // [rsp+34h] [rbp-E4h]
__int32 v32; // [rsp+34h] [rbp-E4h]
const char *v33; // [rsp+38h] [rbp-E0h]
const char *v34; // [rsp+38h] [rbp-E0h]
__m128i v35; // [rsp+40h] [rbp-D8h] BYREF
__int64 v36; // [rsp+50h] [rbp-C8h]
const char *v37; // [rsp+C0h] [rbp-58h] BYREF
unsigned int v38; // [rsp+C8h] [rbp-50h]
__m128i v39; // [rsp+D0h] [rbp-48h] BYREF

v39 = _mm_loadu_si128(a2);
*((_DWORD *)a3 + 2) = 0;
*a3 = 0LL;
v4 = local_idslist_1;
LABEL_12:
while ( !(unsigned int)func3((__int64)&v39, (__int64)&v37, 44) && (int)v38 > 0 )
{
v39.m128i_i32[2] -= v38;
v39.m128i_i64[0] = (__int64)&v37[v38];
v35.m128i_i64[0] = 0LL;
if ( (unsigned int)func1((__int64)&v37, &v35) )
{
if ( !(unsigned int)func2(a1, (__int64)&v37, (__int64)&v35, 8)
&& (int)get_debug_level("sdpops", 6LL) > 2
&& !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v12 = (const char *)v35.m128i_i64[0];
v13 = v35.m128i_i32[2];
v14 = v37;
v28 = v38;
v30 = (const char *)a2->m128i_i64[0];
v32 = a2->m128i_i32[2];
v34 = (const char *)*((_QWORD *)&log_level_info + 16);
v15 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n",
process_no,
v15,
v34,
"sdpops [sdpops_data.c:228]: ",
"sdpops_build_ids_list",
v32,
v30,
v28,
v14,
v13,
v12);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sdpops [sdpops_data.c:228]: ",
"sdpops_build_ids_list",
a2->m128i_u32[2],
a2->m128i_i64[0],
v38,
v37,
v35.m128i_u32[2],
v35.m128i_i64[0]);
}
--dprint_crit;
}
}
else
{
if ( (int)get_debug_level("sdpops", 6LL) > 2 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v5 = (const char *)v35.m128i_i64[0];
v6 = v35.m128i_i32[2];
v7 = v37;
v27 = v38;
v29 = (const char *)a2->m128i_i64[0];
v31 = a2->m128i_i32[2];
v33 = (const char *)*((_QWORD *)&log_level_info + 16);
v8 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n",
process_no,
v8,
v33,
"sdpops [sdpops_data.c:221]: ",
"sdpops_build_ids_list",
v31,
v29,
v27,
v7,
v6,
v5);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sdpops [sdpops_data.c:221]: ",
"sdpops_build_ids_list",
a2->m128i_u32[2],
a2->m128i_i64[0],
v38,
v37,
v35.m128i_u32[2],
v35.m128i_i64[0]);
}
--dprint_crit;
}
v36 = 0LL;
}
v9 = &v35;
while ( v9->m128i_i64[0] )
{
v10 = v9->m128i_i32[2];
if ( *((_DWORD *)a3 + 2) + v10 > 63 )
{
if ( (int)get_debug_level("sdpops", 6LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v18 = (const char *)*((_QWORD *)&log_level_info + 8);
v19 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): the list with codecs ids is too big\n",
process_no,
v19,
v18,
"sdpops [sdpops_data.c:237]: ",
"sdpops_build_ids_list");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): the list with codecs ids is too big\n",
*((const char **)&log_level_info + 8),
"sdpops [sdpops_data.c:237]: ",
"sdpops_build_ids_list");
}
--dprint_crit;
}
*((_DWORD *)a3 + 2) = 0;
*a3 = 0LL;
return (unsigned int)-1;
}
strncpy(v4, (const char *)v9->m128i_i64[0], v10);
v11 = &v4[v10];
*v11 = 44;
v4 = v11 + 1;
*((_DWORD *)a3 + 2) += v10 + 1;
if ( ++v9 == (__m128i *)&v37 )
goto LABEL_12;
}
}
v20 = *((_DWORD *)a3 + 2);
if ( v20 <= 0 )
return (unsigned int)-1;
*((_DWORD *)a3 + 2) = v20 - 1;
*(v4 - 1) = 0;
*a3 = local_idslist_1;
v16 = 0;
if ( (int)get_debug_level("sdpops", 6LL) > 2 )
{
v16 = dprint_crit;
if ( dprint_crit )
{
v16 = 0;
}
else
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(3LL);
v21 = (const char *)*a3;
v22 = *((_DWORD *)a3 + 2);
v23 = (const char *)a2->m128i_i64[0];
v24 = a2->m128i_i32[2];
v25 = (const char *)*((_QWORD *)&log_level_info + 16);
v26 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): codecs list [%.*s] - ids list [%.*s]\n",
process_no,
v26,
v25,
"sdpops [sdpops_data.c:255]: ",
"sdpops_build_ids_list",
v24,
v23,
v22,
v21);
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 34) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): codecs list [%.*s] - ids list [%.*s]\n",
*((_QWORD *)&log_level_info + 16),
"sdpops [sdpops_data.c:255]: ",
"sdpops_build_ids_list",
a2->m128i_u32[2],
a2->m128i_i64[0],
*((unsigned int *)a3 + 2),
*a3);
}
--dprint_crit;
}
}
return v16;
}

original_code:
int sdpops_build_ids_list(sdp_info_t *sdp, str *names, str *ids)
{
 static char _local_idslist[64];
 str tmp;
 str codec;
 str cids[8];
 char *p;
 int i;
 tmp = *names;
 ids->len = 0;
 ids->s = 0;
 p = _local_idslist;
 while(str_find_token(&tmp, &codec, ',')==0
  && codec.len>0)
 {
  tmp.len -= (int)(&codec.s[codec.len]-codec.s);
  tmp.s = codec.s + codec.len;
  cids[0].s = ((void *)0);
  if(sdpops_get_ids_by_name(&codec, &cids[0])==0) {
   do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } (dprint_crit--); } } while(0);
   cids[1].s = ((void *)0);
  } else {
   if(sdpops_sdp_get_ids_by_name(sdp, &codec, cids, 8)==0) {
    do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } (dprint_crit--); } } while(0);
   }
  }
  for(i=0; i<8 && cids[i].s!=((void *)0); i++) {
   if(ids->len + cids[i].len>=64)
   {
    do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "the list with codecs ids is too big\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __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(): " "the list with codecs ids is too big\n", (log_level_info[((-1)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "the list with codecs ids is too big\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __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(): " "the list with codecs ids is too big\n", ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "the list with codecs ids is too big\n", ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __func__); } } (dprint_crit--); } } while(0);
    ids->len = 0;
    ids->s = 0;
    return -1;
   }
   strncpy(p, cids[i].s, cids[i].len);
   p += cids[i].len;
   *p = ',';
   p++;
   ids->len += cids[i].len + 1;
  }
 }
 if(ids->len>0)
 {
  p--;
  ids->len--;
  *p = '\0';
  ids->s = _local_idslist;
  do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "codecs list [%.*s] - ids list [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); 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(): " "codecs list [%.*s] - ids list [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "codecs list [%.*s] - ids list [%.*s]\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); 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(): " "codecs list [%.*s] - ids list [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "codecs list [%.*s] - ids list [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); } } (dprint_crit--); } } while(0);
  return 0;
 }
 return -1;
}

canonical_original_code:
int sdpops_build_ids_list(struct sdp_info *sdp, struct _str *names, struct _str *ids)
{
 static char _local_idslist[64];
 struct _str tmp;
 struct _str codec;
 struct _str cids[8];
 char *p;
 int i;
 tmp = *names;
 ids->len = 0;
 ids->s = 0;
 p = _local_idslist;
 while(str_find_token(&tmp, &codec, ',')==0
  && codec.len>0)
 {
  tmp.len -= (int)(&codec.s[codec.len]-codec.s);
  tmp.s = codec.s + codec.len;
  cids[0].s = ((void *)0);
  if(sdpops_get_ids_by_name(&codec, &cids[0])==0) {
   do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "codecs list [%.*s] - at name [%.*s] with list ids [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "221" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } (dprint_crit--); } } while(0);
   cids[1].s = ((void *)0);
  } else {
   if(sdpops_sdp_get_ids_by_name(sdp, &codec, cids, 8)==0) {
    do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); 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(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "codecs list [%.*s] - at name [%.*s] with first sdp id [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "228" "]: ") , __func__, names->len, names->s, codec.len, codec.s, cids[0].len, cids[0].s); } } (dprint_crit--); } } while(0);
   }
  }
  for(i=0; i<8 && cids[i].s!=((void *)0); i++) {
   if(ids->len + cids[i].len>=64)
   {
    do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "the list with codecs ids is too big\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __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(): " "the list with codecs ids is too big\n", (log_level_info[((-1)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "the list with codecs ids is too big\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __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(): " "the list with codecs ids is too big\n", ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "the list with codecs ids is too big\n", ("sdpops" " [" "sdpops_data.c" ":" "237" "]: ") , __func__); } } (dprint_crit--); } } while(0);
    ids->len = 0;
    ids->s = 0;
    return -1;
   }
   strncpy(p, cids[i].s, cids[i].len);
   p += cids[i].len;
   *p = ',';
   p++;
   ids->len += cids[i].len + 1;
  }
 }
 if(ids->len>0)
 {
  p--;
  ids->len--;
  *p = '\0';
  ids->s = _local_idslist;
  do { if (get_debug_level("sdpops", (sizeof("sdpops")-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(): " "codecs list [%.*s] - ids list [%.*s]\n", process_no, my_pid(), (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); 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(): " "codecs list [%.*s] - ids list [%.*s]\n", (log_level_info[((3)) - (-5)].name), ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((3)); fprintf(stderr, "%2d(%d) %s" "%s(): " "codecs list [%.*s] - ids list [%.*s]\n", process_no, my_pid(), ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); 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(): " "codecs list [%.*s] - ids list [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "codecs list [%.*s] - ids list [%.*s]\n", ("sdpops" " [" "sdpops_data.c" ":" "255" "]: ") , __func__, names->len, names->s, ids->len, ids->s); } } (dprint_crit--); } } while(0);
  return 0;
 }
 return -1;
}

variable_types:
names
struct _str *

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

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

variable_types:
cids
struct _str { char *s; int len; } [8]

variable_types:
p
char *

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

user_defined_types: enum msg_body_type { MSG_BODY_UNKNOWN=0, MSG_BODY_SDP=1 }

user_defined_types: struct sdp_ice_attr { struct sdp_ice_attr *next; struct _str foundation; unsigned int component_id; struct _str transport; struct _str connection_addr; struct _str port; struct _str candidate_type; int candidateType; }

user_defined_types: struct sdp_payload_attr { struct sdp_payload_attr *next; int payload_num; struct _str rtp_payload; struct _str rtp_enc; struct _str rtp_clock; struct _str rtp_params; struct _str fmtp_string; }


repo: virtualolson/who

decompiled_code:
__int64 __fastcall find_mime(int *a1, int a2)
{
int v2; // edx
__int64 v3; // rax
unsigned int v4; // ecx

v2 = *a1;
if ( !*a1 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( a2 == v2 )
break;
v2 = a1[++v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2)
{
int v2; // edx
__int64 v3; // rax
unsigned int v4; // ecx

v2 = *a1;
if ( !*a1 )
return (unsigned int)-1;
v3 = 0LL;
while ( 1 )
{
v4 = v3;
if ( a2 == v2 )
break;
v2 = a1[++v3];
if ( !v2 )
return (unsigned int)-1;
}
return v4;
}

original_code:
static int find_mime(int *mimes, int m)
{
 int i;
 for (i = 0; mimes[i]; i++) {
  if (mimes[i] == m) return i;
 }
 return -1;
}

variable_types:
mimes
int *

variable_types: m int

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall get_accepted_mime_type_idx(int *a1, __int64 a2)
{
int v3; // esi
__int64 v4; // rbx
unsigned int v5; // er13

if ( !a1 )
return (unsigned int)-1;
v3 = *(_DWORD *)(a2 + 4);
if ( !v3 )
return (unsigned int)-1;
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( (int)find_mime(a1, v3) >= 0 )
break;
++v4;
v3 = *(_DWORD *)(a2 + 4 * v4 + 4);
if ( !v3 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, __int64 a2)
{
int v3; // esi
__int64 v4; // rbx
unsigned int v5; // er13

if ( !a1 )
return (unsigned int)-1;
v3 = *(_DWORD *)(a2 + 4);
if ( !v3 )
return (unsigned int)-1;
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( (int)func0(a1, v3) >= 0 )
break;
++v4;
v3 = *(_DWORD *)(a2 + 4 * v4 + 4);
if ( !v3 )
return (unsigned int)-1;
}
return v5;
}

original_code:
static int get_accepted_mime_type_idx(int *accepts_mimes, event_mimetypes_t *em)
{
 int i, mt;
 if (accepts_mimes) {
  i = 0;
  while ((mt = em->mimes[i]) != 0) {
   if (find_mime(accepts_mimes, mt) >= 0) return i;
   i++;
  }
 }
 return -1;
}

canonical_original_code:
static int get_accepted_mime_type_idx(int *accepts_mimes, struct event_mimetypes_t *em)
{
 int i; int mt;
 if (accepts_mimes) {
  i = 0;
  while ((mt = em->mimes[i]) != 0) {
   if (find_mime(accepts_mimes, mt) >= 0) return i;
   i++;
  }
 }
 return -1;
}

variable_types: struct event_mimetypes_t { int event_type; int mimes[128]; } *

variable_types: mt int


decompiled_code:
int *__fastcall find_event_mimetypes(int a1)
{
int v1; // eax

if ( event_package_mimetypes[0] == -1 || a1 == event_package_mimetypes[0] )
{
v1 = 0;
}
else if ( dword_504 == -1 || (v1 = 2, a1 == dword_504) )
{
v1 = 1;
}
return &event_package_mimetypes[129 * v1];
}

canonical_decompiled_code:
int *__fastcall func2(int a1)
{
int v1; // eax

if ( event_package_mimetypes[0] == -1 || a1 == event_package_mimetypes[0] )
{
v1 = 0;
}
else if ( dword_504 == -1 || (v1 = 2, a1 == dword_504) )
{
v1 = 1;
}
return &event_package_mimetypes[129 * v1];
}

original_code:
event_mimetypes_t *find_event_mimetypes(int et)
{
 int i;
 event_mimetypes_t *em;
 i = 0;
 while (et != event_package_mimetypes[i].event_type) {
  if (event_package_mimetypes[i].event_type == -1) break;
  i++;
 }
 em = &event_package_mimetypes[i];
 return em;
}

canonical_original_code:
struct event_mimetypes_t *find_event_mimetypes(int et)
{
 int i;
 struct event_mimetypes_t *em;
 i = 0;
 while (et != event_package_mimetypes[i].event_type) {
  if (event_package_mimetypes[i].event_type == -1) break;
  i++;
 }
 em = &event_package_mimetypes[i];
 return em;
}

variable_types: et int

return_type: struct event_mimetypes_t { int event_type; int mimes[128]; } *


decompiled_code:
__int64 __fastcall check_mime_types(int *a1, __int64 a2)
{
__int64 result; // rax
int v3; // er12
__int64 v4; // rbx
int v5; // eax
int v6; // edx

result = 0LL;
if ( a1 )
{
v3 = *(_DWORD *)(a2 + 4);
if ( v3 )
{
v4 = a2 + 8;
while ( 1 )
{
v5 = find_mime(a1, v3);
if ( v5 >= 0 )
break;
v4 += 4LL;
v3 = *(_DWORD *)(v4 - 4);
if ( !v3 )
return 0xFFFFFFFFLL;
}
v6 = *a1;
*a1 = v3;
a1[v5] = v6;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, __int64 a2)
{
__int64 result; // rax
int v3; // er12
__int64 v4; // rbx
int v5; // eax
int v6; // edx

result = 0LL;
if ( a1 )
{
v3 = *(_DWORD *)(a2 + 4);
if ( v3 )
{
v4 = a2 + 8;
while ( 1 )
{
v5 = func0(a1, v3);
if ( v5 >= 0 )
break;
v4 += 4LL;
v3 = *(_DWORD *)(v4 - 4);
if ( !v3 )
return 0xFFFFFFFFLL;
}
v6 = *a1;
*a1 = v3;
a1[v5] = v6;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int check_mime_types(int *accepts_mimes, event_mimetypes_t *em)
{
 if (accepts_mimes) {
  int j = 0, k;
  int mimetype;
  while ((mimetype = em->mimes[j]) != 0) {
   k = find_mime(accepts_mimes, mimetype);
   if (k >= 0) {
    int am0 = accepts_mimes[0];
    accepts_mimes[0] = mimetype;
    accepts_mimes[k] = am0;
    return 0;
   }
   j++;
  }
  return -1;
 }
 return 0;
}

canonical_original_code:
int check_mime_types(int *accepts_mimes, struct event_mimetypes_t *em)
{
 if (accepts_mimes) {
  int j = 0; int k;
  int mimetype;
  while ((mimetype = em->mimes[j]) != 0) {
   k = find_mime(accepts_mimes, mimetype);
   if (k >= 0) {
    int am0 = accepts_mimes[0];
    accepts_mimes[0] = mimetype;
    accepts_mimes[k] = am0;
    return 0;
   }
   j++;
  }
  return -1;
 }
 return 0;
}

variable_types: j int

variable_types: k int

variable_types: mimetype int

user_defined_types: struct event_mimetypes_t { int event_type; int mimes[128]; }


decompiled_code:
__int64 __fastcall fastrand_seed(unsigned int a1)
{
int *v1; // rbp

srandom(a1);
v1 = &dword_E4;
do
{
*v1 = random();
v1[1] = random();
v1[2] = random();
v1[3] = random();
v1[4] = random();
v1[5] = random();
v1[6] = random();
v1[7] = random();
v1 += 8;
}
while ( v1 != (int *)&unk_4E4 );
return randinit(&is_ctx, 1LL);
}

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

srandom(a1);
v1 = &dword_E4;
do
{
*v1 = random();
v1[1] = random();
v1[2] = random();
v1[3] = random();
v1[4] = random();
v1[5] = random();
v1[6] = random();
v1[7] = random();
v1 += 8;
}
while ( v1 != (int *)&unk_4E4 );
return randinit(&is_ctx, 1LL);
}

original_code:
void fastrand_seed(unsigned int seed)
{
 int i;
 srandom(seed);
 for (i=0; i<(1<<(8)); i++)
  is_ctx.randrsl[i]=random();
 randinit(&is_ctx, 1);
}

variable_types:
seed
unsigned int

return_type: void


fastrand

decompiled_code:
__int64 fastrand()
{
int v0; // edx
int v1; // eax

v0 = is_ctx;
v1 = --is_ctx;
if ( v0 )
return (unsigned int)dword_E4[v1];
isaac(&is_ctx);
is_ctx = 255;
return (unsigned int)dword_4E0;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // edx
int v1; // eax

v0 = is_ctx;
v1 = --is_ctx;
if ( v0 )
return (unsigned int)dword_E4[v1];
isaac(&is_ctx);
is_ctx = 255;
return (unsigned int)dword_4E0;
}

original_code:
unsigned int fastrand()
{
 return (!(&is_ctx)->randcnt-- ? (isaac(&is_ctx), (&is_ctx)->randcnt=(1<<(8))-1, (&is_ctx)->randrsl[(&is_ctx)->randcnt]) : (&is_ctx)->randrsl[(&is_ctx)->randcnt]);
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall fastrand_max(int a1)
{
return (unsigned int)fastrand() % (a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)func1() % (a1 + 1);
}

original_code:
unsigned int fastrand_max(unsigned int max)
{
 return fastrand()%(max+1);
}

variable_types:
max
unsigned int


decompiled_code:
__int64 __fastcall char2int(char *a1, _DWORD *a2)
{
char v2; // al
char v3; // di

v2 = *a1;
if ( (unsigned __int8)(*a1 - 48) > 9u )
return 0xFFFFFFFFLL;
v3 = a1[1];
if ( (unsigned __int8)(v3 - 48) > 9u )
return 0xFFFFFFFFLL;
*a2 = v3 + 2 * (5 * v2 - 240) - 48;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _DWORD *a2)
{
char v2; // al
char v3; // di

v2 = *a1;
if ( (unsigned __int8)(*a1 - 48) > 9u )
return 0xFFFFFFFFLL;
v3 = a1[1];
if ( (unsigned __int8)(v3 - 48) > 9u )
return 0xFFFFFFFFLL;
*a2 = v3 + 2 * (5 * v2 - 240) - 48;
return 0LL;
}

variable_types:
t
int *


original_code:
static int rfc1123totm (char *stime, struct tm *ttm ) {
 char *ptime = stime;
 unsigned int uval;
 int ires;
 uval = (*(ptime + 0) + (*(ptime + 1) << 8) + (*(ptime + 2) << 16) + (*(ptime + 3) << 24));
 ptime+=4;
 switch (uval) {
  case 0x2c6e7553: ttm->tm_wday = 0; break;
  case 0x2c6e6f4d: ttm->tm_wday = 1; break;
  case 0x2c657554: ttm->tm_wday = 2; break;
  case 0x2c646557: ttm->tm_wday = 3; break;
  case 0x2c756854: ttm->tm_wday = 4; break;
  case 0x2c697246: ttm->tm_wday = 5; break;
  case 0x2c746153: ttm->tm_wday = 6; break;
  default: return -2;
 }
 if (*(ptime++)!=' ') return -3;
 if (char2int(ptime,&ttm->tm_mday) || ttm->tm_mday > 31) return -4;
 ptime+=2;
 if (*(ptime++) != ' ') return -5;
 uval = (*(ptime + 0) + (*(ptime + 1) << 8) + (*(ptime + 2) << 16) + (*(ptime + 3) << 24));
 ptime+=4;
 switch (uval) {
  case 0x206e614a: ttm->tm_mon = 0; break;
  case 0x20626546: ttm->tm_mon = 1; break;
  case 0x2072614d: ttm->tm_mon = 2; break;
  case 0x20727041: ttm->tm_mon = 3; break;
  case 0x2079614d: ttm->tm_mon = 4; break;
  case 0x206e754a: ttm->tm_mon = 5; break;
  case 0x206c754a: ttm->tm_mon = 6; break;
  case 0x20677541: ttm->tm_mon = 7; break;
  case 0x20706553: ttm->tm_mon = 8; break;
  case 0x2074634f: ttm->tm_mon = 9; break;
  case 0x20766f4e: ttm->tm_mon = 10; break;
  case 0x20636544: ttm->tm_mon = 11; break;
  default: return -6;
 }
 if (char2int(ptime,&ires)) return -7;
 ptime+=2;
 if (char2int(ptime,&ttm->tm_year)) return -8;
 ptime+=2;
 ttm->tm_year+=(ires-19)*100;
 if (*(ptime++) != ' ') return -9;
 if (char2int(ptime,&ttm->tm_hour) || ttm->tm_hour > 23) return -10;
 ptime+=2;
 if (*(ptime++) != ':') return -11;
 if (char2int(ptime,&ttm->tm_min) || ttm->tm_min > 59) return -12;
 ptime+=2;
 if (*(ptime++) != ':') return -13;
 if (char2int(ptime,&ttm->tm_sec) || ttm->tm_sec > 59) return -14;
 ptime+=2;
 uval = (*(ptime + 0) + (*(ptime + 1) << 8) + (*(ptime + 2) << 16) + (*(ptime + 3) << 24));
 if ((uval | 0x20202020) != 0x746d6720) return -15;
 return 0;
}

canonical_original_code:
static int rfc1123totm(char *stime, struct tm *ttm) {
 char *ptime = stime;
 unsigned int uval;
 int ires;
 uval = (*(ptime + 0) + (*(ptime + 1) << 8) + (*(ptime + 2) << 16) + (*(ptime + 3) << 24));
 ptime+=4;
 switch (uval) {
  case 0x2c6e7553: ttm->tm_wday = 0; break;
  case 0x2c6e6f4d: ttm->tm_wday = 1; break;
  case 0x2c657554: ttm->tm_wday = 2; break;
  case 0x2c646557: ttm->tm_wday = 3; break;
  case 0x2c756854: ttm->tm_wday = 4; break;
  case 0x2c697246: ttm->tm_wday = 5; break;
  case 0x2c746153: ttm->tm_wday = 6; break;
  default: return -2;
 }
 if (*(ptime++)!=' ') return -3;
 if (char2int(ptime,&ttm->tm_mday) || ttm->tm_mday > 31) return -4;
 ptime+=2;
 if (*(ptime++) != ' ') return -5;
 uval = (*(ptime + 0) + (*(ptime + 1) << 8) + (*(ptime + 2) << 16) + (*(ptime + 3) << 24));
 ptime+=4;
 switch (uval) {
  case 0x206e614a: ttm->tm_mon = 0; break;
  case 0x20626546: ttm->tm_mon = 1; break;
  case 0x2072614d: ttm->tm_mon = 2; break;
  case 0x20727041: ttm->tm_mon = 3; break;
  case 0x2079614d: ttm->tm_mon = 4; break;
  case 0x206e754a: ttm->tm_mon = 5; break;
  case 0x206c754a: ttm->tm_mon = 6; break;
  case 0x20677541: ttm->tm_mon = 7; break;
  case 0x20706553: ttm->tm_mon = 8; break;
  case 0x2074634f: ttm->tm_mon = 9; break;
  case 0x20766f4e: ttm->tm_mon = 10; break;
  case 0x20636544: ttm->tm_mon = 11; break;
  default: return -6;
 }
 if (char2int(ptime,&ires)) return -7;
 ptime+=2;
 if (char2int(ptime,&ttm->tm_year)) return -8;
 ptime+=2;
 ttm->tm_year+=(ires-19)*100;
 if (*(ptime++) != ' ') return -9;
 if (char2int(ptime,&ttm->tm_hour) || ttm->tm_hour > 23) return -10;
 ptime+=2;
 if (*(ptime++) != ':') return -11;
 if (char2int(ptime,&ttm->tm_min) || ttm->tm_min > 59) return -12;
 ptime+=2;
 if (*(ptime++) != ':') return -13;
 if (char2int(ptime,&ttm->tm_sec) || ttm->tm_sec > 59) return -14;
 ptime+=2;
 uval = (*(ptime + 0) + (*(ptime + 1) << 8) + (*(ptime + 2) << 16) + (*(ptime + 3) << 24));
 if ((uval | 0x20202020) != 0x746d6720) return -15;
 return 0;
}

variable_types:
stime
char *

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

variable_types:
ptime
char *

variable_types:
uval
unsigned int

variable_types: ires int


decompiled_code:
void __fastcall parse_date(char *a1, __int64 a2, _DWORD *a3)
{
const char *v4; // rbx
unsigned int v5; // eax

*a3 = -1;
if ( a2 - (__int64)a1 <= 28 || (unsigned int)rfc1123totm(a1, a3 + 2) )
{
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR: parse_date: parse error\n",
process_no,
v5,
v4,
"<core> [parser/parse_date.c:157]: ",
"parse_date");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR: parse_date: parse error\n",
*((const char **)&log_level_info + 8),
"<core> [parser/parse_date.c:157]: ",
"parse_date");
}
--dprint_crit;
}
}
else
{
*a3 = 1;
}
}

canonical_decompiled_code:
void __fastcall func2(char *a1, __int64 a2, _DWORD *a3)
{
const char *v4; // rbx
unsigned int v5; // eax

*a3 = -1;
if ( a2 - (__int64)a1 <= 28 || (unsigned int)func1(a1, a3 + 2) )
{
if ( (int)get_debug_level("core", 4LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v4 = (const char *)*((_QWORD *)&log_level_info + 8);
v5 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): ERROR: parse_date: parse error\n",
process_no,
v5,
v4,
"<core> [parser/parse_date.c:157]: ",
"parse_date");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): ERROR: parse_date: parse error\n",
*((const char **)&log_level_info + 8),
"<core> [parser/parse_date.c:157]: ",
"parse_date");
}
--dprint_crit;
}
}
else
{
*a3 = 1;
}
}

original_code:
void parse_date(char *buffer, char *end, struct date_body *db)
{
 db->error=-1;
 if (end - buffer < 29)
  goto error;
 if (rfc1123totm(buffer,&db->date))
  goto error;
 db->error=1;
 return ;
error:
 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: parse_date: parse error\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_date.c" ":" "157" "]: ") , __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: parse_date: parse error\n", (log_level_info[((-1)) - (-5)].name), ("<core> [" "parser/parse_date.c" ":" "157" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "ERROR: parse_date: parse error\n", process_no, my_pid(), ("<core> [" "parser/parse_date.c" ":" "157" "]: ") , __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: parse_date: parse error\n", ("<core> [" "parser/parse_date.c" ":" "157" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "ERROR: parse_date: parse error\n", ("<core> [" "parser/parse_date.c" ":" "157" "]: ") , __func__); } } (dprint_crit--); } } while(0);
 return ;
}

variable_types:
buffer
char *

variable_types:
end
char *

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

user_defined_types: struct date_body { int error; struct tm date; }


decompiled_code:
__int64 __fastcall free_date(__int64 a1)
{
return qm_free(mem_block, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return qm_free(mem_block, a1);
}

original_code:
void free_date(struct date_body *db)
{
 qm_free(mem_block, (db));
}

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


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


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

result = atomic_cmpxchg_int(a1, 0, 1);
if ( (_DWORD)result )
{
v2 = 1024;
if ( (_DWORD)result == 2 )
{
do
{
LABEL_3:
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(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v3 = v2 - 1;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = atomic_cmpxchg_int(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v2 = v3 - 7;
if ( !v2 )
{
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 func2(volatile signed __int32 *a1)
{
__int64 result; // rax
int v2; // ebp
int v3; // ebp

result = func1(a1, 0, 1);
if ( (_DWORD)result )
{
v2 = 1024;
if ( (_DWORD)result == 2 )
{
do
{
LABEL_3:
syscall(202LL, a1, 0LL, 2LL, 0LL, 0LL, 0LL);
result = func0(a1, 2);
}
while ( (_DWORD)result );
}
else
{
while ( 1 )
{
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v3 = v2 - 1;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
result = func1(a1, 0, 1);
if ( !(_DWORD)result )
break;
if ( (_DWORD)result == 2 )
goto LABEL_3;
v2 = v3 - 7;
if ( !v2 )
{
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:
lock
struct atomic_t { int val; } *

variable_types: i int


decompiled_code:
__int64 __fastcall futex_release(volatile __int32 *a1)
{
__int64 result; // rax

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

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

result = func0(a1, 0);
if ( (_DWORD)result == 2 )
result = syscall(202LL, a1, 1LL, 1LL, 0LL, 0LL, 0LL);
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));
 }
}


decompiled_code:
__int64 __fastcall destroy_failure_route_rule_list(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

for ( i = a1; i; result = destroy_failure_route_rule(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 80);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

for ( i = a1; i; result = destroy_failure_route_rule(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 80);
}
return result;
}

original_code:
static void destroy_failure_route_rule_list(void *data) {
 struct failure_route_rule *rs, *rs_tmp;
 rs = (struct failure_route_rule *)(data);
 while (rs != ((void *)0)) {
  rs_tmp = rs->next;
  destroy_failure_route_rule(rs);
  rs = rs_tmp;
 }
}

canonical_original_code:
static void destroy_failure_route_rule_list(void *data) {
 struct failure_route_rule *rs; struct failure_route_rule *rs_tmp;
 rs = (struct failure_route_rule *)(data);
 while (rs != ((void *)0)) {
  rs_tmp = rs->next;
  destroy_failure_route_rule(rs);
  rs = rs_tmp;
 }
}

variable_types:
data
void *

variable_types: struct failure_route_rule { struct _str { char *s; int len; } host; struct _str comment; struct _str prefix; struct _str reply_code; int next_domain; unsigned int flags; unsigned int mask; struct failure_route_rule *next; } *

user_defined_types: struct failure_route_rule { struct _str host; struct _str comment; struct _str prefix; struct _str reply_code; int next_domain; unsigned int flags; unsigned int mask; struct failure_route_rule *next; }


decompiled_code:
__int64 __fastcall destroy_route_flags_list(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

for ( i = a1; i; result = destroy_route_flags(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 40);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rdi
__int64 result; // rax

for ( i = a1; i; result = destroy_route_flags(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 40);
}
return result;
}

original_code:
static void destroy_route_flags_list(void *data) {
 struct route_flags *rf, *rf_tmp;
 rf=(struct route_flags *)(data);
 while (rf!=((void *)0)) {
  rf_tmp = rf->next;
  destroy_route_flags(rf);
  rf = rf_tmp;
 }
}

canonical_original_code:
static void destroy_route_flags_list(void *data) {
 struct route_flags *rf; struct route_flags *rf_tmp;
 rf=(struct route_flags *)(data);
 while (rf!=((void *)0)) {
  rf_tmp = rf->next;
  destroy_route_flags(rf);
  rf = rf_tmp;
 }
}

variable_types: struct route_flags { unsigned int flags; unsigned int mask; struct route_rule { int dice_to; double prob; double orig_prob; struct _str { char *s; int len; } host; int strip; struct _str local_prefix; struct _str local_suffix; struct _str comment; struct _str prefix; int status; struct route_rule_p_list { struct route_rule *rr; int hash_index; struct route_rule_p_list *next; } *backed_up; struct route_rule_p_list *backup; int hash_index; struct route_rule *next; } *rule_list; struct route_rule **rules; int rule_num; int dice_max; int max_targets; struct route_flags *next; } *

user_defined_types: struct route_flags { unsigned int flags; unsigned int mask; struct route_rule *rule_list; struct route_rule **rules; int rule_num; int dice_max; int max_targets; struct route_flags *next; }

user_defined_types: struct route_rule { int dice_to; double prob; double orig_prob; struct _str host; int strip; struct _str local_prefix; struct _str local_suffix; struct _str comment; struct _str prefix; int status; struct route_rule_p_list *backed_up; struct route_rule_p_list *backup; int hash_index; struct route_rule *next; }


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

if ( a1 )
{
dtrie_destroy(a1 + 16, destroy_route_flags_list, cr_match_mode);
dtrie_destroy(a1 + 24, destroy_failure_route_rule_list, cr_match_mode);
futex_get(mem_lock);
qm_free(shm_block, a1);
result = futex_release(mem_lock);
}
return result;
}

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

if ( a1 )
{
dtrie_destroy(a1 + 16, destroy_route_flags_list, cr_match_mode);
dtrie_destroy(a1 + 24, destroy_failure_route_rule_list, cr_match_mode);
func2(mem_lock);
qm_free(shm_block, a1);
result = func3(mem_lock);
}
return result;
}

original_code:
void destroy_domain_data(struct domain_data_t *domain_data) {
 if (domain_data) {
  dtrie_destroy(&domain_data->tree, destroy_route_flags_list, cr_match_mode);
  dtrie_destroy(&domain_data->failure_tree, destroy_failure_route_rule_list,
    cr_match_mode);
  do { futex_get(mem_lock); qm_free(shm_block, (domain_data)); futex_release(mem_lock); }while(0);
 }
}

variable_types: struct domain_data_t { int id; struct _str { char *s; int len; } *name; struct dtrie_node_t { struct dtrie_node_t **child; void *data; } *tree; struct dtrie_node_t *failure_tree; } *

user_defined_types: struct domain_data_t { int id; struct _str *name; struct dtrie_node_t *tree; struct dtrie_node_t *failure_tree; }


decompiled_code:
__int64 __fastcall add_route_to_tree(__int64 a1, _QWORD *a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6, double a7, __int64 a8, unsigned int a9, __int64 a10, __int64 a11, unsigned int a12, unsigned int a13, unsigned int a14, __int64 a15, __int64 a16)
{
__int64 v19; // rbp
__int64 v20; // rax
__int64 v21; // r13
__int64 result; // rax
int v23; // er10
const char *v24; // rbx
unsigned int v25; // eax
int v26; // er8
const char *v27; // r12
unsigned int v28; // eax

v19 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v20 = add_route_flags(v19, a3, a4);
if ( v20 )
{
v21 = v20;
if ( v19 || !(unsigned int)dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v20, cr_match_mode) )
{
result = add_route_rule(v21, a5, a6, a8, a9, a10, a7, a11, a12, a13, a14, a15, a16);
}
else
{
v26 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v26 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v27 = (const char *)*((_QWORD *)&log_level_info + 8);
v28 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert route flags into d-trie\n",
process_no,
v28,
v27,
"carrierroute [cr_domain.c:168]: ",
"add_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:168]: ",
"add_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
v23 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v23 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v24 = (const char *)*((_QWORD *)&log_level_info + 8);
v25 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert route flags into list\n",
process_no,
v25,
v24,
"carrierroute [cr_domain.c:161]: ",
"add_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:161]: ",
"add_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _QWORD *a2, unsigned int a3, unsigned int a4, __int64 a5, unsigned int a6, double a7, __int64 a8, unsigned int a9, __int64 a10, __int64 a11, unsigned int a12, unsigned int a13, unsigned int a14, __int64 a15, __int64 a16)
{
__int64 v19; // rbp
__int64 v20; // rax
__int64 v21; // r13
__int64 result; // rax
int v23; // er10
const char *v24; // rbx
unsigned int v25; // eax
int v26; // er8
const char *v27; // r12
unsigned int v28; // eax

v19 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v20 = add_route_flags(v19, a3, a4);
if ( v20 )
{
v21 = v20;
if ( v19 || !(unsigned int)dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v20, cr_match_mode) )
{
result = add_route_rule(v21, a5, a6, a8, a9, a10, a7, a11, a12, a13, a14, a15, a16);
}
else
{
v26 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v26 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v27 = (const char *)*((_QWORD *)&log_level_info + 8);
v28 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert route flags into d-trie\n",
process_no,
v28,
v27,
"carrierroute [cr_domain.c:168]: ",
"add_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:168]: ",
"add_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
}
else
{
v23 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v23 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v24 = (const char *)*((_QWORD *)&log_level_info + 8);
v25 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert route flags into list\n",
process_no,
v25,
v24,
"carrierroute [cr_domain.c:161]: ",
"add_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert route flags into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:161]: ",
"add_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int add_route_to_tree(struct dtrie_node_t *node, const str * scan_prefix,
  flag_t flags, flag_t mask, const str * full_prefix, int max_targets, double prob,
  const str * rewrite_hostpart, int strip, const str * rewrite_local_prefix,
  const str * rewrite_local_suffix, int status, int hash_index,
  int backup, int * backed_up, const str * comment) {
 void **ret;
 struct route_flags *rf;
 ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 rf = add_route_flags((struct route_flags **)ret, flags, mask);
 if (rf == ((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(): " "cannot insert route flags into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __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(): " "cannot insert route flags into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __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(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (ret == ((void *)0)) {
  if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf, cr_match_mode) != 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(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __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(): " "cannot insert route flags into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __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(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return add_route_rule(rf, full_prefix, max_targets, prob, rewrite_hostpart, strip,
            rewrite_local_prefix, rewrite_local_suffix, status, hash_index,
            backup, backed_up, comment);
}

canonical_original_code:
int add_route_to_tree(struct dtrie_node_t *node, struct _str *scan_prefix, unsigned int flags, unsigned int mask, struct _str *full_prefix, int max_targets, double prob, struct _str *rewrite_hostpart, int strip, struct _str *rewrite_local_prefix, struct _str *rewrite_local_suffix, int status, int hash_index, int backup, int *backed_up, struct _str *comment) {
 void **ret;
 struct route_flags *rf;
 ret = dtrie_contains(node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 rf = add_route_flags((struct route_flags **)ret, flags, mask);
 if (rf == ((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(): " "cannot insert route flags into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __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(): " "cannot insert route flags into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __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(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into list\n", ("carrierroute" " [" "cr_domain.c" ":" "161" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
 }
 if (ret == ((void *)0)) {
  if (dtrie_insert(node, scan_prefix->s, scan_prefix->len, rf, cr_match_mode) != 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(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __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(): " "cannot insert route flags into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert route flags into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __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(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert route flags into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "168" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return add_route_rule(rf, full_prefix, max_targets, prob, rewrite_hostpart, strip,
            rewrite_local_prefix, rewrite_local_suffix, status, hash_index,
            backup, backed_up, comment);
}

variable_types: struct dtrie_node_t { struct dtrie_node_t **child; void *data; } *

variable_types:
flags
unsigned int

variable_types:
mask
unsigned int

variable_types: prob double

variable_types: strip int

variable_types: status int

variable_types: backup int

variable_types:
comment
struct _str *

variable_types:
ret
void **

user_defined_types: struct route_rule_p_list { struct route_rule *rr; int hash_index; struct route_rule_p_list *next; }


decompiled_code:
__int64 __fastcall add_failure_route_to_tree(__int64 a1, _QWORD *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6, unsigned int a7, unsigned int a8, __int64 a9)
{
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // rcx
__int64 result; // rax
int v16; // er9
const char *v17; // r12
unsigned int v18; // eax
int v19; // ecx
const char *v20; // rbp
unsigned int v21; // eax

v12 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v13 = add_failure_route_rule(v12, a3, a4, a5, a6, a7, a8, a9);
if ( v13 )
{
v14 = v13;
result = 0LL;
if ( !v12 )
{
result = dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v14, cr_match_mode);
if ( (_DWORD)result )
{
v19 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v19 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v20 = (const char *)*((_QWORD *)&log_level_info + 8);
v21 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert failure route rule into d-trie\n",
process_no,
v21,
v20,
"carrierroute [cr_domain.c:217]: ",
"add_failure_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:217]: ",
"add_failure_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
}
}
else
{
v16 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v16 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = (const char *)*((_QWORD *)&log_level_info + 8);
v18 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert failure route rule into list\n",
process_no,
v18,
v17,
"carrierroute [cr_domain.c:210]: ",
"add_failure_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:210]: ",
"add_failure_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, _QWORD *a2, __int64 a3, __int64 a4, __int64 a5, unsigned int a6, unsigned int a7, unsigned int a8, __int64 a9)
{
__int64 v12; // rbp
__int64 v13; // rax
__int64 v14; // rcx
__int64 result; // rax
int v16; // er9
const char *v17; // r12
unsigned int v18; // eax
int v19; // ecx
const char *v20; // rbp
unsigned int v21; // eax

v12 = dtrie_contains(a1, *a2, *((unsigned int *)a2 + 2), cr_match_mode);
v13 = add_failure_route_rule(v12, a3, a4, a5, a6, a7, a8, a9);
if ( v13 )
{
v14 = v13;
result = 0LL;
if ( !v12 )
{
result = dtrie_insert(a1, *a2, *((unsigned int *)a2 + 2), v14, cr_match_mode);
if ( (_DWORD)result )
{
v19 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v19 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v20 = (const char *)*((_QWORD *)&log_level_info + 8);
v21 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert failure route rule into d-trie\n",
process_no,
v21,
v20,
"carrierroute [cr_domain.c:217]: ",
"add_failure_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into d-trie\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:217]: ",
"add_failure_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
}
}
else
{
v16 = get_debug_level("carrierroute", 12LL);
result = 0xFFFFFFFFLL;
if ( v16 >= -1 )
{
result = 0xFFFFFFFFLL;
if ( !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v17 = (const char *)*((_QWORD *)&log_level_info + 8);
v18 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): cannot insert failure route rule into list\n",
process_no,
v18,
v17,
"carrierroute [cr_domain.c:210]: ",
"add_failure_route_to_tree");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): cannot insert failure route rule into list\n",
*((const char **)&log_level_info + 8),
"carrierroute [cr_domain.c:210]: ",
"add_failure_route_to_tree");
}
--dprint_crit;
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
int add_failure_route_to_tree(struct dtrie_node_t * failure_node, const str * scan_prefix,
  const str * full_prefix, const str * host, const str * reply_code,
  const flag_t flags, const flag_t mask, const int next_domain, const str * comment) {
 void **ret;
 struct failure_route_rule *frr;
 ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 frr = add_failure_route_rule((struct failure_route_rule **)ret, full_prefix, host, reply_code, flags, mask, next_domain, comment);
 if (frr == ((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(): " "cannot insert failure route rule into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __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(): " "cannot insert failure route rule into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __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(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
  }
 if (ret == ((void *)0)) {
  if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr, cr_match_mode) != 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(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __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(): " "cannot insert failure route rule into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __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(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int add_failure_route_to_tree(struct dtrie_node_t *failure_node, struct _str *scan_prefix, struct _str *full_prefix, struct _str *host, struct _str *reply_code, unsigned int flags, unsigned int mask, int next_domain, struct _str *comment) {
 void **ret;
 struct failure_route_rule *frr;
 ret = dtrie_contains(failure_node, scan_prefix->s, scan_prefix->len, cr_match_mode);
 frr = add_failure_route_rule((struct failure_route_rule **)ret, full_prefix, host, reply_code, flags, mask, next_domain, comment);
 if (frr == ((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(): " "cannot insert failure route rule into list\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __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(): " "cannot insert failure route rule into list\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into list\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __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(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into list\n", ("carrierroute" " [" "cr_domain.c" ":" "210" "]: ") , __func__); } } (dprint_crit--); } } while(0);
  return -1;
  }
 if (ret == ((void *)0)) {
  if (dtrie_insert(failure_node, scan_prefix->s, scan_prefix->len, frr, cr_match_mode) != 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(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __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(): " "cannot insert failure route rule into d-trie\n", (log_level_info[((-1)) - (-5)].name), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "cannot insert failure route rule into d-trie\n", process_no, my_pid(), ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __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(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "cannot insert failure route rule into d-trie\n", ("carrierroute" " [" "cr_domain.c" ":" "217" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   return -1;
  }
 }
 return 0;
}

variable_types:
host
struct _str *

user_defined_types: struct dtrie_node_t { struct dtrie_node_t **child; void *data; }


decompiled_code:
__int64 __fastcall compare_domain_data(int **a1, int **a2)
{
int *v2; // rax
int v3; // ecx
int v4; // esi
__int64 result; // rax

v2 = *a2;
if ( !*a1 )
return v2 != 0LL;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = **a1;
v4 = *v2;
result = 0xFFFFFFFFLL;
if ( v3 >= v4 )
result = v3 > v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int **a1, int **a2)
{
int *v2; // rax
int v3; // ecx
int v4; // esi
__int64 result; // rax

v2 = *a2;
if ( !*a1 )
return v2 != 0LL;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = **a1;
v4 = *v2;
result = 0xFFFFFFFFLL;
if ( v3 >= v4 )
result = v3 > v4;
return result;
}

original_code:
int compare_domain_data(const void *v1, const void *v2) {
  struct domain_data_t *d1 = *(struct domain_data_t * const *)v1;
 struct domain_data_t *d2 = *(struct domain_data_t * const *)v2;
 if (d1 == ((void *)0)) {
  if (d2 == ((void *)0)) return 0;
  else return 1;
 }
 else {
  if (d2 == ((void *)0)) return -1;
  else {
   if (d1->id < d2->id) return -1;
   else if (d1->id > d2->id) return 1;
   else return 0;
  }
 }
}

canonical_original_code:
int compare_domain_data(void *v1, void *v2) {
  struct domain_data_t *d1 = *(struct domain_data_t * const *)v1;
 struct domain_data_t *d2 = *(struct domain_data_t * const *)v2;
 if (d1 == ((void *)0)) {
  if (d2 == ((void *)0)) return 0;
  else return 1;
 }
 else {
  if (d2 == ((void *)0)) return -1;
  else {
   if (d1->id < d2->id) return -1;
   else if (d1->id > d2->id) return 1;
   else return 0;
  }
 }
}


decompiled_code:
__int64 __fastcall ipopsapi_is_ip(__int64 a1)
{
return 2 * (unsigned int)((unsigned int)ip_parser_execute(*(_QWORD *)a1, *(int *)(a1 + 8)) != 4) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return 2 * (unsigned int)((unsigned int)ip_parser_execute(*(_QWORD *)a1, *(int *)(a1 + 8)) != 4) - 1;
}

original_code:
int ipopsapi_is_ip(const str * const ip)
{
  if (ip_parser_execute(ip->s, ip->len) != ip_type_error)
    return 1;
  else
    return -1;
}

canonical_original_code:
int ipopsapi_is_ip(struct _str *ip)
{
  if (ip_parser_execute(ip->s, ip->len) != ip_type_error)
    return 1;
  else
    return -1;
}

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


decompiled_code:
__int64 __fastcall ipopsapi_compare_ips(__int64 *a1, __int64 *a2)
{
__int64 v2; // r12
int v3; // ebp
__int64 v4; // r13
int v5; // er14
unsigned int v6; // eax
unsigned int v7; // ebx
__int64 result; // rax
int v9; // er9

v2 = *a1;
v3 = *((_DWORD *)a1 + 2);
v4 = *a2;
v5 = *((_DWORD *)a2 + 2);
v6 = ip_parser_execute(*a1, v3);
if ( v6 == 3 )
{
++v2;
v3 -= 2;
v7 = 2;
}
else
{
v7 = v6;
result = 0xFFFFFFFFLL;
if ( v7 == 4 )
return result;
}
v9 = ip_parser_execute(v4, v5);
if ( v9 == 3 )
{
++v4;
v5 -= 2;
}
else
{
result = 0xFFFFFFFFLL;
if ( v9 == 4 )
return result;
}
return (unsigned int)compare_ips(v2, v3, v7, v4, v5) == 0 ? -1 : 1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 *a2)
{
__int64 v2; // r12
int v3; // ebp
__int64 v4; // r13
int v5; // er14
unsigned int v6; // eax
unsigned int v7; // ebx
__int64 result; // rax
int v9; // er9

v2 = *a1;
v3 = *((_DWORD *)a1 + 2);
v4 = *a2;
v5 = *((_DWORD *)a2 + 2);
v6 = ip_parser_execute(*a1, v3);
if ( v6 == 3 )
{
++v2;
v3 -= 2;
v7 = 2;
}
else
{
v7 = v6;
result = 0xFFFFFFFFLL;
if ( v7 == 4 )
return result;
}
v9 = ip_parser_execute(v4, v5);
if ( v9 == 3 )
{
++v4;
v5 -= 2;
}
else
{
result = 0xFFFFFFFFLL;
if ( v9 == 4 )
return result;
}
return (unsigned int)compare_ips(v2, v3, v7, v4, v5) == 0 ? -1 : 1;
}

original_code:
int ipopsapi_compare_ips(const str *const ip1, const str *const ip2)
{
  str string1 = *ip1;
  str string2 = *ip2;
  enum enum_ip_type ip1_type, ip2_type;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string1.s += 1;
      string1.len -= 2;
      ip1_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string2.s += 1;
      string2.len -= 2;
      ip2_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  if (_compare_ips(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type))
    return 1;
  else
    return -1;
}

canonical_original_code:
int ipopsapi_compare_ips(struct _str *ip1, struct _str *ip2)
{
  struct _str string1 = *ip1;
  struct _str string2 = *ip2;
  enum enum_ip_type ip1_type; enum enum_ip_type ip2_type;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string1.s += 1;
      string1.len -= 2;
      ip1_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      string2.s += 1;
      string2.len -= 2;
      ip2_type = ip_type_ipv6;
      break;
    default:
      break;
  }
  if (_compare_ips(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type))
    return 1;
  else
    return -1;
}

variable_types: enum enum_ip_type { ip_type_ipv4=1, ip_type_ipv6=2, ip_type_ipv6_reference=3, ip_type_error=4 }


decompiled_code:
__int64 __fastcall ipopsapi_ip_is_in_subnet(__int64 *a1, __int64 a2)
{
__int64 v2; // r12
_BYTE *v3; // rbp
int v4; // ebx
__int64 v5; // r14
unsigned int v6; // er13
__int64 result; // rax
unsigned __int64 v8; // rbx
__int64 v9; // rcx
_BYTE *v10; // rsi
__int64 v11; // r15
int v12; // ebx
unsigned int v13; // eax
__int64 v14; // r9
unsigned int v15; // edi

v2 = *a1;
v3 = *(_BYTE **)a2;
v4 = *(_DWORD *)(a2 + 8);
v5 = *((int *)a1 + 2);
v6 = ip_parser_execute(*a1, v5);
result = 0xFFFFFFFFLL;
if ( v6 - 3 <= 1 )
return result;
v8 = (unsigned __int64)&v3[v4 - 1];
if ( v8 <= (unsigned __int64)v3 )
goto LABEL_35;
v9 = ((_BYTE)v8 - (_BYTE)v3) & 7;
if ( (((_BYTE)v8 - (_BYTE)v3) & 7) == 0 )
{
LABEL_24:
while ( *(_BYTE *)v8 != 47 )
{
v10 = (_BYTE *)(v8 - 1);
v8 = (unsigned __int64)v10;
if ( *v10 == 47 )
break;
v8 = (unsigned __int64)(v10 - 1);
if ( *(v10 - 1) == 47 )
break;
v8 = (unsigned __int64)(v10 - 2);
if ( *(v10 - 2) == 47 )
break;
v8 = (unsigned __int64)(v10 - 3);
if ( *(v10 - 3) == 47 )
break;
v8 = (unsigned __int64)(v10 - 4);
if ( *(v10 - 4) == 47 )
break;
v8 = (unsigned __int64)(v10 - 5);
if ( *(v10 - 5) == 47 )
break;
v8 = (unsigned __int64)(v10 - 6);
if ( *(v10 - 6) == 47 )
break;
v8 = (unsigned __int64)(v10 - 7);
if ( v10 - 7 == v3 )
return 0xFFFFFFFFLL;
}
goto LABEL_35;
}
if ( v9 == 1 )
goto LABEL_22;
if ( v9 != 2 )
{
switch ( v9 )
{
case 3LL:
LABEL_18:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
goto LABEL_20;
case 4LL:
LABEL_16:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
goto LABEL_18;
case 5LL:
LABEL_14:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
goto LABEL_16;
}
if ( v9 != 6 )
{
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
}
if ( *(_BYTE *)v8 != 47 )
{
--v8;
goto LABEL_14;
}
LABEL_35:
if ( v3 == (_BYTE *)v8 )
return 0xFFFFFFFFLL;
v11 = (unsigned int)atoi((const char *)(v8 + 1));
v12 = v8 - (_DWORD)v3;
v13 = ip_parser_execute(v3, v12);
v14 = v13;
v15 = v13 - 3;
result = 0xFFFFFFFFLL;
if ( v15 > 1 )
result = (unsigned int)ip_is_in_subnet(v2, v5, v6, v3, v12, v14, v11) == 0 ? -1 : 1;
return result;
}
LABEL_20:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
LABEL_22:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
if ( (_BYTE *)--v8 != v3 )
goto LABEL_24;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2)
{
__int64 v2; // r12
_BYTE *v3; // rbp
int v4; // ebx
__int64 v5; // r14
unsigned int v6; // er13
__int64 result; // rax
unsigned __int64 v8; // rbx
__int64 v9; // rcx
_BYTE *v10; // rsi
__int64 v11; // r15
int v12; // ebx
unsigned int v13; // eax
__int64 v14; // r9
unsigned int v15; // edi

v2 = *a1;
v3 = *(_BYTE **)a2;
v4 = *(_DWORD *)(a2 + 8);
v5 = *((int *)a1 + 2);
v6 = ip_parser_execute(*a1, v5);
result = 0xFFFFFFFFLL;
if ( v6 - 3 <= 1 )
return result;
v8 = (unsigned __int64)&v3[v4 - 1];
if ( v8 <= (unsigned __int64)v3 )
goto LABEL_35;
v9 = ((_BYTE)v8 - (_BYTE)v3) & 7;
if ( (((_BYTE)v8 - (_BYTE)v3) & 7) == 0 )
{
LABEL_24:
while ( *(_BYTE *)v8 != 47 )
{
v10 = (_BYTE *)(v8 - 1);
v8 = (unsigned __int64)v10;
if ( *v10 == 47 )
break;
v8 = (unsigned __int64)(v10 - 1);
if ( *(v10 - 1) == 47 )
break;
v8 = (unsigned __int64)(v10 - 2);
if ( *(v10 - 2) == 47 )
break;
v8 = (unsigned __int64)(v10 - 3);
if ( *(v10 - 3) == 47 )
break;
v8 = (unsigned __int64)(v10 - 4);
if ( *(v10 - 4) == 47 )
break;
v8 = (unsigned __int64)(v10 - 5);
if ( *(v10 - 5) == 47 )
break;
v8 = (unsigned __int64)(v10 - 6);
if ( *(v10 - 6) == 47 )
break;
v8 = (unsigned __int64)(v10 - 7);
if ( v10 - 7 == v3 )
return 0xFFFFFFFFLL;
}
goto LABEL_35;
}
if ( v9 == 1 )
goto LABEL_22;
if ( v9 != 2 )
{
switch ( v9 )
{
case 3LL:
LABEL_18:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
goto LABEL_20;
case 4LL:
LABEL_16:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
goto LABEL_18;
case 5LL:
LABEL_14:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
goto LABEL_16;
}
if ( v9 != 6 )
{
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
}
if ( *(_BYTE *)v8 != 47 )
{
--v8;
goto LABEL_14;
}
LABEL_35:
if ( v3 == (_BYTE *)v8 )
return 0xFFFFFFFFLL;
v11 = (unsigned int)atoi((const char *)(v8 + 1));
v12 = v8 - (_DWORD)v3;
v13 = ip_parser_execute(v3, v12);
v14 = v13;
v15 = v13 - 3;
result = 0xFFFFFFFFLL;
if ( v15 > 1 )
result = (unsigned int)ip_is_in_subnet(v2, v5, v6, v3, v12, v14, v11) == 0 ? -1 : 1;
return result;
}
LABEL_20:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
--v8;
LABEL_22:
if ( *(_BYTE *)v8 == 47 )
goto LABEL_35;
if ( (_BYTE *)--v8 != v3 )
goto LABEL_24;
return 0xFFFFFFFFLL;
}

original_code:
int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2)
{
  str string1 = *ip1;
  str string2 = *ip2;
  enum enum_ip_type ip1_type, ip2_type;
  char *cidr_pos = ((void *)0);
  int netmask = 0;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  cidr_pos = string2.s + string2.len - 1;
  while (cidr_pos > string2.s)
  {
    if (*cidr_pos == '/') break;
    cidr_pos--;
  }
  if (cidr_pos == string2.s) return -1;
  string2.len = (cidr_pos - string2.s);
  netmask = atoi(cidr_pos+1);
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  if (_ip_is_in_subnet(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type, netmask))
    return 1;
  else
    return -1;
}

canonical_original_code:
int ipopsapi_ip_is_in_subnet(struct _str *ip1, struct _str *ip2)
{
  struct _str string1 = *ip1;
  struct _str string2 = *ip2;
  enum enum_ip_type ip1_type; enum enum_ip_type ip2_type;
  char *cidr_pos = ((void *)0);
  int netmask = 0;
  switch(ip1_type = ip_parser_execute(string1.s, string1.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  cidr_pos = string2.s + string2.len - 1;
  while (cidr_pos > string2.s)
  {
    if (*cidr_pos == '/') break;
    cidr_pos--;
  }
  if (cidr_pos == string2.s) return -1;
  string2.len = (cidr_pos - string2.s);
  netmask = atoi(cidr_pos+1);
  switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
    case(ip_type_error):
      return -1;
      break;
    case(ip_type_ipv6_reference):
      return -1;
      break;
    default:
      break;
  }
  if (_ip_is_in_subnet(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type, netmask))
    return 1;
  else
    return -1;
}

variable_types: netmask int

user_defined_types: enum enum_ip_type { ip_type_ipv4=1, ip_type_ipv6=2, ip_type_ipv6_reference=3, ip_type_error=4 }