decompiled_code:
unsigned __int64 __fastcall db_trans_expand(__int64 a1, int a2)
{
int v2; // er12
const void *v3; // r13
char *v4; // rbp
unsigned __int64 v6; // [rsp+8h] [rbp-30h]

v6 = __readfsqword(0x28u);
v2 = *(_DWORD *)(a1 + 56) + a2;
v3 = *(const void **)(a1 + 24);
v4 = (char *)alloc_bytes_st(24LL * v2, (__int64)"db_context->trans (expand)", (__int64)&db_trans_st);
memcpy(v4, v3, 24LL * *(int *)(a1 + 56));
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 24) = v4;
*(_QWORD *)(a1 + 32) = &v4[*(_QWORD *)(a1 + 32) - (_QWORD)v3];
*(_DWORD *)(a1 + 56) = v2;
--db_trans_st;
pfree(v3);
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, int a2)
{
int v2; // er12
const void *v3; // r13
char *v4; // rbp
unsigned __int64 v6; // [rsp+8h] [rbp-30h]

v6 = __readfsqword(0x28u);
v2 = *(_DWORD *)(a1 + 56) + a2;
v3 = *(const void **)(a1 + 24);
v4 = (char *)func0(24LL * v2, (__int64)"db_context->trans (expand)", (__int64)&db_trans_st);
memcpy(v4, v3, 24LL * *(int *)(a1 + 56));
*(_QWORD *)(a1 + 8) = v4;
*(_QWORD *)(a1 + 24) = v4;
*(_QWORD *)(a1 + 32) = &v4[*(_QWORD *)(a1 + 32) - (_QWORD)v3];
*(_DWORD *)(a1 + 56) = v2;
--db_trans_st;
pfree(v3);
return v6 - __readfsqword(0x28u);
}

original_code:
static void db_trans_expand(struct db_context *ctx, int delta_trans)
{
 int max_trans = ctx->max_trans + delta_trans;
 struct db_trans *const old_trans = ctx->trans0;
 struct db_trans *const new_trans = alloc_bytes_st(sizeof(struct db_trans) * max_trans, "db_context->trans (expand)", &(db_trans_st));;
 memcpy(new_trans, old_trans, ctx->max_trans * sizeof(struct db_trans));
 ctx->trans0 = ctx->prop.trans = new_trans;
 ctx->trans_cur = ctx->trans_cur - old_trans + new_trans;
 ctx->max_trans = max_trans;
 if (old_trans != ((void *)0))
  { db_trans_st.st_curr_cnt--; pfree(old_trans); };
}

canonical_original_code:
static void db_trans_expand(struct db_context *ctx, int delta_trans)
{
 int max_trans = ctx->max_trans + delta_trans;
 struct db_trans *old_trans = ctx->trans0;
 struct db_trans *new_trans = alloc_bytes_st(sizeof(struct db_trans) * max_trans, "db_context->trans (expand)", &(db_trans_st));;
 memcpy(new_trans, old_trans, ctx->max_trans * sizeof(struct db_trans));
 ctx->trans0 = ctx->prop.trans = new_trans;
 ctx->trans_cur = ctx->trans_cur - old_trans + new_trans;
 ctx->max_trans = max_trans;
 if (old_trans != ((void *)0))
  { db_trans_st.st_curr_cnt--; pfree(old_trans); };
}

variable_types: struct db_trans { unsigned short transid; struct db_attr { union { enum ikev1_oakley_attr { OAKLEY_ATTR_undefined=0, OAKLEY_ENCRYPTION_ALGORITHM=1, OAKLEY_HASH_ALGORITHM=2, OAKLEY_AUTHENTICATION_METHOD=3, OAKLEY_GROUP_DESCRIPTION=4, OAKLEY_GROUP_TYPE=5, OAKLEY_GROUP_PRIME=6, OAKLEY_GROUP_GENERATOR_ONE=7, OAKLEY_GROUP_GENERATOR_TWO=8, OAKLEY_GROUP_CURVE_A=9, OAKLEY_GROUP_CURVE_B=10, OAKLEY_LIFE_TYPE=11, OAKLEY_LIFE_DURATION=12, OAKLEY_PRF=13, OAKLEY_KEY_LENGTH=14, OAKLEY_FIELD_SIZE=15, OAKLEY_GROUP_ORDER=16 } oakley; enum ikev1_ipsec_attr { SA_LIFE_TYPE=1, SA_LIFE_DURATION=2, GROUP_DESCRIPTION=3, ENCAPSULATION_MODE=4, AUTH_ALGORITHM=5, KEY_LENGTH=6, KEY_ROUNDS=7, COMPRESS_DICT_SIZE=8, COMPRESS_PRIVATE_ALG=9, ECN_TUNNEL=10, ECN_TUNNEL_or_old_SECCTX=expr, ESN_64BIT_SEQNUM=11, IKEv1_IPSEC_ATTR_UNSPEC_12=12, SIG_ENC_ALGO_VAL=13, ADDRESS_PRESERVATION=14, SA_DIRECTION=15, IPSEC_ATTR_VAL_DESCS_ROOF=16, SECCTX=32001 } ipsec; } type; unsigned short val; } *attrs; unsigned int attr_cnt; } *


repo: libreswan/libreswan

original_code:
static void db_attrs_expand(struct db_context *ctx, int delta_attrs)
{
 unsigned int ti;
 int max_attrs = ctx->max_attrs + delta_attrs;
 struct db_attr *const old_attrs = ctx->attrs0;
 struct db_attr *const new_attrs = alloc_bytes_st(sizeof(struct db_attr) * max_attrs, "db_context->attrs (expand)", &(db_attrs_st));;
 memcpy(new_attrs, old_attrs, ctx->max_attrs * sizeof(struct db_attr));
 ctx->attrs0 = ctx->attrs0 - old_attrs + new_attrs;
 ctx->attrs_cur = ctx->attrs_cur - old_attrs + new_attrs;
 for (ti = 0; ti < ctx->prop.trans_cnt; ti++)
  ctx->prop.trans[ti].attrs = ctx->prop.trans[ti].attrs - old_attrs + new_attrs;
 ctx->max_attrs = max_attrs;
 if (old_attrs != ((void *)0))
  { db_attrs_st.st_curr_cnt--; pfree(old_attrs); };
}

canonical_original_code:
static void db_attrs_expand(struct db_context *ctx, int delta_attrs)
{
 unsigned int ti;
 int max_attrs = ctx->max_attrs + delta_attrs;
 struct db_attr *old_attrs = ctx->attrs0;
 struct db_attr *new_attrs = alloc_bytes_st(sizeof(struct db_attr) * max_attrs, "db_context->attrs (expand)", &(db_attrs_st));;
 memcpy(new_attrs, old_attrs, ctx->max_attrs * sizeof(struct db_attr));
 ctx->attrs0 = ctx->attrs0 - old_attrs + new_attrs;
 ctx->attrs_cur = ctx->attrs_cur - old_attrs + new_attrs;
 for (ti = 0; ti < ctx->prop.trans_cnt; ti++)
  ctx->prop.trans[ti].attrs = ctx->prop.trans[ti].attrs - old_attrs + new_attrs;
 ctx->max_attrs = max_attrs;
 if (old_attrs != ((void *)0))
  { db_attrs_st.st_curr_cnt--; pfree(old_attrs); };
}

variable_types: struct db_context { struct db_prop { unsigned char protoid; struct db_trans { unsigned short transid; struct db_attr { union { enum ikev1_oakley_attr { OAKLEY_ATTR_undefined=0, OAKLEY_ENCRYPTION_ALGORITHM=1, OAKLEY_HASH_ALGORITHM=2, OAKLEY_AUTHENTICATION_METHOD=3, OAKLEY_GROUP_DESCRIPTION=4, OAKLEY_GROUP_TYPE=5, OAKLEY_GROUP_PRIME=6, OAKLEY_GROUP_GENERATOR_ONE=7, OAKLEY_GROUP_GENERATOR_TWO=8, OAKLEY_GROUP_CURVE_A=9, OAKLEY_GROUP_CURVE_B=10, OAKLEY_LIFE_TYPE=11, OAKLEY_LIFE_DURATION=12, OAKLEY_PRF=13, OAKLEY_KEY_LENGTH=14, OAKLEY_FIELD_SIZE=15, OAKLEY_GROUP_ORDER=16 } oakley; enum ikev1_ipsec_attr { SA_LIFE_TYPE=1, SA_LIFE_DURATION=2, GROUP_DESCRIPTION=3, ENCAPSULATION_MODE=4, AUTH_ALGORITHM=5, KEY_LENGTH=6, KEY_ROUNDS=7, COMPRESS_DICT_SIZE=8, COMPRESS_PRIVATE_ALG=9, ECN_TUNNEL=10, ECN_TUNNEL_or_old_SECCTX=expr, ESN_64BIT_SEQNUM=11, IKEv1_IPSEC_ATTR_UNSPEC_12=12, SIG_ENC_ALGO_VAL=13, ADDRESS_PRESERVATION=14, SA_DIRECTION=15, IPSEC_ATTR_VAL_DESCS_ROOF=16, SECCTX=32001 } ipsec; } type; unsigned short val; } *attrs; unsigned int attr_cnt; } *trans; unsigned int trans_cnt; } prop; struct db_trans *trans0; struct db_trans *trans_cur; struct db_attr *attrs0; struct db_attr *attrs_cur; int max_trans; int max_attrs; } *

variable_types:
ti
unsigned int

return_type: void

user_defined_types: struct db_attr { union { enum ikev1_oakley_attr oakley; enum ikev1_ipsec_attr ipsec; } type; unsigned short val; }

user_defined_types: struct db_context { struct db_prop prop; struct db_trans *trans0; struct db_trans *trans_cur; struct db_attr *attrs0; struct db_attr *attrs_cur; int max_trans; int max_attrs; }

user_defined_types: struct db_prop { unsigned char protoid; struct db_trans *trans; unsigned int trans_cnt; }

user_defined_types: struct db_trans { unsigned short transid; struct db_attr *attrs; unsigned int attr_cnt; }


original_code:
static void db_attr_add(struct db_context *ctx, const struct db_attr *a)
{
 if ((ctx->attrs_cur - ctx->attrs0) >= ctx->max_attrs) {
  db_attrs_expand(ctx, ctx->max_attrs / 2 + 1);
 }
 *ctx->attrs_cur++ = *a;
 ctx->trans_cur->attr_cnt++;
}

canonical_original_code:
static void db_attr_add(struct db_context *ctx, struct db_attr *a)
{
 if ((ctx->attrs_cur - ctx->attrs0) >= ctx->max_attrs) {
  db_attrs_expand(ctx, ctx->max_attrs / 2 + 1);
 }
 *ctx->attrs_cur++ = *a;
 ctx->trans_cur->attr_cnt++;
}

variable_types:
a
struct db_attr *

user_defined_types: enum ikev1_oakley_attr { OAKLEY_ATTR_undefined=0, OAKLEY_ENCRYPTION_ALGORITHM=1, OAKLEY_HASH_ALGORITHM=2, OAKLEY_AUTHENTICATION_METHOD=3, OAKLEY_GROUP_DESCRIPTION=4, OAKLEY_GROUP_TYPE=5, OAKLEY_GROUP_PRIME=6, OAKLEY_GROUP_GENERATOR_ONE=7, OAKLEY_GROUP_GENERATOR_TWO=8, OAKLEY_GROUP_CURVE_A=9, OAKLEY_GROUP_CURVE_B=10, OAKLEY_LIFE_TYPE=11, OAKLEY_LIFE_DURATION=12, OAKLEY_PRF=13, OAKLEY_KEY_LENGTH=14, OAKLEY_FIELD_SIZE=15, OAKLEY_GROUP_ORDER=16 }

user_defined_types: enum ikev1_ipsec_attr { SA_LIFE_TYPE=1, SA_LIFE_DURATION=2, GROUP_DESCRIPTION=3, ENCAPSULATION_MODE=4, AUTH_ALGORITHM=5, KEY_LENGTH=6, KEY_ROUNDS=7, COMPRESS_DICT_SIZE=8, COMPRESS_PRIVATE_ALG=9, ECN_TUNNEL=10, ECN_TUNNEL_or_old_SECCTX=expr, ESN_64BIT_SEQNUM=11, IKEv1_IPSEC_ATTR_UNSPEC_12=12, SIG_ENC_ALGO_VAL=13, ADDRESS_PRESERVATION=14, SA_DIRECTION=15, IPSEC_ATTR_VAL_DESCS_ROOF=16, SECCTX=32001 }


