decompiled_code:
__int64 __fastcall mbedtls_pem_free(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)a1;
if ( v2 )
{
mbedtls_platform_zeroize(v2, *(_QWORD *)(a1 + 8));
free(*(void **)a1);
}
free(*(void **)(a1 + 16));
return mbedtls_platform_zeroize(a1, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)a1;
if ( v2 )
{
mbedtls_platform_zeroize(v2, *(_QWORD *)(a1 + 8));
free(*(void **)a1);
}
free(*(void **)(a1 + 16));
return mbedtls_platform_zeroize(a1, 24LL);
}

original_code:
void mbedtls_pem_free(mbedtls_pem_context *ctx)
{
    if (ctx->buf != ((void *)0)) {
        mbedtls_platform_zeroize(ctx->buf, ctx->buflen);
        free(ctx->buf);
    }
    free(ctx->info);
    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pem_context));
}

canonical_original_code:
void mbedtls_pem_free(struct mbedtls_pem_context *ctx)
{
    if (ctx->buf != ((void *)0)) {
        mbedtls_platform_zeroize(ctx->buf, ctx->buflen);
        free(ctx->buf);
    }
    free(ctx->info);
    mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pem_context));
}


repo: rcr/rirc

decompiled_code:
void __fastcall chachapoly_ctx_free(void *ptr)
{
mbedtls_chachapoly_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
mbedtls_chachapoly_free();
free(ptr);
}

original_code:
static void chachapoly_ctx_free(void *ctx)
{
    mbedtls_chachapoly_free((mbedtls_chachapoly_context *) ctx);
    free(ctx);
}

canonical_original_code:
static void chachapoly_ctx_free(void *ctx)
{
    mbedtls_chachapoly_free((struct mbedtls_chachapoly_context *) ctx);
    free(ctx);
}

variable_types:
ctx
void *

return_type: void

user_defined_types: struct mbedtls_chachapoly_context { struct mbedtls_chacha20_context chacha20_ctx; struct mbedtls_poly1305_context poly1305_ctx; unsigned long aad_len; unsigned long ciphertext_len; int state; enum mbedtls_chachapoly_mode_t mode; }

user_defined_types: struct mbedtls_chacha20_context { unsigned int state[16]; unsigned char keystream8[64]; unsigned long keystream_bytes_used; }

user_defined_types: struct mbedtls_poly1305_context { unsigned int r[4]; unsigned int s[4]; unsigned int acc[5]; unsigned char queue[16]; unsigned long queue_len; }

user_defined_types: enum mbedtls_chachapoly_mode_t { MBEDTLS_CHACHAPOLY_ENCRYPT=0, MBEDTLS_CHACHAPOLY_DECRYPT=1 }


decompiled_code:
void *chachapoly_ctx_alloc()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0xF0uLL);
v1 = v0;
if ( v0 )
mbedtls_chachapoly_init(v0);
return v1;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0xF0uLL);
v1 = v0;
if ( v0 )
mbedtls_chachapoly_init(v0);
return v1;
}

original_code:
static void *chachapoly_ctx_alloc(void)
{
    mbedtls_chachapoly_context *ctx;
    ctx = calloc(1, sizeof(mbedtls_chachapoly_context));
    if (ctx == ((void *)0)) {
        return ((void *)0);
    }
    mbedtls_chachapoly_init(ctx);
    return ctx;
}

canonical_original_code:
static void *chachapoly_ctx_alloc()
{
    struct mbedtls_chachapoly_context *ctx;
    ctx = calloc(1, sizeof(mbedtls_chachapoly_context));
    if (ctx == ((void *)0)) {
        return ((void *)0);
    }
    mbedtls_chachapoly_init(ctx);
    return ctx;
}

variable_types: struct mbedtls_chachapoly_context { struct mbedtls_chacha20_context { unsigned int state[16]; unsigned char keystream8[64]; unsigned long keystream_bytes_used; } chacha20_ctx; struct mbedtls_poly1305_context { unsigned int r[4]; unsigned int s[4]; unsigned int acc[5]; unsigned char queue[16]; unsigned long queue_len; } poly1305_ctx; unsigned long aad_len; unsigned long ciphertext_len; int state; enum mbedtls_chachapoly_mode_t { MBEDTLS_CHACHAPOLY_ENCRYPT=0, MBEDTLS_CHACHAPOLY_DECRYPT=1 } mode; } *

return_type: void *


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

if ( a3 != 256 )
return 4294942464LL;
result = mbedtls_chachapoly_setkey();
if ( (_DWORD)result )
result = 4294942464LL;
return result;
}

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

if ( a3 != 256 )
return 4294942464LL;
result = mbedtls_chachapoly_setkey();
if ( (_DWORD)result )
result = 4294942464LL;
return result;
}

original_code:
static int chachapoly_setkey_wrap(void *ctx,
                                  const unsigned char *key,
                                  unsigned int key_bitlen)
{
    if (key_bitlen != 256U) {
        return -0x6100;
    }
    if (0 != mbedtls_chachapoly_setkey((mbedtls_chachapoly_context *) ctx, key)) {
        return -0x6100;
    }
    return 0;
}

canonical_original_code:
static int chachapoly_setkey_wrap(void *ctx, unsigned char *key, unsigned int key_bitlen)
{
    if (key_bitlen != 256U) {
        return -0x6100;
    }
    if (0 != mbedtls_chachapoly_setkey((struct mbedtls_chachapoly_context *) ctx, key)) {
        return -0x6100;
    }
    return 0;
}

variable_types:
key
unsigned char *

return_type: int


decompiled_code:
void __fastcall chacha20_ctx_free(void *ptr)
{
mbedtls_chacha20_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
mbedtls_chacha20_free();
free(ptr);
}

original_code:
static void chacha20_ctx_free(void *ctx)
{
    mbedtls_chacha20_free((mbedtls_chacha20_context *) ctx);
    free(ctx);
}

canonical_original_code:
static void chacha20_ctx_free(void *ctx)
{
    mbedtls_chacha20_free((struct mbedtls_chacha20_context *) ctx);
    free(ctx);
}


decompiled_code:
void *chacha20_ctx_alloc()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x88uLL);
v1 = v0;
if ( v0 )
mbedtls_chacha20_init(v0);
return v1;
}

canonical_decompiled_code:
void *func4()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x88uLL);
v1 = v0;
if ( v0 )
mbedtls_chacha20_init(v0);
return v1;
}

original_code:
static void *chacha20_ctx_alloc(void)
{
    mbedtls_chacha20_context *ctx;
    ctx = calloc(1, sizeof(mbedtls_chacha20_context));
    if (ctx == ((void *)0)) {
        return ((void *)0);
    }
    mbedtls_chacha20_init(ctx);
    return ctx;
}

canonical_original_code:
static void *chacha20_ctx_alloc()
{
    struct mbedtls_chacha20_context *ctx;
    ctx = calloc(1, sizeof(mbedtls_chacha20_context));
    if (ctx == ((void *)0)) {
        return ((void *)0);
    }
    mbedtls_chacha20_init(ctx);
    return ctx;
}

variable_types: struct mbedtls_chacha20_context { unsigned int state[16]; unsigned char keystream8[64]; unsigned long keystream_bytes_used; } *


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

if ( a3 != 256 )
return 4294942464LL;
result = mbedtls_chacha20_setkey();
if ( (_DWORD)result )
result = 4294942464LL;
return result;
}

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

if ( a3 != 256 )
return 4294942464LL;
result = mbedtls_chacha20_setkey();
if ( (_DWORD)result )
result = 4294942464LL;
return result;
}

original_code:
static int chacha20_setkey_wrap(void *ctx, const unsigned char *key,
                                unsigned int key_bitlen)
{
    if (key_bitlen != 256U) {
        return -0x6100;
    }
    if (0 != mbedtls_chacha20_setkey((mbedtls_chacha20_context *) ctx, key)) {
        return -0x6100;
    }
    return 0;
}

canonical_original_code:
static int chacha20_setkey_wrap(void *ctx, unsigned char *key, unsigned int key_bitlen)
{
    if (key_bitlen != 256U) {
        return -0x6100;
    }
    if (0 != mbedtls_chacha20_setkey((struct mbedtls_chacha20_context *) ctx, key)) {
        return -0x6100;
    }
    return 0;
}


decompiled_code:
__int64 chacha20_stream_wrap()
{
__int64 result; // rax

result = mbedtls_chacha20_update();
if ( (_DWORD)result == -81 )
result = 4294942464LL;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

result = mbedtls_chacha20_update();
if ( (_DWORD)result == -81 )
result = 4294942464LL;
return result;
}

original_code:
static int chacha20_stream_wrap(void *ctx, size_t length,
                                const unsigned char *input,
                                unsigned char *output)
{
    int ret = -0x006E;
    ret = mbedtls_chacha20_update(ctx, length, input, output);
    if (ret == -0x0051) {
        return -0x6100;
    }
    return ret;
}

canonical_original_code:
static int chacha20_stream_wrap(void *ctx, unsigned long length, unsigned char *input, unsigned char *output)
{
    int ret = -0x006E;
    ret = mbedtls_chacha20_update(ctx, length, input, output);
    if (ret == -0x0051) {
        return -0x6100;
    }
    return ret;
}

variable_types:
length
unsigned long

variable_types:
input
unsigned char *

variable_types:
output
unsigned char *

variable_types: ret int


decompiled_code:
void __fastcall ccm_ctx_free(void *ptr)
{
mbedtls_ccm_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
mbedtls_ccm_free();
free(ptr);
}

original_code:
static void ccm_ctx_free(void *ctx)
{
    mbedtls_ccm_free(ctx);
    free(ctx);
}


decompiled_code:
void *ccm_ctx_alloc()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x90uLL);
v1 = v0;
if ( v0 )
mbedtls_ccm_init(v0);
return v1;
}

canonical_decompiled_code:
void *func8()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x90uLL);
v1 = v0;
if ( v0 )
mbedtls_ccm_init(v0);
return v1;
}

original_code:
static void *ccm_ctx_alloc(void)
{
    void *ctx = calloc(1, sizeof(mbedtls_ccm_context));
    if (ctx != ((void *)0)) {
        mbedtls_ccm_init((mbedtls_ccm_context *) ctx);
    }
    return ctx;
}

canonical_original_code:
static void *ccm_ctx_alloc()
{
    void *ctx = calloc(1, sizeof(mbedtls_ccm_context));
    if (ctx != ((void *)0)) {
        mbedtls_ccm_init((struct mbedtls_ccm_context *) ctx);
    }
    return ctx;
}

user_defined_types: struct mbedtls_ccm_context { unsigned char y[16]; unsigned char ctr[16]; struct mbedtls_cipher_context_t cipher_ctx; unsigned long plaintext_len; unsigned long add_len; unsigned long tag_len; unsigned long processed; unsigned char q; unsigned char mode; int state; }

user_defined_types: struct mbedtls_cipher_context_t { struct mbedtls_cipher_info_t *cipher_info; int key_bitlen; enum mbedtls_operation_t operation; unsigned char unprocessed_data[16]; unsigned long unprocessed_len; unsigned char iv[16]; unsigned long iv_size; void *cipher_ctx; }

user_defined_types: enum mbedtls_operation_t { MBEDTLS_OPERATION_NONE=-1, MBEDTLS_DECRYPT=0, MBEDTLS_ENCRYPT=1 }

user_defined_types: struct mbedtls_cipher_info_t { enum mbedtls_cipher_type_t type; enum mbedtls_cipher_mode_t mode; unsigned int key_bitlen; char *name; unsigned int iv_size; int flags; unsigned int block_size; struct mbedtls_cipher_base_t *base; }

user_defined_types: enum mbedtls_cipher_type_t { MBEDTLS_CIPHER_NONE=0, MBEDTLS_CIPHER_NULL=1, MBEDTLS_CIPHER_AES_128_ECB=2, MBEDTLS_CIPHER_AES_192_ECB=3, MBEDTLS_CIPHER_AES_256_ECB=4, MBEDTLS_CIPHER_AES_128_CBC=5, MBEDTLS_CIPHER_AES_192_CBC=6, MBEDTLS_CIPHER_AES_256_CBC=7, MBEDTLS_CIPHER_AES_128_CFB128=8, MBEDTLS_CIPHER_AES_192_CFB128=9, MBEDTLS_CIPHER_AES_256_CFB128=10, MBEDTLS_CIPHER_AES_128_CTR=11, MBEDTLS_CIPHER_AES_192_CTR=12, MBEDTLS_CIPHER_AES_256_CTR=13, MBEDTLS_CIPHER_AES_128_GCM=14, MBEDTLS_CIPHER_AES_192_GCM=15, MBEDTLS_CIPHER_AES_256_GCM=16, MBEDTLS_CIPHER_CAMELLIA_128_ECB=17, MBEDTLS_CIPHER_CAMELLIA_192_ECB=18, MBEDTLS_CIPHER_CAMELLIA_256_ECB=19, MBEDTLS_CIPHER_CAMELLIA_128_CBC=20, MBEDTLS_CIPHER_CAMELLIA_192_CBC=21, MBEDTLS_CIPHER_CAMELLIA_256_CBC=22, MBEDTLS_CIPHER_CAMELLIA_128_CFB128=23, MBEDTLS_CIPHER_CAMELLIA_192_CFB128=24, MBEDTLS_CIPHER_CAMELLIA_256_CFB128=25, MBEDTLS_CIPHER_CAMELLIA_128_CTR=26, MBEDTLS_CIPHER_CAMELLIA_192_CTR=27, MBEDTLS_CIPHER_CAMELLIA_256_CTR=28, MBEDTLS_CIPHER_CAMELLIA_128_GCM=29, MBEDTLS_CIPHER_CAMELLIA_192_GCM=30, MBEDTLS_CIPHER_CAMELLIA_256_GCM=31, MBEDTLS_CIPHER_DES_ECB=32, MBEDTLS_CIPHER_DES_CBC=33, MBEDTLS_CIPHER_DES_EDE_ECB=34, MBEDTLS_CIPHER_DES_EDE_CBC=35, MBEDTLS_CIPHER_DES_EDE3_ECB=36, MBEDTLS_CIPHER_DES_EDE3_CBC=37, MBEDTLS_CIPHER_AES_128_CCM=38, MBEDTLS_CIPHER_AES_192_CCM=39, MBEDTLS_CIPHER_AES_256_CCM=40, MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG=41, MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG=42, MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG=43, MBEDTLS_CIPHER_CAMELLIA_128_CCM=44, MBEDTLS_CIPHER_CAMELLIA_192_CCM=45, MBEDTLS_CIPHER_CAMELLIA_256_CCM=46, MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG=47, MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG=48, MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG=49, MBEDTLS_CIPHER_ARIA_128_ECB=50, MBEDTLS_CIPHER_ARIA_192_ECB=51, MBEDTLS_CIPHER_ARIA_256_ECB=52, MBEDTLS_CIPHER_ARIA_128_CBC=53, MBEDTLS_CIPHER_ARIA_192_CBC=54, MBEDTLS_CIPHER_ARIA_256_CBC=55, MBEDTLS_CIPHER_ARIA_128_CFB128=56, MBEDTLS_CIPHER_ARIA_192_CFB128=57, MBEDTLS_CIPHER_ARIA_256_CFB128=58, MBEDTLS_CIPHER_ARIA_128_CTR=59, MBEDTLS_CIPHER_ARIA_192_CTR=60, MBEDTLS_CIPHER_ARIA_256_CTR=61, MBEDTLS_CIPHER_ARIA_128_GCM=62, MBEDTLS_CIPHER_ARIA_192_GCM=63, MBEDTLS_CIPHER_ARIA_256_GCM=64, MBEDTLS_CIPHER_ARIA_128_CCM=65, MBEDTLS_CIPHER_ARIA_192_CCM=66, MBEDTLS_CIPHER_ARIA_256_CCM=67, MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG=68, MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG=69, MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG=70, MBEDTLS_CIPHER_AES_128_OFB=71, MBEDTLS_CIPHER_AES_192_OFB=72, MBEDTLS_CIPHER_AES_256_OFB=73, MBEDTLS_CIPHER_AES_128_XTS=74, MBEDTLS_CIPHER_AES_256_XTS=75, MBEDTLS_CIPHER_CHACHA20=76, MBEDTLS_CIPHER_CHACHA20_POLY1305=77, MBEDTLS_CIPHER_AES_128_KW=78, MBEDTLS_CIPHER_AES_192_KW=79, MBEDTLS_CIPHER_AES_256_KW=80, MBEDTLS_CIPHER_AES_128_KWP=81, MBEDTLS_CIPHER_AES_192_KWP=82, MBEDTLS_CIPHER_AES_256_KWP=83 }

