decompiled_code:
__int64 __fastcall jam_stream_prefix(__int64 a1, unsigned int a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 == 5242880 )
return jam_string(a1, "EXPECTATION FAILED: ");
if ( a2 <= 0x500000 )
{
if ( a2 == 3145728 )
return jam_string(a1, &LC0);
if ( a2 <= 0x300000 )
{
if ( a2 == 0x200000 || (a2 & 0xFFEFFFFF) == 0 )
return v3 - __readfsqword(0x28u);
}
else if ( a2 == 0x400000 )
{
return v3 - __readfsqword(0x28u);
}
goto LABEL_12;
}
if ( a2 != 7340032 )
{
if ( a2 == 15728640 )
return v3 - __readfsqword(0x28u);
if ( a2 == 6291456 )
return jam_string(a1, "FATAL: ASSERTION FAILED: ");
LABEL_12:
jam_stream_prefix_cold();
}
return jam_string(a1, "FATAL ERROR: ");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( a2 == 5242880 )
return jam_string(a1, "EXPECTATION FAILED: ");
if ( a2 <= 0x500000 )
{
if ( a2 == 3145728 )
return jam_string(a1, &LC0);
if ( a2 <= 0x300000 )
{
if ( a2 == 0x200000 || (a2 & 0xFFEFFFFF) == 0 )
return v3 - __readfsqword(0x28u);
}
else if ( a2 == 0x400000 )
{
return v3 - __readfsqword(0x28u);
}
goto LABEL_12;
}
if ( a2 != 7340032 )
{
if ( a2 == 15728640 )
return v3 - __readfsqword(0x28u);
if ( a2 == 6291456 )
return jam_string(a1, "FATAL: ASSERTION FAILED: ");
LABEL_12:
func2();
}
return jam_string(a1, "FATAL ERROR: ");
}

original_code:
static void jam_stream_prefix(struct jambuf *buf, enum stream stream)
{
 switch (stream) {
 case DEBUG_STREAM:
  jam_string(buf, "| ");
  return;
 case PEXPECT_STREAM:
  jam_string(buf, "EXPECTATION FAILED: ");
  return;
 case PASSERT_STREAM:
  jam_string(buf, "FATAL: ASSERTION FAILED: ");
  return;
 case FATAL_STREAM:
  jam_string(buf, "FATAL ERROR: ");
  return;
 case ERROR_STREAM:
  return;
 case ALL_STREAMS:
 case LOG_STREAM:
 case WHACK_STREAM:
 case NO_STREAM:
  return;
 }
 abort();
}

variable_types: enum stream { ALL_STREAMS=0, LOG_STREAM=1048576, WHACK_STREAM=2097152, DEBUG_STREAM=3145728, ERROR_STREAM=4194304, PEXPECT_STREAM=5242880, PASSERT_STREAM=6291456, FATAL_STREAM=7340032, NO_STREAM=15728640 }


repo: libreswan/libreswan

decompiled_code:
unsigned __int64 __fastcall exit_prologue(int a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
exiting_pluto = 1;
pluto_exit_code = a1;
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
exiting_pluto = 1;
pluto_exit_code = a1;
return v2 - __readfsqword(0x28u);
}

original_code:
static void exit_prologue(enum pluto_exit_code exit_code)
{
 exiting_pluto = 1;
 pluto_exit_code = exit_code;
}

variable_types: enum pluto_exit_code { PLUTO_EXIT_OK=0, PLUTO_EXIT_FAIL=1, PLUTO_EXIT_SOCKET_FAIL=2, PLUTO_EXIT_FORK_FAIL=3, PLUTO_EXIT_FIPS_FAIL=4, PLUTO_EXIT_KERNEL_FAIL=5, PLUTO_EXIT_NSS_FAIL=6, PLUTO_EXIT_AUDIT_FAIL=7, PLUTO_EXIT_SECCOMP_FAIL=8, PLUTO_EXIT_UNBOUND_FAIL=9, PLUTO_EXIT_LOCK_FAIL=10, PLUTO_EXIT_SELINUX_FAIL=11, PLUTO_EXIT_LEAVE_STATE=12, PLUTO_EXIT_GIT_BISECT_CAN_NOT_TEST=125, PLUTO_EXIT_SHELL_COMMAND_NOT_FOUND=126, PLUTO_EXIT_SHELL_COMMAND_NOT_EXECUTABLE=127 }

return_type: void


decompiled_code:
__int64 server_helpers_stopped_callback()
{
return stop_server(server_stopped_callback);
}

canonical_decompiled_code:
__int64 func2()
{
return stop_server(server_stopped_callback);
}

original_code:
void server_helpers_stopped_callback(void)
{
 stop_server(server_stopped_callback);
}

canonical_original_code:
void server_helpers_stopped_callback()
{
 stop_server(server_stopped_callback);
}


decompiled_code:
void __fastcall __noreturn server_stopped_callback(const char *a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
if ( (cur_debugging & 1) != 0 )
{
a2 = "an error occurred";
if ( (int)a1 >= 0 )
{
a2 = "no pending or active events";
if ( !(_DWORD)a1 )
a2 = "success";
}
a1 = "event loop exited: %s";
DBG_log("event loop exited: %s", a2);
}
exit_epilogue((__int64)a1, (__int64)a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
if ( (cur_debugging & 1) != 0 )
{
a2 = "an error occurred";
if ( (int)a1 >= 0 )
{
a2 = "no pending or active events";
if ( !(_DWORD)a1 )
a2 = "success";
}
a1 = "event loop exited: %s";
DBG_log("event loop exited: %s", a2);
}
func1((__int64)a1, (__int64)a2, a3, a4, a5, a6);
}

original_code:
void server_stopped_callback(int r)
{
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("event loop exited: %s", r < 0 ? "an error occurred" : r > 0 ? "no pending or active events" : "success"); } };
 exit_epilogue();
}

canonical_original_code:
void server_stopped_callback(int r)
{
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("event loop exited: %s", r < 0 ? "an error occurred" : r > 0 ? "no pending or active events" : "success"); } };
 exit_epilogue();
}

variable_types: r int


decompiled_code:
void __fastcall __noreturn libreswan_exit(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9

exit_prologue(a1);
exit_epilogue(a1, a2, v2, v3, v4, v5);
}

original_code:
void libreswan_exit(enum pluto_exit_code exit_code)
{
 exit_prologue(exit_code);
 exit_epilogue();
}

user_defined_types: enum pluto_exit_code { PLUTO_EXIT_OK=0, PLUTO_EXIT_FAIL=1, PLUTO_EXIT_SOCKET_FAIL=2, PLUTO_EXIT_FORK_FAIL=3, PLUTO_EXIT_FIPS_FAIL=4, PLUTO_EXIT_KERNEL_FAIL=5, PLUTO_EXIT_NSS_FAIL=6, PLUTO_EXIT_AUDIT_FAIL=7, PLUTO_EXIT_SECCOMP_FAIL=8, PLUTO_EXIT_UNBOUND_FAIL=9, PLUTO_EXIT_LOCK_FAIL=10, PLUTO_EXIT_SELINUX_FAIL=11, PLUTO_EXIT_LEAVE_STATE=12, PLUTO_EXIT_GIT_BISECT_CAN_NOT_TEST=125, PLUTO_EXIT_SHELL_COMMAND_NOT_FOUND=126, PLUTO_EXIT_SHELL_COMMAND_NOT_EXECUTABLE=127 }


decompiled_code:
char *__fastcall pmhdr_where(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax

v2 = *(a1 - 2);
if ( v2 != 3671129837LL )
{
if ( v2 == -3671129838LL )
llog_passert(&global_logger, a2, "pointer %p invalid, possible double free (magic == ~LEAK_MAGIC)", a1);
llog_passert(
&global_logger,
a2,
"pointer %p invalid, possible heap corruption or bad pointer (magic != LEAK_MAGIC and ~LEAK_MAGIC})",
a1);
}
return (char *)(a1 - 5);
}

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

v2 = *(a1 - 2);
if ( v2 != 3671129837LL )
{
if ( v2 == -3671129838LL )
llog_passert(&global_logger, a2, "pointer %p invalid, possible double free (magic == ~LEAK_MAGIC)", a1);
llog_passert(
&global_logger,
a2,
"pointer %p invalid, possible heap corruption or bad pointer (magic != LEAK_MAGIC and ~LEAK_MAGIC})",
a1);
}
return (char *)(a1 - 5);
}

original_code:
static union mhdr *pmhdr_where(void *ptr, where_t where)
{
 union mhdr *p = ((union mhdr *)ptr) - 1;
 switch (p->i.magic) {
 case 0xDAD0FEEDul:
  break;
 case ~0xDAD0FEEDul:
  llog_passert(&global_logger, where,
        "pointer %p invalid, possible double free (magic == ~LEAK_MAGIC)", ptr);
 default:
  llog_passert(&global_logger, where,
        "pointer %p invalid, possible heap corruption or bad pointer (magic != LEAK_MAGIC and ~LEAK_MAGIC})", ptr);
 }
 return p;
}

canonical_original_code:
static union mhdr *pmhdr_where(void *ptr, struct where *where)
{
 union mhdr *p = ((union mhdr *)ptr) - 1;
 switch (p->i.magic) {
 case 0xDAD0FEEDul:
  break;
 case ~0xDAD0FEEDul:
  llog_passert(&global_logger, where,
        "pointer %p invalid, possible double free (magic == ~LEAK_MAGIC)", ptr);
 default:
  llog_passert(&global_logger, where,
        "pointer %p invalid, possible heap corruption or bad pointer (magic != LEAK_MAGIC and ~LEAK_MAGIC})", ptr);
 }
 return p;
}

variable_types:
ptr
void *

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

variable_types: union mhdr { struct { char *name; union mhdr *older; unsigned long magic; unsigned long size; } i; unsigned long long junk; } *


decompiled_code:
int __fastcall install_allocation(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

*a1 = a3;
a1[4] = a2;
a1[3] = 3671129837LL;
a1[2] = 0LL;
pthread_mutex_lock(&leak_detective_mutex);
v3 = allocs;
a1[1] = allocs;
if ( v3 )
*(_QWORD *)(v3 + 16) = a1;
allocs = (__int64)a1;
return pthread_mutex_unlock(&leak_detective_mutex);
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

*a1 = a3;
a1[4] = a2;
a1[3] = 3671129837LL;
a1[2] = 0LL;
pthread_mutex_lock(&leak_detective_mutex);
v3 = allocs;
a1[1] = allocs;
if ( v3 )
*(_QWORD *)(v3 + 16) = a1;
allocs = (__int64)a1;
return pthread_mutex_unlock(&leak_detective_mutex);
}

original_code:
static void install_allocation(union mhdr *p, size_t size, const char *name)
{
 p->i.name = name;
 p->i.size = size;
 p->i.magic = 0xDAD0FEEDul;
 p->i.newer = ((void *)0);
 {
  pthread_mutex_lock(&leak_detective_mutex);
  p->i.older = allocs;
  if (allocs != ((void *)0))
   allocs->i.newer = p;
  allocs = p;
  pthread_mutex_unlock(&leak_detective_mutex);
 }
}

canonical_original_code:
static void install_allocation(union mhdr *p, unsigned long size, char *name)
{
 p->i.name = name;
 p->i.size = size;
 p->i.magic = 0xDAD0FEEDul;
 p->i.newer = ((void *)0);
 {
  pthread_mutex_lock(&leak_detective_mutex);
  p->i.older = allocs;
  if (allocs != ((void *)0))
   allocs->i.newer = p;
  allocs = p;
  pthread_mutex_unlock(&leak_detective_mutex);
 }
}

variable_types:
size
unsigned long

variable_types:
name
char *

user_defined_types: union mhdr { struct { char *name; union mhdr *older; unsigned long magic; unsigned long size; } i; unsigned long long junk; }


zalloc

decompiled_code:
void *__fastcall zalloc(size_t size)
{
return calloc(1uLL, size);
}

canonical_decompiled_code:
void *__fastcall func3(size_t size)
{
return calloc(1uLL, size);
}

original_code:
static void *zalloc(size_t size)
{
 return calloc(1, size);
}

canonical_original_code:
static void *zalloc(unsigned long size)
{
 return calloc(1, size);
}

return_type: void *


decompiled_code:
const char *__fastcall enum_name(unsigned __int64 *a1, char **a2)
{
__int64 *v2; // rax
const char *v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[1] = (const char *)__readfsqword(0x28u);
v4[0] = 0LL;
v2 = (__int64 *)enum_range(a1, (unsigned __int64)a2, (unsigned __int64 *)v4);
return enum_range_name(v2, a2, v4[0], 0);
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int64 *a1, char **a2)
{
__int64 *v2; // rax
const char *v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[1] = (const char *)__readfsqword(0x28u);
v4[0] = 0LL;
v2 = (__int64 *)func1(a1, (unsigned __int64)a2, (unsigned __int64 *)v4);
return func2(v2, a2, v4[0], 0);
}

original_code:
const char *enum_name(enum_names *ed, unsigned long val)
{
 const char *prefix = ((void *)0);
 const struct enum_names *range = enum_range(ed, val, &prefix);
 return enum_range_name(range, val, prefix, 0);
}

canonical_original_code:
char *enum_name(struct enum_names *ed, unsigned long val)
{
 char *prefix = ((void *)0);
 struct enum_names *range = enum_range(ed, val, &prefix);
 return enum_range_name(range, val, prefix, 0);
}

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:
prefix
char *

return_type: char *


decompiled_code:
const char *__fastcall enum_name_short(unsigned __int64 *a1, char **a2)
{
__int64 *v2; // rax
const char *v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[1] = (const char *)__readfsqword(0x28u);
v4[0] = 0LL;
v2 = (__int64 *)enum_range(a1, (unsigned __int64)a2, (unsigned __int64 *)v4);
return enum_range_name(v2, a2, v4[0], 1u);
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned __int64 *a1, char **a2)
{
__int64 *v2; // rax
const char *v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[1] = (const char *)__readfsqword(0x28u);
v4[0] = 0LL;
v2 = (__int64 *)func1(a1, (unsigned __int64)a2, (unsigned __int64 *)v4);
return func2(v2, a2, v4[0], 1u);
}

original_code:
const char *enum_name_short(enum_names *ed, unsigned long val)
{
 const char *prefix = ((void *)0);
 const struct enum_names *range = enum_range(ed, val, &prefix);
 return enum_range_name(range, val, prefix, 1);
}