decompiled_code:
__int64 __fastcall db_prop_new(char a1, int a2, int a3)
{
__int64 v4; // rbp

v4 = alloc_bytes_st(0x40uLL, (__int64)"db_context", (__int64)&db_context_st);
db_prop_init(v4, a1, a2, a3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, int a2, int a3)
{
__int64 v4; // rbp

v4 = func0(0x40uLL, (__int64)"db_context", (__int64)&db_context_st);
func1(v4, a1, a2, a3);
return v4;
}

original_code:
struct db_context *db_prop_new(uint8_t protoid, int max_trans, int max_attrs)
{
 struct db_context *ctx = alloc_bytes_st(sizeof(struct db_context), "db_context", &(db_context_st));;
 db_prop_init(ctx, protoid, max_trans, max_attrs);
 return ctx;
}

canonical_original_code:
struct db_context *db_prop_new(unsigned char protoid, int max_trans, int max_attrs)
{
 struct db_context *ctx = alloc_bytes_st(sizeof(struct db_context), "db_context", &(db_context_st));;
 db_prop_init(ctx, protoid, max_trans, max_attrs);
 return ctx;
}

variable_types:
protoid
unsigned char

return_type: struct db_context { struct db_prop { unsigned char protoid; struct db_trans { unsigned short transid; struct db_attr { union { enum ikev1_oakley_attr { OAKLEY_ATTR_undefined=0, OAKLEY_ENCRYPTION_ALGORITHM=1, OAKLEY_HASH_ALGORITHM=2, OAKLEY_AUTHENTICATION_METHOD=3, OAKLEY_GROUP_DESCRIPTION=4, OAKLEY_GROUP_TYPE=5, OAKLEY_GROUP_PRIME=6, OAKLEY_GROUP_GENERATOR_ONE=7, OAKLEY_GROUP_GENERATOR_TWO=8, OAKLEY_GROUP_CURVE_A=9, OAKLEY_GROUP_CURVE_B=10, OAKLEY_LIFE_TYPE=11, OAKLEY_LIFE_DURATION=12, OAKLEY_PRF=13, OAKLEY_KEY_LENGTH=14, OAKLEY_FIELD_SIZE=15, OAKLEY_GROUP_ORDER=16 } oakley; enum ikev1_ipsec_attr { SA_LIFE_TYPE=1, SA_LIFE_DURATION=2, GROUP_DESCRIPTION=3, ENCAPSULATION_MODE=4, AUTH_ALGORITHM=5, KEY_LENGTH=6, KEY_ROUNDS=7, COMPRESS_DICT_SIZE=8, COMPRESS_PRIVATE_ALG=9, ECN_TUNNEL=10, ECN_TUNNEL_or_old_SECCTX=expr, ESN_64BIT_SEQNUM=11, IKEv1_IPSEC_ATTR_UNSPEC_12=12, SIG_ENC_ALGO_VAL=13, ADDRESS_PRESERVATION=14, SA_DIRECTION=15, IPSEC_ATTR_VAL_DESCS_ROOF=16, SECCTX=32001 } ipsec; } type; unsigned short val; } *attrs; unsigned int attr_cnt; } *trans; unsigned int trans_cnt; } prop; struct db_trans *trans0; struct db_trans *trans_cur; struct db_attr *attrs0; struct db_attr *attrs_cur; int max_trans; int max_attrs; } *


decompiled_code:
unsigned __int64 __fastcall db_destroy(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
v2 = *(_QWORD *)(a1 + 24);
if ( v2 )
{
--db_trans_st;
pfree(v2);
}
v3 = *(_QWORD *)(a1 + 40);
if ( v3 )
{
--db_attrs_st;
pfree(v3);
}
--db_context_st;
pfree(a1);
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
v2 = *(_QWORD *)(a1 + 24);
if ( v2 )
{
--db_trans_st;
pfree(v2);
}
v3 = *(_QWORD *)(a1 + 40);
if ( v3 )
{
--db_attrs_st;
pfree(v3);
}
--db_context_st;
pfree(a1);
return v5 - __readfsqword(0x28u);
}

original_code:
void db_destroy(struct db_context *ctx)
{
 if (ctx->trans0 != ((void *)0))
  { db_trans_st.st_curr_cnt--; pfree(ctx->trans0); };
 if (ctx->attrs0 != ((void *)0))
  { db_attrs_st.st_curr_cnt--; pfree(ctx->attrs0); };
 { db_context_st.st_curr_cnt--; pfree(ctx); };
}


decompiled_code:
unsigned __int64 __fastcall db_attr_add_values(__int64 a1, int a2, __int16 a3)
{
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
LODWORD(v4) = a2;
WORD2(v4) = a3;
db_attr_add(a1, &v4);
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1, int a2, __int16 a3)
{
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v5 = __readfsqword(0x28u);
LODWORD(v4) = a2;
WORD2(v4) = a3;
func4(a1, &v4);
return v5 - __readfsqword(0x28u);
}

original_code:
void db_attr_add_values(struct db_context *ctx, enum ikev1_ipsec_attr type, uint16_t val)
{
 struct db_attr attr;
 attr.type.ipsec = type;
 attr.val = val;
 db_attr_add(ctx, &attr);
}

canonical_original_code:
void db_attr_add_values(struct db_context *ctx, enum ikev1_ipsec_attr type, unsigned short val)
{
 struct db_attr attr;
 attr.type.ipsec = type;
 attr.val = val;
 db_attr_add(ctx, &attr);
}

variable_types:
val
unsigned short

variable_types: struct db_attr { union { enum ikev1_oakley_attr { OAKLEY_ATTR_undefined=0, OAKLEY_ENCRYPTION_ALGORITHM=1, OAKLEY_HASH_ALGORITHM=2, OAKLEY_AUTHENTICATION_METHOD=3, OAKLEY_GROUP_DESCRIPTION=4, OAKLEY_GROUP_TYPE=5, OAKLEY_GROUP_PRIME=6, OAKLEY_GROUP_GENERATOR_ONE=7, OAKLEY_GROUP_GENERATOR_TWO=8, OAKLEY_GROUP_CURVE_A=9, OAKLEY_GROUP_CURVE_B=10, OAKLEY_LIFE_TYPE=11, OAKLEY_LIFE_DURATION=12, OAKLEY_PRF=13, OAKLEY_KEY_LENGTH=14, OAKLEY_FIELD_SIZE=15, OAKLEY_GROUP_ORDER=16 } oakley; enum ikev1_ipsec_attr { SA_LIFE_TYPE=1, SA_LIFE_DURATION=2, GROUP_DESCRIPTION=3, ENCAPSULATION_MODE=4, AUTH_ALGORITHM=5, KEY_LENGTH=6, KEY_ROUNDS=7, COMPRESS_DICT_SIZE=8, COMPRESS_PRIVATE_ALG=9, ECN_TUNNEL=10, ECN_TUNNEL_or_old_SECCTX=expr, ESN_64BIT_SEQNUM=11, IKEv1_IPSEC_ATTR_UNSPEC_12=12, SIG_ENC_ALGO_VAL=13, ADDRESS_PRESERVATION=14, SA_DIRECTION=15, IPSEC_ATTR_VAL_DESCS_ROOF=16, SECCTX=32001 } ipsec; } type; unsigned short val; }


decompiled_code:
__int64 __fastcall db_prop_get(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return a1;
}

original_code:
struct db_prop *db_prop_get(struct db_context *ctx)
{
 return &ctx->prop;
}

variable_types: struct db_context { struct db_prop prop; struct db_trans *trans0; struct db_trans *trans_cur; struct db_attr *attrs0; struct db_attr *attrs_cur; int max_trans; int max_attrs; } *

return_type: struct db_prop { unsigned char protoid; struct db_trans { unsigned short transid; struct db_attr { union { enum ikev1_oakley_attr { OAKLEY_ATTR_undefined=0, OAKLEY_ENCRYPTION_ALGORITHM=1, OAKLEY_HASH_ALGORITHM=2, OAKLEY_AUTHENTICATION_METHOD=3, OAKLEY_GROUP_DESCRIPTION=4, OAKLEY_GROUP_TYPE=5, OAKLEY_GROUP_PRIME=6, OAKLEY_GROUP_GENERATOR_ONE=7, OAKLEY_GROUP_GENERATOR_TWO=8, OAKLEY_GROUP_CURVE_A=9, OAKLEY_GROUP_CURVE_B=10, OAKLEY_LIFE_TYPE=11, OAKLEY_LIFE_DURATION=12, OAKLEY_PRF=13, OAKLEY_KEY_LENGTH=14, OAKLEY_FIELD_SIZE=15, OAKLEY_GROUP_ORDER=16 } oakley; enum ikev1_ipsec_attr { SA_LIFE_TYPE=1, SA_LIFE_DURATION=2, GROUP_DESCRIPTION=3, ENCAPSULATION_MODE=4, AUTH_ALGORITHM=5, KEY_LENGTH=6, KEY_ROUNDS=7, COMPRESS_DICT_SIZE=8, COMPRESS_PRIVATE_ALG=9, ECN_TUNNEL=10, ECN_TUNNEL_or_old_SECCTX=expr, ESN_64BIT_SEQNUM=11, IKEv1_IPSEC_ATTR_UNSPEC_12=12, SIG_ENC_ALGO_VAL=13, ADDRESS_PRESERVATION=14, SA_DIRECTION=15, IPSEC_ATTR_VAL_DESCS_ROOF=16, SECCTX=32001 } ipsec; } type; unsigned short val; } *attrs; unsigned int attr_cnt; } *trans; unsigned int trans_cnt; } *


decompiled_code:
__int64 __fastcall jam_sanitized_char(__int64 a1, unsigned __int8 a2, char a3)
{
__int64 result; // rax

switch ( a2 )
{
case 0u:
result = jam_string(a1, &LC0);
break;
case 7u:
result = jam_string(a1, &LC1);
break;
case 8u:
result = jam_string(a1, &LC2);
break;
case 9u:
result = jam_string(a1, &LC3);
break;
case 0xAu:
result = jam_string(a1, &LC4);
break;
case 0xBu:
result = jam_string(a1, &LC5);
break;
case 0xCu:
result = jam_string(a1, &LC6);
break;
case 0xDu:
result = jam_string(a1, &LC7);
break;
default:
if ( (unsigned __int8)char_isprint((unsigned int)(char)a2) )
{
result = jam_char(a1, (unsigned int)(char)a2);
}
else if ( (unsigned __int8)char_isdigit((unsigned int)a3) )
{
result = jam(a1, "\\%03o", a2);
}
else
{
result = jam(a1, "\\%o", a2);
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, char a3)
{
__int64 result; // rax

switch ( a2 )
{
case 0u:
result = jam_string(a1, &LC0);
break;
case 7u:
result = jam_string(a1, &LC1);
break;
case 8u:
result = jam_string(a1, &LC2);
break;
case 9u:
result = jam_string(a1, &LC3);
break;
case 0xAu:
result = jam_string(a1, &LC4);
break;
case 0xBu:
result = jam_string(a1, &LC5);
break;
case 0xCu:
result = jam_string(a1, &LC6);
break;
case 0xDu:
result = jam_string(a1, &LC7);
break;
default:
if ( (unsigned __int8)char_isprint((unsigned int)(char)a2) )
{
result = jam_char(a1, (unsigned int)(char)a2);
}
else if ( (unsigned __int8)char_isdigit((unsigned int)a3) )
{
result = jam(a1, "\\%03o", a2);
}
else
{
result = jam(a1, "\\%o", a2);
}
break;
}
return result;
}

original_code:
static size_t jam_sanitized_char(struct jambuf *buf, char c, char c1)
{
 switch (c) {
 case '\0': return jam_string(buf, "\\0");
 case '\a': return jam_string(buf, "\\a");
 case '\b': return jam_string(buf, "\\b");
 case '\t': return jam_string(buf, "\\t");
 case '\n': return jam_string(buf, "\\n");
 case '\v': return jam_string(buf, "\\v");
 case '\f': return jam_string(buf, "\\f");
 case '\r': return jam_string(buf, "\\r");
 }
 if (char_isprint(c)) {
  return jam_char(buf, c);
 }
 if (char_isdigit(c1)) {
  return jam(buf, "\\%03o", c & 0xFF);
 }
 return jam(buf, "\\%o", c & 0xFF);
}

canonical_original_code:
static unsigned long jam_sanitized_char(struct jambuf *buf, char c, char c1)
{
 switch (c) {
 case '\0': return jam_string(buf, "\\0");
 case '\a': return jam_string(buf, "\\a");
 case '\b': return jam_string(buf, "\\b");
 case '\t': return jam_string(buf, "\\t");
 case '\n': return jam_string(buf, "\\n");
 case '\v': return jam_string(buf, "\\v");
 case '\f': return jam_string(buf, "\\f");
 case '\r': return jam_string(buf, "\\r");
 }
 if (char_isprint(c)) {
  return jam_char(buf, c);
 }
 if (char_isdigit(c1)) {
  return jam(buf, "\\%03o", c & 0xFF);
 }
 return jam(buf, "\\%o", c & 0xFF);
}

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *

variable_types: c char

return_type: unsigned long


decompiled_code:
__int64 __fastcall jam_hex_bytes(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // rbp

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
do
{
v6 += jam(a1, "%02x", *(unsigned __int8 *)(a2 + v4));
v4 = ++v5;
}
while ( v5 < a3 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // rbp

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
do
{
v6 += jam(a1, "%02x", *(unsigned __int8 *)(a2 + v4));
v4 = ++v5;
}
while ( v5 < a3 );
return v6;
}

original_code:
size_t jam_hex_bytes(struct jambuf *buf, const void *ptr, size_t size)
{
 size_t n = 0;
 const uint8_t *bytes = ptr;
 for (unsigned i = 0; i < size; i++) {
  n += jam(buf, "%02x", bytes[i]);
 }
 return n;
}

canonical_original_code:
unsigned long jam_hex_bytes(struct jambuf *buf, void *ptr, unsigned long size)
{
 unsigned long n = 0;
 unsigned char *bytes = ptr;
 for (unsigned int i = 0; i < size; i++) {
  n += jam(buf, "%02x", bytes[i]);
 }
 return n;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
n
unsigned long

variable_types:
bytes
unsigned char *

variable_types:
i
unsigned int

user_defined_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; }


decompiled_code:
__int64 __fastcall jam_HEX_bytes(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // rbp

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
do
{
v6 += jam(a1, "%02X", *(unsigned __int8 *)(a2 + v4));
v4 = ++v5;
}
while ( v5 < a3 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // rbp

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
do
{
v6 += jam(a1, "%02X", *(unsigned __int8 *)(a2 + v4));
v4 = ++v5;
}
while ( v5 < a3 );
return v6;
}

original_code:
size_t jam_HEX_bytes(struct jambuf *buf, const void *ptr, size_t size)
{
 size_t n = 0;
 const uint8_t *bytes = ptr;
 for (unsigned i = 0; i < size; i++) {
  n += jam(buf, "%02X", bytes[i]);
 }
 return n;
}

canonical_original_code:
unsigned long jam_HEX_bytes(struct jambuf *buf, void *ptr, unsigned long size)
{
 unsigned long n = 0;
 unsigned char *bytes = ptr;
 for (unsigned int i = 0; i < size; i++) {
  n += jam(buf, "%02X", bytes[i]);
 }
 return n;
}


decompiled_code:
__int64 __fastcall jam_dump_bytes(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
__int64 v3; // r12
unsigned __int8 *v4; // rbx
unsigned __int64 v5; // r13
const char *v6; // rdx
unsigned int v7; // ebp

v3 = a3;
if ( a3 )
{
v4 = a2;
if ( a2 )
{
v5 = (unsigned __int64)&a2[a3];
if ( a2 >= &a2[a3] )
{
v3 = 0LL;
}
else
{
v6 = (const char *)&LC12;
v3 = 0LL;
do
{
v7 = 0;
do
{
v3 += jam(a1, "%s%02x", v6, *v4++);
++v7;
v6 = " ";
}
while ( v7 <= 3 && v5 > (unsigned __int64)v4 );
if ( v5 <= (unsigned __int64)v4 )
break;
v6 = " ";
}
while ( v5 > (unsigned __int64)v4 );
}
}
else
{
v3 = jam_string(a1, 0LL);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
__int64 v3; // r12
unsigned __int8 *v4; // rbx
unsigned __int64 v5; // r13
const char *v6; // rdx
unsigned int v7; // ebp

v3 = a3;
if ( a3 )
{
v4 = a2;
if ( a2 )
{
v5 = (unsigned __int64)&a2[a3];
if ( a2 >= &a2[a3] )
{
v3 = 0LL;
}
else
{
v6 = (const char *)&LC12;
v3 = 0LL;
do
{
v7 = 0;
do
{
v3 += jam(a1, "%s%02x", v6, *v4++);
++v7;
v6 = " ";
}
while ( v7 <= 3 && v5 > (unsigned __int64)v4 );
if ( v5 <= (unsigned __int64)v4 )
break;
v6 = " ";
}
while ( v5 > (unsigned __int64)v4 );
}
}
else
{
v3 = jam_string(a1, 0LL);
}
}
return v3;
}

original_code:
size_t jam_dump_bytes(struct jambuf *buf, const void *bytes, size_t size)
{
 if (size == 0) {
  return 0;
 } else if (bytes == ((void *)0)) {
  return jam_string(buf, ((void *)0));
 }
 size_t n = 0;
 const uint8_t *byte = bytes;
 const uint8_t *end = byte + size;
 const char *sep = "";
 while (byte < end) {
  for (unsigned b = 0; b < 4 && byte < end; b++) {
   n += jam(buf, "%s%02x", sep, *byte++);
   sep = " ";
  }
  sep = "  ";
 }
 return n;
}

canonical_original_code:
unsigned long jam_dump_bytes(struct jambuf *buf, void *bytes, unsigned long size)
{
 if (size == 0) {
  return 0;
 } else if (bytes == ((void *)0)) {
  return jam_string(buf, ((void *)0));
 }
 unsigned long n = 0;
 unsigned char *byte = bytes;
 unsigned char *end = byte + size;
 char *sep = "";
 while (byte < end) {
  for (unsigned int b = 0; b < 4 && byte < end; b++) {
   n += jam(buf, "%s%02x", sep, *byte++);
   sep = " ";
  }
  sep = "  ";
 }
 return n;
}

variable_types:
bytes
void *

variable_types:
byte
unsigned char *

variable_types:
end
unsigned char *

variable_types:
sep
char *

variable_types:
b
unsigned int


decompiled_code:
__int64 __fastcall jam_sanitized_bytes(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned int v5; // ebp
__int64 v6; // r13
__int64 v7; // rbx
unsigned __int8 v8; // si
char v9; // dl

if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
v7 = 0LL;
do
{
v8 = *(_BYTE *)(a2 + v7);
v7 = ++v5;
v9 = 0;
if ( v5 != a3 )
v9 = *(_BYTE *)(a2 + v5);
v6 += jam_sanitized_char(a1, v8, v9);
}
while ( v5 < a3 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned int v5; // ebp
__int64 v6; // r13
__int64 v7; // rbx
unsigned __int8 v8; // si
char v9; // dl

if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
v7 = 0LL;
do
{
v8 = *(_BYTE *)(a2 + v7);
v7 = ++v5;
v9 = 0;
if ( v5 != a3 )
v9 = *(_BYTE *)(a2 + v5);
v6 += func0(a1, v8, v9);
}
while ( v5 < a3 );
return v6;
}

original_code:
size_t jam_sanitized_bytes(struct jambuf *buf, const void *ptr, size_t size)
{
 size_t n = 0;
 const char *chars = ptr;
 for (unsigned i = 0; i < size; i++) {
  char c = chars[i];
  char c1 = (i + 1 == size ? '\0' : chars[i+1]);
  n += jam_sanitized_char(buf, c, c1);
 }
 return n;
}

canonical_original_code:
unsigned long jam_sanitized_bytes(struct jambuf *buf, void *ptr, unsigned long size)
{
 unsigned long n = 0;
 char *chars = ptr;
 for (unsigned int i = 0; i < size; i++) {
  char c = chars[i];
  char c1 = (i + 1 == size ? '\0' : chars[i+1]);
  n += jam_sanitized_char(buf, c, c1);
 }
 return n;
}

variable_types:
chars
char *


decompiled_code:
__int64 __fastcall jam_shell_quoted_bytes(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // ebp
__int64 v6; // r12
unsigned __int8 v7; // bl

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
do
{
v7 = *(_BYTE *)(a2 + v4);
if ( (unsigned __int8)(v7 - 34) <= 0x3Eu && ((1LL << (v7 - 34)) & 0x4400000000000025LL) != 0
|| !(unsigned __int8)char_isprint((unsigned int)(char)v7) )
{
v6 += jam(a1, "\\%03o", v7);
}
else
{
v6 += jam_char(a1, (unsigned int)(char)v7);
}
v4 = ++v5;
}
while ( v5 < a3 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // ebp
__int64 v6; // r12
unsigned __int8 v7; // bl

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 0;
v6 = 0LL;
do
{
v7 = *(_BYTE *)(a2 + v4);
if ( (unsigned __int8)(v7 - 34) <= 0x3Eu && ((1LL << (v7 - 34)) & 0x4400000000000025LL) != 0
|| !(unsigned __int8)char_isprint((unsigned int)(char)v7) )
{
v6 += jam(a1, "\\%03o", v7);
}
else
{
v6 += jam_char(a1, (unsigned int)(char)v7);
}
v4 = ++v5;
}
while ( v5 < a3 );
return v6;
}

original_code:
size_t jam_shell_quoted_bytes(struct jambuf *buf, const void *ptr, size_t size)
{
 size_t n = 0;
 const char *chars = ptr;
 for (unsigned i = 0; i < size; i++) {
  char c = chars[i];
  switch (c) {
  case '\'':
  case '\\':
  case '"':
  case '`':
  case '$':
   n += jam(buf, "\\%03o", c & 0xFF);
   break;
  default:
   if (char_isprint(c)) {
    n += jam_char(buf, c);
   } else {
    n += jam(buf, "\\%03o", c & 0xFF);
   }
   break;
  }
 }
 return n;
}

canonical_original_code:
unsigned long jam_shell_quoted_bytes(struct jambuf *buf, void *ptr, unsigned long size)
{
 unsigned long n = 0;
 char *chars = ptr;
 for (unsigned int i = 0; i < size; i++) {
  char c = chars[i];
  switch (c) {
  case '\'':
  case '\\':
  case '"':
  case '`':
  case '$':
   n += jam(buf, "\\%03o", c & 0xFF);
   break;
  default:
   if (char_isprint(c)) {
    n += jam_char(buf, c);
   } else {
    n += jam(buf, "\\%03o", c & 0xFF);
   }
   break;
  }
 }
 return n;
}


decompiled_code:
__int64 __fastcall jam_ucase_bytes(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // r12
char v7; // al
unsigned int v8; // ebp
char v9; // dl

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 1;
v6 = 0LL;
do
{
v8 = *(char *)(a2 + v4);
if ( (unsigned __int8)char_islower(v8) )
{
v7 = char_toupper(v8);
v6 += jam_char(a1, (unsigned int)v7);
}
else
{
v9 = 0;
if ( v5 != a3 )
v9 = *(_BYTE *)(a2 + v5);
v6 += jam_sanitized_char(a1, v8, v9);
}
v4 = v5++;
}
while ( v4 < a3 );
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // r12
char v7; // al
unsigned int v8; // ebp
char v9; // dl

v4 = 0LL;
if ( !a3 )
return 0LL;
v5 = 1;
v6 = 0LL;
do
{
v8 = *(char *)(a2 + v4);
if ( (unsigned __int8)char_islower(v8) )
{
v7 = char_toupper(v8);
v6 += jam_char(a1, (unsigned int)v7);
}
else
{
v9 = 0;
if ( v5 != a3 )
v9 = *(_BYTE *)(a2 + v5);
v6 += func0(a1, v8, v9);
}
v4 = v5++;
}
while ( v4 < a3 );
return v6;
}

original_code:
size_t jam_ucase_bytes(struct jambuf *buf, const void *ptr, size_t size)
{
 size_t n = 0;
 const char *chars = ptr;
 for (unsigned i = 0; i < size; i++) {
  char c = chars[i];
  if (char_islower(c)) {
   n += jam_char(buf, char_toupper(c));
  } else {
   char c1 = (i + 1 == size ? '\0' : chars[i+1]);
   n += jam_sanitized_char(buf, c, c1);
  }
 }
 return n;
}

canonical_original_code:
unsigned long jam_ucase_bytes(struct jambuf *buf, void *ptr, unsigned long size)
{
 unsigned long n = 0;
 char *chars = ptr;
 for (unsigned int i = 0; i < size; i++) {
  char c = chars[i];
  if (char_islower(c)) {
   n += jam_char(buf, char_toupper(c));
  } else {
   char c1 = (i + 1 == size ? '\0' : chars[i+1]);
   n += jam_sanitized_char(buf, c, c1);
  }
 }
 return n;
}


decompiled_code:
__int64 __fastcall jam_ucase_string(__int64 a1, const char *a2)
{
unsigned __int64 v2; // rax

v2 = strlen(a2);
return jam_ucase_bytes(a1, (__int64)a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
unsigned __int64 v2; // rax

v2 = strlen(a2);
return func6(a1, (__int64)a2, v2);
}

original_code:
size_t jam_ucase_string(struct jambuf *buf, const char *string)
{
 return jam_ucase_bytes(buf, string, strlen(string));
}

canonical_original_code:
unsigned long jam_ucase_string(struct jambuf *buf, char *string)
{
 return jam_ucase_bytes(buf, string, strlen(string));
}

variable_types:
string
char *


decompiled_code:
__int64 __fastcall jam_policy(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = a2;
if ( a2 )
result = jam_lset_short(a1, &sa_policy_bit_names, &LC0, a2);
return result;
}

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

result = a2;
if ( a2 )
result = jam_lset_short(a1, &sa_policy_bit_names, &LC0, a2);
return result;
}

original_code:
size_t jam_policy(struct jambuf *buf, lset_t policy)
{
 size_t s = 0;
 if (policy != ((lset_t)0)) {
  s += jam_lset_short(buf, &sa_policy_bit_names, "+", policy);
 }
 return s;
}

canonical_original_code:
unsigned long jam_policy(struct jambuf *buf, unsigned long policy)
{
 unsigned long s = 0;
 if (policy != ((unsigned long)0)) {
  s += jam_lset_short(buf, &sa_policy_bit_names, "+", policy);
 }
 return s;
}

variable_types:
policy
unsigned long

variable_types:
s
unsigned long


decompiled_code:
__int64 __fastcall str_policy(__int64 a1, __int64 a2)
{
_QWORD v3[9]; // [rsp+0h] [rbp-48h] BYREF

v3[5] = __readfsqword(0x28u);
array_as_jambuf(v3, a2, 512LL);
jam_policy((__int64)v3, a1);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
_QWORD v3[9]; // [rsp+0h] [rbp-48h] BYREF

v3[5] = __readfsqword(0x28u);
array_as_jambuf(v3, a2, 512LL);
func0((__int64)v3, a1);
return a2;
}

original_code:
const char *str_policy(lset_t policy, policy_buf *dst)
{
 struct jambuf buf = array_as_jambuf((dst->buf), sizeof(dst->buf));
 jam_policy(&buf, policy);
 return dst->buf;
}

canonical_original_code:
char *str_policy(unsigned long policy, struct policy_buf *dst)
{
 struct jambuf buf = array_as_jambuf((dst->buf), sizeof(dst->buf));
 jam_policy(&buf, policy);
 return dst->buf;
}

variable_types:
dst
struct policy_buf { char buf[512]; } *

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; }

return_type: char *


decompiled_code:
unsigned __int64 init_pluto_constants()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
check_enum_names(&pluto_enum_names_checklist, 15LL);
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func3()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
check_enum_names(&pluto_enum_names_checklist, 15LL);
return v1 - __readfsqword(0x28u);
}

original_code:
void init_pluto_constants(void) {
 check_enum_names((pluto_enum_names_checklist), (sizeof(pluto_enum_names_checklist) / sizeof(*(pluto_enum_names_checklist))));
}

canonical_original_code:
void init_pluto_constants() {
 check_enum_names((pluto_enum_names_checklist), (sizeof(pluto_enum_names_checklist) / sizeof(*(pluto_enum_names_checklist))));
}


decompiled_code:
__int64 suppress_object_log_false()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
_Bool suppress_object_log_false(const void *object __attribute__ ((unused)))
{
 return 0;
}

canonical_original_code:
_Bool suppress_object_log_false(void *object)
{
 return 0;
}

variable_types:
object
void *


decompiled_code:
__int64 jam_object_prefix_none()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
size_t jam_object_prefix_none(struct jambuf *buf __attribute__ ((unused)), const void *object __attribute__ ((unused)))
{
 return 0;
}

canonical_original_code:
unsigned long jam_object_prefix_none(struct jambuf *buf, void *object)
{
 return 0;
}

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *


decompiled_code:
__int64 suppress_object_log_true()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
_Bool suppress_object_log_true(const void *object __attribute__ ((unused)))
{
 return 1;
}

canonical_original_code:
_Bool suppress_object_log_true(void *object)
{
 return 1;
}


decompiled_code:
__int64 __fastcall cmp_iface(const void *a1, const void *a2)
{
__int64 v2; // rbp
__int64 v3; // r12
int v4; // ebx
__int64 v5; // rdx
unsigned int v6; // ebx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // rdx
int v12; // eax

v2 = *(_QWORD *)a1;
v3 = *(_QWORD *)a2;
v4 = *(_DWORD *)(address_type(*(_QWORD *)a1) + 336);
v6 = v4 - *(_DWORD *)(address_type(v3) + 336);
if ( v6 )
return v6;
if ( !(unsigned __int8)address_is_loopback(v3, a2, v5) )
{
v6 = ((unsigned __int8)address_is_specified(v3, a2, v8) == 0) + 1;
if ( (unsigned __int8)address_is_loopback(v3, a2, v10) )
return v6;
v12 = ((unsigned __int8)address_is_specified(v3, a2, v11) == 0) + 1;
goto LABEL_14;
}
if ( !(unsigned __int8)address_is_loopback(v3, a2, v8) )
{
if ( (unsigned __int8)address_is_specified(v3, a2, v9) )
return (unsigned int)-1;
v12 = 2;
LABEL_14:
v6 -= v12;
if ( v6 )
return v6;
}
v6 = strcmp((const char *)(v2 + 32), (const char *)(v3 + 32));
if ( !v6 )
{
v6 = addrcmp(v2, v3);
if ( !v6 && (cur_debugging & 1) != 0 )
DBG_log("interface sort not stable or duplicate");
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
__int64 v2; // rbp
__int64 v3; // r12
int v4; // ebx
__int64 v5; // rdx
unsigned int v6; // ebx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx
__int64 v11; // rdx
int v12; // eax

v2 = *(_QWORD *)a1;
v3 = *(_QWORD *)a2;
v4 = *(_DWORD *)(address_type(*(_QWORD *)a1) + 336);
v6 = v4 - *(_DWORD *)(address_type(v3) + 336);
if ( v6 )
return v6;
if ( !(unsigned __int8)address_is_loopback(v3, a2, v5) )
{
v6 = ((unsigned __int8)address_is_specified(v3, a2, v8) == 0) + 1;
if ( (unsigned __int8)address_is_loopback(v3, a2, v10) )
return v6;
v12 = ((unsigned __int8)address_is_specified(v3, a2, v11) == 0) + 1;
goto LABEL_14;
}
if ( !(unsigned __int8)address_is_loopback(v3, a2, v8) )
{
if ( (unsigned __int8)address_is_specified(v3, a2, v9) )
return (unsigned int)-1;
v12 = 2;
LABEL_14:
v6 -= v12;
if ( v6 )
return v6;
}
v6 = strcmp((const char *)(v2 + 32), (const char *)(v3 + 32));
if ( !v6 )
{
v6 = addrcmp(v2, v3);
if ( !v6 && (cur_debugging & 1) != 0 )
DBG_log("interface sort not stable or duplicate");
}
return v6;
}

original_code:
static int cmp_iface(const void *lv, const void *rv)
{
 const struct raw_iface *const *ll = lv;
 const struct raw_iface *const *rr = rv;
 const struct raw_iface *l = *ll;
 const struct raw_iface *r = *rr;
 int i;
 i = address_type(&l->addr)->af - address_type(&r->addr)->af;
 if (i != 0) {
  return i;
 }
 i = (address_is_loopback(l->addr) ? 0 : address_is_specified(l->addr) ? 1 : 2) - (address_is_loopback(r->addr) ? 0 : address_is_specified(r->addr) ? 1 : 2);
 if (i != 0) {
  return i;
 }
 i = strcmp(l->name, r->name);
 if (i != 0) {
  return i;
 }
 i = addrcmp(&l->addr, &r->addr);
 if (i != 0) {
  return i;
 }
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("interface sort not stable or duplicate"); } };
 return 0;
}

canonical_original_code:
static int cmp_iface(void *lv, void *rv)
{
 struct raw_iface **ll = lv;
 struct raw_iface **rr = rv;
 struct raw_iface *l = *ll;
 struct raw_iface *r = *rr;
 int i;
 i = address_type(&l->addr)->af - address_type(&r->addr)->af;
 if (i != 0) {
  return i;
 }
 i = (address_is_loopback(l->addr) ? 0 : address_is_specified(l->addr) ? 1 : 2) - (address_is_loopback(r->addr) ? 0 : address_is_specified(r->addr) ? 1 : 2);
 if (i != 0) {
  return i;
 }
 i = strcmp(l->name, r->name);
 if (i != 0) {
  return i;
 }
 i = addrcmp(&l->addr, &r->addr);
 if (i != 0) {
  return i;
 }
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("interface sort not stable or duplicate"); } };
 return 0;
}

variable_types:
lv
void *

variable_types:
rv
void *

variable_types: struct raw_iface { struct ip_address { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes { unsigned char byte[16]; } bytes; } addr; struct raw_iface *next; char name[]; } **

variable_types: i int

return_type: int

user_defined_types: struct raw_iface { struct ip_address addr; struct raw_iface *next; char name[]; }

user_defined_types: struct ip_address { _Bool is_set; enum ip_version version; struct ip_bytes bytes; }


decompiled_code:
__int64 __fastcall said_is_unset(unsigned __int8 *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1 ^ 1u;
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1 ^ 1u;
else
result = 1LL;
return result;
}

original_code:
_Bool said_is_unset(const ip_said *said)
{
 if (said == ((void *)0)) {
  return 1;
 }
 return !said->is_set;
}

canonical_original_code:
_Bool said_is_unset(struct ip_said *said)
{
 if (said == ((void *)0)) {
  return 1;
 }
 return !said->is_set;
}

variable_types: struct ip_said { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes { unsigned char byte[16]; } dst; unsigned int ipproto; unsigned int spi; } *

user_defined_types: struct ip_said { _Bool is_set; enum ip_version version; struct ip_bytes dst; unsigned int ipproto; unsigned int spi; }


decompiled_code:
__int64 __fastcall said_info(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax

result = 0LL;
if ( (_BYTE)a7 )
result = ip_version_info(HIDWORD(a7));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax

result = 0LL;
if ( (_BYTE)a7 )
result = ip_version_info(HIDWORD(a7));
return result;
}

original_code:
const struct ip_info *said_info(const ip_said said)
{
 if (!said.is_set) {
  return ((void *)0);
 }
 return ip_version_info(said.version);
}

canonical_original_code:
struct ip_info *said_info(struct ip_said said)
{
 if (!said.is_set) {
  return ((void *)0);
 }
 return ip_version_info(said.version);
}

variable_types: struct ip_said { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes dst; unsigned int ipproto; unsigned int spi; }

return_type: struct ip_info { enum ip_version { IPv4=4, IPv6=6 } ip_version; enum ip_index { IPv4_INDEX=0, IPv6_INDEX=1 } ip_index; char *ip_name; unsigned long ip_size; unsigned int mask_cnt; struct { struct ip_address { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes { unsigned char byte[16]; } bytes; } unspec; struct ip_address loopback; unsigned long (*jam)(struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *buf, struct ip_info *info, struct ip_bytes *bytes); unsigned long (*jam_wrapped)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes); } address; struct { unsigned long (*jam)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes, unsigned int hport); } endpoint; struct { struct ip_subnet { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes bytes; unsigned int maskbits; } zero; struct ip_subnet all; } subnet; struct { struct ip_range { _Bool is_set; _Bool is_subnet; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes start; struct ip_bytes end; } zero; struct ip_range all; } range; struct { struct ip_selector { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes bytes; unsigned int maskbits; unsigned int ipproto; int hport; } zero; struct ip_selector all; } selector; unsigned int ikev1_max_fragment_size; unsigned int ikev2_max_fragment_size; struct { int domain; char *domain_name; } socket; int af; char *af_name; unsigned long sockaddr_size; struct ip_address (*address_from_sockaddr)(struct ip_sockaddr { unsigned int len; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } sa; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } sa; } sa); struct ip_port { unsigned int hport; } (*port_from_sockaddr)(struct ip_sockaddr sa); enum ikev2_ts_type { IKEv2_TS_IPV4_ADDR_RANGE=7, IKEv2_TS_IPV6_ADDR_RANGE=8, IKEv2_TS_FC_ADDR_RANGE=9, IKEv2_TS_SECLABEL=10 } ikev2_ts_addr_range_type; enum ikev2_cp_attribute_type { IKEv2_CP_ATTR_RESERVED=0, IKEv2_INTERNAL_IP4_ADDRESS=1, IKEv2_INTERNAL_IP4_NETMASK=2, IKEv2_INTERNAL_IP4_DNS=3, IKEv2_INTERNAL_IP4_NBNS=4, IKEv2_RESERVED_5=5, IKEv2_INTERNAL_IP4_DHCP=6, IKEv2_APPLICATION_VERSION=7, IKEv2_INTERNAL_IP6_ADDRESS=8, IKEv2_RESERVED_9=9, IKEv2_INTERNAL_IP6_DNS=10, IKEv2_RESERVED_11=11, IKEv2_INTERNAL_IP6_DHCP=12, IKEv2_INTERNAL_IP4_SUBNET=13, IKEv2_SUPPORTED_ATTRIBUTES=14, IKEv2_INTERNAL_IP6_SUBNET=15, IKEv2_MIP6_HOME_PREFIX=16, IKEv2_INTERNAL_IP6_LINK=17, IKEv2_INTERNAL_IP6_PREFIX=18, IKEv2_HOME_AGENT_ADDRESS=19, IKEv2_P_CSCF_IP4_ADDRESS=20, IKEv2_P_CSCF_IP6_ADDRESS=21, IKEv2_FTT_KAT=22, IKEv2_EXTERNAL_SOURCE_IP4_NAT_INFO=23, IKEv2_TIMEOUT_PERIOD_FOR_LIVENESS_CHECK=24, IKEv2_INTERNAL_DNS_DOMAIN=25, IKEv2_INTERNAL_DNSSEC_TA=26 } ikev2_internal_address; enum ikev2_cp_attribute_type { IKEv2_CP_ATTR_RESERVED=0, IKEv2_INTERNAL_IP4_ADDRESS=1, IKEv2_INTERNAL_IP4_NETMASK=2, IKEv2_INTERNAL_IP4_DNS=3, IKEv2_INTERNAL_IP4_NBNS=4, IKEv2_RESERVED_5=5, IKEv2_INTERNAL_IP4_DHCP=6, IKEv2_APPLICATION_VERSION=7, IKEv2_INTERNAL_IP6_ADDRESS=8, IKEv2_RESERVED_9=9, IKEv2_INTERNAL_IP6_DNS=10, IKEv2_RESERVED_11=11, IKEv2_INTERNAL_IP6_DHCP=12, IKEv2_INTERNAL_IP4_SUBNET=13, IKEv2_SUPPORTED_ATTRIBUTES=14, IKEv2_INTERNAL_IP6_SUBNET=15, IKEv2_MIP6_HOME_PREFIX=16, IKEv2_INTERNAL_IP6_LINK=17, IKEv2_INTERNAL_IP6_PREFIX=18, IKEv2_HOME_AGENT_ADDRESS=19, IKEv2_P_CSCF_IP4_ADDRESS=20, IKEv2_P_CSCF_IP6_ADDRESS=21, IKEv2_FTT_KAT=22, IKEv2_EXTERNAL_SOURCE_IP4_NAT_INFO=23, IKEv2_TIMEOUT_PERIOD_FOR_LIVENESS_CHECK=24, IKEv2_INTERNAL_DNS_DOMAIN=25, IKEv2_INTERNAL_DNSSEC_TA=26 } ikev2_internal_dns; enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 } id_ip_addr; enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 } id_ip_addr_subnet; enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 } id_ip_addr_range; } *

