shunks

decompiled_code:
__int64 __fastcall shunks(unsigned __int64 a1, unsigned __int64 a2, const char *a3, int a4, _QWORD *a5)
{
__int64 v6; // rbp
__int64 v7; // r13
unsigned __int64 i; // rax
__int64 v9; // rdx
unsigned int v10; // edx
__int64 v11; // rax
unsigned __int64 v12; // rbx
__int64 v13; // r12
char v17; // [rsp+27h] [rbp-61h] BYREF
__int64 v18; // [rsp+28h] [rbp-60h] BYREF
unsigned __int64 v19[11]; // [rsp+30h] [rbp-58h] BYREF

v19[3] = __readfsqword(0x28u);
if ( (cur_debugging & 8) != 0 )
DBG_log("%s() input=\"%.*s\" delims=\"%s\"", "shunks", (unsigned int)a2, a1, a3);
v6 = alloc_bytes(8LL, *a5);
v19[0] = a1;
v19[1] = a2;
v7 = 8LL;
for ( i = shunk_token(v19, &v17, a3); ; i = shunk_token(v19, &v17, a3) )
{
v12 = i;
v13 = v9;
if ( !i )
break;
if ( v9 )
goto LABEL_6;
if ( a4 != 1 )
{
*(_BYTE *)v6 = 1;
LABEL_6:
if ( (cur_debugging & 8) != 0 )
DBG_log("%s() [%u] \"%.*s\"", "shunks", *(unsigned int *)(v6 + 4), (unsigned int)v9, i);
v18 = v6;
realloc_bytes(&v18, v7, v7 + 16, *a5);
v6 = v18;
v10 = *(_DWORD *)(v18 + 4);
v11 = v18 + 16LL * v10;
*(_QWORD *)(v11 + 8) = v12;
*(_QWORD *)(v11 + 16) = v13;
*(_DWORD *)(v6 + 4) = v10 + 1;
v7 += 16LL;
continue;
}
if ( (cur_debugging & 8) != 0 )
DBG_log("%s() pass 1 eat empty", "shunks");
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1, unsigned __int64 a2, const char *a3, int a4, _QWORD *a5)
{
__int64 v6; // rbp
__int64 v7; // r13
unsigned __int64 i; // rax
__int64 v9; // rdx
unsigned int v10; // edx
__int64 v11; // rax
unsigned __int64 v12; // rbx
__int64 v13; // r12
char v17; // [rsp+27h] [rbp-61h] BYREF
__int64 v18; // [rsp+28h] [rbp-60h] BYREF
unsigned __int64 v19[11]; // [rsp+30h] [rbp-58h] BYREF

v19[3] = __readfsqword(0x28u);
if ( (cur_debugging & 8) != 0 )
DBG_log("%s() input=\"%.*s\" delims=\"%s\"", "shunks", (unsigned int)a2, a1, a3);
v6 = alloc_bytes(8LL, *a5);
v19[0] = a1;
v19[1] = a2;
v7 = 8LL;
for ( i = func2(v19, &v17, a3); ; i = func2(v19, &v17, a3) )
{
v12 = i;
v13 = v9;
if ( !i )
break;
if ( v9 )
goto LABEL_6;
if ( a4 != 1 )
{
*(_BYTE *)v6 = 1;
LABEL_6:
if ( (cur_debugging & 8) != 0 )
DBG_log("%s() [%u] \"%.*s\"", "shunks", *(unsigned int *)(v6 + 4), (unsigned int)v9, i);
v18 = v6;
realloc_bytes(&v18, v7, v7 + 16, *a5);
v6 = v18;
v10 = *(_DWORD *)(v18 + 4);
v11 = v18 + 16LL * v10;
*(_QWORD *)(v11 + 8) = v12;
*(_QWORD *)(v11 + 16) = v13;
*(_DWORD *)(v6 + 4) = v10 + 1;
v7 += 16LL;
continue;
}
if ( (cur_debugging & 8) != 0 )
DBG_log("%s() pass 1 eat empty", "shunks");
}
return v6;
}

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


repo: libreswan/libreswan

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 )
{
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:
result = 0LL;
break;
}
}
}
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:
result = 0LL;
break;
}
}
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 )
{
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:
result = 0LL;
break;
}
}
}
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:
result = 0LL;
break;
}
}
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)
{
char v1; // al

v1 = 1;
if ( !BYTE1(a1) && !BYTE2(a1) && !(_BYTE)a1 && !BYTE3(a1) && !BYTE5(a1) )
v1 = BYTE4(a1);
return v1 & 1;
}

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+12h] [rbp-36h]
unsigned __int16 v4; // [rsp+16h] [rbp-32h]

