decompiled_code:
__int64 __fastcall x509_parse_pubkey(__int64 a1, __int64 a2, _DWORD *a3, _BYTE *a4)
{
__int64 result; // rax
_DWORD *v7; // rbx
_BYTE v8[120]; // [rsp-70h] [rbp-78h] BYREF

*(_QWORD *)(a2 + 32) = 0LL;
*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
*a3 = 0;
*a4 = 0;
result = ((__int64 (*)(void))asn1_push_seq)();
if ( !(_DWORD)result )
{
result = asn1_push_seq(a1);
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( !(unsigned __int8)asn1_is_oid(a1 + 120) )
return 13LL;
asn1_oid(a1 + 120, v8);
v7 = find_pubkey_algorithm((__int64)v8);
result = 12LL;
if ( v7 )
{
*(_DWORD *)a2 = v7[14];
result = (*((__int64 (__fastcall **)(__int64, _DWORD *, _BYTE *))v7 + 8))(a1, a3, a4);
if ( !(_DWORD)result )
{
result = asn1_pop(a1);
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_bitstring(a1 + 120) )
{
if ( *((_BYTE *)v7 + 80) )
{
result = (*((__int64 (__fastcall **)(__int64, __int64))v7 + 9))(a1, a2);
if ( !(_DWORD)result )
return asn1_pop(a1);
}
else
{
result = asn1_force_push(a1);
if ( !(_DWORD)result )
{
result = (*((__int64 (__fastcall **)(__int64, __int64))v7 + 9))(a1, a2);
if ( !(_DWORD)result )
{
result = asn1_pop(a1);
if ( !(_DWORD)result )
return asn1_pop(a1);
}
}
}
}
else
{
result = 13LL;
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, _DWORD *a3, _BYTE *a4)
{
__int64 result; // rax
_DWORD *v7; // rbx
_BYTE v8[120]; // [rsp-70h] [rbp-78h] BYREF

*(_QWORD *)(a2 + 32) = 0LL;
*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
*a3 = 0;
*a4 = 0;
result = ((__int64 (*)(void))asn1_push_seq)();
if ( !(_DWORD)result )
{
result = asn1_push_seq(a1);
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( !(unsigned __int8)asn1_is_oid(a1 + 120) )
return 13LL;
asn1_oid(a1 + 120, v8);
v7 = func1((__int64)v8);
result = 12LL;
if ( v7 )
{
*(_DWORD *)a2 = v7[14];
result = (*((__int64 (__fastcall **)(__int64, _DWORD *, _BYTE *))v7 + 8))(a1, a3, a4);
if ( !(_DWORD)result )
{
result = asn1_pop(a1);
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_bitstring(a1 + 120) )
{
if ( *((_BYTE *)v7 + 80) )
{
result = (*((__int64 (__fastcall **)(__int64, __int64))v7 + 9))(a1, a2);
if ( !(_DWORD)result )
return asn1_pop(a1);
}
else
{
result = asn1_force_push(a1);
if ( !(_DWORD)result )
{
result = (*((__int64 (__fastcall **)(__int64, __int64))v7 + 9))(a1, a2);
if ( !(_DWORD)result )
{
result = asn1_pop(a1);
if ( !(_DWORD)result )
return asn1_pop(a1);
}
}
}
}
else
{
result = 13LL;
}
}
}
}
}
}
}
}
return result;
}

original_code:
asinine_err_t
x509_parse_pubkey(asn1_parser_t *parser, x509_pubkey_t *pubkey,
    x509_pubkey_params_t *params, _Bool *has_params) {
 *pubkey = (x509_pubkey_t){0};
 *params = (x509_pubkey_params_t){0};
 *has_params = 0;
 do { asinine_err_t ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { asinine_err_t ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_oid(&parser->token)) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "pubkey: token isn't an OID" };
 }
 asn1_oid_t oid;
 asn1_oid(&parser->token, &oid);
 const pubkey_lookup_t *result = find_pubkey_algorithm(&oid);
 if (result == ((void *)0)) {
  return (asinine_err_t) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "pubkey: algorithm unknown" };
 }
 pubkey->algorithm = result->algorithm;
 do { asinine_err_t ret___LINE__ = result->param_parser(parser, params, has_params); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { asinine_err_t ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_bitstring(&parser->token)) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "pubkey: token isn't a bitstring" };
 }
 if (result->broken_encoding) {
  do { asinine_err_t ret___LINE__ = result->pubkey_parser(parser, pubkey); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 } else {
  do { asinine_err_t ret___LINE__ = asn1_force_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { asinine_err_t ret___LINE__ = result->pubkey_parser(parser, pubkey); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { asinine_err_t ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 }
 return asn1_pop(parser);
}

canonical_original_code:
struct asinine_err x509_parse_pubkey(struct asn1_parser *parser, struct x509_pubkey *pubkey, union x509_pubkey_params *params, _Bool *has_params) {
 *pubkey = (struct x509_pubkey){0};
 *params = (union x509_pubkey_params){0};
 *has_params = 0;
 do { struct asinine_err ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { struct asinine_err ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_oid(&parser->token)) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "pubkey: token isn't an OID" };
 }
 struct asn1_oid oid;
 asn1_oid(&parser->token, &oid);
 struct pubkey_lookup_t *result = find_pubkey_algorithm(&oid);
 if (result == ((void *)0)) {
  return (struct asinine_err) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "pubkey: algorithm unknown" };
 }
 pubkey->algorithm = result->algorithm;
 do { struct asinine_err ret___LINE__ = result->param_parser(parser, params, has_params); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { struct asinine_err ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_bitstring(&parser->token)) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "pubkey: token isn't a bitstring" };
 }
 if (result->broken_encoding) {
  do { struct asinine_err ret___LINE__ = result->pubkey_parser(parser, pubkey); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 } else {
  do { struct asinine_err ret___LINE__ = asn1_force_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { struct asinine_err ret___LINE__ = result->pubkey_parser(parser, pubkey); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { struct asinine_err ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 }
 return asn1_pop(parser);
}

variable_types: struct pubkey_lookup_t { struct asn1_oid { unsigned int arcs[-1]; unsigned long num; } oid; enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 } algorithm; struct asinine_err { enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 } errno; char *reason; } (*param_parser)(struct asn1_parser { unsigned char *current; void *end; void *stack[-1]; unsigned char depth; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } token; } *, union x509_pubkey_params { enum x509_ecdsa_curve { X509_ECDSA_CURVE_INVALID=0, X509_ECDSA_CURVE_SECP256R1=1, X509_ECDSA_CURVE_SECP384R1=2, X509_ECDSA_CURVE_SECP521R1=3 } ecdsa_curve; } *, _Bool *); struct asinine_err (*pubkey_parser)(struct asn1_parser *, struct x509_pubkey { enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 } algorithm; union { struct x509_pubkey_rsa { unsigned char *n; unsigned long n_num; unsigned char *e; unsigned long e_num; } rsa; struct x509_pubkey_ecdsa { unsigned char *point; unsigned long point_num; } ecdsa; } key; } *); _Bool broken_encoding; } *

user_defined_types: struct pubkey_lookup_t { struct asn1_oid oid; enum x509_pubkey_algo algorithm; struct asinine_err (*param_parser)(struct asn1_parser *, union x509_pubkey_params *, _Bool *); struct asinine_err (*pubkey_parser)(struct asn1_parser *, struct x509_pubkey *); _Bool broken_encoding; }


repo: lmb/asinine

original_code:
void
x509_sort_name(x509_name_t *name) {
 for (size_t i = 1; i < name->num; i++) {
  x509_rdn_t temp = name->rdns[i];
  size_t j = i;
  while (j > 0 && name->rdns[j - 1].type > temp.type) {
   name->rdns[j] = name->rdns[j - 1];
   j--;
  }
  name->rdns[j] = temp;
 }
}

canonical_original_code:
void x509_sort_name(struct x509_name *name) {
 for (unsigned long i = 1; i < name->num; i++) {
  struct x509_rdn temp = name->rdns[i];
  unsigned long j = i;
  while (j > 0 && name->rdns[j - 1].type > temp.type) {
   name->rdns[j] = name->rdns[j - 1];
   j--;
  }
  name->rdns[j] = temp;
 }
}

variable_types: struct x509_name { unsigned long num; struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } value; } rdns[-1]; } *

variable_types:
i
unsigned long

variable_types:
j
unsigned long

return_type: void

user_defined_types: struct x509_rdn { enum x509_rdn_type type; struct asn1_token value; }

user_defined_types: struct x509_name { unsigned long num; struct x509_rdn rdns[-1]; }

user_defined_types: struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type type; }

user_defined_types: struct asn1_type { enum asn1_tag tag; enum asn1_class class; enum asn1_encoding encoding; }