user_defined_types: struct ip_info { enum ip_version ip_version; enum ip_index ip_index; char *ip_name; unsigned long ip_size; unsigned int mask_cnt; struct { struct ip_address unspec; struct ip_address loopback; unsigned long (*jam)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes); unsigned long (*jam_wrapped)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes); } address; struct { unsigned long (*jam)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes, unsigned int hport); } endpoint; struct { struct ip_subnet zero; struct ip_subnet all; } subnet; struct { struct ip_range zero; struct ip_range all; } range; struct { struct ip_selector zero; struct ip_selector all; } selector; unsigned int ikev1_max_fragment_size; unsigned int ikev2_max_fragment_size; struct { int domain; char *domain_name; } socket; int af; char *af_name; unsigned long sockaddr_size; struct ip_address (*address_from_sockaddr)(struct ip_sockaddr sa); struct ip_port (*port_from_sockaddr)(struct ip_sockaddr sa); enum ikev2_ts_type ikev2_ts_addr_range_type; enum ikev2_cp_attribute_type ikev2_internal_address; enum ikev2_cp_attribute_type ikev2_internal_dns; enum ike_id_type id_ip_addr; enum ike_id_type id_ip_addr_subnet; enum ike_id_type id_ip_addr_range; }

user_defined_types: struct ip_subnet { _Bool is_set; enum ip_version version; struct ip_bytes bytes; unsigned int maskbits; }