LOBYTE(v3) = (_BYTE)a1 != (unsigned __int8)a2;
BYTE1(v3) = BYTE1(a1) != BYTE1(a2);
BYTE2(v3) = BYTE2(a2) != BYTE2(a1);
HIBYTE(v3) = BYTE3(a1) != BYTE3(a2);
LOBYTE(v4) = BYTE4(a2) != BYTE4(a1);
HIBYTE(v4) = BYTE5(a2) != BYTE5(a1);
return v3 | ((unsigned __int64)v4 << 32);
}

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

LOBYTE(v3) = (_BYTE)a1 != (unsigned __int8)a2;
BYTE1(v3) = BYTE1(a1) != BYTE1(a2);
BYTE2(v3) = BYTE2(a2) != BYTE2(a1);
HIBYTE(v3) = BYTE3(a1) != BYTE3(a2);
LOBYTE(v4) = BYTE4(a2) != BYTE4(a1);
HIBYTE(v4) = BYTE5(a2) != BYTE5(a1);
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)
{
unsigned __int64 v1; // rax
unsigned int v3; // [rsp+22h] [rbp-16h]
unsigned __int16 v4; // [rsp+26h] [rbp-12h]

v1 = authby_xor(
a1 & 0xFF00000000LL | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | ((unsigned __int64)BYTE3(a1) << 24) | a1 & 0xFF0000000000LL,
0x10101010101LL);
LOWORD(v3) = v1;
BYTE2(v3) = BYTE2(v1);
HIBYTE(v3) = BYTE3(v1);
LOBYTE(v4) = BYTE4(v1);
HIBYTE(v4) = BYTE5(v1);
return v3 | ((unsigned __int64)v4 << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned int v3; // [rsp+22h] [rbp-16h]
unsigned __int16 v4; // [rsp+26h] [rbp-12h]

v1 = func1(
a1 & 0xFF00000000LL | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | ((unsigned __int64)BYTE3(a1) << 24) | a1 & 0xFF0000000000LL,
0x10101010101LL);
LOWORD(v3) = v1;
BYTE2(v3) = BYTE2(v1);
HIBYTE(v3) = BYTE3(v1);
LOBYTE(v4) = BYTE4(v1);
HIBYTE(v4) = BYTE5(v1);
return v3 | ((unsigned __int64)v4 << 32);
}

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; // al
char v5; // di
char v6; // al
char v7; // si
char v8; // al
char v9; // cl
char v10; // al
char v11; // dl
char v12; // al
unsigned int v16; // [rsp+12h] [rbp-16h]
unsigned __int16 v17; // [rsp+16h] [rbp-12h]

v2 = 0;
if ( (_BYTE)a1 )
v2 = a2;
v3 = v2 & 1;
v4 = 0;
if ( BYTE1(a1) )
v4 = BYTE1(a2);
v5 = v4 & 1;
v6 = 0;
if ( BYTE2(a1) )
v6 = BYTE2(a2);
v7 = v6 & 1;
v8 = 0;
if ( BYTE3(a1) )
v8 = BYTE3(a2);
v9 = v8 & 1;
v10 = 0;
if ( BYTE4(a1) )
v10 = BYTE4(a2);
v11 = v10 & 1;
v12 = 0;
if ( BYTE5(a1) )
v12 = BYTE5(a2);
LOBYTE(v16) = v3;
BYTE1(v16) = v5;
BYTE2(v16) = v7;
HIBYTE(v16) = v9;
LOBYTE(v17) = v11;
HIBYTE(v17) = v12 & 1;
return v16 | ((unsigned __int64)v17 << 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_; });
}


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(__int64 a1)
{
char v1; // al

v1 = 1;
if ( !BYTE3(a1) )
v1 = BYTE5(a1);
return v1 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
char v1; // al

v1 = 1;
if ( !BYTE3(a1) )
v1 = BYTE5(a1);
return v1 & 1;
}

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:
__int64 __fastcall authby_has_digsig(__int64 a1)
{
char v1; // dl
char v2; // al

v1 = 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);
v2 = 1;
if ( !v1 )
v2 = authby_has_rsasig(((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40));
return v2 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
char v1; // dl
char v2; // al

v1 = func8(a1 & 0xFF00000000LL | (unsigned __int8)a1 | (unsigned __int64)((unsigned __int16)a1 & 0xFF00) | ((unsigned __int64)BYTE2(a1) << 16) | ((unsigned __int64)BYTE3(a1) << 24) | a1 & 0xFF0000000000LL);
v2 = 1;
if ( !v1 )
v2 = func7(((unsigned __int64)BYTE4(a1) << 32) | ((unsigned __int64)BYTE2(a1) << 16) | (unsigned __int16)a1 | ((unsigned __int64)BYTE3(a1) << 24) | ((unsigned __int64)BYTE5(a1) << 40));
return v2 & 1;
}

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


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 *