decompiled_code:
__int64 __fastcall x509_parse_optional_name(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int32 v3; // er13
__int64 v4; // rax
__m128i *v5; // rdx
_BYTE v6[104]; // [rsp+0h] [rbp-68h] BYREF

memset(a2, 0, 0x210uLL);
result = asn1_push_seq(a1);
if ( !(_DWORD)result )
{
while ( !(unsigned __int8)asn1_eof(a1) && (unsigned __int64)*a2 <= 0xC )
{
result = asn1_next(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_is_set(a1 + 120) )
return 13LL;
result = asn1_push(a1);
if ( (_DWORD)result )
return result;
result = asn1_push_seq(a1);
if ( (_DWORD)result )
return result;
result = asn1_next(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_is_oid(a1 + 120) )
return 13LL;
result = asn1_oid(a1 + 120, v6);
if ( (_DWORD)result )
return result;
v3 = find_rdn_type((__int64)v6);
if ( !v3 )
return 12LL;
result = asn1_next(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_is_string(a1 + 120) )
return 13LL;
v4 = *a2 + 1;
v5 = (__m128i *)&a2[5 * *a2];
v5->m128i_i32[2] = v3;
v5[1] = _mm_loadu_si128((const __m128i *)(a1 + 120));
v5[2] = _mm_loadu_si128((const __m128i *)(a1 + 136));
*a2 = v4;
result = asn1_pop(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_eof(a1) )
return 12LL;
result = asn1_pop(a1);
if ( (_DWORD)result )
return result;
}
if ( (unsigned __int8)asn1_eof(a1) )
{
x509_sort_name((unsigned __int64 *)a2);
result = asn1_pop(a1);
}
else
{
result = 11LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2)
{
__int64 result; // rax
__int32 v3; // er13
__int64 v4; // rax
__m128i *v5; // rdx
_BYTE v6[104]; // [rsp+0h] [rbp-68h] BYREF

memset(a2, 0, 0x210uLL);
result = asn1_push_seq(a1);
if ( !(_DWORD)result )
{
while ( !(unsigned __int8)asn1_eof(a1) && (unsigned __int64)*a2 <= 0xC )
{
result = asn1_next(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_is_set(a1 + 120) )
return 13LL;
result = asn1_push(a1);
if ( (_DWORD)result )
return result;
result = asn1_push_seq(a1);
if ( (_DWORD)result )
return result;
result = asn1_next(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_is_oid(a1 + 120) )
return 13LL;
result = asn1_oid(a1 + 120, v6);
if ( (_DWORD)result )
return result;
v3 = func1((__int64)v6);
if ( !v3 )
return 12LL;
result = asn1_next(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_is_string(a1 + 120) )
return 13LL;
v4 = *a2 + 1;
v5 = (__m128i *)&a2[5 * *a2];
v5->m128i_i32[2] = v3;
v5[1] = _mm_loadu_si128((const __m128i *)(a1 + 120));
v5[2] = _mm_loadu_si128((const __m128i *)(a1 + 136));
*a2 = v4;
result = asn1_pop(a1);
if ( (_DWORD)result )
return result;
if ( !(unsigned __int8)asn1_eof(a1) )
return 12LL;
result = asn1_pop(a1);
if ( (_DWORD)result )
return result;
}
if ( (unsigned __int8)asn1_eof(a1) )
{
func2((unsigned __int64 *)a2);
result = asn1_pop(a1);
}
else
{
result = 11LL;
}
}
return result;
}

original_code:
asinine_err_t
x509_parse_optional_name(asn1_parser_t *parser, x509_name_t *name) {
 const asn1_token_t *token = &parser->token;
 *name = (x509_name_t){0};
 do { asinine_err_t ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 while (!asn1_eof(parser) && name->num < (13)) {
  do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_is_set(token)) {
   return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  do { asinine_err_t ret___LINE__ = asn1_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { asinine_err_t ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_is_oid(token)) {
   return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  asn1_oid_t oid;
  do { asinine_err_t ret___LINE__ = asn1_oid(token, &oid); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  x509_rdn_type_t type = find_rdn_type(&oid);
  if (type == X509_RDN_INVALID) {
   return (asinine_err_t) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "name: unknown RDN" };
  }
  do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_is_string(token)) {
   return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  name->rdns[name->num].type = type;
  name->rdns[name->num].value = *token;
  name->num++;
  do { asinine_err_t ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_eof(parser)) {
   return (asinine_err_t) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "name: multiple AVA" };
  }
  do { asinine_err_t ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 }
 if (!asn1_eof(parser)) {
  return (asinine_err_t) { .errno = ASININE_ERR_MEMORY, .reason = "name: too many RDNs" };
 }
 x509_sort_name(name);
 return asn1_pop(parser);
}

canonical_original_code:
struct asinine_err x509_parse_optional_name(struct asn1_parser *parser, struct x509_name *name) {
 struct asn1_token *token = &parser->token;
 *name = (struct x509_name){0};
 do { struct asinine_err ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 while (!asn1_eof(parser) && name->num < (13)) {
  do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_is_set(token)) {
   return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  do { struct asinine_err ret___LINE__ = asn1_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { struct asinine_err ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_is_oid(token)) {
   return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  struct asn1_oid oid;
  do { struct asinine_err ret___LINE__ = asn1_oid(token, &oid); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  enum x509_rdn_type type = find_rdn_type(&oid);
  if (type == X509_RDN_INVALID) {
   return (struct asinine_err) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "name: unknown RDN" };
  }
  do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_is_string(token)) {
   return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  name->rdns[name->num].type = type;
  name->rdns[name->num].value = *token;
  name->num++;
  do { struct asinine_err ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  if (!asn1_eof(parser)) {
   return (struct asinine_err) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "name: multiple AVA" };
  }
  do { struct asinine_err ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 }
 if (!asn1_eof(parser)) {
  return (struct asinine_err) { .errno = ASININE_ERR_MEMORY, .reason = "name: too many RDNs" };
 }
 x509_sort_name(name);
 return asn1_pop(parser);
}

variable_types: struct asn1_parser { unsigned char *current; void *end; void *stack[-1]; unsigned char depth; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } token; } *

variable_types: struct x509_name { unsigned long num; struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token value; } rdns[-1]; } *

variable_types: struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } *

variable_types: struct asinine_err { enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 } errno; char *reason; }

variable_types: struct asn1_oid { unsigned int arcs[-1]; unsigned long num; }

user_defined_types: struct asinine_err { enum asinine_errno errno; char *reason; }

user_defined_types: struct asn1_parser { unsigned char *current; void *end; void *stack[-1]; unsigned char depth; struct asn1_token token; }


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

result = x509_parse_optional_name(a1, a2);
if ( !(_DWORD)result )
result = *a2 == 0 ? 0xD : 0;
return result;
}

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

result = func3(a1, a2);
if ( !(_DWORD)result )
result = *a2 == 0 ? 0xD : 0;
return result;
}

original_code:
asinine_err_t
x509_parse_name(asn1_parser_t *parser, x509_name_t *name) {
 do { asinine_err_t ret___LINE__ = x509_parse_optional_name(parser, name); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (name->num == 0) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "name: empty" };
 }
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err x509_parse_name(struct asn1_parser *parser, struct x509_name *name) {
 do { struct asinine_err ret___LINE__ = x509_parse_optional_name(parser, name); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (name->num == 0) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "name: empty" };
 }
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

return_type: struct asinine_err { enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 } errno; char *reason; }

user_defined_types: enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 }

user_defined_types: enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 }

user_defined_types: enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 }

user_defined_types: enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 }


decompiled_code:
void __fastcall x509_name_eq(__int64 *a1, _QWORD *a2, _QWORD *a3)
{
__int64 v4; // r12
_QWORD *v5; // rbp
_QWORD *v6; // rbx
__int64 v7; // r14
size_t v8; // rdx

v4 = *a1;
if ( *a1 == *a2 )
{
v5 = a1 + 1;
v6 = a2 + 1;
v7 = 0LL;
if ( v4 )
{
while ( 1 )
{
if ( *(_DWORD *)v5 != *(_DWORD *)v6 )
{
set_reason(a3, (__int64)"attribute type mismatch");
return;
}
v8 = v5[3];
if ( v8 != v6[3] )
{
set_reason(a3, (__int64)"value length mismatch");
return;
}
if ( memcmp((const void *)v5[2], (const void *)v6[2], v8) )
break;
++v7;
v5 += 5;
v6 += 5;
if ( v4 == v7 )
goto LABEL_10;
}
set_reason(a3, (__int64)"value mismatch");
}
else
{
LABEL_10:
set_reason(a3, 0LL);
}
}
else
{
set_reason(a3, (__int64)"differing number of RDNs");
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 *a1, _QWORD *a2, _QWORD *a3)
{
__int64 v4; // r12
_QWORD *v5; // rbp
_QWORD *v6; // rbx
__int64 v7; // r14
size_t v8; // rdx

v4 = *a1;
if ( *a1 == *a2 )
{
v5 = a1 + 1;
v6 = a2 + 1;
v7 = 0LL;
if ( v4 )
{
while ( 1 )
{
if ( *(_DWORD *)v5 != *(_DWORD *)v6 )
{
func0(a3, (__int64)"attribute type mismatch");
return;
}
v8 = v5[3];
if ( v8 != v6[3] )
{
func0(a3, (__int64)"value length mismatch");
return;
}
if ( memcmp((const void *)v5[2], (const void *)v6[2], v8) )
break;
++v7;
v5 += 5;
v6 += 5;
if ( v4 == v7 )
goto LABEL_10;
}
func0(a3, (__int64)"value mismatch");
}
else
{
LABEL_10:
func0(a3, 0LL);
}
}
else
{
func0(a3, (__int64)"differing number of RDNs");
}
}

original_code:
_Bool
x509_name_eq(const x509_name_t *a, const x509_name_t *b, const char **reason) {
 if (a->num != b->num) {
  set_reason(reason, "differing number of RDNs");
  return 0;
 }
 for (size_t i = 0; i < a->num; i++) {
  const x509_rdn_t *a_rdn = &a->rdns[i];
  const x509_rdn_t *b_rdn = &b->rdns[i];
  if (a_rdn->type != b_rdn->type) {
   set_reason(reason, "attribute type mismatch");
   return 0;
  }
  if (a_rdn->value.length != b_rdn->value.length) {
   set_reason(reason, "value length mismatch");
   return 0;
  }
  if (memcmp(a_rdn->value.data, b_rdn->value.data, a_rdn->value.length) !=
      0) {
   set_reason(reason, "value mismatch");
   return 0;
  }
 }
 set_reason(reason, ((void *)0));
 return 1;
}

canonical_original_code:
_Bool x509_name_eq(struct x509_name *a, struct x509_name *b, char **reason) {
 if (a->num != b->num) {
  set_reason(reason, "differing number of RDNs");
  return 0;
 }
 for (unsigned long i = 0; i < a->num; i++) {
  struct x509_rdn *a_rdn = &a->rdns[i];
  struct x509_rdn *b_rdn = &b->rdns[i];
  if (a_rdn->type != b_rdn->type) {
   set_reason(reason, "attribute type mismatch");
   return 0;
  }
  if (a_rdn->value.length != b_rdn->value.length) {
   set_reason(reason, "value length mismatch");
   return 0;
  }
  if (memcmp(a_rdn->value.data, b_rdn->value.data, a_rdn->value.length) !=
      0) {
   set_reason(reason, "value mismatch");
   return 0;
  }
 }
 set_reason(reason, ((void *)0));
 return 1;
}

variable_types:
b
struct x509_name *

variable_types:
reason
char **

variable_types: struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } value; } *