user_defined_types: struct ip_range { _Bool is_set; _Bool is_subnet; enum ip_version version; struct ip_bytes start; struct ip_bytes end; }

user_defined_types: struct ip_selector { _Bool is_set; enum ip_version version; struct ip_bytes bytes; unsigned int maskbits; unsigned int ipproto; int hport; }

user_defined_types: struct ip_sockaddr { unsigned int len; union { struct sockaddr sa; struct sockaddr_in sin; struct sockaddr_in6 sin6; } sa; }

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

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


decompiled_code:
__int64 __fastcall said_type(const __m128i *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( a1 )
result = said_info((__int64)a1, a2, a3, a4, a5, a6, _mm_loadu_si128(a1).m128i_i64[0]);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const __m128i *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( a1 )
result = func4((__int64)a1, a2, a3, a4, a5, a6, _mm_loadu_si128(a1).m128i_i64[0]);
else
result = 0LL;
return result;
}

original_code:
const struct ip_info *said_type(const ip_said *said)
{
 if (said == ((void *)0)) {
  return ((void *)0);
 }
 return said_info(*said);
}

canonical_original_code:
struct ip_info *said_type(struct ip_said *said)
{
 if (said == ((void *)0)) {
  return ((void *)0);
 }
 return said_info(*said);
}

variable_types: struct ip_said { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes dst; unsigned int ipproto; unsigned int spi; } *

user_defined_types: enum ip_index { IPv4_INDEX=0, IPv6_INDEX=1 }

user_defined_types: enum ikev2_ts_type { IKEv2_TS_IPV4_ADDR_RANGE=7, IKEv2_TS_IPV6_ADDR_RANGE=8, IKEv2_TS_FC_ADDR_RANGE=9, IKEv2_TS_SECLABEL=10 }

