decompiled_code:
__int64 __fastcall unb64(char *a1, _BYTE *a2, unsigned __int64 a3)
{
char *v3; // rax
char v4; // bl
char *v5; // rax
signed __int64 v6; // rax
char v7; // bl
char v8; // r14
char *v9; // rax
signed __int64 v10; // rax
char v11; // bl
char v12; // bp
char *v13; // rax
__int64 result; // rax

if ( a3 <= 2 )
return 4294967294LL;
v3 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", *a1);
if ( !v3 )
return 4294967292LL;
v4 = 4 * (v3 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
v5 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", a1[1]);
if ( !v5 )
return 4294967291LL;
v6 = v5 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
*a2 = ((unsigned int)v6 >> 4) | v4;
v7 = 16 * v6;
v8 = a1[2];
v9 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", v8);
if ( v9 )
{
v10 = v9 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
a2[1] = ((unsigned int)v10 >> 2) | v7;
v11 = (_BYTE)v10 << 6;
v12 = a1[3];
v13 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", v12);
if ( v13 )
{
a2[2] = v11 | ((_BYTE)v13 - (unsigned __int8)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
return 3LL;
}
if ( v12 == 61 )
{
if ( (v11 & 0xC0) == 0 )
return 2LL;
return 4294967293LL;
}
result = 4294967289LL;
}
else
{
if ( v8 == 61 && a1[3] == 61 )
{
if ( (v7 & 0xF0) == 0 )
return 1LL;
return 4294967293LL;
}
result = 4294967290LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _BYTE *a2, unsigned __int64 a3)
{
char *v3; // rax
char v4; // bl
char *v5; // rax
signed __int64 v6; // rax
char v7; // bl
char v8; // r14
char *v9; // rax
signed __int64 v10; // rax
char v11; // bl
char v12; // bp
char *v13; // rax
__int64 result; // rax

if ( a3 <= 2 )
return 4294967294LL;
v3 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", *a1);
if ( !v3 )
return 4294967292LL;
v4 = 4 * (v3 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
v5 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", a1[1]);
if ( !v5 )
return 4294967291LL;
v6 = v5 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
*a2 = ((unsigned int)v6 >> 4) | v4;
v7 = 16 * v6;
v8 = a1[2];
v9 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", v8);
if ( v9 )
{
v10 = v9 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
a2[1] = ((unsigned int)v10 >> 2) | v7;
v11 = (_BYTE)v10 << 6;
v12 = a1[3];
v13 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", v12);
if ( v13 )
{
a2[2] = v11 | ((_BYTE)v13 - (unsigned __int8)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
return 3LL;
}
if ( v12 == 61 )
{
if ( (v11 & 0xC0) == 0 )
return 2LL;
return 4294967293LL;
}
result = 4294967289LL;
}
else
{
if ( v8 == 61 && a1[3] == 61 )
{
if ( (v7 & 0xF0) == 0 )
return 1LL;
return 4294967293LL;
}
result = 4294967290LL;
}
return result;
}

original_code:
static int unb64(const char *src,
   char *dst,
   size_t dstlen)
{
 const char *p;
 unsigned byte1;
 unsigned byte2;
 static const char base64[] =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 if (dstlen < 3)
  return (-2);
 p = strchr(base64, *src++);
 if (p == ((void *)0))
  return (-4);
 byte1 = (p - base64) << 2;
 p = strchr(base64, *src++);
 if (p == ((void *)0))
  return (-5);
 byte2 = p - base64;
 *dst++ = byte1 | (byte2 >> 4);
 byte1 = (byte2 & 0xf) << 4;
 p = strchr(base64, *src++);
 if (p == ((void *)0)) {
  if (*(src - 1) == '=' && *src == '=') {
   if (byte1 != 0)
    return (-3);
   return 1;
  }
  return (-6);
 }
 byte2 = p - base64;
 *dst++ = byte1 | (byte2 >> 2);
 byte1 = (byte2 & 0x3) << 6;
 p = strchr(base64, *src++);
 if (p == ((void *)0)) {
  if (*(src - 1) == '=') {
   if (byte1 != 0)
    return (-3);
   return 2;
  }
  return (-7);
 }
 byte2 = p - base64;
 *dst++ = byte1 | byte2;
 return 3;
}

canonical_original_code:
static int unb64(char *src, char *dst, unsigned long dstlen)
{
 char *p;
 unsigned int byte1;
 unsigned int byte2;
 static char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 if (dstlen < 3)
  return (-2);
 p = strchr(base64, *src++);
 if (p == ((void *)0))
  return (-4);
 byte1 = (p - base64) << 2;
 p = strchr(base64, *src++);
 if (p == ((void *)0))
  return (-5);
 byte2 = p - base64;
 *dst++ = byte1 | (byte2 >> 4);
 byte1 = (byte2 & 0xf) << 4;
 p = strchr(base64, *src++);
 if (p == ((void *)0)) {
  if (*(src - 1) == '=' && *src == '=') {
   if (byte1 != 0)
    return (-3);
   return 1;
  }
  return (-6);
 }
 byte2 = p - base64;
 *dst++ = byte1 | (byte2 >> 2);
 byte1 = (byte2 & 0x3) << 6;
 p = strchr(base64, *src++);
 if (p == ((void *)0)) {
  if (*(src - 1) == '=') {
   if (byte1 != 0)
    return (-3);
   return 2;
  }
  return (-7);
 }
 byte2 = p - base64;
 *dst++ = byte1 | byte2;
 return 3;
}

variable_types:
p
char *


unhex

repo: libreswan/libreswan

original_code:
static int unhex(const char *src,
   char *dst,
   size_t dstlen)
{
 const char *p;
 unsigned byte;
 static const char hex[] = "0123456789abcdef";
 if (dstlen < 1)
  return (-2);
 p = strchr(hex, *src);
 if (p == ((void *)0))
  p = strchr(hex, char_tolower(*src));
 if (p == ((void *)0))
  return (-4);
 byte = (p - hex) << 4;
 src++;
 p = strchr(hex, *src);
 if (p == ((void *)0))
  p = strchr(hex, char_tolower(*src));
 if (p == ((void *)0))
  return (-5);
 byte |= (p - hex);
 *dst = byte;
 return 1;
}

canonical_original_code:
static int unhex(char *src, char *dst, unsigned long dstlen)
{
 char *p;
 unsigned int byte;
 static char hex[] = "0123456789abcdef";
 if (dstlen < 1)
  return (-2);
 p = strchr(hex, *src);
 if (p == ((void *)0))
  p = strchr(hex, char_tolower(*src));
 if (p == ((void *)0))
  return (-4);
 byte = (p - hex) << 4;
 src++;
 p = strchr(hex, *src);
 if (p == ((void *)0))
  p = strchr(hex, char_tolower(*src));
 if (p == ((void *)0))
  return (-5);
 byte |= (p - hex);
 *dst = byte;
 return 1;
}

variable_types:
src
char *

variable_types:
dst
char *

variable_types:
dstlen
unsigned long

variable_types:
byte
unsigned int

variable_types:
hex
char []

return_type: int


ttodata

decompiled_code:
const char *__fastcall ttodata(char *a1, unsigned __int64 a2, int a3, char *a4, __int64 a5, _QWORD *a6)
{
if ( !a2 )
a2 = strlen(a1);
return ttodatav(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
const char *__fastcall func5(char *a1, unsigned __int64 a2, int a3, char *a4, __int64 a5, _QWORD *a6)
{
if ( !a2 )
a2 = strlen(a1);
return func2(a1, a2, a3, a4, a5, a6);
}

original_code:
const char *ttodata(const char *src,
      size_t srclen,
      int base,
      void *dst,
      size_t dstlen,
      size_t *lenp)
{
 if (srclen == 0)
  srclen = strlen(src);
 return ttodatav(src, srclen, base, dst, dstlen, lenp);
}

canonical_original_code:
char *ttodata(char *src, unsigned long srclen, int base, void *dst, unsigned long dstlen, unsigned long *lenp)
{
 if (srclen == 0)
  srclen = strlen(src);
 return ttodatav(src, srclen, base, dst, dstlen, lenp);
}

variable_types:
srclen
unsigned long

variable_types: base int

variable_types:
dst
void *

variable_types:
lenp
unsigned long *

return_type: char *


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

for ( result = *a1; result; a1 += 2 )
{
if ( a1[1] == a2 )
break;
result = a1[2];
}
return result;
}

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

for ( result = *a1; result; a1 += 2 )
{
if ( a1[1] == a2 )
break;
result = a1[2];
}
return result;
}

original_code:
const char *sparse_name(sparse_names sd, unsigned long val)
{
 for (const struct sparse_name *p = sd; p->name != ((void *)0); p++) {
  if (p->value == val) {
   return p->name;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *sparse_name(struct sparse_name sd[], unsigned long val)
{
 for (struct sparse_name *p = sd; p->name != ((void *)0); p++) {
  if (p->value == val) {
   return p->name;
  }
 }
 return ((void *)0);
}

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

variable_types:
val
unsigned long

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


decompiled_code:
__int64 __fastcall jam_sparse(__int64 a1, __int64 *a2, __int64 a3)
{
__int64 v4; // rax
__int64 result; // rax

v4 = sparse_name(a2, a3);
if ( v4 )
result = jam_string(a1, v4);
else
result = jam(a1, "%lu??", a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 *a2, __int64 a3)
{
__int64 v4; // rax
__int64 result; // rax

v4 = func0(a2, a3);
if ( v4 )
result = jam_string(a1, v4);
else
result = jam(a1, "%lu??", a3);
return result;
}

original_code:
size_t jam_sparse(struct jambuf *buf, sparse_names sd, unsigned long val)
{
 const char *p = sparse_name(sd, val);
 if (p != ((void *)0)) {
  return jam_string(buf, p);
 }
 return jam(buf, "%lu??", val);
}

canonical_original_code:
unsigned long jam_sparse(struct jambuf *buf, struct sparse_name sd[], unsigned long val)
{
 char *p = sparse_name(sd, val);
 if (p != ((void *)0)) {
  return jam_string(buf, p);
 }
 return jam(buf, "%lu??", val);
}

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

return_type: unsigned long

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


decompiled_code:
__int64 __fastcall str_sparse(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12

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

original_code:
const char *str_sparse(sparse_names sd, unsigned long val, sparse_buf *buf)
{
 const char *p = sparse_name(sd, val);
 if (p != ((void *)0)) {
  return p;
 }
 snprintf(buf->buf, sizeof(buf->buf), "%lu??", val);
 return buf->buf;
}

canonical_original_code:
char *str_sparse(struct sparse_name sd[], unsigned long val, struct sparse_buf *buf)
{
 char *p = sparse_name(sd, val);
 if (p != ((void *)0)) {
  return p;
 }
 snprintf(buf->buf, sizeof(buf->buf), "%lu??", val);
 return buf->buf;
}

variable_types:
buf
struct sparse_buf { char buf[16]; } *


decompiled_code:
__int64 __fastcall keyword_by_value_linear(__int64 *a1, int a2)
{
unsigned __int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rdi
unsigned int v5; // edx
__int64 result; // rax

v2 = a1[1];
v3 = 0LL;
if ( !v2 )
return 0LL;
v4 = *a1;
v5 = 0;
while ( 1 )
{
result = v4 + 32 * v3;
if ( *(_DWORD *)(result + 16) == a2 )
break;
v3 = ++v5;
if ( v5 >= v2 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
unsigned __int64 v2; // rcx
__int64 v3; // rax
__int64 v4; // rdi
unsigned int v5; // edx
__int64 result; // rax

v2 = a1[1];
v3 = 0LL;
if ( !v2 )
return 0LL;
v4 = *a1;
v5 = 0;
while ( 1 )
{
result = v4 + 32 * v3;
if ( *(_DWORD *)(result + 16) == a2 )
break;
v3 = ++v5;
if ( v5 >= v2 )
return 0LL;
}
return result;
}

original_code:
const struct keyword *keyword_by_value_linear(const struct keywords *keywords,
           unsigned value)
{
 for (unsigned ki = 0; ki < keywords->nr_values; ki++) {
  const struct keyword *kv = &keywords->values[ki];
  if (kv->value == value) {
   return kv;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct keyword *keyword_by_value_linear(struct keywords *keywords, unsigned int value)
{
 for (unsigned int ki = 0; ki < keywords->nr_values; ki++) {
  struct keyword *kv = &keywords->values[ki];
  if (kv->value == value) {
   return kv;
  }
 }
 return ((void *)0);
}

variable_types: struct keywords { struct keyword *values; unsigned long nr_values; struct keyword *(*by_value)(struct keywords *, unsigned int); char *name; } *

variable_types:
value
unsigned int

variable_types:
ki
unsigned int

variable_types: struct keyword { char *name; char *sname; unsigned int value; char *details; } *


decompiled_code:
__int64 __fastcall keyword_by_value(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 16))();
}

original_code:
const struct keyword *keyword_by_value(const struct keywords *keywords,
           unsigned value)
{
 return keywords->by_value(keywords, value);
}

canonical_original_code:
struct keyword *keyword_by_value(struct keywords *keywords, unsigned int value)
{
 return keywords->by_value(keywords, value);
}

return_type: struct keyword { char *name; char *sname; unsigned int value; char *details; } *

user_defined_types: struct keywords { struct keyword *values; unsigned long nr_values; struct keyword *(*by_value)(struct keywords *, unsigned int); char *name; }


decompiled_code:
__int64 __fastcall jam_keyword_name(__int64 a1, __int64 a2, unsigned int a3)
{
_QWORD *v4; // rax
__int64 result; // rax

v4 = (_QWORD *)keyword_by_value(a2);
if ( v4 )
result = jam_string(a1, *v4);
else
result = jam(a1, "'%s %u'", *(const char **)(a2 + 24), a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
_QWORD *v4; // rax
__int64 result; // rax

v4 = (_QWORD *)func4(a2);
if ( v4 )
result = jam_string(a1, *v4);
else
result = jam(a1, "'%s %u'", *(const char **)(a2 + 24), a3);
return result;
}

original_code:
size_t jam_keyword_name(struct jambuf *buf, const struct keywords *keywords, unsigned value)
{
 const struct keyword *keyword = keyword_by_value(keywords, value);
 if (keyword == ((void *)0)) {
  return jam(buf, "'%s %u'", keywords->name, value);
 } else {
  return jam_string(buf, keyword->name);
 }
}

canonical_original_code:
unsigned long jam_keyword_name(struct jambuf *buf, struct keywords *keywords, unsigned int value)
{
 struct keyword *keyword = keyword_by_value(keywords, value);
 if (keyword == ((void *)0)) {
  return jam(buf, "'%s %u'", keywords->name, value);
 } else {
  return jam_string(buf, keyword->name);
 }
}

variable_types: struct keywords { struct keyword { char *name; char *sname; unsigned int value; char *details; } *values; unsigned long nr_values; struct keyword *(*by_value)(struct keywords *, unsigned int); char *name; } *

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


decompiled_code:
__int64 __fastcall jam_keyword_sname(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 result; // rax

v4 = keyword_by_value(a2);
if ( v4 )
result = jam_string(a1, *(_QWORD *)(v4 + 8));
else
result = jam(a1, "'%s %u'", *(const char **)(a2 + 24), a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
__int64 result; // rax

v4 = func4(a2);
if ( v4 )
result = jam_string(a1, *(_QWORD *)(v4 + 8));
else
result = jam(a1, "'%s %u'", *(const char **)(a2 + 24), a3);
return result;
}

original_code:
size_t jam_keyword_sname(struct jambuf *buf, const struct keywords *keywords, unsigned value)
{
 const struct keyword *keyword = keyword_by_value(keywords, value);
 if (keyword == ((void *)0)) {
  return jam(buf, "'%s %u'", keywords->name, value);
 } else {
  return jam_string(buf, keyword->sname);
 }
}

canonical_original_code:
unsigned long jam_keyword_sname(struct jambuf *buf, struct keywords *keywords, unsigned int value)
{
 struct keyword *keyword = keyword_by_value(keywords, value);
 if (keyword == ((void *)0)) {
  return jam(buf, "'%s %u'", keywords->name, value);
 } else {
  return jam_string(buf, keyword->sname);
 }
}

user_defined_types: struct keyword { char *name; char *sname; unsigned int value; char *details; }


decompiled_code:
unsigned __int64 __fastcall eat_whitespace(__int64 a1)
{
__int64 v1; // rcx
_BYTE *v2; // rax
_BYTE *v3; // rcx
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

v1 = *(_QWORD *)(a1 + 8);
v5 = __readfsqword(0x28u);
if ( v1 )
{
v2 = *(_BYTE **)a1;
v3 = (_BYTE *)(*(_QWORD *)a1 + v1);
do
{
if ( *v2 != 32 && *v2 != 9 )
break;
*(_QWORD *)a1 = ++v2;
*(_QWORD *)(a1 + 8) = v3 - v2;
}
while ( v2 != v3 );
}
return v5 - __readfsqword(0x28u);
}

original_code:
static void eat_whitespace(chunk_t *src)
{
 while (src->len > 0 && (*src->ptr == ' ' || *src->ptr == '\t')) {
  src->ptr++;
  src->len--;
 }
}

canonical_original_code:
static void eat_whitespace(struct chunk_t *src)
{
 while (src->len > 0 && (*src->ptr == ' ' || *src->ptr == '\t')) {
  src->ptr++;
  src->len--;
 }
}

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

return_type: void


decompiled_code:
__int64 __fastcall extract_token(_QWORD *a1, char a2, __int64 a3)
{
char *v4; // rax
__int64 v5; // rcx

v4 = (char *)memchr(*(const void **)a3, a2, *(_QWORD *)(a3 + 8));
*a1 = 0LL;
a1[1] = 0LL;
if ( !v4 )
return 0LL;
v5 = (unsigned int)v4 - (unsigned int)*(_QWORD *)a3;
*a1 = *(_QWORD *)a3;
a1[1] = v5;
*(_QWORD *)a3 = v4 + 1;
*(_QWORD *)(a3 + 8) += ~a1[1];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, char a2, __int64 a3)
{
char *v4; // rax
__int64 v5; // rcx

v4 = (char *)memchr(*(const void **)a3, a2, *(_QWORD *)(a3 + 8));
*a1 = 0LL;
a1[1] = 0LL;
if ( !v4 )
return 0LL;
v5 = (unsigned int)v4 - (unsigned int)*(_QWORD *)a3;
*a1 = *(_QWORD *)a3;
a1[1] = v5;
*(_QWORD *)a3 = v4 + 1;
*(_QWORD *)(a3 + 8) += ~a1[1];
return 1LL;
}

original_code:
static _Bool extract_token(chunk_t *token, char termination, chunk_t *src)
{
 uint8_t *eot = memchr(src->ptr, termination, src->len);
 *token = ((const chunk_t) { .ptr = ((void *)0), .len = 0 });
 if (eot == ((void *)0))
  return 0;
 token->ptr = src->ptr;
 token->len = (unsigned)(eot - src->ptr);
 src->ptr = eot + 1;
 src->len -= (token->len + 1);
 return 1;
}

canonical_original_code:
static _Bool extract_token(struct chunk_t *token, char termination, struct chunk_t *src)
{
 unsigned char *eot = memchr(src->ptr, termination, src->len);
 *token = ((struct chunk_t) { .ptr = ((void *)0), .len = 0 });
 if (eot == ((void *)0))
  return 0;
 token->ptr = src->ptr;
 token->len = (unsigned int)(eot - src->ptr);
 src->ptr = eot + 1;
 src->len -= (token->len + 1);
 return 1;
}

variable_types: termination char

variable_types:
src
struct chunk_t *

variable_types:
eot
unsigned char *

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


fetchline

original_code:
static _Bool fetchline(chunk_t *src, chunk_t *line)
{
 if (src->len == 0)
  return 0;
 if (extract_token(line, '\n', src)) {
  if (line->len > 0 && *(line->ptr + line->len - 1) == '\r')
   line->len--;
 } else {
  *line = *src;
  src->ptr += src->len;
  src->len = 0;
 }
 return 1;
}

canonical_original_code:
static _Bool fetchline(struct chunk_t *src, struct chunk_t *line)
{
 if (src->len == 0)
  return 0;
 if (extract_token(line, '\n', src)) {
  if (line->len > 0 && *(line->ptr + line->len - 1) == '\r')
   line->len--;
 } else {
  *line = *src;
  src->ptr += src->len;
  src->len = 0;
 }
 return 1;
}

variable_types:
line
struct chunk_t *


present

decompiled_code:
__int64 __fastcall present(char *s2, __int64 a2)
{
unsigned int v2; // er14
unsigned int v3; // eax
unsigned __int64 v4; // r13
__int64 v5; // rbp
const char *v6; // r15

v2 = 0;
v3 = strlen(s2);
v4 = *(_QWORD *)(a2 + 8);
v5 = v3;
if ( v4 >= v3 )
{
v6 = *(const char **)a2;
if ( !strncmp(*(const char **)a2, s2, v3) )
{
v2 = 1;
*(_QWORD *)a2 = &v6[v5];
*(_QWORD *)(a2 + 8) = v4 - v5;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, __int64 a2)
{
unsigned int v2; // er14
unsigned int v3; // eax
unsigned __int64 v4; // r13
__int64 v5; // rbp
const char *v6; // r15

v2 = 0;
v3 = strlen(s2);
v4 = *(_QWORD *)(a2 + 8);
v5 = v3;
if ( v4 >= v3 )
{
v6 = *(const char **)a2;
if ( !strncmp(*(const char **)a2, s2, v3) )
{
v2 = 1;
*(_QWORD *)a2 = &v6[v5];
*(_QWORD *)(a2 + 8) = v4 - v5;
}
}
return v2;
}

original_code:
static _Bool present(const char* pattern, chunk_t* ch)
{
 unsigned pattern_len = strlen(pattern);
 if (ch->len >= pattern_len &&
  (strncmp(((char *)ch->ptr), (pattern), (pattern_len)) == 0)) {
  ch->ptr += pattern_len;
  ch->len -= pattern_len;
  return 1;
 }
 return 0;
}

canonical_original_code:
static _Bool present(char *pattern, struct chunk_t *ch)
{
 unsigned int pattern_len = strlen(pattern);
 if (ch->len >= pattern_len &&
  (strncmp(((char *)ch->ptr), (pattern), (pattern_len)) == 0)) {
  ch->ptr += pattern_len;
  ch->len -= pattern_len;
  return 1;
 }
 return 0;
}

variable_types:
pattern
char *


original_code:
static _Bool find_boundary(const char *tag, chunk_t *line)
{
 chunk_t name = ((const chunk_t) { .ptr = ((void *)0), .len = 0 });
 if (!present("-----", line))
  return 0;
 if (!present(tag, line))
  return 0;
 if (*line->ptr != ' ')
  return 0;
 line->ptr++;
 line->len--;
 name.ptr = line->ptr;
 while (line->len > 0) {
  if (present("-----", line)) {
   { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("  -----%s %.*s-----", tag, (int)name.len, name.ptr); } };
   return 1;
  }
  line->ptr++;
  line->len--;
  name.len++;
 }
 return 0;
}

canonical_original_code:
static _Bool find_boundary(char *tag, struct chunk_t *line)
{
 struct chunk_t name = ((const chunk_t) { .ptr = ((void *)0), .len = 0 });
 if (!present("-----", line))
  return 0;
 if (!present(tag, line))
  return 0;
 if (*line->ptr != ' ')
  return 0;
 line->ptr++;
 line->len--;
 name.ptr = line->ptr;
 while (line->len > 0) {
  if (present("-----", line)) {
   { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("  -----%s %.*s-----", tag, (int)name.len, name.ptr); } };
   return 1;
  }
  line->ptr++;
  line->len--;
  name.len++;
 }
 return 0;
}

variable_types:
tag
char *

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


decompiled_code:
__int64 __fastcall reqid_ah(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return a1;
}

original_code:
reqid_t reqid_ah(reqid_t r)
{
 return r;
}

canonical_original_code:
unsigned int reqid_ah(unsigned int r)
{
 return r;
}

variable_types:
r
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall reqid_esp(unsigned int a1)
{
return a1 - ((a1 < 0x4000) - 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return a1 - ((a1 < 0x4000) - 1);
}

original_code:
reqid_t reqid_esp(reqid_t r)
{
 return r <= 0x3fff ? r : (r + 1);
}

canonical_original_code:
unsigned int reqid_esp(unsigned int r)
{
 return r <= 0x3fff ? r : (r + 1);
}


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

result = a1;
if ( a1 > 0x3FFF )
result = a1 + 2;
return result;
}

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

result = a1;
if ( a1 > 0x3FFF )
result = a1 + 2;
return result;
}

original_code:
reqid_t reqid_ipcomp(reqid_t r)
{
 return r <= 0x3fff ? r : (r + 2);
}

canonical_original_code:
unsigned int reqid_ipcomp(unsigned int r)
{
 return r <= 0x3fff ? r : (r + 2);
}


realtime

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

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

original_code:
realtime_t realtime(time_t time)
{
 return (realtime_t) { { time, 0, }, };
}

canonical_original_code:
struct realtime_t realtime(long time)
{
 return (struct realtime_t) { { time, 0, }, };
}

variable_types: time long

return_type: struct realtime_t { struct timeval { long tv_sec; long tv_usec; } rt; }

user_defined_types: struct realtime_t { struct timeval rt; }


decompiled_code:
__int64 realtime_ms()
{
return timeval_ms();
}

canonical_decompiled_code:
__int64 func1()
{
return timeval_ms();
}

original_code:
realtime_t realtime_ms(intmax_t milliseconds)
{
 return (realtime_t) { .rt = timeval_ms(milliseconds), };
}

canonical_original_code:
struct realtime_t realtime_ms(long milliseconds)
{
 return (struct realtime_t) { .rt = timeval_ms(milliseconds), };
}

variable_types: milliseconds long

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


realmicroseconds

decompiled_code:
__int64 __fastcall realmicroseconds(__int64 a1, __int64 a2)
{
return 1000000 * a1 + a2;
}

original_code:
uint64_t realmicroseconds(realtime_t t)
{
 return t.rt.tv_sec * 1000000LL + t.rt.tv_usec;
}

canonical_original_code:
unsigned long realmicroseconds(struct realtime_t t)
{
 return t.rt.tv_sec * 1000000LL + t.rt.tv_usec;
}

variable_types: struct realtime_t { struct timeval { long tv_sec; long tv_usec; } rt; }


realtimesum

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

result = a1 + a7;
if ( (__int64)((*(unsigned __int128 *)&_mm_loadu_si128((const __m128i *)&a7) >> 64) + a2) > 999999 )
++result;
return result;
}

original_code:
realtime_t realtimesum(realtime_t t, deltatime_t d)
{
 realtime_t s;
 do { (&s.rt)->tv_sec = (&t.rt)->tv_sec + (&d.dt)->tv_sec; (&s.rt)->tv_usec = (&t.rt)->tv_usec + (&d.dt)->tv_usec; if ((&s.rt)->tv_usec >= 1000000) { ++(&s.rt)->tv_sec; (&s.rt)->tv_usec -= 1000000; } } while (0);
 return s;
}

canonical_original_code:
struct realtime_t realtimesum(struct realtime_t t, struct deltatime_t d)
{
 struct realtime_t s;
 do { (&s.rt)->tv_sec = (&t.rt)->tv_sec + (&d.dt)->tv_sec; (&s.rt)->tv_usec = (&t.rt)->tv_usec + (&d.dt)->tv_usec; if ((&s.rt)->tv_usec >= 1000000) { ++(&s.rt)->tv_sec; (&s.rt)->tv_usec -= 1000000; } } while (0);
 return s;
}

variable_types:
t
struct realtime_t

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


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

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

original_code:
_Bool is_realtime_epoch(realtime_t t)
{
 return !((&t.rt)->tv_sec || (&t.rt)->tv_usec);
}

canonical_original_code:
_Bool is_realtime_epoch(struct realtime_t t)
{
 return !((&t.rt)->tv_sec || (&t.rt)->tv_usec);
}


decompiled_code:
__int64 realtime_sub_sign()
{
return timeval_sub_sign();
}

canonical_decompiled_code:
__int64 func5()
{
return timeval_sub_sign();
}

original_code:
int realtime_sub_sign(realtime_t l, realtime_t r)
{
 return timeval_sub_sign(l.rt, r.rt);
}

canonical_original_code:
int realtime_sub_sign(struct realtime_t l, struct realtime_t r)
{
 return timeval_sub_sign(l.rt, r.rt);
}

variable_types:
r
struct realtime_t


realtimediff

decompiled_code:
__int64 __fastcall realtimediff(__int64 a1)
{
deltatime_timevals_diff();
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
deltatime_timevals_diff();
return a1;
}

original_code:
deltatime_t realtimediff(realtime_t a, realtime_t b)
{
 return deltatime_timevals_diff(a.rt, b.rt);
}

canonical_original_code:
struct deltatime_t realtimediff(struct realtime_t a, struct realtime_t b)
{
 return deltatime_timevals_diff(a.rt, b.rt);
}

variable_types: struct realtime_t { struct timeval rt; }

variable_types:
b
struct realtime_t

return_type: struct deltatime_t { struct timeval { long tv_sec; long tv_usec; } dt; _Bool is_set; }

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


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

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

original_code:
clockid_t realtime_clockid(void)
{
 return 0;
}

canonical_original_code:
int realtime_clockid()
{
 return 0;
}


realnow

decompiled_code:
__time_t realnow()
{
unsigned int v0; // ebx
int *v2; // rax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-10h]

v4 = __readfsqword(0x28u);
v0 = realtime_clockid();
if ( clock_gettime(v0, &v3) < 0 )
{
v2 = _errno_location();
fatal_errno(5LL, &global_logger, (unsigned int)*v2, "clock_gettime(%d,...) call in realnow() failed", v0);
}
return v3.tv_sec;
}

canonical_decompiled_code:
__time_t func8()
{
unsigned int v0; // ebx
int *v2; // rax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v4; // [rsp+18h] [rbp-10h]

v4 = __readfsqword(0x28u);
v0 = func7();
if ( clock_gettime(v0, &v3) < 0 )
{
v2 = _errno_location();
fatal_errno(5LL, &global_logger, (unsigned int)*v2, "clock_gettime(%d,...) call in realnow() failed", v0);
}
return v3.tv_sec;
}

original_code:
realtime_t realnow(void)
{
 struct timespec ts;
 int e = clock_gettime(realtime_clockid(), &ts);
 if (e < 0) {
  fatal_errno(PLUTO_EXIT_KERNEL_FAIL, &global_logger, (*__errno_location ()),
       "clock_gettime(%d,...) call in realnow() failed",
       realtime_clockid());
 }
 realtime_t t = {
  .rt = {
   .tv_sec = ts.tv_sec,
   .tv_usec = ts.tv_nsec / 1000,
  },
 };
 return t;
}

canonical_original_code:
struct realtime_t realnow()
{
 struct timespec ts;
 int e = clock_gettime(realtime_clockid(), &ts);
 if (e < 0) {
  fatal_errno(PLUTO_EXIT_KERNEL_FAIL, &global_logger, (*__errno_location ()),
       "clock_gettime(%d,...) call in realnow() failed",
       realtime_clockid());
 }
 struct realtime_t t = {
  .rt = {
   .tv_sec = ts.tv_sec,
   .tv_usec = ts.tv_nsec / 1000,
  },
 };
 return t;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: e int


original_code:
size_t jam_realtime(struct jambuf *buf, const realtime_t rtm, _Bool utc)
{
 static const char *months[] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 size_t s = 0;
 if (is_realtime_epoch(rtm)) {
  s += jam(buf, "--- -- --:--:--%s----", (utc) ? " UTC " : " ");
 } else {
  struct realtm t = (utc ? utc_realtime : local_realtime)(rtm);
  s += jam(buf, "%s %02d %02d:%02d:%02d%s%04d",
    months[t.tm.tm_mon], t.tm.tm_mday, t.tm.tm_hour,
    t.tm.tm_min, t.tm.tm_sec,
    (utc) ? " UTC " : " ", t.tm.tm_year + 1900);
 }
 return s;
}

canonical_original_code:
unsigned long jam_realtime(struct jambuf *buf, struct realtime_t rtm, _Bool utc)
{
 static char *months[] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 unsigned long s = 0;
 if (is_realtime_epoch(rtm)) {
  s += jam(buf, "--- -- --:--:--%s----", (utc) ? " UTC " : " ");
 } else {
  struct realtm t = (utc ? utc_realtime : local_realtime)(rtm);
  s += jam(buf, "%s %02d %02d:%02d:%02d%s%04d",
    months[t.tm.tm_mon], t.tm.tm_mday, t.tm.tm_hour,
    t.tm.tm_min, t.tm.tm_sec,
    (utc) ? " UTC " : " ", t.tm.tm_year + 1900);
 }
 return s;
}

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

variable_types:
months
char *[]

variable_types:
s
unsigned long

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

user_defined_types: struct realtm { struct tm tm; long microsec; }


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

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

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

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

original_code:
const char *str_realtime(realtime_t r, _Bool utc, realtime_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_realtime(&jambuf, r, utc);
 return buf->buf;
}

canonical_original_code:
char *str_realtime(struct realtime_t r, _Bool utc, struct realtime_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_realtime(&jambuf, r, utc);
 return buf->buf;
}

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

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


decompiled_code:
__int64 __fastcall hash_connection_serialno(__int64 a1)
{
__int64 v1; // rdi
__int64 v2; // rdx

v1 = shunk2(a1, 4LL);
return hash_bytes(v1, v2, zero_hash);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rdi
__int64 v2; // rdx

v1 = shunk2(a1, 4LL);
return hash_bytes(v1, v2, zero_hash);
}

original_code:
static hash_t hash_connection_serialno(const co_serial_t *serialno)
{
 return ({ shunk_t h_ = shunk2(&(*serialno), sizeof(*serialno)); hash_bytes(h_.ptr, h_.len, zero_hash); });
}

canonical_original_code:
static struct hash_t hash_connection_serialno(enum co_serial_t *serialno)
{
 return ({ struct shunk h_ = shunk2(&(*serialno), sizeof(*serialno)); hash_bytes(h_.ptr, h_.len, zero_hash); });
}

variable_types: enum co_serial_t { UNSET_CO_SERIAL=0, MAX_CO_SERIAL=expr } *

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

return_type: struct hash_t { unsigned int hash; }


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

v1 = __readfsqword(0x28u);
if ( (cur_debugging & 1) != 0 )
DBG_log("kernel_alg_init()");
ipcomp_num = 0LL;
integ_num = 0LL;
memset(&integ_by_fqn, 0, 0x100uLL);
memset(&encrypt_by_fqn, 0, 0x100uLL);
encrypt_num = 0LL;
memset(&ipcomp_by_fqn, 0, 0x100uLL);
return v1 - __readfsqword(0x28u);
}

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

v1 = __readfsqword(0x28u);
if ( (cur_debugging & 1) != 0 )
DBG_log("kernel_alg_init()");
ipcomp_num = 0LL;
integ_num = 0LL;
memset(&integ_by_fqn, 0, 0x100uLL);
memset(&encrypt_by_fqn, 0, 0x100uLL);
encrypt_num = 0LL;
memset(&ipcomp_by_fqn, 0, 0x100uLL);
return v1 - __readfsqword(0x28u);
}

original_code:
void kernel_alg_init(void)
{
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("kernel_alg_init()"); } };
 memset((&integ_by_fqn), '\0', sizeof(*(&integ_by_fqn)));
 memset((&encrypt_by_fqn), '\0', sizeof(*(&encrypt_by_fqn)));
 memset((&ipcomp_by_fqn), '\0', sizeof(*(&ipcomp_by_fqn)));
 encrypt_num = integ_num = ipcomp_num = 0;
}

canonical_original_code:
void kernel_alg_init()
{
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("kernel_alg_init()"); } };
 memset((&integ_by_fqn), '\0', sizeof(*(&integ_by_fqn)));
 memset((&encrypt_by_fqn), '\0', sizeof(*(&encrypt_by_fqn)));
 memset((&ipcomp_by_fqn), '\0', sizeof(*(&ipcomp_by_fqn)));
 encrypt_num = integ_num = ipcomp_num = 0;
}


decompiled_code:
__int64 kernel_alg_encrypt_count()
{
return encrypt_num;
}

canonical_decompiled_code:
__int64 func11()
{
return encrypt_num;
}

original_code:
int kernel_alg_encrypt_count(void)
{
 return encrypt_num;
}

canonical_original_code:
int kernel_alg_encrypt_count()
{
 return encrypt_num;
}


decompiled_code:
__int64 kernel_alg_integ_count()
{
return integ_num;
}

canonical_decompiled_code:
__int64 func12()
{
return integ_num;
}

original_code:
int kernel_alg_integ_count(void)
{
 return integ_num;
}

canonical_original_code:
int kernel_alg_integ_count()
{
 return integ_num;
}


decompiled_code:
__int64 kernel_alg_ipcomp_count()
{
return ipcomp_num;
}

canonical_decompiled_code:
__int64 func13()
{
return ipcomp_num;
}

original_code:
int kernel_alg_ipcomp_count(void)
{
 return ipcomp_num;
}

canonical_original_code:
int kernel_alg_ipcomp_count()
{
 return ipcomp_num;
}


decompiled_code:
const char *__fastcall vet_seclabel(__int64 a1, __int64 a2)
{
if ( (cur_debugging & 1) != 0 )
DBG_log("%s() not implemented: %zu", "vet_seclabel", a2);
return "Labeled IPsec not supported";
}

canonical_decompiled_code:
const char *__fastcall func0(__int64 a1, __int64 a2)
{
if ( (cur_debugging & 1) != 0 )
DBG_log("%s() not implemented: %zu", "vet_seclabel", a2);
return "Labeled IPsec not supported";
}

original_code:
err_t vet_seclabel(shunk_t sl)
{
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("%s() not implemented: %zu", __func__, sl.len); } };
 return "Labeled IPsec not supported";
}

canonical_original_code:
char *vet_seclabel(struct shunk sl)
{
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("%s() not implemented: %zu", __func__, sl.len); } };
 return "Labeled IPsec not supported";
}

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


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

original_code:
shunk_t shunk2(const void *ptr, int len)
{
 return (shunk_t) { .ptr = ptr, .len = len, };
}

canonical_original_code:
struct shunk shunk2(void *ptr, int len)
{
 return (struct shunk) { .ptr = ptr, .len = len, };
}

variable_types:
ptr
void *

variable_types: len int

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


decompiled_code:
__int64 __fastcall shunk1(const char *a1)
{
if ( !a1 )
return 0LL;
strlen(a1);
return shunk2((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
if ( !a1 )
return 0LL;
strlen(a1);
return func0((__int64)a1);
}

original_code:
shunk_t shunk1(const char *ptr)
{
 if (ptr == ((void *)0)) {
  return null_shunk;
 } else {
  return shunk2(ptr, strlen(ptr));
 }
}

canonical_original_code:
struct shunk shunk1(char *ptr)
{
 if (ptr == ((void *)0)) {
  return null_shunk;
 } else {
  return shunk2(ptr, strlen(ptr));
 }
}

variable_types:
ptr
char *


shunks

original_code:
struct shunks *shunks(shunk_t input, const char *delims,
        enum shunks_opt opt, where_t where)
{
 { if ((cur_debugging & (((lset_t)1 << (DBG_TMI_IX))))) { DBG_log("%s() input=\"""%.*s""\" delims=\"%s\"", __func__, ((int) (input).len), (const char *) ((input).ptr), delims); } };
 size_t tokens_size = sizeof(struct shunks);
 struct shunks *tokens = alloc_bytes(tokens_size, where->func);
 shunk_t cursor = input;
 while (1) {
  char delim;
  shunk_t token = shunk_token(&cursor, &delim, delims);
  if (token.ptr == ((void *)0)) {
   break;
  }
  if (token.len == 0) {
   if (opt == EAT_EMPTY_SHUNKS) {
    { if ((cur_debugging & (((lset_t)1 << (DBG_TMI_IX))))) { DBG_log("%s() pass 1 eat empty", __func__); } };
    continue;
   }
   tokens->kept_empty_shunks = 1;
  }
  { if ((cur_debugging & (((lset_t)1 << (DBG_TMI_IX))))) { DBG_log("%s() [%u] \"""%.*s""\"", __func__, tokens->len, ((int) (token).len), (const char *) ((token).ptr)); } };
  void *new = tokens;
  size_t new_size = tokens_size + sizeof(shunk_t);
  realloc_bytes(&new, tokens_size, new_size, where->func);
  tokens = new;
  tokens_size = new_size;
  tokens->list[tokens->len] = token;
  tokens->len++;
 }
 return tokens;
}

canonical_original_code:
struct shunks *shunks(struct shunk input, char *delims, enum shunks_opt opt, struct where *where)
{
 { if ((cur_debugging & (((unsigned long)1 << (DBG_TMI_IX))))) { DBG_log("%s() input=\"""%.*s""\" delims=\"%s\"", __func__, ((int) (input).len), (char *) ((input).ptr), delims); } };
 unsigned long tokens_size = sizeof(struct shunks);
 struct shunks *tokens = alloc_bytes(tokens_size, where->func);
 struct shunk cursor = input;
 while (1) {
  char delim;
  struct shunk token = shunk_token(&cursor, &delim, delims);
  if (token.ptr == ((void *)0)) {
   break;
  }
  if (token.len == 0) {
   if (opt == EAT_EMPTY_SHUNKS) {
    { if ((cur_debugging & (((unsigned long)1 << (DBG_TMI_IX))))) { DBG_log("%s() pass 1 eat empty", __func__); } };
    continue;
   }
   tokens->kept_empty_shunks = 1;
  }
  { if ((cur_debugging & (((unsigned long)1 << (DBG_TMI_IX))))) { DBG_log("%s() [%u] \"""%.*s""\"", __func__, tokens->len, ((int) (token).len), (char *) ((token).ptr)); } };
  void *new = tokens;
  unsigned long new_size = tokens_size + sizeof(shunk_t);
  realloc_bytes(&new, tokens_size, new_size, where->func);
  tokens = new;
  tokens_size = new_size;
  tokens->list[tokens->len] = token;
  tokens->len++;
 }
 return tokens;
}

variable_types:
input
struct shunk

variable_types:
delims
char *

variable_types: enum shunks_opt { KEEP_EMPTY_SHUNKS=0, EAT_EMPTY_SHUNKS=1 }

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

variable_types: struct shunks { _Bool kept_empty_shunks; unsigned int len; struct shunk { void *ptr; unsigned long len; } list[]; } *

variable_types: delim char

variable_types:
new
void *

user_defined_types: struct shunks { _Bool kept_empty_shunks; unsigned int len; struct shunk list[]; }


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

if ( a1 > 0x4036 )
{
result = 0LL;
if ( a1 == 40960 )
result = 20LL;
}
else if ( a1 <= 0x3FFF )
{
if ( a1 - 1 > 0x25 )
{
LABEL_4:
result = 0LL;
}
else
{
switch ( a1 )
{
case 1u:
result = 29LL;
break;
case 5u:
result = 12LL;
break;
case 7u:
result = 13LL;
break;
case 0xEu:
result = 19LL;
break;
case 0x11u:
result = 11LL;
break;
case 0x18u:
result = 1LL;
break;
case 0x22u:
result = 27LL;
break;
case 0x24u:
result = 10LL;
break;
case 0x25u:
result = 6LL;
break;
case 0x26u:
result = 28LL;
break;
default:
goto LABEL_4;
}
}
}
else
{
switch ( a1 )
{
case 0x4000u:
result = 8LL;
break;
case 0x4003u:
result = 14LL;
break;
case 0x4004u:
result = 17LL;
break;
case 0x4005u:
result = 16LL;
break;
case 0x4006u:
result = 2LL;
break;
case 0x4007u:
result = 32LL;
break;
case 0x4009u:
result = 25LL;
break;
case 0x400Au:
result = 5LL;
break;
case 0x400Cu:
result = 15LL;
break;
case 0x4010u:
result = 30LL;
break;
case 0x4011u:
result = 3LL;
break;
case 0x4016u:
result = 24LL;
break;
case 0x4017u:
result = 22LL;
break;
case 0x4018u:
result = 23LL;
break;
case 0x4022u:
result = 4LL;
break;
case 0x402Eu:
result = 7LL;
break;
case 0x402Fu:
result = 26LL;
break;
case 0x4033u:
result = 31LL;
break;
case 0x4034u:
result = 21LL;
break;
case 0x4035u:
result = 18LL;
break;
case 0x4036u:
result = 9LL;
break;
default:
goto LABEL_4;
}
}
return result;
}

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

if ( a1 > 0x4036 )
{
result = 0LL;
if ( a1 == 40960 )
result = 20LL;
}
else if ( a1 <= 0x3FFF )
{
if ( a1 - 1 > 0x25 )
{
LABEL_4:
result = 0LL;
}
else
{
switch ( a1 )
{
case 1u:
result = 29LL;
break;
case 5u:
result = 12LL;
break;
case 7u:
result = 13LL;
break;
case 0xEu:
result = 19LL;
break;
case 0x11u:
result = 11LL;
break;
case 0x18u:
result = 1LL;
break;
case 0x22u:
result = 27LL;
break;
case 0x24u:
result = 10LL;
break;
case 0x25u:
result = 6LL;
break;
case 0x26u:
result = 28LL;
break;
default:
goto LABEL_4;
}
}
}
else
{
switch ( a1 )
{
case 0x4000u:
result = 8LL;
break;
case 0x4003u:
result = 14LL;
break;
case 0x4004u:
result = 17LL;
break;
case 0x4005u:
result = 16LL;
break;
case 0x4006u:
result = 2LL;
break;
case 0x4007u:
result = 32LL;
break;
case 0x4009u:
result = 25LL;
break;
case 0x400Au:
result = 5LL;
break;
case 0x400Cu:
result = 15LL;
break;
case 0x4010u:
result = 30LL;
break;
case 0x4011u:
result = 3LL;
break;
case 0x4016u:
result = 24LL;
break;
case 0x4017u:
result = 22LL;
break;
case 0x4018u:
result = 23LL;
break;
case 0x4022u:
result = 4LL;
break;
case 0x402Eu:
result = 7LL;
break;
case 0x402Fu:
result = 26LL;
break;
case 0x4033u:
result = 31LL;
break;
case 0x4034u:
result = 21LL;
break;
case 0x4035u:
result = 18LL;
break;
case 0x4036u:
result = 9LL;
break;
default:
goto LABEL_4;
}
}
return result;
}

original_code:
enum v2_pd v2_pd_from_notification(v2_notification_t n)
{
 switch (n) {
 case v2N_AUTHENTICATION_FAILED: return PD_v2N_AUTHENTICATION_FAILED;;
 case v2N_COOKIE: return PD_v2N_COOKIE;;
 case v2N_COOKIE2: return PD_v2N_COOKIE2;;
 case v2N_CHILDLESS_IKEV2_SUPPORTED: return PD_v2N_CHILDLESS_IKEV2_SUPPORTED;;
 case v2N_ESP_TFC_PADDING_NOT_SUPPORTED: return PD_v2N_ESP_TFC_PADDING_NOT_SUPPORTED;;
 case v2N_FAILED_CP_REQUIRED: return PD_v2N_FAILED_CP_REQUIRED;;
 case v2N_IKEV2_FRAGMENTATION_SUPPORTED: return PD_v2N_IKEV2_FRAGMENTATION_SUPPORTED;;
 case v2N_INITIAL_CONTACT: return PD_v2N_INITIAL_CONTACT;;
 case v2N_INTERMEDIATE_EXCHANGE_SUPPORTED: return PD_v2N_INTERMEDIATE_EXCHANGE_SUPPORTED;;
 case v2N_INTERNAL_ADDRESS_FAILURE: return PD_v2N_INTERNAL_ADDRESS_FAILURE;;
 case v2N_INVALID_KE_PAYLOAD: return PD_v2N_INVALID_KE_PAYLOAD;;
 case v2N_INVALID_MAJOR_VERSION: return PD_v2N_INVALID_MAJOR_VERSION;;
 case v2N_INVALID_SYNTAX: return PD_v2N_INVALID_SYNTAX;;
 case v2N_IPCOMP_SUPPORTED: return PD_v2N_IPCOMP_SUPPORTED;;
 case v2N_MOBIKE_SUPPORTED: return PD_v2N_MOBIKE_SUPPORTED;;
 case v2N_NAT_DETECTION_DESTINATION_IP: return PD_v2N_NAT_DETECTION_DESTINATION_IP;;
 case v2N_NAT_DETECTION_SOURCE_IP: return PD_v2N_NAT_DETECTION_SOURCE_IP;;
 case v2N_NO_PPK_AUTH: return PD_v2N_NO_PPK_AUTH;;
 case v2N_NO_PROPOSAL_CHOSEN: return PD_v2N_NO_PROPOSAL_CHOSEN;;
 case v2N_NULL_AUTH: return PD_v2N_NULL_AUTH;;
 case v2N_PPK_IDENTITY: return PD_v2N_PPK_IDENTITY;;
 case v2N_REDIRECT: return PD_v2N_REDIRECT;;
 case v2N_REDIRECTED_FROM: return PD_v2N_REDIRECTED_FROM;;
 case v2N_REDIRECT_SUPPORTED: return PD_v2N_REDIRECT_SUPPORTED;;
 case v2N_REKEY_SA: return PD_v2N_REKEY_SA;;
 case v2N_SIGNATURE_HASH_ALGORITHMS: return PD_v2N_SIGNATURE_HASH_ALGORITHMS;;
 case v2N_SINGLE_PAIR_REQUIRED: return PD_v2N_SINGLE_PAIR_REQUIRED;;
 case v2N_TS_UNACCEPTABLE: return PD_v2N_TS_UNACCEPTABLE;;
 case v2N_UNSUPPORTED_CRITICAL_PAYLOAD: return PD_v2N_UNSUPPORTED_CRITICAL_PAYLOAD;;
 case v2N_UPDATE_SA_ADDRESSES: return PD_v2N_UPDATE_SA_ADDRESSES;;
 case v2N_USE_PPK: return PD_v2N_USE_PPK;;
 case v2N_USE_TRANSPORT_MODE: return PD_v2N_USE_TRANSPORT_MODE;;
 default: return PD_v2_INVALID;
 }
}

canonical_original_code:
enum v2_pd v2_pd_from_notification(enum v2_notification_t n)
{
 switch (n) {
 case v2N_AUTHENTICATION_FAILED: return PD_v2N_AUTHENTICATION_FAILED;;
 case v2N_COOKIE: return PD_v2N_COOKIE;;
 case v2N_COOKIE2: return PD_v2N_COOKIE2;;
 case v2N_CHILDLESS_IKEV2_SUPPORTED: return PD_v2N_CHILDLESS_IKEV2_SUPPORTED;;
 case v2N_ESP_TFC_PADDING_NOT_SUPPORTED: return PD_v2N_ESP_TFC_PADDING_NOT_SUPPORTED;;
 case v2N_FAILED_CP_REQUIRED: return PD_v2N_FAILED_CP_REQUIRED;;
 case v2N_IKEV2_FRAGMENTATION_SUPPORTED: return PD_v2N_IKEV2_FRAGMENTATION_SUPPORTED;;
 case v2N_INITIAL_CONTACT: return PD_v2N_INITIAL_CONTACT;;
 case v2N_INTERMEDIATE_EXCHANGE_SUPPORTED: return PD_v2N_INTERMEDIATE_EXCHANGE_SUPPORTED;;
 case v2N_INTERNAL_ADDRESS_FAILURE: return PD_v2N_INTERNAL_ADDRESS_FAILURE;;
 case v2N_INVALID_KE_PAYLOAD: return PD_v2N_INVALID_KE_PAYLOAD;;
 case v2N_INVALID_MAJOR_VERSION: return PD_v2N_INVALID_MAJOR_VERSION;;
 case v2N_INVALID_SYNTAX: return PD_v2N_INVALID_SYNTAX;;
 case v2N_IPCOMP_SUPPORTED: return PD_v2N_IPCOMP_SUPPORTED;;
 case v2N_MOBIKE_SUPPORTED: return PD_v2N_MOBIKE_SUPPORTED;;
 case v2N_NAT_DETECTION_DESTINATION_IP: return PD_v2N_NAT_DETECTION_DESTINATION_IP;;
 case v2N_NAT_DETECTION_SOURCE_IP: return PD_v2N_NAT_DETECTION_SOURCE_IP;;
 case v2N_NO_PPK_AUTH: return PD_v2N_NO_PPK_AUTH;;
 case v2N_NO_PROPOSAL_CHOSEN: return PD_v2N_NO_PROPOSAL_CHOSEN;;
 case v2N_NULL_AUTH: return PD_v2N_NULL_AUTH;;
 case v2N_PPK_IDENTITY: return PD_v2N_PPK_IDENTITY;;
 case v2N_REDIRECT: return PD_v2N_REDIRECT;;
 case v2N_REDIRECTED_FROM: return PD_v2N_REDIRECTED_FROM;;
 case v2N_REDIRECT_SUPPORTED: return PD_v2N_REDIRECT_SUPPORTED;;
 case v2N_REKEY_SA: return PD_v2N_REKEY_SA;;
 case v2N_SIGNATURE_HASH_ALGORITHMS: return PD_v2N_SIGNATURE_HASH_ALGORITHMS;;
 case v2N_SINGLE_PAIR_REQUIRED: return PD_v2N_SINGLE_PAIR_REQUIRED;;
 case v2N_TS_UNACCEPTABLE: return PD_v2N_TS_UNACCEPTABLE;;
 case v2N_UNSUPPORTED_CRITICAL_PAYLOAD: return PD_v2N_UNSUPPORTED_CRITICAL_PAYLOAD;;
 case v2N_UPDATE_SA_ADDRESSES: return PD_v2N_UPDATE_SA_ADDRESSES;;
 case v2N_USE_PPK: return PD_v2N_USE_PPK;;
 case v2N_USE_TRANSPORT_MODE: return PD_v2N_USE_TRANSPORT_MODE;;
 default: return PD_v2_INVALID;
 }
}

variable_types: enum v2_notification_t { v2N_NOTHING_WRONG=0, v2N_ERROR_FLOOR=1, v2N_UNSUPPORTED_CRITICAL_PAYLOAD=1, v2N_INVALID_IKE_SPI=4, v2N_INVALID_MAJOR_VERSION=5, v2N_INVALID_SYNTAX=7, v2N_INVALID_MESSAGE_ID=9, v2N_INVALID_SPI=11, v2N_NO_PROPOSAL_CHOSEN=14, v2N_INVALID_KE_PAYLOAD=17, v2N_AUTHENTICATION_FAILED=24, v2N_SINGLE_PAIR_REQUIRED=34, v2N_NO_ADDITIONAL_SAS=35, v2N_INTERNAL_ADDRESS_FAILURE=36, v2N_FAILED_CP_REQUIRED=37, v2N_TS_UNACCEPTABLE=38, v2N_INVALID_SELECTORS=39, v2N_UNACCEPTABLE_ADDRESSES=40, v2N_UNEXPECTED_NAT_DETECTED=41, v2N_USE_ASSIGNED_HoA=42, v2N_TEMPORARY_FAILURE=43, v2N_CHILD_SA_NOT_FOUND=44, v2N_INVALID_GROUP_ID=45, v2N_AUTHORIZATION_FAILED=46, v2N_STATE_NOT_FOUND=47, v2N_ERROR_PSTATS_ROOF=48, v2N_STATUS_FLOOR=16384, v2N_INITIAL_CONTACT=16384, v2N_SET_WINDOW_SIZE=16385, v2N_ADDITIONAL_TS_POSSIBLE=16386, v2N_IPCOMP_SUPPORTED=16387, v2N_NAT_DETECTION_SOURCE_IP=16388, v2N_NAT_DETECTION_DESTINATION_IP=16389, v2N_COOKIE=16390, v2N_USE_TRANSPORT_MODE=16391, v2N_HTTP_CERT_LOOKUP_SUPPORTED=16392, v2N_REKEY_SA=16393, v2N_ESP_TFC_PADDING_NOT_SUPPORTED=16394, v2N_NON_FIRST_FRAGMENTS_ALSO=16395, v2N_MOBIKE_SUPPORTED=16396, v2N_ADDITIONAL_IP4_ADDRESS=16397, v2N_ADDITIONAL_IP6_ADDRESS=16398, v2N_NO_ADDITIONAL_ADDRESSES=16399, v2N_UPDATE_SA_ADDRESSES=16400, v2N_COOKIE2=16401, v2N_NO_NATS_ALLOWED=16402, v2N_AUTH_LIFETIME=16403, v2N_MULTIPLE_AUTH_SUPPORTED=16404, v2N_ANOTHER_AUTH_FOLLOWS=16405, v2N_REDIRECT_SUPPORTED=16406, v2N_REDIRECT=16407, v2N_REDIRECTED_FROM=16408, v2N_TICKET_LT_OPAQUE=16409, v2N_TICKET_REQUEST=16410, v2N_TICKET_ACK=16411, v2N_TICKET_NACK=16412, v2N_TICKET_OPAQUE=16413, v2N_LINK_ID=16414, v2N_USE_WESP_MODE=16415, v2N_ROHC_SUPPORTED=16416, v2N_EAP_ONLY_AUTHENTICATION=16417, v2N_CHILDLESS_IKEV2_SUPPORTED=16418, v2N_QUICK_CRASH_DETECTION=16419, v2N_IKEV2_MESSAGE_ID_SYNC_SUPPORTED=16420, v2N_IPSEC_REPLAY_COUNTER_SYNC_SUPPORTED=16421, v2N_IKEV2_MESSAGE_ID_SYNC=16422, v2N_IPSEC_REPLAY_COUNTER_SYNC=16423, v2N_SECURE_PASSWORD_METHODS=16424, v2N_PSK_PERSIST=16425, v2N_PSK_CONFIRM=16426, v2N_ERX_SUPPORTED=16427, v2N_IFOM_CAPABILITY=16428, v2N_SENDER_REQUEST_ID=16429, v2N_IKEV2_FRAGMENTATION_SUPPORTED=16430, v2N_SIGNATURE_HASH_ALGORITHMS=16431, v2N_CLONE_IKE_SA_SUPPORTED=16432, v2N_CLONE_IKE_SA=16433, v2N_PUZZLE=16434, v2N_USE_PPK=16435, v2N_PPK_IDENTITY=16436, v2N_NO_PPK_AUTH=16437, v2N_INTERMEDIATE_EXCHANGE_SUPPORTED=16438, v2N_IP4_ALLOWED=16439, v2N_IP6_ALLOWED=16440, v2N_ADDITIONAL_KEY_EXCHANGE=16441, v2N_USE_AGGFRAG=16442, v2N_STATUS_PSTATS_ROOF=16443, v2N_NULL_AUTH=40960 }

return_type: enum v2_pd { PD_v2_INVALID=0, PD_v2N_AUTHENTICATION_FAILED=1, PD_v2N_COOKIE=2, PD_v2N_COOKIE2=3, PD_v2N_CHILDLESS_IKEV2_SUPPORTED=4, PD_v2N_ESP_TFC_PADDING_NOT_SUPPORTED=5, PD_v2N_FAILED_CP_REQUIRED=6, PD_v2N_IKEV2_FRAGMENTATION_SUPPORTED=7, PD_v2N_INITIAL_CONTACT=8, PD_v2N_INTERMEDIATE_EXCHANGE_SUPPORTED=9, PD_v2N_INTERNAL_ADDRESS_FAILURE=10, PD_v2N_INVALID_KE_PAYLOAD=11, PD_v2N_INVALID_MAJOR_VERSION=12, PD_v2N_INVALID_SYNTAX=13, PD_v2N_IPCOMP_SUPPORTED=14, PD_v2N_MOBIKE_SUPPORTED=15, PD_v2N_NAT_DETECTION_DESTINATION_IP=16, PD_v2N_NAT_DETECTION_SOURCE_IP=17, PD_v2N_NO_PPK_AUTH=18, PD_v2N_NO_PROPOSAL_CHOSEN=19, PD_v2N_NULL_AUTH=20, PD_v2N_PPK_IDENTITY=21, PD_v2N_REDIRECT=22, PD_v2N_REDIRECTED_FROM=23, PD_v2N_REDIRECT_SUPPORTED=24, PD_v2N_REKEY_SA=25, PD_v2N_SIGNATURE_HASH_ALGORITHMS=26, PD_v2N_SINGLE_PAIR_REQUIRED=27, PD_v2N_TS_UNACCEPTABLE=28, PD_v2N_UNSUPPORTED_CRITICAL_PAYLOAD=29, PD_v2N_UPDATE_SA_ADDRESSES=30, PD_v2N_USE_PPK=31, PD_v2N_USE_TRANSPORT_MODE=32, PD_v2_ROOF=33 }


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

result = BYTE1(a1);
if ( !BYTE1(a1) )
{
result = BYTE2(a1);
if ( !BYTE2(a1) )
{
result = (unsigned __int8)a1;
if ( !(_BYTE)a1 )
{
result = BYTE3(a1);
if ( !BYTE3(a1) )
{
result = BYTE5(a1);
if ( !BYTE5(a1) )
result = BYTE4(a1);
}
}
}
}
return result;
}

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

result = BYTE1(a1);
if ( !BYTE1(a1) )
{
result = BYTE2(a1);
if ( !BYTE2(a1) )
{
result = (unsigned __int8)a1;
if ( !(_BYTE)a1 )
{
result = BYTE3(a1);
if ( !BYTE3(a1) )
{
result = BYTE5(a1);
if ( !BYTE5(a1) )
result = BYTE4(a1);
}
}
}
}
return result;
}

original_code:
_Bool authby_is_set(struct authby authby)
{
 return ((authby).null || (authby).never || (authby).psk || (authby).rsasig || (authby).rsasig_v1_5 || (authby).ecdsa);
}

variable_types: struct authby { _Bool psk; _Bool null; _Bool never; _Bool rsasig; _Bool ecdsa; _Bool rsasig_v1_5; }


decompiled_code:
unsigned __int64 __fastcall authby_xor(__int64 a1, __int64 a2)
{
unsigned int v3; // [rsp+0h] [rbp-36h]
unsigned __int16 v4; // [rsp+4h] [rbp-32h]

LOBYTE(v4) = BYTE4(a1) ^ BYTE4(a2);
LOWORD(v3) = a2 ^ a1;
BYTE2(v3) = BYTE2(a1) ^ BYTE2(a2);
HIBYTE(v3) = BYTE3(a2) ^ BYTE3(a1);
HIBYTE(v4) = BYTE5(a1) ^ BYTE5(a2);
return v3 | ((unsigned __int64)v4 << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v3; // [rsp+0h] [rbp-36h]
unsigned __int16 v4; // [rsp+4h] [rbp-32h]

LOBYTE(v4) = BYTE4(a1) ^ BYTE4(a2);
LOWORD(v3) = a2 ^ a1;
BYTE2(v3) = BYTE2(a1) ^ BYTE2(a2);
HIBYTE(v3) = BYTE3(a2) ^ BYTE3(a1);
HIBYTE(v4) = BYTE5(a1) ^ BYTE5(a2);
return v3 | ((unsigned __int64)v4 << 32);
}

original_code:
struct authby authby_xor(struct authby lhs, struct authby rhs)
{
 return ({ struct authby tmp_ = { .null = (lhs).null != (rhs).null, .never = (lhs).never != (rhs).never, .psk = (lhs).psk != (rhs).psk, .rsasig = (lhs).rsasig != (rhs).rsasig, .ecdsa = (lhs).ecdsa != (rhs).ecdsa, .rsasig_v1_5 = (lhs).rsasig_v1_5 != (rhs).rsasig_v1_5, }; tmp_; });
}

variable_types:
lhs
struct authby

variable_types:
rhs
struct authby

return_type: struct authby { _Bool psk; _Bool null; _Bool never; _Bool rsasig; _Bool ecdsa; _Bool rsasig_v1_5; }


decompiled_code:
unsigned __int64 __fastcall authby_not(__int64 a1)
{
return authby_xor(
((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40),
0x10101010101LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1)
{
return func1(
((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40),
0x10101010101LL);
}

original_code:
struct authby authby_not(struct authby lhs)
{
 return authby_xor(lhs, (struct authby) { 1, 1, 1, 1, 1, 1 });
}

user_defined_types: struct authby { _Bool psk; _Bool null; _Bool never; _Bool rsasig; _Bool ecdsa; _Bool rsasig_v1_5; }


decompiled_code:
unsigned __int64 __fastcall authby_and(__int64 a1, __int64 a2)
{
char v2; // al
char v3; // r8
char v4; // di
char v5; // si
char v6; // cl
char v7; // dl
unsigned int v11; // [rsp+12h] [rbp-16h]
unsigned __int16 v12; // [rsp+16h] [rbp-12h]

v2 = a2;
if ( !(_BYTE)a1 )
v2 = 0;
v3 = 0;
if ( BYTE1(a1) )
v3 = BYTE1(a2);
v4 = 0;
if ( BYTE2(a1) )
v4 = BYTE2(a2);
v5 = 0;
if ( BYTE3(a1) )
v5 = BYTE3(a2);
v6 = 0;
if ( BYTE4(a1) )
v6 = BYTE4(a2);
v7 = 0;
if ( BYTE5(a1) )
v7 = BYTE5(a2);
LOBYTE(v11) = v2;
HIBYTE(v12) = v7;
BYTE1(v11) = v3;
BYTE2(v11) = v4;
HIBYTE(v11) = v5;
LOBYTE(v12) = v6;
return v11 | ((unsigned __int64)v12 << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1, __int64 a2)
{
char v2; // al
char v3; // r8
char v4; // di
char v5; // si
char v6; // cl
char v7; // dl
unsigned int v11; // [rsp+12h] [rbp-16h]
unsigned __int16 v12; // [rsp+16h] [rbp-12h]

v2 = a2;
if ( !(_BYTE)a1 )
v2 = 0;
v3 = 0;
if ( BYTE1(a1) )
v3 = BYTE1(a2);
v4 = 0;
if ( BYTE2(a1) )
v4 = BYTE2(a2);
v5 = 0;
if ( BYTE3(a1) )
v5 = BYTE3(a2);
v6 = 0;
if ( BYTE4(a1) )
v6 = BYTE4(a2);
v7 = 0;
if ( BYTE5(a1) )
v7 = BYTE5(a2);
LOBYTE(v11) = v2;
HIBYTE(v12) = v7;
BYTE1(v11) = v3;
BYTE2(v11) = v4;
HIBYTE(v11) = v5;
LOBYTE(v12) = v6;
return v11 | ((unsigned __int64)v12 << 32);
}

original_code:
struct authby authby_and(struct authby lhs, struct authby rhs)
{
 return ({ struct authby tmp_ = { .null = (lhs).null && (rhs).null, .never = (lhs).never && (rhs).never, .psk = (lhs).psk && (rhs).psk, .rsasig = (lhs).rsasig && (rhs).rsasig, .ecdsa = (lhs).ecdsa && (rhs).ecdsa, .rsasig_v1_5 = (lhs).rsasig_v1_5 && (rhs).rsasig_v1_5, }; tmp_; });
}


decompiled_code:
unsigned __int64 __fastcall authby_or(__int64 a1, __int64 a2)
{
char v2; // r8
char v3; // al
char v4; // di
char v5; // si
char v6; // cl
char v7; // dl
unsigned int v11; // [rsp+12h] [rbp-16h]
unsigned __int16 v12; // [rsp+16h] [rbp-12h]

v2 = 1;
v3 = a2;
if ( (_BYTE)a1 )
v3 = 1;
if ( !BYTE1(a1) )
v2 = BYTE1(a2);
v4 = 1;
if ( !BYTE2(a1) )
v4 = BYTE2(a2);
v5 = 1;
if ( !BYTE3(a1) )
v5 = BYTE3(a2);
v6 = 1;
if ( !BYTE4(a1) )
v6 = BYTE4(a2);
v7 = 1;
if ( !BYTE5(a1) )
v7 = BYTE5(a2);
LOBYTE(v11) = v3;
HIBYTE(v12) = v7;
BYTE1(v11) = v2;
BYTE2(v11) = v4;
HIBYTE(v11) = v5;
LOBYTE(v12) = v6;
return v11 | ((unsigned __int64)v12 << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, __int64 a2)
{
char v2; // r8
char v3; // al
char v4; // di
char v5; // si
char v6; // cl
char v7; // dl
unsigned int v11; // [rsp+12h] [rbp-16h]
unsigned __int16 v12; // [rsp+16h] [rbp-12h]

v2 = 1;
v3 = a2;
if ( (_BYTE)a1 )
v3 = 1;
if ( !BYTE1(a1) )
v2 = BYTE1(a2);
v4 = 1;
if ( !BYTE2(a1) )
v4 = BYTE2(a2);
v5 = 1;
if ( !BYTE3(a1) )
v5 = BYTE3(a2);
v6 = 1;
if ( !BYTE4(a1) )
v6 = BYTE4(a2);
v7 = 1;
if ( !BYTE5(a1) )
v7 = BYTE5(a2);
LOBYTE(v11) = v3;
HIBYTE(v12) = v7;
BYTE1(v11) = v2;
BYTE2(v11) = v4;
HIBYTE(v11) = v5;
LOBYTE(v12) = v6;
return v11 | ((unsigned __int64)v12 << 32);
}

original_code:
struct authby authby_or(struct authby lhs, struct authby rhs)
{
 return ({ struct authby tmp_ = { .null = (lhs).null || (rhs).null, .never = (lhs).never || (rhs).never, .psk = (lhs).psk || (rhs).psk, .rsasig = (lhs).rsasig || (rhs).rsasig, .ecdsa = (lhs).ecdsa || (rhs).ecdsa, .rsasig_v1_5 = (lhs).rsasig_v1_5 || (rhs).rsasig_v1_5, }; tmp_; });
}


decompiled_code:
__int64 __fastcall authby_eq(__int64 a1, __int64 a2)
{
return (BYTE4(a2) == BYTE4(a1)) & (unsigned __int8)(BYTE5(a2) == BYTE5(a1)
&& BYTE3(a1) == BYTE3(a2)
&& (_BYTE)a1 == (unsigned __int8)a2
&& BYTE1(a1) == BYTE1(a2)
&& BYTE2(a2) == BYTE2(a1));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return (BYTE4(a2) == BYTE4(a1)) & (unsigned __int8)(BYTE5(a2) == BYTE5(a1)
&& BYTE3(a1) == BYTE3(a2)
&& (_BYTE)a1 == (unsigned __int8)a2
&& BYTE1(a1) == BYTE1(a2)
&& BYTE2(a2) == BYTE2(a1));
}

original_code:
_Bool authby_eq(struct authby lhs, struct authby rhs)
{
 struct authby eq = ({ struct authby tmp_ = { .null = (lhs).null == (rhs).null, .never = (lhs).never == (rhs).never, .psk = (lhs).psk == (rhs).psk, .rsasig = (lhs).rsasig == (rhs).rsasig, .ecdsa = (lhs).ecdsa == (rhs).ecdsa, .rsasig_v1_5 = (lhs).rsasig_v1_5 == (rhs).rsasig_v1_5, }; tmp_; });
 return ((eq).null && (eq).never && (eq).psk && (eq).rsasig && (eq).rsasig_v1_5 && (eq).ecdsa);
}


decompiled_code:
__int64 __fastcall authby_le(__int64 a1, __int64 a2)
{
return (BYTE4(a2) >= BYTE4(a1)) & (unsigned __int8)(BYTE5(a2) >= BYTE5(a1)
&& BYTE3(a1) <= BYTE3(a2)
&& (unsigned __int8)a1 <= (unsigned __int8)a2
&& BYTE1(a1) <= BYTE1(a2)
&& BYTE2(a2) >= BYTE2(a1));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
return (BYTE4(a2) >= BYTE4(a1)) & (unsigned __int8)(BYTE5(a2) >= BYTE5(a1)
&& BYTE3(a1) <= BYTE3(a2)
&& (unsigned __int8)a1 <= (unsigned __int8)a2
&& BYTE1(a1) <= BYTE1(a2)
&& BYTE2(a2) >= BYTE2(a1));
}

original_code:
_Bool authby_le(struct authby lhs, struct authby rhs)
{
 struct authby le = ({ struct authby tmp_ = { .null = (lhs).null <= (rhs).null, .never = (lhs).never <= (rhs).never, .psk = (lhs).psk <= (rhs).psk, .rsasig = (lhs).rsasig <= (rhs).rsasig, .ecdsa = (lhs).ecdsa <= (rhs).ecdsa, .rsasig_v1_5 = (lhs).rsasig_v1_5 <= (rhs).rsasig_v1_5, }; tmp_; });
 return ((le).null && (le).never && (le).psk && (le).rsasig && (le).rsasig_v1_5 && (le).ecdsa);
}


decompiled_code:
__int64 __fastcall authby_has_rsasig(unsigned __int64 a1)
{
unsigned int v1; // eax
unsigned __int64 v2; // rdi
__int64 result; // rax

v1 = a1;
v2 = a1 >> 40;
result = HIBYTE(v1);
if ( !(_BYTE)result )
result = (unsigned int)v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 a1)
{
unsigned int v1; // eax
unsigned __int64 v2; // rdi
__int64 result; // rax

v1 = a1;
v2 = a1 >> 40;
result = HIBYTE(v1);
if ( !(_BYTE)result )
result = (unsigned int)v2;
return result;
}

original_code:
_Bool authby_has_rsasig(struct authby lhs)
{
 return lhs.rsasig || lhs.rsasig_v1_5;
}


decompiled_code:
unsigned __int64 __fastcall authby_has_ecdsa(unsigned __int64 a1)
{
return HIDWORD(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(unsigned __int64 a1)
{
return HIDWORD(a1);
}

original_code:
_Bool authby_has_ecdsa(struct authby lhs)
{
 return lhs.ecdsa;
}


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

result = authby_has_ecdsa(a1 & 0xFF00000000LL | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | ((unsigned __int64)BYTE3(a1) << 24) | a1 & 0xFF0000000000LL);
if ( !(_BYTE)result )
result = authby_has_rsasig(a1 & 0xFF00000000LL | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | ((unsigned __int64)BYTE3(a1) << 24) | a1 & 0xFF0000000000LL);
return result;
}

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

result = func8(a1 & 0xFF00000000LL | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | ((unsigned __int64)BYTE3(a1) << 24) | a1 & 0xFF0000000000LL);
if ( !(_BYTE)result )
result = func7(a1 & 0xFF00000000LL | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | ((unsigned __int64)BYTE3(a1) << 24) | a1 & 0xFF0000000000LL);
return result;
}

original_code:
_Bool authby_has_digsig(struct authby lhs)
{
 return authby_has_ecdsa(lhs) || authby_has_rsasig(lhs);
}


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

result = 3LL;
if ( !BYTE3(a1) )
{
result = 4LL;
if ( !BYTE4(a1) )
{
result = 3LL;
if ( !BYTE5(a1) )
{
result = 2LL;
if ( !(_BYTE)a1 )
{
result = 5LL;
if ( !BYTE1(a1) )
result = BYTE2(a1);
}
}
}
}
return result;
}

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

result = 3LL;
if ( !BYTE3(a1) )
{
result = 4LL;
if ( !BYTE4(a1) )
{
result = 3LL;
if ( !BYTE5(a1) )
{
result = 2LL;
if ( !(_BYTE)a1 )
{
result = 5LL;
if ( !BYTE1(a1) )
result = BYTE2(a1);
}
}
}
}
return result;
}

original_code:
enum keyword_auth auth_from_authby(struct authby authby)
{
 return (authby.rsasig ? AUTH_RSASIG :
  authby.ecdsa ? AUTH_ECDSA :
  authby.rsasig_v1_5 ? AUTH_RSASIG :
  authby.psk ? AUTH_PSK :
  authby.null ? AUTH_NULL :
  authby.never ? AUTH_NEVER :
  AUTH_UNSET);
}

return_type: enum keyword_auth { AUTH_UNSET=0, AUTH_NEVER=1, AUTH_PSK=2, AUTH_RSASIG=3, AUTH_ECDSA=4, AUTH_NULL=5, AUTH_EAPONLY=6 }


decompiled_code:
unsigned __int64 __fastcall authby_from_auth(unsigned int a1)
{
unsigned __int64 result; // rax
_BYTE v2[6]; // [rsp+2h] [rbp-16h]

switch ( a1 )
{
case 0u:
case 1u:
*(_DWORD *)v2 = 0x10000;
*(_WORD *)&v2[4] = 0;
break;
case 2u:
*(_DWORD *)&v2[1] = 0;
v2[5] = 0;
v2[0] = 1;
break;
case 3u:
*(_DWORD *)v2 = 0x1000000;
*(_WORD *)&v2[4] = 256;
break;
case 4u:
*(_DWORD *)v2 = 0;
*(_WORD *)&v2[4] = 1;
break;
case 5u:
*(_DWORD *)v2 = 256;
*(_WORD *)&v2[4] = 0;
break;
case 6u:
*(_DWORD *)v2 = 0;
*(_WORD *)&v2[4] = 0;
break;
default:
libreswan_bad_case("auth", a1, here_1);
return result;
}
return ((unsigned __int64)*(unsigned __int16 *)&v2[4] << 32) | *(unsigned int *)v2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(unsigned int a1)
{
unsigned __int64 result; // rax
_BYTE v2[6]; // [rsp+2h] [rbp-16h]

switch ( a1 )
{
case 0u:
case 1u:
*(_DWORD *)v2 = 0x10000;
*(_WORD *)&v2[4] = 0;
break;
case 2u:
*(_DWORD *)&v2[1] = 0;
v2[5] = 0;
v2[0] = 1;
break;
case 3u:
*(_DWORD *)v2 = 0x1000000;
*(_WORD *)&v2[4] = 256;
break;
case 4u:
*(_DWORD *)v2 = 0;
*(_WORD *)&v2[4] = 1;
break;
case 5u:
*(_DWORD *)v2 = 256;
*(_WORD *)&v2[4] = 0;
break;
case 6u:
*(_DWORD *)v2 = 0;
*(_WORD *)&v2[4] = 0;
break;
default:
libreswan_bad_case("auth", a1, here_1);
return result;
}
return ((unsigned __int64)*(unsigned __int16 *)&v2[4] << 32) | *(unsigned int *)v2;
}

original_code:
struct authby authby_from_auth(enum keyword_auth auth)
{
 switch (auth) {
 case AUTH_RSASIG:
  return (struct authby) { .rsasig = 1, .rsasig_v1_5 = 1 };
 case AUTH_ECDSA:
  return (struct authby) { .ecdsa = 1, };
 case AUTH_PSK:
  return (struct authby) { .psk = 1, };
 case AUTH_NULL:
  return (struct authby) { .null = 1, };
 case AUTH_NEVER:
 case AUTH_UNSET:
  return (struct authby) { .never = 1, };
 case AUTH_EAPONLY:
  return (struct authby) {0};
 }
 libreswan_bad_case("auth", (auth), ({ static const struct where here = { .func = __func__, .file = "lib/libswan/authby.c", .line = 123, }; &here; }));
}

canonical_original_code:
struct authby authby_from_auth(enum keyword_auth auth)
{
 switch (auth) {
 case AUTH_RSASIG:
  return (struct authby) { .rsasig = 1, .rsasig_v1_5 = 1 };
 case AUTH_ECDSA:
  return (struct authby) { .ecdsa = 1, };
 case AUTH_PSK:
  return (struct authby) { .psk = 1, };
 case AUTH_NULL:
  return (struct authby) { .null = 1, };
 case AUTH_NEVER:
 case AUTH_UNSET:
  return (struct authby) { .never = 1, };
 case AUTH_EAPONLY:
  return (struct authby) {0};
 }
 libreswan_bad_case("auth", (auth), ({ static struct where here = { .func = __func__, .file = "lib/libswan/authby.c", .line = 123, }; &here; }));
}

variable_types: enum keyword_auth { AUTH_UNSET=0, AUTH_NEVER=1, AUTH_PSK=2, AUTH_RSASIG=3, AUTH_ECDSA=4, AUTH_NULL=5, AUTH_EAPONLY=6 }

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


decompiled_code:
__int64 __fastcall jam_authby(__int64 a1, __int64 a2)
{
char v2; // al
__int64 v3; // r12
const char *v4; // rsi
__int64 v5; // rdx
__int64 v7; // r12
__int64 v8; // rdx
__int64 v9; // rbx
__int64 v10; // rdx
__int64 v11; // rbx
__int64 v12; // rdx
__int64 v13; // rbx
__int64 v14; // rdx
__int64 v15; // rbx
__int64 v16; // rdx
__int64 v17; // rbx
__int64 v18; // rdx

v2 = a2;
v3 = 0LL;
v4 = (const char *)&LC2;
v5 = 0LL;
if ( v2 )
{
v7 = jam_string(a1, &LC2, 0LL);
v4 = "+";
v3 = jam_string(a1, "PSK", v8) + v7;
if ( !BYTE3(a2) )
{
LABEL_3:
if ( !BYTE4(a2) )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( !BYTE3(a2) )
{
goto LABEL_3;
}
v9 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "RSASIG", v10) + v9;
if ( !BYTE4(a2) )
{
LABEL_4:
if ( !BYTE2(a2) )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
v11 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "ECDSA", v12) + v11;
if ( !BYTE2(a2) )
{
LABEL_5:
if ( !BYTE1(a2) )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
v13 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "AUTH_NEVER", v14) + v13;
if ( !BYTE1(a2) )
{
LABEL_6:
if ( !BYTE5(a2) )
goto LABEL_7;
LABEL_14:
v17 = jam_string(a1, v4, v5);
v3 += jam_string(a1, "RSASIG_v1_5", v18) + v17;
if ( v3 )
return v3;
return jam_string(a1, "none", v5);
}
LABEL_13:
v15 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "AUTH_NULL", v16) + v15;
if ( BYTE5(a2) )
goto LABEL_14;
LABEL_7:
if ( v3 )
return v3;
return jam_string(a1, "none", v5);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
char v2; // al
__int64 v3; // r12
const char *v4; // rsi
__int64 v5; // rdx
__int64 v7; // r12
__int64 v8; // rdx
__int64 v9; // rbx
__int64 v10; // rdx
__int64 v11; // rbx
__int64 v12; // rdx
__int64 v13; // rbx
__int64 v14; // rdx
__int64 v15; // rbx
__int64 v16; // rdx
__int64 v17; // rbx
__int64 v18; // rdx

v2 = a2;
v3 = 0LL;
v4 = (const char *)&LC2;
v5 = 0LL;
if ( v2 )
{
v7 = jam_string(a1, &LC2, 0LL);
v4 = "+";
v3 = jam_string(a1, "PSK", v8) + v7;
if ( !BYTE3(a2) )
{
LABEL_3:
if ( !BYTE4(a2) )
goto LABEL_4;
goto LABEL_11;
}
}
else if ( !BYTE3(a2) )
{
goto LABEL_3;
}
v9 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "RSASIG", v10) + v9;
if ( !BYTE4(a2) )
{
LABEL_4:
if ( !BYTE2(a2) )
goto LABEL_5;
goto LABEL_12;
}
LABEL_11:
v11 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "ECDSA", v12) + v11;
if ( !BYTE2(a2) )
{
LABEL_5:
if ( !BYTE1(a2) )
goto LABEL_6;
goto LABEL_13;
}
LABEL_12:
v13 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "AUTH_NEVER", v14) + v13;
if ( !BYTE1(a2) )
{
LABEL_6:
if ( !BYTE5(a2) )
goto LABEL_7;
LABEL_14:
v17 = jam_string(a1, v4, v5);
v3 += jam_string(a1, "RSASIG_v1_5", v18) + v17;
if ( v3 )
return v3;
return jam_string(a1, "none", v5);
}
LABEL_13:
v15 = jam_string(a1, v4, v5);
v4 = "+";
v3 += jam_string(a1, "AUTH_NULL", v16) + v15;
if ( BYTE5(a2) )
goto LABEL_14;
LABEL_7:
if ( v3 )
return v3;
return jam_string(a1, "none", v5);
}

original_code:
size_t jam_authby(struct jambuf *buf, struct authby authby)
{
 size_t s = 0;
 const char *sep = "";
 { if (authby.psk) { s += jam_string(buf, sep); s += jam_string(buf, "PSK"); sep = "+"; } };
 { if (authby.rsasig) { s += jam_string(buf, sep); s += jam_string(buf, "RSASIG"); sep = "+"; } };
 { if (authby.ecdsa) { s += jam_string(buf, sep); s += jam_string(buf, "ECDSA"); sep = "+"; } };
 { if (authby.never) { s += jam_string(buf, sep); s += jam_string(buf, "AUTH_NEVER"); sep = "+"; } };
 { if (authby.null) { s += jam_string(buf, sep); s += jam_string(buf, "AUTH_NULL"); sep = "+"; } };
 { if (authby.rsasig_v1_5) { s += jam_string(buf, sep); s += jam_string(buf, "RSASIG_v1_5"); sep = "+"; } };
 if (s == 0) {
  s += jam_string(buf, "none");
 }
 return s;
}

canonical_original_code:
unsigned long jam_authby(struct jambuf *buf, struct authby authby)
{
 unsigned long s = 0;
 char *sep = "";
 { if (authby.psk) { s += jam_string(buf, sep); s += jam_string(buf, "PSK"); sep = "+"; } };
 { if (authby.rsasig) { s += jam_string(buf, sep); s += jam_string(buf, "RSASIG"); sep = "+"; } };
 { if (authby.ecdsa) { s += jam_string(buf, sep); s += jam_string(buf, "ECDSA"); sep = "+"; } };
 { if (authby.never) { s += jam_string(buf, sep); s += jam_string(buf, "AUTH_NEVER"); sep = "+"; } };
 { if (authby.null) { s += jam_string(buf, sep); s += jam_string(buf, "AUTH_NULL"); sep = "+"; } };
 { if (authby.rsasig_v1_5) { s += jam_string(buf, sep); s += jam_string(buf, "RSASIG_v1_5"); sep = "+"; } };
 if (s == 0) {
  s += jam_string(buf, "none");
 }
 return s;
}

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

variable_types:
s
unsigned long

variable_types:
sep
char *


decompiled_code:
__int64 __fastcall str_authby(__int64 a1, __int64 a2)
{
char v3[40]; // [rsp+10h] [rbp-48h] BYREF
unsigned __int64 v4; // [rsp+38h] [rbp-20h]

v4 = __readfsqword(0x28u);
array_as_jambuf(v3, a2, 41LL);
jam_authby(
(__int64)v3,
((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40));
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
char v3[40]; // [rsp+10h] [rbp-48h] BYREF
unsigned __int64 v4; // [rsp+38h] [rbp-20h]

v4 = __readfsqword(0x28u);
array_as_jambuf(v3, a2, 41LL);
func12(
(__int64)v3,
((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40));
return a2;
}

original_code:
const char *str_authby(struct authby authby, authby_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_authby(&jambuf, authby);
 return buf->buf;
}

canonical_original_code:
char *str_authby(struct authby authby, struct authby_buf *buf)
{
 struct jambuf jambuf = array_as_jambuf((buf->buf), sizeof(buf->buf));
 jam_authby(&jambuf, authby);
 return buf->buf;
}

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

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


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

if ( a1 > 0x395 )
{
if ( a1 > 0x1087 )
{
v2 = "VENDOR_DEFINED";
if ( a1 == 0x80000000 )
return (char *)v2;
goto LABEL_20;
}
if ( a1 <= 0x104F )
{
v2 = "CAMELLIA_CBC";
if ( a1 == 1362 )
return (char *)v2;
goto LABEL_20;
}
switch ( a1 )
{
case 0x1050uLL:
v2 = "ECDH1_DERIVE";
break;
case 0x1080uLL:
v2 = "AES_KEY_GEN";
break;
case 0x1081uLL:
v2 = "AES_ECB";
break;
case 0x1082uLL:
v2 = "AES_CBC";
break;
case 0x1083uLL:
v2 = "AES_MAC";
break;
case 0x1086uLL:
v2 = "AES_CTR";
break;
case 0x1087uLL:
v2 = "AES_GCM";
break;
default:
goto LABEL_20;
}
}
else if ( a1 > 0x35F )
{
switch ( a1 )
{
case 0x360uLL:
v2 = "CONCATENATE_BASE_AND_KEY";
break;
case 0x362uLL:
v2 = "CONCATENATE_BASE_AND_DATA";
break;
case 0x363uLL:
v2 = "CONCATENATE_DATA_AND_BASE";
break;
case 0x364uLL:
v2 = "XOR_BASE_AND_DATA";
break;
case 0x365uLL:
v2 = "EXTRACT_KEY_FROM_KEY";
break;
case 0x390uLL:
v2 = "MD5_KEY_DERIVATION";
break;
case 0x392uLL:
v2 = "SHA1_KEY_DERIVATION";
break;
case 0x393uLL:
v2 = "SHA256_KEY_DERIVATION";
break;
case 0x394uLL:
v2 = "SHA384_KEY_DERIVATION";
break;
case 0x395uLL:
v2 = "SHA512_KEY_DERIVATION";
break;
default:
goto LABEL_20;
}
}
else
{
if ( a1 > 0x271 )
goto LABEL_20;
if ( a1 > 0x24F )
{
switch ( a1 )
{
case 0x250uLL:
v2 = "SHA256";
break;
case 0x251uLL:
v2 = "SHA256_HMAC";
break;
case 0x260uLL:
v2 = "SHA384";
break;
case 0x261uLL:
v2 = "SHA384_HMAC";
break;
case 0x270uLL:
v2 = "SHA512";
break;
case 0x271uLL:
v2 = "SHA512_HMAC";
break;
default:
goto LABEL_20;
}
}
else
{
v2 = "MD5_HMAC";
if ( a1 != 529 )
{
if ( a1 <= 0x211 )
{
v2 = "DES3_CBC";
switch ( a1 )
{
case 0x133uLL:
return (char *)v2;
case 0x210uLL:
return "MD5";
case 0x21uLL:
return "DH_PKCS_DERIVE";
}
goto LABEL_20;
}
v2 = "SHA_1";
if ( a1 != 544 )
{
if ( a1 == 545 )
return "SHA_1_HMAC";
LABEL_20:
v2 = a2;
_snprintf_chk(a2, 23LL, 1LL, -1LL, "CKM_%08lx", a1);
return (char *)v2;
}
}
}
}
return (char *)v2;
}

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

if ( a1 > 0x395 )
{
if ( a1 > 0x1087 )
{
v2 = "VENDOR_DEFINED";
if ( a1 == 0x80000000 )
return (char *)v2;
goto LABEL_20;
}
if ( a1 <= 0x104F )
{
v2 = "CAMELLIA_CBC";
if ( a1 == 1362 )
return (char *)v2;
goto LABEL_20;
}
switch ( a1 )
{
case 0x1050uLL:
v2 = "ECDH1_DERIVE";
break;
case 0x1080uLL:
v2 = "AES_KEY_GEN";
break;
case 0x1081uLL:
v2 = "AES_ECB";
break;
case 0x1082uLL:
v2 = "AES_CBC";
break;
case 0x1083uLL:
v2 = "AES_MAC";
break;
case 0x1086uLL:
v2 = "AES_CTR";
break;
case 0x1087uLL:
v2 = "AES_GCM";
break;
default:
goto LABEL_20;
}
}
else if ( a1 > 0x35F )
{
switch ( a1 )
{
case 0x360uLL:
v2 = "CONCATENATE_BASE_AND_KEY";
break;
case 0x362uLL:
v2 = "CONCATENATE_BASE_AND_DATA";
break;
case 0x363uLL:
v2 = "CONCATENATE_DATA_AND_BASE";
break;
case 0x364uLL:
v2 = "XOR_BASE_AND_DATA";
break;
case 0x365uLL:
v2 = "EXTRACT_KEY_FROM_KEY";
break;
case 0x390uLL:
v2 = "MD5_KEY_DERIVATION";
break;
case 0x392uLL:
v2 = "SHA1_KEY_DERIVATION";
break;
case 0x393uLL:
v2 = "SHA256_KEY_DERIVATION";
break;
case 0x394uLL:
v2 = "SHA384_KEY_DERIVATION";
break;
case 0x395uLL:
v2 = "SHA512_KEY_DERIVATION";
break;
default:
goto LABEL_20;
}
}
else
{
if ( a1 > 0x271 )
goto LABEL_20;
if ( a1 > 0x24F )
{
switch ( a1 )
{
case 0x250uLL:
v2 = "SHA256";
break;
case 0x251uLL:
v2 = "SHA256_HMAC";
break;
case 0x260uLL:
v2 = "SHA384";
break;
case 0x261uLL:
v2 = "SHA384_HMAC";
break;
case 0x270uLL:
v2 = "SHA512";
break;
case 0x271uLL:
v2 = "SHA512_HMAC";
break;
default:
goto LABEL_20;
}
}
else
{
v2 = "MD5_HMAC";
if ( a1 != 529 )
{
if ( a1 <= 0x211 )
{
v2 = "DES3_CBC";
switch ( a1 )
{
case 0x133uLL:
return (char *)v2;
case 0x210uLL:
return "MD5";
case 0x21uLL:
return "DH_PKCS_DERIVE";
}
goto LABEL_20;
}
v2 = "SHA_1";
if ( a1 != 544 )
{
if ( a1 == 545 )
return "SHA_1_HMAC";
LABEL_20:
v2 = a2;
_snprintf_chk(a2, 23LL, 1LL, -1LL, "CKM_%08lx", a1);
return (char *)v2;
}
}
}
}
return (char *)v2;
}

original_code:
const char *str_nss_ckm(CK_MECHANISM_TYPE mechanism, enum_buf *buf)
{
 switch (mechanism) {
  case 0x00000362: return &"CKM_CONCATENATE_BASE_AND_DATA"[strlen("CKM_")];
  case 0x00000360: return &"CKM_CONCATENATE_BASE_AND_KEY"[strlen("CKM_")];
  case 0x00000363: return &"CKM_CONCATENATE_DATA_AND_BASE"[strlen("CKM_")];
  case 0x00000364: return &"CKM_XOR_BASE_AND_DATA"[strlen("CKM_")];
  case 0x00000365: return &"CKM_EXTRACT_KEY_FROM_KEY"[strlen("CKM_")];
  case 0x00001082: return &"CKM_AES_CBC"[strlen("CKM_")];
  case 0x00000133: return &"CKM_DES3_CBC"[strlen("CKM_")];
  case 0x00000552: return &"CKM_CAMELLIA_CBC"[strlen("CKM_")];
  case 0x00001086: return &"CKM_AES_CTR"[strlen("CKM_")];
  case 0x00001087: return &"CKM_AES_GCM"[strlen("CKM_")];
  case 0x00001083: return &"CKM_AES_MAC"[strlen("CKM_")];
  case 0x00001081: return &"CKM_AES_ECB"[strlen("CKM_")];
  case 0x00001080: return &"CKM_AES_KEY_GEN"[strlen("CKM_")];
  case 0x00000210: return &"CKM_MD5"[strlen("CKM_")];
  case 0x00000220: return &"CKM_SHA_1"[strlen("CKM_")];
  case 0x00000250: return &"CKM_SHA256"[strlen("CKM_")];
  case 0x00000260: return &"CKM_SHA384"[strlen("CKM_")];
  case 0x00000270: return &"CKM_SHA512"[strlen("CKM_")];
  case 0x00000390: return &"CKM_MD5_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000392: return &"CKM_SHA1_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000393: return &"CKM_SHA256_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000394: return &"CKM_SHA384_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000395: return &"CKM_SHA512_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000211: return &"CKM_MD5_HMAC"[strlen("CKM_")];
  case 0x00000221: return &"CKM_SHA_1_HMAC"[strlen("CKM_")];
  case 0x00000251: return &"CKM_SHA256_HMAC"[strlen("CKM_")];
  case 0x00000261: return &"CKM_SHA384_HMAC"[strlen("CKM_")];
  case 0x00000271: return &"CKM_SHA512_HMAC"[strlen("CKM_")];
  case 0x00000021: return &"CKM_DH_PKCS_DERIVE"[strlen("CKM_")];
  case 0x00001050: return &"CKM_ECDH1_DERIVE"[strlen("CKM_")];
  case 0x80000000: return &"CKM_VENDOR_DEFINED"[strlen("CKM_")];
 default:
 {
  snprintf(buf->buf, sizeof(buf->buf),
    "CKM_%08lx", (long)mechanism);
  return buf->buf;
 }
 }
}

canonical_original_code:
char *str_nss_ckm(unsigned long mechanism, struct enum_buf *buf)
{
 switch (mechanism) {
  case 0x00000362: return &"CKM_CONCATENATE_BASE_AND_DATA"[strlen("CKM_")];
  case 0x00000360: return &"CKM_CONCATENATE_BASE_AND_KEY"[strlen("CKM_")];
  case 0x00000363: return &"CKM_CONCATENATE_DATA_AND_BASE"[strlen("CKM_")];
  case 0x00000364: return &"CKM_XOR_BASE_AND_DATA"[strlen("CKM_")];
  case 0x00000365: return &"CKM_EXTRACT_KEY_FROM_KEY"[strlen("CKM_")];
  case 0x00001082: return &"CKM_AES_CBC"[strlen("CKM_")];
  case 0x00000133: return &"CKM_DES3_CBC"[strlen("CKM_")];
  case 0x00000552: return &"CKM_CAMELLIA_CBC"[strlen("CKM_")];
  case 0x00001086: return &"CKM_AES_CTR"[strlen("CKM_")];
  case 0x00001087: return &"CKM_AES_GCM"[strlen("CKM_")];
  case 0x00001083: return &"CKM_AES_MAC"[strlen("CKM_")];
  case 0x00001081: return &"CKM_AES_ECB"[strlen("CKM_")];
  case 0x00001080: return &"CKM_AES_KEY_GEN"[strlen("CKM_")];
  case 0x00000210: return &"CKM_MD5"[strlen("CKM_")];
  case 0x00000220: return &"CKM_SHA_1"[strlen("CKM_")];
  case 0x00000250: return &"CKM_SHA256"[strlen("CKM_")];
  case 0x00000260: return &"CKM_SHA384"[strlen("CKM_")];
  case 0x00000270: return &"CKM_SHA512"[strlen("CKM_")];
  case 0x00000390: return &"CKM_MD5_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000392: return &"CKM_SHA1_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000393: return &"CKM_SHA256_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000394: return &"CKM_SHA384_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000395: return &"CKM_SHA512_KEY_DERIVATION"[strlen("CKM_")];
  case 0x00000211: return &"CKM_MD5_HMAC"[strlen("CKM_")];
  case 0x00000221: return &"CKM_SHA_1_HMAC"[strlen("CKM_")];
  case 0x00000251: return &"CKM_SHA256_HMAC"[strlen("CKM_")];
  case 0x00000261: return &"CKM_SHA384_HMAC"[strlen("CKM_")];
  case 0x00000271: return &"CKM_SHA512_HMAC"[strlen("CKM_")];
  case 0x00000021: return &"CKM_DH_PKCS_DERIVE"[strlen("CKM_")];
  case 0x00001050: return &"CKM_ECDH1_DERIVE"[strlen("CKM_")];
  case 0x80000000: return &"CKM_VENDOR_DEFINED"[strlen("CKM_")];
 default:
 {
  snprintf(buf->buf, sizeof(buf->buf),
    "CKM_%08lx", (long)mechanism);
  return buf->buf;
 }
 }
}

variable_types:
mechanism
unsigned long

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


decompiled_code:
__int64 __fastcall jam_nss_ckm(__int64 a1, unsigned __int64 a2)
{
char *v2; // rax
char v4[24]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-10h]

v5 = __readfsqword(0x28u);
v2 = str_nss_ckm(a2, v4);
return jam_string(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2)
{
char *v2; // rax
char v4[24]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 v5; // [rsp+18h] [rbp-10h]

v5 = __readfsqword(0x28u);
v2 = func0(a2, v4);
return jam_string(a1, v2);
}

original_code:
size_t jam_nss_ckm(struct jambuf *buf, CK_MECHANISM_TYPE mechanism)
{
 enum_buf b;
 return jam_string(buf, str_nss_ckm(mechanism, &b));
}

canonical_original_code:
unsigned long jam_nss_ckm(struct jambuf *buf, unsigned long mechanism)
{
 struct enum_buf b;
 return jam_string(buf, str_nss_ckm(mechanism, &b));
}

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


decompiled_code:
__int64 __fastcall jam_impairment(__int64 a1, __int64 a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rcx
__int64 v9; // rsi
unsigned __int64 v11; // rax
__int64 v12; // rdi
unsigned __int64 v13; // [rsp+8h] [rbp-20h]

v13 = __readfsqword(0x28u);
jam(a1, "%s:", *(const char **)a2);
v3 = value_of_isra_0(*(unsigned int **)(a2 + 40), *(_QWORD *)(a2 + 48));
v4 = *(_QWORD *)(a2 + 16);
v5 = v3;
if ( !v4 )
{
v12 = *(_QWORD *)(a2 + 24);
if ( v12 )
{
v9 = enum_name_short(v12, v3);
if ( v9 )
return jam_string(a1, v9, v7, v8);
return jam(a1, "?%u?", v5);
}
if ( *(_QWORD *)(a2 + 32) )
{
if ( v3 )
return jam(a1, "%u", v3 - 1);
}
else if ( v3 )
{
if ( v3 == 1 )
return jam(a1, "yes");
return jam(a1, "?%u?", v5);
}
return jam(a1, "no");
}
v6 = keyword_by_value(v4, v3);
if ( v6 )
{
v8 = v13 - __readfsqword(0x28u);
v9 = *(_QWORD *)(v6 + 8);
return jam_string(a1, v9, v7, v8);
}
v11 = *(_QWORD *)(*(_QWORD *)(a2 + 16) + 8LL);
if ( v11 > v5 )
return jam(a1, "?%u?", v5);
return jam(a1, "%zu", v5 - v11);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v3; // eax
__int64 v4; // rdi
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rcx
__int64 v9; // rsi
unsigned __int64 v11; // rax
__int64 v12; // rdi
unsigned __int64 v13; // [rsp+8h] [rbp-20h]

v13 = __readfsqword(0x28u);
jam(a1, "%s:", *(const char **)a2);
v3 = func0(*(unsigned int **)(a2 + 40), *(_QWORD *)(a2 + 48));
v4 = *(_QWORD *)(a2 + 16);
v5 = v3;
if ( !v4 )
{
v12 = *(_QWORD *)(a2 + 24);
if ( v12 )
{
v9 = enum_name_short(v12, v3);
if ( v9 )
return jam_string(a1, v9, v7, v8);
return jam(a1, "?%u?", v5);
}
if ( *(_QWORD *)(a2 + 32) )
{
if ( v3 )
return jam(a1, "%u", v3 - 1);
}
else if ( v3 )
{
if ( v3 == 1 )
return jam(a1, "yes");
return jam(a1, "?%u?", v5);
}
return jam(a1, "no");
}
v6 = keyword_by_value(v4, v3);
if ( v6 )
{
v8 = v13 - __readfsqword(0x28u);
v9 = *(_QWORD *)(v6 + 8);
return jam_string(a1, v9, v7, v8);
}
v11 = *(_QWORD *)(*(_QWORD *)(a2 + 16) + 8LL);
if ( v11 > v5 )
return jam(a1, "?%u?", v5);
return jam(a1, "%zu", v5 - v11);
}

original_code:
static void jam_impairment(struct jambuf *buf,
      const struct impairment *impairment)
{
 jam(buf, "%s:", impairment->what);
 unsigned value = value_of(impairment);
 if (impairment->how_keywords != ((void *)0)) {
  const struct keyword *kw = keyword_by_value(impairment->how_keywords, value);
  if (kw != ((void *)0)) {
   jam_string(buf, kw->sname);
  } else if (value >= impairment->how_keywords->nr_values) {
   jam(buf, "%zu", value - impairment->how_keywords->nr_values);
  } else {
   jam(buf, "?%u?", value);
  }
 } else if (impairment->how_enum_names != ((void *)0)) {
  const char *sname = enum_name_short(impairment->how_enum_names, value);
  if (sname != ((void *)0)) {
   jam_string(buf, sname);
  } else {
   jam(buf, "?%u?", value);
  }
 } else if (impairment->unsigned_help != ((void *)0)) {
  if (value == 0) {
   jam(buf, "no");
  } else {
   jam(buf, "%u", value-1);
  }
 } else {
  switch (value) {
  case 0: jam(buf, "no"); break;
  case 1: jam(buf, "yes"); break;
  default: jam(buf, "?%u?", value);
  }
 }
}

canonical_original_code:
static void jam_impairment(struct jambuf *buf, struct impairment *impairment)
{
 jam(buf, "%s:", impairment->what);
 unsigned int value = value_of(impairment);
 if (impairment->how_keywords != ((void *)0)) {
  struct keyword *kw = keyword_by_value(impairment->how_keywords, value);
  if (kw != ((void *)0)) {
   jam_string(buf, kw->sname);
  } else if (value >= impairment->how_keywords->nr_values) {
   jam(buf, "%zu", value - impairment->how_keywords->nr_values);
  } else {
   jam(buf, "?%u?", value);
  }
 } else if (impairment->how_enum_names != ((void *)0)) {
  char *sname = enum_name_short(impairment->how_enum_names, value);
  if (sname != ((void *)0)) {
   jam_string(buf, sname);
  } else {
   jam(buf, "?%u?", value);
  }
 } else if (impairment->unsigned_help != ((void *)0)) {
  if (value == 0) {
   jam(buf, "no");
  } else {
   jam(buf, "%u", value-1);
  }
 } else {
  switch (value) {
  case 0: jam(buf, "no"); break;
  case 1: jam(buf, "yes"); break;
  default: jam(buf, "?%u?", value);
  }
 }
}

variable_types: struct impairment { char *what; char *help; struct keywords { struct keyword { char *name; char *sname; unsigned int value; char *details; } *values; unsigned long nr_values; struct keyword *(*by_value)(struct keywords *, unsigned int); char *name; } *how_keywords; struct enum_names { unsigned long en_first; unsigned long en_last; char **en_names; unsigned long en_checklen; char *en_prefix; struct enum_names *en_next_range; } *how_enum_names; char *unsigned_help; void *value; unsigned long sizeof_value; enum impair_action { CALL_IMPAIR_UPDATE=0, CALL_INITIATE_v2_LIVENESS=1, CALL_SEND_KEEPALIVE=2, CALL_GLOBAL_EVENT_HANDLER=3, CALL_STATE_EVENT_HANDLER=4, CALL_IMPAIR_DROP_INCOMING=5, CALL_IMPAIR_DROP_OUTGOING=6 } action; unsigned int param; } *

variable_types:
value
unsigned int

variable_types:
sname
char *

user_defined_types: struct impairment { char *what; char *help; struct keywords *how_keywords; struct enum_names *how_enum_names; char *unsigned_help; void *value; unsigned long sizeof_value; enum impair_action action; unsigned int param; }


decompiled_code:
__int64 have_impairments()
{
_QWORD *v0; // rbx

v0 = &impairments[13];
do
{
if ( !*((_DWORD *)v0 + 4) && value_of_isra_0((unsigned int *)*v0, v0[1]) )
return 1LL;
v0 += 8;
}
while ( v0 != &impairments[661] );
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
_QWORD *v0; // rbx

v0 = &impairments[13];
do
{
if ( !*((_DWORD *)v0 + 4) && func0((unsigned int *)*v0, v0[1]) )
return 1LL;
v0 += 8;
}
while ( v0 != &impairments[661] );
return 0LL;
}

original_code:
_Bool have_impairments(void)
{
 for (unsigned ci = 1; ci < (sizeof(impairments) / sizeof(*(impairments))); ci++) {
  const struct impairment *impairment = &impairments[ci];
  if (impairment->action == CALL_IMPAIR_UPDATE &&
      value_of(impairment) != 0) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
_Bool have_impairments()
{
 for (unsigned int ci = 1; ci < (sizeof(impairments) / sizeof(*(impairments))); ci++) {
  struct impairment *impairment = &impairments[ci];
  if (impairment->action == CALL_IMPAIR_UPDATE &&
      value_of(impairment) != 0) {
   return 1;
  }
 }
 return 0;
}

variable_types:
ci
unsigned int

user_defined_types: enum impair_action { CALL_IMPAIR_UPDATE=0, CALL_INITIATE_v2_LIVENESS=1, CALL_SEND_KEEPALIVE=2, CALL_GLOBAL_EVENT_HANDLER=3, CALL_STATE_EVENT_HANDLER=4, CALL_IMPAIR_DROP_INCOMING=5, CALL_IMPAIR_DROP_OUTGOING=6 }

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


decompiled_code:
unsigned __int64 __fastcall jam_impairments(__int64 a1, void *a2)
{
void *v3; // r13
_QWORD *v4; // rbx
_QWORD *v5; // rbp
__int64 v6; // rdx
__int64 v7; // rcx
void *v8; // rsi
__int64 v9; // rsi
unsigned __int64 v11; // [rsp+8h] [rbp-30h]

v3 = &LC7;
v4 = &impairments[8];
v5 = &impairments[656];
v11 = __readfsqword(0x28u);
do
{
while ( *((_DWORD *)v4 + 14) || !value_of_isra_0((unsigned int *)v4[5], v4[6]) )
{
v4 += 8;
if ( v4 == v5 )
return v11 - __readfsqword(0x28u);
}
v8 = v3;
v3 = a2;
jam_string(a1, v8, v6, v7);
v9 = (__int64)v4;
v4 += 8;
jam_impairment(a1, v9);
}
while ( v4 != v5 );
return v11 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, void *a2)
{
void *v3; // r13
_QWORD *v4; // rbx
_QWORD *v5; // rbp
__int64 v6; // rdx
__int64 v7; // rcx
void *v8; // rsi
__int64 v9; // rsi
unsigned __int64 v11; // [rsp+8h] [rbp-30h]

v3 = &LC7;
v4 = &impairments[8];
v5 = &impairments[656];
v11 = __readfsqword(0x28u);
do
{
while ( *((_DWORD *)v4 + 14) || !func0((unsigned int *)v4[5], v4[6]) )
{
v4 += 8;
if ( v4 == v5 )
return v11 - __readfsqword(0x28u);
}
v8 = v3;
v3 = a2;
jam_string(a1, v8, v6, v7);
v9 = (__int64)v4;
v4 += 8;
func1(a1, v9);
}
while ( v4 != v5 );
return v11 - __readfsqword(0x28u);
}

original_code:
void jam_impairments(struct jambuf *buf, const char *sep)
{
 const char *s = "";
 for (unsigned ci = 1; ci < (sizeof(impairments) / sizeof(*(impairments))); ci++) {
  const struct impairment *impairment = &impairments[ci];
  if (impairment->action == CALL_IMPAIR_UPDATE &&
      value_of(impairment) != 0) {
   jam_string(buf, s); s = sep;
   jam_impairment(buf, impairment);
  }
 }
}

canonical_original_code:
void jam_impairments(struct jambuf *buf, char *sep)
{
 char *s = "";
 for (unsigned int ci = 1; ci < (sizeof(impairments) / sizeof(*(impairments))); ci++) {
  struct impairment *impairment = &impairments[ci];
  if (impairment->action == CALL_IMPAIR_UPDATE &&
      value_of(impairment) != 0) {
   jam_string(buf, s); s = sep;
   jam_impairment(buf, impairment);
  }
 }
}

variable_types:
s
char *


original_code:
static int pam_conv(int num_msg,
      const struct pam_message **msgm,
      struct pam_response **response,
      void *appdata_ptr)
{
 struct pam_thread_arg *const arg = appdata_ptr;
 int count = 0;
 struct pam_response *reply;
 if (num_msg <= 0)
  return 19;
 reply = malloc(num_msg * sizeof(struct pam_response));
 for (count = 0; count < num_msg; ++count) {
  const char *s = ((void *)0);
  switch (msgm[count]->msg_style) {
  case 1:
   s = arg->password;
   break;
  case 2:
   s = arg->name;
   break;
  }
  reply[count].resp_retcode = 0;
  reply[count].resp = ((void *)0);
  if (s != ((void *)0)) {
   size_t len = strlen(s) + 1;
   char *t = malloc(len);
   memcpy(t, s, len);
   reply[count].resp = t;
  }
 }
 *response = reply;
 return 0;
}

canonical_original_code:
static int pam_conv(int num_msg, struct pam_message **msgm, struct pam_response **response, void *appdata_ptr)
{
 struct pam_thread_arg *arg = appdata_ptr;
 int count = 0;
 struct pam_response *reply;
 if (num_msg <= 0)
  return 19;
 reply = malloc(num_msg * sizeof(struct pam_response));
 for (count = 0; count < num_msg; ++count) {
  char *s = ((void *)0);
  switch (msgm[count]->msg_style) {
  case 1:
   s = arg->password;
   break;
  case 2:
   s = arg->name;
   break;
  }
  reply[count].resp_retcode = 0;
  reply[count].resp = ((void *)0);
  if (s != ((void *)0)) {
   unsigned long len = strlen(s) + 1;
   char *t = malloc(len);
   memcpy(t, s, len);
   reply[count].resp = t;
  }
 }
 *response = reply;
 return 0;
}

variable_types: struct pam_message { int msg_style; char *msg; } **

variable_types: struct pam_response { char *resp; int resp_retcode; } **

variable_types: struct pam_thread_arg { char *name; char *password; char *c_name; struct ip_address { _Bool is_set; enum ip_version { IPv4=4, IPv6=6 } version; struct ip_bytes { unsigned char byte[16]; } bytes; } rhost; unsigned long st_serialno; unsigned long c_instance_serial; char *atype; } *

variable_types: count int

variable_types:
len
unsigned long

variable_types:
t
char *

user_defined_types: struct pam_thread_arg { char *name; char *password; char *c_name; struct ip_address rhost; unsigned long st_serialno; unsigned long c_instance_serial; char *atype; }

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


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

v3 = __readfsqword(0x28u);
if ( (cur_debugging & 1) != 0 )
DBG_log(
"%s helper thread %s for state #%lu, %s[%lu] user=%s.",
*(const char **)(a1 + 64),
a2,
*(_QWORD *)(a1 + 48),
*(const char **)(a1 + 16),
*(_QWORD *)(a1 + 56),
*(const char **)a1);
return v3 - __readfsqword(0x28u);
}

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

v3 = __readfsqword(0x28u);
if ( (cur_debugging & 1) != 0 )
DBG_log(
"%s helper thread %s for state #%lu, %s[%lu] user=%s.",
*(const char **)(a1 + 64),
a2,
*(_QWORD *)(a1 + 48),
*(const char **)(a1 + 16),
*(_QWORD *)(a1 + 56),
*(const char **)a1);
return v3 - __readfsqword(0x28u);
}

original_code:
static void dbg_pam_step(const struct pam_thread_arg *arg, const char *what)
{
 { if ((cur_debugging & (((lset_t)1 << (DBG_BASE_IX))))) { DBG_log("%s helper thread %s for state #%lu, %s[%lu] user=%s.", arg->atype, what, arg->st_serialno, arg->c_name, arg->c_instance_serial, arg->name); } };
}

canonical_original_code:
static void dbg_pam_step(struct pam_thread_arg *arg, char *what)
{
 { if ((cur_debugging & (((unsigned long)1 << (DBG_BASE_IX))))) { DBG_log("%s helper thread %s for state #%lu, %s[%lu] user=%s.", arg->atype, what, arg->st_serialno, arg->c_name, arg->c_instance_serial, arg->name); } };
}

variable_types:
what
char *

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


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

if ( a1 > 0xFF )
result = 0LL;
else
result = (char *)&ip_protocols + 72 * a1;
return result;
}

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

if ( a1 > 0xFF )
result = 0LL;
else
result = (char *)&ip_protocols + 72 * a1;
return result;
}

original_code:
const struct ip_protocol *protocol_from_ipproto(unsigned ipproto)
{
 if (ipproto >= (sizeof(ip_protocols) / sizeof(*(ip_protocols)))) {
  return ((void *)0);
 }
 const struct ip_protocol *p = &ip_protocols[ipproto];
 return p;
}

canonical_original_code:
struct ip_protocol *protocol_from_ipproto(unsigned int ipproto)
{
 if (ipproto >= (sizeof(ip_protocols) / sizeof(*(ip_protocols)))) {
  return ((void *)0);
 }
 struct ip_protocol *p = &ip_protocols[ipproto];
 return p;
}

variable_types:
ipproto
unsigned int

variable_types: struct ip_protocol { unsigned int ipproto; char *description; char *prefix; char *name; _Bool ipv6_extension_header; char *reference; unsigned int ikev1_protocol_id; struct ip_encap { char *name; struct ip_protocol *outer; struct ip_protocol *inner; unsigned int encap_type; } *encap_esp; _Bool zero_port_is_any; } *

user_defined_types: struct ip_protocol { unsigned int ipproto; char *description; char *prefix; char *name; _Bool ipv6_extension_header; char *reference; unsigned int ikev1_protocol_id; struct ip_encap *encap_esp; _Bool zero_port_is_any; }


decompiled_code:
const char *__fastcall str_protocol(__int64 a1)
{
const char *result; // rax

result = "<null-protocol>";
if ( a1 )
result = *(const char **)(a1 + 24);
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1)
{
const char *result; // rax

result = "<null-protocol>";
if ( a1 )
result = *(const char **)(a1 + 24);
return result;
}

original_code:
const char *str_protocol(const struct ip_protocol *protocol)
{
 if (protocol == ((void *)0)) {
  return "<null-protocol>";
 }
 return protocol->name;
}

canonical_original_code:
char *str_protocol(struct ip_protocol *protocol)
{
 if (protocol == ((void *)0)) {
  return "<null-protocol>";
 }
 return protocol->name;
}

user_defined_types: struct ip_encap { char *name; struct ip_protocol *outer; struct ip_protocol *inner; unsigned int encap_type; }


decompiled_code:
__int64 __fastcall jam_protocol(__int64 a1, __int64 a2)
{
const char *v2; // rsi

v2 = str_protocol(a2);
return jam_string(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
const char *v2; // rsi

v2 = func3(a2);
return jam_string(a1, v2);
}

original_code:
size_t jam_protocol(struct jambuf *buf, const struct ip_protocol *protocol)
{
 return jam_string(buf, str_protocol(protocol));
}

canonical_original_code:
unsigned long jam_protocol(struct jambuf *buf, struct ip_protocol *protocol)
{
 return jam_string(buf, str_protocol(protocol));
}

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


decompiled_code:
__int64 __fastcall jam_protocol_pair(__int64 a1, __int64 a2, char a3, __int64 a4)
{
unsigned int v5; // er13
const char *v7; // rsi
__int64 v8; // rbx
__int64 v9; // rbx
const char *v10; // rsi
__int64 v11; // rbx
__int64 v12; // rbx

v5 = a3;
v7 = "<null>";
v8 = jam_char(a1, (unsigned int)a3);
if ( a2 )
{
v7 = "<all>";
if ( *(_DWORD *)a2 )
v7 = *(const char **)(a2 + 24);
}
v9 = jam_string(a1, v7) + v8;
if ( a2 != a4 )
{
v10 = "<null>";
v11 = jam_char(a1, v5) + v9;
if ( a4 )
{
v10 = "<all>";
if ( *(_DWORD *)a4 )
v10 = *(const char **)(a4 + 24);
}
v9 = jam_string(a1, v10) + v11;
}
v12 = jam_char(a1, v5) + v9;
return v12 + jam_char(a1, 62LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, char a3, __int64 a4)
{
unsigned int v5; // er13
const char *v7; // rsi
__int64 v8; // rbx
__int64 v9; // rbx
const char *v10; // rsi
__int64 v11; // rbx
__int64 v12; // rbx

v5 = a3;
v7 = "<null>";
v8 = jam_char(a1, (unsigned int)a3);
if ( a2 )
{
v7 = "<all>";
if ( *(_DWORD *)a2 )
v7 = *(const char **)(a2 + 24);
}
v9 = jam_string(a1, v7) + v8;
if ( a2 != a4 )
{
v10 = "<null>";
v11 = jam_char(a1, v5) + v9;
if ( a4 )
{
v10 = "<all>";
if ( *(_DWORD *)a4 )
v10 = *(const char **)(a4 + 24);
}
v9 = jam_string(a1, v10) + v11;
}
v12 = jam_char(a1, v5) + v9;
return v12 + jam_char(a1, 62LL);
}

original_code:
size_t jam_protocol_pair(struct jambuf *buf,
    const struct ip_protocol *src,
    char sep,
    const struct ip_protocol *dst)
{
 size_t s = 0;
 s += jam_char(buf, sep);
 s += jam_string(buf, (src == ((void *)0) ? "<null>" :
         src->ipproto == 0 ? "<all>" :
         src->name));
 if (src != dst) {
  s += jam_char(buf, sep);
  s += jam_string(buf, (dst == ((void *)0) ? "<null>" :
          dst->ipproto == 0 ? "<all>" :
          dst->name));
 }
 s += jam_char(buf, sep);
 s += jam_char(buf, '>');
 return s;
}

canonical_original_code:
unsigned long jam_protocol_pair(struct jambuf *buf, struct ip_protocol *src, char sep, struct ip_protocol *dst)
{
 unsigned long s = 0;
 s += jam_char(buf, sep);
 s += jam_string(buf, (src == ((void *)0) ? "<null>" :
         src->ipproto == 0 ? "<all>" :
         src->name));
 if (src != dst) {
  s += jam_char(buf, sep);
  s += jam_string(buf, (dst == ((void *)0) ? "<null>" :
          dst->ipproto == 0 ? "<all>" :
          dst->name));
 }
 s += jam_char(buf, sep);
 s += jam_char(buf, '>');
 return s;
}

variable_types: sep char

variable_types:
dst
struct ip_protocol *

variable_types:
s
unsigned long

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