decompiled_code:
__int64 __fastcall x509_parse_alt_names(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rbp
__int64 result; // rax
unsigned int v4; // edx
unsigned int v5; // eax
int v6; // edx
__int64 v7; // rcx
__int64 v8; // rax
unsigned __int64 *v9; // rax
__int64 v10; // rcx

v2 = 0LL;
memset(a2, 0, 0xE20uLL);
result = asn1_push_seq(a1);
if ( !(_DWORD)result )
{
while ( 2 )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
v4 = *(_DWORD *)(a1 + 144);
v5 = HIBYTE(v4);
v6 = v4 & 0xFFFFFF;
if ( (HIBYTE(*(_DWORD *)(a1 + 144)) & 3) == 2 )
{
switch ( (char)v6 )
{
case 0:
case 3:
case 5:
case 8:
result = 12LL;
break;
case 1:
if ( *(_QWORD *)(a1 + 136) )
goto LABEL_11;
result = 13LL;
break;
case 2:
v10 = *(_QWORD *)(a1 + 136);
if ( v10 && (v10 != 1 || **(_BYTE **)(a1 + 128) != 32) )
goto LABEL_11;
result = 13LL;
break;
case 4:
if ( (v5 & 4) == 0 )
goto LABEL_30;
if ( a2[385] == -1LL || a2[385] == 0 )
{
result = asn1_push(a1);
if ( !(_DWORD)result )
{
result = x509_parse_name(a1, (__int64 *)&a2[66 * a2[385] + 386]);
if ( !(_DWORD)result )
{
++a2[385];
result = asn1_pop(a1);
if ( !(_DWORD)result )
{
if ( !(unsigned __int8)asn1_eof(a1) )
continue;
goto LABEL_14;
}
}
}
}
else
{
result = 11LL;
}
break;
case 6:
if ( *(_QWORD *)(a1 + 136) )
goto LABEL_11;
result = 13LL;
break;
case 7:
v7 = *(_QWORD *)(a1 + 136);
if ( v7 == 4 || v7 == 16 )
{
LABEL_11:
if ( (v5 & 4) != 0 )
goto LABEL_30;
v8 = 3 * v2++;
v9 = &a2[v8];
*((_DWORD *)v9 + 2) = v6;
v9[3] = *(_QWORD *)(a1 + 128);
v9[2] = *(_QWORD *)(a1 + 136);
*a2 = v2;
if ( (unsigned __int8)asn1_eof(a1) != 1 && v2 <= 0x7F )
continue;
LABEL_14:
if ( (unsigned __int8)asn1_eof(a1) )
result = asn1_pop(a1);
else
result = 11LL;
}
else
{
result = 13LL;
}
break;
default:
result = 13LL;
break;
}
}
else
{
LABEL_30:
result = 13LL;
}
}
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rbp
__int64 result; // rax
unsigned int v4; // edx
unsigned int v5; // eax
int v6; // edx
__int64 v7; // rcx
__int64 v8; // rax
unsigned __int64 *v9; // rax
__int64 v10; // rcx

v2 = 0LL;
memset(a2, 0, 0xE20uLL);
result = asn1_push_seq(a1);
if ( !(_DWORD)result )
{
while ( 2 )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
v4 = *(_DWORD *)(a1 + 144);
v5 = HIBYTE(v4);
v6 = v4 & 0xFFFFFF;
if ( (HIBYTE(*(_DWORD *)(a1 + 144)) & 3) == 2 )
{
switch ( (char)v6 )
{
case 0:
case 3:
case 5:
case 8:
result = 12LL;
break;
case 1:
if ( *(_QWORD *)(a1 + 136) )
goto LABEL_11;
result = 13LL;
break;
case 2:
v10 = *(_QWORD *)(a1 + 136);
if ( v10 && (v10 != 1 || **(_BYTE **)(a1 + 128) != 32) )
goto LABEL_11;
result = 13LL;
break;
case 4:
if ( (v5 & 4) == 0 )
goto LABEL_30;
if ( a2[385] == -1LL || a2[385] == 0 )
{
result = asn1_push(a1);
if ( !(_DWORD)result )
{
result = func4(a1, (__int64 *)&a2[66 * a2[385] + 386]);
if ( !(_DWORD)result )
{
++a2[385];
result = asn1_pop(a1);
if ( !(_DWORD)result )
{
if ( !(unsigned __int8)asn1_eof(a1) )
continue;
goto LABEL_14;
}
}
}
}
else
{
result = 11LL;
}
break;
case 6:
if ( *(_QWORD *)(a1 + 136) )
goto LABEL_11;
result = 13LL;
break;
case 7:
v7 = *(_QWORD *)(a1 + 136);
if ( v7 == 4 || v7 == 16 )
{
LABEL_11:
if ( (v5 & 4) != 0 )
goto LABEL_30;
v8 = 3 * v2++;
v9 = &a2[v8];
*((_DWORD *)v9 + 2) = v6;
v9[3] = *(_QWORD *)(a1 + 128);
v9[2] = *(_QWORD *)(a1 + 136);
*a2 = v2;
if ( (unsigned __int8)asn1_eof(a1) != 1 && v2 <= 0x7F )
continue;
LABEL_14:
if ( (unsigned __int8)asn1_eof(a1) )
result = asn1_pop(a1);
else
result = 11LL;
}
else
{
result = 13LL;
}
break;
default:
result = 13LL;
break;
}
}
else
{
LABEL_30:
result = 13LL;
}
}
break;
}
}
return result;
}

original_code:
asinine_err_t
x509_parse_alt_names(asn1_parser_t *parser, x509_alt_names_t *alt_names) {
 const asn1_token_t *token = &parser->token;
 *alt_names = (x509_alt_names_t){0};
 do { asinine_err_t ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 size_t i = 0;
 do {
  do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  asn1_type_t type = token->type;
  if (type.class != ASN1_CLASS_CONTEXT) {
   return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  switch ((uint8_t)type.tag) {
  case X509_ALT_NAME_RFC822NAME:
   if (token->length == 0) {
    return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty RFC822Name" };
   }
   break;
  case X509_ALT_NAME_DNSNAME:
   if (token->length == 0) {
    return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty DNSName" };
   }
   if (token->length == 1 && token->data[0] == ' ') {
    return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty DNSName" };
   }
   break;
  case X509_ALT_NAME_URI:
   if (token->length == 0) {
    return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty URI" };
   }
   break;
  case X509_ALT_NAME_IP:
   if (token->length != 4 && token->length != 16) {
    return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "SAN: invalid IP" };
   }
   break;
  case X509_ALT_NAME_DIRECTORY:
   if (type.encoding != ASN1_ENCODING_CONSTRUCTED) {
    return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
   }
   if (alt_names->directory_num + 1 > (sizeof alt_names->directory / sizeof(alt_names->directory)[0])) {
    return (asinine_err_t) { .errno = ASININE_ERR_MEMORY, .reason = "SAN: too many directoryNames" };
   }
   do { asinine_err_t ret___LINE__ = asn1_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   do { asinine_err_t ret___LINE__ = x509_parse_name( parser, &alt_names->directory[alt_names->directory_num]); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   alt_names->directory_num++;
   do { asinine_err_t ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   continue;
  case 0:
  case 3:
  case 5:
  case 8:
   return (asinine_err_t) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "name: unknown SAN" };
  default:
   return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "name: unknown SAN" };
  }
  if (type.encoding != ASN1_ENCODING_PRIMITIVE) {
   return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  alt_names->names[i].type = (x509_alt_name_type_t)type.tag;
  alt_names->names[i].data = token->data;
  alt_names->names[i].length = token->length;
  alt_names->num = ++i;
 } while (!asn1_eof(parser) && i < (128));
 if (!asn1_eof(parser)) {
  return (asinine_err_t) { .errno = ASININE_ERR_MEMORY, .reason = "name: too many SANs" };
 }
 return asn1_pop(parser);
}

canonical_original_code:
struct asinine_err x509_parse_alt_names(struct asn1_parser *parser, struct x509_alt_names *alt_names) {
 struct asn1_token *token = &parser->token;
 *alt_names = (struct x509_alt_names){0};
 do { struct asinine_err ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 unsigned long i = 0;
 do {
  do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  struct asn1_type type = token->type;
  if (type.class != ASN1_CLASS_CONTEXT) {
   return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  switch ((unsigned char)type.tag) {
  case X509_ALT_NAME_RFC822NAME:
   if (token->length == 0) {
    return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty RFC822Name" };
   }
   break;
  case X509_ALT_NAME_DNSNAME:
   if (token->length == 0) {
    return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty DNSName" };
   }
   if (token->length == 1 && token->data[0] == ' ') {
    return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty DNSName" };
   }
   break;
  case X509_ALT_NAME_URI:
   if (token->length == 0) {
    return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "SAN: empty URI" };
   }
   break;
  case X509_ALT_NAME_IP:
   if (token->length != 4 && token->length != 16) {
    return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "SAN: invalid IP" };
   }
   break;
  case X509_ALT_NAME_DIRECTORY:
   if (type.encoding != ASN1_ENCODING_CONSTRUCTED) {
    return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
   }
   if (alt_names->directory_num + 1 > (sizeof alt_names->directory / sizeof(alt_names->directory)[0])) {
    return (struct asinine_err) { .errno = ASININE_ERR_MEMORY, .reason = "SAN: too many directoryNames" };
   }
   do { struct asinine_err ret___LINE__ = asn1_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   do { struct asinine_err ret___LINE__ = x509_parse_name( parser, &alt_names->directory[alt_names->directory_num]); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   alt_names->directory_num++;
   do { struct asinine_err ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   continue;
  case 0:
  case 3:
  case 5:
  case 8:
   return (struct asinine_err) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "name: unknown SAN" };
  default:
   return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "name: unknown SAN" };
  }
  if (type.encoding != ASN1_ENCODING_PRIMITIVE) {
   return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = ((void *)0) };
  }
  alt_names->names[i].type = (enum x509_alt_name_type)type.tag;
  alt_names->names[i].data = token->data;
  alt_names->names[i].length = token->length;
  alt_names->num = ++i;
 } while (!asn1_eof(parser) && i < (128));
 if (!asn1_eof(parser)) {
  return (struct asinine_err) { .errno = ASININE_ERR_MEMORY, .reason = "name: too many SANs" };
 }
 return asn1_pop(parser);
}

variable_types: struct x509_alt_names { unsigned long num; struct x509_alt_name_t { enum x509_alt_name_type { X509_ALT_NAME_RFC822NAME=1, X509_ALT_NAME_DNSNAME=2, X509_ALT_NAME_DIRECTORY=4, X509_ALT_NAME_URI=6, X509_ALT_NAME_IP=7 } type; unsigned long length; unsigned char *data; } names[-1]; unsigned long directory_num; struct x509_name { unsigned long num; struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token value; } rdns[-1]; } directory[-1]; } *

variable_types: struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; }

user_defined_types: struct x509_alt_names { unsigned long num; struct x509_alt_name_t names[-1]; unsigned long directory_num; struct x509_name directory[-1]; }

user_defined_types: enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 }

user_defined_types: struct x509_alt_name_t { enum x509_alt_name_type type; unsigned long length; unsigned char *data; }


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

result = "(INVALID)";
if ( a1 <= 0x13 )
result = CSWTCH_25[a1];
return result;
}

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

result = "(INVALID)";
if ( a1 <= 0x13 )
result = CSWTCH_25[a1];
return result;
}

original_code:
const char *
x509_rdn_type_string(x509_rdn_type_t type) {
 switch (type) {
 case X509_RDN_INVALID:
  return "INVALID";
 case X509_RDN_COUNTRY:
  return "Country";
 case X509_RDN_STATE_OR_PROVINCE:
  return "State or Province";
 case X509_RDN_LOCALITY:
  return "Locality";
 case X509_RDN_ORGANIZATION:
  return "Organization";
 case X509_RDN_ORGANIZATIONAL_UNIT:
  return "Organizational Unit";
 case X509_RDN_ORGANIZATIONAL_ID:
  return "Organizational ID";
 case X509_RDN_DISTINGUISHED_NAME:
  return "Distinguished Name";
 case X509_RDN_DISTINGUISHED_NAME_QUALIFIER:
  return "Distinguished Name Qualifier";
 case X509_RDN_COMMON_NAME:
  return "Common Name";
 case X509_RDN_SERIAL_NUMBER:
  return "Serial Number";
 case X509_RDN_EMAIL:
  return "E-Mail";
 case X509_RDN_BUSINESS_CATEGORY:
  return "Business category";
 case X509_RDN_JURISDICTION_COUNTRY:
  return "Jurisdiction (Country)";
 case X509_RDN_JURISDICTION_STATE_OR_PROVINCE:
  return "Jurisdiction (State or Province)";
 case X509_RDN_JURISDICTION_LOCALITY:
  return "Jurisdiction (Locality)";
 case X509_RDN_POSTAL_CODE:
  return "Postal code";
 case X509_RDN_PO_BOX:
  return "PO Box";
 case X509_RDN_STREET_ADDRESS:
  return "Street address";
 case X509_RDN_SURNAME:
  return "Surname";
 }
 return "(INVALID)";
}