user_defined_types: enum ikev2_cp_attribute_type { IKEv2_CP_ATTR_RESERVED=0, IKEv2_INTERNAL_IP4_ADDRESS=1, IKEv2_INTERNAL_IP4_NETMASK=2, IKEv2_INTERNAL_IP4_DNS=3, IKEv2_INTERNAL_IP4_NBNS=4, IKEv2_RESERVED_5=5, IKEv2_INTERNAL_IP4_DHCP=6, IKEv2_APPLICATION_VERSION=7, IKEv2_INTERNAL_IP6_ADDRESS=8, IKEv2_RESERVED_9=9, IKEv2_INTERNAL_IP6_DNS=10, IKEv2_RESERVED_11=11, IKEv2_INTERNAL_IP6_DHCP=12, IKEv2_INTERNAL_IP4_SUBNET=13, IKEv2_SUPPORTED_ATTRIBUTES=14, IKEv2_INTERNAL_IP6_SUBNET=15, IKEv2_MIP6_HOME_PREFIX=16, IKEv2_INTERNAL_IP6_LINK=17, IKEv2_INTERNAL_IP6_PREFIX=18, IKEv2_HOME_AGENT_ADDRESS=19, IKEv2_P_CSCF_IP4_ADDRESS=20, IKEv2_P_CSCF_IP6_ADDRESS=21, IKEv2_FTT_KAT=22, IKEv2_EXTERNAL_SOURCE_IP4_NAT_INFO=23, IKEv2_TIMEOUT_PERIOD_FOR_LIVENESS_CHECK=24, IKEv2_INTERNAL_DNS_DOMAIN=25, IKEv2_INTERNAL_DNSSEC_TA=26 }

user_defined_types: enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 }

user_defined_types: struct ip_bytes { unsigned char byte[16]; }

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

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


decompiled_code:
__int64 __fastcall str_said(const __m128i *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
_QWORD v7[9]; // [rsp+0h] [rbp-48h] BYREF

v7[5] = __readfsqword(0x28u);
array_as_jambuf(v7, a2, 72LL);
jam_said((__int64)v7, a1, v2, v3, v4, v5);
return a2;
}

original_code:
const char *str_said(const ip_said *said, said_buf *buf)
{
 struct jambuf b = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_said(&b, said);
 return buf->buf;
}

canonical_original_code:
char *str_said(struct ip_said *said, struct said_buf *buf)
{
 struct jambuf b = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_said(&b, said);
 return buf->buf;
}

variable_types:
buf
struct said_buf { char buf[-1]; } *

user_defined_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; }


decompiled_code:
unsigned __int64 __fastcall unpack_nonce(__m128i *a1, __m128i *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
free_chunk_content();
*a1 = _mm_loadu_si128(a2);
*a2 = _mm_loadu_si128(&empty_chunk);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__m128i *a1, __m128i *a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
free_chunk_content();
*a1 = _mm_loadu_si128(a2);
*a2 = _mm_loadu_si128(&empty_chunk);
return v3 - __readfsqword(0x28u);
}

original_code:
void unpack_nonce(chunk_t *n, chunk_t *nonce)
{
 free_chunk_content(n);
 *n = *nonce;
 *nonce = empty_chunk;
}

canonical_original_code:
void unpack_nonce(struct chunk_t *n, struct chunk_t *nonce)
{
 free_chunk_content(n);
 *n = *nonce;
 *nonce = empty_chunk;
}

variable_types: struct chunk_t { unsigned char *ptr; unsigned long len; } *

variable_types:
nonce
struct chunk_t *


trydotted

decompiled_code:
const char *__fastcall trydotted(__int64 a1, __int64 a2, __m128i *a3)
{
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rdi
const char *result; // rax
unsigned __int64 v8; // rax
unsigned int v9; // edx
__m128i v10; // [rsp+0h] [rbp-88h] BYREF
__int64 v11; // [rsp+10h] [rbp-78h]
unsigned __int64 v12; // [rsp+28h] [rbp-60h] BYREF
__int64 v13; // [rsp+30h] [rbp-58h] BYREF
__int64 v14; // [rsp+38h] [rbp-50h]
__m128i v15; // [rsp+40h] [rbp-48h]
unsigned __int64 v16; // [rsp+58h] [rbp-30h]

v16 = __readfsqword(0x28u);
v15 = _mm_loadu_si128(&unset_ip_bytes);
v13 = a1;
v14 = a2;
v4 = 0LL;
while ( v13 )
{
v6 = shunk_token(&v13, 0LL, ".");
if ( !v5 )
return "empty dotted-numeric address field";
result = (const char *)shunk_to_uintmax(v6, v5, 0LL, 0LL, &v12);
if ( result )
return result;
if ( !v14 && (_DWORD)v4 )
{
if ( (unsigned int)v4 > 3 )
{
LABEL_16:
result = "overflow in dotted-numeric address";
if ( v12 )
return result;
}
else
{
v8 = v12;
v9 = 3;
while ( v8 )
{
v15.m128i_i8[v9] = v8;
v8 >>= 8;
if ( (unsigned int)v4 > --v9 )
{
v12 = v8;
goto LABEL_16;
}
}
}
LABEL_9:
result = "garbage at end of dotted-address";
if ( v13 )
return result;
break;
}
if ( v12 > 0xFF )
return "byte overflow in dotted-numeric address";
v15.m128i_i8[v4++] = v12;
if ( v4 == 4 )
goto LABEL_9;
}
address_from_raw(&v10, here_1, ip_families[0], v15.m128i_i64[0], v15.m128i_i64[1]);
*a3 = _mm_loadu_si128(&v10);
a3[1].m128i_i64[0] = v11;
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1, __int64 a2, __m128i *a3)
{
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rdi
const char *result; // rax
unsigned __int64 v8; // rax
unsigned int v9; // edx
__m128i v10; // [rsp+0h] [rbp-88h] BYREF
__int64 v11; // [rsp+10h] [rbp-78h]
unsigned __int64 v12; // [rsp+28h] [rbp-60h] BYREF
__int64 v13; // [rsp+30h] [rbp-58h] BYREF
__int64 v14; // [rsp+38h] [rbp-50h]
__m128i v15; // [rsp+40h] [rbp-48h]
unsigned __int64 v16; // [rsp+58h] [rbp-30h]

v16 = __readfsqword(0x28u);
v15 = _mm_loadu_si128(&unset_ip_bytes);
v13 = a1;
v14 = a2;
v4 = 0LL;
while ( v13 )
{
v6 = shunk_token(&v13, 0LL, ".");
if ( !v5 )
return "empty dotted-numeric address field";
result = (const char *)shunk_to_uintmax(v6, v5, 0LL, 0LL, &v12);
if ( result )
return result;
if ( !v14 && (_DWORD)v4 )
{
if ( (unsigned int)v4 > 3 )
{
LABEL_16:
result = "overflow in dotted-numeric address";
if ( v12 )
return result;
}
else
{
v8 = v12;
v9 = 3;
while ( v8 )
{
v15.m128i_i8[v9] = v8;
v8 >>= 8;
if ( (unsigned int)v4 > --v9 )
{
v12 = v8;
goto LABEL_16;
}
}
}
LABEL_9:
result = "garbage at end of dotted-address";
if ( v13 )
return result;
break;
}
if ( v12 > 0xFF )
return "byte overflow in dotted-numeric address";
v15.m128i_i8[v4++] = v12;
if ( v4 == 4 )
goto LABEL_9;
}
address_from_raw(&v10, here_1, ip_families[0], v15.m128i_i64[0], v15.m128i_i64[1]);
*a3 = _mm_loadu_si128(&v10);
a3[1].m128i_i64[0] = v11;
return 0LL;
}

original_code:
static err_t trydotted(shunk_t src, ip_address *dst)
{
 struct ip_bytes bytes = unset_ip_bytes;
 shunk_t cursor = src;
 for (unsigned b = 0; b < 4 && cursor.ptr != ((void *)0) ; b++) {
  shunk_t token = shunk_token(&cursor, ((void *)0), ".");
  if (token.len == 0) {
   return "empty dotted-numeric address field";
  }
  uintmax_t byte;
  err_t err = shunk_to_uintmax(token, ((void *)0), 0, &byte);
  if (err != ((void *)0)) {
   return err;
  }
  if (cursor.len == 0 && b > 0) {
   for (unsigned e = 3; e >= b && byte != 0; e--) {
    bytes.byte[e] = byte;
    byte = byte >> 8;
   }
   if (byte != 0) {
    return "overflow in dotted-numeric address";
   }
   break;
  }
  if (byte > (255)) {
   return "byte overflow in dotted-numeric address";
  }
  bytes.byte[b] = byte;
 }
 if (cursor.ptr != ((void *)0)) {
  return "garbage at end of dotted-address";
 }
 *dst = address_from_raw(({ static const struct where here = { .func = __func__, .file = "lib/libswan/ttoaddress_num.c", .line = 224, }; &here; }), ip_families[IPv4_INDEX].ip_version, bytes);
 return ((void *)0);
}

canonical_original_code:
static char *trydotted(struct shunk src, struct ip_address *dst)
{
 struct ip_bytes bytes = unset_ip_bytes;
 struct shunk cursor = src;
 for (unsigned int b = 0; b < 4 && cursor.ptr != ((void *)0) ; b++) {
  struct shunk token = shunk_token(&cursor, ((void *)0), ".");
  if (token.len == 0) {
   return "empty dotted-numeric address field";
  }
  unsigned long byte;
  char *err = shunk_to_uintmax(token, ((void *)0), 0, &byte);
  if (err != ((void *)0)) {
   return err;
  }
  if (cursor.len == 0 && b > 0) {
   for (unsigned int e = 3; e >= b && byte != 0; e--) {
    bytes.byte[e] = byte;
    byte = byte >> 8;
   }
   if (byte != 0) {
    return "overflow in dotted-numeric address";
   }
   break;
  }
  if (byte > (255)) {
   return "byte overflow in dotted-numeric address";
  }
  bytes.byte[b] = byte;
 }
 if (cursor.ptr != ((void *)0)) {
  return "garbage at end of dotted-address";
 }
 *dst = address_from_raw(({ static struct where here = { .func = __func__, .file = "lib/libswan/ttoaddress_num.c", .line = 224, }; &here; }), ip_families[IPv4_INDEX].ip_version, bytes);
 return ((void *)0);
}

variable_types: struct shunk { void *ptr; unsigned long len; }

variable_types: struct ip_address { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes { unsigned char byte[16]; } bytes; } *

variable_types:
b
unsigned int

variable_types:
byte
unsigned long

variable_types:
err
char *

variable_types:
e
unsigned int

variable_types: struct where { char *func; char *file; long line; }

user_defined_types: struct ip_address { _Bool is_set; enum ip_version version; struct ip_bytes bytes; }


decompiled_code:
_BOOL8 __fastcall lmod_empty(__int128 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int128 a1)
{
return a1 == 0;
}

original_code:
_Bool lmod_empty(lmod_t mod)
{
 return mod.set == ((lset_t)0) && mod.clr == ((lset_t)0);
}

canonical_original_code:
_Bool lmod_empty(struct lmod_t mod)
{
 return mod.set == ((unsigned long)0) && mod.clr == ((unsigned long)0);
}

variable_types: struct lmod_t { unsigned long set; unsigned long clr; }


decompiled_code:
unsigned __int64 __fastcall lmod_merge(__int64 *a1, __int64 a2, __int64 a3)
{
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*a1 = a2 | *a1 & ~a3;
a1[1] = a3 | a1[1] & ~a2;
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 *a1, __int64 a2, __int64 a3)
{
unsigned __int64 v4; // [rsp+8h] [rbp-10h]

v4 = __readfsqword(0x28u);
*a1 = a2 | *a1 & ~a3;
a1[1] = a3 | a1[1] & ~a2;
return v4 - __readfsqword(0x28u);
}

original_code:
void lmod_merge(lmod_t *lhs, lmod_t rhs)
{
 lhs->set = (lhs->set & ~rhs.clr) | rhs.set;
 lhs->clr = (lhs->clr & ~rhs.set) | rhs.clr;
}

canonical_original_code:
void lmod_merge(struct lmod_t *lhs, struct lmod_t rhs)
{
 lhs->set = (lhs->set & ~rhs.clr) | rhs.set;
 lhs->clr = (lhs->clr & ~rhs.set) | rhs.clr;
}

variable_types: struct lmod_t { unsigned long set; unsigned long clr; } *

variable_types:
rhs
struct lmod_t


lmod

decompiled_code:
__int64 __fastcall lmod(__int64 a1, __int64 a2, __int64 a3)
{
return a2 | a1 & ~a3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
return a2 | a1 & ~a3;
}

original_code:
lset_t lmod(lset_t set, lmod_t mod)
{
 return (set & ~mod.clr ) | mod.set;
}

canonical_original_code:
unsigned long lmod(unsigned long set, struct lmod_t mod)
{
 return (set & ~mod.clr ) | mod.set;
}

variable_types:
set
unsigned long

user_defined_types: struct lmod_t { unsigned long set; unsigned long clr; }


decompiled_code:
__int64 __fastcall lmod_set(__int64 a1, __int64 a2, __int64 a3)
{
return a1 | a3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
return a1 | a3;
}

original_code:
lmod_t lmod_set(lmod_t mod, lset_t set)
{
 mod.set |= set;
 mod.clr &= ~set;
 return mod;
}

canonical_original_code:
struct lmod_t lmod_set(struct lmod_t mod, unsigned long set)
{
 mod.set |= set;
 mod.clr &= ~set;
 return mod;
}

variable_types:
mod
struct lmod_t

return_type: struct lmod_t { unsigned long set; unsigned long clr; }


decompiled_code:
__int64 __fastcall lmod_clr(__int64 a1, __int64 a2, __int64 a3)
{
return a1 & ~a3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
return a1 & ~a3;
}

original_code:
lmod_t lmod_clr(lmod_t mod, lset_t clr)
{
 mod.clr |= clr;
 mod.set &= ~clr;
 return mod;
}

canonical_original_code:
struct lmod_t lmod_clr(struct lmod_t mod, unsigned long clr)
{
 mod.clr |= clr;
 mod.set &= ~clr;
 return mod;
}

variable_types:
clr
unsigned long


decompiled_code:
_BOOL8 __fastcall lmod_is_set(__int64 a1, __int64 a2, __int64 a3)
{
return (a3 & a1) == a3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
return (a3 & a1) == a3;
}

original_code:
_Bool lmod_is_set(lmod_t mod, lset_t set)
{
 return (((set) & (mod.set)) == (set));
}

canonical_original_code:
_Bool lmod_is_set(struct lmod_t mod, unsigned long set)
{
 return (((set) & (mod.set)) == (set));
}


decompiled_code:
_BOOL8 __fastcall lmod_is_clr(__int64 a1, __int64 a2, __int64 a3)
{
return (a3 & a2) == a3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
return (a3 & a2) == a3;
}