return_type: unsigned long


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

return_type: char *


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

if ( a1 > 0x395 )
{
if ( a1 > 0x1087 )
{
v2 = "VENDOR_DEFINED";
if ( a1 == 0x80000000 )
return (char *)v2;
goto LABEL_25;
}
if ( a1 <= 0x104F )
{
v2 = "CAMELLIA_CBC";
if ( a1 == 1362 )
return (char *)v2;
goto LABEL_25;
}
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_25;
}
}
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_25;
}
}
else
{
if ( a1 > 0x271 )
goto LABEL_25;
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_25;
}
}
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_25;
}
v2 = "SHA_1";
if ( a1 != 544 )
{
if ( a1 == 545 )
return "SHA_1_HMAC";
LABEL_25:
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; // rbx

if ( a1 > 0x395 )
{
if ( a1 > 0x1087 )
{
v2 = "VENDOR_DEFINED";
if ( a1 == 0x80000000 )
return (char *)v2;
goto LABEL_25;
}
if ( a1 <= 0x104F )
{
v2 = "CAMELLIA_CBC";
if ( a1 == 1362 )
return (char *)v2;
goto LABEL_25;
}
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_25;
}
}
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_25;
}
}
else
{
if ( a1 > 0x271 )
goto LABEL_25;
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_25;
}
}
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_25;
}
v2 = "SHA_1";
if ( a1 != 544 )
{
if ( a1 == 545 )
return "SHA_1_HMAC";
LABEL_25:
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]; }

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


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

v11 = __readfsqword(0x28u);
jam(a1, "%s:", *(const char **)a2);
v3 = value_of(a2);
v4 = v3;
v5 = *(_QWORD *)(a2 + 16);
if ( v5 )
{
v6 = keyword_by_value(v5, v3);
if ( v6 )
{
jam_string(a1, *(_QWORD *)(v6 + 8));
return v11 - __readfsqword(0x28u);
}
v8 = *(_QWORD *)(*(_QWORD *)(a2 + 16) + 8LL);
if ( v8 <= v4 )
{
jam(a1, "%zu", v4 - v8);
return v11 - __readfsqword(0x28u);
}
LABEL_7:
jam(a1, "?%u?", v4);
return v11 - __readfsqword(0x28u);
}
v9 = *(_QWORD *)(a2 + 24);
if ( v9 )
{
v10 = enum_name_short(v9, v3);
if ( v10 )
{
jam_string(a1, v10);
return v11 - __readfsqword(0x28u);
}
goto LABEL_7;
}
if ( *(_QWORD *)(a2 + 32) )
{
if ( v3 )
{
jam(a1, "%u", v3 - 1);
return v11 - __readfsqword(0x28u);
}
goto LABEL_14;
}
if ( !v3 )
{
LABEL_14:
jam(a1, "no");
return v11 - __readfsqword(0x28u);
}
if ( v3 == 1 )
jam(a1, "yes");
else
jam(a1, "?%u?", v3);
return v11 - __readfsqword(0x28u);
}

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

v11 = __readfsqword(0x28u);
jam(a1, "%s:", *(const char **)a2);
v3 = func3(a2);
v4 = v3;
v5 = *(_QWORD *)(a2 + 16);
if ( v5 )
{
v6 = keyword_by_value(v5, v3);
if ( v6 )
{
jam_string(a1, *(_QWORD *)(v6 + 8));
return v11 - __readfsqword(0x28u);
}
v8 = *(_QWORD *)(*(_QWORD *)(a2 + 16) + 8LL);
if ( v8 <= v4 )
{
jam(a1, "%zu", v4 - v8);
return v11 - __readfsqword(0x28u);
}
LABEL_7:
jam(a1, "?%u?", v4);
return v11 - __readfsqword(0x28u);
}
v9 = *(_QWORD *)(a2 + 24);
if ( v9 )
{
v10 = enum_name_short(v9, v3);
if ( v10 )
{
jam_string(a1, v10);
return v11 - __readfsqword(0x28u);
}
goto LABEL_7;
}
if ( *(_QWORD *)(a2 + 32) )
{
if ( v3 )
{
jam(a1, "%u", v3 - 1);
return v11 - __readfsqword(0x28u);
}
goto LABEL_14;
}
if ( !v3 )
{
LABEL_14:
jam(a1, "no");
return v11 - __readfsqword(0x28u);
}
if ( v3 == 1 )
jam(a1, "yes");
else
jam(a1, "?%u?", v3);
return v11 - __readfsqword(0x28u);
}

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 *