canonical_original_code:
char *x509_rdn_type_string(enum x509_rdn_type type) {
 switch (type) {
 case X509_RDN_INVALID:
  return "INVALID";
 case X509_RDN_COUNTRY:
  return "Country";
 case X509_RDN_STATE_OR_PROVINCE:
  return "State or Province";
 case X509_RDN_LOCALITY:
  return "Locality";
 case X509_RDN_ORGANIZATION:
  return "Organization";
 case X509_RDN_ORGANIZATIONAL_UNIT:
  return "Organizational Unit";
 case X509_RDN_ORGANIZATIONAL_ID:
  return "Organizational ID";
 case X509_RDN_DISTINGUISHED_NAME:
  return "Distinguished Name";
 case X509_RDN_DISTINGUISHED_NAME_QUALIFIER:
  return "Distinguished Name Qualifier";
 case X509_RDN_COMMON_NAME:
  return "Common Name";
 case X509_RDN_SERIAL_NUMBER:
  return "Serial Number";
 case X509_RDN_EMAIL:
  return "E-Mail";
 case X509_RDN_BUSINESS_CATEGORY:
  return "Business category";
 case X509_RDN_JURISDICTION_COUNTRY:
  return "Jurisdiction (Country)";
 case X509_RDN_JURISDICTION_STATE_OR_PROVINCE:
  return "Jurisdiction (State or Province)";
 case X509_RDN_JURISDICTION_LOCALITY:
  return "Jurisdiction (Locality)";
 case X509_RDN_POSTAL_CODE:
  return "Postal code";
 case X509_RDN_PO_BOX:
  return "PO Box";
 case X509_RDN_STREET_ADDRESS:
  return "Street address";
 case X509_RDN_SURNAME:
  return "Surname";
 }
 return "(INVALID)";
}

variable_types: enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 }

return_type: char *


decompiled_code:
bool __fastcall signature_is_compatible(int a1, int a2)
{
if ( a2 == 1 )
return (unsigned int)(a1 - 1) <= 5;
if ( a2 == 2 )
return (unsigned int)(a1 - 7) <= 2;
return 0;
}

canonical_decompiled_code:
bool __fastcall func0(int a1, int a2)
{
if ( a2 == 1 )
return (unsigned int)(a1 - 1) <= 5;
if ( a2 == 2 )
return (unsigned int)(a1 - 7) <= 2;
return 0;
}

original_code:
static _Bool
signature_is_compatible(
    x509_sig_algo_t sig_algo, x509_pubkey_algo_t pubkey_algo) {
 switch (pubkey_algo) {
 case X509_PUBKEY_RSA:
  switch (sig_algo) {
  case X509_SIGNATURE_MD2_RSA:
  case X509_SIGNATURE_MD5_RSA:
  case X509_SIGNATURE_SHA1_RSA:
  case X509_SIGNATURE_SHA256_RSA:
  case X509_SIGNATURE_SHA384_RSA:
  case X509_SIGNATURE_SHA512_RSA:
   return 1;
  default:
   return 0;
  }
 case X509_PUBKEY_ECDSA:
  switch (sig_algo) {
  case X509_SIGNATURE_SHA256_ECDSA:
  case X509_SIGNATURE_SHA384_ECDSA:
  case X509_SIGNATURE_SHA512_ECDSA:
   return 1;
  default:
   return 0;
  }
 default:
  return 0;
 }
}

canonical_original_code:
static _Bool signature_is_compatible(enum x509_sig_algo sig_algo, enum x509_pubkey_algo pubkey_algo) {
 switch (pubkey_algo) {
 case X509_PUBKEY_RSA:
  switch (sig_algo) {
  case X509_SIGNATURE_MD2_RSA:
  case X509_SIGNATURE_MD5_RSA:
  case X509_SIGNATURE_SHA1_RSA:
  case X509_SIGNATURE_SHA256_RSA:
  case X509_SIGNATURE_SHA384_RSA:
  case X509_SIGNATURE_SHA512_RSA:
   return 1;
  default:
   return 0;
  }
 case X509_PUBKEY_ECDSA:
  switch (sig_algo) {
  case X509_SIGNATURE_SHA256_ECDSA:
  case X509_SIGNATURE_SHA384_ECDSA:
  case X509_SIGNATURE_SHA512_ECDSA:
   return 1;
  default:
   return 0;
  }
 default:
  return 0;
 }
}

variable_types: enum x509_sig_algo { X509_SIGNATURE_INVALID=0, X509_SIGNATURE_MD2_RSA=1, X509_SIGNATURE_MD5_RSA=2, X509_SIGNATURE_SHA1_RSA=3, X509_SIGNATURE_SHA256_RSA=4, X509_SIGNATURE_SHA384_RSA=5, X509_SIGNATURE_SHA512_RSA=6, X509_SIGNATURE_SHA256_ECDSA=7, X509_SIGNATURE_SHA384_ECDSA=8, X509_SIGNATURE_SHA512_ECDSA=9, X509_SIGNATURE_SHA256_DSA=10 }

variable_types: enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 }


decompiled_code:
__int64 __fastcall cert_is_self_issued(__int64 a1)
{
return x509_name_eq(a1 + 48, a1 + 576, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return x509_name_eq(a1 + 48, a1 + 576, 0LL);
}

original_code:
static _Bool
cert_is_self_issued(const x509_cert_t *cert) {
 return x509_name_eq(&cert->issuer, &cert->subject, ((void *)0));
}

canonical_original_code:
static _Bool cert_is_self_issued(struct x509_cert *cert) {
 return x509_name_eq(&cert->issuer, &cert->subject, ((void *)0));
}

variable_types: struct x509_cert { enum x509_version { X509_V1=0, X509_V2=1, X509_V3=2 } version; struct x509_signature { enum x509_sig_algo { X509_SIGNATURE_INVALID=0, X509_SIGNATURE_MD2_RSA=1, X509_SIGNATURE_MD5_RSA=2, X509_SIGNATURE_SHA1_RSA=3, X509_SIGNATURE_SHA256_RSA=4, X509_SIGNATURE_SHA384_RSA=5, X509_SIGNATURE_SHA512_RSA=6, X509_SIGNATURE_SHA256_ECDSA=7, X509_SIGNATURE_SHA384_ECDSA=8, X509_SIGNATURE_SHA512_ECDSA=9, X509_SIGNATURE_SHA256_DSA=10 } algorithm; unsigned char *data; unsigned long num; } signature; unsigned char *raw; unsigned long raw_num; struct x509_name { unsigned long num; struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } value; } rdns[-1]; } issuer; struct x509_name subject; struct x509_pubkey { enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 } algorithm; union { struct x509_pubkey_rsa { unsigned char *n; unsigned long n_num; unsigned char *e; unsigned long e_num; } rsa; struct x509_pubkey_ecdsa { unsigned char *point; unsigned long point_num; } ecdsa; } key; } pubkey; _Bool has_pubkey_params; union x509_pubkey_params { enum x509_ecdsa_curve { X509_ECDSA_CURVE_INVALID=0, X509_ECDSA_CURVE_SECP256R1=1, X509_ECDSA_CURVE_SECP384R1=2, X509_ECDSA_CURVE_SECP521R1=3 } ecdsa_curve; } pubkey_params; struct asn1_time { int year; unsigned char month; unsigned char day; unsigned char hour; unsigned char minute; unsigned char second; } valid_from; struct asn1_time valid_to; struct x509_alt_names { unsigned long num; struct x509_alt_name_t { enum x509_alt_name_type { X509_ALT_NAME_RFC822NAME=1, X509_ALT_NAME_DNSNAME=2, X509_ALT_NAME_DIRECTORY=4, X509_ALT_NAME_URI=6, X509_ALT_NAME_IP=7 } type; unsigned long length; unsigned char *data; } names[-1]; unsigned long directory_num; struct x509_name directory[-1]; } subject_alt_names; unsigned short key_usage; unsigned char ext_key_usage; _Bool is_ca; char path_len_constraint; } *

user_defined_types: struct x509_cert { enum x509_version version; struct x509_signature signature; unsigned char *raw; unsigned long raw_num; struct x509_name issuer; struct x509_name subject; struct x509_pubkey pubkey; _Bool has_pubkey_params; union x509_pubkey_params pubkey_params; struct asn1_time valid_from; struct asn1_time valid_to; struct x509_alt_names subject_alt_names; unsigned short key_usage; unsigned char ext_key_usage; _Bool is_ca; char path_len_constraint; }

user_defined_types: struct x509_signature { enum x509_sig_algo algorithm; unsigned char *data; unsigned long num; }

user_defined_types: struct x509_pubkey { enum x509_pubkey_algo algorithm; union { struct x509_pubkey_rsa rsa; struct x509_pubkey_ecdsa ecdsa; } key; }

user_defined_types: union x509_pubkey_params { enum x509_ecdsa_curve ecdsa_curve; }


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

if ( !signature_is_compatible(*(_DWORD *)(a2 + 8), *(_DWORD *)(a1 + 8)) )
return 13LL;
result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int64, _QWORD, _QWORD, _QWORD))(a1 + 584))(
a1 + 8,
*(unsigned int *)(a1 + 48),
a2 + 8,
*(_QWORD *)(a2 + 32),
*(_QWORD *)(a2 + 40),
*(_QWORD *)a1);
if ( !(_DWORD)result )
{
if ( (int)asn1_time_cmp(a2 + 1152, a1 + 592) > 0 || (int)asn1_time_cmp(a2 + 1164, a1 + 592) < 0 )
result = 14LL;
else
result = (unsigned __int8)x509_name_eq(a2 + 48, a1 + 56, 0LL) == 0 ? 0xD : 0;
}
return result;
}

original_code:
static asinine_err_t
process_certificate(x509_path_t *path, const x509_cert_t *cert) {
 if (!signature_is_compatible(
         cert->signature.algorithm, path->public_key.algorithm)) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "signature: algorithm doesn't match public key" };
 }
 do { asinine_err_t ret___LINE__ = path->cb(&path->public_key, path->public_key_parameters, &cert->signature, cert->raw, cert->raw_num, path->ctx); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (asn1_time_cmp(&cert->valid_from, &path->now) > 0 ||
     asn1_time_cmp(&cert->valid_to, &path->now) < 0) {
  return (asinine_err_t) { .errno = ASININE_ERR_EXPIRED, .reason = ((void *)0) };
 }
 if (!x509_name_eq(&cert->issuer, &path->issuer_name, ((void *)0))) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "issuer: no match" };
 }
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
static struct asinine_err process_certificate(struct x509_path *path, struct x509_cert *cert) {
 if (!signature_is_compatible(
         cert->signature.algorithm, path->public_key.algorithm)) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "signature: algorithm doesn't match public key" };
 }
 do { struct asinine_err ret___LINE__ = path->cb(&path->public_key, path->public_key_parameters, &cert->signature, cert->raw, cert->raw_num, path->ctx); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (asn1_time_cmp(&cert->valid_from, &path->now) > 0 ||
     asn1_time_cmp(&cert->valid_to, &path->now) < 0) {
  return (struct asinine_err) { .errno = ASININE_ERR_EXPIRED, .reason = ((void *)0) };
 }
 if (!x509_name_eq(&cert->issuer, &path->issuer_name, ((void *)0))) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "issuer: no match" };
 }
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types: struct x509_path { void *ctx; struct x509_pubkey { enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 } algorithm; union { struct x509_pubkey_rsa { unsigned char *n; unsigned long n_num; unsigned char *e; unsigned long e_num; } rsa; struct x509_pubkey_ecdsa { unsigned char *point; unsigned long point_num; } ecdsa; } key; } public_key; union x509_pubkey_params { enum x509_ecdsa_curve { X509_ECDSA_CURVE_INVALID=0, X509_ECDSA_CURVE_SECP256R1=1, X509_ECDSA_CURVE_SECP384R1=2, X509_ECDSA_CURVE_SECP521R1=3 } ecdsa_curve; } public_key_parameters; struct x509_name { unsigned long num; struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } value; } rdns[-1]; } issuer_name; struct asinine_err (*cb)(struct x509_pubkey *pubkey, union x509_pubkey_params params, struct x509_signature { enum x509_sig_algo { X509_SIGNATURE_INVALID=0, X509_SIGNATURE_MD2_RSA=1, X509_SIGNATURE_MD5_RSA=2, X509_SIGNATURE_SHA1_RSA=3, X509_SIGNATURE_SHA256_RSA=4, X509_SIGNATURE_SHA384_RSA=5, X509_SIGNATURE_SHA512_RSA=6, X509_SIGNATURE_SHA256_ECDSA=7, X509_SIGNATURE_SHA384_ECDSA=8, X509_SIGNATURE_SHA512_ECDSA=9, X509_SIGNATURE_SHA256_DSA=10 } algorithm; unsigned char *data; unsigned long num; } *sig, unsigned char *raw, unsigned long raw_num, void *ctx); struct asn1_time { int year; unsigned char month; unsigned char day; unsigned char hour; unsigned char minute; unsigned char second; } now; char max_length; } *