canonical_original_code:
char *enum_name_short(struct enum_names *ed, unsigned long val)
{
 char *prefix = ((void *)0);
 struct enum_names *range = enum_range(ed, val, &prefix);
 return enum_range_name(range, val, prefix, 1);
}

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_enum(__int64 a1, unsigned __int64 *a2, char **a3)
{
if ( enum_name(a2, a3) )
return jam_string(a1);
if ( a2[4] )
{
jam_string(a1);
jam_string(a1);
}
return jam(a1, "%lu??", a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int64 *a2, char **a3)
{
if ( func3(a2, a3) )
return jam_string(a1);
if ( a2[4] )
{
jam_string(a1);
jam_string(a1);
}
return jam(a1, "%lu??", a3);
}

original_code:
size_t jam_enum(struct jambuf *buf, enum_names *en, unsigned long val)
{
 const char *name = enum_name(en, val);
 if (name == ((void *)0)) {
  if (en->en_prefix != ((void *)0)) {
   jam_string(buf, en->en_prefix);
   jam_string(buf, "_");
  }
  return jam(buf, "%lu??", val);
 }
 return jam_string(buf, name);
}

canonical_original_code:
unsigned long jam_enum(struct jambuf *buf, struct enum_names *en, unsigned long val)
{
 char *name = enum_name(en, val);
 if (name == ((void *)0)) {
  if (en->en_prefix != ((void *)0)) {
   jam_string(buf, en->en_prefix);
   jam_string(buf, "_");
  }
  return jam(buf, "%lu??", val);
 }
 return jam_string(buf, name);
}

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

return_type: unsigned long


decompiled_code:
__int64 __fastcall jam_enum_short(__int64 a1, unsigned __int64 *a2, char **a3)
{
if ( enum_name_short(a2, a3) )
return jam_string(a1);
if ( a2[4] )
{
jam_string(a1);
jam_string(a1);
}
return jam(a1, "%lu??", a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int64 *a2, char **a3)
{
if ( func4(a2, a3) )
return jam_string(a1);
if ( a2[4] )
{
jam_string(a1);
jam_string(a1);
}
return jam(a1, "%lu??", a3);
}

original_code:
size_t jam_enum_short(struct jambuf *buf, enum_names *en, unsigned long val)
{
 const char *name = enum_name_short(en, val);
 if (name == ((void *)0)) {
  if (en->en_prefix != ((void *)0)) {
   jam_string(buf, en->en_prefix);
   jam_string(buf, "_");
  }
  return jam(buf, "%lu??", val);
 }
 return jam_string(buf, name);
}

canonical_original_code:
unsigned long jam_enum_short(struct jambuf *buf, struct enum_names *en, unsigned long val)
{
 char *name = enum_name_short(en, val);
 if (name == ((void *)0)) {
  if (en->en_prefix != ((void *)0)) {
   jam_string(buf, en->en_prefix);
   jam_string(buf, "_");
  }
  return jam(buf, "%lu??", val);
 }
 return jam_string(buf, name);
}

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


decompiled_code:
const char *__fastcall str_enum(unsigned __int64 *a1, char **a2, const char *a3)
{
const char *v4; // r12

v4 = enum_name(a1, a2);
if ( !v4 )
{
v4 = a3;
_snprintf_chk(a3, 23LL, 1LL, -1LL, "%lu??", a2);
}
return v4;
}

canonical_decompiled_code:
const char *__fastcall func7(unsigned __int64 *a1, char **a2, const char *a3)
{
const char *v4; // r12

v4 = func3(a1, a2);
if ( !v4 )
{
v4 = a3;
_snprintf_chk(a3, 23LL, 1LL, -1LL, "%lu??", a2);
}
return v4;
}

original_code:
const char *str_enum(enum_names *ed, unsigned long val, enum_buf *b)
{
 const char *p = enum_name(ed, val);
 if (p == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  p = b->buf;
 }
 return p;
}

canonical_original_code:
char *str_enum(struct enum_names *ed, unsigned long val, struct enum_buf *b)
{
 char *p = enum_name(ed, val);
 if (p == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  p = b->buf;
 }
 return p;
}

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

variable_types:
p
char *


decompiled_code:
const char *__fastcall str_enum_short(unsigned __int64 *a1, char **a2, const char *a3)
{
__int64 *v4; // rax
const char *v5; // r12
const char *v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[1] = (const char *)__readfsqword(0x28u);
v4 = (__int64 *)enum_range(a1, (unsigned __int64)a2, (unsigned __int64 *)v7);
v5 = enum_range_name(v4, a2, v7[0], 1u);
if ( !v5 )
{
v5 = a3;
_snprintf_chk(a3, 23LL, 1LL, -1LL, "%lu??", a2);
}
return v5;
}

canonical_decompiled_code:
const char *__fastcall func8(unsigned __int64 *a1, char **a2, const char *a3)
{
__int64 *v4; // rax
const char *v5; // r12
const char *v7[5]; // [rsp+0h] [rbp-28h] BYREF

v7[1] = (const char *)__readfsqword(0x28u);
v4 = (__int64 *)func1(a1, (unsigned __int64)a2, (unsigned __int64 *)v7);
v5 = func2(v4, a2, v7[0], 1u);
if ( !v5 )
{
v5 = a3;
_snprintf_chk(a3, 23LL, 1LL, -1LL, "%lu??", a2);
}
return v5;
}

original_code:
const char *str_enum_short(enum_names *ed, unsigned long val, enum_buf *b)
{
 const char *prefix;
 const struct enum_names *range = enum_range(ed, val, &prefix);
 const char *name = enum_range_name(range, val, prefix, 1);
 if (name == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  name = b->buf;
 }
 return name;
}

canonical_original_code:
char *str_enum_short(struct enum_names *ed, unsigned long val, struct enum_buf *b)
{
 char *prefix;
 struct enum_names *range = enum_range(ed, val, &prefix);
 char *name = enum_range_name(range, val, prefix, 1);
 if (name == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  name = b->buf;
 }
 return name;
}


decompiled_code:
const char *__fastcall str_enum_enum(unsigned __int64 *a1, unsigned __int64 a2, char **a3, const char *a4)
{
unsigned __int64 *v6; // rax

v6 = (unsigned __int64 *)enum_enum_table(a1, a2);
if ( v6 )
return str_enum(v6, a3, a4);
_snprintf_chk(a4, 23LL, 1LL, -1LL, "%lu??", a3);
return a4;
}

canonical_decompiled_code:
const char *__fastcall func13(unsigned __int64 *a1, unsigned __int64 a2, char **a3, const char *a4)
{
unsigned __int64 *v6; // rax

v6 = (unsigned __int64 *)func11(a1, a2);
if ( v6 )
return func7(v6, a3, a4);
_snprintf_chk(a4, 23LL, 1LL, -1LL, "%lu??", a3);
return a4;
}

original_code:
const char *str_enum_enum(enum_enum_names *een, unsigned long table,
     unsigned long val, enum_buf *b)
{
 enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  return b->buf;
 }
 return str_enum(en, val, b);
}

canonical_original_code:
char *str_enum_enum(struct enum_enum_names *een, unsigned long table, unsigned long val, struct enum_buf *b)
{
 struct enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  return b->buf;
 }
 return str_enum(en, val, b);
}

variable_types: struct enum_enum_names { unsigned long een_first; unsigned long een_last; 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; } **een_enum_name; unsigned long een_checklen; } *

variable_types:
table
unsigned long

user_defined_types: struct enum_enum_names { unsigned long een_first; unsigned long een_last; struct enum_names **een_enum_name; unsigned long een_checklen; }


decompiled_code:
const char *__fastcall str_enum_enum_short(unsigned __int64 *a1, unsigned __int64 a2, char **a3, const char *a4)
{
unsigned __int64 *v6; // rax

v6 = (unsigned __int64 *)enum_enum_table(a1, a2);
if ( v6 )
return str_enum_short(v6, a3, a4);
_snprintf_chk(a4, 23LL, 1LL, -1LL, "%lu??", a3);
return a4;
}

canonical_decompiled_code:
const char *__fastcall func14(unsigned __int64 *a1, unsigned __int64 a2, char **a3, const char *a4)
{
unsigned __int64 *v6; // rax

v6 = (unsigned __int64 *)func11(a1, a2);
if ( v6 )
return func8(v6, a3, a4);
_snprintf_chk(a4, 23LL, 1LL, -1LL, "%lu??", a3);
return a4;
}

original_code:
const char *str_enum_enum_short(enum_enum_names *een, unsigned long table,
    unsigned long val, enum_buf *b)
{
 enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  return b->buf;
 }
 return str_enum_short(en, val, b);
}

canonical_original_code:
char *str_enum_enum_short(struct enum_enum_names *een, unsigned long table, unsigned long val, struct enum_buf *b)
{
 struct enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  snprintf(b->buf, sizeof(b->buf), "%lu??", val);
  return b->buf;
 }
 return str_enum_short(en, val, b);
}


decompiled_code:
__int64 __fastcall jam_enum_enum(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, char **a4)
{
unsigned __int64 *v6; // rax
__int64 result; // rax

v6 = (unsigned __int64 *)enum_enum_table(a2, a3);
if ( v6 )
result = jam_enum(a1, v6, a4);
else
result = jam(a1, "%lu??%lu??", a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, char **a4)
{
unsigned __int64 *v6; // rax
__int64 result; // rax

v6 = (unsigned __int64 *)func11(a2, a3);
if ( v6 )
result = func5(a1, v6, a4);
else
result = jam(a1, "%lu??%lu??", a3, a4);
return result;
}

original_code:
size_t jam_enum_enum(struct jambuf *buf, enum_enum_names *een,
       unsigned long table, unsigned long val)
{
 enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  return jam(buf, "%lu??%lu??", table, val);
 }
 return jam_enum(buf, en, val);
}

canonical_original_code:
unsigned long jam_enum_enum(struct jambuf *buf, struct enum_enum_names *een, unsigned long table, unsigned long val)
{
 struct enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  return jam(buf, "%lu??%lu??", table, val);
 }
 return jam_enum(buf, en, val);
}


decompiled_code:
__int64 __fastcall jam_enum_enum_short(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, char **a4)
{
unsigned __int64 *v6; // rax
__int64 result; // rax

v6 = (unsigned __int64 *)enum_enum_table(a2, a3);
if ( v6 )
result = jam_enum_short(a1, v6, a4);
else
result = jam(a1, "%lu??%lu??", a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, char **a4)
{
unsigned __int64 *v6; // rax
__int64 result; // rax

v6 = (unsigned __int64 *)func11(a2, a3);
if ( v6 )
result = func6(a1, v6, a4);
else
result = jam(a1, "%lu??%lu??", a3, a4);
return result;
}

original_code:
size_t jam_enum_enum_short(struct jambuf *buf, enum_enum_names *een,
      unsigned long table, unsigned long val)
{
 enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  return jam(buf, "%lu??%lu??", table, val);
 }
 return jam_enum_short(buf, en, val);
}

canonical_original_code:
unsigned long jam_enum_enum_short(struct jambuf *buf, struct enum_enum_names *een, unsigned long table, unsigned long val)
{
 struct enum_names *en = enum_enum_table(een, table);
 if (en == ((void *)0)) {
  return jam(buf, "%lu??%lu??", table, val);
 }
 return jam_enum_short(buf, en, val);
}


decompiled_code:
unsigned __int64 __fastcall check_enum_names(__int64 a1, __int64 a2)
{
__int64 i; // rbx
unsigned __int64 *v4; // rdi
unsigned __int64 v6; // [rsp+8h] [rbp-20h]

v6 = __readfsqword(0x28u);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = *(unsigned __int64 **)(a1 + 8 * i);
enum_name(v4, (char **)0xFFFFFFFFFFFFFFD6LL);
}
}
return v6 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(__int64 a1, __int64 a2)
{
__int64 i; // rbx
unsigned __int64 *v4; // rdi
unsigned __int64 v6; // [rsp+8h] [rbp-20h]

v6 = __readfsqword(0x28u);
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v4 = *(unsigned __int64 **)(a1 + 8 * i);
func3(v4, (char **)0xFFFFFFFFFFFFFFD6LL);
}
}
return v6 - __readfsqword(0x28u);
}

original_code:
void check_enum_names(enum_names *checklist[], size_t tl)
{
 size_t i;
 for (i = 0; i != tl; i++) {
  (void) enum_name(checklist[i], -42UL);
 }
}