original_code:
_Bool lmod_is_clr(lmod_t mod, lset_t clr)
{
 return (((clr) & (mod.clr)) == (clr));
}

canonical_original_code:
_Bool lmod_is_clr(struct lmod_t mod, unsigned long clr)
{
 return (((clr) & (mod.clr)) == (clr));
}


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

result = impair[4];
if ( !(_DWORD)result )
result = *(unsigned int *)(a1 + 40);
return result;
}

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

result = impair[4];
if ( !(_DWORD)result )
result = *(unsigned int *)(a1 + 40);
return result;
}

original_code:
static unsigned log_limit(const struct log_limiter *limiter)
{
 if (impair.log_rate_limit == 0) {
  return limiter->limit;
 } else {
  return impair.log_rate_limit;
 }
}

canonical_original_code:
static unsigned int log_limit(struct log_limiter *limiter)
{
 if (impair.log_rate_limit == 0) {
  return limiter->limit;
 } else {
  return impair.log_rate_limit;
 }
}

variable_types: struct log_limiter { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned int limit; unsigned int count; char *what; } *

return_type: unsigned int

user_defined_types: struct log_limiter { union pthread_mutex_t mutex; unsigned int limit; unsigned int count; char *what; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
unsigned __int64 init_log_limiter()
{
__int64 v1; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v2; // [rsp+18h] [rbp-10h]

v2 = __readfsqword(0x28u);
deltatime(&v1, 3600LL);
enable_periodic_timer(7LL, reset_log_limiter);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func4()
{
__int64 v1; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v2; // [rsp+18h] [rbp-10h]

v2 = __readfsqword(0x28u);
deltatime(&v1, 3600LL);
enable_periodic_timer(7LL, reset_log_limiter);
return v2 - __readfsqword(0x28u);
}

original_code:
void init_log_limiter(void)
{
 enable_periodic_timer(EVENT_RESET_LOG_LIMITER,
         reset_log_limiter,
         deltatime(secs_per_hour));
}

canonical_original_code:
void init_log_limiter()
{
 enable_periodic_timer(EVENT_RESET_LOG_LIMITER,
         reset_log_limiter,
         deltatime(secs_per_hour));
}


original_code:
static size_t jam_lset_pretty(struct jambuf *buf, enum_names *en, lset_t val,
         const char *separator, _Bool shorten)
{
 if (val == ((lset_t)0)) {
  return jam(buf, "none");
 }
 size_t s = 0;
 const char *sep = "";
 const struct enum_names *range = ((void *)0);
 const char *prefix = ((void *)0);
 for (unsigned e = 0; val != 0; e++) {
  lset_t bit = ((lset_t)1 << (e));
  if (val & bit) {
   if (range == ((void *)0) || e > range->en_last) {
    range = enum_range(en, e, &prefix);
   }
   s += jam_string(buf, sep);
   sep = separator;
   const char *name = enum_range_name(range, e, prefix, shorten);
   if (name == ((void *)0)) {
    s += jam(buf, "0x" "%""l" "x", bit);
   } else {
    s += jam_string(buf, name);
   }
  }
  val &= ~bit;
 }
 return s;
}

canonical_original_code:
static unsigned long jam_lset_pretty(struct jambuf *buf, struct enum_names *en, unsigned long val, char *separator, _Bool shorten)
{
 if (val == ((unsigned long)0)) {
  return jam(buf, "none");
 }
 unsigned long s = 0;
 char *sep = "";
 struct enum_names *range = ((void *)0);
 char *prefix = ((void *)0);
 for (unsigned int e = 0; val != 0; e++) {
  unsigned long bit = ((lset_t)1 << (e));
  if (val & bit) {
   if (range == ((void *)0) || e > range->en_last) {
    range = enum_range(en, e, &prefix);
   }
   s += jam_string(buf, sep);
   sep = separator;
   char *name = enum_range_name(range, e, prefix, shorten);
   if (name == ((void *)0)) {
    s += jam(buf, "0x" "%""l" "x", bit);
   } else {
    s += jam_string(buf, name);
   }
  }
  val &= ~bit;
 }
 return s;
}

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *

variable_types: struct enum_names { unsigned long en_first; unsigned long en_last; char **en_names; unsigned long en_checklen; char *en_prefix; struct enum_names *en_next_range; } *

variable_types:
val
unsigned long

variable_types:
separator
char *

variable_types:
s
unsigned long

variable_types:
sep
char *

variable_types:
prefix
char *

variable_types:
bit
unsigned long

variable_types:
name
char *


decompiled_code:
__int64 __fastcall test_lset(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // er12
__int64 v4; // rbx

if ( !a2 )
return 1LL;
v2 = a2;
v3 = 0;
do
{
v4 = 1LL << v3;
if ( (v2 & (1LL << v3)) != 0 && !enum_name(a1, v3) )
return 0LL;
++v3;
v2 &= ~v4;
}
while ( v2 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // er12
__int64 v4; // rbx

if ( !a2 )
return 1LL;
v2 = a2;
v3 = 0;
do
{
v4 = 1LL << v3;
if ( (v2 & (1LL << v3)) != 0 && !enum_name(a1, v3) )
return 0LL;
++v3;
v2 &= ~v4;
}
while ( v2 );
return 1LL;
}

original_code:
_Bool test_lset(const struct enum_names *en, lset_t val)
{
 for (unsigned e = 0; val != 0; e++) {
  lset_t bit = ((lset_t)1 << (e));
  if (val & bit) {
   const char *n = enum_name(en, e);
   if (n == ((void *)0)) {
    return 0;
   }
  }
  val &= ~bit;
 }
 return 1;
}

canonical_original_code:
_Bool test_lset(struct enum_names *en, unsigned long val)
{
 for (unsigned int e = 0; val != 0; e++) {
  unsigned long bit = ((lset_t)1 << (e));
  if (val & bit) {
   char *n = enum_name(en, e);
   if (n == ((void *)0)) {
    return 0;
   }
  }
  val &= ~bit;
 }
 return 1;
}

variable_types:
e
unsigned int

variable_types:
n
char *

user_defined_types: struct enum_names { unsigned long en_first; unsigned long en_last; char **en_names; unsigned long en_checklen; char *en_prefix; struct enum_names *en_next_range; }


decompiled_code:
__int64 __fastcall jam_lset(__int64 a1, __int64 a2, __int64 a3)
{
return jam_lset_pretty(a1, a2, a3, "+", 0);
}

original_code:
size_t jam_lset(struct jambuf *buf, enum_names *en, lset_t val)
{
 return jam_lset_pretty(buf, en, val, "+", 0);
}

canonical_original_code:
unsigned long jam_lset(struct jambuf *buf, struct enum_names *en, unsigned long val)
{
 return jam_lset_pretty(buf, en, val, "+", 0);
}


decompiled_code:
__int64 __fastcall str_lset(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD v5[11]; // [rsp+0h] [rbp-58h] BYREF

v5[5] = __readfsqword(0x28u);
array_as_jambuf(v5, a3, 512LL);
jam_lset((__int64)v5, a1, a2);
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD v5[11]; // [rsp+0h] [rbp-58h] BYREF

v5[5] = __readfsqword(0x28u);
array_as_jambuf(v5, a3, 512LL);
func2((__int64)v5, a1, a2);
return a3;
}

original_code:
const char *str_lset(enum_names *en, lset_t val, lset_buf *out)
{
 struct jambuf buf = array_as_jambuf((out->buf), sizeof(out->buf));
 jam_lset(&buf, en, val);
 return out->buf;
}

canonical_original_code:
char *str_lset(struct enum_names *en, unsigned long val, struct lset_buf *out)
{
 struct jambuf buf = array_as_jambuf((out->buf), sizeof(out->buf));
 jam_lset(&buf, en, val);
 return out->buf;
}

variable_types:
out
struct lset_buf { char buf[512]; } *

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; }


decompiled_code:
__int64 __fastcall jam_lset_short(__int64 a1, __int64 a2, void *a3, __int64 a4)
{
return jam_lset_pretty(a1, a2, a4, a3, 1u);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, void *a3, __int64 a4)
{
return func0(a1, a2, a4, a3, 1u);
}

original_code:
size_t jam_lset_short(struct jambuf *buf, enum_names *en,
        const char *separator, lset_t val)
{
 return jam_lset_pretty(buf, en, val, separator, 1);
}

canonical_original_code:
unsigned long jam_lset_short(struct jambuf *buf, struct enum_names *en, char *separator, unsigned long val)
{
 return jam_lset_pretty(buf, en, val, separator, 1);
}


decompiled_code:
__int64 __fastcall str_lset_short(__int64 a1, void *a2, __int64 a3, __int64 a4)
{
_QWORD v7[11]; // [rsp+0h] [rbp-58h] BYREF

v7[5] = __readfsqword(0x28u);
array_as_jambuf(v7, a4, 512LL);
jam_lset_short((__int64)v7, a1, a2, a3);
return a4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, void *a2, __int64 a3, __int64 a4)
{
_QWORD v7[11]; // [rsp+0h] [rbp-58h] BYREF

v7[5] = __readfsqword(0x28u);
array_as_jambuf(v7, a4, 512LL);
func4((__int64)v7, a1, a2, a3);
return a4;
}

original_code:
const char *str_lset_short(enum_names *en, const char *separator,
      lset_t val, lset_buf *out)
{
 struct jambuf buf = array_as_jambuf((out->buf), sizeof(out->buf));
 jam_lset_short(&buf, en, separator, val);
 return out->buf;
}

canonical_original_code:
char *str_lset_short(struct enum_names *en, char *separator, unsigned long val, struct lset_buf *out)
{
 struct jambuf buf = array_as_jambuf((out->buf), sizeof(out->buf));
 jam_lset_short(&buf, en, separator, val);
 return out->buf;
}


original_code:
size_t jam_sparse_lset(struct jambuf *buf, const struct sparse_name *sd, lset_t val)
{
 if (val == ((lset_t)0)) {
  return jam(buf, "none");
 }
 size_t s = 0;
 const char *sep = "";
 for (unsigned e = 0; val != 0; e++) {
  lset_t bit = ((lset_t)1 << (e));
  if (val & bit) {
   s += jam_string(buf, sep);
   sep = "+";
   const char *name = sparse_name(sd, bit);
   if (name == ((void *)0)) {
    s += jam(buf, "0x" "%""l" "x", bit);
   } else {
    s += jam_string(buf, name);
   }
  }
  val &= ~bit;
 }
 return s;
}

canonical_original_code:
unsigned long jam_sparse_lset(struct jambuf *buf, struct sparse_name *sd, unsigned long val)
{
 if (val == ((unsigned long)0)) {
  return jam(buf, "none");
 }
 unsigned long s = 0;
 char *sep = "";
 for (unsigned int e = 0; val != 0; e++) {
  unsigned long bit = ((lset_t)1 << (e));
  if (val & bit) {
   s += jam_string(buf, sep);
   sep = "+";
   char *name = sparse_name(sd, bit);
   if (name == ((void *)0)) {
    s += jam(buf, "0x" "%""l" "x", bit);
   } else {
    s += jam_string(buf, name);
   }
  }
  val &= ~bit;
 }
 return s;
}

variable_types: struct sparse_name { char *name; unsigned long value; } *


original_code:
static size_t jam_ipv4_endpoint(struct jambuf *buf, const struct ip_info *afi,
    const struct ip_bytes *bytes, unsigned hport)
{
 size_t s = 0;
 s += afi->address.jam(buf, afi, bytes);
 s += jam(buf, ":%u", hport);
 return s;
}

canonical_original_code:
static unsigned long jam_ipv4_endpoint(struct jambuf *buf, struct ip_info *afi, struct ip_bytes *bytes, unsigned int hport)
{
 unsigned long s = 0;
 s += afi->address.jam(buf, afi, bytes);
 s += jam(buf, ":%u", hport);
 return s;
}

variable_types: struct ip_info { enum ip_version { IPv4=4, IPv6=6 } ip_version; enum ip_index { IPv4_INDEX=0, IPv6_INDEX=1 } ip_index; char *ip_name; unsigned long ip_size; unsigned int mask_cnt; struct { struct ip_address { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes { unsigned char byte[16]; } bytes; } unspec; struct ip_address loopback; unsigned long (*jam)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes); unsigned long (*jam_wrapped)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes); } address; struct { unsigned long (*jam)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes, unsigned int hport); } endpoint; struct { struct ip_subnet { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes bytes; unsigned int maskbits; } zero; struct ip_subnet all; } subnet; struct { struct ip_range { _Bool is_set; _Bool is_subnet; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes start; struct ip_bytes end; } zero; struct ip_range all; } range; struct { struct ip_selector { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes bytes; unsigned int maskbits; unsigned int ipproto; int hport; } zero; struct ip_selector all; } selector; unsigned int ikev1_max_fragment_size; unsigned int ikev2_max_fragment_size; struct { int domain; char *domain_name; } socket; int af; char *af_name; unsigned long sockaddr_size; struct ip_address (*address_from_sockaddr)(struct ip_sockaddr { unsigned int len; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } sa; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } sa; } sa); struct ip_port { unsigned int hport; } (*port_from_sockaddr)(struct ip_sockaddr sa); enum ikev2_ts_type { IKEv2_TS_IPV4_ADDR_RANGE=7, IKEv2_TS_IPV6_ADDR_RANGE=8, IKEv2_TS_FC_ADDR_RANGE=9, IKEv2_TS_SECLABEL=10 } ikev2_ts_addr_range_type; enum ikev2_cp_attribute_type { IKEv2_CP_ATTR_RESERVED=0, IKEv2_INTERNAL_IP4_ADDRESS=1, IKEv2_INTERNAL_IP4_NETMASK=2, IKEv2_INTERNAL_IP4_DNS=3, IKEv2_INTERNAL_IP4_NBNS=4, IKEv2_RESERVED_5=5, IKEv2_INTERNAL_IP4_DHCP=6, IKEv2_APPLICATION_VERSION=7, IKEv2_INTERNAL_IP6_ADDRESS=8, IKEv2_RESERVED_9=9, IKEv2_INTERNAL_IP6_DNS=10, IKEv2_RESERVED_11=11, IKEv2_INTERNAL_IP6_DHCP=12, IKEv2_INTERNAL_IP4_SUBNET=13, IKEv2_SUPPORTED_ATTRIBUTES=14, IKEv2_INTERNAL_IP6_SUBNET=15, IKEv2_MIP6_HOME_PREFIX=16, IKEv2_INTERNAL_IP6_LINK=17, IKEv2_INTERNAL_IP6_PREFIX=18, IKEv2_HOME_AGENT_ADDRESS=19, IKEv2_P_CSCF_IP4_ADDRESS=20, IKEv2_P_CSCF_IP6_ADDRESS=21, IKEv2_FTT_KAT=22, IKEv2_EXTERNAL_SOURCE_IP4_NAT_INFO=23, IKEv2_TIMEOUT_PERIOD_FOR_LIVENESS_CHECK=24, IKEv2_INTERNAL_DNS_DOMAIN=25, IKEv2_INTERNAL_DNSSEC_TA=26 } ikev2_internal_address; enum ikev2_cp_attribute_type { IKEv2_CP_ATTR_RESERVED=0, IKEv2_INTERNAL_IP4_ADDRESS=1, IKEv2_INTERNAL_IP4_NETMASK=2, IKEv2_INTERNAL_IP4_DNS=3, IKEv2_INTERNAL_IP4_NBNS=4, IKEv2_RESERVED_5=5, IKEv2_INTERNAL_IP4_DHCP=6, IKEv2_APPLICATION_VERSION=7, IKEv2_INTERNAL_IP6_ADDRESS=8, IKEv2_RESERVED_9=9, IKEv2_INTERNAL_IP6_DNS=10, IKEv2_RESERVED_11=11, IKEv2_INTERNAL_IP6_DHCP=12, IKEv2_INTERNAL_IP4_SUBNET=13, IKEv2_SUPPORTED_ATTRIBUTES=14, IKEv2_INTERNAL_IP6_SUBNET=15, IKEv2_MIP6_HOME_PREFIX=16, IKEv2_INTERNAL_IP6_LINK=17, IKEv2_INTERNAL_IP6_PREFIX=18, IKEv2_HOME_AGENT_ADDRESS=19, IKEv2_P_CSCF_IP4_ADDRESS=20, IKEv2_P_CSCF_IP6_ADDRESS=21, IKEv2_FTT_KAT=22, IKEv2_EXTERNAL_SOURCE_IP4_NAT_INFO=23, IKEv2_TIMEOUT_PERIOD_FOR_LIVENESS_CHECK=24, IKEv2_INTERNAL_DNS_DOMAIN=25, IKEv2_INTERNAL_DNSSEC_TA=26 } ikev2_internal_dns; enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 } id_ip_addr; enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 } id_ip_addr_subnet; enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 } id_ip_addr_range; } *