variable_types: struct x509_cert { enum x509_version { X509_V1=0, X509_V2=1, X509_V3=2 } version; struct x509_signature signature; unsigned char *raw; unsigned long raw_num; struct x509_name issuer; struct x509_name subject; struct x509_pubkey pubkey; _Bool has_pubkey_params; union x509_pubkey_params pubkey_params; struct asn1_time valid_from; struct asn1_time valid_to; struct x509_alt_names { unsigned long num; struct x509_alt_name_t { enum x509_alt_name_type { X509_ALT_NAME_RFC822NAME=1, X509_ALT_NAME_DNSNAME=2, X509_ALT_NAME_DIRECTORY=4, X509_ALT_NAME_URI=6, X509_ALT_NAME_IP=7 } type; unsigned long length; unsigned char *data; } names[-1]; unsigned long directory_num; struct x509_name directory[-1]; } subject_alt_names; unsigned short key_usage; unsigned char ext_key_usage; _Bool is_ca; char path_len_constraint; } *

user_defined_types: struct x509_path { void *ctx; struct x509_pubkey public_key; union x509_pubkey_params public_key_parameters; struct x509_name issuer_name; struct asinine_err (*cb)(struct x509_pubkey *pubkey, union x509_pubkey_params params, struct x509_signature *sig, unsigned char *raw, unsigned long raw_num, void *ctx); struct asn1_time now; char max_length; }

user_defined_types: struct x509_rdn { enum x509_rdn_type type; struct asn1_token value; }


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

while ( !(unsigned __int8)asn1_end(a1) )
{
if ( (unsigned int)x509_parse_cert(a1, a3) )
{
result = asn1_abort(a1);
if ( (_DWORD)result )
return result;
}
else if ( (unsigned __int8)x509_name_eq(a3 + 576, a2 + 48, 0LL) )
{
return 0LL;
}
}
return 17LL;
}

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

while ( !(unsigned __int8)asn1_end(a1) )
{
if ( (unsigned int)x509_parse_cert(a1, a3) )
{
result = asn1_abort(a1);
if ( (_DWORD)result )
return result;
}
else if ( (unsigned __int8)x509_name_eq(a3 + 576, a2 + 48, 0LL) )
{
return 0LL;
}
}
return 17LL;
}

original_code:
asinine_err_t
x509_find_issuer(
    asn1_parser_t *parser, const x509_cert_t *cert, x509_cert_t *issuer) {
 while (!asn1_end(parser)) {
  asinine_err_t err = x509_parse_cert(parser, issuer);
  if (err.errno != ASININE_OK) {
   do { asinine_err_t ret___LINE__ = asn1_abort(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   continue;
  }
  if (x509_name_eq(&issuer->subject, &cert->issuer, ((void *)0))) {
   return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
  }
 }
 return (asinine_err_t) { .errno = ASININE_ERR_NOT_FOUND, .reason = "issuer: no match in trust store" };
}

canonical_original_code:
struct asinine_err x509_find_issuer(struct asn1_parser *parser, struct x509_cert *cert, struct x509_cert *issuer) {
 while (!asn1_end(parser)) {
  struct asinine_err err = x509_parse_cert(parser, issuer);
  if (err.errno != ASININE_OK) {
   do { struct asinine_err ret___LINE__ = asn1_abort(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
   continue;
  }
  if (x509_name_eq(&issuer->subject, &cert->issuer, ((void *)0))) {
   return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
  }
 }
 return (struct asinine_err) { .errno = ASININE_ERR_NOT_FOUND, .reason = "issuer: no match in trust store" };
}

variable_types: struct x509_cert { enum x509_version { X509_V1=0, X509_V2=1, X509_V3=2 } version; struct x509_signature { enum x509_sig_algo { X509_SIGNATURE_INVALID=0, X509_SIGNATURE_MD2_RSA=1, X509_SIGNATURE_MD5_RSA=2, X509_SIGNATURE_SHA1_RSA=3, X509_SIGNATURE_SHA256_RSA=4, X509_SIGNATURE_SHA384_RSA=5, X509_SIGNATURE_SHA512_RSA=6, X509_SIGNATURE_SHA256_ECDSA=7, X509_SIGNATURE_SHA384_ECDSA=8, X509_SIGNATURE_SHA512_ECDSA=9, X509_SIGNATURE_SHA256_DSA=10 } algorithm; unsigned char *data; unsigned long num; } signature; unsigned char *raw; unsigned long raw_num; struct x509_name { unsigned long num; struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token value; } rdns[-1]; } issuer; struct x509_name subject; struct x509_pubkey { enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 } algorithm; union { struct x509_pubkey_rsa { unsigned char *n; unsigned long n_num; unsigned char *e; unsigned long e_num; } rsa; struct x509_pubkey_ecdsa { unsigned char *point; unsigned long point_num; } ecdsa; } key; } pubkey; _Bool has_pubkey_params; union x509_pubkey_params { enum x509_ecdsa_curve { X509_ECDSA_CURVE_INVALID=0, X509_ECDSA_CURVE_SECP256R1=1, X509_ECDSA_CURVE_SECP384R1=2, X509_ECDSA_CURVE_SECP521R1=3 } ecdsa_curve; } pubkey_params; struct asn1_time { int year; unsigned char month; unsigned char day; unsigned char hour; unsigned char minute; unsigned char second; } valid_from; struct asn1_time valid_to; struct x509_alt_names { unsigned long num; struct x509_alt_name_t { enum x509_alt_name_type { X509_ALT_NAME_RFC822NAME=1, X509_ALT_NAME_DNSNAME=2, X509_ALT_NAME_DIRECTORY=4, X509_ALT_NAME_URI=6, X509_ALT_NAME_IP=7 } type; unsigned long length; unsigned char *data; } names[-1]; unsigned long directory_num; struct x509_name directory[-1]; } subject_alt_names; unsigned short key_usage; unsigned char ext_key_usage; _Bool is_ca; char path_len_constraint; } *

variable_types:
issuer
struct x509_cert *

user_defined_types: struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type type; }

user_defined_types: struct x509_name { unsigned long num; struct x509_rdn rdns[-1]; }


original_code:
asinine_err_t
x509_path_add(x509_path_t *path, const x509_cert_t *cert) {
 do { asinine_err_t ret___LINE__ = process_certificate(path, cert); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 path->issuer_name = cert->subject;
 if (cert->has_pubkey_params) {
  path->public_key_parameters = cert->pubkey_params;
 } else if (cert->pubkey.algorithm != path->public_key.algorithm) {
  path->public_key_parameters = (x509_pubkey_params_t){0};
 }
 path->public_key = cert->pubkey;
 if (cert->version != X509_V3) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "certficiate: not X509v3" };
 }
 if (!cert->is_ca) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "certificate: not a CA" };
 }
 if (!cert_is_self_issued(cert) && path->max_length != -1) {
  if (path->max_length < 1) {
   return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "path: too long" };
  }
  path->max_length--;
 }
 if (cert->path_len_constraint != -1 &&
     (path->max_length == -1 ||
         cert->path_len_constraint < path->max_length)) {
  path->max_length = cert->path_len_constraint;
 }
 if (cert->key_usage != 0 &&
     (cert->key_usage & X509_KEYUSE_KEY_CERT_SIGN) == 0) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "certificate: missing signing key usage" };
 }
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err x509_path_add(struct x509_path *path, struct x509_cert *cert) {
 do { struct asinine_err ret___LINE__ = process_certificate(path, cert); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 path->issuer_name = cert->subject;
 if (cert->has_pubkey_params) {
  path->public_key_parameters = cert->pubkey_params;
 } else if (cert->pubkey.algorithm != path->public_key.algorithm) {
  path->public_key_parameters = (union x509_pubkey_params){0};
 }
 path->public_key = cert->pubkey;
 if (cert->version != X509_V3) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "certficiate: not X509v3" };
 }
 if (!cert->is_ca) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "certificate: not a CA" };
 }
 if (!cert_is_self_issued(cert) && path->max_length != -1) {
  if (path->max_length < 1) {
   return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "path: too long" };
  }
  path->max_length--;
 }
 if (cert->path_len_constraint != -1 &&
     (path->max_length == -1 ||
         cert->path_len_constraint < path->max_length)) {
  path->max_length = cert->path_len_constraint;
 }
 if (cert->key_usage != 0 &&
     (cert->key_usage & X509_KEYUSE_KEY_CERT_SIGN) == 0) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "certificate: missing signing key usage" };
 }
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

user_defined_types: struct asinine_err { enum asinine_errno errno; char *reason; }

user_defined_types: enum x509_ecdsa_curve { X509_ECDSA_CURVE_INVALID=0, X509_ECDSA_CURVE_SECP256R1=1, X509_ECDSA_CURVE_SECP384R1=2, X509_ECDSA_CURVE_SECP521R1=3 }

user_defined_types: struct asn1_time { int year; unsigned char month; unsigned char day; unsigned char hour; unsigned char minute; unsigned char second; }

user_defined_types: enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 }

user_defined_types: struct x509_pubkey_rsa { unsigned char *n; unsigned long n_num; unsigned char *e; unsigned long e_num; }

user_defined_types: struct x509_pubkey_ecdsa { unsigned char *point; unsigned long point_num; }

user_defined_types: enum x509_alt_name_type { X509_ALT_NAME_RFC822NAME=1, X509_ALT_NAME_DNSNAME=2, X509_ALT_NAME_DIRECTORY=4, X509_ALT_NAME_URI=6, X509_ALT_NAME_IP=7 }

user_defined_types: struct asn1_type { enum asn1_tag tag; enum asn1_class class; enum asn1_encoding encoding; }

user_defined_types: enum x509_sig_algo { X509_SIGNATURE_INVALID=0, X509_SIGNATURE_MD2_RSA=1, X509_SIGNATURE_MD5_RSA=2, X509_SIGNATURE_SHA1_RSA=3, X509_SIGNATURE_SHA256_RSA=4, X509_SIGNATURE_SHA384_RSA=5, X509_SIGNATURE_SHA512_RSA=6, X509_SIGNATURE_SHA256_ECDSA=7, X509_SIGNATURE_SHA384_ECDSA=8, X509_SIGNATURE_SHA512_ECDSA=9, X509_SIGNATURE_SHA256_DSA=10 }


