decompiled_code:
__int64 __fastcall ckaid_starts_with(_QWORD *a1, const char *a2)
{
size_t v2; // rax
unsigned int v3; // edx
char v4; // dl
__int64 v5; // rbx
int v6; // er14
unsigned __int64 v7; // rax
unsigned __int8 v8; // r14
char *endptr; // [rsp+8h] [rbp-40h] BYREF
char nptr[2]; // [rsp+16h] [rbp-32h] BYREF
unsigned __int64 v12; // [rsp+18h] [rbp-30h]

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

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const char *a2)
{
size_t v2; // rax
unsigned int v3; // edx
char v4; // dl
__int64 v5; // rbx
int v6; // er14
unsigned __int64 v7; // rax
unsigned __int8 v8; // r14
char *endptr; // [rsp+8h] [rbp-40h] BYREF
char nptr[2]; // [rsp+16h] [rbp-32h] BYREF
unsigned __int64 v12; // [rsp+18h] [rbp-30h]

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

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


repo: libreswan/libreswan

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

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

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

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

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

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

return_type: unsigned long


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

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

return_type: char *


decompiled_code:
const char *__fastcall string_to_ckaid(const char *a1, size_t *a2)
{
const char *v2; // rdx
size_t v3; // rax

v2 = "empty";
if ( a1 )
{
v3 = strlen(a1) + 1;
*a2 = v3 >> 1;
v2 = "too long";
if ( v3 <= 0x51 )
v2 = (const char *)ttodata(a1, 0LL, 16LL, a2 + 1, v3 >> 1, a2);
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func5(const char *a1, size_t *a2)
{
const char *v2; // rdx
size_t v3; // rax

v2 = "empty";
if ( a1 )
{
v3 = strlen(a1) + 1;
*a2 = v3 >> 1;
v2 = "too long";
if ( v3 <= 0x51 )
v2 = (const char *)ttodata(a1, 0LL, 16LL, a2 + 1, v3 >> 1, a2);
}
return v2;
}

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(_BYTE *a1, __int64 a2)
{
__int64 result; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
for ( result = 0LL; ; result = (unsigned int)(result + 1) )
{
while ( *((_BYTE *)&oid_names + 16 * (int)result) != *a1 )
{
LOWORD(result) = *((_WORD *)&oid_names + 8 * (int)result + 1);
if ( !(_WORD)result )
return 0xFFFFFFFFLL;
result = (unsigned __int16)result;
}
++a1;
if ( !--a2 )
break;
if ( !*((_BYTE *)&oid_names + 16 * (int)result + 1) )
return 0xFFFFFFFFLL;
}
if ( *((_BYTE *)&oid_names + 16 * (int)result + 1) )
result = 0xFFFFFFFFLL;
return result;
}

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

if ( !a2 )
return 0xFFFFFFFFLL;
for ( result = 0LL; ; result = (unsigned int)(result + 1) )
{
while ( *((_BYTE *)&oid_names + 16 * (int)result) != *a1 )
{
LOWORD(result) = *((_WORD *)&oid_names + 8 * (int)result + 1);
if ( !(_WORD)result )
return 0xFFFFFFFFLL;
result = (unsigned __int16)result;
}
++a1;
if ( !--a2 )
break;
if ( !*((_BYTE *)&oid_names + 16 * (int)result + 1) )
return 0xFFFFFFFFLL;
}
if ( *((_BYTE *)&oid_names + 16 * (int)result + 1) )
result = 0xFFFFFFFFLL;
return result;
}

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

return_type: void


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) & 0x1F] << (*(_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) & 0x1F] << (*(_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(_QWORD *a1, _DWORD *a2)
{
__int64 v2; // rax
const char *v3; // rdx
unsigned __int8 *v4; // rcx

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

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

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

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
const char *v3; // rcx
unsigned __int8 *v4; // r9
unsigned __int8 *v5; // rdx
unsigned __int64 v6; // rax
unsigned __int8 v7; // cl
unsigned __int64 v8; // rdx
unsigned __int8 v10; // r8
unsigned __int64 v11; // rax
unsigned __int64 v12; // rdi

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

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

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

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 *v3[3]; // [rsp+0h] [rbp-38h] BYREF
int v4; // [rsp+1Ch] [rbp-1Ch] BYREF
unsigned __int64 v5[3]; // [rsp+20h] [rbp-18h] BYREF

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

canonical_decompiled_code:
const char *__fastcall func5(unsigned __int8 *a1, unsigned __int8 *a2)
{
const char *result; // rax
unsigned __int8 *v3[3]; // [rsp+0h] [rbp-38h] BYREF
int v4; // [rsp+1Ch] [rbp-1Ch] BYREF
unsigned __int64 v5[3]; // [rsp+20h] [rbp-18h] BYREF

v3[0] = a1;
v3[1] = a2;
v5[1] = __readfsqword(0x28u);
result = func3(v3, &v4);
if ( !result )
{
result = "content is not binary ASN.1";
if ( (unsigned int)(v4 - 48) <= 1 )
result = func4(v3, v5);
}
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(_QWORD *a1, unsigned __int64 a2, _QWORD *a3)
{
const char *result; // rax

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

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

result = "ASN.1 length larger than space";
if ( a1[1] >= a2 )
{
*a3 = *a1;
a3[1] = a2;
*a1 += a2;
a1[1] -= a2;
result = 0LL;
}
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(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(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:
unsigned __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 )
{
if ( a1 == 2 )
_syslog_chk(3LL, 1LL, &LC0, a2);
else
_syslog_chk(6LL, 1LL, &LC0, a2);
}
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __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 )
{
if ( a1 == 2 )
_syslog_chk(3LL, 1LL, &LC0, a2);
else
_syslog_chk(6LL, 1LL, &LC0, a2);
}
return v3 - __readfsqword(0x28u);
}

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
char *v3; // rax
char *v4; // rbx
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 )
{
va_start(va, a2);
v2 = s;
_vsnprintf_chk(s, 0x3FFFLL, 1LL, 0x4000LL, a2, va);
s[0x3FFF] = 0;
while ( 1 )
{
v3 = strchr(v2, 10);
v4 = v3;
if ( !v3 )
break;
*v3 = 0;
log_one_line(a1, (__int64)v2);
v2 = v4 + 1;
}
log_one_line(a1, (__int64)v2);
}
return v8 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func1(int a1, __int64 a2, ...)
{
char *v2; // rbp
char *v3; // rax
char *v4; // rbx
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 )
{
va_start(va, a2);
v2 = s;
_vsnprintf_chk(s, 0x3FFFLL, 1LL, 0x4000LL, a2, va);
s[0x3FFF] = 0;
while ( 1 )
{
v3 = strchr(v2, 10);
v4 = v3;
if ( !v3 )
break;
*v3 = 0;
func0(a1, (__int64)v2);
v2 = v4 + 1;
}
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, char a3)
{
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

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

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char a1, char a2, char a3)
{
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

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

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 i; // ebx
__int64 v6; // rdx
__int64 v7; // r12
void *v8; // r15
size_t v9; // rdx
unsigned int v10; // ebx
__int64 v11; // rdx
__int64 v12; // r8
__int64 *v13; // rax
__int64 v16; // [rsp+8h] [rbp-60h]
void *v17; // [rsp+10h] [rbp-58h] BYREF
size_t v18; // [rsp+18h] [rbp-50h]
unsigned __int64 v19; // [rsp+28h] [rbp-40h]

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

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

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

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 v2; // rax
__int64 v3; // r12
__int64 v4; // rax

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

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

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

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:
unsigned __int64 __fastcall jam_list_entry(__int64 a1, const void **a2)
{
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
if ( a2 )
{
if ( a2[2] )
(*((void (**)(void))a2[3] + 1))();
else
jam(a1, "HEAD");
jam(a1, " %p<-%p->%p", a2[1], a2, *a2);
}
else
{
jam(a1, "(null)");
}
return v3 - __readfsqword(0x28u);
}

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

v3 = __readfsqword(0x28u);
if ( a2 )
{
if ( a2[2] )
(*((void (**)(void))a2[3] + 1))();
else
jam(a1, "HEAD");
jam(a1, " %p<-%p->%p", a2[1], a2, *a2);
}
else
{
jam(a1, "(null)");
}
return v3 - __readfsqword(0x28u);
}

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

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

user_defined_types: struct list_entry { struct list_entry *next[2]; void *data; struct list_info *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 )
return -14LL;
if ( *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 )
return -14LL;
if ( *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 )
return -14LL;
if ( *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 )
return -14LL;
if ( *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)
{
char v2; // dl
char v3; // al

v2 = fd_p(a1);
v3 = 0;
if ( v2 )
v3 = fd_p(a2) & (a1 == a2);
return v3 & 1;
}

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

v2 = func4(a1);
v3 = 0;
if ( v2 )
v3 = func4(a2) & (a1 == a2);
return v3 & 1;
}

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 v7; // rbx
ssize_t v8; // rax
unsigned int *v9; // rdx
__int16 v10; // cx
void *v13; // [rsp+8h] [rbp-60h]
socklen_t addr_len; // [rsp+18h] [rbp-50h] BYREF
struct sockaddr addr[4]; // [rsp+1Ch] [rbp-4Ch] BYREF

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

canonical_decompiled_code:
size_t __fastcall func0(int fd, const void **a2, __int64 a3, int a4, int a5)
{
size_t v7; // rbx
ssize_t v8; // rax
unsigned int *v9; // rdx
__int16 v10; // cx
void *v13; // [rsp+8h] [rbp-60h]
socklen_t addr_len; // [rsp+18h] [rbp-50h] BYREF
struct sockaddr addr[4]; // [rsp+1Ch] [rbp-4Ch] BYREF

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

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:
unsigned __int64 lsw_nss_shutdown()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

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

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

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

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; // rbp

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

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

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

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 v8; // rdx
unsigned __int8 v9; // cl
unsigned __int8 v10; // r8
unsigned int v11; // esi

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

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v8; // rdx
unsigned __int8 v9; // cl
unsigned __int8 v10; // r8
unsigned int v11; // esi

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

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


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

v2 = __readfsqword(0x28u);
*(_QWORD *)(a1 + 8) = clone_bytes(
*(_QWORD *)(a1 + 8),
8LL * *(unsigned int *)(a1 + 16),
"sa copy attrs array (unshare)");
return v2 - __readfsqword(0x28u);
}

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

v2 = __readfsqword(0x28u);
*(_QWORD *)(a1 + 8) = clone_bytes(
*(_QWORD *)(a1 + 8),
8LL * *(unsigned int *)(a1 + 16),
"sa copy attrs array (unshare)");
return v2 - __readfsqword(0x28u);
}

original_code:
static void unshare_trans(struct db_trans *tr)
{
 tr->attrs = clone_bytes(tr->attrs, tr->attr_cnt * sizeof(tr->attrs[0]),
  "sa copy attrs array (unshare)");
}

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

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


decompiled_code:
unsigned __int64 __fastcall unshare_prop(__int64 a1)
{
unsigned int v1; // ebx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
*(_QWORD *)(a1 + 8) = clone_bytes(
*(_QWORD *)(a1 + 8),
24LL * *(unsigned int *)(a1 + 16),
"sa copy trans array (unshare)");
if ( *(_DWORD *)(a1 + 16) )
{
v1 = 0;
do
unshare_trans(*(_QWORD *)(a1 + 8) + 24LL * v1++);
while ( *(_DWORD *)(a1 + 16) > v1 );
}
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // ebx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
*(_QWORD *)(a1 + 8) = clone_bytes(
*(_QWORD *)(a1 + 8),
24LL * *(unsigned int *)(a1 + 16),
"sa copy trans array (unshare)");
if ( *(_DWORD *)(a1 + 16) )
{
v1 = 0;
do
func3(*(_QWORD *)(a1 + 8) + 24LL * v1++);
while ( *(_DWORD *)(a1 + 16) > v1 );
}
return v3 - __readfsqword(0x28u);
}

original_code:
static void unshare_prop(struct db_prop *p)
{
 unsigned int i;
 p->trans = clone_bytes(p->trans, p->trans_cnt * sizeof(p->trans[0]),
  "sa copy trans array (unshare)");
 for (i = 0; i < p->trans_cnt; i++)
  unshare_trans(&p->trans[i]);
}

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

variable_types:
i
unsigned int

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


decompiled_code:
unsigned __int64 __fastcall unshare_propconj(__int64 a1)
{
unsigned int v1; // ebx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
*(_QWORD *)a1 = clone_bytes(*(_QWORD *)a1, 24LL * *(unsigned int *)(a1 + 8), "sa copy prop array (unshare)");
if ( *(_DWORD *)(a1 + 8) )
{
v1 = 0;
do
unshare_prop(*(_QWORD *)a1 + 24LL * v1++);
while ( *(_DWORD *)(a1 + 8) > v1 );
}
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // ebx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
*(_QWORD *)a1 = clone_bytes(*(_QWORD *)a1, 24LL * *(unsigned int *)(a1 + 8), "sa copy prop array (unshare)");
if ( *(_DWORD *)(a1 + 8) )
{
v1 = 0;
do
func4(*(_QWORD *)a1 + 24LL * v1++);
while ( *(_DWORD *)(a1 + 8) > v1 );
}
return v3 - __readfsqword(0x28u);
}

original_code:
static void unshare_propconj(struct db_prop_conj *pc)
{
 unsigned int i;
 pc->props = clone_bytes(pc->props, pc->prop_cnt * sizeof(pc->props[0]),
  "sa copy prop array (unshare)");
 for (i = 0; i < pc->prop_cnt; i++)
  unshare_prop(&pc->props[i]);
}

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

user_defined_types: struct db_prop_conj { struct db_prop *props; unsigned int prop_cnt; }


decompiled_code:
__int64 __fastcall sa_copy_sa(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // ebx

v2 = clone_bytes(a1, 24LL, "sa copy prop_conj (sa_copy_sa)");
dbg_alloc("sadb", v2, a2);
*(_BYTE *)v2 = 1;
*(_BYTE *)(v2 + 1) = *(_BYTE *)(a1 + 1);
*(_QWORD *)(v2 + 8) = clone_bytes(
*(_QWORD *)(v2 + 8),
16LL * *(unsigned int *)(v2 + 16),
"sa copy prop conj array (sa_copy_sa)");
if ( *(_DWORD *)(v2 + 16) )
{
v3 = 0;
do
unshare_propconj(*(_QWORD *)(v2 + 8) + 16LL * v3++);
while ( *(_DWORD *)(v2 + 16) > v3 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int v3; // ebx

v2 = clone_bytes(a1, 24LL, "sa copy prop_conj (sa_copy_sa)");
dbg_alloc("sadb", v2, a2);
*(_BYTE *)v2 = 1;
*(_BYTE *)(v2 + 1) = *(_BYTE *)(a1 + 1);
*(_QWORD *)(v2 + 8) = clone_bytes(
*(_QWORD *)(v2 + 8),
16LL * *(unsigned int *)(v2 + 16),
"sa copy prop conj array (sa_copy_sa)");
if ( *(_DWORD *)(v2 + 16) )
{
v3 = 0;
do
func5(*(_QWORD *)(v2 + 8) + 16LL * v3++);
while ( *(_DWORD *)(v2 + 16) > v3 );
}
return v2;
}

original_code:
struct db_sa *sa_copy_sa(const struct db_sa *sa, where_t where)
{
 struct db_sa *nsa = clone_bytes((const void *)&(*sa), sizeof(*sa), ("sa copy prop_conj (sa_copy_sa)"));
 dbg_alloc("sadb", nsa, where);
 nsa->dynamic = 1;
 nsa->parentSA = sa->parentSA;
 nsa->prop_conjs = clone_bytes(nsa->prop_conjs,
  sizeof(nsa->prop_conjs[0]) * nsa->prop_conj_cnt,
  "sa copy prop conj array (sa_copy_sa)");
 for (unsigned int i = 0; i < nsa->prop_conj_cnt; i++)
  unshare_propconj(&nsa->prop_conjs[i]);
 return nsa;
}

canonical_original_code:
struct db_sa *sa_copy_sa(struct db_sa *sa, struct where *where)
{
 struct db_sa *nsa = clone_bytes((const void *)&(*sa), sizeof(*sa), ("sa copy prop_conj (sa_copy_sa)"));
 dbg_alloc("sadb", nsa, where);
 nsa->dynamic = 1;
 nsa->parentSA = sa->parentSA;
 nsa->prop_conjs = clone_bytes(nsa->prop_conjs,
  sizeof(nsa->prop_conjs[0]) * nsa->prop_conj_cnt,
  "sa copy prop conj array (sa_copy_sa)");
 for (unsigned int i = 0; i < nsa->prop_conj_cnt; i++)
  unshare_propconj(&nsa->prop_conjs[i]);
 return nsa;
}

variable_types:
sa
struct db_sa *

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

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

user_defined_types: struct db_sa { _Bool dynamic; _Bool parentSA; struct db_prop_conj *prop_conjs; unsigned int prop_conj_cnt; }


ttoul

decompiled_code:
const char *__fastcall ttoul(char *a1, unsigned __int64 a2, int a3, unsigned __int64 *a4)
{
const char *result; // rax
char *v6; // rbx
char *v8; // r13
unsigned __int64 v9; // rax
int v10; // edi
unsigned __int64 v11; // rbp
char *v12; // rax
signed int v13; // eax
int v14; // er14
char *v15; // rax
int v16; // edx

result = "empty string";
if ( a2 )
{
v6 = a1;
if ( !a3 )
{
if ( a2 <= 2 )
{
if ( a2 != 2 || *a1 != 48 )
return (const char *)ttoul(a1, a2, 10LL);
}
else
{
if ( *a1 != 48 )
return (const char *)ttoul(a1, a2, 10LL);
if ( (a1[1] & 0xDF) == 88 )
return (const char *)ttoul(a1 + 2, a2 - 2, 16LL);
}
return (const char *)ttoul(a1 + 1, a2 - 1, 8LL);
}
if ( (a3 & 0xFFFFFFFD) == 8 || (result = "unsupported number base", a3 == 16) )
{
v8 = &a1[a2];
if ( a3 != 16 )
{
v9 = 0xFFFFFFFFFFFFFFFFLL / a3;
v10 = ~(v9 * a3);
if ( v6 < v8 )
{
v11 = 0LL;
while ( 1 )
{
v16 = *v6++ - 48;
if ( v16 < 0 || a3 <= v16 )
return "non-digit in number";
if ( v9 < v11 )
return "unsigned-long overflow";
if ( v9 == v11 && v10 < v16 )
return "unsigned-long overflow";
v11 = v16 + a3 * v11;
if ( v8 == v6 )
goto LABEL_27;
}
}
v11 = 0LL;
LABEL_27:
*a4 = v11;
return 0LL;
}
if ( a1 < v8 )
{
v11 = 0LL;
while ( 1 )
{
v14 = *v6++;
v15 = strchr("0123456789abcdef", v14);
if ( v15 )
{
v13 = (_DWORD)v15 - (unsigned int)"0123456789abcdef";
}
else
{
v12 = strchr("0123456789ABCDEF", v14);
if ( !v12 )
return "non-hex digit in hex number";
v13 = (_DWORD)v12 - (unsigned int)"0123456789ABCDEF";
}
v11 = v13 | (16 * v11);
if ( v8 == v6 )
goto LABEL_26;
}
}
v11 = 0LL;
LABEL_26:
result = "hex number too long";
if ( a2 <= 0x10 )
goto LABEL_27;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(char *a1, unsigned __int64 a2, int a3, unsigned __int64 *a4)
{
const char *result; // rax
char *v6; // rbx
char *v8; // r13
unsigned __int64 v9; // rax
int v10; // edi
unsigned __int64 v11; // rbp
char *v12; // rax
signed int v13; // eax
int v14; // er14
char *v15; // rax
int v16; // edx

result = "empty string";
if ( a2 )
{
v6 = a1;
if ( !a3 )
{
if ( a2 <= 2 )
{
if ( a2 != 2 || *a1 != 48 )
return (const char *)func0(a1, a2, 10LL);
}
else
{
if ( *a1 != 48 )
return (const char *)func0(a1, a2, 10LL);
if ( (a1[1] & 0xDF) == 88 )
return (const char *)func0(a1 + 2, a2 - 2, 16LL);
}
return (const char *)func0(a1 + 1, a2 - 1, 8LL);
}
if ( (a3 & 0xFFFFFFFD) == 8 || (result = "unsupported number base", a3 == 16) )
{
v8 = &a1[a2];
if ( a3 != 16 )
{
v9 = 0xFFFFFFFFFFFFFFFFLL / a3;
v10 = ~(v9 * a3);
if ( v6 < v8 )
{
v11 = 0LL;
while ( 1 )
{
v16 = *v6++ - 48;
if ( v16 < 0 || a3 <= v16 )
return "non-digit in number";
if ( v9 < v11 )
return "unsigned-long overflow";
if ( v9 == v11 && v10 < v16 )
return "unsigned-long overflow";
v11 = v16 + a3 * v11;
if ( v8 == v6 )
goto LABEL_27;
}
}
v11 = 0LL;
LABEL_27:
*a4 = v11;
return 0LL;
}
if ( a1 < v8 )
{
v11 = 0LL;
while ( 1 )
{
v14 = *v6++;
v15 = strchr("0123456789abcdef", v14);
if ( v15 )
{
v13 = (_DWORD)v15 - (unsigned int)"0123456789abcdef";
}
else
{
v12 = strchr("0123456789ABCDEF", v14);
if ( !v12 )
return "non-hex digit in hex number";
v13 = (_DWORD)v12 - (unsigned int)"0123456789ABCDEF";
}
v11 = v13 | (16 * v11);
if ( v8 == v6 )
goto LABEL_26;
}
}
v11 = 0LL;
LABEL_26:
result = "hex number too long";
if ( a2 <= 0x10 )
goto LABEL_27;
}
}
return result;
}

original_code:
static err_t ttoul(const char *src, size_t srclen,
     int base,
     unsigned long *resultp)
{
 const char *stop;
 static const char hex[] = "0123456789abcdef";
 static const char uchex[] = "0123456789ABCDEF";
 int d;
 char c;
 const char *p;
 unsigned long r;
 unsigned long rlimit;
 int dlimit;
 if (srclen == 0)
  return "empty string";
 if (base == 0) {
  if (srclen > 2 && *src == '0' &&
   (*(src + 1) == 'x' || *(src + 1) == 'X'))
   return ttoul(src + 2, srclen - 2, 16, resultp);
  if (srclen > 1 && *src == '0')
   return ttoul(src + 1, srclen - 1, 8, resultp);
  return ttoul(src, srclen, 10, resultp);
 }
 if (base != 8 && base != 10 && base != 16)
  return "unsupported number base";
 r = 0;
 stop = src + srclen;
 if (base == 16) {
  while (src < stop) {
   c = *src++;
   p = strchr(hex, c);
   if (p != ((void *)0)) {
    d = p - hex;
   } else {
    p = strchr(uchex, c);
    if (p == ((void *)0))
     return "non-hex digit in hex number";
    d = p - uchex;
   }
   r = (r << 4) | d;
  }
  if (srclen > sizeof(unsigned long) * 2)
   return "hex number too long";
 } else {
  rlimit = (0x7fffffffffffffffL * 2UL + 1UL) / base;
  dlimit = (int)((0x7fffffffffffffffL * 2UL + 1UL) - rlimit * base);
  while (src < stop) {
   c = *src++;
   d = c - '0';
   if (d < 0 || d >= base)
    return "non-digit in number";
   if (r > rlimit || (r == rlimit && d > dlimit))
    return "unsigned-long overflow";
   r = r * base + d;
  }
 }
 *resultp = r;
 return ((void *)0);
}

canonical_original_code:
static char *ttoul(char *src, unsigned long srclen, int base, unsigned long *resultp)
{
 char *stop;
 static char hex[] = "0123456789abcdef";
 static char uchex[] = "0123456789ABCDEF";
 int d;
 char c;
 char *p;
 unsigned long r;
 unsigned long rlimit;
 int dlimit;
 if (srclen == 0)
  return "empty string";
 if (base == 0) {
  if (srclen > 2 && *src == '0' &&
   (*(src + 1) == 'x' || *(src + 1) == 'X'))
   return ttoul(src + 2, srclen - 2, 16, resultp);
  if (srclen > 1 && *src == '0')
   return ttoul(src + 1, srclen - 1, 8, resultp);
  return ttoul(src, srclen, 10, resultp);
 }
 if (base != 8 && base != 10 && base != 16)
  return "unsupported number base";
 r = 0;
 stop = src + srclen;
 if (base == 16) {
  while (src < stop) {
   c = *src++;
   p = strchr(hex, c);
   if (p != ((void *)0)) {
    d = p - hex;
   } else {
    p = strchr(uchex, c);
    if (p == ((void *)0))
     return "non-hex digit in hex number";
    d = p - uchex;
   }
   r = (r << 4) | d;
  }
  if (srclen > sizeof(unsigned long) * 2)
   return "hex number too long";
 } else {
  rlimit = (0x7fffffffffffffffL * 2UL + 1UL) / base;
  dlimit = (int)((0x7fffffffffffffffL * 2UL + 1UL) - rlimit * base);
  while (src < stop) {
   c = *src++;
   d = c - '0';
   if (d < 0 || d >= base)
    return "non-digit in number";
   if (r > rlimit || (r == rlimit && d > dlimit))
    return "unsigned-long overflow";
   r = r * base + d;
  }
 }
 *resultp = r;
 return ((void *)0);
}

variable_types:
src
char *

variable_types:
srclen
unsigned long

variable_types: base int

variable_types:
resultp
unsigned long *

variable_types:
stop
char *

variable_types:
hex
char []

variable_types:
uchex
char []

variable_types: d int

variable_types: c char

variable_types:
p
char *

variable_types:
r
unsigned long

variable_types:
rlimit
unsigned long

variable_types: dlimit int


ttoulb

decompiled_code:
const char *__fastcall ttoulb(char *a1, unsigned __int64 a2, int a3, unsigned __int64 a4, unsigned __int64 *a5)
{
const char *result; // rax

if ( !a2 )
a2 = strlen(a1);
result = ttoul(a1, a2, a3, a5);
if ( !result && *a5 > a4 )
result = "too large";
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(char *a1, unsigned __int64 a2, int a3, unsigned __int64 a4, unsigned __int64 *a5)
{
const char *result; // rax

if ( !a2 )
a2 = strlen(a1);
result = func0(a1, a2, a3, a5);
if ( !result && *a5 > a4 )
result = "too large";
return result;
}

original_code:
err_t ttoulb(const char *src,
      size_t srclen,
      int base,
      unsigned long upb,
      unsigned long *resultp)
{
 if (srclen == 0)
  srclen = strlen(src);
 const char *ugh = ttoul(src, srclen, base, resultp);
 return ugh != ((void *)0) ? ugh : *resultp > upb ? "too large" : ((void *)0);
}

canonical_original_code:
char *ttoulb(char *src, unsigned long srclen, int base, unsigned long upb, unsigned long *resultp)
{
 if (srclen == 0)
  srclen = strlen(src);
 char *ugh = ttoul(src, srclen, base, resultp);
 return ugh != ((void *)0) ? ugh : *resultp > upb ? "too large" : ((void *)0);
}

variable_types:
upb
unsigned long

variable_types:
ugh
char *


addrcmp

decompiled_code:
__int64 __fastcall addrcmp(__int64 a1, __int64 a2)
{
char v2; // dl
__int64 result; // rax
char v4; // dl

if ( !(unsigned __int8)((__int64 (*)(void))address_is_unset)() || (v2 = address_is_unset(a2), result = 0LL, !v2) )
{
if ( (unsigned __int8)address_is_unset(a1) )
{
result = 0xFFFFFFFFLL;
}
else
{
v4 = address_is_unset(a2);
result = 1LL;
if ( !v4 )
result = ip_bytes_cmp(
*(unsigned int *)(a1 + 4),
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16),
*(unsigned int *)(a2 + 4),
*(_QWORD *)(a2 + 8),
*(_QWORD *)(a2 + 16));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
char v2; // dl
__int64 result; // rax
char v4; // dl

if ( !(unsigned __int8)((__int64 (*)(void))address_is_unset)() || (v2 = address_is_unset(a2), result = 0LL, !v2) )
{
if ( (unsigned __int8)address_is_unset(a1) )
{
result = 0xFFFFFFFFLL;
}
else
{
v4 = address_is_unset(a2);
result = 1LL;
if ( !v4 )
result = ip_bytes_cmp(
*(unsigned int *)(a1 + 4),
*(_QWORD *)(a1 + 8),
*(_QWORD *)(a1 + 16),
*(unsigned int *)(a2 + 4),
*(_QWORD *)(a2 + 8),
*(_QWORD *)(a2 + 16));
}
}
return result;
}

original_code:
int
addrcmp(const ip_address *l, const ip_address *r)
{
 if (address_is_unset(l) && address_is_unset(r)) {
  return 0;
 }
 if (address_is_unset(l)) {
  return -1;
 }
 if (address_is_unset(r)) {
  return 1;
 }
 return ip_bytes_cmp(l->version, l->bytes,
       r->version, r->bytes);
}

canonical_original_code:
int addrcmp(struct ip_address *l, struct ip_address *r)
{
 if (address_is_unset(l) && address_is_unset(r)) {
  return 0;
 }
 if (address_is_unset(l)) {
  return -1;
 }
 if (address_is_unset(r)) {
  return 1;
 }
 return ip_bytes_cmp(l->version, l->bytes,
       r->version, r->bytes);
}

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

variable_types:
r
struct ip_address *

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


sameaddr

decompiled_code:
bool __fastcall sameaddr(__int64 a1, __int64 a2)
{
return (unsigned int)addrcmp(a1, a2) == 0;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2)
{
return (unsigned int)func0(a1, a2) == 0;
}

original_code:
_Bool sameaddr(const ip_address *a, const ip_address *b)
{
 return addrcmp(a, b) == 0;
}

canonical_original_code:
_Bool sameaddr(struct ip_address *a, struct ip_address *b)
{
 return addrcmp(a, b) == 0;
}

variable_types:
b
struct ip_address *

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


original_code:
size_t jam_nss_ckf(struct jambuf *buf, CK_FLAGS flags)
{
 const char *sep = "";
 size_t size = 0;
 if (flags & 0x00000800) { size += jam_string(buf, sep); size += jam_string(buf, &"CKF_SIGN"[strlen("CKF_")]); sep = "+"; flags ^= 0x00000800; };
 if (flags & 0x00000100) { size += jam_string(buf, sep); size += jam_string(buf, &"CKF_ENCRYPT"[strlen("CKF_")]); sep = "+"; flags ^= 0x00000100; };
 if (flags & 0x00000200) { size += jam_string(buf, sep); size += jam_string(buf, &"CKF_DECRYPT"[strlen("CKF_")]); sep = "+"; flags ^= 0x00000200; };
 if (flags != 0) {
  size += jam(buf, "%sCKF_%08lx", sep, (long) flags);
 }
 return size;
}

canonical_original_code:
unsigned long jam_nss_ckf(struct jambuf *buf, unsigned long flags)
{
 char *sep = "";
 unsigned long size = 0;
 if (flags & 0x00000800) { size += jam_string(buf, sep); size += jam_string(buf, &"CKF_SIGN"[strlen("CKF_")]); sep = "+"; flags ^= 0x00000800; };
 if (flags & 0x00000100) { size += jam_string(buf, sep); size += jam_string(buf, &"CKF_ENCRYPT"[strlen("CKF_")]); sep = "+"; flags ^= 0x00000100; };
 if (flags & 0x00000200) { size += jam_string(buf, sep); size += jam_string(buf, &"CKF_DECRYPT"[strlen("CKF_")]); sep = "+"; flags ^= 0x00000200; };
 if (flags != 0) {
  size += jam(buf, "%sCKF_%08lx", sep, (long) flags);
 }
 return size;
}

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

variable_types:
flags
unsigned long

variable_types:
sep
char *

variable_types:
size
unsigned long


decompiled_code:
__int64 alloc_printf(__int64 a1, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v3; // [rsp+18h] [rbp-C0h]

va_start(va, a1);
v3 = __readfsqword(0x28u);
return alloc_vprintf(a1, (const __m128i *)va);
}

canonical_decompiled_code:
__int64 func1(__int64 a1, ...)
{
gcc_va_list va; // [rsp+0h] [rbp-D8h] BYREF
unsigned __int64 v3; // [rsp+18h] [rbp-C0h]

va_start(va, a1);
v3 = __readfsqword(0x28u);
return func0(a1, (const __m128i *)va);
}

original_code:
char *alloc_printf(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 char *d = alloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 return d;
}

canonical_original_code:
char *alloc_printf(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 char *d = alloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 return d;
}

variable_types:
fmt
char *

variable_types:
d
char *


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

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

original_code:
chunk_t chunk2(void *ptr, size_t len)
{
 return (chunk_t) { .ptr = ptr, .len = len, };
}

canonical_original_code:
struct chunk_t chunk2(void *ptr, unsigned long len)
{
 return (struct chunk_t) { .ptr = ptr, .len = len, };
}

variable_types:
ptr
void *

variable_types:
len
unsigned long

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


decompiled_code:
__int64 alloc_chunk()
{
__int64 v0; // rax

v0 = alloc_bytes();
return chunk2(v0);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax

v0 = alloc_bytes();
return func0(v0);
}

original_code:
chunk_t alloc_chunk(size_t count, const char *name)
{
 uint8_t *ptr = ((uint8_t*) alloc_bytes(sizeof(uint8_t) * (count), (name)));
 return chunk2(ptr, count);
}

canonical_original_code:
struct chunk_t alloc_chunk(unsigned long count, char *name)
{
 unsigned char *ptr = ((uint8_t*) alloc_bytes(sizeof(uint8_t) * (count), (name)));
 return chunk2(ptr, count);
}

variable_types:
count
unsigned long

variable_types:
name
char *

variable_types:
ptr
unsigned char *

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


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

v2 = __readfsqword(0x28u);
if ( *a1 )
pfree();
*a1 = 0LL;
a1[1] = 0LL;
return v2 - __readfsqword(0x28u);
}

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

v2 = __readfsqword(0x28u);
if ( *a1 )
pfree();
*a1 = 0LL;
a1[1] = 0LL;
return v2 - __readfsqword(0x28u);
}

original_code:
void free_chunk_content(chunk_t *chunk)
{
 if (chunk->ptr != ((void *)0)) {
  pfree(chunk->ptr);
 }
 *chunk = empty_chunk;
}

canonical_original_code:
void free_chunk_content(struct chunk_t *chunk)
{
 if (chunk->ptr != ((void *)0)) {
  pfree(chunk->ptr);
 }
 *chunk = empty_chunk;
}

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


decompiled_code:
__int64 clone_bytes_as_chunk()
{
__int64 v0; // rax

v0 = clone_bytes();
return chunk2(v0);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax

v0 = clone_bytes();
return func0(v0);
}

original_code:
chunk_t clone_bytes_as_chunk(const void *bytes, size_t sizeof_bytes, const char *name)
{
 return chunk2(clone_bytes(bytes, sizeof_bytes, name), sizeof_bytes);
}

canonical_original_code:
struct chunk_t clone_bytes_as_chunk(void *bytes, unsigned long sizeof_bytes, char *name)
{
 return chunk2(clone_bytes(bytes, sizeof_bytes, name), sizeof_bytes);
}

variable_types:
bytes
void *


decompiled_code:
__int64 clone_bytes_bytes_as_chunk()
{
__int64 v0; // rax

v0 = clone_bytes_bytes();
return chunk2(v0);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax

v0 = clone_bytes_bytes();
return func0(v0);
}

original_code:
chunk_t clone_bytes_bytes_as_chunk(const void *lhs_ptr, size_t lhs_len,
       const void *rhs_ptr, size_t rhs_len,
       const char *name)
{
 void *new = clone_bytes_bytes(lhs_ptr, lhs_len, rhs_ptr, rhs_len, name);
 return chunk2(new, lhs_len + rhs_len);
}

canonical_original_code:
struct chunk_t clone_bytes_bytes_as_chunk(void *lhs_ptr, unsigned long lhs_len, void *rhs_ptr, unsigned long rhs_len, char *name)
{
 void *new = clone_bytes_bytes(lhs_ptr, lhs_len, rhs_ptr, rhs_len, name);
 return chunk2(new, lhs_len + rhs_len);
}

variable_types:
new
void *


decompiled_code:
unsigned __int64 __fastcall append_chunk_bytes(__int64 a1, __int64 *a2, __int64 a3, __int64 a4)
{
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // r13
unsigned __int64 v8; // [rsp+8h] [rbp-20h]

v8 = __readfsqword(0x28u);
v4 = clone_bytes_bytes_as_chunk(*a2, a2[1], a3, a4, a1);
v6 = v5;
free_chunk_content(a2);
*a2 = v4;
a2[1] = v6;
return v8 - __readfsqword(0x28u);
}

original_code:
void append_chunk_bytes(const char *name, chunk_t *lhs,
   const void *rhs_ptr, size_t rhs_len)
{
 chunk_t new = clone_bytes_bytes_as_chunk(lhs->ptr, lhs->len, rhs_ptr, rhs_len, name);
 free_chunk_content(lhs);
 *lhs = new;
}

canonical_original_code:
void append_chunk_bytes(char *name, struct chunk_t *lhs, void *rhs_ptr, unsigned long rhs_len)
{
 struct chunk_t new = clone_bytes_bytes_as_chunk(lhs->ptr, lhs->len, rhs_ptr, rhs_len, name);
 free_chunk_content(lhs);
 *lhs = new;
}

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


decompiled_code:
const char *__fastcall keyblob_to_keyid(__int64 a1, __int64 a2, __int64 a3)
{
bool v3; // cc
const char *result; // rax

v3 = (unsigned __int64)datatot(a1, a2, 64LL, a3, 10LL) <= 9;
result = "key blob is too small";
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
bool v3; // cc
const char *result; // rax

v3 = (unsigned __int64)datatot(a1, a2, 64LL, a3, 10LL) <= 9;
result = "key blob is too small";
if ( !v3 )
result = 0LL;
return result;
}

original_code:
err_t keyblob_to_keyid(const uint8_t *src, size_t srclen, keyid_t *dst)
{
 size_t ret = datatot(src, srclen, 64, dst->keyid, sizeof(dst->keyid));
 if (ret < sizeof(dst->keyid)) {
  return "key blob is too small";
 } else {
  return ((void *)0);
 }
}

canonical_original_code:
char *keyblob_to_keyid(unsigned char *src, unsigned long srclen, struct keyid_t *dst)
{
 unsigned long ret = datatot(src, srclen, 64, dst->keyid, sizeof(dst->keyid));
 if (ret < sizeof(dst->keyid)) {
  return "key blob is too small";
 } else {
  return ((void *)0);
 }
}

variable_types:
src
unsigned char *

variable_types:
srclen
unsigned long

variable_types:
dst
struct keyid_t { char keyid[10]; } *

variable_types:
ret
unsigned long


decompiled_code:
const char *__fastcall splitkey_to_keyid(char *a1, unsigned __int64 a2, char *a3, __int64 a4, __int64 a5)
{
char *v7; // rsi
char *v8; // rax
char *v9; // rax
char v11; // [rsp+Eh] [rbp-1Ah] BYREF
char v12[2]; // [rsp+Fh] [rbp-19h] BYREF
char v13; // [rsp+11h] [rbp-17h] BYREF
__int64 v14[2]; // [rsp+18h] [rbp-10h] BYREF

v14[0] = __readfsqword(0x28u);
if ( a2 > 0xFF )
{
if ( a2 > 0xFFFF )
{
*(_QWORD *)a5 = empty_keyid;
*(_WORD *)(a5 + 8) = *((_WORD *)&empty_keyid + 4);
return "unrepresentable exponent length";
}
v11 = 0;
v12[0] = BYTE1(a2);
v12[1] = a2;
v7 = &v13;
goto LABEL_3;
}
v11 = a2;
v7 = v12;
if ( a2 )
{
LABEL_3:
v8 = a1;
do
*v7++ = *v8++;
while ( a2 + a1 - v8 && v7 < (char *)v14 );
}
if ( a4 && v7 < (char *)v14 )
{
v9 = a3;
do
*v7++ = *v9++;
while ( &a3[a4 - (_QWORD)v9] && v7 < (char *)v14 );
}
return keyblob_to_keyid((__int64)&v11, v7 - &v11, a5);
}

canonical_decompiled_code:
const char *__fastcall func1(char *a1, unsigned __int64 a2, char *a3, __int64 a4, __int64 a5)
{
char *v7; // rsi
char *v8; // rax
char *v9; // rax
char v11; // [rsp+Eh] [rbp-1Ah] BYREF
char v12[2]; // [rsp+Fh] [rbp-19h] BYREF
char v13; // [rsp+11h] [rbp-17h] BYREF
__int64 v14[2]; // [rsp+18h] [rbp-10h] BYREF

v14[0] = __readfsqword(0x28u);
if ( a2 > 0xFF )
{
if ( a2 > 0xFFFF )
{
*(_QWORD *)a5 = empty_keyid;
*(_WORD *)(a5 + 8) = *((_WORD *)&empty_keyid + 4);
return "unrepresentable exponent length";
}
v11 = 0;
v12[0] = BYTE1(a2);
v12[1] = a2;
v7 = &v13;
goto LABEL_3;
}
v11 = a2;
v7 = v12;
if ( a2 )
{
LABEL_3:
v8 = a1;
do
*v7++ = *v8++;
while ( a2 + a1 - v8 && v7 < (char *)v14 );
}
if ( a4 && v7 < (char *)v14 )
{
v9 = a3;
do
*v7++ = *v9++;
while ( &a3[a4 - (_QWORD)v9] && v7 < (char *)v14 );
}
return func0((__int64)&v11, v7 - &v11, a5);
}

original_code:
err_t splitkey_to_keyid(const uint8_t *e, size_t elen,
   const uint8_t *m, size_t mlen,
   keyid_t *dst)
{
 uint8_t keyblob[sizeof(keyid_t)];
 uint8_t *const blob_end = keyblob + sizeof(keyblob);
 uint8_t *p = keyblob;
 if (elen <= 0xff) {
  *p++ = elen;
 } else if (elen <= 0xffff) {
  *p++ = 0;
  *p++ = (elen >> 8) & 0xff;
  *p++ = elen & 0xff;
 } else {
  *dst = empty_keyid;
  return "unrepresentable exponent length";
 }
 while (elen > 0 && p < blob_end) {
  *p++ = *e++;
  elen--;
 }
 while (mlen > 0 && p < blob_end) {
  *p++ = *m++;
  mlen--;
 }
 return keyblob_to_keyid(keyblob, p - keyblob, dst);
}

canonical_original_code:
char *splitkey_to_keyid(unsigned char *e, unsigned long elen, unsigned char *m, unsigned long mlen, struct keyid_t *dst)
{
 unsigned char keyblob[-1];
 unsigned char *blob_end = keyblob + sizeof(keyblob);
 unsigned char *p = keyblob;
 if (elen <= 0xff) {
  *p++ = elen;
 } else if (elen <= 0xffff) {
  *p++ = 0;
  *p++ = (elen >> 8) & 0xff;
  *p++ = elen & 0xff;
 } else {
  *dst = empty_keyid;
  return "unrepresentable exponent length";
 }
 while (elen > 0 && p < blob_end) {
  *p++ = *e++;
  elen--;
 }
 while (mlen > 0 && p < blob_end) {
  *p++ = *m++;
  mlen--;
 }
 return keyblob_to_keyid(keyblob, p - keyblob, dst);
}

variable_types:
e
unsigned char *

variable_types:
elen
unsigned long

variable_types:
m
unsigned char *

variable_types:
mlen
unsigned long

variable_types:
keyblob
unsigned char [-1]

variable_types:
p
unsigned char *


decompiled_code:
__int64 lsw_fips_system()
{
return 1 - ((unsigned int)((unsigned int)PK11_IsFIPS() == 0) - 1);
}

canonical_decompiled_code:
__int64 func0()
{
return 1 - ((unsigned int)((unsigned int)PK11_IsFIPS() == 0) - 1);
}

original_code:
static enum lsw_fips_mode lsw_fips_system(void)
{
 return PK11_IsFIPS() ? LSW_FIPS_ON : LSW_FIPS_OFF;
}

canonical_original_code:
static enum lsw_fips_mode lsw_fips_system()
{
 return PK11_IsFIPS() ? LSW_FIPS_ON : LSW_FIPS_OFF;
}

return_type: enum lsw_fips_mode { LSW_FIPS_UNKNOWN=0, LSW_FIPS_OFF=1, LSW_FIPS_ON=2 }


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

v2 = __readfsqword(0x28u);
fips_mode = a1;
return v2 - __readfsqword(0x28u);
}

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

v2 = __readfsqword(0x28u);
fips_mode = a1;
return v2 - __readfsqword(0x28u);
}

original_code:
void lsw_set_fips_mode(enum lsw_fips_mode fips)
{
 fips_mode = fips;
}

variable_types: enum lsw_fips_mode { LSW_FIPS_UNKNOWN=0, LSW_FIPS_OFF=1, LSW_FIPS_ON=2 }


decompiled_code:
__int64 __fastcall same_secitem_as_chunk(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, unsigned int a8)
{
return chunk2(*(unsigned __int128 *)&_mm_loadu_si128((const __m128i *)&a7) >> 64, a8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, unsigned int a8)
{
return chunk2(*(unsigned __int128 *)&_mm_loadu_si128((const __m128i *)&a7) >> 64, a8);
}

original_code:
chunk_t same_secitem_as_chunk(SECItem si)
{
 return chunk2(si.data, si.len);
}

canonical_original_code:
struct chunk_t same_secitem_as_chunk(struct SECItemStr si)
{
 return chunk2(si.data, si.len);
}

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 SECItemStr { enum SECItemType type; unsigned char *data; unsigned int len; }


decompiled_code:
__int64 __fastcall same_secitem_as_shunk(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, unsigned int a8)
{
return shunk2(*(unsigned __int128 *)&_mm_loadu_si128((const __m128i *)&a7) >> 64, a8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, unsigned int a8)
{
return shunk2(*(unsigned __int128 *)&_mm_loadu_si128((const __m128i *)&a7) >> 64, a8);
}

original_code:
shunk_t same_secitem_as_shunk(SECItem si)
{
 return shunk2(si.data, si.len);
}

canonical_original_code:
struct shunk same_secitem_as_shunk(struct SECItemStr si)
{
 return shunk2(si.data, si.len);
}

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

user_defined_types: 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 }


decompiled_code:
__int64 __fastcall clone_secitem_as_chunk(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, unsigned int a8)
{
return clone_bytes(*(unsigned __int128 *)&_mm_loadu_si128((const __m128i *)&a7) >> 64, a8, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, unsigned int a8)
{
return clone_bytes(*(unsigned __int128 *)&_mm_loadu_si128((const __m128i *)&a7) >> 64, a8, a1);
}

original_code:
chunk_t clone_secitem_as_chunk(SECItem si, const char *name)
{
 chunk_t chunk = {
  .len = si.len,
  .ptr = clone_bytes(si.data, si.len, name),
 };
 return chunk;
}

canonical_original_code:
struct chunk_t clone_secitem_as_chunk(struct SECItemStr si, char *name)
{
 struct chunk_t chunk = {
  .len = si.len,
  .ptr = clone_bytes(si.data, si.len, name),
 };
 return chunk;
}

variable_types:
name
char *


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

v1 = __readfsqword(0x28u);
get_rnd_bytes(&v2_cookie_secret, 32LL);
if ( (cur_debugging & 0x10) != 0 )
DBG_dump("v2_cookie_secret", &v2_cookie_secret, 32LL);
return v1 - __readfsqword(0x28u);
}

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

v1 = __readfsqword(0x28u);
get_rnd_bytes(&v2_cookie_secret, 32LL);
if ( (cur_debugging & 0x10) != 0 )
DBG_dump("v2_cookie_secret", &v2_cookie_secret, 32LL);
return v1 - __readfsqword(0x28u);
}

original_code:
void refresh_v2_cookie_secret(void)
{
 get_rnd_bytes(&v2_cookie_secret, sizeof(v2_cookie_secret));
 if ((cur_debugging & (((lset_t)1 << (DBG_CRYPT_IX))))) {
  DBG_dump("v2_cookie_secret", &(v2_cookie_secret), sizeof(v2_cookie_secret));
 }
}

canonical_original_code:
void refresh_v2_cookie_secret()
{
 get_rnd_bytes(&v2_cookie_secret, sizeof(v2_cookie_secret));
 if ((cur_debugging & (((unsigned long)1 << (DBG_CRYPT_IX))))) {
  DBG_dump("v2_cookie_secret", &(v2_cookie_secret), sizeof(v2_cookie_secret));
 }
}


decompiled_code:
__int64 __fastcall lswglob_errfunc(const char *a1, __int64 a2)
{
log_error(lswglob_logger, a2, "problem with %s file \"%s\"", (const char *)lswglob_what, a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __int64 a2)
{
log_error(lswglob_logger, a2, "problem with %s file \"%s\"", (const char *)lswglob_what, a1);
return 1LL;
}

original_code:
static int lswglob_errfunc(const char *epath, int eerrno)
{
 { int e_ = eerrno; log_error(lswglob_logger, e_, "problem with %s file \"%s\"", lswglob_what, epath); };
 return 1;
}

canonical_original_code:
static int lswglob_errfunc(char *epath, int eerrno)
{
 { int e_ = eerrno; log_error(lswglob_logger, e_, "problem with %s file \"%s\"", lswglob_what, epath); };
 return 1;
}

variable_types:
epath
char *

variable_types: eerrno int