return_type: void

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

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 have_impairments()
{
_QWORD *v0; // rbx

v0 = &impairments[8];
do
{
if ( !*((_DWORD *)v0 + 14) && value_of((__int64)v0) )
return 1LL;
v0 += 8;
}
while ( v0 != &impairments[656] );
return 0LL;
}

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

v0 = &impairments[8];
do
{
if ( !*((_DWORD *)v0 + 14) && func3((__int64)v0) )
return 1LL;
v0 += 8;
}
while ( v0 != &impairments[656] );
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; }

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


decompiled_code:
unsigned __int64 __fastcall jam_impairments(__int64 a1, void *a2)
{
_QWORD *v2; // rbx
void *v3; // r14
unsigned __int64 v5; // [rsp+8h] [rbp-40h]

v5 = __readfsqword(0x28u);
v2 = &impairments[8];
v3 = &LC13;
do
{
if ( !*((_DWORD *)v2 + 14) && value_of((__int64)v2) )
{
jam_string(a1, v3);
jam_impairment(a1, (__int64)v2);
v3 = a2;
}
v2 += 8;
}
while ( v2 != &impairments[656] );
return v5 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, void *a2)
{
_QWORD *v2; // rbx
void *v3; // r14
unsigned __int64 v5; // [rsp+8h] [rbp-40h]

v5 = __readfsqword(0x28u);
v2 = &impairments[8];
v3 = &LC13;
do
{
if ( !*((_DWORD *)v2 + 14) && func3((__int64)v2) )
{
jam_string(a1, v3);
func4(a1, (__int64)v2);
v3 = a2;
}
v2 += 8;
}
while ( v2 != &impairments[656] );
return v5 - __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 *


decompiled_code:
__int64 __fastcall pam_conv(int a1, int **a2, _QWORD *a3, const char **a4)
{
__int64 result; // rax
char *v6; // rbx
const char *v7; // r15
size_t v8; // r13
void *v9; // r12
int v10; // eax
char *v13; // [rsp+18h] [rbp-50h]

result = 19LL;
if ( a1 > 0 )
{
v13 = (char *)malloc(16LL * a1);
v6 = v13;
while ( 1 )
{
v10 = **a2;
if ( v10 == 1 )
break;
if ( v10 == 2 )
{
v7 = *a4;
LABEL_4:
*((_DWORD *)v6 + 2) = 0;
*(_QWORD *)v6 = 0LL;
if ( v7 )
{
v8 = strlen(v7) + 1;
v9 = malloc(v8);
memcpy(v9, v7, v8);
*(_QWORD *)v6 = v9;
}
goto LABEL_6;
}
*((_DWORD *)v6 + 2) = 0;
*(_QWORD *)v6 = 0LL;
LABEL_6:
++a2;
v6 += 16;
if ( v6 == &v13[16 * a1] )
{
*a3 = v13;
return 0LL;
}
}
v7 = a4[1];
goto LABEL_4;
}
return result;
}

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 *

return_type: int

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

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

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

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 v6; // er13
__int64 v7; // rbx
const char *v8; // rsi
__int64 v9; // rbx
__int64 v10; // rbx
const char *v11; // rsi
__int64 v12; // rbx

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

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

v6 = a3;
v7 = jam_char(a1, (unsigned int)a3);
v8 = "<null>";
if ( a2 )
{
v8 = "<all>";
if ( *(_DWORD *)a2 )
v8 = *(const char **)(a2 + 24);
}
v9 = jam_string(a1, v8) + v7;
if ( a2 != a4 )
{
v10 = jam_char(a1, v6) + v9;
v11 = "<null>";
if ( a4 )
{
v11 = "<all>";
if ( *(_DWORD *)a4 )
v11 = *(const char **)(a4 + 24);
}
v9 = jam_string(a1, v11) + v10;
}
v12 = jam_char(a1, v6) + 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


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

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

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

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

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

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


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

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

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

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

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

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


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

v1 = __readfsqword(0x28u);
stop_server(server_stopped_callback);
return v1 - __readfsqword(0x28u);
}

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

v1 = __readfsqword(0x28u);
stop_server(server_stopped_callback);
return v1 - __readfsqword(0x28u);
}

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

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


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

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

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

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