decompiled_code:
__int64 __fastcall x509_path_end(__int64 a1, __int64 a2)
{
__int64 v2; // rax
bool v3; // zf
__int64 v4; // rdx
__int64 result; // rax

v2 = process_certificate(a1, a2);
v3 = (_DWORD)v2 == 0;
v4 = v2;
result = 0LL;
if ( !v3 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rax
bool v3; // zf
__int64 v4; // rdx
__int64 result; // rax

v2 = func2(a1, a2);
v3 = (_DWORD)v2 == 0;
v4 = v2;
result = 0LL;
if ( !v3 )
result = v4;
return result;
}

original_code:
asinine_err_t
x509_path_end(x509_path_t *path, const x509_cert_t *cert) {
 do { asinine_err_t ret___LINE__ = process_certificate(path, cert); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err x509_path_end(struct x509_path *path, struct x509_cert *cert) {
 do { struct asinine_err ret___LINE__ = process_certificate(path, cert); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

user_defined_types: struct x509_cert { enum x509_version version; struct x509_signature signature; unsigned char *raw; unsigned long raw_num; struct x509_name issuer; struct x509_name subject; struct x509_pubkey pubkey; _Bool has_pubkey_params; union x509_pubkey_params pubkey_params; struct asn1_time valid_from; struct asn1_time valid_to; struct x509_alt_names subject_alt_names; unsigned short key_usage; unsigned char ext_key_usage; _Bool is_ca; char path_len_constraint; }

user_defined_types: enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 }

user_defined_types: struct x509_alt_names { unsigned long num; struct x509_alt_name_t names[-1]; unsigned long directory_num; struct x509_name directory[-1]; }

user_defined_types: struct x509_alt_name_t { enum x509_alt_name_type type; unsigned long length; unsigned char *data; }

user_defined_types: enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 }

user_defined_types: enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 }

user_defined_types: enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 }

user_defined_types: enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 }