user_defined_types: enum mbedtls_cipher_mode_t { MBEDTLS_MODE_NONE=0, MBEDTLS_MODE_ECB=1, MBEDTLS_MODE_CBC=2, MBEDTLS_MODE_CFB=3, MBEDTLS_MODE_OFB=4, MBEDTLS_MODE_CTR=5, MBEDTLS_MODE_GCM=6, MBEDTLS_MODE_STREAM=7, MBEDTLS_MODE_CCM=8, MBEDTLS_MODE_CCM_STAR_NO_TAG=9, MBEDTLS_MODE_XTS=10, MBEDTLS_MODE_CHACHAPOLY=11, MBEDTLS_MODE_KW=12, MBEDTLS_MODE_KWP=13 }

user_defined_types: struct mbedtls_cipher_base_t { enum mbedtls_cipher_id_t cipher; int (*ecb_func)(void *ctx, enum mbedtls_operation_t mode, unsigned char *input, unsigned char *output); int (*stream_func)(void *ctx, unsigned long length, unsigned char *input, unsigned char *output); int (*setkey_enc_func)(void *ctx, unsigned char *key, unsigned int key_bitlen); int (*setkey_dec_func)(void *ctx, unsigned char *key, unsigned int key_bitlen); void *(*ctx_alloc_func)(); void (*ctx_free_func)(void *ctx); }

user_defined_types: enum mbedtls_cipher_id_t { MBEDTLS_CIPHER_ID_NONE=0, MBEDTLS_CIPHER_ID_NULL=1, MBEDTLS_CIPHER_ID_AES=2, MBEDTLS_CIPHER_ID_DES=3, MBEDTLS_CIPHER_ID_3DES=4, MBEDTLS_CIPHER_ID_CAMELLIA=5, MBEDTLS_CIPHER_ID_ARIA=6, MBEDTLS_CIPHER_ID_CHACHA20=7 }


decompiled_code:
__int64 __fastcall ccm_aes_setkey_wrap(__int64 a1, __int64 a2, unsigned int a3)
{
return mbedtls_ccm_setkey(a1, 2LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned int a3)
{
return mbedtls_ccm_setkey(a1, 2LL, a2, a3);
}

original_code:
static int ccm_aes_setkey_wrap(void *ctx, const unsigned char *key,
                               unsigned int key_bitlen)
{
    return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
                              key, key_bitlen);
}

canonical_original_code:
static int ccm_aes_setkey_wrap(void *ctx, unsigned char *key, unsigned int key_bitlen)
{
    return mbedtls_ccm_setkey((struct mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
                              key, key_bitlen);
}


decompiled_code:
void __fastcall gcm_ctx_free(void *ptr)
{
mbedtls_gcm_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
mbedtls_gcm_free();
free(ptr);
}

original_code:
static void gcm_ctx_free(void *ctx)
{
    mbedtls_gcm_free(ctx);
    free(ctx);
}


decompiled_code:
void *gcm_ctx_alloc()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x190uLL);
v1 = v0;
if ( v0 )
mbedtls_gcm_init(v0);
return v1;
}

canonical_decompiled_code:
void *func11()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x190uLL);
v1 = v0;
if ( v0 )
mbedtls_gcm_init(v0);
return v1;
}

original_code:
static void *gcm_ctx_alloc(void)
{
    void *ctx = calloc(1, sizeof(mbedtls_gcm_context));
    if (ctx != ((void *)0)) {
        mbedtls_gcm_init((mbedtls_gcm_context *) ctx);
    }
    return ctx;
}

canonical_original_code:
static void *gcm_ctx_alloc()
{
    void *ctx = calloc(1, sizeof(mbedtls_gcm_context));
    if (ctx != ((void *)0)) {
        mbedtls_gcm_init((struct mbedtls_gcm_context *) ctx);
    }
    return ctx;
}

user_defined_types: struct mbedtls_gcm_context { struct mbedtls_cipher_context_t cipher_ctx; unsigned long HL[16]; unsigned long HH[16]; unsigned long len; unsigned long add_len; unsigned char base_ectr[16]; unsigned char y[16]; unsigned char buf[16]; int mode; }


decompiled_code:
__int64 __fastcall gcm_aes_setkey_wrap(__int64 a1, __int64 a2, unsigned int a3)
{
return mbedtls_gcm_setkey(a1, 2LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, unsigned int a3)
{
return mbedtls_gcm_setkey(a1, 2LL, a2, a3);
}

original_code:
static int gcm_aes_setkey_wrap(void *ctx, const unsigned char *key,
                               unsigned int key_bitlen)
{
    return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
                              key, key_bitlen);
}

canonical_original_code:
static int gcm_aes_setkey_wrap(void *ctx, unsigned char *key, unsigned int key_bitlen)
{
    return mbedtls_gcm_setkey((struct mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
                              key, key_bitlen);
}


decompiled_code:
void __fastcall aes_ctx_free(void *ptr)
{
mbedtls_aes_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
mbedtls_aes_free();
free(ptr);
}

original_code:
static void aes_ctx_free(void *ctx)
{
    mbedtls_aes_free((mbedtls_aes_context *) ctx);
    free(ctx);
}

canonical_original_code:
static void aes_ctx_free(void *ctx)
{
    mbedtls_aes_free((struct mbedtls_aes_context *) ctx);
    free(ctx);
}

user_defined_types: struct mbedtls_aes_context { int nr; unsigned long rk_offset; unsigned int buf[68]; }


decompiled_code:
void *aes_ctx_alloc()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x120uLL);
v1 = v0;
if ( v0 )
mbedtls_aes_init(v0);
return v1;
}

canonical_decompiled_code:
void *func14()
{
void *v0; // rax
void *v1; // rbx

v0 = calloc(1uLL, 0x120uLL);
v1 = v0;
if ( v0 )
mbedtls_aes_init(v0);
return v1;
}

original_code:
static void *aes_ctx_alloc(void)
{
    mbedtls_aes_context *aes = calloc(1, sizeof(mbedtls_aes_context));
    if (aes == ((void *)0)) {
        return ((void *)0);
    }
    mbedtls_aes_init(aes);
    return aes;
}

canonical_original_code:
static void *aes_ctx_alloc()
{
    struct mbedtls_aes_context *aes = calloc(1, sizeof(mbedtls_aes_context));
    if (aes == ((void *)0)) {
        return ((void *)0);
    }
    mbedtls_aes_init(aes);
    return aes;
}

variable_types: struct mbedtls_aes_context { int nr; unsigned long rk_offset; unsigned int buf[68]; } *


decompiled_code:
__int64 aes_setkey_dec_wrap()
{
return mbedtls_aes_setkey_dec();
}

canonical_decompiled_code:
__int64 func15()
{
return mbedtls_aes_setkey_dec();
}

original_code:
static int aes_setkey_dec_wrap(void *ctx, const unsigned char *key,
                               unsigned int key_bitlen)
{
    return mbedtls_aes_setkey_dec((mbedtls_aes_context *) ctx, key, key_bitlen);
}

canonical_original_code:
static int aes_setkey_dec_wrap(void *ctx, unsigned char *key, unsigned int key_bitlen)
{
    return mbedtls_aes_setkey_dec((struct mbedtls_aes_context *) ctx, key, key_bitlen);
}


decompiled_code:
__int64 aes_setkey_enc_wrap()
{
return mbedtls_aes_setkey_enc();
}

canonical_decompiled_code:
__int64 func16()
{
return mbedtls_aes_setkey_enc();
}

original_code:
static int aes_setkey_enc_wrap(void *ctx, const unsigned char *key,
                               unsigned int key_bitlen)
{
    return mbedtls_aes_setkey_enc((mbedtls_aes_context *) ctx, key, key_bitlen);
}

canonical_original_code:
static int aes_setkey_enc_wrap(void *ctx, unsigned char *key, unsigned int key_bitlen)
{
    return mbedtls_aes_setkey_enc((struct mbedtls_aes_context *) ctx, key, key_bitlen);
}


decompiled_code:
__int64 aes_crypt_ecb_wrap()
{
return mbedtls_aes_crypt_ecb();
}

canonical_decompiled_code:
__int64 func17()
{
return mbedtls_aes_crypt_ecb();
}

original_code:
static int aes_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation,
                              const unsigned char *input, unsigned char *output)
{
    return mbedtls_aes_crypt_ecb((mbedtls_aes_context *) ctx, operation, input, output);
}

canonical_original_code:
static int aes_crypt_ecb_wrap(void *ctx, enum mbedtls_operation_t operation, unsigned char *input, unsigned char *output)
{
    return mbedtls_aes_crypt_ecb((struct mbedtls_aes_context *) ctx, operation, input, output);
}

variable_types: enum mbedtls_operation_t { MBEDTLS_OPERATION_NONE=-1, MBEDTLS_DECRYPT=0, MBEDTLS_ENCRYPT=1 }


decompiled_code:
__int64 __fastcall chachapoly_pad_aad(__int64 a1)
{
int v1; // eax
__int64 v3; // [rsp+1h] [rbp-17h] BYREF
int v4; // [rsp+9h] [rbp-Fh]
__int16 v5; // [rsp+Dh] [rbp-Bh]
char v6; // [rsp+Fh] [rbp-9h]

v1 = *(_DWORD *)(a1 + 216) & 0xF;
if ( !v1 )
return 0LL;
v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0;
return mbedtls_poly1305_update(a1 + 136, &v3, (unsigned int)(16 - v1));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
__int64 v3; // [rsp+1h] [rbp-17h] BYREF
int v4; // [rsp+9h] [rbp-Fh]
__int16 v5; // [rsp+Dh] [rbp-Bh]
char v6; // [rsp+Fh] [rbp-9h]

v1 = *(_DWORD *)(a1 + 216) & 0xF;
if ( !v1 )
return 0LL;
v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0;
return mbedtls_poly1305_update(a1 + 136, &v3, (unsigned int)(16 - v1));
}

original_code:
static int chachapoly_pad_aad(mbedtls_chachapoly_context *ctx)
{
    uint32_t partial_block_len = (uint32_t) (ctx->aad_len % 16U);
    unsigned char zeroes[15];
    if (partial_block_len == 0U) {
        return 0;
    }
    memset(zeroes, 0, sizeof(zeroes));
    return mbedtls_poly1305_update(&ctx->poly1305_ctx,
                                   zeroes,
                                   16U - partial_block_len);
}

canonical_original_code:
static int chachapoly_pad_aad(struct mbedtls_chachapoly_context *ctx)
{
    unsigned int partial_block_len = (uint32_t) (ctx->aad_len % 16U);
    unsigned char zeroes[15];
    if (partial_block_len == 0U) {
        return 0;
    }
    memset(zeroes, 0, sizeof(zeroes));
    return mbedtls_poly1305_update(&ctx->poly1305_ctx,
                                   zeroes,
                                   16U - partial_block_len);
}

variable_types:
zeroes
unsigned char [15]


decompiled_code:
__int64 __fastcall chachapoly_pad_ciphertext(__int64 a1)
{
int v1; // eax
__int64 v3; // [rsp+1h] [rbp-17h] BYREF
int v4; // [rsp+9h] [rbp-Fh]
__int16 v5; // [rsp+Dh] [rbp-Bh]
char v6; // [rsp+Fh] [rbp-9h]

v1 = *(_DWORD *)(a1 + 224) & 0xF;
if ( !v1 )
return 0LL;
v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0;
return mbedtls_poly1305_update(a1 + 136, &v3, (unsigned int)(16 - v1));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
__int64 v3; // [rsp+1h] [rbp-17h] BYREF
int v4; // [rsp+9h] [rbp-Fh]
__int16 v5; // [rsp+Dh] [rbp-Bh]
char v6; // [rsp+Fh] [rbp-9h]

v1 = *(_DWORD *)(a1 + 224) & 0xF;
if ( !v1 )
return 0LL;
v3 = 0LL;
v4 = 0;
v5 = 0;
v6 = 0;
return mbedtls_poly1305_update(a1 + 136, &v3, (unsigned int)(16 - v1));
}