variable_types: r int


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

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

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

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


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

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

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

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

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

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

variable_types:
ptr
void *

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

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


decompiled_code:
unsigned __int64 __fastcall install_allocation(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
unsigned __int64 v5; // [rsp+8h] [rbp-10h]

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

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

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

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

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

variable_types:
size
unsigned long

variable_types:
name
char *

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


zalloc

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

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

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

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

return_type: void *


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

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

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

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

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

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

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

variable_types:
val
unsigned long

variable_types:
prefix
char *


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

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

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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
const char *__fastcall str_enum(_QWORD *a1, char **a2, const char *a3)
{
const char *v4; // rbx

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

canonical_decompiled_code:
const char *__fastcall func6(_QWORD *a1, char **a2, const char *a3)
{
const char *v4; // rbx

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

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

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

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

variable_types:
p
char *


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

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

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

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

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

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


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

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

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

v6 = (_QWORD *)func10(a1, a2);
if ( v6 )
return func6(v6, a3, a4);
v7 = a4;
_snprintf_chk(a4, 23LL, 1LL, -1LL, "%lu??", a3);
return v7;
}

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

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

variable_types: struct enum_enum_names { unsigned long een_first; unsigned long een_last; struct enum_names { unsigned long en_first; unsigned long en_last; char **en_names; unsigned long en_checklen; char *en_prefix; struct enum_names *en_next_range; } **een_enum_name; unsigned long een_checklen; } *

variable_types:
table
unsigned long

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


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

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

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

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

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

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


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

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

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

v6 = (_QWORD *)func10(a2, a3);
if ( v6 )
result = func4(a1, v6, a4);
else
result = jam(a1, "%lu??%lu??", a3, a4);
return result;
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

variable_types:
tl
unsigned long

variable_types:
i
unsigned long


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

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

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

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

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

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

variable_types:
len
unsigned long

variable_types:
hash
struct hash_t

variable_types:
bytes
unsigned char *

variable_types:
j
unsigned int

return_type: struct hash_t { unsigned int hash; }


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

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

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

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

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

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

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

user_defined_types: struct list_head { struct list_entry head; }

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

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


decompiled_code:
bool __fastcall ike_spi_eq(const void *a1, const void *a2)
{
return memcmp(a1, a2, 8uLL) == 0;
}

canonical_decompiled_code:
bool __fastcall func0(const void *a1, const void *a2)
{
return memcmp(a1, a2, 8uLL) == 0;
}

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

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

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

variable_types:
rhs
struct ike_spi_t *


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

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

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

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

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


decompiled_code:
_BOOL8 __fastcall ike_spis_eq(__int64 a1, __int64 a2)
{
bool v2; // dl
bool v3; // al

v2 = ike_spi_eq((const void *)a1, (const void *)a2);
v3 = 0;
if ( v2 )
v3 = ike_spi_eq((const void *)(a1 + 8), (const void *)(a2 + 8));
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2)
{
bool v2; // dl
bool v3; // al

v2 = func0((const void *)a1, (const void *)a2);
v3 = 0;
if ( v2 )
v3 = func0((const void *)(a1 + 8), (const void *)(a2 + 8));
return v3;
}

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

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

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

variable_types:
rhs
struct ike_spis_t *

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


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

v1 = __readfsqword(0x28u);
get_rnd_bytes(&ike_spi_secret, 32LL);
return v1 - __readfsqword(0x28u);
}

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

v1 = __readfsqword(0x28u);
get_rnd_bytes(&ike_spi_secret, 32LL);
return v1 - __readfsqword(0x28u);
}

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

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


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

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

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

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

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

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

variable_types:
v
unsigned long

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

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


decompiled_code:
unsigned __int64 __fastcall double_delay(__m128i *a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__m128i v7; // [rsp+0h] [rbp-28h] BYREF
__int64 v8; // [rsp+10h] [rbp-18h]
unsigned __int64 v9; // [rsp+18h] [rbp-10h]

v9 = __readfsqword(0x28u);
if ( a2 )
{
deltatime_add(&v7);
if ( (int)deltatime_sub_sign(&v7, a2, v3, v4, v5, v6) < 0 )
{
*a1 = _mm_loadu_si128(&v7);
a1[1].m128i_i64[0] = v8;
}
}
return v9 - __readfsqword(0x28u);
}

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

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

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

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

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


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

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

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

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

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

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

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

variable_types:
num
unsigned long

variable_types:
suffix
char *


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

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

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

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

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

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

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

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