variable_types:
bytes
struct ip_bytes *

variable_types:
hport
unsigned int

user_defined_types: struct ip_info { enum ip_version ip_version; enum ip_index ip_index; char *ip_name; unsigned long ip_size; unsigned int mask_cnt; struct { struct ip_address unspec; struct ip_address loopback; unsigned long (*jam)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes); unsigned long (*jam_wrapped)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes); } address; struct { unsigned long (*jam)(struct jambuf *buf, struct ip_info *info, struct ip_bytes *bytes, unsigned int hport); } endpoint; struct { struct ip_subnet zero; struct ip_subnet all; } subnet; struct { struct ip_range zero; struct ip_range all; } range; struct { struct ip_selector zero; struct ip_selector all; } selector; unsigned int ikev1_max_fragment_size; unsigned int ikev2_max_fragment_size; struct { int domain; char *domain_name; } socket; int af; char *af_name; unsigned long sockaddr_size; struct ip_address (*address_from_sockaddr)(struct ip_sockaddr sa); struct ip_port (*port_from_sockaddr)(struct ip_sockaddr sa); enum ikev2_ts_type ikev2_ts_addr_range_type; enum ikev2_cp_attribute_type ikev2_internal_address; enum ikev2_cp_attribute_type ikev2_internal_dns; enum ike_id_type id_ip_addr; enum ike_id_type id_ip_addr_subnet; enum ike_id_type id_ip_addr_range; }

user_defined_types: struct ip_subnet { _Bool is_set; enum ip_version version; struct ip_bytes bytes; unsigned int maskbits; }

user_defined_types: struct ip_range { _Bool is_set; _Bool is_subnet; enum ip_version version; struct ip_bytes start; struct ip_bytes end; }

user_defined_types: struct ip_selector { _Bool is_set; enum ip_version version; struct ip_bytes bytes; unsigned int maskbits; unsigned int ipproto; int hport; }

user_defined_types: struct ip_sockaddr { unsigned int len; union { struct sockaddr sa; struct sockaddr_in sin; struct sockaddr_in6 sin6; } sa; }


decompiled_code:
__int64 __fastcall jam_ipv4_address(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp
unsigned __int64 v5; // rbx
const char *v6; // rdx

v3 = *(_QWORD *)(a2 + 16);
if ( v3 )
{
v5 = 0LL;
v3 = 0LL;
v6 = (const char *)&LC4;
do
{
v3 += jam(a1, "%s%u", v6, *(unsigned __int8 *)(a3 + v5++));
v6 = ".";
}
while ( *(_QWORD *)(a2 + 16) > v5 );
}
return v3;
}

original_code:
static size_t jam_ipv4_address(struct jambuf *buf, const struct ip_info *afi, const struct ip_bytes *bytes)
{
 const char *sep = "";
 size_t s = 0;
 for (size_t i = 0; i < afi->ip_size; i++) {
  s += jam(buf, "%s%""u", sep, bytes->byte[i]);
  sep = ".";
 }
 return s;
}

canonical_original_code:
static unsigned long jam_ipv4_address(struct jambuf *buf, struct ip_info *afi, struct ip_bytes *bytes)
{
 char *sep = "";
 unsigned long s = 0;
 for (unsigned long i = 0; i < afi->ip_size; i++) {
  s += jam(buf, "%s%""u", sep, bytes->byte[i]);
  sep = ".";
 }
 return s;
}

variable_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *

variable_types:
i
unsigned long

user_defined_types: enum ip_index { IPv4_INDEX=0, IPv6_INDEX=1 }

user_defined_types: enum ikev2_ts_type { IKEv2_TS_IPV4_ADDR_RANGE=7, IKEv2_TS_IPV6_ADDR_RANGE=8, IKEv2_TS_FC_ADDR_RANGE=9, IKEv2_TS_SECLABEL=10 }

user_defined_types: enum ikev2_cp_attribute_type { IKEv2_CP_ATTR_RESERVED=0, IKEv2_INTERNAL_IP4_ADDRESS=1, IKEv2_INTERNAL_IP4_NETMASK=2, IKEv2_INTERNAL_IP4_DNS=3, IKEv2_INTERNAL_IP4_NBNS=4, IKEv2_RESERVED_5=5, IKEv2_INTERNAL_IP4_DHCP=6, IKEv2_APPLICATION_VERSION=7, IKEv2_INTERNAL_IP6_ADDRESS=8, IKEv2_RESERVED_9=9, IKEv2_INTERNAL_IP6_DNS=10, IKEv2_RESERVED_11=11, IKEv2_INTERNAL_IP6_DHCP=12, IKEv2_INTERNAL_IP4_SUBNET=13, IKEv2_SUPPORTED_ATTRIBUTES=14, IKEv2_INTERNAL_IP6_SUBNET=15, IKEv2_MIP6_HOME_PREFIX=16, IKEv2_INTERNAL_IP6_LINK=17, IKEv2_INTERNAL_IP6_PREFIX=18, IKEv2_HOME_AGENT_ADDRESS=19, IKEv2_P_CSCF_IP4_ADDRESS=20, IKEv2_P_CSCF_IP6_ADDRESS=21, IKEv2_FTT_KAT=22, IKEv2_EXTERNAL_SOURCE_IP4_NAT_INFO=23, IKEv2_TIMEOUT_PERIOD_FOR_LIVENESS_CHECK=24, IKEv2_INTERNAL_DNS_DOMAIN=25, IKEv2_INTERNAL_DNSSEC_TA=26 }

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

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


original_code:
static size_t jam_ipv6_address(struct jambuf *buf, const struct ip_info *afi, const struct ip_bytes *bytes)
{
 size_t s = 0;
 shunk_t zeros = zeros_to_skip(afi, bytes);
 const char *sep = "";
 const uint8_t *ptr = bytes->byte;
 const uint8_t *last = ptr + afi->ip_size - 2;
 while (ptr <= last) {
  if (ptr == zeros.ptr) {
   s += jam(buf, "::");
   sep = "";
   ptr += zeros.len;
  } else {
   unsigned ia = (ptr[0] << 8) + ptr[1];
   s += jam(buf, "%s%x", sep, ia);
   sep = ":";
   ptr += 2;
  }
 }
 return s;
}

canonical_original_code:
static unsigned long jam_ipv6_address(struct jambuf *buf, struct ip_info *afi, struct ip_bytes *bytes)
{
 unsigned long s = 0;
 struct shunk zeros = zeros_to_skip(afi, bytes);
 char *sep = "";
 unsigned char *ptr = bytes->byte;
 unsigned char *last = ptr + afi->ip_size - 2;
 while (ptr <= last) {
  if (ptr == zeros.ptr) {
   s += jam(buf, "::");
   sep = "";
   ptr += zeros.len;
  } else {
   unsigned int ia = (ptr[0] << 8) + ptr[1];
   s += jam(buf, "%s%x", sep, ia);
   sep = ":";
   ptr += 2;
  }
 }
 return s;
}

variable_types: struct shunk { void *ptr; unsigned long len; }

variable_types:
ptr
unsigned char *

variable_types:
last
unsigned char *

variable_types:
ia
unsigned int

user_defined_types: struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; }

user_defined_types: enum ike_id_type { ID_FROMCERT=-1, ID_NONE=0, ID_IPV4_ADDR=1, ID_FQDN=2, ID_USER_FQDN=3, ID_RFC822_ADDR=expr, ID_IPV4_ADDR_SUBNET=4, ID_IPV6_ADDR=5, ID_IPV6_ADDR_SUBNET=6, ID_IPV4_ADDR_RANGE=7, ID_IPV6_ADDR_RANGE=8, ID_DER_ASN1_DN=9, ID_DER_ASN1_GN=10, ID_KEY_ID=11, ID_FC_NAME=12, ID_NULL=13 }

user_defined_types: struct ip_bytes { unsigned char byte[16]; }

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

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


decompiled_code:
__int64 __fastcall jam_ipv6_address_wrapped(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // rbx

v4 = jam_string(a1, "[");
v5 = jam_ipv6_address(a1, a2, a3) + v4;
return v5 + jam_string(a1, "]");
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // rbx

v4 = jam_string(a1, "[");
v5 = func6(a1, a2, a3) + v4;
return v5 + jam_string(a1, "]");
}

original_code:
static size_t jam_ipv6_address_wrapped(struct jambuf *buf, const struct ip_info *afi, const struct ip_bytes *bytes)
{
 size_t s = 0;
 s += jam_string(buf, "[");
 s += jam_ipv6_address(buf, afi, bytes);
 s += jam_string(buf, "]");
 return s;
}

canonical_original_code:
static unsigned long jam_ipv6_address_wrapped(struct jambuf *buf, struct ip_info *afi, struct ip_bytes *bytes)
{
 unsigned long s = 0;
 s += jam_string(buf, "[");
 s += jam_ipv6_address(buf, afi, bytes);
 s += jam_string(buf, "]");
 return s;
}

variable_types:
s
unsigned long

user_defined_types: struct ip_address { _Bool is_set; enum ip_version version; struct ip_bytes bytes; }