original_code:
static int chachapoly_pad_ciphertext(mbedtls_chachapoly_context *ctx)
{
    uint32_t partial_block_len = (uint32_t) (ctx->ciphertext_len % 16U);
    unsigned char zeroes[15];
    if (partial_block_len == 0U) {
        return 0;
    }
    memset(zeroes, 0, sizeof(zeroes));
    return mbedtls_poly1305_update(&ctx->poly1305_ctx,
                                   zeroes,
                                   16U - partial_block_len);
}

canonical_original_code:
static int chachapoly_pad_ciphertext(struct mbedtls_chachapoly_context *ctx)
{
    unsigned int partial_block_len = (uint32_t) (ctx->ciphertext_len % 16U);
    unsigned char zeroes[15];
    if (partial_block_len == 0U) {
        return 0;
    }
    memset(zeroes, 0, sizeof(zeroes));
    return mbedtls_poly1305_update(&ctx->poly1305_ctx,
                                   zeroes,
                                   16U - partial_block_len);
}


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

mbedtls_chacha20_init();
result = mbedtls_poly1305_init(a1 + 136);
*(_QWORD *)(a1 + 216) = 0LL;
*(_QWORD *)(a1 + 224) = 0LL;
*(_DWORD *)(a1 + 232) = 0;
*(_DWORD *)(a1 + 236) = 0;
return result;
}

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

mbedtls_chacha20_init();
result = mbedtls_poly1305_init(a1 + 136);
*(_QWORD *)(a1 + 216) = 0LL;
*(_QWORD *)(a1 + 224) = 0LL;
*(_DWORD *)(a1 + 232) = 0;
*(_DWORD *)(a1 + 236) = 0;
return result;
}

original_code:
void mbedtls_chachapoly_init(mbedtls_chachapoly_context *ctx)
{
    mbedtls_chacha20_init(&ctx->chacha20_ctx);
    mbedtls_poly1305_init(&ctx->poly1305_ctx);
    ctx->aad_len = 0U;
    ctx->ciphertext_len = 0U;
    ctx->state = (0);
    ctx->mode = MBEDTLS_CHACHAPOLY_ENCRYPT;
}

canonical_original_code:
void mbedtls_chachapoly_init(struct mbedtls_chachapoly_context *ctx)
{
    mbedtls_chacha20_init(&ctx->chacha20_ctx);
    mbedtls_poly1305_init(&ctx->poly1305_ctx);
    ctx->aad_len = 0U;
    ctx->ciphertext_len = 0U;
    ctx->state = (0);
    ctx->mode = MBEDTLS_CHACHAPOLY_ENCRYPT;
}


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

if ( a1 )
{
mbedtls_chacha20_free();
result = mbedtls_poly1305_free(a1 + 136);
*(_QWORD *)(a1 + 216) = 0LL;
*(_QWORD *)(a1 + 224) = 0LL;
*(_DWORD *)(a1 + 232) = 0;
*(_DWORD *)(a1 + 236) = 0;
}
return result;
}

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

if ( a1 )
{
mbedtls_chacha20_free();
result = mbedtls_poly1305_free(a1 + 136);
*(_QWORD *)(a1 + 216) = 0LL;
*(_QWORD *)(a1 + 224) = 0LL;
*(_DWORD *)(a1 + 232) = 0;
*(_DWORD *)(a1 + 236) = 0;
}
return result;
}

original_code:
void mbedtls_chachapoly_free(mbedtls_chachapoly_context *ctx)
{
    if (ctx == ((void *)0)) {
        return;
    }
    mbedtls_chacha20_free(&ctx->chacha20_ctx);
    mbedtls_poly1305_free(&ctx->poly1305_ctx);
    ctx->aad_len = 0U;
    ctx->ciphertext_len = 0U;
    ctx->state = (0);
    ctx->mode = MBEDTLS_CHACHAPOLY_ENCRYPT;
}

canonical_original_code:
void mbedtls_chachapoly_free(struct mbedtls_chachapoly_context *ctx)
{
    if (ctx == ((void *)0)) {
        return;
    }
    mbedtls_chacha20_free(&ctx->chacha20_ctx);
    mbedtls_poly1305_free(&ctx->poly1305_ctx);
    ctx->aad_len = 0U;
    ctx->ciphertext_len = 0U;
    ctx->state = (0);
    ctx->mode = MBEDTLS_CHACHAPOLY_ENCRYPT;
}


decompiled_code:
__int64 mbedtls_chachapoly_setkey()
{
return mbedtls_chacha20_setkey();
}

canonical_decompiled_code:
__int64 func4()
{
return mbedtls_chacha20_setkey();
}

original_code:
int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context *ctx,
                              const unsigned char key[32])
{
    int ret = -0x006E;
    ret = mbedtls_chacha20_setkey(&ctx->chacha20_ctx, key);
    return ret;
}

canonical_original_code:
int mbedtls_chachapoly_setkey(struct mbedtls_chachapoly_context *ctx, unsigned char key[32])
{
    int ret = -0x006E;
    ret = mbedtls_chacha20_setkey(&ctx->chacha20_ctx, key);
    return ret;
}

variable_types:
key
unsigned char [32]


original_code:
int mbedtls_chachapoly_starts(mbedtls_chachapoly_context *ctx,
                              const unsigned char nonce[12],
                              mbedtls_chachapoly_mode_t mode)
{
    int ret = -0x006E;
    unsigned char poly1305_key[64];
    ret = mbedtls_chacha20_starts(&ctx->chacha20_ctx, nonce, 0U);
    if (ret != 0) {
        goto cleanup;
    }
    memset(poly1305_key, 0, sizeof(poly1305_key));
    ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, sizeof(poly1305_key),
                                  poly1305_key, poly1305_key);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_poly1305_starts(&ctx->poly1305_ctx, poly1305_key);
    if (ret == 0) {
        ctx->aad_len = 0U;
        ctx->ciphertext_len = 0U;
        ctx->state = (1);
        ctx->mode = mode;
    }
cleanup:
    mbedtls_platform_zeroize(poly1305_key, 64U);
    return ret;
}

canonical_original_code:
int mbedtls_chachapoly_starts(struct mbedtls_chachapoly_context *ctx, unsigned char nonce[12], enum mbedtls_chachapoly_mode_t mode)
{
    int ret = -0x006E;
    unsigned char poly1305_key[64];
    ret = mbedtls_chacha20_starts(&ctx->chacha20_ctx, nonce, 0U);
    if (ret != 0) {
        goto cleanup;
    }
    memset(poly1305_key, 0, sizeof(poly1305_key));
    ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, sizeof(poly1305_key),
                                  poly1305_key, poly1305_key);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_poly1305_starts(&ctx->poly1305_ctx, poly1305_key);
    if (ret == 0) {
        ctx->aad_len = 0U;
        ctx->ciphertext_len = 0U;
        ctx->state = (1);
        ctx->mode = mode;
    }
cleanup:
    mbedtls_platform_zeroize(poly1305_key, 64U);
    return ret;
}

variable_types:
nonce
unsigned char [12]

variable_types: enum mbedtls_chachapoly_mode_t { MBEDTLS_CHACHAPOLY_ENCRYPT=0, MBEDTLS_CHACHAPOLY_DECRYPT=1 }


decompiled_code:
__int64 __fastcall mbedtls_chachapoly_update_aad(__int64 a1, __int64 a2, __int64 a3)
{
if ( *(_DWORD *)(a1 + 232) != 1 )
return 4294967212LL;
*(_QWORD *)(a1 + 216) += a3;
return mbedtls_poly1305_update(a1 + 136, a2, a3);
}

original_code:
int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context *ctx,
                                  const unsigned char *aad,
                                  size_t aad_len)
{
    if (ctx->state != (1)) {
        return -0x0054;
    }
    ctx->aad_len += aad_len;
    return mbedtls_poly1305_update(&ctx->poly1305_ctx, aad, aad_len);
}

canonical_original_code:
int mbedtls_chachapoly_update_aad(struct mbedtls_chachapoly_context *ctx, unsigned char *aad, unsigned long aad_len)
{
    if (ctx->state != (1)) {
        return -0x0054;
    }
    ctx->aad_len += aad_len;
    return mbedtls_poly1305_update(&ctx->poly1305_ctx, aad, aad_len);
}

variable_types:
aad
unsigned char *


decompiled_code:
__int64 __fastcall mbedtls_chachapoly_update(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // eax
__int64 result; // rax

v5 = *(_DWORD *)(a1 + 232);
if ( (unsigned int)(v5 - 1) > 1 )
return 4294967212LL;
if ( v5 != 1 || (*(_DWORD *)(a1 + 232) = 2, result = chachapoly_pad_aad(a1), !(_DWORD)result) )
{
*(_QWORD *)(a1 + 224) += a2;
if ( *(_DWORD *)(a1 + 236) )
{
result = mbedtls_poly1305_update(a1 + 136, a3, a2);
if ( !(_DWORD)result )
result = mbedtls_chacha20_update(a1, a2, a3, a4);
}
else
{
result = mbedtls_chacha20_update(a1, a2, a3, a4);
if ( !(_DWORD)result )
result = mbedtls_poly1305_update(a1 + 136, a4, a2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v5; // eax
__int64 result; // rax

v5 = *(_DWORD *)(a1 + 232);
if ( (unsigned int)(v5 - 1) > 1 )
return 4294967212LL;
if ( v5 != 1 || (*(_DWORD *)(a1 + 232) = 2, result = func0(a1), !(_DWORD)result) )
{
*(_QWORD *)(a1 + 224) += a2;
if ( *(_DWORD *)(a1 + 236) )
{
result = mbedtls_poly1305_update(a1 + 136, a3, a2);
if ( !(_DWORD)result )
result = mbedtls_chacha20_update(a1, a2, a3, a4);
}
else
{
result = mbedtls_chacha20_update(a1, a2, a3, a4);
if ( !(_DWORD)result )
result = mbedtls_poly1305_update(a1 + 136, a4, a2);
}
}
return result;
}

original_code:
int mbedtls_chachapoly_update(mbedtls_chachapoly_context *ctx,
                              size_t len,
                              const unsigned char *input,
                              unsigned char *output)
{
    int ret = -0x006E;
    if ((ctx->state != (1)) &&
        (ctx->state != (2))) {
        return -0x0054;
    }
    if (ctx->state == (1)) {
        ctx->state = (2);
        ret = chachapoly_pad_aad(ctx);
        if (ret != 0) {
            return ret;
        }
    }
    ctx->ciphertext_len += len;
    if (ctx->mode == MBEDTLS_CHACHAPOLY_ENCRYPT) {
        ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, len, input, output);
        if (ret != 0) {
            return ret;
        }
        ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, output, len);
        if (ret != 0) {
            return ret;
        }
    } else {
        ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, input, len);
        if (ret != 0) {
            return ret;
        }
        ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, len, input, output);
        if (ret != 0) {
            return ret;
        }
    }
    return 0;
}