decompiled_code:
const char *test_x509_parse_name()
{
int v0; // er8
const char *result; // rax
char v2; // r8
bool v3; // zf
__int128 v4[2]; // [rsp+0h] [rbp-4F8h] BYREF
__int64 v5; // [rsp+20h] [rbp-4D8h]
char v6[160]; // [rsp+30h] [rbp-4C8h] BYREF
__int64 v7; // [rsp+D0h] [rbp-428h] BYREF
int v8; // [rsp+D8h] [rbp-420h]
int v9; // [rsp+100h] [rbp-3F8h]
__int64 v10[67]; // [rsp+2E0h] [rbp-218h] BYREF

v5 = 0x786F7262656C6265LL;
v4[0] = (__int128)_mm_load_si128((const __m128i *)&LC14);
v4[1] = (__int128)_mm_load_si128((const __m128i *)&LC15);
asn1_init(v6, v4, 40LL);
v0 = x509_parse_name(v6, &v7);
result = "src/tests/x509-tests.c:71: (x509_parse_name(&parser, &a)).errno == ASININE_OK";
if ( !v0 )
{
result = "src/tests/x509-tests.c:73: a.num == 2";
if ( v7 == 2 )
{
result = "src/tests/x509-tests.c:74: a.rdns[0].type == X509_RDN_COUNTRY";
if ( v8 == 4 )
{
result = "src/tests/x509-tests.c:75: a.rdns[1].type == X509_RDN_COMMON_NAME";
if ( v9 == 16 )
{
v2 = x509_name_eq(&v7, &v7, 0LL);
result = "src/tests/x509-tests.c:77: x509_name_eq(&a, &a, NULL)";
if ( v2 )
{
memset(v10, 0, 0x210uLL);
v10[0] = 1LL;
LODWORD(v10[1]) = 4;
v10[3] = (__int64)"Slartibartfass";
v10[4] = 14LL;
LODWORD(v10[5]) = 12;
v3 = (unsigned __int8)x509_name_eq(&v7, v10, 0LL) == 0;
result = "src/tests/x509-tests.c:89: !x509_name_eq(&a, &b, NULL)";
if ( v3 )
result = 0LL;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *func1()
{
int v0; // er8
const char *result; // rax
char v2; // r8
bool v3; // zf
__int128 v4[2]; // [rsp+0h] [rbp-4F8h] BYREF
__int64 v5; // [rsp+20h] [rbp-4D8h]
char v6[160]; // [rsp+30h] [rbp-4C8h] BYREF
__int64 v7; // [rsp+D0h] [rbp-428h] BYREF
int v8; // [rsp+D8h] [rbp-420h]
int v9; // [rsp+100h] [rbp-3F8h]
__int64 v10[67]; // [rsp+2E0h] [rbp-218h] BYREF

v5 = 0x786F7262656C6265LL;
v4[0] = (__int128)_mm_load_si128((const __m128i *)&LC14);
v4[1] = (__int128)_mm_load_si128((const __m128i *)&LC15);
asn1_init(v6, v4, 40LL);
v0 = x509_parse_name(v6, &v7);
result = "src/tests/x509-tests.c:71: (x509_parse_name(&parser, &a)).errno == ASININE_OK";
if ( !v0 )
{
result = "src/tests/x509-tests.c:73: a.num == 2";
if ( v7 == 2 )
{
result = "src/tests/x509-tests.c:74: a.rdns[0].type == X509_RDN_COUNTRY";
if ( v8 == 4 )
{
result = "src/tests/x509-tests.c:75: a.rdns[1].type == X509_RDN_COMMON_NAME";
if ( v9 == 16 )
{
v2 = x509_name_eq(&v7, &v7, 0LL);
result = "src/tests/x509-tests.c:77: x509_name_eq(&a, &a, NULL)";
if ( v2 )
{
memset(v10, 0, 0x210uLL);
v10[0] = 1LL;
LODWORD(v10[1]) = 4;
v10[3] = (__int64)"Slartibartfass";
v10[4] = 14LL;
LODWORD(v10[5]) = 12;
v3 = (unsigned __int8)x509_name_eq(&v7, v10, 0LL) == 0;
result = "src/tests/x509-tests.c:89: !x509_name_eq(&a, &b, NULL)";
if ( v3 )
result = 0LL;
}
}
}
}
}
return result;
}

variable_types: struct asn1_parser { unsigned char *current; void *end; void *stack[-1]; unsigned char depth; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } token; }

variable_types: struct x509_name { unsigned long num; struct x509_rdn { enum x509_rdn_type { X509_RDN_INVALID=0, X509_RDN_JURISDICTION_COUNTRY=1, X509_RDN_JURISDICTION_STATE_OR_PROVINCE=2, X509_RDN_JURISDICTION_LOCALITY=3, X509_RDN_COUNTRY=4, X509_RDN_STATE_OR_PROVINCE=5, X509_RDN_LOCALITY=6, X509_RDN_POSTAL_CODE=7, X509_RDN_STREET_ADDRESS=8, X509_RDN_PO_BOX=9, X509_RDN_BUSINESS_CATEGORY=10, X509_RDN_ORGANIZATION=11, X509_RDN_ORGANIZATIONAL_UNIT=12, X509_RDN_ORGANIZATIONAL_ID=13, X509_RDN_DISTINGUISHED_NAME=14, X509_RDN_DISTINGUISHED_NAME_QUALIFIER=15, X509_RDN_COMMON_NAME=16, X509_RDN_SERIAL_NUMBER=17, X509_RDN_SURNAME=18, X509_RDN_EMAIL=19 } type; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } value; } rdns[-1]; }

user_defined_types: struct asn1_parser { unsigned char *current; void *end; void *stack[-1]; unsigned char depth; struct asn1_token token; }

user_defined_types: struct x509_name { unsigned long num; struct x509_rdn rdns[-1]; }

user_defined_types: struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type type; }

user_defined_types: struct x509_rdn { enum x509_rdn_type type; struct asn1_token value; }


original_code:
static char *
test_x509_sort_name() {
 x509_name_t name = {
     .num = 3,
     .rdns =
         {
             {
                 .type = X509_RDN_ORGANIZATION,
                 .value = (asn1_token_t) { .type = {.class = ASN1_CLASS_UNIVERSAL, .tag = (ASN1_TAG_UTF8STRING), .encoding = (ASN1_ENCODING_PRIMITIVE)}, .data = ((uint8_t *)("Warudo")), .length = (strlen("Warudo")) },
             },
             {
                 .type = X509_RDN_COMMON_NAME,
                 .value = (asn1_token_t) { .type = {.class = ASN1_CLASS_UNIVERSAL, .tag = (ASN1_TAG_UTF8STRING), .encoding = (ASN1_ENCODING_PRIMITIVE)}, .data = ((uint8_t *)("!!!")), .length = (strlen("!!!")) },
             },
             {
                 .type = X509_RDN_COUNTRY,
                 .value = (asn1_token_t) { .type = {.class = ASN1_CLASS_UNIVERSAL, .tag = (ASN1_TAG_UTF8STRING), .encoding = (ASN1_ENCODING_PRIMITIVE)}, .data = ((uint8_t *)("Za")), .length = (strlen("Za")) },
             },
         },
 };
 x509_sort_name(&name);
 do { if (!(strncmp((char *)name.rdns[0].value.data, "Za", 2) == 0)) return "src/tests/x509-tests.c" ":" "117" ": " "strncmp((char *)name.rdns[0].value.data, \"Za\", 2) == 0"; } while (0);
 do { if (!(strncmp((char *)name.rdns[1].value.data, "Warudo", 6) == 0)) return "src/tests/x509-tests.c" ":" "118" ": " "strncmp((char *)name.rdns[1].value.data, \"Warudo\", 6) == 0"; } while (0);
 do { if (!(strncmp((char *)name.rdns[2].value.data, "!!!", 3) == 0)) return "src/tests/x509-tests.c" ":" "119" ": " "strncmp((char *)name.rdns[2].value.data, \"!!!\", 3) == 0"; } while (0);
 return 0;
}

canonical_original_code:
static char *test_x509_sort_name() {
 struct x509_name name = {
     .num = 3,
     .rdns =
         {
             {
                 .type = X509_RDN_ORGANIZATION,
                 .value = (asn1_token_t) { .type = {.class = ASN1_CLASS_UNIVERSAL, .tag = (ASN1_TAG_UTF8STRING), .encoding = (ASN1_ENCODING_PRIMITIVE)}, .data = ((uint8_t *)("Warudo")), .length = (strlen("Warudo")) },
             },
             {
                 .type = X509_RDN_COMMON_NAME,
                 .value = (asn1_token_t) { .type = {.class = ASN1_CLASS_UNIVERSAL, .tag = (ASN1_TAG_UTF8STRING), .encoding = (ASN1_ENCODING_PRIMITIVE)}, .data = ((uint8_t *)("!!!")), .length = (strlen("!!!")) },
             },
             {
                 .type = X509_RDN_COUNTRY,
                 .value = (asn1_token_t) { .type = {.class = ASN1_CLASS_UNIVERSAL, .tag = (ASN1_TAG_UTF8STRING), .encoding = (ASN1_ENCODING_PRIMITIVE)}, .data = ((uint8_t *)("Za")), .length = (strlen("Za")) },
             },
         },
 };
 x509_sort_name(&name);
 do { if (!(strncmp((char *)name.rdns[0].value.data, "Za", 2) == 0)) return "src/tests/x509-tests.c" ":" "117" ": " "strncmp((char *)name.rdns[0].value.data, \"Za\", 2) == 0"; } while (0);
 do { if (!(strncmp((char *)name.rdns[1].value.data, "Warudo", 6) == 0)) return "src/tests/x509-tests.c" ":" "118" ": " "strncmp((char *)name.rdns[1].value.data, \"Warudo\", 6) == 0"; } while (0);
 do { if (!(strncmp((char *)name.rdns[2].value.data, "!!!", 3) == 0)) return "src/tests/x509-tests.c" ":" "119" ": " "strncmp((char *)name.rdns[2].value.data, \"!!!\", 3) == 0"; } while (0);
 return 0;
}


decompiled_code:
__int64 __fastcall test_x509_all(_DWORD *a1)
{
const char *v1; // rax
unsigned int v2; // er12
const char *v3; // rsi
const char *v4; // rax
const char *v5; // rsi
const char *v7; // rsi

printf("sizeof x509_rdn_t: %zu\n", 0x28uLL);
printf("sizeof x509_name_t: %zu\n", 0x210uLL);
printf("sizeof x509_cert_t: %zu\n", 0x12C0uLL);
v1 = test_x509_certs();
if ( a1 )
{
++*a1;
if ( v1 )
{
v2 = 1;
printf("> %s\n", v1);
}
else
{
v2 = 0;
}
v3 = test_x509_parse_name();
++*a1;
if ( v3 )
{
++v2;
printf("> %s\n", v3);
}
v4 = test_x509_sort_name();
++*a1;
v5 = v4;
}
else
{
if ( v1 )
{
v2 = 1;
printf("> %s\n", v1);
}
else
{
v2 = 0;
}
v7 = test_x509_parse_name();
if ( v7 )
{
++v2;
printf("> %s\n", v7);
}
v5 = test_x509_sort_name();
}
if ( v5 )
{
++v2;
printf("> %s\n", v5);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
const char *v1; // rax
unsigned int v2; // er12
const char *v3; // rsi
const char *v4; // rax
const char *v5; // rsi
const char *v7; // rsi

printf("sizeof x509_rdn_t: %zu\n", 0x28uLL);
printf("sizeof x509_name_t: %zu\n", 0x210uLL);
printf("sizeof x509_cert_t: %zu\n", 0x12C0uLL);
v1 = func0();
if ( a1 )
{
++*a1;
if ( v1 )
{
v2 = 1;
printf("> %s\n", v1);
}
else
{
v2 = 0;
}
v3 = func1();
++*a1;
if ( v3 )
{
++v2;
printf("> %s\n", v3);
}
v4 = func2();
++*a1;
v5 = v4;
}
else
{
if ( v1 )
{
v2 = 1;
printf("> %s\n", v1);
}
else
{
v2 = 0;
}
v7 = func1();
if ( v7 )
{
++v2;
printf("> %s\n", v7);
}
v5 = func2();
}
if ( v5 )
{
++v2;
printf("> %s\n", v5);
}
return v2;
}

original_code:
int
test_x509_all(int *tests_run) {
 int failed_tests = 0;;
 printf("sizeof x509_rdn_t: %zu\n", sizeof(x509_rdn_t));
 printf("sizeof x509_name_t: %zu\n", sizeof(x509_name_t));
 printf("sizeof x509_cert_t: %zu\n", sizeof(x509_cert_t));
 do { const char *message = test_x509_certs(); if (tests_run != ((void *)0)) (*tests_run)++; if (message) { failed_tests++; printf("> %s\n", message); } } while (0);
 do { const char *message = test_x509_parse_name(); if (tests_run != ((void *)0)) (*tests_run)++; if (message) { failed_tests++; printf("> %s\n", message); } } while (0);
 do { const char *message = test_x509_sort_name(); if (tests_run != ((void *)0)) (*tests_run)++; if (message) { failed_tests++; printf("> %s\n", message); } } while (0);
 return failed_tests;;
}

canonical_original_code:
int test_x509_all(int *tests_run) {
 int failed_tests = 0;;
 printf("sizeof x509_rdn_t: %zu\n", sizeof(x509_rdn_t));
 printf("sizeof x509_name_t: %zu\n", sizeof(x509_name_t));
 printf("sizeof x509_cert_t: %zu\n", sizeof(x509_cert_t));
 do { char *message = test_x509_certs(); if (tests_run != ((void *)0)) (*tests_run)++; if (message) { failed_tests++; printf("> %s\n", message); } } while (0);
 do { char *message = test_x509_parse_name(); if (tests_run != ((void *)0)) (*tests_run)++; if (message) { failed_tests++; printf("> %s\n", message); } } while (0);
 do { char *message = test_x509_sort_name(); if (tests_run != ((void *)0)) (*tests_run)++; if (message) { failed_tests++; printf("> %s\n", message); } } while (0);
 return failed_tests;;
}

variable_types:
message
char *

return_type: int


original_code:
static _Bool
append_arc(asn1_oid_t *oid, asn1_oid_arc_t arc) {
 if (oid->num >= (12)) {
  return 0;
 }
 oid->arcs[oid->num++] = arc;
 return 1;
}

canonical_original_code:
static _Bool append_arc(struct asn1_oid *oid, unsigned int arc) {
 if (oid->num >= (12)) {
  return 0;
 }
 oid->arcs[oid->num++] = arc;
 return 1;
}

variable_types: struct asn1_oid { unsigned int arcs[-1]; unsigned long num; } *

variable_types:
arc
unsigned int


decompiled_code:
__int64 __fastcall arc_digits(unsigned int a1)
{
__int64 v1; // r8
unsigned int v2; // eax

v1 = 1LL;
if ( a1 > 9 )
{
do
{
++v1;
v2 = a1;
a1 /= 0xAu;
}
while ( v2 > 0x63 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 v1; // r8
unsigned int v2; // eax

v1 = 1LL;
if ( a1 > 9 )
{
do
{
++v1;
v2 = a1;
a1 /= 0xAu;
}
while ( v2 > 0x63 );
}
return v1;
}

original_code:
static size_t
arc_digits(asn1_oid_arc_t num) {
 size_t digits = 1;
 while (num / 10 > 0) {
  digits++;
  num /= 10;
 }
 return digits;
}

canonical_original_code:
static unsigned long arc_digits(unsigned int num) {
 unsigned long digits = 1;
 while (num / 10 > 0) {
  digits++;
  num /= 10;
 }
 return digits;
}

variable_types:
num
unsigned int

variable_types:
digits
unsigned long

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall format_arc(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
unsigned __int64 v3; // rax
unsigned int v4; // ecx
__int64 v5; // r9
unsigned __int64 v6; // r10
unsigned __int64 v7; // r8
unsigned __int64 v8; // rdx
char v9; // al

v3 = arc_digits(a3);
v7 = v3;
if ( v3 < a2 )
*(_BYTE *)(v5 + v3) = 46;
if ( v3 )
{
v8 = v3;
do
{
--v8;
v9 = v4;
v4 /= 0xAu;
if ( v8 < v6 )
*(_BYTE *)(v5 + v8) = v9 - 10 * v4 + 48;
}
while ( v8 );
}
return v7 + 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned __int64 a2, unsigned int a3)
{
unsigned __int64 v3; // rax
unsigned int v4; // ecx
__int64 v5; // r9
unsigned __int64 v6; // r10
unsigned __int64 v7; // r8
unsigned __int64 v8; // rdx
char v9; // al

v3 = func1(a3);
v7 = v3;
if ( v3 < a2 )
*(_BYTE *)(v5 + v3) = 46;
if ( v3 )
{
v8 = v3;
do
{
--v8;
v9 = v4;
v4 /= 0xAu;
if ( v8 < v6 )
*(_BYTE *)(v5 + v8) = v9 - 10 * v4 + 48;
}
while ( v8 );
}
return v7 + 1;
}

original_code:
static size_t
format_arc(char *buffer, size_t len, asn1_oid_arc_t arc) {
 size_t digits = arc_digits(arc);
 if (digits < len) {
  buffer[digits] = '.';
 }
 for (size_t i = digits; i > 0; i--) {
  char digit = (char)(arc % 10) + '0';
  arc /= 10;
  if (i - 1 < len) {
   buffer[i - 1] = digit;
  }
 }
 return digits + 1;
}

canonical_original_code:
static unsigned long format_arc(char *buffer, unsigned long len, unsigned int arc) {
 unsigned long digits = arc_digits(arc);
 if (digits < len) {
  buffer[digits] = '.';
 }
 for (unsigned long i = digits; i > 0; i--) {
  char digit = (char)(arc % 10) + '0';
  arc /= 10;
  if (i - 1 < len) {
   buffer[i - 1] = digit;
  }
 }
 return digits + 1;
}

variable_types:
buffer
char *

variable_types:
len
unsigned long

variable_types:
i
unsigned long

variable_types: digit char


original_code:
asinine_err_t
asn1_oid(const asn1_token_t *token, asn1_oid_t *oid) {
 asn1_oid_arc_t arc;
 _Bool is_first_arc;
 size_t arc_bits;
 const uint8_t *data;
 *oid = (asn1_oid_t){0};
 if (token->data == ((void *)0) || token->length == 0) {
  return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "OID: zero length" };
 }
 if ((*(token->data + token->length - 1) & (1 << 7)) != 0) {
  return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "OID: no end marker" };
 }
 arc = 0;
 arc_bits = 0;
 is_first_arc = 1;
 for (data = token->data; data < token->data + token->length; data++) {
  if (arc == 0 && *data == 0x80) {
   return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "OID: leading byte is zero" };
  }
  arc = (arc << 7) | (*data & ((1 << 7) - 1));
  arc_bits += 7;
  if (arc_bits > sizeof(arc) * 8) {
   return (asinine_err_t) { .errno = ASININE_ERR_MEMORY, .reason = "OID: arc too long" };
  }
  if ((*data & (1 << 7)) == 0) {
   if (is_first_arc) {
    asn1_oid_arc_t x = (((arc) < (80)) ? arc : 80) / 40;
    if (!append_arc(oid, x)) {
     return (asinine_err_t) { .errno = ASININE_ERR_MEMORY, .reason = "OID: too many arcs" };
    }
    arc = (arc - (x * 40));
    is_first_arc = 0;
   }
   if (!append_arc(oid, arc)) {
    return (asinine_err_t) { .errno = ASININE_ERR_MEMORY, .reason = "OID: too many arcs" };
   }
   arc = 0;
   arc_bits = 0;
  }
 }
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err asn1_oid(struct asn1_token *token, struct asn1_oid *oid) {
 unsigned int arc;
 _Bool is_first_arc;
 unsigned long arc_bits;
 unsigned char *data;
 *oid = (struct asn1_oid){0};
 if (token->data == ((void *)0) || token->length == 0) {
  return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "OID: zero length" };
 }
 if ((*(token->data + token->length - 1) & (1 << 7)) != 0) {
  return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "OID: no end marker" };
 }
 arc = 0;
 arc_bits = 0;
 is_first_arc = 1;
 for (data = token->data; data < token->data + token->length; data++) {
  if (arc == 0 && *data == 0x80) {
   return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "OID: leading byte is zero" };
  }
  arc = (arc << 7) | (*data & ((1 << 7) - 1));
  arc_bits += 7;
  if (arc_bits > sizeof(arc) * 8) {
   return (struct asinine_err) { .errno = ASININE_ERR_MEMORY, .reason = "OID: arc too long" };
  }
  if ((*data & (1 << 7)) == 0) {
   if (is_first_arc) {
    unsigned int x = (((arc) < (80)) ? arc : 80) / 40;
    if (!append_arc(oid, x)) {
     return (struct asinine_err) { .errno = ASININE_ERR_MEMORY, .reason = "OID: too many arcs" };
    }
    arc = (arc - (x * 40));
    is_first_arc = 0;
   }
   if (!append_arc(oid, arc)) {
    return (struct asinine_err) { .errno = ASININE_ERR_MEMORY, .reason = "OID: too many arcs" };
   }
   arc = 0;
   arc_bits = 0;
  }
 }
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types: struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } *

variable_types:
data
unsigned char *

variable_types:
x
unsigned int

user_defined_types: struct asn1_oid { unsigned int arcs[-1]; unsigned long num; }

user_defined_types: struct asinine_err { enum asinine_errno errno; char *reason; }


original_code:
size_t
asn1_oid_to_string(char *buffer, size_t len, const asn1_oid_t *oid) {
 if (oid->num == 0) {
  if (len > 0) {
   buffer[0] = '\0';
  }
  return 0;
 }
 size_t required = 0;
 size_t remaining = len;
 for (size_t i = 0; i < oid->num; i++) {
  asn1_oid_arc_t arc = oid->arcs[i];
  size_t n = format_arc(buffer, remaining, arc);
  required += n;
  if (n > remaining) {
   buffer += remaining;
   remaining = 0;
   continue;
  }
  buffer += n;
  remaining -= n;
 }
 if (len > 0) {
  *(buffer - 1) = '\0';
 }
 return required - 1;
}

canonical_original_code:
unsigned long asn1_oid_to_string(char *buffer, unsigned long len, struct asn1_oid *oid) {
 if (oid->num == 0) {
  if (len > 0) {
   buffer[0] = '\0';
  }
  return 0;
 }
 unsigned long required = 0;
 unsigned long remaining = len;
 for (unsigned long i = 0; i < oid->num; i++) {
  unsigned int arc = oid->arcs[i];
  unsigned long n = format_arc(buffer, remaining, arc);
  required += n;
  if (n > remaining) {
   buffer += remaining;
   remaining = 0;
   continue;
  }
  buffer += n;
  remaining -= n;
 }
 if (len > 0) {
  *(buffer - 1) = '\0';
 }
 return required - 1;
}

variable_types:
required
unsigned long

variable_types:
remaining
unsigned long

variable_types:
n
unsigned long


original_code:
_Bool
asn1_oid_eq(const asn1_oid_t *oid, size_t num, ...) {
 size_t i;
 va_list arcs;
 if (oid->num != num) {
  return 0;
 }
 __builtin_va_start(arcs,num);
 for (i = 0; i < num; i++) {
  asn1_oid_arc_t arc = __builtin_va_arg(arcs,asn1_oid_arc_t);
  if (oid->arcs[i] != arc) {
   return 0;
  }
 }
 __builtin_va_end(arcs);
 return 1;
}

canonical_original_code:
_Bool asn1_oid_eq(struct asn1_oid *oid, unsigned long num, ...) {
 unsigned long i;
 __builtin_va_list arcs;
 if (oid->num != num) {
  return 0;
 }
 __builtin_va_start(arcs,num);
 for (i = 0; i < num; i++) {
  unsigned int arc = __builtin_va_arg(arcs,asn1_oid_arc_t);
  if (oid->arcs[i] != arc) {
   return 0;
  }
 }
 __builtin_va_end(arcs);
 return 1;
}

variable_types:
num
unsigned long


original_code:
int
asn1_oid_cmp(const asn1_oid_t *a, const asn1_oid_t *b) {
 size_t num = a->num;
 if (num > b->num) {
  num = b->num;
 }
 for (size_t i = 0; i < num; ++i) {
  if (a->arcs[i] != b->arcs[i]) {
   return (a->arcs[i] > b->arcs[i]) - (a->arcs[i] < b->arcs[i]);
  }
 }
 return (a->num > b->num) - (a->num < b->num);
}

canonical_original_code:
int asn1_oid_cmp(struct asn1_oid *a, struct asn1_oid *b) {
 unsigned long num = a->num;
 if (num > b->num) {
  num = b->num;
 }
 for (unsigned long i = 0; i < num; ++i) {
  if (a->arcs[i] != b->arcs[i]) {
   return (a->arcs[i] > b->arcs[i]) - (a->arcs[i] < b->arcs[i]);
  }
 }
 return (a->num > b->num) - (a->num < b->num);
}

variable_types:
b
struct asn1_oid *


repo: lneto/luadata

decompiled_code:
unsigned __int64 __fastcall swap_bytes_out(unsigned __int64 *a1, char a2)
{
unsigned __int64 v2; // rax
unsigned __int64 result; // rax
char v4; // r10

v2 = _byteswap_uint64(*a1);
*a1 = v2;
if ( (a2 & 7) != 0 )
{
contract((__int64 *)a1, a2, 64 - a2, a2 & 7);
result = *a1 >> v4;
}
else
{
result = v2 >> (64 - a2);
}
*a1 = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 *a1, char a2)
{
unsigned __int64 v2; // rax
unsigned __int64 result; // rax
char v4; // r10

v2 = _byteswap_uint64(*a1);
*a1 = v2;
if ( (a2 & 7) != 0 )
{
func2((__int64 *)a1, a2, 64 - a2, a2 & 7);
result = *a1 >> v4;
}
else
{
result = v2 >> (64 - a2);
}
*a1 = result;
return result;
}

original_code:
static void
swap_bytes_out(uint64_t *value, size_t width)
{
 size_t msb_offset = ((64) - width);
 *value = __builtin_bswap64(*value);
 byte_t truncated = (width % 8);
 if (truncated > 0)
  contract(value, width, msb_offset, truncated);
 *value >>= msb_offset;
}

canonical_original_code:
static void swap_bytes_out(unsigned long *value, unsigned long width)
{
 unsigned long msb_offset = ((64) - width);
 *value = __builtin_bswap64(*value);
 unsigned char truncated = (width % 8);
 if (truncated > 0)
  contract(value, width, msb_offset, truncated);
 *value >>= msb_offset;
}

variable_types:
value
unsigned long *

variable_types:
width
unsigned long

variable_types:
truncated
unsigned char


original_code:
uint64_t
binary_get_uint64(byte_t *bytes, size_t offset, size_t width, int endian)
{
 size_t msb_offset = (offset % 8);
 size_t lsb_offset = ((((ssize_t) (8 - msb_offset - width))>((ssize_t) 0))?((ssize_t) (8 - msb_offset - width)):((ssize_t) 0));
 size_t pos = (offset / 8);
 size_t overflow = (width - (8 - msb_offset - lsb_offset));
 byte_t mask = ((byte_t) (0x7f * 2 + 1) >> (msb_offset + lsb_offset) << lsb_offset);
 uint64_t value = (byte_t) (bytes[ pos ] & mask) >> lsb_offset;
 for (; overflow >= 8; overflow -= 8)
  value = (value << 8) | bytes[ ++pos ];
 if (overflow > 0) {
  size_t overflow_lsb_offset = (8 - overflow);
  value <<= overflow;
  value |= (byte_t) bytes[ ++pos ] >> overflow_lsb_offset;
 }
 if ((width > 8 && endian == 1234))
  swap_bytes_in(&value, width);
 return value;
}

canonical_original_code:
unsigned long binary_get_uint64(unsigned char *bytes, unsigned long offset, unsigned long width, int endian)
{
 unsigned long msb_offset = (offset % 8);
 unsigned long lsb_offset = ((((ssize_t) (8 - msb_offset - width))>((ssize_t) 0))?((ssize_t) (8 - msb_offset - width)):((ssize_t) 0));
 unsigned long pos = (offset / 8);
 unsigned long overflow = (width - (8 - msb_offset - lsb_offset));
 unsigned char mask = ((byte_t) (0x7f * 2 + 1) >> (msb_offset + lsb_offset) << lsb_offset);
 unsigned long value = (byte_t) (bytes[ pos ] & mask) >> lsb_offset;
 for (; overflow >= 8; overflow -= 8)
  value = (value << 8) | bytes[ ++pos ];
 if (overflow > 0) {
  unsigned long overflow_lsb_offset = (8 - overflow);
  value <<= overflow;
  value |= (unsigned char) bytes[ ++pos ] >> overflow_lsb_offset;
 }
 if ((width > 8 && endian == 1234))
  swap_bytes_in(&value, width);
 return value;
}

variable_types:
bytes
unsigned char *

variable_types:
offset
unsigned long

variable_types: endian int

variable_types:
pos
unsigned long

variable_types:
overflow
unsigned long

variable_types:
mask
unsigned char

variable_types:
value
unsigned long


original_code:
void
binary_set_uint64(byte_t *bytes, size_t offset, size_t width, int endian,
 uint64_t value)
{
 size_t msb_offset = (offset % 8);
 size_t lsb_offset = ((((ssize_t) (8 - msb_offset - width))>((ssize_t) 0))?((ssize_t) (8 - msb_offset - width)):((ssize_t) 0));
 size_t pos = (offset / 8);
 size_t overflow = (width - (8 - msb_offset - lsb_offset));
 byte_t clear_mask = ~((byte_t) (0x7f * 2 + 1) >> (msb_offset + lsb_offset) << lsb_offset);
 if ((width > 8 && endian == 1234))
  swap_bytes_out(&value, width);
 bytes[ pos ] &= clear_mask;
 bytes[ pos ] |= (uint64_t) value << lsb_offset >> overflow;
 for (; overflow >= 8; overflow -= 8)
  bytes[ ++pos ] = (uint64_t) value >> (overflow - 8);
 if (overflow > 0) {
  size_t overflow_lsb_offset = (8 - overflow);
  byte_t overflow_clear_mask = ~((0x7f * 2 + 1) << overflow_lsb_offset);
  bytes[ ++pos ] &= overflow_clear_mask;
  bytes[ pos ] |= value << overflow_lsb_offset;
 }
}

canonical_original_code:
void binary_set_uint64(unsigned char *bytes, unsigned long offset, unsigned long width, int endian, unsigned long value)
{
 unsigned long msb_offset = (offset % 8);
 unsigned long lsb_offset = ((((ssize_t) (8 - msb_offset - width))>((ssize_t) 0))?((ssize_t) (8 - msb_offset - width)):((ssize_t) 0));
 unsigned long pos = (offset / 8);
 unsigned long overflow = (width - (8 - msb_offset - lsb_offset));
 unsigned char clear_mask = ~((byte_t) (0x7f * 2 + 1) >> (msb_offset + lsb_offset) << lsb_offset);
 if ((width > 8 && endian == 1234))
  swap_bytes_out(&value, width);
 bytes[ pos ] &= clear_mask;
 bytes[ pos ] |= (unsigned long) value << lsb_offset >> overflow;
 for (; overflow >= 8; overflow -= 8)
  bytes[ ++pos ] = (unsigned long) value >> (overflow - 8);
 if (overflow > 0) {
  unsigned long overflow_lsb_offset = (8 - overflow);
  unsigned char overflow_clear_mask = ~((0x7f * 2 + 1) << overflow_lsb_offset);
  bytes[ ++pos ] &= overflow_clear_mask;
  bytes[ pos ] |= value << overflow_lsb_offset;
 }
}


repo: lnykryn/systemd-tutor

decompiled_code:
void __fastcall signal_handler(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
f_exit = 1;
}
else if ( a1 == 1 )
{
f_reload = 1;
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
f_exit = 1;
}
else if ( a1 == 1 )
{
f_reload = 1;
}
}

original_code:
static void signal_handler(int sig) {
    switch (sig) {
    case 1:
        f_reload = 1;
        break;
    case 2:
    case 15:
        f_exit = 1;
        break;
    }
}

variable_types: sig int