decompiled_code:
__int64 __fastcall jam_ipv6_endpoint(__int64 a1, __int64 a2, unsigned __int64 a3, unsigned int a4)
{
__int64 v5; // rbx

v5 = jam_ipv6_address_wrapped(a1, a2, a3);
return v5 + jam(a1, ":%u", a4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned __int64 a3, unsigned int a4)
{
__int64 v5; // rbx

v5 = func7(a1, a2, a3);
return v5 + jam(a1, ":%u", a4);
}

original_code:
static size_t jam_ipv6_endpoint(struct jambuf *buf, const struct ip_info *afi,
    const struct ip_bytes *bytes, unsigned hport)
{
 size_t s = 0;
 s += jam_ipv6_address_wrapped(buf, afi, bytes);
 s += jam(buf, ":%u", hport);
 return s;
}

canonical_original_code:
static unsigned long jam_ipv6_endpoint(struct jambuf *buf, struct ip_info *afi, struct ip_bytes *bytes, unsigned int hport)
{
 unsigned long s = 0;
 s += jam_ipv6_address_wrapped(buf, afi, bytes);
 s += jam(buf, ":%u", hport);
 return s;
}


aftoinfo

decompiled_code:
char *__fastcall aftoinfo(int a1)
{
char *result; // rax

result = (char *)&ip_families;
if ( a1 != 2 )
{
result = (char *)&ip_families + 400;
if ( a1 != 10 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(int a1)
{
char *result; // rax

result = (char *)&ip_families;
if ( a1 != 2 )
{
result = (char *)&ip_families + 400;
if ( a1 != 10 )
result = 0LL;
}
return result;
}

original_code:
const struct ip_info *aftoinfo(int af)
{
 switch (af) {
 case 2:
  return &ip_families[IPv4_INDEX];
 case 10:
  return &ip_families[IPv6_INDEX];
 case 0:
  return ((void *)0);
 default:
  return ((void *)0);
 }
}

variable_types: af int


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

result = 0LL;
if ( !global_oco )
{
global_oco = clone_bytes(&LC1, 1LL, "rootdir");
qword_828 = clone_bytes("/etc", 5LL, "default conf ipsec_conf_dir");
qword_830 = clone_bytes("/etc/ipsec.conf", 16LL, "default conf conffile");
qword_838 = clone_bytes("/etc/ipsec.secrets", 19LL, "default ipsec.secrets");
qword_848 = clone_bytes("/var", 5LL, "default vardir");
qword_850 = clone_bytes("/etc/ipsec.d", 13LL, "default conf ipsecd_dir");
qword_880 = clone_bytes("/var/lib/ipsec/nss", 19LL, "default nssdir");
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( !global_oco )
{
global_oco = clone_bytes(&LC1, 1LL, "rootdir");
qword_828 = clone_bytes("/etc", 5LL, "default conf ipsec_conf_dir");
qword_830 = clone_bytes("/etc/ipsec.conf", 16LL, "default conf conffile");
qword_838 = clone_bytes("/etc/ipsec.secrets", 19LL, "default ipsec.secrets");
qword_848 = clone_bytes("/var", 5LL, "default vardir");
qword_850 = clone_bytes("/etc/ipsec.d", 13LL, "default conf ipsecd_dir");
qword_880 = clone_bytes("/var/lib/ipsec/nss", 19LL, "default nssdir");
result = 1LL;
}
return result;
}

original_code:
static _Bool lsw_conf_setdefault(void)
{
 if (global_oco.rootdir != ((void *)0)) {
  return 0;
 }
 global_oco.rootdir = (("") == ((void *)0) ? ((void *)0) : clone_bytes((""), strlen(("")) + 1, ("rootdir")));
 global_oco.confdir = (("/etc") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc"), strlen(("/etc")) + 1, ("default conf ipsec_conf_dir")));
 global_oco.conffile = (("/etc/ipsec.conf") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc/ipsec.conf"), strlen(("/etc/ipsec.conf")) + 1, ("default conf conffile")));
 global_oco.secretsfile = (("/etc/ipsec.secrets") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc/ipsec.secrets"), strlen(("/etc/ipsec.secrets")) + 1, ("default ipsec.secrets")));
 global_oco.vardir = (("/var") == ((void *)0) ? ((void *)0) : clone_bytes(("/var"), strlen(("/var")) + 1, ("default vardir")));
 global_oco.confddir = (("/etc/ipsec.d") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc/ipsec.d"), strlen(("/etc/ipsec.d")) + 1, ("default conf ipsecd_dir")));
 global_oco.nssdir = (("/var/lib/ipsec/nss") == ((void *)0) ? ((void *)0) : clone_bytes(("/var/lib/ipsec/nss"), strlen(("/var/lib/ipsec/nss")) + 1, ("default nssdir")));
 return 1;
}

canonical_original_code:
static _Bool lsw_conf_setdefault()
{
 if (global_oco.rootdir != ((void *)0)) {
  return 0;
 }
 global_oco.rootdir = (("") == ((void *)0) ? ((void *)0) : clone_bytes((""), strlen(("")) + 1, ("rootdir")));
 global_oco.confdir = (("/etc") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc"), strlen(("/etc")) + 1, ("default conf ipsec_conf_dir")));
 global_oco.conffile = (("/etc/ipsec.conf") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc/ipsec.conf"), strlen(("/etc/ipsec.conf")) + 1, ("default conf conffile")));
 global_oco.secretsfile = (("/etc/ipsec.secrets") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc/ipsec.secrets"), strlen(("/etc/ipsec.secrets")) + 1, ("default ipsec.secrets")));
 global_oco.vardir = (("/var") == ((void *)0) ? ((void *)0) : clone_bytes(("/var"), strlen(("/var")) + 1, ("default vardir")));
 global_oco.confddir = (("/etc/ipsec.d") == ((void *)0) ? ((void *)0) : clone_bytes(("/etc/ipsec.d"), strlen(("/etc/ipsec.d")) + 1, ("default conf ipsecd_dir")));
 global_oco.nssdir = (("/var/lib/ipsec/nss") == ((void *)0) ? ((void *)0) : clone_bytes(("/var/lib/ipsec/nss"), strlen(("/var/lib/ipsec/nss")) + 1, ("default nssdir")));
 return 1;
}


subst

decompiled_code:
unsigned __int64 __fastcall subst(__int64 *a1, const char *a2, __int64 a3)
{
__int64 v3; // rbx
size_t v5; // rax
unsigned __int64 v7; // [rsp+8h] [rbp-20h]

v3 = (__int64)a2;
v7 = __readfsqword(0x28u);
if ( *a1 )
{
pfree();
*a1 = 0LL;
}
if ( a2 )
{
v5 = strlen(a2);
v3 = clone_bytes(a2, v5 + 1, a3);
}
*a1 = v3;
return v7 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 *a1, const char *a2, __int64 a3)
{
__int64 v3; // rbx
size_t v5; // rax
unsigned __int64 v7; // [rsp+8h] [rbp-20h]

v3 = (__int64)a2;
v7 = __readfsqword(0x28u);
if ( *a1 )
{
pfree();
*a1 = 0LL;
}
if ( a2 )
{
v5 = strlen(a2);
v3 = clone_bytes(a2, v5 + 1, a3);
}
*a1 = v3;
return v7 - __readfsqword(0x28u);
}

original_code:
static void subst(char **field, const char *value, const char *name)
{
 { typeof(*field) *pp_ = &(*field); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 *field = ((value) == ((void *)0) ? ((void *)0) : clone_bytes((value), strlen((value)) + 1, (name)));
}

canonical_original_code:
static void subst(char **field, char *value, char *name)
{
 { typeof(*field) *pp_ = &(*field); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 *field = ((value) == ((void *)0) ? ((void *)0) : clone_bytes((value), strlen((value)) + 1, (name)));
}

variable_types:
field
char **

variable_types:
value
char *

variable_types:
name
char *


decompiled_code:
unsigned __int64 lsw_conf_calculate()
{
char v1[4104]; // [rsp+0h] [rbp-1018h] BYREF
unsigned __int64 v2; // [rsp+1008h] [rbp-10h]

v2 = __readfsqword(0x28u);
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/cacerts", (const char *)qword_850);
subst(&qword_860, v1, (__int64)"cacert path");
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/crls", (const char *)qword_850);
subst(&qword_868, v1, (__int64)"crls path");
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/policies", (const char *)qword_850);
subst(&qword_858, v1, (__int64)"policies path");
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/nsspassword", (const char *)qword_850);
subst(&qword_870, v1, (__int64)"nsspassword file");
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func2()
{
char v1[4104]; // [rsp+0h] [rbp-1018h] BYREF
unsigned __int64 v2; // [rsp+1008h] [rbp-10h]

v2 = __readfsqword(0x28u);
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/cacerts", (const char *)qword_850);
func1(&qword_860, v1, (__int64)"cacert path");
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/crls", (const char *)qword_850);
func1(&qword_868, v1, (__int64)"crls path");
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/policies", (const char *)qword_850);
func1(&qword_858, v1, (__int64)"policies path");
_snprintf_chk(v1, 4096LL, 1LL, 4096LL, "%s/nsspassword", (const char *)qword_850);
func1(&qword_870, v1, (__int64)"nsspassword file");
return v2 - __readfsqword(0x28u);
}

original_code:
static void lsw_conf_calculate(void)
{
 char buf[4096];
 snprintf(buf, sizeof(buf), "%s" "/cacerts", global_oco.confddir);
 subst(&global_oco.cacerts_dir, buf, "cacert path");
 snprintf(buf, sizeof(buf), "%s" "/crls", global_oco.confddir);
 subst(&global_oco.crls_dir, buf, "crls path");
 snprintf(buf, sizeof(buf), "%s/policies", global_oco.confddir);
 subst(&global_oco.policies_dir, buf, "policies path");
 snprintf(buf, sizeof(buf), "%s/nsspassword", global_oco.confddir);
 subst(&global_oco.nsspassword_file, buf, "nsspassword file");
}

canonical_original_code:
static void lsw_conf_calculate()
{
 char buf[4096];
 snprintf(buf, sizeof(buf), "%s" "/cacerts", global_oco.confddir);
 subst(&global_oco.cacerts_dir, buf, "cacert path");
 snprintf(buf, sizeof(buf), "%s" "/crls", global_oco.confddir);
 subst(&global_oco.crls_dir, buf, "crls path");
 snprintf(buf, sizeof(buf), "%s/policies", global_oco.confddir);
 subst(&global_oco.policies_dir, buf, "policies path");
 snprintf(buf, sizeof(buf), "%s/nsspassword", global_oco.confddir);
 subst(&global_oco.nsspassword_file, buf, "nsspassword file");
}

variable_types:
buf
char [4096]


decompiled_code:
unsigned __int64 lsw_conf_free_oco()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
if ( global_oco )
{
pfree();
global_oco = 0LL;
}
if ( qword_828 )
{
pfree();
qword_828 = 0LL;
}
if ( qword_830 )
{
pfree();
qword_830 = 0LL;
}
if ( qword_838 )
{
pfree();
qword_838 = 0LL;
}
if ( qword_848 )
{
pfree();
qword_848 = 0LL;
}
if ( qword_850 )
{
pfree();
qword_850 = 0LL;
}
if ( qword_858 )
{
pfree();
qword_858 = 0LL;
}
if ( qword_860 )
{
pfree();
qword_860 = 0LL;
}
if ( qword_868 )
{
pfree();
qword_868 = 0LL;
}
if ( qword_870 )
{
pfree();
qword_870 = 0LL;
}
if ( qword_878 )
{
pfree();
qword_878 = 0LL;
}
if ( qword_880 )
pfree();
global_oco = 0xFBFBFBFBFBFBFBFBLL;
qword_828 = 0xFBFBFBFBFBFBFBFBLL;
qword_830 = 0xFBFBFBFBFBFBFBFBLL;
qword_838 = 0xFBFBFBFBFBFBFBFBLL;
qword_840 = 0xFBFBFBFBFBFBFBFBLL;
qword_848 = 0xFBFBFBFBFBFBFBFBLL;
qword_850 = 0xFBFBFBFBFBFBFBFBLL;
qword_858 = 0xFBFBFBFBFBFBFBFBLL;
qword_860 = 0xFBFBFBFBFBFBFBFBLL;
qword_868 = 0xFBFBFBFBFBFBFBFBLL;
qword_870 = 0xFBFBFBFBFBFBFBFBLL;
qword_878 = 0xFBFBFBFBFBFBFBFBLL;
qword_880 = 0xFBFBFBFBFBFBFBFBLL;
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func3()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
if ( global_oco )
{
pfree();
global_oco = 0LL;
}
if ( qword_828 )
{
pfree();
qword_828 = 0LL;
}
if ( qword_830 )
{
pfree();
qword_830 = 0LL;
}
if ( qword_838 )
{
pfree();
qword_838 = 0LL;
}
if ( qword_848 )
{
pfree();
qword_848 = 0LL;
}
if ( qword_850 )
{
pfree();
qword_850 = 0LL;
}
if ( qword_858 )
{
pfree();
qword_858 = 0LL;
}
if ( qword_860 )
{
pfree();
qword_860 = 0LL;
}
if ( qword_868 )
{
pfree();
qword_868 = 0LL;
}
if ( qword_870 )
{
pfree();
qword_870 = 0LL;
}
if ( qword_878 )
{
pfree();
qword_878 = 0LL;
}
if ( qword_880 )
pfree();
global_oco = 0xFBFBFBFBFBFBFBFBLL;
qword_828 = 0xFBFBFBFBFBFBFBFBLL;
qword_830 = 0xFBFBFBFBFBFBFBFBLL;
qword_838 = 0xFBFBFBFBFBFBFBFBLL;
qword_840 = 0xFBFBFBFBFBFBFBFBLL;
qword_848 = 0xFBFBFBFBFBFBFBFBLL;
qword_850 = 0xFBFBFBFBFBFBFBFBLL;
qword_858 = 0xFBFBFBFBFBFBFBFBLL;
qword_860 = 0xFBFBFBFBFBFBFBFBLL;
qword_868 = 0xFBFBFBFBFBFBFBFBLL;
qword_870 = 0xFBFBFBFBFBFBFBFBLL;
qword_878 = 0xFBFBFBFBFBFBFBFBLL;
qword_880 = 0xFBFBFBFBFBFBFBFBLL;
return v1 - __readfsqword(0x28u);
}

original_code:
void lsw_conf_free_oco(void)
{
 { typeof(global_oco.rootdir) *pp_ = &(global_oco.rootdir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.confdir) *pp_ = &(global_oco.confdir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.conffile) *pp_ = &(global_oco.conffile); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.secretsfile) *pp_ = &(global_oco.secretsfile); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.vardir) *pp_ = &(global_oco.vardir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.confddir) *pp_ = &(global_oco.confddir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.policies_dir) *pp_ = &(global_oco.policies_dir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.cacerts_dir) *pp_ = &(global_oco.cacerts_dir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.crls_dir) *pp_ = &(global_oco.crls_dir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.nsspassword_file) *pp_ = &(global_oco.nsspassword_file); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.nsspassword) *pp_ = &(global_oco.nsspassword); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.nssdir) *pp_ = &(global_oco.nssdir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 memset(((&global_oco)), 0xFB, (sizeof(*(&global_oco))));
}

canonical_original_code:
void lsw_conf_free_oco()
{
 { typeof(global_oco.rootdir) *pp_ = &(global_oco.rootdir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.confdir) *pp_ = &(global_oco.confdir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.conffile) *pp_ = &(global_oco.conffile); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.secretsfile) *pp_ = &(global_oco.secretsfile); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.vardir) *pp_ = &(global_oco.vardir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.confddir) *pp_ = &(global_oco.confddir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.policies_dir) *pp_ = &(global_oco.policies_dir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.cacerts_dir) *pp_ = &(global_oco.cacerts_dir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.crls_dir) *pp_ = &(global_oco.crls_dir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.nsspassword_file) *pp_ = &(global_oco.nsspassword_file); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.nsspassword) *pp_ = &(global_oco.nsspassword); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 { typeof(global_oco.nssdir) *pp_ = &(global_oco.nssdir); if (*pp_ != ((void *)0)) { pfree(*pp_); *pp_ = ((void *)0); } };
 memset(((&global_oco)), 0xFB, (sizeof(*(&global_oco))));
}


decompiled_code:
__int64 *lsw_init_options()
{
if ( (unsigned __int8)lsw_conf_setdefault() )
lsw_conf_calculate();
return &global_oco;
}

canonical_decompiled_code:
__int64 *func4()
{
if ( (unsigned __int8)func0() )
func2();
return &global_oco;
}

original_code:
const struct lsw_conf_options *lsw_init_options(void)
{
 if (lsw_conf_setdefault()) {
  lsw_conf_calculate();
 }
 return &global_oco;
}

canonical_original_code:
struct lsw_conf_options *lsw_init_options()
{
 if (lsw_conf_setdefault()) {
  lsw_conf_calculate();
 }
 return &global_oco;
}

return_type: struct lsw_conf_options { char *rootdir; char *confdir; char *conffile; char *secretsfile; char *ppkdir; char *vardir; char *confddir; char *policies_dir; char *cacerts_dir; char *crls_dir; char *nsspassword_file; char *nsspassword; char *nssdir; } *