canonical_original_code:
int mbedtls_chachapoly_update(struct mbedtls_chachapoly_context *ctx, unsigned long len, unsigned char *input, unsigned char *output)
{
    int ret = -0x006E;
    if ((ctx->state != (1)) &&
        (ctx->state != (2))) {
        return -0x0054;
    }
    if (ctx->state == (1)) {
        ctx->state = (2);
        ret = chachapoly_pad_aad(ctx);
        if (ret != 0) {
            return ret;
        }
    }
    ctx->ciphertext_len += len;
    if (ctx->mode == MBEDTLS_CHACHAPOLY_ENCRYPT) {
        ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, len, input, output);
        if (ret != 0) {
            return ret;
        }
        ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, output, len);
        if (ret != 0) {
            return ret;
        }
    } else {
        ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, input, len);
        if (ret != 0) {
            return ret;
        }
        ret = mbedtls_chacha20_update(&ctx->chacha20_ctx, len, input, output);
        if (ret != 0) {
            return ret;
        }
    }
    return 0;
}

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall mbedtls_chachapoly_finish(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4; // [rsp-8h] [rbp-28h] BYREF
char v5[32]; // [rsp+0h] [rbp-20h] BYREF

v2 = *(_DWORD *)(a1 + 232);
if ( !v2 )
return 4294967212LL;
if ( v2 == 1 )
{
result = chachapoly_pad_aad(a1);
if ( (_DWORD)result )
return result;
goto LABEL_4;
}
if ( v2 != 2 || (result = chachapoly_pad_ciphertext(a1), !(_DWORD)result) )
{
LABEL_4:
*(_DWORD *)(a1 + 232) = 3;
mbedtls_put_unaligned_uint64(&v4, *(_QWORD *)(a1 + 216));
mbedtls_put_unaligned_uint64(v5, *(_QWORD *)(a1 + 224));
result = mbedtls_poly1305_update(a1 + 136, &v4, 16LL);
if ( !(_DWORD)result )
result = mbedtls_poly1305_finish(a1 + 136, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
__int64 v4; // [rsp-8h] [rbp-28h] BYREF
char v5[32]; // [rsp+0h] [rbp-20h] BYREF

v2 = *(_DWORD *)(a1 + 232);
if ( !v2 )
return 4294967212LL;
if ( v2 == 1 )
{
result = func0(a1);
if ( (_DWORD)result )
return result;
goto LABEL_4;
}
if ( v2 != 2 || (result = func1(a1), !(_DWORD)result) )
{
LABEL_4:
*(_DWORD *)(a1 + 232) = 3;
mbedtls_put_unaligned_uint64(&v4, *(_QWORD *)(a1 + 216));
mbedtls_put_unaligned_uint64(v5, *(_QWORD *)(a1 + 224));
result = mbedtls_poly1305_update(a1 + 136, &v4, 16LL);
if ( !(_DWORD)result )
result = mbedtls_poly1305_finish(a1 + 136, a2);
}
return result;
}

original_code:
int mbedtls_chachapoly_finish(mbedtls_chachapoly_context *ctx,
                              unsigned char mac[16])
{
    int ret = -0x006E;
    unsigned char len_block[16];
    if (ctx->state == (0)) {
        return -0x0054;
    }
    if (ctx->state == (1)) {
        ret = chachapoly_pad_aad(ctx);
        if (ret != 0) {
            return ret;
        }
    } else if (ctx->state == (2)) {
        ret = chachapoly_pad_ciphertext(ctx);
        if (ret != 0) {
            return ret;
        }
    }
    ctx->state = (3);
    { if (((1234) == (4321))) { mbedtls_put_unaligned_uint64((len_block) + (0), __builtin_bswap64((uint64_t) (ctx->aad_len))); } else { mbedtls_put_unaligned_uint64((len_block) + (0), (uint64_t) (ctx->aad_len)); } };
    { if (((1234) == (4321))) { mbedtls_put_unaligned_uint64((len_block) + (8), __builtin_bswap64((uint64_t) (ctx->ciphertext_len))); } else { mbedtls_put_unaligned_uint64((len_block) + (8), (uint64_t) (ctx->ciphertext_len)); } };
    ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, len_block, 16U);
    if (ret != 0) {
        return ret;
    }
    ret = mbedtls_poly1305_finish(&ctx->poly1305_ctx, mac);
    return ret;
}

canonical_original_code:
int mbedtls_chachapoly_finish(struct mbedtls_chachapoly_context *ctx, unsigned char mac[16])
{
    int ret = -0x006E;
    unsigned char len_block[16];
    if (ctx->state == (0)) {
        return -0x0054;
    }
    if (ctx->state == (1)) {
        ret = chachapoly_pad_aad(ctx);
        if (ret != 0) {
            return ret;
        }
    } else if (ctx->state == (2)) {
        ret = chachapoly_pad_ciphertext(ctx);
        if (ret != 0) {
            return ret;
        }
    }
    ctx->state = (3);
    { if (((1234) == (4321))) { mbedtls_put_unaligned_uint64((len_block) + (0), __builtin_bswap64((unsigned long) (ctx->aad_len))); } else { mbedtls_put_unaligned_uint64((len_block) + (0), (unsigned long) (ctx->aad_len)); } };
    { if (((1234) == (4321))) { mbedtls_put_unaligned_uint64((len_block) + (8), __builtin_bswap64((unsigned long) (ctx->ciphertext_len))); } else { mbedtls_put_unaligned_uint64((len_block) + (8), (unsigned long) (ctx->ciphertext_len)); } };
    ret = mbedtls_poly1305_update(&ctx->poly1305_ctx, len_block, 16U);
    if (ret != 0) {
        return ret;
    }
    ret = mbedtls_poly1305_finish(&ctx->poly1305_ctx, mac);
    return ret;
}

variable_types:
mac
unsigned char [16]


decompiled_code:
__int64 __fastcall chachapoly_crypt_and_tag(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 result; // rax

result = mbedtls_chachapoly_starts(a1, a4, a2);
if ( !(_DWORD)result )
{
result = mbedtls_chachapoly_update_aad(a1, a5, a6);
if ( !(_DWORD)result )
{
result = mbedtls_chachapoly_update(a1, a3, a7, a8);
if ( !(_DWORD)result )
result = mbedtls_chachapoly_finish(a1, a9);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, __int64 a9)
{
__int64 result; // rax

result = func5(a1, a4, a2);
if ( !(_DWORD)result )
{
result = func6(a1, a5, a6);
if ( !(_DWORD)result )
{
result = func7(a1, a3, a7, a8);
if ( !(_DWORD)result )
result = func8(a1, a9);
}
}
return result;
}

original_code:
static int chachapoly_crypt_and_tag(mbedtls_chachapoly_context *ctx,
                                    mbedtls_chachapoly_mode_t mode,
                                    size_t length,
                                    const unsigned char nonce[12],
                                    const unsigned char *aad,
                                    size_t aad_len,
                                    const unsigned char *input,
                                    unsigned char *output,
                                    unsigned char tag[16])
{
    int ret = -0x006E;
    ret = mbedtls_chachapoly_starts(ctx, nonce, mode);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_chachapoly_update_aad(ctx, aad, aad_len);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_chachapoly_update(ctx, length, input, output);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_chachapoly_finish(ctx, tag);
cleanup:
    return ret;
}

canonical_original_code:
static int chachapoly_crypt_and_tag(struct mbedtls_chachapoly_context *ctx, enum mbedtls_chachapoly_mode_t mode, unsigned long length, unsigned char nonce[12], unsigned char *aad, unsigned long aad_len, unsigned char *input, unsigned char *output, unsigned char tag[16])
{
    int ret = -0x006E;
    ret = mbedtls_chachapoly_starts(ctx, nonce, mode);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_chachapoly_update_aad(ctx, aad, aad_len);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_chachapoly_update(ctx, length, input, output);
    if (ret != 0) {
        goto cleanup;
    }
    ret = mbedtls_chachapoly_finish(ctx, tag);
cleanup:
    return ret;
}

variable_types:
tag
unsigned char [16]


decompiled_code:
__int64 __fastcall mbedtls_chachapoly_encrypt_and_tag(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
return chachapoly_crypt_and_tag(a1, 0, a2, a3, a4, a5, a6, a7, a8);
}

original_code:
int mbedtls_chachapoly_encrypt_and_tag(mbedtls_chachapoly_context *ctx,
                                       size_t length,
                                       const unsigned char nonce[12],
                                       const unsigned char *aad,
                                       size_t aad_len,
                                       const unsigned char *input,
                                       unsigned char *output,
                                       unsigned char tag[16])
{
    return chachapoly_crypt_and_tag(ctx, MBEDTLS_CHACHAPOLY_ENCRYPT,
                                    length, nonce, aad, aad_len,
                                    input, output, tag);
}

canonical_original_code:
int mbedtls_chachapoly_encrypt_and_tag(struct mbedtls_chachapoly_context *ctx, unsigned long length, unsigned char nonce[12], unsigned char *aad, unsigned long aad_len, unsigned char *input, unsigned char *output, unsigned char tag[16])
{
    return chachapoly_crypt_and_tag(ctx, MBEDTLS_CHACHAPOLY_ENCRYPT,
                                    length, nonce, aad, aad_len,
                                    input, output, tag);
}

variable_types: struct mbedtls_chachapoly_context { struct mbedtls_chacha20_context { unsigned int state[16]; unsigned char keystream8[64]; unsigned long keystream_bytes_used; } chacha20_ctx; struct mbedtls_poly1305_context { unsigned int r[4]; unsigned int s[4]; unsigned int acc[5]; unsigned char queue[16]; unsigned long queue_len; } poly1305_ctx; unsigned long aad_len; unsigned long ciphertext_len; int state; enum mbedtls_chachapoly_mode_t { MBEDTLS_CHACHAPOLY_ENCRYPT=0, MBEDTLS_CHACHAPOLY_DECRYPT=1 } mode; } *


decompiled_code:
__int64 __fastcall mbedtls_chachapoly_auth_decrypt(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
unsigned int v9; // ecx
__int64 i; // rdx
char v12[40]; // [rsp+8h] [rbp-28h] BYREF

v9 = chachapoly_crypt_and_tag(a1, 1, a2, a3, a4, a5, a7, a8, (__int64)v12);
if ( !v9 )
{
for ( i = 0LL; i != 16; ++i )
v9 |= (unsigned __int8)(v12[i] ^ *(_BYTE *)(a6 + i));
if ( v9 )
{
mbedtls_platform_zeroize(a8, a2);
v9 = -86;
}
}
return v9;
}

original_code:
int mbedtls_chachapoly_auth_decrypt(mbedtls_chachapoly_context *ctx,
                                    size_t length,
                                    const unsigned char nonce[12],
                                    const unsigned char *aad,
                                    size_t aad_len,
                                    const unsigned char tag[16],
                                    const unsigned char *input,
                                    unsigned char *output)
{
    int ret = -0x006E;
    unsigned char check_tag[16];
    size_t i;
    int diff;
    if ((ret = chachapoly_crypt_and_tag(ctx,
                                        MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce,
                                        aad, aad_len, input, output, check_tag)) != 0) {
        return ret;
    }
    for (diff = 0, i = 0; i < sizeof(check_tag); i++) {
        diff |= tag[i] ^ check_tag[i];
    }
    if (diff != 0) {
        mbedtls_platform_zeroize(output, length);
        return -0x0056;
    }
    return 0;
}

canonical_original_code:
int mbedtls_chachapoly_auth_decrypt(struct mbedtls_chachapoly_context *ctx, unsigned long length, unsigned char nonce[12], unsigned char *aad, unsigned long aad_len, unsigned char tag[16], unsigned char *input, unsigned char *output)
{
    int ret = -0x006E;
    unsigned char check_tag[16];
    unsigned long i;
    int diff;
    if ((ret = chachapoly_crypt_and_tag(ctx,
                                        MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce,
                                        aad, aad_len, input, output, check_tag)) != 0) {
        return ret;
    }
    for (diff = 0, i = 0; i < sizeof(check_tag); i++) {
        diff |= tag[i] ^ check_tag[i];
    }
    if (diff != 0) {
        mbedtls_platform_zeroize(output, length);
        return -0x0056;
    }
    return 0;
}

variable_types:
i
unsigned long

variable_types: diff int


decompiled_code:
__int64 __fastcall mode_bit(unsigned __int8 a1)
{
return (unsigned int)mode_bits_0[(*_ctype_tolower_loc())[a1]];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return (unsigned int)mode_bits_0[(*_ctype_tolower_loc())[a1]];
}

variable_types:
c
unsigned char

return_type: unsigned int


decompiled_code:
_BOOL8 __fastcall mode_isset(__int64 a1, int a2)
{
unsigned __int16 v2; // r12
bool v3; // zf
_BOOL8 result; // rax

v2 = (*_ctype_b_loc())[a2];
if ( (v2 & 0x200) == 0 || (v3 = (*(_DWORD *)(a1 + 4) & (unsigned int)mode_bit(a2)) == 0, result = 1LL, v3) )
{
result = 0LL;
if ( (v2 & 0x100) != 0 )
result = (*(_DWORD *)(a1 + 8) & (unsigned int)mode_bit(a2)) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, int a2)
{
unsigned __int16 v2; // r12
bool v3; // zf
_BOOL8 result; // rax

v2 = (*_ctype_b_loc())[a2];
if ( (v2 & 0x200) == 0 || (v3 = (*(_DWORD *)(a1 + 4) & (unsigned int)func0(a2)) == 0, result = 1LL, v3) )
{
result = 0LL;
if ( (v2 & 0x100) != 0 )
result = (*(_DWORD *)(a1 + 8) & (unsigned int)func0(a2)) != 0;
}
return result;
}

original_code:
static int
mode_isset(const struct mode *m, int flag)
{
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short int) _ISlower) && (m->lower & mode_bit(flag)))
  return 1;
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short int) _ISupper) && (m->upper & mode_bit(flag)))
  return 1;
 return 0;
}

canonical_original_code:
static int mode_isset(struct mode *m, int flag)
{
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short) _ISlower) && (m->lower & mode_bit(flag)))
  return 1;
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short) _ISupper) && (m->upper & mode_bit(flag)))
  return 1;
 return 0;
}

variable_types: struct mode { char prefix; unsigned int lower; unsigned int upper; } *

variable_types: flag int


original_code:
static void
mode_set(struct mode *m, int flag, int set)
{
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short int) _ISlower))
  ((m->lower) ^= (-(!!set) ^ (m->lower)) & (mode_bit(flag)));
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short int) _ISupper))
  ((m->upper) ^= (-(!!set) ^ (m->upper)) & (mode_bit(flag)));
}

canonical_original_code:
static void mode_set(struct mode *m, int flag, int set)
{
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short) _ISlower))
  ((m->lower) ^= (-(!!set) ^ (m->lower)) & (mode_bit(flag)));
 if (((*__ctype_b_loc ())[(int) ((flag))] & (unsigned short) _ISupper))
  ((m->upper) ^= (-(!!set) ^ (m->upper)) & (mode_bit(flag)));
}

variable_types: set int

user_defined_types: struct mode { char prefix; unsigned int lower; unsigned int upper; }


decompiled_code:
__int64 __fastcall mode_cfg_chanmodes(__int64 a1, signed __int8 *a2)
{
signed __int8 *v2; // rbp
signed __int8 i; // bl

*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
v2 = a2 + 1;
for ( i = *a2; i; i = *(v2 - 1) )
{
if ( (unsigned int)mode_bit(i) && !mode_isset(a1, i) )
mode_set(a1, i, 1);
++v2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, signed __int8 *a2)
{
signed __int8 *v2; // rbp
signed __int8 i; // bl

*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
v2 = a2 + 1;
for ( i = *a2; i; i = *(v2 - 1) )
{
if ( (unsigned int)func0(i) && !func1(a1, i) )
func2(a1, i, 1);
++v2;
}
return 0LL;
}

original_code:
static int
mode_cfg_chanmodes(struct mode_cfg *cfg, const char *str)
{
 char c;
 struct mode *chanmodes = &(cfg->chanmodes);
 chanmodes->lower = 0;
 chanmodes->upper = 0;
 while ((c = *str++)) {
  if (!mode_bit(c))
   continue;
  if (mode_isset(chanmodes, c))
   continue;
  mode_set(chanmodes, c, 1);
 }
 return 0;
}

canonical_original_code:
static int mode_cfg_chanmodes(struct mode_cfg *cfg, char *str)
{
 char c;
 struct mode *chanmodes = &(cfg->chanmodes);
 chanmodes->lower = 0;
 chanmodes->upper = 0;
 while ((c = *str++)) {
  if (!mode_bit(c))
   continue;
  if (mode_isset(chanmodes, c))
   continue;
  mode_set(chanmodes, c, 1);
 }
 return 0;
}

variable_types: struct mode_cfg { struct mode { char prefix; unsigned int lower; unsigned int upper; } chanmodes; struct mode usermodes; struct { struct mode A; struct mode B; struct mode C; struct mode D; } CHANMODES; struct { char F[-1]; char T[-1]; } PREFIX; } *

variable_types:
str
char *

variable_types: c char

user_defined_types: struct mode_cfg { struct mode chanmodes; struct mode usermodes; struct { struct mode A; struct mode B; struct mode C; struct mode D; } CHANMODES; struct { char F[-1]; char T[-1]; } PREFIX; }


decompiled_code:
__int64 __fastcall mode_cfg_usermodes(__int64 a1, signed __int8 *a2)
{
__int64 v2; // r12
signed __int8 *v3; // rbp
signed __int8 i; // bl

v2 = a1 + 12;
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)(a1 + 20) = 0;
v3 = a2 + 1;
for ( i = *a2; i; i = *(v3 - 1) )
{
if ( (unsigned int)mode_bit(i) && !mode_isset(v2, i) )
mode_set(v2, i, 1);
++v3;
}
return 0LL;
}