canonical_original_code:
void check_enum_names(struct enum_names *checklist[], unsigned long tl)
{
 unsigned long i;
 for (i = 0; i != tl; i++) {
  (void) enum_name(checklist[i], -42UL);
 }
}

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:
tl
unsigned long

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall hash_bytes(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
__int64 v5; // rdx

result = a3;
if ( a2 )
{
v4 = 0;
v5 = 0LL;
do
{
result = (unsigned int)*(unsigned __int8 *)(a1 + v5) + 251 * (_DWORD)result;
v5 = ++v4;
}
while ( v4 < a2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // ecx
__int64 v5; // rdx

result = a3;
if ( a2 )
{
v4 = 0;
v5 = 0LL;
do
{
result = (unsigned int)*(unsigned __int8 *)(a1 + v5) + 251 * (_DWORD)result;
v5 = ++v4;
}
while ( v4 < a2 );
}
return result;
}

original_code:
hash_t hash_bytes(const void *ptr, size_t len, hash_t hash)
{
 const uint8_t *bytes = ptr;
 for (unsigned j = 0; j < len; j++) {
  hash.hash = hash.hash * 251 + bytes[j];
 }
 return hash;
}

canonical_original_code:
struct hash_t hash_bytes(void *ptr, unsigned long len, struct hash_t hash)
{
 unsigned char *bytes = ptr;
 for (unsigned int j = 0; j < len; j++) {
  hash.hash = hash.hash * 251 + bytes[j];
 }
 return hash;
}

variable_types:
len
unsigned long

variable_types:
hash
struct hash_t

variable_types:
bytes
unsigned char *

variable_types:
j
unsigned int

return_type: struct hash_t { unsigned int hash; }


decompiled_code:
unsigned __int64 __fastcall hash_table_bucket(__int64 a1, unsigned int a2)
{
return 32 * ((unsigned __int64)a2 % *(_QWORD *)(a1 + 32)) + *(_QWORD *)(a1 + 40);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned int a2)
{
return 32 * ((unsigned __int64)a2 % *(_QWORD *)(a1 + 32)) + *(_QWORD *)(a1 + 40);
}

original_code:
struct list_head *hash_table_bucket(struct hash_table *table, hash_t hash)
{
 return &table->slots[hash.hash % table->nr_slots];
}

canonical_original_code:
struct list_head *hash_table_bucket(struct hash_table *table, struct hash_t hash)
{
 return &table->slots[hash.hash % table->nr_slots];
}

variable_types: struct hash_table { struct list_info *info; struct hash_t { unsigned int hash; } (*hasher)(void *data); struct list_entry *(*entry)(void *data); long nr_entries; unsigned long nr_slots; struct list_head *slots; } *

return_type: struct list_head { struct list_entry { struct list_entry *next[2]; void *data; struct list_info { char *name; void (*jam)(struct jambuf { char *array; unsigned long total; unsigned long roof; char *dots; } *buf, void *data); long offset; } *info; } head; } *

user_defined_types: struct hash_table { struct list_info *info; struct hash_t (*hasher)(void *data); struct list_entry *(*entry)(void *data); long nr_entries; unsigned long nr_slots; struct list_head *slots; }

user_defined_types: struct list_head { struct list_entry head; }

user_defined_types: struct list_entry { struct list_entry *next[2]; void *data; struct list_info *info; }

user_defined_types: struct list_info { char *name; void (*jam)(struct jambuf *buf, void *data); long offset; }


decompiled_code:
bool __fastcall ike_spi_eq(_QWORD *a1, _QWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
bool __fastcall func0(_QWORD *a1, _QWORD *a2)
{
return *a1 == *a2;
}

original_code:
_Bool ike_spi_eq(const ike_spi_t *lhs, const ike_spi_t *rhs)
{
 return (memcmp((lhs), (rhs), (sizeof(*lhs))) == 0);
}

canonical_original_code:
_Bool ike_spi_eq(struct ike_spi_t *lhs, struct ike_spi_t *rhs)
{
 return (memcmp((lhs), (rhs), (sizeof(*lhs))) == 0);
}

variable_types: struct ike_spi_t { unsigned char bytes[8]; } *

variable_types:
rhs
struct ike_spi_t *


decompiled_code:
bool __fastcall ike_spi_is_zero(_QWORD *a1)
{
return ike_spi_eq(a1, &zero_ike_spi);
}

canonical_decompiled_code:
bool __fastcall func1(_QWORD *a1)
{
return func0(a1, &zero_ike_spi);
}

original_code:
_Bool ike_spi_is_zero(const ike_spi_t *spi)
{
 return ike_spi_eq(spi, &zero_ike_spi);
}

canonical_original_code:
_Bool ike_spi_is_zero(struct ike_spi_t *spi)
{
 return ike_spi_eq(spi, &zero_ike_spi);
}

user_defined_types: struct ike_spi_t { unsigned char bytes[8]; }


decompiled_code:
bool __fastcall ike_spis_eq(_QWORD *a1, _QWORD *a2)
{
bool result; // al

if ( ike_spi_eq(a1, a2) )
result = ike_spi_eq(a1 + 1, a2 + 1);
else
result = 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func2(_QWORD *a1, _QWORD *a2)
{
bool result; // al

if ( func0(a1, a2) )
result = func0(a1 + 1, a2 + 1);
else
result = 0;
return result;
}

original_code:
_Bool ike_spis_eq(const ike_spis_t *lhs, const ike_spis_t *rhs)
{
 return (ike_spi_eq(&lhs->initiator, &rhs->initiator) &&
  ike_spi_eq(&lhs->responder, &rhs->responder));
}

canonical_original_code:
_Bool ike_spis_eq(struct ike_spis_t *lhs, struct ike_spis_t *rhs)
{
 return (ike_spi_eq(&lhs->initiator, &rhs->initiator) &&
  ike_spi_eq(&lhs->responder, &rhs->responder));
}

variable_types: struct ike_spis_t { struct ike_spi_t { unsigned char bytes[8]; } initiator; struct ike_spi_t responder; } *

variable_types:
rhs
struct ike_spis_t *

user_defined_types: struct ike_spis_t { struct ike_spi_t initiator; struct ike_spi_t responder; }


decompiled_code:
__int64 refresh_ike_spi_secret()
{
return get_rnd_bytes(&ike_spi_secret, 32LL);
}

canonical_decompiled_code:
__int64 func3()
{
return get_rnd_bytes(&ike_spi_secret, 32LL);
}

original_code:
void refresh_ike_spi_secret(void)
{
 get_rnd_bytes(&ike_spi_secret, sizeof(ike_spi_secret));
}

canonical_original_code:
void refresh_ike_spi_secret()
{
 get_rnd_bytes(&ike_spi_secret, sizeof(ike_spi_secret));
}


decompiled_code:
__int64 ike_initiator_spi()
{
int v0; // eax
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4[5]; // [rsp+0h] [rbp-28h] BYREF

v4[1] = __readfsqword(0x28u);
v0 = impair[8];
if ( v0 )
{
v2 = (unsigned int)(v0 - 1);
if ( (cur_debugging & 1) != 0 )
DBG_log("forcing IKE initiator SPI to 0x%jx", (unsigned int)(v0 - 1));
v3 = chunk2(v4, 8LL);
hton_bytes(v2, v3);
result = v4[0];
}
else
{
do
get_rnd_bytes(v4, 8LL);
while ( ike_spi_is_zero(v4) );
result = v4[0];
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4[5]; // [rsp+0h] [rbp-28h] BYREF

v4[1] = __readfsqword(0x28u);
v0 = impair[8];
if ( v0 )
{
v2 = (unsigned int)(v0 - 1);
if ( (cur_debugging & 1) != 0 )
DBG_log("forcing IKE initiator SPI to 0x%jx", (unsigned int)(v0 - 1));
v3 = chunk2(v4, 8LL);
hton_bytes(v2, v3);
result = v4[0];
}
else
{
do
get_rnd_bytes(v4, 8LL);
while ( func1(v4) );
result = v4[0];
}
return result;
}

original_code:
ike_spi_t ike_initiator_spi(void)
{
 if (impair.ike_initiator_spi > 0) {
  uintmax_t v = impair.ike_initiator_spi - 1;
  { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("forcing IKE initiator SPI to 0x%jx", v); } };
  ike_spi_t spi;
  ({ const chunk_t hunk_ = chunk2(&(spi), sizeof(spi)); hton_bytes(v, hunk_.ptr, hunk_.len); });
  return spi;
 }
 ike_spi_t spi;
 do {
  get_rnd_bytes(spi.bytes, sizeof(spi));
 } while (ike_spi_is_zero(&spi));
 return spi;
}

canonical_original_code:
struct ike_spi_t ike_initiator_spi()
{
 if (impair.ike_initiator_spi > 0) {
  unsigned long v = impair.ike_initiator_spi - 1;
  { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("forcing IKE initiator SPI to 0x%jx", v); } };
  struct ike_spi_t spi;
  ({ struct chunk_t hunk_ = chunk2(&(spi), sizeof(spi)); hton_bytes(v, hunk_.ptr, hunk_.len); });
  return spi;
 }
 struct ike_spi_t spi;
 do {
  get_rnd_bytes(spi.bytes, sizeof(spi));
 } while (ike_spi_is_zero(&spi));
 return spi;
}

variable_types:
v
unsigned long

variable_types: struct ike_spi_t { unsigned char bytes[8]; }

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


original_code:
static void double_delay(retransmit_t *rt, unsigned long nr_retransmits)
{
 if (nr_retransmits > 0) {
  deltatime_t delay = deltatime_add(rt->delay, rt->delay);
  if ((deltatime_sub_sign(delay, rt->timeout) < 0)) {
   rt->delay = delay;
  }
 }
}

canonical_original_code:
static void double_delay(struct retransmit_t *rt, unsigned long nr_retransmits)
{
 if (nr_retransmits > 0) {
  struct deltatime_t delay = deltatime_add(rt->delay, rt->delay);
  if ((deltatime_sub_sign(delay, rt->timeout) < 0)) {
   rt->delay = delay;
  }
 }
}

variable_types: struct retransmit_t { struct deltatime_t { struct timeval { long tv_sec; long tv_usec; } dt; _Bool is_set; } delay; struct deltatime_t timeout; struct monotime_t { struct timeval mt; } start; struct deltatime_t delays; unsigned long nr_retransmits; unsigned long nr_duplicate_replies; unsigned long limit; unsigned long who_for; } *

user_defined_types: struct deltatime_t { struct timeval dt; _Bool is_set; }

user_defined_types: struct retransmit_t { struct deltatime_t delay; struct deltatime_t timeout; struct monotime_t start; struct deltatime_t delays; unsigned long nr_retransmits; unsigned long nr_duplicate_replies; unsigned long limit; unsigned long who_for; }


decompiled_code:
__int64 __fastcall jam_humber(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
const char *v3; // rcx

v2 = a2;
if ( a2 <= 0xFFFFFFFFFFFFFFFLL )
{
if ( a2 <= 0x3FFFFFFFFFFFFLL )
{
if ( a2 > 0xFFFFFFFFFFLL )
{
v2 = a2 >> 40;
v3 = (const char *)&LC2;
}
else if ( a2 <= 0x3FFFFFFF )
{
if ( a2 > 0xFFFFF )
{
v2 = a2 >> 20;
v3 = (const char *)&LC4;
}
else
{
v3 = (const char *)&LC6;
if ( a2 > 0x3FF )
{
v2 = a2 >> 10;
v3 = (const char *)&LC5;
}
}
}
else
{
v2 = a2 >> 30;
v3 = (const char *)&LC3;
}
}
else
{
v2 = a2 >> 50;
v3 = (const char *)&LC1;
}
}
else
{
v2 = a2 >> 60;
v3 = (const char *)&LC0;
}
return jam(a1, "%ju%s", v2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
const char *v3; // rcx

v2 = a2;
if ( a2 <= 0xFFFFFFFFFFFFFFFLL )
{
if ( a2 <= 0x3FFFFFFFFFFFFLL )
{
if ( a2 > 0xFFFFFFFFFFLL )
{
v2 = a2 >> 40;
v3 = (const char *)&LC2;
}
else if ( a2 <= 0x3FFFFFFF )
{
if ( a2 > 0xFFFFF )
{
v2 = a2 >> 20;
v3 = (const char *)&LC4;
}
else
{
v3 = (const char *)&LC6;
if ( a2 > 0x3FF )
{
v2 = a2 >> 10;
v3 = (const char *)&LC5;
}
}
}
else
{
v2 = a2 >> 30;
v3 = (const char *)&LC3;
}
}
else
{
v2 = a2 >> 50;
v3 = (const char *)&LC1;
}
}
else
{
v2 = a2 >> 60;
v3 = (const char *)&LC0;
}
return jam(a1, "%ju%s", v2, v3);
}

original_code:
size_t jam_humber(struct jambuf *buf, uintmax_t num)
{
 const char *suffix;
 uint64_t to_print;
 if (num >= binary_per_exa) {
  to_print = num / binary_per_exa;
  suffix = "Ei";
 } else if (num >= binary_per_peta) {
  to_print = num / binary_per_peta;
  suffix = "Pi";
 } else if (num >= binary_per_tera) {
  to_print = num / binary_per_tera;
  suffix = "Ti";
 } else if (num >= binary_per_giga) {
  to_print = num / binary_per_giga;
  suffix = "Gi";
 } else if (num >= binary_per_mega) {
  to_print = num / binary_per_mega;
  suffix = "Mi";
 } else if (num >= binary_per_kilo) {
  to_print = num / binary_per_kilo;
  suffix = "Ki";
 } else {
  to_print = num;
  suffix = "";
 }
 return jam(buf, "%ju%s", to_print, suffix);
}

canonical_original_code:
unsigned long jam_humber(struct jambuf *buf, unsigned long num)
{
 char *suffix;
 unsigned long to_print;
 if (num >= binary_per_exa) {
  to_print = num / binary_per_exa;
  suffix = "Ei";
 } else if (num >= binary_per_peta) {
  to_print = num / binary_per_peta;
  suffix = "Pi";
 } else if (num >= binary_per_tera) {
  to_print = num / binary_per_tera;
  suffix = "Ti";
 } else if (num >= binary_per_giga) {
  to_print = num / binary_per_giga;
  suffix = "Gi";
 } else if (num >= binary_per_mega) {
  to_print = num / binary_per_mega;
  suffix = "Mi";
 } else if (num >= binary_per_kilo) {
  to_print = num / binary_per_kilo;
  suffix = "Ki";
 } else {
  to_print = num;
  suffix = "";
 }
 return jam(buf, "%ju%s", to_print, suffix);
}

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

variable_types:
num
unsigned long

variable_types:
suffix
char *


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

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

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

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

original_code:
const char *str_humber(uintmax_t num, humber_buf *buf)
{
 struct jambuf jb = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_humber(&jb, num);
 return buf->buf;
}

canonical_original_code:
char *str_humber(unsigned long num, struct humber_buf *buf)
{
 struct jambuf jb = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_humber(&jb, num);
 return buf->buf;
}

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

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


decompiled_code:
__int64 __fastcall ckaid_starts_with(_QWORD *a1, const char *a2)
{
char v2; // dl
__int64 v3; // rbp
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
unsigned int v6; // ebx
char *endptr; // [rsp+8h] [rbp-50h] BYREF
char nptr[2]; // [rsp+16h] [rbp-42h] BYREF
unsigned __int64 v11; // [rsp+18h] [rbp-40h]

v11 = __readfsqword(0x28u);
if ( strlen(a2) <= 2LL * *a1 )
{
v2 = *a2;
v3 = 0LL;
if ( !*a2 )
return 1;
while ( 1 )
{
v6 = *((unsigned __int8 *)a1 + ((int)v3 >> 1) + 8);
v4 = (v3 & 1) != 0 ? (unsigned __int64)(v6 & 0xF) : (unsigned __int64)(v6 >> 4);
nptr[0] = v2;
nptr[1] = 0;
v5 = strtoul(nptr, &endptr, 16);
if ( *endptr || v4 != v5 )
break;
v2 = a2[++v3];
if ( !v2 )
return 1;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const char *a2)
{
char v2; // dl
__int64 v3; // rbp
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
unsigned int v6; // ebx
char *endptr; // [rsp+8h] [rbp-50h] BYREF
char nptr[2]; // [rsp+16h] [rbp-42h] BYREF
unsigned __int64 v11; // [rsp+18h] [rbp-40h]

v11 = __readfsqword(0x28u);
if ( strlen(a2) <= 2LL * *a1 )
{
v2 = *a2;
v3 = 0LL;
if ( !*a2 )
return 1;
while ( 1 )
{
v6 = *((unsigned __int8 *)a1 + ((int)v3 >> 1) + 8);
v4 = (v3 & 1) != 0 ? (unsigned __int64)(v6 & 0xF) : (unsigned __int64)(v6 >> 4);
nptr[0] = v2;
nptr[1] = 0;
v5 = strtoul(nptr, &endptr, 16);
if ( *endptr || v4 != v5 )
break;
v2 = a2[++v3];
if ( !v2 )
return 1;
}
}
return 0;
}

original_code:
_Bool ckaid_starts_with(const ckaid_t *ckaid, const char *start)
{
 if (strlen(start) > ckaid->len * 2) {
  return 0;
 }
 for (int i = 0; start[i] != '\0'; i++) {
  const char *p = start + i;
  unsigned byte = ckaid->ptr[i / 2];
  unsigned nibble = (i & 1) ? (byte & 0xf) : (byte >> 4);
  char n[2] = { *p, };
  char *end;
  unsigned long ni = strtoul(n, &end, 16);
  if (*end != '\0') {
   return 0;
  }
  if (ni != nibble) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool ckaid_starts_with(struct ckaid_t *ckaid, char *start)
{
 if (strlen(start) > ckaid->len * 2) {
  return 0;
 }
 for (int i = 0; start[i] != '\0'; i++) {
  char *p = start + i;
  unsigned int byte = ckaid->ptr[i / 2];
  unsigned int nibble = (i & 1) ? (byte & 0xf) : (byte >> 4);
  char n[2] = { *p, };
  char *end;
  unsigned long ni = strtoul(n, &end, 16);
  if (*end != '\0') {
   return 0;
  }
  if (ni != nibble) {
   return 0;
  }
 }
 return 1;
}

variable_types: struct ckaid_t { unsigned long len; unsigned char ptr[40]; } *

variable_types:
start
char *

variable_types: i int

variable_types:
p
char *

variable_types:
byte
unsigned int

variable_types:
nibble
unsigned int

variable_types:
n
char [2]

variable_types:
end
char *

variable_types:
ni
unsigned long


decompiled_code:
bool __fastcall ckaid_eq_nss(_QWORD *a1, __int64 a2)
{
size_t v2; // rdx
bool result; // al

v2 = *(unsigned int *)(a2 + 16);
result = 0;
if ( *a1 == v2 )
result = memcmp(a1 + 1, *(const void **)(a2 + 8), v2) == 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func1(_QWORD *a1, __int64 a2)
{
size_t v2; // rdx
bool result; // al

v2 = *(unsigned int *)(a2 + 16);
result = 0;
if ( *a1 == v2 )
result = memcmp(a1 + 1, *(const void **)(a2 + 8), v2) == 0;
return result;
}

original_code:
_Bool ckaid_eq_nss(const ckaid_t *l, const SECItem *r)
{
 return (l->len == r->len &&
  (memcmp((l->ptr), (r->data), (r->len)) == 0));
}

canonical_original_code:
_Bool ckaid_eq_nss(struct ckaid_t *l, struct SECItemStr *r)
{
 return (l->len == r->len &&
  (memcmp((l->ptr), (r->data), (r->len)) == 0));
}

variable_types: struct SECItemStr { enum SECItemType { siBuffer=0, siClearDataBuffer=1, siCipherDataBuffer=2, siDERCertBuffer=3, siEncodedCertBuffer=4, siDERNameBuffer=5, siEncodedNameBuffer=6, siAsciiNameString=7, siAsciiString=8, siDEROID=9, siUnsignedInteger=10, siUTCTime=11, siGeneralizedTime=12, siVisibleString=13, siUTF8String=14, siBMPString=15 } type; unsigned char *data; unsigned int len; } *

user_defined_types: struct ckaid_t { unsigned long len; unsigned char ptr[40]; }

user_defined_types: struct SECItemStr { enum SECItemType type; unsigned char *data; unsigned int len; }


decompiled_code:
__int64 __fastcall jam_ckaid(__int64 a1, _QWORD *a2)
{
return jam_hex_bytes(a1, a2 + 1, *a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
return jam_hex_bytes(a1, a2 + 1, *a2);
}

original_code:
size_t jam_ckaid(struct jambuf *buf, const ckaid_t *ckaid)
{
 return jam_hex_bytes(buf, ckaid->ptr, ckaid->len);
}

canonical_original_code:
unsigned long jam_ckaid(struct jambuf *buf, struct ckaid_t *ckaid)
{
 return jam_hex_bytes(buf, ckaid->ptr, ckaid->len);
}


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

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

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

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

original_code:
const char *str_ckaid(const ckaid_t *ckaid, ckaid_buf *buf)
{
 struct jambuf jam = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_ckaid(&jam, ckaid);
 return buf->buf;
}

canonical_original_code:
char *str_ckaid(struct ckaid_t *ckaid, struct ckaid_buf *buf)
{
 struct jambuf jam = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_ckaid(&jam, ckaid);
 return buf->buf;
}

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


decompiled_code:
const char *__fastcall string_to_ckaid(const char *a1, unsigned __int64 *a2)
{
size_t v2; // r8
const char *result; // rax
unsigned __int64 v4; // r8

if ( !a1 )
return "empty";
v2 = strlen(a1) + 1;
result = "too long";
v4 = v2 >> 1;
*a2 = v4;
if ( v4 <= 0x28 )
result = (const char *)ttodata(a1, 0LL, 16LL, a2 + 1, v4, a2);
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(const char *a1, unsigned __int64 *a2)
{
size_t v2; // r8
const char *result; // rax
unsigned __int64 v4; // r8

if ( !a1 )
return "empty";
v2 = strlen(a1) + 1;
result = "too long";
v4 = v2 >> 1;
*a2 = v4;
if ( v4 <= 0x28 )
result = (const char *)ttodata(a1, 0LL, 16LL, a2 + 1, v4, a2);
return result;
}

original_code:
err_t string_to_ckaid(const char *string, ckaid_t *ckaid)
{
 if (string == ((void *)0)) {
  return "empty";
 }
 ckaid->len = (strlen(string) + 1) / 2;
 if (ckaid->len > sizeof(ckaid->ptr )) {
  return "too long";
 }
 const char *err = ttodata(string, 0, 16, ckaid->ptr, ckaid->len, &ckaid->len);
 if (err != ((void *)0)) {
  return err;
 }
 return ((void *)0);
}

canonical_original_code:
char *string_to_ckaid(char *string, struct ckaid_t *ckaid)
{
 if (string == ((void *)0)) {
  return "empty";
 }
 ckaid->len = (strlen(string) + 1) / 2;
 if (ckaid->len > sizeof(ckaid->ptr )) {
  return "too long";
 }
 char *err = ttodata(string, 0, 16, ckaid->ptr, ckaid->len, &ckaid->len);
 if (err != ((void *)0)) {
  return err;
 }
 return ((void *)0);
}

variable_types:
string
char *

variable_types:
err
char *


decompiled_code:
int __fastcall cloexec_socket(int a1, int a2, int a3)
{
return socket(a1, a2 | 0x80000, a3);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3)
{
return socket(a1, a2 | 0x80000, a3);
}

original_code:
int cloexec_socket(int domain, int type, int protocol)
{
 return socket(domain, type|SOCK_CLOEXEC, protocol);
}

variable_types: domain int

variable_types: type int

variable_types: protocol int

return_type: int


decompiled_code:
__int64 __fastcall known_oid(char *a1, __int64 a2)
{
char v2; // dl
unsigned int i; // er8
char *v4; // rax
char v6; // al

if ( !a2 )
return (unsigned int)-1;
v2 = *a1;
for ( i = 0; ; ++i )
{
while ( 1 )
{
v4 = (char *)&oid_names + 16 * (int)i;
if ( *v4 == v2 )
break;
i = *((unsigned __int16 *)v4 + 1);
if ( !(_WORD)i )
return (unsigned int)-1;
}
v6 = v4[1];
if ( !--a2 )
break;
if ( !v6 )
return (unsigned int)-1;
v2 = *++a1;
}
if ( v6 )
i = -1;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
char v2; // dl
unsigned int i; // er8
char *v4; // rax
char v6; // al

if ( !a2 )
return (unsigned int)-1;
v2 = *a1;
for ( i = 0; ; ++i )
{
while ( 1 )
{
v4 = (char *)&oid_names + 16 * (int)i;
if ( *v4 == v2 )
break;
i = *((unsigned __int16 *)v4 + 1);
if ( !(_WORD)i )
return (unsigned int)-1;
}
v6 = v4[1];
if ( !--a2 )
break;
if ( !v6 )
return (unsigned int)-1;
v2 = *++a1;
}
if ( v6 )
i = -1;
return i;
}

original_code:
int known_oid(asn1_t object)
{
 int oid = 0;
 while (object.len > 0) {
  if (oid_names[oid].octet == *(const uint8_t*)object.ptr) {
   object.len--;
   object.ptr++;
   if (object.len == 0) {
    if (oid_names[oid].down == 0)
     return oid;
    else
     return (-1);
   } else {
    if (oid_names[oid].down == 0) {
     return (-1);
    } else {
     oid++;
    }
   }
  } else {
   if (oid_names[oid].next != 0)
    oid = oid_names[oid].next;
   else
    return (-1);
  }
 }
 return (-1);
}

canonical_original_code:
int known_oid(struct shunk object)
{
 int oid = 0;
 while (object.len > 0) {
  if (oid_names[oid].octet == *(unsigned char *)object.ptr) {
   object.len--;
   object.ptr++;
   if (object.len == 0) {
    if (oid_names[oid].down == 0)
     return oid;
    else
     return (-1);
   } else {
    if (oid_names[oid].down == 0) {
     return (-1);
    } else {
     oid++;
    }
   }
  } else {
   if (oid_names[oid].next != 0)
    oid = oid_names[oid].next;
   else
    return (-1);
  }
 }
 return (-1);
}

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

variable_types: oid int


original_code:
void code_asn1_length(size_t length, chunk_t *code)
{
 if (length < 128) {
  code->ptr[0] = length;
  code->len = 1;
 } else if (length < 256) {
  code->ptr[0] = 0x81;
  code->ptr[1] = (uint8_t) length;
  code->len = 2;
 } else if (length < 65536) {
  code->ptr[0] = 0x82;
  code->ptr[1] = length >> 8;
  code->ptr[2] = length & 0x00ff;
  code->len = 3;
 } else {
  code->ptr[0] = 0x83;
  code->ptr[1] = length >> 16;
  code->ptr[2] = (length >> 8) & 0x00ff;
  code->ptr[3] = length & 0x0000ff;
  code->len = 4;
 }
}

canonical_original_code:
void code_asn1_length(unsigned long length, struct chunk_t *code)
{
 if (length < 128) {
  code->ptr[0] = length;
  code->len = 1;
 } else if (length < 256) {
  code->ptr[0] = 0x81;
  code->ptr[1] = (unsigned char) length;
  code->len = 2;
 } else if (length < 65536) {
  code->ptr[0] = 0x82;
  code->ptr[1] = length >> 8;
  code->ptr[2] = length & 0x00ff;
  code->len = 3;
 } else {
  code->ptr[0] = 0x83;
  code->ptr[1] = length >> 16;
  code->ptr[2] = (length >> 8) & 0x00ff;
  code->ptr[3] = length & 0x0000ff;
  code->len = 4;
 }
}

variable_types:
length
unsigned long

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


decompiled_code:
__int64 __fastcall is_asn1_printablestring(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // edx

v2 = 0LL;
if ( !a2 )
return 1LL;
v3 = 0;
while ( ((printable_set_0[*(_BYTE *)(a1 + v2) >> 3] << (*(_BYTE *)(a1 + v2) & 7)) & 0x80u) != 0 )
{
v2 = ++v3;
if ( v3 >= a2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // edx

v2 = 0LL;
if ( !a2 )
return 1LL;
v3 = 0;
while ( ((printable_set_0[*(_BYTE *)(a1 + v2) >> 3] << (*(_BYTE *)(a1 + v2) & 7)) & 0x80u) != 0 )
{
v2 = ++v3;
if ( v3 >= a2 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool is_asn1_printablestring(shunk_t str)
{
 static const uint8_t printable_set[256 / 8] = {
  0000u,
  0000u,
  0000u,
  0000u,
  0201u,
  0337u,
  0377u,
  0345u,
  0177u,
  0377u,
  0377u,
  0340u,
  0177u,
  0377u,
  0377u,
  0340u,
 };
 const uint8_t *s = str.ptr;
 for (unsigned i = 0; i < str.len; i++) {
  uint8_t u = s[i];
  uint8_t ps = printable_set[u / 8];
  uint8_t pb = ps << (u % 8);
  if (!(pb & 0x80)) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool is_asn1_printablestring(struct shunk str)
{
 static unsigned char printable_set[-1] = {
  0000u,
  0000u,
  0000u,
  0000u,
  0201u,
  0337u,
  0377u,
  0345u,
  0177u,
  0377u,
  0377u,
  0340u,
  0177u,
  0377u,
  0377u,
  0340u,
 };
 unsigned char *s = str.ptr;
 for (unsigned int i = 0; i < str.len; i++) {
  unsigned char u = s[i];
  unsigned char ps = printable_set[u / 8];
  unsigned char pb = ps << (u % 8);
  if (!(pb & 0x80)) {
   return 0;
  }
 }
 return 1;
}

variable_types:
s
unsigned char *

variable_types:
i
unsigned int

variable_types:
u
unsigned char

variable_types:
ps
unsigned char

variable_types:
pb
unsigned char

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


decompiled_code:
const char *__fastcall unwrap_asn1_type(unsigned __int8 **a1, _DWORD *a2)
{
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rdx

*a2 = 0;
v2 = a1[1];
if ( !v2 )
return "missing ASN.1 type";
v3 = *a1;
a1[1] = v2 - 1;
*a1 = v3 + 1;
if ( !v3 )
return "missing ASN.1 type";
*a2 = *v3;
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned __int8 **a1, _DWORD *a2)
{
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rdx

*a2 = 0;
v2 = a1[1];
if ( !v2 )
return "missing ASN.1 type";
v3 = *a1;
a1[1] = v2 - 1;
*a1 = v3 + 1;
if ( !v3 )
return "missing ASN.1 type";
*a2 = *v3;
return 0LL;
}

original_code:
err_t unwrap_asn1_type(asn1_t *cursor, enum asn1_type *ty)
{
 *ty = 0;
 const uint8_t *b = ({ size_t hg_len_ = sizeof(uint8_t); typeof(cursor) hg_hunk_ = cursor; _Bool hg_ok_ = (hg_hunk_->len >= hg_len_); const void *hg_ptr_ = ((void *)0); if (hg_ok_) { hg_ptr_ = hg_hunk_->ptr; hg_hunk_->ptr += hg_len_; hg_hunk_->len -= hg_len_; } hg_ptr_; });
 if (b == ((void *)0)) {
  return "missing ASN.1 type";
 }
 *ty = *b;
 return ((void *)0);
}

canonical_original_code:
char *unwrap_asn1_type(struct shunk *cursor, enum asn1_type *ty)
{
 *ty = 0;
 unsigned char *b = ({ size_t hg_len_ = sizeof(uint8_t); typeof(cursor) hg_hunk_ = cursor; _Bool hg_ok_ = (hg_hunk_->len >= hg_len_); const void *hg_ptr_ = ((void *)0); if (hg_ok_) { hg_ptr_ = hg_hunk_->ptr; hg_hunk_->ptr += hg_len_; hg_hunk_->len -= hg_len_; } hg_ptr_; });
 if (b == ((void *)0)) {
  return "missing ASN.1 type";
 }
 *ty = *b;
 return ((void *)0);
}

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

variable_types: enum asn1_type { ASN1_EOC=0, ASN1_BOOLEAN=1, ASN1_INTEGER=2, ASN1_BIT_STRING=3, ASN1_OCTET_STRING=4, ASN1_NULL=5, ASN1_OID=6, ASN1_ENUMERATED=10, ASN1_UTF8STRING=12, ASN1_NUMERICSTRING=18, ASN1_PRINTABLESTRING=19, ASN1_T61STRING=20, ASN1_VIDEOTEXSTRING=21, ASN1_IA5STRING=22, ASN1_UTCTIME=23, ASN1_GENERALIZEDTIME=24, ASN1_GRAPHICSTRING=25, ASN1_VISIBLESTRING=26, ASN1_GENERALSTRING=27, ASN1_UNIVERSALSTRING=28, ASN1_BMPSTRING=30, ASN1_CONSTRUCTED=32, ASN1_SEQUENCE=48, ASN1_SET=49, ASN1_CONTEXT_S_0=128, ASN1_CONTEXT_S_1=129, ASN1_CONTEXT_S_2=130, ASN1_CONTEXT_S_3=131, ASN1_CONTEXT_S_4=132, ASN1_CONTEXT_S_5=133, ASN1_CONTEXT_S_6=134, ASN1_CONTEXT_S_7=135, ASN1_CONTEXT_S_8=136, ASN1_CONTEXT_C_0=160, ASN1_CONTEXT_C_1=161, ASN1_CONTEXT_C_2=162, ASN1_CONTEXT_C_3=163, ASN1_CONTEXT_C_4=164, ASN1_CONTEXT_C_5=165 } *

variable_types:
b
unsigned char *


decompiled_code:
const char *__fastcall unwrap_asn1_length(unsigned __int8 **a1, unsigned __int64 *a2)
{
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rcx
unsigned __int64 v4; // rax
unsigned __int8 *v5; // rdx
unsigned __int64 v6; // r8
const char *v7; // r9
unsigned __int8 v9; // r8
unsigned __int64 v10; // rax
unsigned __int64 v11; // rdi
unsigned __int8 *v12; // rcx
__int64 v13; // r8

*a2 = 0LL;
v2 = a1[1];
if ( !v2 )
return "insufficient number of octets to parse ASN.1 length";
v3 = *a1;
v4 = (unsigned __int64)(v2 - 1);
a1[1] = (unsigned __int8 *)v4;
v5 = v3 + 1;
*a1 = v3 + 1;
if ( !v3 )
return "insufficient number of octets to parse ASN.1 length";
v6 = *v3;
if ( (v6 & 0x80u) != 0LL )
{
v9 = v6 & 0x7F;
v7 = "number of length octets overflows size_t";
if ( v9 <= 8u )
{
v7 = "number of length octets is larger than ASN.1 object";
if ( v4 >= v9 )
{
v10 = v4 - v9;
*a1 = &v5[v9];
a1[1] = (unsigned __int8 *)v10;
if ( v9 )
{
v11 = 0LL;
v12 = &v3[(unsigned __int8)(v9 + 1)];
do
{
v13 = *v5++;
v11 = v13 + (v11 << 8);
}
while ( v12 != v5 );
v7 = "remaining ASN.1 object is shorter than length";
if ( v10 < v11 )
return v7;
}
else
{
v11 = 0LL;
}
*a2 = v11;
return 0LL;
}
}
}
else
{
v7 = "number of length octets is larger than ASN.1 object";
if ( v4 >= v6 )
{
*a2 = v6;
v7 = 0LL;
}
}
return v7;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned __int8 **a1, unsigned __int64 *a2)
{
unsigned __int8 *v2; // rax
unsigned __int8 *v3; // rcx
unsigned __int64 v4; // rax
unsigned __int8 *v5; // rdx
unsigned __int64 v6; // r8
const char *v7; // r9
unsigned __int8 v9; // r8
unsigned __int64 v10; // rax
unsigned __int64 v11; // rdi
unsigned __int8 *v12; // rcx
__int64 v13; // r8

*a2 = 0LL;
v2 = a1[1];
if ( !v2 )
return "insufficient number of octets to parse ASN.1 length";
v3 = *a1;
v4 = (unsigned __int64)(v2 - 1);
a1[1] = (unsigned __int8 *)v4;
v5 = v3 + 1;
*a1 = v3 + 1;
if ( !v3 )
return "insufficient number of octets to parse ASN.1 length";
v6 = *v3;
if ( (v6 & 0x80u) != 0LL )
{
v9 = v6 & 0x7F;
v7 = "number of length octets overflows size_t";
if ( v9 <= 8u )
{
v7 = "number of length octets is larger than ASN.1 object";
if ( v4 >= v9 )
{
v10 = v4 - v9;
*a1 = &v5[v9];
a1[1] = (unsigned __int8 *)v10;
if ( v9 )
{
v11 = 0LL;
v12 = &v3[(unsigned __int8)(v9 + 1)];
do
{
v13 = *v5++;
v11 = v13 + (v11 << 8);
}
while ( v12 != v5 );
v7 = "remaining ASN.1 object is shorter than length";
if ( v10 < v11 )
return v7;
}
else
{
v11 = 0LL;
}
*a2 = v11;
return 0LL;
}
}
}
else
{
v7 = "number of length octets is larger than ASN.1 object";
if ( v4 >= v6 )
{
*a2 = v6;
v7 = 0LL;
}
}
return v7;
}

original_code:
err_t unwrap_asn1_length(asn1_t *cursor, size_t *length)
{
 *length = 0;
 const uint8_t *np = (uint8_t *) ({ size_t hg_len_ = sizeof(uint8_t); typeof(cursor) hg_hunk_ = cursor; _Bool hg_ok_ = (hg_hunk_->len >= hg_len_); const void *hg_ptr_ = ((void *)0); if (hg_ok_) { hg_ptr_ = hg_hunk_->ptr; hg_hunk_->ptr += hg_len_; hg_hunk_->len -= hg_len_; } hg_ptr_; });
 if (np == ((void *)0)) {
  return "insufficient number of octets to parse ASN.1 length";
 }
 uint8_t n = *np;
 if ((n & 0x80) == 0) {
  if (n > cursor->len) {
   return "number of length octets is larger than ASN.1 object";
  }
  *length = n;
  return ((void *)0);
 }
 n &= 0x7f;
 if (n > sizeof(*length)) {
  return "number of length octets overflows size_t";
 }
 const uint8_t *lp = ({ size_t hg_len_ = n; typeof(cursor) hg_hunk_ = cursor; _Bool hg_ok_ = (hg_hunk_->len >= hg_len_); const void *hg_ptr_ = ((void *)0); if (hg_ok_) { hg_ptr_ = hg_hunk_->ptr; hg_hunk_->ptr += hg_len_; hg_hunk_->len -= hg_len_; } hg_ptr_; });
 if (lp == ((void *)0)) {
  return "number of length octets is larger than ASN.1 object";
 }
 size_t len = 0;
 while (n-- > 0) {
  len = 256 * len + *lp++;
 }
 if (len > cursor->len) {
  return "remaining ASN.1 object is shorter than length";
 }
 *length = len;
 return ((void *)0);
}

canonical_original_code:
char *unwrap_asn1_length(struct shunk *cursor, unsigned long *length)
{
 *length = 0;
 unsigned char *np = (uint8_t *) ({ size_t hg_len_ = sizeof(uint8_t); typeof(cursor) hg_hunk_ = cursor; _Bool hg_ok_ = (hg_hunk_->len >= hg_len_); const void *hg_ptr_ = ((void *)0); if (hg_ok_) { hg_ptr_ = hg_hunk_->ptr; hg_hunk_->ptr += hg_len_; hg_hunk_->len -= hg_len_; } hg_ptr_; });
 if (np == ((void *)0)) {
  return "insufficient number of octets to parse ASN.1 length";
 }
 unsigned char n = *np;
 if ((n & 0x80) == 0) {
  if (n > cursor->len) {
   return "number of length octets is larger than ASN.1 object";
  }
  *length = n;
  return ((void *)0);
 }
 n &= 0x7f;
 if (n > sizeof(*length)) {
  return "number of length octets overflows size_t";
 }
 unsigned char *lp = ({ size_t hg_len_ = n; typeof(cursor) hg_hunk_ = cursor; _Bool hg_ok_ = (hg_hunk_->len >= hg_len_); const void *hg_ptr_ = ((void *)0); if (hg_ok_) { hg_ptr_ = hg_hunk_->ptr; hg_hunk_->ptr += hg_len_; hg_hunk_->len -= hg_len_; } hg_ptr_; });
 if (lp == ((void *)0)) {
  return "number of length octets is larger than ASN.1 object";
 }
 unsigned long len = 0;
 while (n-- > 0) {
  len = 256 * len + *lp++;
 }
 if (len > cursor->len) {
  return "remaining ASN.1 object is shorter than length";
 }
 *length = len;
 return ((void *)0);
}

variable_types:
length
unsigned long *

variable_types:
np
unsigned char *

variable_types:
n
unsigned char

variable_types:
lp
unsigned char *

variable_types:
len
unsigned long


decompiled_code:
const char *__fastcall asn1_ok(unsigned __int8 *a1, unsigned __int8 *a2)
{
const char *result; // rax
unsigned __int8 *vars0[3]; // [rsp+0h] [rbp+0h] BYREF
int vars1C; // [rsp+1Ch] [rbp+1Ch] BYREF
unsigned __int64 vars20[3]; // [rsp+20h] [rbp+20h] BYREF

vars0[0] = a1;
vars0[1] = a2;
vars20[1] = __readfsqword(0x28u);
result = unwrap_asn1_type(vars0, &vars1C);
if ( !result )
{
result = "content is not binary ASN.1";
if ( (unsigned int)(vars1C - 48) <= 1 )
result = unwrap_asn1_length(vars0, vars20);
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(unsigned __int8 *a1, unsigned __int8 *a2)
{
const char *result; // rax
unsigned __int8 *vars0[3]; // [rsp+0h] [rbp+0h] BYREF
int vars1C; // [rsp+1Ch] [rbp+1Ch] BYREF
unsigned __int64 vars20[3]; // [rsp+20h] [rbp+20h] BYREF

vars0[0] = a1;
vars0[1] = a2;
vars20[1] = __readfsqword(0x28u);
result = func3(vars0, &vars1C);
if ( !result )
{
result = "content is not binary ASN.1";
if ( (unsigned int)(vars1C - 48) <= 1 )
result = func4(vars0, vars20);
}
return result;
}

original_code:
err_t asn1_ok(asn1_t blob)
{
 err_t e;
 enum asn1_type type;
 e = unwrap_asn1_type(&blob, &type);
 if (e != ((void *)0)) {
  return e;
 }
 switch (type) {
 case ASN1_SEQUENCE:
 case ASN1_SET:
  break;
 default:
  return "content is not binary ASN.1";
 }
 size_t length;
 e = unwrap_asn1_length(&blob, &length);
 if (e != ((void *)0)) {
  return e;
 }
 return ((void *)0);
}

canonical_original_code:
char *asn1_ok(struct shunk blob)
{
 char *e;
 enum asn1_type type;
 e = unwrap_asn1_type(&blob, &type);
 if (e != ((void *)0)) {
  return e;
 }
 switch (type) {
 case ASN1_SEQUENCE:
 case ASN1_SET:
  break;
 default:
  return "content is not binary ASN.1";
 }
 unsigned long length;
 e = unwrap_asn1_length(&blob, &length);
 if (e != ((void *)0)) {
  return e;
 }
 return ((void *)0);
}

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

variable_types:
e
char *

variable_types: enum asn1_type { ASN1_EOC=0, ASN1_BOOLEAN=1, ASN1_INTEGER=2, ASN1_BIT_STRING=3, ASN1_OCTET_STRING=4, ASN1_NULL=5, ASN1_OID=6, ASN1_ENUMERATED=10, ASN1_UTF8STRING=12, ASN1_NUMERICSTRING=18, ASN1_PRINTABLESTRING=19, ASN1_T61STRING=20, ASN1_VIDEOTEXSTRING=21, ASN1_IA5STRING=22, ASN1_UTCTIME=23, ASN1_GENERALIZEDTIME=24, ASN1_GRAPHICSTRING=25, ASN1_VISIBLESTRING=26, ASN1_GENERALSTRING=27, ASN1_UNIVERSALSTRING=28, ASN1_BMPSTRING=30, ASN1_CONSTRUCTED=32, ASN1_SEQUENCE=48, ASN1_SET=49, ASN1_CONTEXT_S_0=128, ASN1_CONTEXT_S_1=129, ASN1_CONTEXT_S_2=130, ASN1_CONTEXT_S_3=131, ASN1_CONTEXT_S_4=132, ASN1_CONTEXT_S_5=133, ASN1_CONTEXT_S_6=134, ASN1_CONTEXT_S_7=135, ASN1_CONTEXT_S_8=136, ASN1_CONTEXT_C_0=160, ASN1_CONTEXT_C_1=161, ASN1_CONTEXT_C_2=162, ASN1_CONTEXT_C_3=163, ASN1_CONTEXT_C_4=164, ASN1_CONTEXT_C_5=165 }


decompiled_code:
const char *__fastcall unwrap_asn1_value(__int64 *a1, unsigned __int64 a2, _QWORD *a3)
{
const char *result; // rax
__int64 v4; // rax

result = "ASN.1 length larger than space";
if ( a1[1] >= a2 )
{
v4 = *a1;
a3[1] = a2;
*a3 = v4;
result = 0LL;
*a1 += a2;
a1[1] -= a2;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func6(__int64 *a1, unsigned __int64 a2, _QWORD *a3)
{
const char *result; // rax
__int64 v4; // rax

result = "ASN.1 length larger than space";
if ( a1[1] >= a2 )
{
v4 = *a1;
a3[1] = a2;
*a3 = v4;
result = 0LL;
*a1 += a2;
a1[1] -= a2;
}
return result;
}

original_code:
err_t unwrap_asn1_value(asn1_t *cursor, size_t length, asn1_t *contents)
{
 if (length > cursor->len) {
  return "ASN.1 length larger than space";
 }
 contents->ptr = cursor->ptr;
 contents->len = length;
 cursor->ptr += length;
 cursor->len -= length;
 return ((void *)0);
}

canonical_original_code:
char *unwrap_asn1_value(struct shunk *cursor, unsigned long length, struct shunk *contents)
{
 if (length > cursor->len) {
  return "ASN.1 length larger than space";
 }
 contents->ptr = cursor->ptr;
 contents->len = length;
 cursor->ptr += length;
 cursor->len -= length;
 return ((void *)0);
}

variable_types:
length
unsigned long

variable_types:
contents
struct shunk *


decompiled_code:
const char *__fastcall unwrap_asn1_tlv(unsigned __int8 **a1, int a2, _QWORD *a3)
{
const char *result; // rax
int v5; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned __int64 v6[5]; // [rsp+10h] [rbp-28h] BYREF

v6[1] = __readfsqword(0x28u);
result = unwrap_asn1_type(a1, &v5);
if ( !result )
{
result = "unexpected ASN.1 type";
if ( v5 == a2 )
{
result = unwrap_asn1_length(a1, v6);
if ( !result )
result = unwrap_asn1_value((__int64 *)a1, v6[0], a3);
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(unsigned __int8 **a1, int a2, _QWORD *a3)
{
const char *result; // rax
int v5; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned __int64 v6[5]; // [rsp+10h] [rbp-28h] BYREF

v6[1] = __readfsqword(0x28u);
result = func3(a1, &v5);
if ( !result )
{
result = "unexpected ASN.1 type";
if ( v5 == a2 )
{
result = func4(a1, v6);
if ( !result )
result = func6((__int64 *)a1, v6[0], a3);
}
}
return result;
}

original_code:
err_t unwrap_asn1_tlv(asn1_t *cursor, enum asn1_type ty, asn1_t *value)
{
 err_t e;
 enum asn1_type type;
 e = unwrap_asn1_type(cursor, &type);
 if (e != ((void *)0)) {
  return e;
 }
 if (ty != type) {
  return "unexpected ASN.1 type";
 }
 size_t length;
 e = unwrap_asn1_length(cursor, &length);
 if (e != ((void *)0)) {
  return e;
 }
 e = unwrap_asn1_value(cursor, length, value);
 if (e != ((void *)0)) {
  return e;
 }
 return ((void *)0);
}

canonical_original_code:
char *unwrap_asn1_tlv(struct shunk *cursor, enum asn1_type ty, struct shunk *value)
{
 char *e;
 enum asn1_type type;
 e = unwrap_asn1_type(cursor, &type);
 if (e != ((void *)0)) {
  return e;
 }
 if (ty != type) {
  return "unexpected ASN.1 type";
 }
 unsigned long length;
 e = unwrap_asn1_length(cursor, &length);
 if (e != ((void *)0)) {
  return e;
 }
 e = unwrap_asn1_value(cursor, length, value);
 if (e != ((void *)0)) {
  return e;
 }
 return ((void *)0);
}

variable_types:
value
struct shunk *

user_defined_types: enum asn1_type { ASN1_EOC=0, ASN1_BOOLEAN=1, ASN1_INTEGER=2, ASN1_BIT_STRING=3, ASN1_OCTET_STRING=4, ASN1_NULL=5, ASN1_OID=6, ASN1_ENUMERATED=10, ASN1_UTF8STRING=12, ASN1_NUMERICSTRING=18, ASN1_PRINTABLESTRING=19, ASN1_T61STRING=20, ASN1_VIDEOTEXSTRING=21, ASN1_IA5STRING=22, ASN1_UTCTIME=23, ASN1_GENERALIZEDTIME=24, ASN1_GRAPHICSTRING=25, ASN1_VISIBLESTRING=26, ASN1_GENERALSTRING=27, ASN1_UNIVERSALSTRING=28, ASN1_BMPSTRING=30, ASN1_CONSTRUCTED=32, ASN1_SEQUENCE=48, ASN1_SET=49, ASN1_CONTEXT_S_0=128, ASN1_CONTEXT_S_1=129, ASN1_CONTEXT_S_2=130, ASN1_CONTEXT_S_3=131, ASN1_CONTEXT_S_4=132, ASN1_CONTEXT_S_5=133, ASN1_CONTEXT_S_6=134, ASN1_CONTEXT_S_7=135, ASN1_CONTEXT_S_8=136, ASN1_CONTEXT_C_0=160, ASN1_CONTEXT_C_1=161, ASN1_CONTEXT_C_2=162, ASN1_CONTEXT_C_3=163, ASN1_CONTEXT_C_4=164, ASN1_CONTEXT_C_5=165 }


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

v3 = __readfsqword(0x28u);
if ( log_to_console )
_fprintf_chk(stderr, 1LL, &LC0, a2);
if ( !log_to_syslog )
return v3 - __readfsqword(0x28u);
if ( a1 == 2 )
return _syslog_chk(3LL, 1LL, &LC0, a2);
return _syslog_chk(6LL, 1LL, &LC0, a2);
}

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

v3 = __readfsqword(0x28u);
if ( log_to_console )
_fprintf_chk(stderr, 1LL, &LC0, a2);
if ( !log_to_syslog )
return v3 - __readfsqword(0x28u);
if ( a1 == 2 )
return _syslog_chk(3LL, 1LL, &LC0, a2);
return _syslog_chk(6LL, 1LL, &LC0, a2);
}

original_code:
static void log_one_line(int level, const char *buff)
{
 if (log_to_console)
  fprintf(stderr, "%s\n", buff);
 if (log_to_syslog) {
  if (level == 2)
   syslog(3, "%s\n", buff);
  else
   syslog(6, "%s\n", buff);
 }
}

canonical_original_code:
static void log_one_line(int level, char *buff)
{
 if (log_to_console)
  fprintf(stderr, "%s\n", buff);
 if (log_to_syslog) {
  if (level == 2)
   syslog(3, "%s\n", buff);
  else
   syslog(6, "%s\n", buff);
 }
}

variable_types: level int

variable_types:
buff
char *


decompiled_code:
unsigned __int64 starter_log(int a1, __int64 a2, ...)
{
char *v2; // rbp
__int64 v3; // rsi
char *v4; // rax
gcc_va_list va; // [rsp+8h] [rbp-40F0h] BYREF
char s[16392]; // [rsp+20h] [rbp-40D8h] BYREF
unsigned __int64 v8; // [rsp+4028h] [rbp-D0h]

v8 = __readfsqword(0x28u);
if ( log_debugging == 1 || a1 != 3 )
{
v2 = s;
va_start(va, a2);
_vsnprintf_chk(s, 0x3FFFLL, 1LL, 0x4000LL, a2, va);
s[0x3FFF] = 0;
while ( 1 )
{
v4 = strchr(v2, 10);
if ( !v4 )
break;
*v4 = 0;
v3 = (__int64)v2;
v2 = v4 + 1;
log_one_line(a1, v3);
}
log_one_line(a1, (__int64)v2);
}
return v8 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func1(int a1, __int64 a2, ...)
{
char *v2; // rbp
__int64 v3; // rsi
char *v4; // rax
gcc_va_list va; // [rsp+8h] [rbp-40F0h] BYREF
char s[16392]; // [rsp+20h] [rbp-40D8h] BYREF
unsigned __int64 v8; // [rsp+4028h] [rbp-D0h]

v8 = __readfsqword(0x28u);
if ( log_debugging == 1 || a1 != 3 )
{
v2 = s;
va_start(va, a2);
_vsnprintf_chk(s, 0x3FFFLL, 1LL, 0x4000LL, a2, va);
s[0x3FFF] = 0;
while ( 1 )
{
v4 = strchr(v2, 10);
if ( !v4 )
break;
*v4 = 0;
v3 = (__int64)v2;
v2 = v4 + 1;
func0(a1, v3);
}
func0(a1, (__int64)v2);
}
return v8 - __readfsqword(0x28u);
}

original_code:
void starter_log(int level, const char *fmt, ...)
{
 va_list args;
 char buff[16384];
 char *b;
 if (!log_debugging && level == 3)
  return;
 __builtin_va_start(args,fmt);
 vsnprintf(buff, 16384 - 1, fmt, args);
 buff[16384 - 1] = '\0';
 for (b = buff;;) {
  char *p = strchr(b, '\n');
  if (p == ((void *)0))
   break;
  *p = '\0';
  log_one_line(level, b);
  b = p + 1;
 }
 log_one_line(level, b);
 __builtin_va_end(args);
}

canonical_original_code:
void starter_log(int level, char *fmt, ...)
{
 __builtin_va_list args;
 char buff[16384];
 char *b;
 if (!log_debugging && level == 3)
  return;
 __builtin_va_start(args,fmt);
 vsnprintf(buff, 16384 - 1, fmt, args);
 buff[16384 - 1] = '\0';
 for (b = buff;;) {
  char *p = strchr(b, '\n');
  if (p == ((void *)0))
   break;
  *p = '\0';
  log_one_line(level, b);
  b = p + 1;
 }
 log_one_line(level, b);
 __builtin_va_end(args);
}

variable_types:
fmt
char *

variable_types:
buff
char [16384]

variable_types:
b
char *

variable_types:
p
char *


decompiled_code:
unsigned __int64 __fastcall starter_use_log(char a1, char a2, __int64 a3)
{
char v3; // al
__int64 v4; // rcx
char v5; // bl
unsigned __int64 result; // rax
unsigned __int64 v7; // [rsp+8h] [rbp-10h]

v3 = a1;
v7 = __readfsqword(0x28u);
v4 = 0LL;
log_debugging = a1;
log_to_console = a2;
if ( log_to_syslog != (_BYTE)a3 )
{
v5 = a3;
if ( (_BYTE)a3 )
openlog("libipsecconf", 1, 8);
else
closelog();
log_to_syslog = v5;
v3 = log_debugging;
}
if ( v3 )
result = starter_log(2, (__int64)"debugging mode enabled", a3, v4);
else
result = v7 - __readfsqword(0x28u);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char a1, char a2, __int64 a3)
{
char v3; // al
__int64 v4; // rcx
char v5; // bl
unsigned __int64 result; // rax
unsigned __int64 v7; // [rsp+8h] [rbp-10h]

v3 = a1;
v7 = __readfsqword(0x28u);
v4 = 0LL;
log_debugging = a1;
log_to_console = a2;
if ( log_to_syslog != (_BYTE)a3 )
{
v5 = a3;
if ( (_BYTE)a3 )
openlog("libipsecconf", 1, 8);
else
closelog();
log_to_syslog = v5;
v3 = log_debugging;
}
if ( v3 )
result = func1(2, (__int64)"debugging mode enabled", a3, v4);
else
result = v7 - __readfsqword(0x28u);
return result;
}

original_code:
void starter_use_log(_Bool debug, _Bool console, _Bool mysyslog)
{
 log_debugging = debug;
 log_to_console = console;
 if (mysyslog != log_to_syslog) {
  if (mysyslog)
   openlog("libipsecconf", 0x01, (1<<3));
  else
   closelog();
  log_to_syslog = mysyslog;
 }
 if (log_debugging)
  starter_log(2, "debugging mode enabled");
}


decompiled_code:
__int64 __fastcall clone_shunk_tokens(void *src, size_t n, __int64 a3, _QWORD *a4)
{
unsigned int v6; // er12
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rcx
__int64 v10; // r15
void *v11; // r9
__int64 v12; // r12
void *v13; // rax
size_t v14; // rdx
__int64 v15; // rdx
__int64 v16; // r8
__int64 *v17; // rax
void *v19; // [rsp+8h] [rbp-60h]
void *v20; // [rsp+10h] [rbp-58h] BYREF
size_t v21; // [rsp+18h] [rbp-50h]
unsigned __int64 v22; // [rsp+28h] [rbp-40h]

v22 = __readfsqword(0x28u);
if ( !src )
return 0LL;
if ( (cur_debugging & 1) != 0 )
DBG_log("%s() input: %.*s", "clone_shunk_tokens", (unsigned int)n, src);
v20 = src;
v6 = 0;
v21 = n;
while ( shunk_token(&v20, 0LL, a3) )
v6 -= (v7 == 0) - 1;
if ( !v6 )
return 0LL;
v8 = alloc_bytes(16LL * (v6 + 1) + n, *a4);
v9 = 16LL * (v6 + 1);
v10 = v8;
v11 = (void *)(v8 + v9);
if ( (cur_debugging & 1) != 0 )
{
v19 = (void *)(v8 + v9);
DBG_log("%s() nr tokens %u, sizeof-tokens %zu sizeof-strings %zu", "clone_shunk_tokens", v6, v9, n);
v11 = v19;
}
v12 = 0LL;
v13 = memcpy(v11, src, n);
v20 = (void *)shunk2(v13, (unsigned int)n);
v21 = v14;
while ( 1 )
{
v16 = shunk_token(&v20, 0LL, a3);
if ( !v16 )
break;
if ( v15 )
{
v17 = (__int64 *)(v10 + 16LL * (unsigned int)v12);
*v17 = v16;
v17[1] = v15;
if ( (cur_debugging & 1) != 0 )
DBG_log("%s() %d: %.*s", "clone_shunk_tokens", (unsigned int)v12, (unsigned int)v15);
v12 = (unsigned int)(v12 + 1);
}
}
*(__m128i *)(v10 + 16 * v12) = _mm_loadu_si128(&null_shunk);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *src, size_t n, __int64 a3, _QWORD *a4)
{
unsigned int v6; // er12
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rcx
__int64 v10; // r15
void *v11; // r9
__int64 v12; // r12
void *v13; // rax
size_t v14; // rdx
__int64 v15; // rdx
__int64 v16; // r8
__int64 *v17; // rax
void *v19; // [rsp+8h] [rbp-60h]
void *v20; // [rsp+10h] [rbp-58h] BYREF
size_t v21; // [rsp+18h] [rbp-50h]
unsigned __int64 v22; // [rsp+28h] [rbp-40h]

v22 = __readfsqword(0x28u);
if ( !src )
return 0LL;
if ( (cur_debugging & 1) != 0 )
DBG_log("%s() input: %.*s", "clone_shunk_tokens", (unsigned int)n, src);
v20 = src;
v6 = 0;
v21 = n;
while ( shunk_token(&v20, 0LL, a3) )
v6 -= (v7 == 0) - 1;
if ( !v6 )
return 0LL;
v8 = alloc_bytes(16LL * (v6 + 1) + n, *a4);
v9 = 16LL * (v6 + 1);
v10 = v8;
v11 = (void *)(v8 + v9);
if ( (cur_debugging & 1) != 0 )
{
v19 = (void *)(v8 + v9);
DBG_log("%s() nr tokens %u, sizeof-tokens %zu sizeof-strings %zu", "clone_shunk_tokens", v6, v9, n);
v11 = v19;
}
v12 = 0LL;
v13 = memcpy(v11, src, n);
v20 = (void *)shunk2(v13, (unsigned int)n);
v21 = v14;
while ( 1 )
{
v16 = shunk_token(&v20, 0LL, a3);
if ( !v16 )
break;
if ( v15 )
{
v17 = (__int64 *)(v10 + 16LL * (unsigned int)v12);
*v17 = v16;
v17[1] = v15;
if ( (cur_debugging & 1) != 0 )
DBG_log("%s() %d: %.*s", "clone_shunk_tokens", (unsigned int)v12, (unsigned int)v15);
v12 = (unsigned int)(v12 + 1);
}
}
*(__m128i *)(v10 + 16 * v12) = _mm_loadu_si128(&null_shunk);
return v10;
}

original_code:
shunk_t *clone_shunk_tokens(shunk_t input, const char *delims, where_t where)
{
 if (input.ptr == ((void *)0)) {
  return ((void *)0);
 }
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("%s() input: ""%.*s", __func__, ((int) (input).len), (const char *) ((input).ptr)); } };
 unsigned nr_tokens = 0;
 shunk_t cursor = input;
 while (1) {
  shunk_t token = shunk_token(&cursor, ((void *)0) , delims);
  if (token.ptr == ((void *)0)) {
   break;
  }
  if (token.len == 0) {
   continue;
  }
  nr_tokens++;
 }
 if (nr_tokens == 0) {
  return ((void *)0);
 }
 size_t sizeof_tokens = (nr_tokens + 1) * sizeof(shunk_t);
 void *buf = alloc_bytes(sizeof_tokens + input.len, where->func);
 shunk_t *tokens = buf;
 char *strings = buf + sizeof_tokens;
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("%s() nr tokens %u, sizeof-tokens %zu sizeof-strings %zu", __func__, nr_tokens, sizeof_tokens, input.len); } };
 memcpy(strings, input.ptr, input.len);
 cursor = shunk2(strings, input.len);
 unsigned nr = 0;
 while (1) {
  shunk_t token = shunk_token(&cursor, ((void *)0) , delims);
  if (token.ptr == ((void *)0)) {
   break;
  }
  if (token.len == 0) {
   continue;
  }
  tokens[nr] = token;
  { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("%s() %d: ""%.*s", __func__, nr, ((int) (token).len), (const char *) ((token).ptr)); } };
  nr++;
 }
 tokens[nr] = null_shunk;
 return tokens;
}

canonical_original_code:
struct shunk *clone_shunk_tokens(struct shunk input, char *delims, struct where *where)
{
 if (input.ptr == ((void *)0)) {
  return ((void *)0);
 }
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("%s() input: ""%.*s", __func__, ((int) (input).len), (char *) ((input).ptr)); } };
 unsigned int nr_tokens = 0;
 struct shunk cursor = input;
 while (1) {
  struct shunk token = shunk_token(&cursor, ((void *)0) , delims);
  if (token.ptr == ((void *)0)) {
   break;
  }
  if (token.len == 0) {
   continue;
  }
  nr_tokens++;
 }
 if (nr_tokens == 0) {
  return ((void *)0);
 }
 unsigned long sizeof_tokens = (nr_tokens + 1) * sizeof(shunk_t);
 void *buf = alloc_bytes(sizeof_tokens + input.len, where->func);
 struct shunk *tokens = buf;
 char *strings = buf + sizeof_tokens;
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("%s() nr tokens %u, sizeof-tokens %zu sizeof-strings %zu", __func__, nr_tokens, sizeof_tokens, input.len); } };
 memcpy(strings, input.ptr, input.len);
 cursor = shunk2(strings, input.len);
 unsigned int nr = 0;
 while (1) {
  struct shunk token = shunk_token(&cursor, ((void *)0) , delims);
  if (token.ptr == ((void *)0)) {
   break;
  }
  if (token.len == 0) {
   continue;
  }
  tokens[nr] = token;
  { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("%s() %d: ""%.*s", __func__, nr, ((int) (token).len), (char *) ((token).ptr)); } };
  nr++;
 }
 tokens[nr] = null_shunk;
 return tokens;
}

variable_types:
input
struct shunk

variable_types:
delims
char *

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

variable_types:
buf
void *

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

variable_types:
strings
char *

variable_types:
nr
unsigned int


decompiled_code:
__int64 __fastcall jam_nss_error_code(__int64 a1, unsigned int a2)
{
__int64 v3; // rsi
__int64 v4; // rbx
__int64 v5; // rax
__int64 v7; // rdx

if ( !a2 )
return jam_string(a1, "error code not saved by NSS");
v3 = PR_ErrorToName(a2);
if ( v3 )
{
v4 = jam_string(a1, v3);
}
else
{
v7 = a2 + 0x2000;
if ( (unsigned int)v7 > 0x3E7 )
v4 = jam(a1, "NSS %d 0x%x", a2, a2);
else
v4 = jam(a1, "SEC_ERROR_BASE+%d", v7);
}
jam_string(a1, ": ");
v5 = PR_ErrorToString(a2, 0LL);
return v4 + jam_string(a1, v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 v3; // rsi
__int64 v4; // rbx
__int64 v5; // rax
__int64 v7; // rdx

if ( !a2 )
return jam_string(a1, "error code not saved by NSS");
v3 = PR_ErrorToName(a2);
if ( v3 )
{
v4 = jam_string(a1, v3);
}
else
{
v7 = a2 + 0x2000;
if ( (unsigned int)v7 > 0x3E7 )
v4 = jam(a1, "NSS %d 0x%x", a2, a2);
else
v4 = jam(a1, "SEC_ERROR_BASE+%d", v7);
}
jam_string(a1, ": ");
v5 = PR_ErrorToString(a2, 0LL);
return v4 + jam_string(a1, v5);
}

original_code:
size_t jam_nss_error_code(struct jambuf *buf, PRErrorCode code)
{
 if (code == 0) {
  return jam_string(buf, "error code not saved by NSS");
 }
 size_t size = 0;
 const char *name = PR_ErrorToName(code);
 if (name != ((void *)0)) {
  size += jam_string(buf, name);
 } else if ((((code) >= (-0x2000)) && ((code) < ((-0x2000) + 1000)))) {
  size += jam(buf, "SEC_ERROR_BASE+%d", code - (-0x2000));
 } else {
  size += jam(buf, "NSS %d 0x%x", code, code);
 }
 jam_string(buf, ": ");
 const char *string = PR_ErrorToString(code, 0);
 size += jam_string(buf, string);
 return size;
}

canonical_original_code:
unsigned long jam_nss_error_code(struct jambuf *buf, int code)
{
 if (code == 0) {
  return jam_string(buf, "error code not saved by NSS");
 }
 unsigned long size = 0;
 char *name = PR_ErrorToName(code);
 if (name != ((void *)0)) {
  size += jam_string(buf, name);
 } else if ((((code) >= (-0x2000)) && ((code) < ((-0x2000) + 1000)))) {
  size += jam(buf, "SEC_ERROR_BASE+%d", code - (-0x2000));
 } else {
  size += jam(buf, "NSS %d 0x%x", code, code);
 }
 jam_string(buf, ": ");
 char *string = PR_ErrorToString(code, 0);
 size += jam_string(buf, string);
 return size;
}

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

variable_types: code int

variable_types:
size
unsigned long

variable_types:
name
char *

variable_types:
string
char *


decompiled_code:
__int64 __fastcall jam_list_entry(__int64 a1, const void **a2)
{
if ( !a2 )
return jam(a1, "(null)");
if ( a2[2] )
(*((void (**)(void))a2[3] + 1))();
else
jam(a1, "HEAD");
return jam(a1, " %p<-%p->%p", a2[1], a2, *a2);
}

original_code:
void jam_list_entry(struct jambuf *buf, const struct list_entry *entry)
{
 if (entry == ((void *)0)) {
  jam(buf, "(null)");
 } else {
  if (entry->data == ((void *)0)) {
   jam(buf, "HEAD");
  } else {
   entry->info->jam(buf, entry->data);
  }
  jam(buf, " %p<-%p->%p", entry->next[NEW2OLD], entry, entry->next[OLD2NEW]);
 }
}

canonical_original_code:
void jam_list_entry(struct jambuf *buf, struct list_entry *entry)
{
 if (entry == ((void *)0)) {
  jam(buf, "(null)");
 } else {
  if (entry->data == ((void *)0)) {
   jam(buf, "HEAD");
  } else {
   entry->info->jam(buf, entry->data);
  }
  jam(buf, " %p<-%p->%p", entry->next[NEW2OLD], entry, entry->next[OLD2NEW]);
 }
}

variable_types: struct list_entry { struct list_entry *next[2]; void *data; struct list_info { char *name; void (*jam)(struct jambuf *buf, void *data); long offset; } *info; } *


decompiled_code:
unsigned __int64 __fastcall fd_leak(int *a1, __int64 a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
if ( (cur_debugging & 1) != 0 )
DBG_log(
"leaking fd@%p's FD; will be closed when pluto exits (%s() +%lu %s)",
a1,
*(const char **)a2,
*(_QWORD *)(a2 + 16),
*(const char **)(a2 + 8));
if ( a1 )
a1[1] = dup(a1[1]);
return v3 - __readfsqword(0x28u);
}

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

v3 = __readfsqword(0x28u);
if ( (cur_debugging & 1) != 0 )
DBG_log(
"leaking fd@%p's FD; will be closed when pluto exits (%s() +%lu %s)",
a1,
*(const char **)a2,
*(_QWORD *)(a2 + 16),
*(const char **)(a2 + 8));
if ( a1 )
a1[1] = dup(a1[1]);
return v3 - __readfsqword(0x28u);
}

original_code:
void fd_leak(struct fd *fd, where_t where)
{
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("leaking ""fd@%p""'s FD; will be closed when pluto exits ""(%s() +%lu %s)""", (fd), (where)->func, (where)->line, (where)->file); } };
 if (fd != ((void *)0)) {
  fd->fd = dup(fd->fd);
 }
}

canonical_original_code:
void fd_leak(struct fd *fd, struct where *where)
{
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("leaking ""fd@%p""'s FD; will be closed when pluto exits ""(%s() +%lu %s)""", (fd), (where)->func, (where)->line, (where)->file); } };
 if (fd != ((void *)0)) {
  fd->fd = dup(fd->fd);
 }
}

variable_types: struct fd { unsigned int magic; int fd; struct refcnt { unsigned int count; struct refcnt_base { char *what; } *base; } refcnt; } *

user_defined_types: struct fd { unsigned int magic; int fd; struct refcnt refcnt; }

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

user_defined_types: struct refcnt { unsigned int count; struct refcnt_base *base; }


decompiled_code:
ssize_t __fastcall fd_sendmsg(_DWORD *a1, const struct msghdr *a2, int a3)
{
ssize_t result; // rax

if ( !a1 || *a1 != 15731998 )
return -14LL;
result = sendmsg(a1[1], a2, a3);
if ( result < 0 )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(_DWORD *a1, const struct msghdr *a2, int a3)
{
ssize_t result; // rax

if ( !a1 || *a1 != 15731998 )
return -14LL;
result = sendmsg(a1[1], a2, a3);
if ( result < 0 )
result = -*_errno_location();
return result;
}

original_code:
ssize_t fd_sendmsg(const struct fd *fd, const struct msghdr *msg, int flags)
{
 if (fd == ((void *)0) || fd->magic != 0xf00d1e) {
  return -14;
 }
 ssize_t s = sendmsg(fd->fd, msg, flags);
 return s < 0 ? -(*__errno_location ()) : s;
}

canonical_original_code:
long fd_sendmsg(struct fd *fd, struct msghdr *msg, int flags)
{
 if (fd == ((void *)0) || fd->magic != 0xf00d1e) {
  return -14;
 }
 long s = sendmsg(fd->fd, msg, flags);
 return s < 0 ? -(*__errno_location ()) : s;
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

variable_types: flags int

variable_types: s long

return_type: long

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
ssize_t __fastcall fd_read(_DWORD *a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( !a1 || *a1 != 15731998 )
return -14LL;
result = read(a1[1], a2, a3);
if ( result < 0 )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func3(_DWORD *a1, void *a2, size_t a3)
{
ssize_t result; // rax

if ( !a1 || *a1 != 15731998 )
return -14LL;
result = read(a1[1], a2, a3);
if ( result < 0 )
result = -*_errno_location();
return result;
}

original_code:
ssize_t fd_read(const struct fd *fd, void *buf, size_t nbytes)
{
 if (fd == ((void *)0) || fd->magic != 0xf00d1e) {
  return -14;
 }
 ssize_t s = read(fd->fd, buf, nbytes);
 return s < 0 ? -(*__errno_location ()) : s;
}

canonical_original_code:
long fd_read(struct fd *fd, void *buf, unsigned long nbytes)
{
 if (fd == ((void *)0) || fd->magic != 0xf00d1e) {
  return -14;
 }
 long s = read(fd->fd, buf, nbytes);
 return s < 0 ? -(*__errno_location ()) : s;
}

variable_types:
nbytes
unsigned long


decompiled_code:
__int64 __fastcall fd_p(_DWORD *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 1LL;
if ( *a1 != 15731998 )
{
llog_pexpect(&global_logger, here_1, "wrong magic for fd@%p", a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 1LL;
if ( *a1 != 15731998 )
{
llog_pexpect(&global_logger, here_1, "wrong magic for fd@%p", a1);
result = 0LL;
}
return result;
}

original_code:
_Bool fd_p(const struct fd *fd)
{
 if (fd == ((void *)0)) {
  return 0;
 }
 if (fd->magic != 0xf00d1e) {
  llog_pexpect(&global_logger, ({ static const struct where here = { .func = __func__, .file = "lib/libswan/fd.c", .line = 128, }; &here; }),
        "wrong magic for ""fd@%p""", (fd));
  return 0;
 }
 return 1;
}

canonical_original_code:
_Bool fd_p(struct fd *fd)
{
 if (fd == ((void *)0)) {
  return 0;
 }
 if (fd->magic != 0xf00d1e) {
  llog_pexpect(&global_logger, ({ static struct where here = { .func = __func__, .file = "lib/libswan/fd.c", .line = 128, }; &here; }),
        "wrong magic for ""fd@%p""", (fd));
  return 0;
 }
 return 1;
}

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


decompiled_code:
__int64 __fastcall same_fd(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned int v3; // eax
unsigned int v4; // er8

result = fd_p(a1);
if ( (_BYTE)result )
{
v3 = fd_p(a2);
v4 = v3;
LOBYTE(v3) = a1 == a2;
result = v4 & v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned int v3; // eax
unsigned int v4; // er8

result = func4(a1);
if ( (_BYTE)result )
{
v3 = func4(a2);
v4 = v3;
LOBYTE(v3) = a1 == a2;
result = v4 & v3;
}
return result;
}

original_code:
_Bool same_fd(const struct fd *l, const struct fd *r)
{
 return fd_p(l) && fd_p(r) && l == r;
}

canonical_original_code:
_Bool same_fd(struct fd *l, struct fd *r)
{
 return fd_p(l) && fd_p(r) && l == r;
}

variable_types:
r
struct fd *


decompiled_code:
size_t __fastcall netlink_read_reply(int fd, const void **a2, __int64 a3, int a4, int a5)
{
size_t v6; // rbx
char *v7; // rcx
char *v8; // rsi
ssize_t v9; // rax
char *v11; // rdx
unsigned __int64 v12; // rsi
__int16 v13; // si
char *v17; // [rsp+18h] [rbp-60h]
socklen_t addr_len; // [rsp+28h] [rbp-50h] BYREF
struct sockaddr addr[4]; // [rsp+2Ch] [rbp-4Ch] BYREF

v6 = 0LL;
v7 = (char *)*a2;
*(_QWORD *)&addr[0].sa_data[10] = __readfsqword(0x28u);
while ( 1 )
{
v8 = v7;
do
{
addr_len = 12;
v9 = recvfrom(fd, &v8[v6], a3 - v6, 0, addr, &addr_len);
if ( v9 <= 0 || addr_len != 12 )
return -1LL;
v8 = (char *)*a2;
}
while ( *(_DWORD *)&addr[0].sa_data[2] );
v7 = (char *)*a2;
v11 = &v8[v6];
if ( v9 <= 15 )
return -1LL;
v12 = *(unsigned int *)v11;
if ( (unsigned int)v12 <= 0xF )
return -1LL;
if ( v9 < v12 )
return -1LL;
v13 = *((_WORD *)v11 + 2);
if ( v13 == 2 )
return -1LL;
v6 += v9;
if ( v13 == 3 || (v11[6] & 2) == 0 || *((_DWORD *)v11 + 2) == a4 && *((_DWORD *)v11 + 3) == a5 )
break;
if ( a3 - 0x8000 <= v6 )
{
a3 *= 2LL;
v17 = (char *)alloc_bytes(a3, "netlink query", v11, v7);
memcpy(v17, *a2, v6);
pfree(*a2);
v7 = v17;
*a2 = v17;
}
}
return v6;
}

canonical_decompiled_code:
size_t __fastcall func0(int fd, const void **a2, __int64 a3, int a4, int a5)
{
size_t v6; // rbx
char *v7; // rcx
char *v8; // rsi
ssize_t v9; // rax
char *v11; // rdx
unsigned __int64 v12; // rsi
__int16 v13; // si
char *v17; // [rsp+18h] [rbp-60h]
socklen_t addr_len; // [rsp+28h] [rbp-50h] BYREF
struct sockaddr addr[4]; // [rsp+2Ch] [rbp-4Ch] BYREF

v6 = 0LL;
v7 = (char *)*a2;
*(_QWORD *)&addr[0].sa_data[10] = __readfsqword(0x28u);
while ( 1 )
{
v8 = v7;
do
{
addr_len = 12;
v9 = recvfrom(fd, &v8[v6], a3 - v6, 0, addr, &addr_len);
if ( v9 <= 0 || addr_len != 12 )
return -1LL;
v8 = (char *)*a2;
}
while ( *(_DWORD *)&addr[0].sa_data[2] );
v7 = (char *)*a2;
v11 = &v8[v6];
if ( v9 <= 15 )
return -1LL;
v12 = *(unsigned int *)v11;
if ( (unsigned int)v12 <= 0xF )
return -1LL;
if ( v9 < v12 )
return -1LL;
v13 = *((_WORD *)v11 + 2);
if ( v13 == 2 )
return -1LL;
v6 += v9;
if ( v13 == 3 || (v11[6] & 2) == 0 || *((_DWORD *)v11 + 2) == a4 && *((_DWORD *)v11 + 3) == a5 )
break;
if ( a3 - 0x8000 <= v6 )
{
a3 *= 2LL;
v17 = (char *)alloc_bytes(a3, "netlink query", v11, v7);
memcpy(v17, *a2, v6);
pfree(*a2);
v7 = v17;
*a2 = v17;
}
}
return v6;
}

original_code:
ssize_t netlink_read_reply(int sock, char **pbuf, size_t bufsize,
      unsigned int seqnum, __u32 pid)
{
 size_t msglen = 0;
 for (;;) {
  struct sockaddr_nl sa;
  ssize_t readlen;
  do {
   socklen_t salen = sizeof(sa);
   readlen = recvfrom(sock, *pbuf + msglen,
     bufsize - msglen, 0,
     (struct sockaddr *)&sa, &salen);
   if (readlen <= 0 || salen != sizeof(sa))
    return -1;
  } while (sa.nl_pid != 0);
  struct nlmsghdr *nlhdr = (struct nlmsghdr *)(*pbuf + msglen);
  if (!(((size_t)readlen) >= (int)sizeof(struct nlmsghdr) && (nlhdr)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlhdr)->nlmsg_len <= ((size_t)readlen)) ||
   nlhdr->nlmsg_type == 0x2)
   return -1;
  msglen += readlen;
  if (nlhdr->nlmsg_type == 0x3)
   break;
  if ((nlhdr->nlmsg_flags & 0x02) == 0)
   break;
  if (nlhdr->nlmsg_seq == seqnum && nlhdr->nlmsg_pid == pid)
   break;
  if (msglen >= bufsize - 32768) {
   bufsize = bufsize * 2;
   char *newbuf = alloc_bytes(bufsize, "netlink query");
   memcpy(newbuf, *pbuf, msglen);
   pfree(*pbuf);
   *pbuf = newbuf;
  }
 }
 return msglen;
}

canonical_original_code:
long netlink_read_reply(int sock, char **pbuf, unsigned long bufsize, unsigned int seqnum, unsigned int pid)
{
 unsigned long msglen = 0;
 for (;;) {
  struct sockaddr_nl sa;
  long readlen;
  do {
   unsigned int salen = sizeof(sa);
   readlen = recvfrom(sock, *pbuf + msglen,
     bufsize - msglen, 0,
     (struct sockaddr *)&sa, &salen);
   if (readlen <= 0 || salen != sizeof(sa))
    return -1;
  } while (sa.nl_pid != 0);
  struct nlmsghdr *nlhdr = (struct nlmsghdr *)(*pbuf + msglen);
  if (!(((unsigned long)readlen) >= (int)sizeof(struct nlmsghdr) && (nlhdr)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlhdr)->nlmsg_len <= ((unsigned long)readlen)) ||
   nlhdr->nlmsg_type == 0x2)
   return -1;
  msglen += readlen;
  if (nlhdr->nlmsg_type == 0x3)
   break;
  if ((nlhdr->nlmsg_flags & 0x02) == 0)
   break;
  if (nlhdr->nlmsg_seq == seqnum && nlhdr->nlmsg_pid == pid)
   break;
  if (msglen >= bufsize - 32768) {
   bufsize = bufsize * 2;
   char *newbuf = alloc_bytes(bufsize, "netlink query");
   memcpy(newbuf, *pbuf, msglen);
   pfree(*pbuf);
   *pbuf = newbuf;
  }
 }
 return msglen;
}

variable_types: sock int

variable_types:
pbuf
char **

variable_types:
bufsize
unsigned long

variable_types:
seqnum
unsigned int

variable_types:
pid
unsigned int

variable_types:
msglen
unsigned long

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

variable_types: readlen long

variable_types:
salen
unsigned int

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types:
newbuf
char *

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


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

v1 = __readfsqword(0x28u);
NSS_Shutdown();
if ( (flags & 2) != 0 )
result = v1 - __readfsqword(0x28u);
else
result = PR_Cleanup();
return result;
}

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

v1 = __readfsqword(0x28u);
NSS_Shutdown();
if ( (flags & 2) != 0 )
result = v1 - __readfsqword(0x28u);
else
result = PR_Cleanup();
return result;
}

original_code:
void lsw_nss_shutdown(void)
{
 NSS_Shutdown();
 if (!(flags & LSW_NSS_SKIP_PR_CLEANUP)) {
  PR_Cleanup();
 }
}

canonical_original_code:
void lsw_nss_shutdown()
{
 NSS_Shutdown();
 if (!(flags & LSW_NSS_SKIP_PR_CLEANUP)) {
  PR_Cleanup();
 }
}


decompiled_code:
void *__fastcall zalloc_chunk(size_t n)
{
void *v1; // rax

v1 = (void *)alloc_bytes();
return memset(v1, 0, n);
}

canonical_decompiled_code:
void *__fastcall func0(size_t n)
{
void *v1; // rax

v1 = (void *)alloc_bytes();
return memset(v1, 0, n);
}

original_code:
static chunk_t zalloc_chunk(size_t length, const char *name)
{
 chunk_t chunk;
 chunk.len = length;
 chunk.ptr = alloc_bytes(length, name);
 memset(chunk.ptr, 0, chunk.len);
 return chunk;
}

canonical_original_code:
static struct chunk_t zalloc_chunk(unsigned long length, char *name)
{
 struct chunk_t chunk;
 chunk.len = length;
 chunk.ptr = alloc_bytes(length, name);
 memset(chunk.ptr, 0, chunk.len);
 return chunk;
}

variable_types:
length
unsigned long

variable_types:
name
char *

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


decompiled_code:
__int64 __fastcall verify_bytes(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v7; // rdx
unsigned int v8; // er12
__int64 v10; // rcx
__int64 v11; // r8

if ( a3 == a5 )
{
v7 = 0LL;
if ( a3 )
{
while ( 1 )
{
v10 = *(unsigned __int8 *)(a2 + v7);
v11 = *(unsigned __int8 *)(a4 + v7);
if ( (_BYTE)v10 != (_BYTE)v11 )
break;
if ( a3 == ++v7 )
goto LABEL_3;
}
v8 = 0;
if ( (cur_debugging & 0x10) != 0 )
DBG_log("verify_chunk_data: %s: bytes at %zd differ, expected %02x found %02x", a1, v7, v10, v11);
}
else
{
LABEL_3:
v8 = 1;
if ( (cur_debugging & 0x10) != 0 )
DBG_log("verify_chunk_data: %s: ok", a1);
}
}
else
{
v8 = 0;
if ( (cur_debugging & 0x10) != 0 )
DBG_log("verify_chunk: %s: expected length %zd but got %zd", a1, a3, a5);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v7; // rdx
unsigned int v8; // er12
__int64 v10; // rcx
__int64 v11; // r8

if ( a3 == a5 )
{
v7 = 0LL;
if ( a3 )
{
while ( 1 )
{
v10 = *(unsigned __int8 *)(a2 + v7);
v11 = *(unsigned __int8 *)(a4 + v7);
if ( (_BYTE)v10 != (_BYTE)v11 )
break;
if ( a3 == ++v7 )
goto LABEL_3;
}
v8 = 0;
if ( (cur_debugging & 0x10) != 0 )
DBG_log("verify_chunk_data: %s: bytes at %zd differ, expected %02x found %02x", a1, v7, v10, v11);
}
else
{
LABEL_3:
v8 = 1;
if ( (cur_debugging & 0x10) != 0 )
DBG_log("verify_chunk_data: %s: ok", a1);
}
}
else
{
v8 = 0;
if ( (cur_debugging & 0x10) != 0 )
DBG_log("verify_chunk: %s: expected length %zd but got %zd", a1, a3, a5);
}
return v8;
}

original_code:
_Bool verify_bytes(const char *desc,
    const void *expected, size_t expected_size,
    const void *actual, size_t actual_size)
{
 if (expected_size != actual_size) {
  { if ((cur_debugging & (((lset_t)1 << (DBG_CRYPT_IX))))) { DBG_log("verify_chunk: %s: expected length %zd but got %zd", desc, expected_size, actual_size); } };
  return 0;
 }
 size_t i;
 for (i = 0; i < expected_size; i++) {
  uint8_t e = ((const uint8_t*)expected)[i];
  uint8_t a = ((const uint8_t*)actual)[i];
  if (e != a) {
   { if ((cur_debugging & (((lset_t)1 << (DBG_CRYPT_IX))))) { DBG_log("verify_chunk_data: %s: bytes at %zd differ, expected %02x found %02x", desc, i, e, a); } };
   return 0;
  }
 }
 { if ((cur_debugging & (((lset_t)1 << (DBG_CRYPT_IX))))) { DBG_log("verify_chunk_data: %s: ok", desc); } };
 return 1;
}

canonical_original_code:
_Bool verify_bytes(char *desc, void *expected, unsigned long expected_size, void *actual, unsigned long actual_size)
{
 if (expected_size != actual_size) {
  { if ((cur_debugging & (((unsigned long)1 << (DBG_CRYPT_IX))))) { DBG_log("verify_chunk: %s: expected length %zd but got %zd", desc, expected_size, actual_size); } };
  return 0;
 }
 unsigned long i;
 for (i = 0; i < expected_size; i++) {
  unsigned char e = ((const uint8_t*)expected)[i];
  unsigned char a = ((const uint8_t*)actual)[i];
  if (e != a) {
   { if ((cur_debugging & (((unsigned long)1 << (DBG_CRYPT_IX))))) { DBG_log("verify_chunk_data: %s: bytes at %zd differ, expected %02x found %02x", desc, i, e, a); } };
   return 0;
  }
 }
 { if ((cur_debugging & (((unsigned long)1 << (DBG_CRYPT_IX))))) { DBG_log("verify_chunk_data: %s: ok", desc); } };
 return 1;
}

variable_types:
desc
char *

variable_types:
expected
void *

variable_types:
actual
void *

variable_types:
i
unsigned long

variable_types:
e
unsigned char

variable_types:
a
unsigned char


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

v2 = __readfsqword(0x28u);
if ( *(_QWORD *)(a1 + 8) )
{
pfree();
*(_QWORD *)(a1 + 8) = 0LL;
}
return v2 - __readfsqword(0x28u);
}

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

v2 = __readfsqword(0x28u);
if ( *(_QWORD *)(a1 + 8) )
{
pfree();
*(_QWORD *)(a1 + 8) = 0LL;
}
return v2 - __readfsqword(0x28u);
}

original_code:
static void free_sa_trans(struct db_trans *tr)
{
 if (tr->attrs != ((void *)0)) {
  pfree(tr->attrs);
  tr->attrs = ((void *)0);
 }
}

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

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

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