original_code:
static int
mode_cfg_usermodes(struct mode_cfg *cfg, const char *str)
{
 char c;
 struct mode *usermodes = &(cfg->usermodes);
 usermodes->lower = 0;
 usermodes->upper = 0;
 while ((c = *str++)) {
  if (!mode_bit(c))
   continue;
  if (mode_isset(usermodes, c))
   continue;
  mode_set(usermodes, c, 1);
 }
 return 0;
}

canonical_original_code:
static int mode_cfg_usermodes(struct mode_cfg *cfg, char *str)
{
 char c;
 struct mode *usermodes = &(cfg->usermodes);
 usermodes->lower = 0;
 usermodes->upper = 0;
 while ((c = *str++)) {
  if (!mode_bit(c))
   continue;
  if (mode_isset(usermodes, c))
   continue;
  mode_set(usermodes, c, 1);
 }
 return 0;
}


original_code:
static int
mode_cfg_subtypes(struct mode_cfg *cfg, const char *str)
{
 char c;
 struct mode *subtypes[] = {
  &(cfg->CHANMODES.A),
  &(cfg->CHANMODES.B),
  &(cfg->CHANMODES.C),
  &(cfg->CHANMODES.D)
 };
 struct mode *setting = subtypes[0];
 memset(&(cfg->CHANMODES.A), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.B), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.C), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.D), 0, sizeof(struct mode));
 unsigned commas = 0;
 while ((c = *str++)) {
  if (c == ',') {
   switch (commas) {
    case 0:
    case 1:
    case 2:
     setting = subtypes[++commas];
     continue;
    default:
     goto error;
   }
  }
  if (!mode_bit(c))
   goto error;
  mode_set(setting, c, 1);
 }
 return 0;
error:
 memset(&(cfg->CHANMODES.A), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.B), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.C), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.D), 0, sizeof(struct mode));
 return -1;
}

canonical_original_code:
static int mode_cfg_subtypes(struct mode_cfg *cfg, char *str)
{
 char c;
 struct mode *subtypes[] = {
  &(cfg->CHANMODES.A),
  &(cfg->CHANMODES.B),
  &(cfg->CHANMODES.C),
  &(cfg->CHANMODES.D)
 };
 struct mode *setting = subtypes[0];
 memset(&(cfg->CHANMODES.A), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.B), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.C), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.D), 0, sizeof(struct mode));
 unsigned int commas = 0;
 while ((c = *str++)) {
  if (c == ',') {
   switch (commas) {
    case 0:
    case 1:
    case 2:
     setting = subtypes[++commas];
     continue;
    default:
     goto error;
   }
  }
  if (!mode_bit(c))
   goto error;
  mode_set(setting, c, 1);
 }
 return 0;
error:
 memset(&(cfg->CHANMODES.A), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.B), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.C), 0, sizeof(struct mode));
 memset(&(cfg->CHANMODES.D), 0, sizeof(struct mode));
 return -1;
}

variable_types: struct mode { char prefix; unsigned int lower; unsigned int upper; } *[]

variable_types:
commas
unsigned int


original_code:
static int
mode_cfg_prefix(struct mode_cfg *cfg, const char *str)
{
 char *cfg_f = cfg->PREFIX.F;
 char *cfg_t = cfg->PREFIX.T;
 char *dup = irc_strdup(str);
 char *str_f;
 char *str_t;
 memset(cfg->PREFIX.F, 0, sizeof(cfg->PREFIX.F));
 memset(cfg->PREFIX.T, 0, sizeof(cfg->PREFIX.T));
 if (*(str_f = dup) != '(')
  goto error;
 if (!(str_t = strchr(str_f, ')')))
  goto error;
 *str_f++ = 0;
 *str_t++ = 0;
 if (strlen(str_f) != strlen(str_t))
  goto error;
 while (*str_f) {
  char cf = *str_f++;
  char ct = *str_t++;
  if (!mode_bit(cf))
   goto error;
  if (!(((*__ctype_b_loc ())[(int) ((ct))] & (unsigned short int) _ISgraph)))
   goto error;
  if (strchr(cfg->PREFIX.F, cf))
   goto error;
  *cfg_f++ = cf;
  *cfg_t++ = ct;
 }
 *cfg_f = 0;
 *cfg_t = 0;
 free(dup);
 return 0;
error:
 *(cfg->PREFIX.F) = 0;
 *(cfg->PREFIX.T) = 0;
 free(dup);
 return -1;
}

canonical_original_code:
static int mode_cfg_prefix(struct mode_cfg *cfg, char *str)
{
 char *cfg_f = cfg->PREFIX.F;
 char *cfg_t = cfg->PREFIX.T;
 char *dup = irc_strdup(str);
 char *str_f;
 char *str_t;
 memset(cfg->PREFIX.F, 0, sizeof(cfg->PREFIX.F));
 memset(cfg->PREFIX.T, 0, sizeof(cfg->PREFIX.T));
 if (*(str_f = dup) != '(')
  goto error;
 if (!(str_t = strchr(str_f, ')')))
  goto error;
 *str_f++ = 0;
 *str_t++ = 0;
 if (strlen(str_f) != strlen(str_t))
  goto error;
 while (*str_f) {
  char cf = *str_f++;
  char ct = *str_t++;
  if (!mode_bit(cf))
   goto error;
  if (!(((*__ctype_b_loc ())[(int) ((ct))] & (unsigned short) _ISgraph)))
   goto error;
  if (strchr(cfg->PREFIX.F, cf))
   goto error;
  *cfg_f++ = cf;
  *cfg_t++ = ct;
 }
 *cfg_f = 0;
 *cfg_t = 0;
 free(dup);
 return 0;
error:
 *(cfg->PREFIX.F) = 0;
 *(cfg->PREFIX.T) = 0;
 free(dup);
 return -1;
}

variable_types:
dup
char *

variable_types: cf char

variable_types: ct char


decompiled_code:
__int64 __fastcall mode_cfg(__int64 a1, signed __int8 *a2, unsigned int a3)
{
__int64 result; // rax

switch ( a3 )
{
case 0u:
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 172) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 180) >> 3));
strcpy((char *)(a1 + 72), "ov");
strcpy((char *)(a1 + 125), "@+");
mode_cfg_chanmodes(a1, "OovaimnqpsrtklbeI");
mode_cfg_usermodes(a1, "aiwroOs");
mode_cfg_subtypes(a1, "IObe,k,l,aimnqpsrt");
result = 0LL;
break;
case 1u:
result = mode_cfg_chanmodes(a1, a2);
break;
case 2u:
result = mode_cfg_usermodes(a1, a2);
break;
case 3u:
result = mode_cfg_subtypes(a1, a2);
break;
case 4u:
result = mode_cfg_prefix(a1, (__int64)a2);
break;
default:
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/mode.c", 123LL, "mode_cfg");
fprintf(stderr, "mode configuration type unknown: %d", a3);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, signed __int8 *a2, unsigned int a3)
{
__int64 result; // rax

switch ( a3 )
{
case 0u:
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 172) = 0LL;
memset(
(void *)((a1 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 180) >> 3));
strcpy((char *)(a1 + 72), "ov");
strcpy((char *)(a1 + 125), "@+");
func3(a1, "OovaimnqpsrtklbeI");
func4(a1, "aiwroOs");
func5(a1, "IObe,k,l,aimnqpsrt");
result = 0LL;
break;
case 1u:
result = func3(a1, a2);
break;
case 2u:
result = func4(a1, a2);
break;
case 3u:
result = func5(a1, a2);
break;
case 4u:
result = func6(a1, (__int64)a2);
break;
default:
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/mode.c", 123LL, "mode_cfg");
fprintf(stderr, "mode configuration type unknown: %d", a3);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
return result;
}

original_code:
int
mode_cfg(struct mode_cfg *cfg, const char *cfg_str, enum mode_cfg_type cfg_type)
{
 switch (cfg_type) {
  case MODE_CFG_DEFAULTS:
   memset(cfg, 0, sizeof(*cfg));
   (void) snprintf(cfg->PREFIX.F, sizeof(cfg->PREFIX.F), "ov");
   (void) snprintf(cfg->PREFIX.T, sizeof(cfg->PREFIX.T), "@+");
   mode_cfg_chanmodes(cfg, "OovaimnqpsrtklbeI");
   mode_cfg_usermodes(cfg, "aiwroOs");
   mode_cfg_subtypes(cfg, "IObe,k,l,aimnqpsrt");
   break;
  case MODE_CFG_CHANMODES:
   return mode_cfg_chanmodes(cfg, cfg_str);
  case MODE_CFG_USERMODES:
   return mode_cfg_usermodes(cfg, cfg_str);
  case MODE_CFG_SUBTYPES:
   return mode_cfg_subtypes(cfg, cfg_str);
  case MODE_CFG_PREFIX:
   return mode_cfg_prefix(cfg, cfg_str);
  default:
   do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/mode.c", 123, __func__); fprintf(stderr, "mode configuration type unknown: %d", cfg_type); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 }
 return 0;
}

canonical_original_code:
int mode_cfg(struct mode_cfg *cfg, char *cfg_str, enum mode_cfg_type cfg_type)
{
 switch (cfg_type) {
  case MODE_CFG_DEFAULTS:
   memset(cfg, 0, sizeof(*cfg));
   (void) snprintf(cfg->PREFIX.F, sizeof(cfg->PREFIX.F), "ov");
   (void) snprintf(cfg->PREFIX.T, sizeof(cfg->PREFIX.T), "@+");
   mode_cfg_chanmodes(cfg, "OovaimnqpsrtklbeI");
   mode_cfg_usermodes(cfg, "aiwroOs");
   mode_cfg_subtypes(cfg, "IObe,k,l,aimnqpsrt");
   break;
  case MODE_CFG_CHANMODES:
   return mode_cfg_chanmodes(cfg, cfg_str);
  case MODE_CFG_USERMODES:
   return mode_cfg_usermodes(cfg, cfg_str);
  case MODE_CFG_SUBTYPES:
   return mode_cfg_subtypes(cfg, cfg_str);
  case MODE_CFG_PREFIX:
   return mode_cfg_prefix(cfg, cfg_str);
  default:
   do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/mode.c", 123, __func__); fprintf(stderr, "mode configuration type unknown: %d", cfg_type); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 }
 return 0;
}

variable_types: enum mode_cfg_type { MODE_CFG_DEFAULTS=0, MODE_CFG_CHANMODES=1, MODE_CFG_USERMODES=2, MODE_CFG_SUBTYPES=3, MODE_CFG_PREFIX=4 }


decompiled_code:
__int64 __fastcall mode_chanmode_set(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int v6; // ebx

if ( !mode_isset(a2, a3) )
return (unsigned int)-1;
v6 = mode_isset(a2 + 24, a3);
if ( v6 )
return 0;
mode_set(a1, a3, a4);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int v6; // ebx

if ( !func1(a2, a3) )
return (unsigned int)-1;
v6 = func1(a2 + 24, a3);
if ( v6 )
return 0;
func2(a1, a3, a4);
return v6;
}

original_code:
int
mode_chanmode_set(struct mode *m, const struct mode_cfg *cfg, int flag, int set)
{
 if (!mode_isset(&(cfg->chanmodes), flag))
  return -1;
 if (mode_isset(&(cfg->CHANMODES.A), flag))
  return 0;
 mode_set(m, flag, set);
 return 0;
}

canonical_original_code:
int mode_chanmode_set(struct mode *m, struct mode_cfg *cfg, int flag, int set)
{
 if (!mode_isset(&(cfg->chanmodes), flag))
  return -1;
 if (mode_isset(&(cfg->CHANMODES.A), flag))
  return 0;
 mode_set(m, flag, set);
 return 0;
}

variable_types: struct mode_cfg { struct mode chanmodes; struct mode usermodes; struct { struct mode A; struct mode B; struct mode C; struct mode D; } CHANMODES; struct { char F[-1]; char T[-1]; } PREFIX; } *


decompiled_code:
__int64 __fastcall mode_prfxmode_set(_BYTE *a1, __int64 a2, int a3, int a4)
{
_BYTE *v7; // rdx
_BYTE *v8; // rbx
char v9; // cl
__int64 result; // rax
char v11; // al
char i; // si

v7 = (_BYTE *)(a2 + 72);
v8 = (_BYTE *)(a2 + 125);
v9 = *(_BYTE *)(a2 + 72);
result = 0xFFFFFFFFLL;
if ( v9 )
{
while ( 1 )
{
v11 = v7[53];
if ( !v11 )
return 0xFFFFFFFFLL;
if ( v9 == a3 || v11 == a3 )
break;
v9 = *++v7;
if ( !*v7 )
return 0xFFFFFFFFLL;
}
if ( v9 )
{
mode_set((__int64)a1, v9, a4);
for ( i = *(_BYTE *)(a2 + 72); i; i = *(++v8 - 53) )
{
if ( mode_isset((__int64)a1, i) )
break;
}
*a1 = *v8;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, __int64 a2, int a3, int a4)
{
_BYTE *v7; // rdx
_BYTE *v8; // rbx
char v9; // cl
__int64 result; // rax
char v11; // al
char i; // si

v7 = (_BYTE *)(a2 + 72);
v8 = (_BYTE *)(a2 + 125);
v9 = *(_BYTE *)(a2 + 72);
result = 0xFFFFFFFFLL;
if ( v9 )
{
while ( 1 )
{
v11 = v7[53];
if ( !v11 )
return 0xFFFFFFFFLL;
if ( v9 == a3 || v11 == a3 )
break;
v9 = *++v7;
if ( !*v7 )
return 0xFFFFFFFFLL;
}
if ( v9 )
{
func2((__int64)a1, v9, a4);
for ( i = *(_BYTE *)(a2 + 72); i; i = *(++v8 - 53) )
{
if ( func1((__int64)a1, i) )
break;
}
*a1 = *v8;
result = 0LL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
mode_prfxmode_set(struct mode *m, const struct mode_cfg *cfg, int flag, int set)
{
 const char *f = cfg->PREFIX.F;
 const char *t = cfg->PREFIX.T;
 while (*f && *t && *f != flag && *t != flag) {
  f++;
  t++;
 }
 if (!*f || !*t)
  return -1;
 mode_set(m, *f, set);
 f = cfg->PREFIX.F;
 t = cfg->PREFIX.T;
 while (*f) {
  if (mode_isset(m, *f))
   break;
  f++;
  t++;
 }
 m->prefix = *t;
 return 0;
}

canonical_original_code:
int mode_prfxmode_set(struct mode *m, struct mode_cfg *cfg, int flag, int set)
{
 char *f = cfg->PREFIX.F;
 char *t = cfg->PREFIX.T;
 while (*f && *t && *f != flag && *t != flag) {
  f++;
  t++;
 }
 if (!*f || !*t)
  return -1;
 mode_set(m, *f, set);
 f = cfg->PREFIX.F;
 t = cfg->PREFIX.T;
 while (*f) {
  if (mode_isset(m, *f))
   break;
  f++;
  t++;
 }
 m->prefix = *t;
 return 0;
}

variable_types:
f
char *

variable_types:
t
char *


decompiled_code:
__int64 __fastcall mode_usermode_set(__int64 a1, __int64 a2, int a3, int a4)
{
if ( !mode_isset(a2 + 12, a3) )
return 0xFFFFFFFFLL;
mode_set(a1, a3, a4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3, int a4)
{
if ( !func1(a2 + 12, a3) )
return 0xFFFFFFFFLL;
func2(a1, a3, a4);
return 0LL;
}

original_code:
int
mode_usermode_set(struct mode *m, const struct mode_cfg *cfg, int flag, int set)
{
 if (!mode_isset(&(cfg->usermodes), flag))
  return -1;
 mode_set(m, flag, set);
 return 0;
}

canonical_original_code:
int mode_usermode_set(struct mode *m, struct mode_cfg *cfg, int flag, int set)
{
 if (!mode_isset(&(cfg->usermodes), flag))
  return -1;
 mode_set(m, flag, set);
 return 0;
}


original_code:
const char*
mode_str(const struct mode *m, struct mode_str *m_str)
{
 char *str = m_str->str;
 uint32_t lower = m->lower;
 uint32_t upper = m->upper;
 for (char c = 'a'; c <= 'z' && lower; c++, lower >>= 1)
  if (lower & 1)
   *str++ = c;
 for (char c = 'A'; c <= 'Z' && upper; c++, upper >>= 1)
  if (upper & 1)
   *str++ = c;
 *str = 0;
 return m_str->str;
}

canonical_original_code:
char *mode_str(struct mode *m, struct mode_str *m_str)
{
 char *str = m_str->str;
 unsigned int lower = m->lower;
 unsigned int upper = m->upper;
 for (char c = 'a'; c <= 'z' && lower; c++, lower >>= 1)
  if (lower & 1)
   *str++ = c;
 for (char c = 'A'; c <= 'Z' && upper; c++, upper >>= 1)
  if (upper & 1)
   *str++ = c;
 *str = 0;
 return m_str->str;
}

variable_types:
lower
unsigned int

variable_types:
upper
unsigned int

return_type: char *


decompiled_code:
__int64 __fastcall mode_type(__int64 a1, int a2, int a3)
{
char *v4; // rdx
__int64 result; // rax
_BOOL4 v6; // edx
_BOOL4 v7; // edx

v4 = strchr((const char *)(a1 + 72), a2);
result = 3LL;
if ( !v4 )
{
v6 = mode_isset(a1 + 24, a2);
result = 2LL;
if ( !v6 )
{
v7 = mode_isset(a1 + 36, a2);
result = 2LL;
if ( !v7 )
{
if ( mode_isset(a1 + 48, a2) )
result = 1 - ((unsigned int)(a3 == 0) - 1);
else
result = mode_isset(a1 + 60, a2);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, int a3)
{
char *v4; // rdx
__int64 result; // rax
_BOOL4 v6; // edx
_BOOL4 v7; // edx

v4 = strchr((const char *)(a1 + 72), a2);
result = 3LL;
if ( !v4 )
{
v6 = func1(a1 + 24, a2);
result = 2LL;
if ( !v6 )
{
v7 = func1(a1 + 36, a2);
result = 2LL;
if ( !v7 )
{
if ( func1(a1 + 48, a2) )
result = 1 - ((unsigned int)(a3 == 0) - 1);
else
result = func1(a1 + 60, a2);
}
}
}
return result;
}

original_code:
enum mode_type
mode_type(const struct mode_cfg *cfg, int flag, int set)
{
 if (strchr(cfg->PREFIX.F, flag))
  return MODE_FLAG_PREFIX;
 if (mode_isset(&(cfg->CHANMODES.A), flag))
  return MODE_FLAG_CHANMODE_PARAM;
 if (mode_isset(&(cfg->CHANMODES.B), flag))
  return MODE_FLAG_CHANMODE_PARAM;
 if (mode_isset(&(cfg->CHANMODES.C), flag))
  return (set ? MODE_FLAG_CHANMODE_PARAM : MODE_FLAG_CHANMODE);
 if (mode_isset(&(cfg->CHANMODES.D), flag))
  return MODE_FLAG_CHANMODE;
 return MODE_FLAG_INVALID_FLAG;
}

canonical_original_code:
enum mode_type mode_type(struct mode_cfg *cfg, int flag, int set)
{
 if (strchr(cfg->PREFIX.F, flag))
  return MODE_FLAG_PREFIX;
 if (mode_isset(&(cfg->CHANMODES.A), flag))
  return MODE_FLAG_CHANMODE_PARAM;
 if (mode_isset(&(cfg->CHANMODES.B), flag))
  return MODE_FLAG_CHANMODE_PARAM;
 if (mode_isset(&(cfg->CHANMODES.C), flag))
  return (set ? MODE_FLAG_CHANMODE_PARAM : MODE_FLAG_CHANMODE);
 if (mode_isset(&(cfg->CHANMODES.D), flag))
  return MODE_FLAG_CHANMODE;
 return MODE_FLAG_INVALID_FLAG;
}

return_type: enum mode_type { MODE_FLAG_INVALID_FLAG=0, MODE_FLAG_CHANMODE=1, MODE_FLAG_CHANMODE_PARAM=2, MODE_FLAG_PREFIX=3 }


original_code:
static int asn1_get_sequence_of_cb(void *ctx,
                                   int tag,
                                   unsigned char *start,
                                   size_t len)
{
    asn1_get_sequence_of_cb_ctx_t *cb_ctx =
        (asn1_get_sequence_of_cb_ctx_t *) ctx;
    mbedtls_asn1_sequence *cur =
        cb_ctx->cur;
    if (cur->buf.p != ((void *)0)) {
        cur->next =
            calloc(1, sizeof(mbedtls_asn1_sequence));
        if (cur->next == ((void *)0)) {
            return -0x006A;
        }
        cur = cur->next;
    }
    cur->buf.p = start;
    cur->buf.len = len;
    cur->buf.tag = tag;
    cb_ctx->cur = cur;
    return 0;
}

canonical_original_code:
static int asn1_get_sequence_of_cb(void *ctx, int tag, unsigned char *start, unsigned long len)
{
    struct asn1_get_sequence_of_cb_ctx_t *cb_ctx = (asn1_get_sequence_of_cb_ctx_t *) ctx;
    struct mbedtls_asn1_sequence *cur = cb_ctx->cur;
    if (cur->buf.p != ((void *)0)) {
        cur->next =
            calloc(1, sizeof(mbedtls_asn1_sequence));
        if (cur->next == ((void *)0)) {
            return -0x006A;
        }
        cur = cur->next;
    }
    cur->buf.p = start;
    cur->buf.len = len;
    cur->buf.tag = tag;
    cb_ctx->cur = cur;
    return 0;
}

variable_types:
ctx
void *

variable_types: tag int

variable_types:
start
unsigned char *

variable_types:
len
unsigned long

variable_types: struct asn1_get_sequence_of_cb_ctx_t { int tag; struct mbedtls_asn1_sequence { struct mbedtls_asn1_buf { int tag; unsigned long len; unsigned char *p; } buf; struct mbedtls_asn1_sequence *next; } *cur; } *

user_defined_types: struct asn1_get_sequence_of_cb_ctx_t { int tag; struct mbedtls_asn1_sequence *cur; }

user_defined_types: struct mbedtls_asn1_sequence { struct mbedtls_asn1_buf buf; struct mbedtls_asn1_sequence *next; }


canonical_original_code:
int mbedtls_asn1_get_len(unsigned char **p, unsigned char *end, unsigned long *len)
{
    if ((end - *p) < 1) {
        return -0x0060;
    }
    if ((**p & 0x80) == 0) {
        *len = *(*p)++;
    } else {
        switch (**p & 0x7F) {
            case 1:
                if ((end - *p) < 2) {
                    return -0x0060;
                }
                *len = (*p)[1];
                (*p) += 2;
                break;
            case 2:
                if ((end - *p) < 3) {
                    return -0x0060;
                }
                *len = ((unsigned long) (*p)[1] << 8) | (*p)[2];
                (*p) += 3;
                break;
            case 3:
                if ((end - *p) < 4) {
                    return -0x0060;
                }
                *len = ((unsigned long) (*p)[1] << 16) |
                       ((unsigned long) (*p)[2] << 8) | (*p)[3];
                (*p) += 4;
                break;
            case 4:
                if ((end - *p) < 5) {
                    return -0x0060;
                }
                *len = ((unsigned long) (*p)[1] << 24) | ((unsigned long) (*p)[2] << 16) |
                       ((unsigned long) (*p)[3] << 8) | (*p)[4];
                (*p) += 5;
                break;
            default:
                return -0x0064;
        }
    }
    if (*len > (unsigned long) (end - *p)) {
        return -0x0060;
    }
    return 0;
}

variable_types:
p
unsigned char **

variable_types:
end
unsigned char *

variable_types:
len
unsigned long *


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_tag(unsigned __int8 **a1, __int64 a2, unsigned __int64 *a3, int a4)
{
unsigned __int8 *v4; // rax

v4 = *a1;
if ( a2 - (__int64)*a1 <= 0 )
return 4294967200LL;
if ( *v4 != a4 )
return 4294967198LL;
*a1 = v4 + 1;
return mbedtls_asn1_get_len(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 **a1, __int64 a2, unsigned __int64 *a3, int a4)
{
unsigned __int8 *v4; // rax

v4 = *a1;
if ( a2 - (__int64)*a1 <= 0 )
return 4294967200LL;
if ( *v4 != a4 )
return 4294967198LL;
*a1 = v4 + 1;
return func1(a1, a2, a3);
}

original_code:
int mbedtls_asn1_get_tag(unsigned char **p,
                         const unsigned char *end,
                         size_t *len, int tag)
{
    if ((end - *p) < 1) {
        return -0x0060;
    }
    if (**p != tag) {
        return -0x0062;
    }
    (*p)++;
    return mbedtls_asn1_get_len(p, end, len);
}

canonical_original_code:
int mbedtls_asn1_get_tag(unsigned char **p, unsigned char *end, unsigned long *len, int tag)
{
    if ((end - *p) < 1) {
        return -0x0060;
    }
    if (**p != tag) {
        return -0x0062;
    }
    (*p)++;
    return mbedtls_asn1_get_len(p, end, len);
}


original_code:
static int asn1_get_tagged_int(unsigned char **p,
                               const unsigned char *end,
                               int tag, int *val)
{
    int ret = -0x006E;
    size_t len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len, tag)) != 0) {
        return ret;
    }
    if (len == 0) {
        return -0x0064;
    }
    if ((**p & 0x80) != 0) {
        return -0x0064;
    }
    while (len > 0 && **p == 0) {
        ++(*p);
        --len;
    }
    if (len > sizeof(int)) {
        return -0x0064;
    }
    if (len == sizeof(int) && (**p & 0x80) != 0) {
        return -0x0064;
    }
    *val = 0;
    while (len-- > 0) {
        *val = (*val << 8) | **p;
        (*p)++;
    }
    return 0;
}

canonical_original_code:
static int asn1_get_tagged_int(unsigned char **p, unsigned char *end, int tag, int *val)
{
    int ret = -0x006E;
    unsigned long len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len, tag)) != 0) {
        return ret;
    }
    if (len == 0) {
        return -0x0064;
    }
    if ((**p & 0x80) != 0) {
        return -0x0064;
    }
    while (len > 0 && **p == 0) {
        ++(*p);
        --len;
    }
    if (len > sizeof(int)) {
        return -0x0064;
    }
    if (len == sizeof(int) && (**p & 0x80) != 0) {
        return -0x0064;
    }
    *val = 0;
    while (len-- > 0) {
        *val = (*val << 8) | **p;
        (*p)++;
    }
    return 0;
}

variable_types:
val
int *

variable_types: ret int


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_bool(unsigned __int8 **a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax
unsigned __int64 v5[3]; // [rsp+8h] [rbp-18h] BYREF

result = mbedtls_asn1_get_tag(a1, a2, v5, 1);
if ( !(_DWORD)result )
{
if ( v5[0] == 1 )
*a3 = *(*a1)++ != 0;
else
result = 4294967196LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 **a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax
unsigned __int64 v5[3]; // [rsp+8h] [rbp-18h] BYREF

result = func2(a1, a2, v5, 1);
if ( !(_DWORD)result )
{
if ( v5[0] == 1 )
*a3 = *(*a1)++ != 0;
else
result = 4294967196LL;
}
return result;
}

original_code:
int mbedtls_asn1_get_bool(unsigned char **p,
                          const unsigned char *end,
                          int *val)
{
    int ret = -0x006E;
    size_t len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len, 0x01)) != 0) {
        return ret;
    }
    if (len != 1) {
        return -0x0064;
    }
    *val = (**p != 0) ? 1 : 0;
    (*p)++;
    return 0;
}

canonical_original_code:
int mbedtls_asn1_get_bool(unsigned char **p, unsigned char *end, int *val)
{
    int ret = -0x006E;
    unsigned long len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len, 0x01)) != 0) {
        return ret;
    }
    if (len != 1) {
        return -0x0064;
    }
    *val = (**p != 0) ? 1 : 0;
    (*p)++;
    return 0;
}


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_int(unsigned __int8 **a1, __int64 a2, int *a3)
{
return asn1_get_tagged_int(a1, a2, 2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 **a1, __int64 a2, int *a3)
{
return func3(a1, a2, 2, a3);
}

original_code:
int mbedtls_asn1_get_int(unsigned char **p,
                         const unsigned char *end,
                         int *val)
{
    return asn1_get_tagged_int(p, end, 0x02, val);
}

canonical_original_code:
int mbedtls_asn1_get_int(unsigned char **p, unsigned char *end, int *val)
{
    return asn1_get_tagged_int(p, end, 0x02, val);
}


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_enum(unsigned __int8 **a1, __int64 a2, int *a3)
{
return asn1_get_tagged_int(a1, a2, 10, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 **a1, __int64 a2, int *a3)
{
return func3(a1, a2, 10, a3);
}

original_code:
int mbedtls_asn1_get_enum(unsigned char **p,
                          const unsigned char *end,
                          int *val)
{
    return asn1_get_tagged_int(p, end, 0x0A, val);
}

canonical_original_code:
int mbedtls_asn1_get_enum(unsigned char **p, unsigned char *end, int *val)
{
    return asn1_get_tagged_int(p, end, 0x0A, val);
}


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_mpi(unsigned __int8 **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

result = mbedtls_asn1_get_tag(a1, a2, v5, 2);
if ( !(_DWORD)result )
{
result = mbedtls_mpi_read_binary(a3, *a1, v5[0]);
*a1 += v5[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

result = func2(a1, a2, v5, 2);
if ( !(_DWORD)result )
{
result = mbedtls_mpi_read_binary(a3, *a1, v5[0]);
*a1 += v5[0];
}
return result;
}

original_code:
int mbedtls_asn1_get_mpi(unsigned char **p,
                         const unsigned char *end,
                         mbedtls_mpi *X)
{
    int ret = -0x006E;
    size_t len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len, 0x02)) != 0) {
        return ret;
    }
    ret = mbedtls_mpi_read_binary(X, *p, len);
    *p += len;
    return ret;
}

canonical_original_code:
int mbedtls_asn1_get_mpi(unsigned char **p, unsigned char *end, struct mbedtls_mpi *X)
{
    int ret = -0x006E;
    unsigned long len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len, 0x02)) != 0) {
        return ret;
    }
    ret = mbedtls_mpi_read_binary(X, *p, len);
    *p += len;
    return ret;
}

variable_types: struct mbedtls_mpi { int s; unsigned long n; unsigned long *p; } *


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_bitstring(unsigned __int8 **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int8 v5; // dl
__int64 v6; // rdx
unsigned __int8 *v7; // rdx

result = mbedtls_asn1_get_tag(a1, a2, (unsigned __int64 *)a3, 3);
if ( !(_DWORD)result )
{
if ( *(_QWORD *)a3 )
{
--*(_QWORD *)a3;
v5 = **a1;
*(_BYTE *)(a3 + 8) = v5;
if ( v5 > 7u )
{
result = 4294967196LL;
}
else
{
v6 = (__int64)(*a1 + 1);
*a1 = (unsigned __int8 *)v6;
*(_QWORD *)(a3 + 16) = v6;
v7 = (unsigned __int8 *)(*(_QWORD *)a3 + v6);
*a1 = v7;
if ( v7 != (unsigned __int8 *)a2 )
result = 4294967194LL;
}
}
else
{
result = 4294967200LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned __int8 v5; // dl
__int64 v6; // rdx
unsigned __int8 *v7; // rdx

result = func2(a1, a2, (unsigned __int64 *)a3, 3);
if ( !(_DWORD)result )
{
if ( *(_QWORD *)a3 )
{
--*(_QWORD *)a3;
v5 = **a1;
*(_BYTE *)(a3 + 8) = v5;
if ( v5 > 7u )
{
result = 4294967196LL;
}
else
{
v6 = (__int64)(*a1 + 1);
*a1 = (unsigned __int8 *)v6;
*(_QWORD *)(a3 + 16) = v6;
v7 = (unsigned __int8 *)(*(_QWORD *)a3 + v6);
*a1 = v7;
if ( v7 != (unsigned __int8 *)a2 )
result = 4294967194LL;
}
}
else
{
result = 4294967200LL;
}
}
return result;
}

original_code:
int mbedtls_asn1_get_bitstring(unsigned char **p, const unsigned char *end,
                               mbedtls_asn1_bitstring *bs)
{
    int ret = -0x006E;
    if ((ret = mbedtls_asn1_get_tag(p, end, &bs->len, 0x03)) != 0) {
        return ret;
    }
    if (bs->len < 1) {
        return -0x0060;
    }
    bs->len -= 1;
    bs->unused_bits = **p;
    if (bs->unused_bits > 7) {
        return -0x0064;
    }
    (*p)++;
    bs->p = *p;
    *p += bs->len;
    if (*p != end) {
        return -0x0066;
    }
    return 0;
}

canonical_original_code:
int mbedtls_asn1_get_bitstring(unsigned char **p, unsigned char *end, struct mbedtls_asn1_bitstring *bs)
{
    int ret = -0x006E;
    if ((ret = mbedtls_asn1_get_tag(p, end, &bs->len, 0x03)) != 0) {
        return ret;
    }
    if (bs->len < 1) {
        return -0x0060;
    }
    bs->len -= 1;
    bs->unused_bits = **p;
    if (bs->unused_bits > 7) {
        return -0x0064;
    }
    (*p)++;
    bs->p = *p;
    *p += bs->len;
    if (*p != end) {
        return -0x0066;
    }
    return 0;
}

variable_types: struct mbedtls_asn1_bitstring { unsigned long len; unsigned char unused_bits; unsigned char *p; } *


decompiled_code:
__int64 __fastcall mbedtls_asn1_traverse_sequence_of(unsigned __int8 **a1, unsigned __int64 a2, unsigned __int8 a3, char a4, unsigned __int8 a5, char a6, __int64 (__fastcall *a7)(__int64, _QWORD, unsigned __int8 *, unsigned __int64), __int64 a8)
{
unsigned int v10; // ebp
unsigned __int8 *v11; // rax
unsigned __int8 v12; // r12
unsigned int v13; // eax
unsigned __int64 v17[8]; // [rsp+18h] [rbp-40h] BYREF

v10 = mbedtls_asn1_get_tag(a1, a2, v17, 48);
if ( !v10 )
{
v11 = *a1;
if ( (unsigned __int8 *)a2 == &(*a1)[v17[0]] )
{
if ( (unsigned __int64)v11 < a2 )
{
while ( 1 )
{
*a1 = v11 + 1;
v12 = *v11;
if ( (*v11 & a3) != a4 )
break;
v10 = mbedtls_asn1_get_len(a1, a2, v17);
if ( v10 )
return v10;
if ( (v12 & a5) == a6 )
{
if ( a7 )
{
v13 = a7(a8, v12, *a1, v17[0]);
if ( v13 )
return v13;
}
}
v11 = &(*a1)[v17[0]];
*a1 = v11;
if ( (unsigned __int64)v11 >= a2 )
return v10;
}
v10 = -98;
}
}
else
{
v10 = -102;
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 **a1, unsigned __int64 a2, unsigned __int8 a3, char a4, unsigned __int8 a5, char a6, __int64 (__fastcall *a7)(__int64, _QWORD, unsigned __int8 *, unsigned __int64), __int64 a8)
{
unsigned int v10; // ebp
unsigned __int8 *v11; // rax
unsigned __int8 v12; // r12
unsigned int v13; // eax
unsigned __int64 v17[8]; // [rsp+18h] [rbp-40h] BYREF

v10 = func2(a1, a2, v17, 48);
if ( !v10 )
{
v11 = *a1;
if ( (unsigned __int8 *)a2 == &(*a1)[v17[0]] )
{
if ( (unsigned __int64)v11 < a2 )
{
while ( 1 )
{
*a1 = v11 + 1;
v12 = *v11;
if ( (*v11 & a3) != a4 )
break;
v10 = func1(a1, a2, v17);
if ( v10 )
return v10;
if ( (v12 & a5) == a6 )
{
if ( a7 )
{
v13 = a7(a8, v12, *a1, v17[0]);
if ( v13 )
return v13;
}
}
v11 = &(*a1)[v17[0]];
*a1 = v11;
if ( (unsigned __int64)v11 >= a2 )
return v10;
}
v10 = -98;
}
}
else
{
v10 = -102;
}
}
return v10;
}

original_code:
int mbedtls_asn1_traverse_sequence_of(
    unsigned char **p,
    const unsigned char *end,
    unsigned char tag_must_mask, unsigned char tag_must_val,
    unsigned char tag_may_mask, unsigned char tag_may_val,
    int (*cb)(void *ctx, int tag,
              unsigned char *start, size_t len),
    void *ctx)
{
    int ret;
    size_t len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
                                    0x20 | 0x10)) != 0) {
        return ret;
    }
    if (*p + len != end) {
        return -0x0066;
    }
    while (*p < end) {
        unsigned char const tag = *(*p)++;
        if ((tag & tag_must_mask) != tag_must_val) {
            return -0x0062;
        }
        if ((ret = mbedtls_asn1_get_len(p, end, &len)) != 0) {
            return ret;
        }
        if ((tag & tag_may_mask) == tag_may_val) {
            if (cb != ((void *)0)) {
                ret = cb(ctx, tag, *p, len);
                if (ret != 0) {
                    return ret;
                }
            }
        }
        *p += len;
    }
    return 0;
}

canonical_original_code:
int mbedtls_asn1_traverse_sequence_of(unsigned char **p, unsigned char *end, unsigned char tag_must_mask, unsigned char tag_must_val, unsigned char tag_may_mask, unsigned char tag_may_val, int (*cb)(void *ctx, int tag, unsigned char *start, unsigned long len), void *ctx)
{
    int ret;
    unsigned long len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
                                    0x20 | 0x10)) != 0) {
        return ret;
    }
    if (*p + len != end) {
        return -0x0066;
    }
    while (*p < end) {
        unsigned char tag = *(*p)++;
        if ((tag & tag_must_mask) != tag_must_val) {
            return -0x0062;
        }
        if ((ret = mbedtls_asn1_get_len(p, end, &len)) != 0) {
            return ret;
        }
        if ((tag & tag_may_mask) == tag_may_val) {
            if (cb != ((void *)0)) {
                ret = cb(ctx, tag, *p, len);
                if (ret != 0) {
                    return ret;
                }
            }
        }
        *p += len;
    }
    return 0;
}

variable_types: int (*)(void *ctx, int tag, unsigned char *start, unsigned long len)

variable_types:
tag
unsigned char


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_bitstring_null(unsigned __int8 **a1, __int64 a2, unsigned __int64 *a3)
{
__int64 result; // rax

result = mbedtls_asn1_get_tag(a1, a2, a3, 3);
if ( !(_DWORD)result )
{
if ( *a3 )
{
--*a3;
if ( **a1 )
result = 4294967192LL;
else
++*a1;
}
else
{
result = 4294967192LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 **a1, __int64 a2, unsigned __int64 *a3)
{
__int64 result; // rax

result = func2(a1, a2, a3, 3);
if ( !(_DWORD)result )
{
if ( *a3 )
{
--*a3;
if ( **a1 )
result = 4294967192LL;
else
++*a1;
}
else
{
result = 4294967192LL;
}
}
return result;
}

original_code:
int mbedtls_asn1_get_bitstring_null(unsigned char **p, const unsigned char *end,
                                    size_t *len)
{
    int ret = -0x006E;
    if ((ret = mbedtls_asn1_get_tag(p, end, len, 0x03)) != 0) {
        return ret;
    }
    if (*len == 0) {
        return -0x0068;
    }
    --(*len);
    if (**p != 0) {
        return -0x0068;
    }
    ++(*p);
    return 0;
}

canonical_original_code:
int mbedtls_asn1_get_bitstring_null(unsigned char **p, unsigned char *end, unsigned long *len)
{
    int ret = -0x006E;
    if ((ret = mbedtls_asn1_get_tag(p, end, len, 0x03)) != 0) {
        return ret;
    }
    if (*len == 0) {
        return -0x0068;
    }
    --(*len);
    if (**p != 0) {
        return -0x0068;
    }
    ++(*p);
    return 0;
}


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_sequence_of(unsigned __int8 **a1, unsigned __int64 a2, _QWORD *a3, int a4)
{
int v5; // [rsp+0h] [rbp-18h] BYREF
_QWORD *v6; // [rsp+8h] [rbp-10h]

v5 = a4;
v6 = a3;
*a3 = 0LL;
a3[1] = 0LL;
a3[2] = 0LL;
a3[3] = 0LL;
return mbedtls_asn1_traverse_sequence_of(
a1,
a2,
0xFFu,
a4,
0,
0,
(__int64 (__fastcall *)(__int64, _QWORD, unsigned __int8 *, unsigned __int64))asn1_get_sequence_of_cb,
(__int64)&v5);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int8 **a1, unsigned __int64 a2, _QWORD *a3, int a4)
{
int v5; // [rsp+0h] [rbp-18h] BYREF
_QWORD *v6; // [rsp+8h] [rbp-10h]

v5 = a4;
v6 = a3;
*a3 = 0LL;
a3[1] = 0LL;
a3[2] = 0LL;
a3[3] = 0LL;
return func9(
a1,
a2,
0xFFu,
a4,
0,
0,
(__int64 (__fastcall *)(__int64, _QWORD, unsigned __int8 *, unsigned __int64))asn1_get_sequence_of_cb,
(__int64)&v5);
}

original_code:
int mbedtls_asn1_get_sequence_of(unsigned char **p,
                                 const unsigned char *end,
                                 mbedtls_asn1_sequence *cur,
                                 int tag)
{
    asn1_get_sequence_of_cb_ctx_t cb_ctx = { tag, cur };
    memset(cur, 0, sizeof(mbedtls_asn1_sequence));
    return mbedtls_asn1_traverse_sequence_of(
        p, end, 0xFF, tag, 0, 0,
        asn1_get_sequence_of_cb, &cb_ctx);
}

canonical_original_code:
int mbedtls_asn1_get_sequence_of(unsigned char **p, unsigned char *end, struct mbedtls_asn1_sequence *cur, int tag)
{
    struct asn1_get_sequence_of_cb_ctx_t cb_ctx = { tag, cur };
    memset(cur, 0, sizeof(mbedtls_asn1_sequence));
    return mbedtls_asn1_traverse_sequence_of(
        p, end, 0xFF, tag, 0, 0,
        asn1_get_sequence_of_cb, &cb_ctx);
}

variable_types: struct asn1_get_sequence_of_cb_ctx_t { int tag; struct mbedtls_asn1_sequence { struct mbedtls_asn1_buf { int tag; unsigned long len; unsigned char *p; } buf; struct mbedtls_asn1_sequence *next; } *cur; }


original_code:
int mbedtls_asn1_get_alg(unsigned char **p,
                         const unsigned char *end,
                         mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params)
{
    int ret = -0x006E;
    size_t len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
                                    0x20 | 0x10)) != 0) {
        return ret;
    }
    if ((end - *p) < 1) {
        return -0x0060;
    }
    alg->tag = **p;
    end = *p + len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &alg->len, 0x06)) != 0) {
        return ret;
    }
    alg->p = *p;
    *p += alg->len;
    if (*p == end) {
        mbedtls_platform_zeroize(params, sizeof(mbedtls_asn1_buf));
        return 0;
    }
    params->tag = **p;
    (*p)++;
    if ((ret = mbedtls_asn1_get_len(p, end, &params->len)) != 0) {
        return ret;
    }
    params->p = *p;
    *p += params->len;
    if (*p != end) {
        return -0x0066;
    }
    return 0;
}

canonical_original_code:
int mbedtls_asn1_get_alg(unsigned char **p, unsigned char *end, struct mbedtls_asn1_buf *alg, struct mbedtls_asn1_buf *params)
{
    int ret = -0x006E;
    unsigned long len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &len,
                                    0x20 | 0x10)) != 0) {
        return ret;
    }
    if ((end - *p) < 1) {
        return -0x0060;
    }
    alg->tag = **p;
    end = *p + len;
    if ((ret = mbedtls_asn1_get_tag(p, end, &alg->len, 0x06)) != 0) {
        return ret;
    }
    alg->p = *p;
    *p += alg->len;
    if (*p == end) {
        mbedtls_platform_zeroize(params, sizeof(mbedtls_asn1_buf));
        return 0;
    }
    params->tag = **p;
    (*p)++;
    if ((ret = mbedtls_asn1_get_len(p, end, &params->len)) != 0) {
        return ret;
    }
    params->p = *p;
    *p += params->len;
    if (*p != end) {
        return -0x0066;
    }
    return 0;
}

variable_types: struct mbedtls_asn1_buf { int tag; unsigned long len; unsigned char *p; } *

variable_types:
params
struct mbedtls_asn1_buf *


decompiled_code:
__int64 __fastcall mbedtls_asn1_get_alg_null(unsigned __int8 **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
result = mbedtls_asn1_get_alg(a1, a2, a3, (__int64)&v4);
if ( !(_DWORD)result )
{
if ( (_DWORD)v4 != 5 && (_DWORD)v4 )
{
result = 4294967192LL;
}
else if ( v5 )
{
result = 4294967192LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 **a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
result = func13(a1, a2, a3, (__int64)&v4);
if ( !(_DWORD)result )
{
if ( (_DWORD)v4 != 5 && (_DWORD)v4 )
{
result = 4294967192LL;
}
else if ( v5 )
{
result = 4294967192LL;
}
}
return result;
}

original_code:
int mbedtls_asn1_get_alg_null(unsigned char **p,
                              const unsigned char *end,
                              mbedtls_asn1_buf *alg)
{
    int ret = -0x006E;
    mbedtls_asn1_buf params;
    memset(&params, 0, sizeof(mbedtls_asn1_buf));
    if ((ret = mbedtls_asn1_get_alg(p, end, alg, &params)) != 0) {
        return ret;
    }
    if ((params.tag != 0x05 && params.tag != 0) || params.len != 0) {
        return -0x0068;
    }
    return 0;
}

canonical_original_code:
int mbedtls_asn1_get_alg_null(unsigned char **p, unsigned char *end, struct mbedtls_asn1_buf *alg)
{
    int ret = -0x006E;
    struct mbedtls_asn1_buf params;
    memset(&params, 0, sizeof(mbedtls_asn1_buf));
    if ((ret = mbedtls_asn1_get_alg(p, end, alg, &params)) != 0) {
        return ret;
    }
    if ((params.tag != 0x05 && params.tag != 0) || params.len != 0) {
        return -0x0068;
    }
    return 0;
}

variable_types: struct mbedtls_asn1_buf { int tag; unsigned long len; unsigned char *p; }


decompiled_code:
void __fastcall mbedtls_asn1_free_named_data_list(__int64 *a1)
{
__int64 i; // rbx

for ( i = *a1; *a1; i = *a1 )
{
*a1 = *(_QWORD *)(i + 48);
free(*(void **)(i + 16));
free(*(void **)(i + 40));
free((void *)i);
}
}

original_code:
void mbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data **head)
{
    mbedtls_asn1_named_data *cur;
    while ((cur = *head) != ((void *)0)) {
        *head = cur->next;
        free(cur->oid.p);
        free(cur->val.p);
        free(cur);
    }
}

canonical_original_code:
void mbedtls_asn1_free_named_data_list(struct mbedtls_asn1_named_data **head)
{
    struct mbedtls_asn1_named_data *cur;
    while ((cur = *head) != ((void *)0)) {
        *head = cur->next;
        free(cur->oid.p);
        free(cur->val.p);
        free(cur);
    }
}

variable_types: struct mbedtls_asn1_named_data { struct mbedtls_asn1_buf { int tag; unsigned long len; unsigned char *p; } oid; struct mbedtls_asn1_buf val; struct mbedtls_asn1_named_data *next; unsigned char next_merged; } **

user_defined_types: struct mbedtls_asn1_named_data { struct mbedtls_asn1_buf oid; struct mbedtls_asn1_buf val; struct mbedtls_asn1_named_data *next; unsigned char next_merged; }


decompiled_code:
__int64 __fastcall mbedtls_asn1_find_named_data(__int64 a1, const void *a2, size_t a3)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 48) )
{
if ( *(_QWORD *)(i + 8) == a3 && !memcmp(*(const void **)(i + 16), a2, a3) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, const void *a2, size_t a3)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 48) )
{
if ( *(_QWORD *)(i + 8) == a3 && !memcmp(*(const void **)(i + 16), a2, a3) )
break;
}
return i;
}

original_code:
const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data(const mbedtls_asn1_named_data *list,
                                                            const char *oid, size_t len)
{
    while (list != ((void *)0)) {
        if (list->oid.len == len &&
            memcmp(list->oid.p, oid, len) == 0) {
            break;
        }
        list = list->next;
    }
    return list;
}

canonical_original_code:
struct mbedtls_asn1_named_data *mbedtls_asn1_find_named_data(struct mbedtls_asn1_named_data *list, char *oid, unsigned long len)
{
    while (list != ((void *)0)) {
        if (list->oid.len == len &&
            memcmp(list->oid.p, oid, len) == 0) {
            break;
        }
        list = list->next;
    }
    return list;
}

variable_types:
list
struct mbedtls_asn1_named_data *

variable_types:
oid
char *

return_type: struct mbedtls_asn1_named_data { struct mbedtls_asn1_buf { int tag; unsigned long len; unsigned char *p; } oid; struct mbedtls_asn1_buf val; struct mbedtls_asn1_named_data *next; unsigned char next_merged; } *


decompiled_code:
_BOOL8 __fastcall irc_ischanchar(char a1, int a2)
{
_BOOL8 result; // rax

if ( a2 )
return (a1 == 38) | (unsigned __int8)((a1 & 0xF7) == 35);
if ( a1 > 44 )
return a1 != 58;
result = 1LL;
if ( a1 >= 0 )
{
switch ( a1 )
{
case 0:
case 7:
case 10:
case 13:
case 32:
case 44:
result = 0LL;
break;
default:
result = 1LL;
break;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1, int a2)
{
_BOOL8 result; // rax

if ( a2 )
return (a1 == 38) | (unsigned __int8)((a1 & 0xF7) == 35);
if ( a1 > 44 )
return a1 != 58;
result = 1LL;
if ( a1 >= 0 )
{
switch ( a1 )
{
case 0:
case 7:
case 10:
case 13:
case 32:
case 44:
result = 0LL;
break;
default:
result = 1LL;
break;
}
}
return result;
}

original_code:
static inline int
irc_ischanchar(char c, int first)
{
 if (first)
  return (c == '#' || c == '+' || c == '&');
 switch (c) {
  case 0x00:
  case 0x07:
  case 0x0D:
  case 0x0A:
  case ' ':
  case ',':
  case ':':
   return 0;
  default:
   return 1;
 }
}

variable_types: c char

variable_types: first int


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

switch ( a1 )
{
case 2:
if ( a2 == 94 )
return 126LL;
break;
case 3:
break;
case 1:
goto LABEL_9;
default:
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/utils/utils.c", 406LL, "irc_toupper");
fwrite("Unknown CASEMAPPING", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
switch ( a2 )
{
case '{':
return 91LL;
case '}':
return 93LL;
case '|':
return 92LL;
}
LABEL_9:
result = a2 - 32;
if ( a2 - 97 >= 0x1A )
result = a2;
return result;
}

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

switch ( a1 )
{
case 2:
if ( a2 == 94 )
return 126LL;
break;
case 3:
break;
case 1:
goto LABEL_9;
default:
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/utils/utils.c", 406LL, "irc_toupper");
fwrite("Unknown CASEMAPPING", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
switch ( a2 )
{
case '{':
return 91LL;
case '}':
return 93LL;
case '|':
return 92LL;
}
LABEL_9:
result = a2 - 32;
if ( a2 - 97 >= 0x1A )
result = a2;
return result;
}

original_code:
static inline int
irc_toupper(enum casemapping cm, int c)
{
 switch (cm) {
  case CASEMAPPING_RFC1459:
   if (c == '^') return '~';
  case CASEMAPPING_STRICT_RFC1459:
   if (c == '{') return '[';
   if (c == '}') return ']';
   if (c == '|') return '\\';
  case CASEMAPPING_ASCII:
   return (c >= 'a' && c <= 'z') ? (c + 'A' - 'a') : c;
  default:
   do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/utils/utils.c", 406, __func__); fprintf(stderr, "Unknown CASEMAPPING"); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 }
}

variable_types: enum casemapping { CASEMAPPING_INVALID=0, CASEMAPPING_ASCII=1, CASEMAPPING_RFC1459=2, CASEMAPPING_STRICT_RFC1459=3 }

variable_types: c int


decompiled_code:
__int64 __fastcall irc_isnick(char *a1)
{
__int64 result; // rax
char *v2; // rbx
char v3; // di

result = irc_isnickchar(*a1, 1);
v2 = a1 + 1;
if ( (_DWORD)result )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
break;
++v2;
result = irc_isnickchar(v3, 0);
if ( !(_DWORD)result )
return result;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
__int64 result; // rax
char *v2; // rbx
char v3; // di

result = func1(*a1, 1);
v2 = a1 + 1;
if ( (_DWORD)result )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
break;
++v2;
result = func1(v3, 0);
if ( !(_DWORD)result )
return result;
}
result = 1LL;
}
return result;
}

original_code:
int
irc_isnick(const char *str)
{
 if (!irc_isnickchar(*str++, 1))
  return 0;
 while (*str) {
  if (!irc_isnickchar(*str++, 0))
   return 0;
 }
 return 1;
}

canonical_original_code:
int irc_isnick(char *str)
{
 if (!irc_isnickchar(*str++, 1))
  return 0;
 while (*str) {
  if (!irc_isnickchar(*str++, 0))
   return 0;
 }
 return 1;
}

variable_types:
str
char *


decompiled_code:
_BOOL8 __fastcall irc_ischan(char *a1)
{
_BOOL8 result; // rax
char *v2; // rbx
char v3; // di

result = irc_ischanchar(*a1, 1);
v2 = a1 + 1;
if ( result )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
break;
++v2;
result = irc_ischanchar(v3, 0);
if ( !result )
return result;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *a1)
{
_BOOL8 result; // rax
char *v2; // rbx
char v3; // di

result = func0(*a1, 1);
v2 = a1 + 1;
if ( result )
{
while ( 1 )
{
v3 = *v2;
if ( !*v2 )
break;
++v2;
result = func0(v3, 0);
if ( !result )
return result;
}
result = 1LL;
}
return result;
}

original_code:
int
irc_ischan(const char *str)
{
 if (!irc_ischanchar(*str++, 1))
  return 0;
 while (*str) {
  if (!irc_ischanchar(*str++, 0))
   return 0;
 }
 return 1;
}

canonical_original_code:
int irc_ischan(char *str)
{
 if (!irc_ischanchar(*str++, 1))
  return 0;
 while (*str) {
  if (!irc_ischanchar(*str++, 0))
   return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall irc_strcmp(int a1, char *a2, char *a3)
{
int v5; // ebx
__int64 result; // rax

while ( 1 )
{
v5 = irc_toupper(a1, *a2++);
result = irc_toupper(a1, *a3++);
if ( v5 != (_DWORD)result )
break;
if ( !(_DWORD)result )
return result;
}
return (unsigned int)(result - v5);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, char *a2, char *a3)
{
int v5; // ebx
__int64 result; // rax

while ( 1 )
{
v5 = func2(a1, *a2++);
result = func2(a1, *a3++);
if ( v5 != (_DWORD)result )
break;
if ( !(_DWORD)result )
return result;
}
return (unsigned int)(result - v5);
}

original_code:
int
irc_strcmp(enum casemapping cm, const char *s1, const char *s2)
{
 int c1, c2;
 for (;;) {
  c1 = irc_toupper(cm, *s1++);
  c2 = irc_toupper(cm, *s2++);
  if ((c1 -= c2))
   return -c1;
  if (c2 == 0)
   break;
 }
 return 0;
}

canonical_original_code:
int irc_strcmp(enum casemapping cm, char *s1, char *s2)
{
 int c1; int c2;
 for (;;) {
  c1 = irc_toupper(cm, *s1++);
  c2 = irc_toupper(cm, *s2++);
  if ((c1 -= c2))
   return -c1;
  if (c2 == 0)
   break;
 }
 return 0;
}

user_defined_types: enum casemapping { CASEMAPPING_INVALID=0, CASEMAPPING_ASCII=1, CASEMAPPING_RFC1459=2, CASEMAPPING_STRICT_RFC1459=3 }