decompiled_code:
__int64 __fastcall mbedtls_ecdh_make_public(unsigned __int8 *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( *((_DWORD *)a1 + 2) == 1 )
result = ecdh_make_public_internal_constprop_0((__int64)(a1 + 16), a2, *a1, a3, a4, a5, a6);
else
result = 4294946944LL;
return result;
}

original_code:
int mbedtls_ecdh_make_public(mbedtls_ecdh_context *ctx, size_t *olen,
                             unsigned char *buf, size_t blen,
                             int (*f_rng)(void *, unsigned char *, size_t),
                             void *p_rng)
{
    int restart_enabled = 0;
    switch (ctx->var) {
        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
            return ecdh_make_public_internal(&ctx->ctx.mbed_ecdh, olen,
                                             ctx->point_format, buf, blen,
                                             f_rng, p_rng,
                                             restart_enabled);
        default:
            return -0x4F80;
    }
}

canonical_original_code:
int mbedtls_ecdh_make_public(struct mbedtls_ecdh_context *ctx, unsigned long *olen, unsigned char *buf, unsigned long blen, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    int restart_enabled = 0;
    switch (ctx->var) {
        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
            return ecdh_make_public_internal(&ctx->ctx.mbed_ecdh, olen,
                                             ctx->point_format, buf, blen,
                                             f_rng, p_rng,
                                             restart_enabled);
        default:
            return -0x4F80;
    }
}


repo: rcr/rirc

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

if ( *(_DWORD *)(a1 + 8) == 1 )
result = ecdh_read_public_internal(a1 + 16, a2, a3);
else
result = 4294946944LL;
return result;
}

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

if ( *(_DWORD *)(a1 + 8) == 1 )
result = func4(a1 + 16, a2, a3);
else
result = 4294946944LL;
return result;
}

original_code:
int mbedtls_ecdh_read_public(mbedtls_ecdh_context *ctx,
                             const unsigned char *buf, size_t blen)
{
    switch (ctx->var) {
        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
            return ecdh_read_public_internal(&ctx->ctx.mbed_ecdh,
                                             buf, blen);
        default:
            return -0x4F80;
    }
}

canonical_original_code:
int mbedtls_ecdh_read_public(struct mbedtls_ecdh_context *ctx, unsigned char *buf, unsigned long blen)
{
    switch (ctx->var) {
        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
            return ecdh_read_public_internal(&ctx->ctx.mbed_ecdh,
                                             buf, blen);
        default:
            return -0x4F80;
    }
}

variable_types: struct mbedtls_ecdh_context { unsigned char point_format; enum mbedtls_ecp_group_id { MBEDTLS_ECP_DP_NONE=0, MBEDTLS_ECP_DP_SECP192R1=1, MBEDTLS_ECP_DP_SECP224R1=2, MBEDTLS_ECP_DP_SECP256R1=3, MBEDTLS_ECP_DP_SECP384R1=4, MBEDTLS_ECP_DP_SECP521R1=5, MBEDTLS_ECP_DP_BP256R1=6, MBEDTLS_ECP_DP_BP384R1=7, MBEDTLS_ECP_DP_BP512R1=8, MBEDTLS_ECP_DP_CURVE25519=9, MBEDTLS_ECP_DP_SECP192K1=10, MBEDTLS_ECP_DP_SECP224K1=11, MBEDTLS_ECP_DP_SECP256K1=12, MBEDTLS_ECP_DP_CURVE448=13 } grp_id; enum mbedtls_ecdh_variant { MBEDTLS_ECDH_VARIANT_NONE=0, MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0=1 } var; union { struct mbedtls_ecdh_context_mbed { struct mbedtls_ecp_group { enum mbedtls_ecp_group_id { MBEDTLS_ECP_DP_NONE=0, MBEDTLS_ECP_DP_SECP192R1=1, MBEDTLS_ECP_DP_SECP224R1=2, MBEDTLS_ECP_DP_SECP256R1=3, MBEDTLS_ECP_DP_SECP384R1=4, MBEDTLS_ECP_DP_SECP521R1=5, MBEDTLS_ECP_DP_BP256R1=6, MBEDTLS_ECP_DP_BP384R1=7, MBEDTLS_ECP_DP_BP512R1=8, MBEDTLS_ECP_DP_CURVE25519=9, MBEDTLS_ECP_DP_SECP192K1=10, MBEDTLS_ECP_DP_SECP224K1=11, MBEDTLS_ECP_DP_SECP256K1=12, MBEDTLS_ECP_DP_CURVE448=13 } id; struct mbedtls_mpi { int s; unsigned long n; unsigned long *p; } P; struct mbedtls_mpi A; struct mbedtls_mpi B; struct mbedtls_ecp_point { struct mbedtls_mpi X; struct mbedtls_mpi Y; struct mbedtls_mpi Z; } G; struct mbedtls_mpi N; unsigned long pbits; unsigned long nbits; unsigned int h; int (*modp)(struct mbedtls_mpi *); int (*t_pre)(struct mbedtls_ecp_point *, void *); int (*t_post)(struct mbedtls_ecp_point *, void *); void *t_data; struct mbedtls_ecp_point *T; unsigned long T_size; } grp; struct mbedtls_mpi d; struct mbedtls_ecp_point Q; struct mbedtls_ecp_point Qp; struct mbedtls_mpi z; } mbed_ecdh; } ctx; } *

variable_types:
buf
unsigned char *

variable_types:
blen
unsigned long

return_type: int

user_defined_types: struct mbedtls_ecdh_context { unsigned char point_format; enum mbedtls_ecp_group_id grp_id; enum mbedtls_ecdh_variant var; union { struct mbedtls_ecdh_context_mbed mbed_ecdh; } ctx; }

user_defined_types: struct mbedtls_ecdh_context_mbed { struct mbedtls_ecp_group grp; struct mbedtls_mpi d; struct mbedtls_ecp_point Q; struct mbedtls_ecp_point Qp; struct mbedtls_mpi z; }

user_defined_types: struct mbedtls_ecp_group { enum mbedtls_ecp_group_id id; struct mbedtls_mpi P; struct mbedtls_mpi A; struct mbedtls_mpi B; struct mbedtls_ecp_point G; struct mbedtls_mpi N; unsigned long pbits; unsigned long nbits; unsigned int h; int (*modp)(struct mbedtls_mpi *); int (*t_pre)(struct mbedtls_ecp_point *, void *); int (*t_post)(struct mbedtls_ecp_point *, void *); void *t_data; struct mbedtls_ecp_point *T; unsigned long T_size; }


decompiled_code:
__int64 __fastcall mbedtls_ecdh_calc_secret(__int64 a1, __int64 *a2, __int64 a3, unsigned __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 8) == 1 )
result = ecdh_calc_secret_internal_constprop_0(a1 + 16, a2, a3, a4, a5, a6);
else
result = 4294946944LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 *a2, __int64 a3, unsigned __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 8) == 1 )
result = func14(a1 + 16, a2, a3, a4, a5, a6);
else
result = 4294946944LL;
return result;
}

original_code:
int mbedtls_ecdh_calc_secret(mbedtls_ecdh_context *ctx, size_t *olen,
                             unsigned char *buf, size_t blen,
                             int (*f_rng)(void *, unsigned char *, size_t),
                             void *p_rng)
{
    int restart_enabled = 0;
    switch (ctx->var) {
        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
            return ecdh_calc_secret_internal(&ctx->ctx.mbed_ecdh, olen, buf,
                                             blen, f_rng, p_rng,
                                             restart_enabled);
        default:
            return -0x4F80;
    }
}

canonical_original_code:
int mbedtls_ecdh_calc_secret(struct mbedtls_ecdh_context *ctx, unsigned long *olen, unsigned char *buf, unsigned long blen, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    int restart_enabled = 0;
    switch (ctx->var) {
        case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0:
            return ecdh_calc_secret_internal(&ctx->ctx.mbed_ecdh, olen, buf,
                                             blen, f_rng, p_rng,
                                             restart_enabled);
        default:
            return -0x4F80;
    }
}

variable_types:
olen
unsigned long *

variable_types: int (*)(void *, unsigned char *, unsigned long)

user_defined_types: enum mbedtls_ecp_group_id { MBEDTLS_ECP_DP_NONE=0, MBEDTLS_ECP_DP_SECP192R1=1, MBEDTLS_ECP_DP_SECP224R1=2, MBEDTLS_ECP_DP_SECP256R1=3, MBEDTLS_ECP_DP_SECP384R1=4, MBEDTLS_ECP_DP_SECP521R1=5, MBEDTLS_ECP_DP_BP256R1=6, MBEDTLS_ECP_DP_BP384R1=7, MBEDTLS_ECP_DP_BP512R1=8, MBEDTLS_ECP_DP_CURVE25519=9, MBEDTLS_ECP_DP_SECP192K1=10, MBEDTLS_ECP_DP_SECP224K1=11, MBEDTLS_ECP_DP_SECP256K1=12, MBEDTLS_ECP_DP_CURVE448=13 }

user_defined_types: enum mbedtls_ecdh_variant { MBEDTLS_ECDH_VARIANT_NONE=0, MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0=1 }

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

user_defined_types: struct mbedtls_ecp_point { struct mbedtls_mpi X; struct mbedtls_mpi Y; struct mbedtls_mpi Z; }


decompiled_code:
__int64 __fastcall server_set_PREFIX(__int64 a1, __int64 a2)
{
return mode_cfg(a1 + 276, a2, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return mode_cfg(a1 + 276, a2, 4LL);
}

original_code:
static int
server_set_PREFIX(struct server *s, char *val)
{
 return mode_cfg(&(s->mode_cfg), val, MODE_CFG_PREFIX);
}

variable_types: struct server { char *host; char *port; char *pass; char *username; char *realname; char *nick; char *mode; enum casemapping { CASEMAPPING_INVALID=0, CASEMAPPING_ASCII=1, CASEMAPPING_RFC1459=2, CASEMAPPING_STRICT_RFC1459=3 } casemapping; struct { unsigned long next; unsigned long size; char *base; char **set; } nicks; struct channel { char *name; char *key; enum activity { ACTIVITY_DEFAULT=0, ACTIVITY_JPQ=1, ACTIVITY_ACTIVE=2, ACTIVITY_PINGED=3, ACTIVITY_T_SIZE=4 } activity; enum channel_type { CHANNEL_T_INVALID=0, CHANNEL_T_RIRC=1, CHANNEL_T_CHANNEL=2, CHANNEL_T_PRIVMSG=3, CHANNEL_T_SERVER=4, CHANNEL_T_SIZE=5 } type; unsigned long name_len; struct buffer { unsigned int head; unsigned int tail; unsigned int scrollback; unsigned long pad; struct buffer_line { enum buffer_line_type { BUFFER_LINE_OTHER=0, BUFFER_LINE_SERVER_INFO=1, BUFFER_LINE_SERVER_ERROR=2, BUFFER_LINE_JOIN=3, BUFFER_LINE_NICK=4, BUFFER_LINE_PART=5, BUFFER_LINE_QUIT=6, BUFFER_LINE_CHAT=7, BUFFER_LINE_PINGED=8, BUFFER_LINE_T_SIZE=9 } type; char prefix; char from[-1]; char text[-1]; unsigned long from_len; unsigned long text_len; long time; struct { unsigned int colour; unsigned int cols; unsigned int rows; unsigned int initialized; } cached; } buffer_lines[-1]; unsigned int buffer_i_bot; unsigned int buffer_i_top; long time_last; } buffer; struct channel *next; struct channel *prev; struct input { char buf[410]; struct { char *ptrs[16]; unsigned short current; unsigned short head; unsigned short tail; } hist; unsigned short head; unsigned short tail; unsigned short window; } input; struct mode { char prefix; unsigned int lower; unsigned int upper; } chanmodes; struct mode_str { char str[-1]; } chanmodes_str; struct server *server; struct user_list { struct user { struct { int height; struct user *tree_left; struct user *tree_right; } ul; char *nick; unsigned long nick_len; struct mode prfxmodes; char _[]; } *tree_root; unsigned int count; } users; unsigned int parted; unsigned int joined; char _[]; } *channel; struct channel_list { struct channel *head; struct channel *tail; unsigned int count; } clist; struct ircv3_caps { struct ircv3_cap { char *val; unsigned int req; unsigned int req_auto; unsigned int set; unsigned int supported; unsigned int supports_del; unsigned int supports_req; } account_notify; struct ircv3_cap away_notify; struct ircv3_cap chghost; struct ircv3_cap extended_join; struct ircv3_cap invite_notify; struct ircv3_cap multi_prefix; struct ircv3_cap sasl; } ircv3_caps; struct ircv3_sasl { enum { IRCV3_SASL_MECH_NONE=0, IRCV3_SASL_MECH_EXTERNAL=1, IRCV3_SASL_MECH_PLAIN=2 } mech; enum { IRCV3_SASL_STATE_NONE=0, IRCV3_SASL_STATE_REQ_MECH=1, IRCV3_SASL_STATE_AUTHENTICATED=2 } state; char *user; char *pass; } ircv3_sasl; struct mode usermodes; 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; } mode_cfg; struct mode_str mode_str; struct server *next; struct server *prev; unsigned int ping; unsigned int connected; unsigned int quitting; unsigned int registered; void *connection; struct { unsigned long i; char cl; char buf[-1]; } read; } *

variable_types:
val
char *

user_defined_types: struct server { char *host; char *port; char *pass; char *username; char *realname; char *nick; char *mode; enum casemapping casemapping; struct { unsigned long next; unsigned long size; char *base; char **set; } nicks; struct channel *channel; struct channel_list clist; struct ircv3_caps ircv3_caps; struct ircv3_sasl ircv3_sasl; struct mode usermodes; struct mode_cfg mode_cfg; struct mode_str mode_str; struct server *next; struct server *prev; unsigned int ping; unsigned int connected; unsigned int quitting; unsigned int registered; void *connection; struct { unsigned long i; char cl; char buf[-1]; } read; }

user_defined_types: struct ircv3_caps { struct ircv3_cap account_notify; struct ircv3_cap away_notify; struct ircv3_cap chghost; struct ircv3_cap extended_join; struct ircv3_cap invite_notify; struct ircv3_cap multi_prefix; struct ircv3_cap sasl; }

user_defined_types: struct channel { char *name; char *key; enum activity activity; enum channel_type type; unsigned long name_len; struct buffer buffer; struct channel *next; struct channel *prev; struct input input; struct mode chanmodes; struct mode_str chanmodes_str; struct server *server; struct user_list users; unsigned int parted; unsigned int joined; char _[]; }

user_defined_types: struct buffer { unsigned int head; unsigned int tail; unsigned int scrollback; unsigned long pad; struct buffer_line buffer_lines[-1]; unsigned int buffer_i_bot; unsigned int buffer_i_top; long time_last; }

user_defined_types: struct user_list { struct user *tree_root; unsigned int count; }

user_defined_types: struct buffer_line { enum buffer_line_type type; char prefix; char from[-1]; char text[-1]; unsigned long from_len; unsigned long text_len; long time; struct { unsigned int colour; unsigned int cols; unsigned int rows; unsigned int initialized; } cached; }


decompiled_code:
__int64 __fastcall server_set_CHANMODES(__int64 a1, __int64 a2)
{
return mode_cfg(a1 + 276, a2, 3LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return mode_cfg(a1 + 276, a2, 3LL);
}

original_code:
static int
server_set_CHANMODES(struct server *s, char *val)
{
 return mode_cfg(&(s->mode_cfg), val, MODE_CFG_SUBTYPES);
}

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

user_defined_types: struct channel_list { struct channel *head; struct channel *tail; unsigned int count; }

user_defined_types: struct ircv3_sasl { enum { IRCV3_SASL_MECH_NONE=0, IRCV3_SASL_MECH_EXTERNAL=1, IRCV3_SASL_MECH_PLAIN=2 } mech; enum { IRCV3_SASL_STATE_NONE=0, IRCV3_SASL_STATE_REQ_MECH=1, IRCV3_SASL_STATE_AUTHENTICATED=2 } state; char *user; char *pass; }

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

user_defined_types: struct ircv3_cap { char *val; unsigned int req; unsigned int req_auto; unsigned int set; unsigned int supported; unsigned int supports_del; unsigned int supports_req; }

user_defined_types: enum activity { ACTIVITY_DEFAULT=0, ACTIVITY_JPQ=1, ACTIVITY_ACTIVE=2, ACTIVITY_PINGED=3, ACTIVITY_T_SIZE=4 }

user_defined_types: enum channel_type { CHANNEL_T_INVALID=0, CHANNEL_T_RIRC=1, CHANNEL_T_CHANNEL=2, CHANNEL_T_PRIVMSG=3, CHANNEL_T_SERVER=4, CHANNEL_T_SIZE=5 }

user_defined_types: struct input { char buf[410]; struct { char *ptrs[16]; unsigned short current; unsigned short head; unsigned short tail; } hist; unsigned short head; unsigned short tail; unsigned short window; }

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

user_defined_types: struct user { struct { int height; struct user *tree_left; struct user *tree_right; } ul; char *nick; unsigned long nick_len; struct mode prfxmodes; char _[]; }

user_defined_types: enum buffer_line_type { BUFFER_LINE_OTHER=0, BUFFER_LINE_SERVER_INFO=1, BUFFER_LINE_SERVER_ERROR=2, BUFFER_LINE_JOIN=3, BUFFER_LINE_NICK=4, BUFFER_LINE_PART=5, BUFFER_LINE_QUIT=6, BUFFER_LINE_CHAT=7, BUFFER_LINE_PINGED=8, BUFFER_LINE_T_SIZE=9 }


decompiled_code:
int __fastcall server_cmp(const char **a1, const char *a2, const char *a3)
{
int result; // eax

result = strcmp(*a1, a2);
if ( !result )
result = strcmp(a1[1], a3);
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char **a1, const char *a2, const char *a3)
{
int result; // eax

result = strcmp(*a1, a2);
if ( !result )
result = strcmp(a1[1], a3);
return result;
}

original_code:
static int
server_cmp(const struct server *s, const char *host, const char *port)
{
 int cmp;
 if ((cmp = strcmp(s->host, host)))
  return cmp;
 if ((cmp = strcmp(s->port, port)))
  return cmp;
 return 0;
}

canonical_original_code:
static int server_cmp(struct server *s, char *host, char *port)
{
 int cmp;
 if ((cmp = strcmp(s->host, host)))
  return cmp;
 if ((cmp = strcmp(s->port, port)))
  return cmp;
 return 0;
}

variable_types:
host
char *

variable_types:
port
char *

variable_types: cmp int

user_defined_types: struct server { char *host; char *port; char *pass; char *username; char *realname; char *nick; char *mode; enum casemapping casemapping; struct { unsigned long next; unsigned long size; char *base; char **set; } nicks; struct channel *channel; struct channel_list clist; struct ircv3_caps ircv3_caps; struct ircv3_sasl ircv3_sasl; struct mode usermodes; struct mode_cfg mode_cfg; struct mode_str mode_str; struct server *next; struct server *prev; unsigned int ping; unsigned int connected; unsigned int quitting; unsigned int registered; void *connection; struct { unsigned long i; char cl; char buf[-1]; } read; }


decompiled_code:
__int64 __fastcall server_set_CASEMAPPING(__int64 a1, const char *a2)
{
bool v2; // zf
__int64 result; // rax

v2 = strcmp(a2, "ascii") == 0;
result = !v2;
if ( v2 )
{
*(_DWORD *)(a1 + 56) = 1;
}
else
{
v2 = strcmp(a2, "rfc1459") == 0;
result = !v2;
if ( v2 )
{
*(_DWORD *)(a1 + 56) = 2;
}
else
{
v2 = strcmp(a2, "strict-rfc1459") == 0;
result = !v2;
if ( v2 )
*(_DWORD *)(a1 + 56) = 3;
else
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
bool v2; // zf
__int64 result; // rax

v2 = strcmp(a2, "ascii") == 0;
result = !v2;
if ( v2 )
{
*(_DWORD *)(a1 + 56) = 1;
}
else
{
v2 = strcmp(a2, "rfc1459") == 0;
result = !v2;
if ( v2 )
{
*(_DWORD *)(a1 + 56) = 2;
}
else
{
v2 = strcmp(a2, "strict-rfc1459") == 0;
result = !v2;
if ( v2 )
*(_DWORD *)(a1 + 56) = 3;
else
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static int
server_set_CASEMAPPING(struct server *s, char *val)
{
 if (!strcmp(val, "ascii")) {
  s->casemapping = CASEMAPPING_ASCII;
  return 0;
 }
 if (!strcmp(val, "rfc1459")) {
  s->casemapping = CASEMAPPING_RFC1459;
  return 0;
 }
 if (!strcmp(val, "strict-rfc1459")) {
  s->casemapping = CASEMAPPING_STRICT_RFC1459;
  return 0;
 }
 return -1;
}

user_defined_types: struct ircv3_caps { struct ircv3_cap account_notify; struct ircv3_cap away_notify; struct ircv3_cap chghost; struct ircv3_cap extended_join; struct ircv3_cap invite_notify; struct ircv3_cap multi_prefix; struct ircv3_cap sasl; }


decompiled_code:
__int64 __fastcall parse_005(__int64 a1, char **a2)
{
char *v2; // rax
const unsigned __int16 **v3; // rax
char *v4; // r12
const unsigned __int16 *v5; // rdx
__int64 result; // rax
char *v7; // rax
char *v8; // rax
char *s; // [rsp+8h] [rbp-20h] BYREF

v2 = *a2;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
s = v2;
if ( !irc_strtrim(&s) )
return 0LL;
v3 = _ctype_b_loc();
v4 = s;
v5 = *v3;
result = 0LL;
if ( (v5[*s] & 8) != 0 )
{
*(_QWORD *)a1 = s;
v7 = strchr(v4, 32);
if ( v7 )
{
*v7 = 0;
*a2 = v7 + 1;
}
else
{
*a2 = &v4[strlen(v4)];
}
v8 = strchr(*(const char **)a1, 61);
if ( v8 )
{
s = v8 + 1;
*v8 = 0;
if ( *s )
*(_QWORD *)(a1 + 8) = s;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char **a2)
{
char *v2; // rax
const unsigned __int16 **v3; // rax
char *v4; // r12
const unsigned __int16 *v5; // rdx
__int64 result; // rax
char *v7; // rax
char *v8; // rax
char *s; // [rsp+8h] [rbp-20h] BYREF

v2 = *a2;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
s = v2;
if ( !irc_strtrim(&s) )
return 0LL;
v3 = _ctype_b_loc();
v4 = s;
v5 = *v3;
result = 0LL;
if ( (v5[*s] & 8) != 0 )
{
*(_QWORD *)a1 = s;
v7 = strchr(v4, 32);
if ( v7 )
{
*v7 = 0;
*a2 = v7 + 1;
}
else
{
*a2 = &v4[strlen(v4)];
}
v8 = strchr(*(const char **)a1, 61);
if ( v8 )
{
s = v8 + 1;
*v8 = 0;
if ( *s )
*(_QWORD *)(a1 + 8) = s;
}
result = 1LL;
}
return result;
}

original_code:
static int
parse_005(struct opt *opt, char **str)
{
 char *t, *p = *str;
 opt->arg = ((void *)0);
 opt->val = ((void *)0);
 if (!irc_strtrim(&p))
  return 0;
 if (!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISalnum))
  return 0;
 opt->arg = p;
 if ((t = strchr(p, ' '))) {
  *t++ = 0;
  *str = t;
 } else {
  *str = strchr(p, 0);
 }
 if ((p = strchr(opt->arg, '='))) {
  *p++ = 0;
  if (*p)
   opt->val = p;
 }
 return 1;
}

canonical_original_code:
static int parse_005(struct opt *opt, char **str)
{
 char *t; char *p = *str;
 opt->arg = ((void *)0);
 opt->val = ((void *)0);
 if (!irc_strtrim(&p))
  return 0;
 if (!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISalnum))
  return 0;
 opt->arg = p;
 if ((t = strchr(p, ' '))) {
  *t++ = 0;
  *str = t;
 } else {
  *str = strchr(p, 0);
 }
 if ((p = strchr(opt->arg, '='))) {
  *p++ = 0;
  if (*p)
   opt->val = p;
 }
 return 1;
}

variable_types:
opt
struct opt { char *arg; char *val; } *

variable_types:
str
char **

variable_types:
t
char *

variable_types:
p
char *


decompiled_code:
const char **__fastcall server_list_get(const char ***a1, const char *a2, const char *a3)
{
const char **v3; // r12
const char **v5; // rbx

v3 = *a1;
if ( !*a1 )
return v3;
v5 = *a1;
if ( !server_cmp(*a1, a2, a3) )
return v3;
do
{
v5 = (const char **)v5[64];
if ( v3 == v5 )
return 0LL;
}
while ( server_cmp(v5, a2, a3) );
return v5;
}

canonical_decompiled_code:
const char **__fastcall func5(const char ***a1, const char *a2, const char *a3)
{
const char **v3; // r12
const char **v5; // rbx

v3 = *a1;
if ( !*a1 )
return v3;
v5 = *a1;
if ( !func2(*a1, a2, a3) )
return v3;
do
{
v5 = (const char **)v5[64];
if ( v3 == v5 )
return 0LL;
}
while ( func2(v5, a2, a3) );
return v5;
}

original_code:
struct server*
server_list_get(struct server_list *sl, const char *host, const char *port)
{
 struct server *tmp;
 if ((tmp = sl->head) == ((void *)0))
  return ((void *)0);
 if (!server_cmp(sl->head, host, port))
  return sl->head;
 while ((tmp = tmp->next) != sl->head) {
  if (!server_cmp(tmp, host, port))
   return tmp;
 }
 return ((void *)0);
}

canonical_original_code:
struct server *server_list_get(struct server_list *sl, char *host, char *port)
{
 struct server *tmp;
 if ((tmp = sl->head) == ((void *)0))
  return ((void *)0);
 if (!server_cmp(sl->head, host, port))
  return sl->head;
 while ((tmp = tmp->next) != sl->head) {
  if (!server_cmp(tmp, host, port))
   return tmp;
 }
 return ((void *)0);
}

variable_types: struct server_list { struct server *head; struct server *tail; } *

return_type: struct server { char *host; char *port; char *pass; char *username; char *realname; char *nick; char *mode; enum casemapping { CASEMAPPING_INVALID=0, CASEMAPPING_ASCII=1, CASEMAPPING_RFC1459=2, CASEMAPPING_STRICT_RFC1459=3 } casemapping; struct { unsigned long next; unsigned long size; char *base; char **set; } nicks; struct channel { char *name; char *key; enum activity { ACTIVITY_DEFAULT=0, ACTIVITY_JPQ=1, ACTIVITY_ACTIVE=2, ACTIVITY_PINGED=3, ACTIVITY_T_SIZE=4 } activity; enum channel_type { CHANNEL_T_INVALID=0, CHANNEL_T_RIRC=1, CHANNEL_T_CHANNEL=2, CHANNEL_T_PRIVMSG=3, CHANNEL_T_SERVER=4, CHANNEL_T_SIZE=5 } type; unsigned long name_len; struct buffer { unsigned int head; unsigned int tail; unsigned int scrollback; unsigned long pad; struct buffer_line { enum buffer_line_type { BUFFER_LINE_OTHER=0, BUFFER_LINE_SERVER_INFO=1, BUFFER_LINE_SERVER_ERROR=2, BUFFER_LINE_JOIN=3, BUFFER_LINE_NICK=4, BUFFER_LINE_PART=5, BUFFER_LINE_QUIT=6, BUFFER_LINE_CHAT=7, BUFFER_LINE_PINGED=8, BUFFER_LINE_T_SIZE=9 } type; char prefix; char from[-1]; char text[-1]; unsigned long from_len; unsigned long text_len; long time; struct { unsigned int colour; unsigned int cols; unsigned int rows; unsigned int initialized; } cached; } buffer_lines[-1]; unsigned int buffer_i_bot; unsigned int buffer_i_top; long time_last; } buffer; struct channel *next; struct channel *prev; struct input { char buf[410]; struct { char *ptrs[16]; unsigned short current; unsigned short head; unsigned short tail; } hist; unsigned short head; unsigned short tail; unsigned short window; } input; struct mode { char prefix; unsigned int lower; unsigned int upper; } chanmodes; struct mode_str { char str[-1]; } chanmodes_str; struct server *server; struct user_list { struct user { struct { int height; struct user *tree_left; struct user *tree_right; } ul; char *nick; unsigned long nick_len; struct mode prfxmodes; char _[]; } *tree_root; unsigned int count; } users; unsigned int parted; unsigned int joined; char _[]; } *channel; struct channel_list { struct channel *head; struct channel *tail; unsigned int count; } clist; struct ircv3_caps { struct ircv3_cap { char *val; unsigned int req; unsigned int req_auto; unsigned int set; unsigned int supported; unsigned int supports_del; unsigned int supports_req; } account_notify; struct ircv3_cap away_notify; struct ircv3_cap chghost; struct ircv3_cap extended_join; struct ircv3_cap invite_notify; struct ircv3_cap multi_prefix; struct ircv3_cap sasl; } ircv3_caps; struct ircv3_sasl { enum { IRCV3_SASL_MECH_NONE=0, IRCV3_SASL_MECH_EXTERNAL=1, IRCV3_SASL_MECH_PLAIN=2 } mech; enum { IRCV3_SASL_STATE_NONE=0, IRCV3_SASL_STATE_REQ_MECH=1, IRCV3_SASL_STATE_AUTHENTICATED=2 } state; char *user; char *pass; } ircv3_sasl; struct mode usermodes; 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; } mode_cfg; struct mode_str mode_str; struct server *next; struct server *prev; unsigned int ping; unsigned int connected; unsigned int quitting; unsigned int registered; void *connection; struct { unsigned long i; char cl; char buf[-1]; } read; } *

user_defined_types: struct channel { char *name; char *key; enum activity activity; enum channel_type type; unsigned long name_len; struct buffer buffer; struct channel *next; struct channel *prev; struct input input; struct mode chanmodes; struct mode_str chanmodes_str; struct server *server; struct user_list users; unsigned int parted; unsigned int joined; char _[]; }


original_code:
struct server*
server_list_del(struct server_list *sl, struct server *s)
{
 struct server *tmp_h,
               *tmp_t;
 if (sl->head == s && sl->tail == s) {
  sl->head = ((void *)0);
  sl->tail = ((void *)0);
 } else if ((tmp_h = sl->head) == s) {
  sl->head = sl->tail->next = sl->head->next;
  sl->head->prev = sl->tail;
 } else if ((tmp_t = sl->tail) == s) {
  sl->tail = sl->head->prev = sl->tail->prev;
  sl->tail->next = sl->head;
 } else {
  while ((tmp_h = tmp_h->next) != s) {
   if (tmp_h == tmp_t)
    return ((void *)0);
  }
  s->next->prev = s->prev;
  s->prev->next = s->next;
 }
 s->next = ((void *)0);
 s->prev = ((void *)0);
 return s;
}

canonical_original_code:
struct server *server_list_del(struct server_list *sl, struct server *s)
{
 struct server *tmp_h; struct server *tmp_t;
 if (sl->head == s && sl->tail == s) {
  sl->head = ((void *)0);
  sl->tail = ((void *)0);
 } else if ((tmp_h = sl->head) == s) {
  sl->head = sl->tail->next = sl->head->next;
  sl->head->prev = sl->tail;
 } else if ((tmp_t = sl->tail) == s) {
  sl->tail = sl->head->prev = sl->tail->prev;
  sl->tail->next = sl->head;
 } else {
  while ((tmp_h = tmp_h->next) != s) {
   if (tmp_h == tmp_t)
    return ((void *)0);
  }
  s->next->prev = s->prev;
  s->prev->next = s->next;
 }
 s->next = ((void *)0);
 s->prev = ((void *)0);
 return s;
}

variable_types:
s
struct server *

user_defined_types: struct server_list { struct server *head; struct server *tail; }

user_defined_types: struct buffer { unsigned int head; unsigned int tail; unsigned int scrollback; unsigned long pad; struct buffer_line buffer_lines[-1]; unsigned int buffer_i_bot; unsigned int buffer_i_top; long time_last; }


original_code:
void
server_reset(struct server *s)
{
 ircv3_caps_reset(&(s->ircv3_caps));
 ircv3_sasl_reset(&(s->ircv3_sasl));
 memset(&(s->usermodes), 0, sizeof(s->usermodes));
 memset(&(s->mode_str), 0, sizeof(s->mode_str));
 s->ping = 0;
 s->quitting = 0;
 s->registered = 0;
 s->nicks.next = 0;
}

return_type: void

user_defined_types: struct user_list { struct user *tree_root; unsigned int count; }

user_defined_types: struct buffer_line { enum buffer_line_type type; char prefix; char from[-1]; char text[-1]; unsigned long from_len; unsigned long text_len; long time; struct { unsigned int colour; unsigned int cols; unsigned int rows; unsigned int initialized; } cached; }


decompiled_code:
void __fastcall server_free(void *ptr)
{
channel_list_free((char *)ptr + 104);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 6));
free(*((void **)ptr + 5));
free(*((void **)ptr + 10));
free(*((void **)ptr + 11));
free(*((void **)ptr + 31));
free(*((void **)ptr + 32));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
channel_list_free((char *)ptr + 104);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 6));
free(*((void **)ptr + 5));
free(*((void **)ptr + 10));
free(*((void **)ptr + 11));
free(*((void **)ptr + 31));
free(*((void **)ptr + 32));
free(ptr);
}

original_code:
void
server_free(struct server *s)
{
 channel_list_free(&(s->clist));
 free((void *)s->host);
 free((void *)s->port);
 free((void *)s->pass);
 free((void *)s->username);
 free((void *)s->realname);
 free((void *)s->mode);
 free((void *)s->nick);
 free((void *)s->nicks.base);
 free((void *)s->nicks.set);
 free((void *)s->ircv3_sasl.user);
 free((void *)s->ircv3_sasl.pass);
 free(s);
}

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

user_defined_types: struct channel_list { struct channel *head; struct channel *tail; unsigned int count; }


decompiled_code:
__int64 __fastcall server_set_chans(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
char *v3; // r13
const char *i; // rbp
const char *v5; // r14
char *v6; // rax
const char *j; // rbp
__int64 v8; // rsi

v2 = 0LL;
v3 = (char *)irc_strdup(a2);
for ( i = v3; ; i = v5 )
{
++v2;
v6 = strchr(i, 44);
if ( !v6 )
break;
*v6 = 0;
v5 = v6 + 1;
if ( !(unsigned int)irc_ischan(i) && !(unsigned int)irc_isnick(i) )
goto LABEL_16;
}
if ( !(unsigned int)irc_ischan(i) && !(unsigned int)irc_isnick(i) )
{
LABEL_16:
free(v3);
return 0xFFFFFFFFLL;
}
for ( j = v3; v2; --v2 )
{
while ( channel_list_get(a1 + 104, j, *(unsigned int *)(a1 + 56)) )
{
if ( !--v2 )
goto LABEL_14;
}
if ( (unsigned int)irc_ischan(j) )
v8 = channel(j, 2LL);
else
v8 = channel(j, 3LL);
*(_QWORD *)(v8 + 680656) = a1;
channel_list_add(a1 + 104, v8);
j += strlen(j) + 1;
}
LABEL_14:
free(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
char *v3; // r13
const char *i; // rbp
const char *v5; // r14
char *v6; // rax
const char *j; // rbp
__int64 v8; // rsi

v2 = 0LL;
v3 = (char *)irc_strdup(a2);
for ( i = v3; ; i = v5 )
{
++v2;
v6 = strchr(i, 44);
if ( !v6 )
break;
*v6 = 0;
v5 = v6 + 1;
if ( !(unsigned int)irc_ischan(i) && !(unsigned int)irc_isnick(i) )
goto LABEL_16;
}
if ( !(unsigned int)irc_ischan(i) && !(unsigned int)irc_isnick(i) )
{
LABEL_16:
free(v3);
return 0xFFFFFFFFLL;
}
for ( j = v3; v2; --v2 )
{
while ( channel_list_get(a1 + 104, j, *(unsigned int *)(a1 + 56)) )
{
if ( !--v2 )
goto LABEL_14;
}
if ( (unsigned int)irc_ischan(j) )
v8 = channel(j, 2LL);
else
v8 = channel(j, 3LL);
*(_QWORD *)(v8 + 680656) = a1;
channel_list_add(a1 + 104, v8);
j += strlen(j) + 1;
}
LABEL_14:
free(v3);
return 0LL;
}

original_code:
int
server_set_chans(struct server *s, const char *str)
{
 char *dup;
 char *p1;
 char *p2;
 size_t n_chans = 0;
 p2 = dup = irc_strdup(str);
 do {
  n_chans++;
  p1 = p2;
  p2 = strchr(p2, ',');
  if (p2)
   *p2++ = 0;
  if (!irc_ischan(p1) && !irc_isnick(p1)) {
   free(dup);
   return -1;
  }
 } while (p2);
 for (const char *chan = dup; n_chans; n_chans--) {
  struct channel *c;
  if (channel_list_get(&s->clist, chan, s->casemapping))
   continue;
  if (irc_ischan(chan))
   c = channel(chan, CHANNEL_T_CHANNEL);
  else
   c = channel(chan, CHANNEL_T_PRIVMSG);
  c->server = s;
  channel_list_add(&s->clist, c);
  chan = strchr(chan, 0) + 1;
 }
 free(dup);
 return 0;
}

canonical_original_code:
int server_set_chans(struct server *s, char *str)
{
 char *dup;
 char *p1;
 char *p2;
 unsigned long n_chans = 0;
 p2 = dup = irc_strdup(str);
 do {
  n_chans++;
  p1 = p2;
  p2 = strchr(p2, ',');
  if (p2)
   *p2++ = 0;
  if (!irc_ischan(p1) && !irc_isnick(p1)) {
   free(dup);
   return -1;
  }
 } while (p2);
 for (char *chan = dup; n_chans; n_chans--) {
  struct channel *c;
  if (channel_list_get(&s->clist, chan, s->casemapping))
   continue;
  if (irc_ischan(chan))
   c = channel(chan, CHANNEL_T_CHANNEL);
  else
   c = channel(chan, CHANNEL_T_PRIVMSG);
  c->server = s;
  channel_list_add(&s->clist, c);
  chan = strchr(chan, 0) + 1;
 }
 free(dup);
 return 0;
}

variable_types:
str
char *

variable_types:
dup
char *

variable_types:
chan
char *

variable_types: struct channel { char *name; char *key; enum activity { ACTIVITY_DEFAULT=0, ACTIVITY_JPQ=1, ACTIVITY_ACTIVE=2, ACTIVITY_PINGED=3, ACTIVITY_T_SIZE=4 } activity; enum channel_type { CHANNEL_T_INVALID=0, CHANNEL_T_RIRC=1, CHANNEL_T_CHANNEL=2, CHANNEL_T_PRIVMSG=3, CHANNEL_T_SERVER=4, CHANNEL_T_SIZE=5 } type; unsigned long name_len; struct buffer { unsigned int head; unsigned int tail; unsigned int scrollback; unsigned long pad; struct buffer_line { enum buffer_line_type { BUFFER_LINE_OTHER=0, BUFFER_LINE_SERVER_INFO=1, BUFFER_LINE_SERVER_ERROR=2, BUFFER_LINE_JOIN=3, BUFFER_LINE_NICK=4, BUFFER_LINE_PART=5, BUFFER_LINE_QUIT=6, BUFFER_LINE_CHAT=7, BUFFER_LINE_PINGED=8, BUFFER_LINE_T_SIZE=9 } type; char prefix; char from[-1]; char text[-1]; unsigned long from_len; unsigned long text_len; long time; struct { unsigned int colour; unsigned int cols; unsigned int rows; unsigned int initialized; } cached; } buffer_lines[-1]; unsigned int buffer_i_bot; unsigned int buffer_i_top; long time_last; } buffer; struct channel *next; struct channel *prev; struct input { char buf[410]; struct { char *ptrs[16]; unsigned short current; unsigned short head; unsigned short tail; } hist; unsigned short head; unsigned short tail; unsigned short window; } input; struct mode { char prefix; unsigned int lower; unsigned int upper; } chanmodes; struct mode_str { char str[-1]; } chanmodes_str; struct server { char *host; char *port; char *pass; char *username; char *realname; char *nick; char *mode; enum casemapping { CASEMAPPING_INVALID=0, CASEMAPPING_ASCII=1, CASEMAPPING_RFC1459=2, CASEMAPPING_STRICT_RFC1459=3 } casemapping; struct { unsigned long next; unsigned long size; char *base; char **set; } nicks; struct channel *channel; struct channel_list { struct channel *head; struct channel *tail; unsigned int count; } clist; struct ircv3_caps { struct ircv3_cap { char *val; unsigned int req; unsigned int req_auto; unsigned int set; unsigned int supported; unsigned int supports_del; unsigned int supports_req; } account_notify; struct ircv3_cap away_notify; struct ircv3_cap chghost; struct ircv3_cap extended_join; struct ircv3_cap invite_notify; struct ircv3_cap multi_prefix; struct ircv3_cap sasl; } ircv3_caps; struct ircv3_sasl { enum { IRCV3_SASL_MECH_NONE=0, IRCV3_SASL_MECH_EXTERNAL=1, IRCV3_SASL_MECH_PLAIN=2 } mech; enum { IRCV3_SASL_STATE_NONE=0, IRCV3_SASL_STATE_REQ_MECH=1, IRCV3_SASL_STATE_AUTHENTICATED=2 } state; char *user; char *pass; } ircv3_sasl; struct mode usermodes; 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; } mode_cfg; struct mode_str mode_str; struct server *next; struct server *prev; unsigned int ping; unsigned int connected; unsigned int quitting; unsigned int registered; void *connection; struct { unsigned long i; char cl; char buf[-1]; } read; } *server; struct user_list { struct user { struct { int height; struct user *tree_left; struct user *tree_right; } ul; char *nick; unsigned long nick_len; struct mode prfxmodes; char _[]; } *tree_root; unsigned int count; } users; unsigned int parted; unsigned int joined; char _[]; } *


decompiled_code:
__int64 __fastcall server_set_nicks(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
char *v3; // r12
const char *i; // rbp
char *v5; // rax
const char *v6; // r14
char **v8; // rax
char **v9; // rbp
int *v10; // rax
char *v11; // rax

v2 = 0LL;
v3 = (char *)irc_strdup(a2);
for ( i = v3; ; i = v6 )
{
++v2;
v5 = strchr(i, 44);
if ( !v5 )
break;
*v5 = 0;
v6 = v5 + 1;
if ( !(unsigned int)irc_isnick(i) )
goto LABEL_6;
}
if ( !(unsigned int)irc_isnick(i) )
{
LABEL_6:
free(v3);
return 0xFFFFFFFFLL;
}
free(*(void **)(a1 + 80));
free(*(void **)(a1 + 88));
*(_QWORD *)(a1 + 64) = 0LL;
*(_QWORD *)(a1 + 72) = v2;
*(_QWORD *)(a1 + 80) = v3;
v8 = (char **)malloc(8 * v2);
*(_QWORD *)(a1 + 88) = v8;
v9 = v8;
if ( !v8 )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/server.c", 251LL, "server_set_nicks");
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "malloc: %s", v11);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
for ( ; v2; --v2 )
{
*v9++ = v3;
v3 += strlen(v3) + 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
char *v3; // r12
const char *i; // rbp
char *v5; // rax
const char *v6; // r14
char **v8; // rax
char **v9; // rbp
int *v10; // rax
char *v11; // rax

v2 = 0LL;
v3 = (char *)irc_strdup(a2);
for ( i = v3; ; i = v6 )
{
++v2;
v5 = strchr(i, 44);
if ( !v5 )
break;
*v5 = 0;
v6 = v5 + 1;
if ( !(unsigned int)irc_isnick(i) )
goto LABEL_6;
}
if ( !(unsigned int)irc_isnick(i) )
{
LABEL_6:
free(v3);
return 0xFFFFFFFFLL;
}
free(*(void **)(a1 + 80));
free(*(void **)(a1 + 88));
*(_QWORD *)(a1 + 64) = 0LL;
*(_QWORD *)(a1 + 72) = v2;
*(_QWORD *)(a1 + 80) = v3;
v8 = (char **)malloc(8 * v2);
*(_QWORD *)(a1 + 88) = v8;
v9 = v8;
if ( !v8 )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/server.c", 251LL, "server_set_nicks");
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "malloc: %s", v11);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
for ( ; v2; --v2 )
{
*v9++ = v3;
v3 += strlen(v3) + 1;
}
return 0LL;
}

original_code:
int
server_set_nicks(struct server *s, const char *str)
{
 char *dup;
 char *p1;
 char *p2;
 size_t n_nicks = 0;
 p2 = dup = irc_strdup(str);
 do {
  n_nicks++;
  p1 = p2;
  p2 = strchr(p2, ',');
  if (p2)
   *p2++ = 0;
  if (!irc_isnick(p1)) {
   free(dup);
   return -1;
  }
 } while (p2);
 free((void *)s->nicks.base);
 free((void *)s->nicks.set);
 s->nicks.next = 0;
 s->nicks.size = n_nicks;
 s->nicks.base = dup;
 if ((s->nicks.set = malloc(sizeof(*s->nicks.set) * n_nicks)) == ((void *)0))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/server.c", 251, __func__); fprintf(stderr, "malloc: %s", strerror((*__errno_location ()))); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 for (const char **set = s->nicks.set; n_nicks; n_nicks--, set++) {
  *set = dup;
  dup = strchr(dup, 0) + 1;
 }
 return 0;
}

canonical_original_code:
int server_set_nicks(struct server *s, char *str)
{
 char *dup;
 char *p1;
 char *p2;
 unsigned long n_nicks = 0;
 p2 = dup = irc_strdup(str);
 do {
  n_nicks++;
  p1 = p2;
  p2 = strchr(p2, ',');
  if (p2)
   *p2++ = 0;
  if (!irc_isnick(p1)) {
   free(dup);
   return -1;
  }
 } while (p2);
 free((void *)s->nicks.base);
 free((void *)s->nicks.set);
 s->nicks.next = 0;
 s->nicks.size = n_nicks;
 s->nicks.base = dup;
 if ((s->nicks.set = malloc(sizeof(*s->nicks.set) * n_nicks)) == ((void *)0))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/server.c", 251, __func__); fprintf(stderr, "malloc: %s", strerror((*__errno_location ()))); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 for (char **set = s->nicks.set; n_nicks; n_nicks--, set++) {
  *set = dup;
  dup = strchr(dup, 0) + 1;
 }
 return 0;
}

variable_types:
set
char **

user_defined_types: struct ircv3_sasl { enum { IRCV3_SASL_MECH_NONE=0, IRCV3_SASL_MECH_EXTERNAL=1, IRCV3_SASL_MECH_PLAIN=2 } mech; enum { IRCV3_SASL_STATE_NONE=0, IRCV3_SASL_STATE_REQ_MECH=1, IRCV3_SASL_STATE_AUTHENTICATED=2 } state; char *user; char *pass; }

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 server_set_004(__int64 a1, __int64 a2)
{
const char *v2; // rbp
const char *v3; // r12
__int64 v4; // r13
__int64 result; // rax
__int64 v6[6]; // [rsp+8h] [rbp-30h] BYREF

v6[0] = a2;
if ( !irc_strsep(v6) )
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: server_name is null");
if ( !irc_strsep(v6) )
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: version is null");
v2 = (const char *)irc_strsep(v6);
if ( !v2 )
{
v4 = a1 + 276;
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: user_modes is null");
v3 = (const char *)irc_strsep(v6);
if ( !v3 )
return newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: chan_modes is null");
goto LABEL_9;
}
v3 = (const char *)irc_strsep(v6);
if ( v3 )
{
v4 = a1 + 276;
if ( (unsigned int)mode_cfg(a1 + 276, v2, 2LL) )
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004 user_modes: %s", v2);
LABEL_9:
result = mode_cfg(v4, v3, 1LL);
if ( (_DWORD)result )
result = newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004 chan_modes: %s", v3);
return result;
}
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: chan_modes is null");
result = mode_cfg(a1 + 276, v2, 2LL);
if ( (_DWORD)result )
result = newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004 user_modes: %s", v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
const char *v2; // rbp
const char *v3; // r12
__int64 v4; // r13
__int64 result; // rax
__int64 v6[6]; // [rsp+8h] [rbp-30h] BYREF

v6[0] = a2;
if ( !irc_strsep(v6) )
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: server_name is null");
if ( !irc_strsep(v6) )
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: version is null");
v2 = (const char *)irc_strsep(v6);
if ( !v2 )
{
v4 = a1 + 276;
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: user_modes is null");
v3 = (const char *)irc_strsep(v6);
if ( !v3 )
return newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: chan_modes is null");
goto LABEL_9;
}
v3 = (const char *)irc_strsep(v6);
if ( v3 )
{
v4 = a1 + 276;
if ( (unsigned int)mode_cfg(a1 + 276, v2, 2LL) )
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004 user_modes: %s", v2);
LABEL_9:
result = mode_cfg(v4, v3, 1LL);
if ( (_DWORD)result )
result = newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004 chan_modes: %s", v3);
return result;
}
newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004: chan_modes is null");
result = mode_cfg(a1 + 276, v2, 2LL);
if ( (_DWORD)result )
result = newlinef(*(_QWORD *)(a1 + 96), 2LL, "-!!-", "invalid numeric 004 user_modes: %s", v2);
return result;
}

original_code:
void
server_set_004(struct server *s, char *str)
{
 const char *user_modes;
 const char *chan_modes;
 if (!irc_strsep(&str))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: server_name is null"); } while (0);
 if (!irc_strsep(&str))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: version is null"); } while (0);
 if (!(user_modes = irc_strsep(&str)))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: user_modes is null"); } while (0);
 if (!(chan_modes = irc_strsep(&str)))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: chan_modes is null"); } while (0);
 if (user_modes) {
  if (!mode_cfg(&(s->mode_cfg), user_modes, MODE_CFG_USERMODES))
   do { ; } while (0);
  else
   do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004 user_modes: %s", user_modes); } while (0);
 }
 if (chan_modes) {
  if (!mode_cfg(&(s->mode_cfg), chan_modes, MODE_CFG_CHANMODES))
   do { ; } while (0);
  else
   do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004 chan_modes: %s", chan_modes); } while (0);
 }
}

canonical_original_code:
void server_set_004(struct server *s, char *str)
{
 char *user_modes;
 char *chan_modes;
 if (!irc_strsep(&str))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: server_name is null"); } while (0);
 if (!irc_strsep(&str))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: version is null"); } while (0);
 if (!(user_modes = irc_strsep(&str)))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: user_modes is null"); } while (0);
 if (!(chan_modes = irc_strsep(&str)))
  do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004: chan_modes is null"); } while (0);
 if (user_modes) {
  if (!mode_cfg(&(s->mode_cfg), user_modes, MODE_CFG_USERMODES))
   do { ; } while (0);
  else
   do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004 user_modes: %s", user_modes); } while (0);
 }
 if (chan_modes) {
  if (!mode_cfg(&(s->mode_cfg), chan_modes, MODE_CFG_CHANMODES))
   do { ; } while (0);
  else
   do { newlinef((s)->channel, BUFFER_LINE_SERVER_ERROR, "-!!-", "invalid numeric 004 chan_modes: %s", chan_modes); } while (0);
 }
}

user_defined_types: struct ircv3_cap { char *val; unsigned int req; unsigned int req_auto; unsigned int set; unsigned int supported; unsigned int supports_del; unsigned int supports_req; }

user_defined_types: enum activity { ACTIVITY_DEFAULT=0, ACTIVITY_JPQ=1, ACTIVITY_ACTIVE=2, ACTIVITY_PINGED=3, ACTIVITY_T_SIZE=4 }


original_code:
void
server_set_sasl(struct server *s, const char *mech, const char *user, const char *pass)
{
 free((void *)s->ircv3_sasl.user);
 free((void *)s->ircv3_sasl.pass);
 if (!strcasecmp(mech, "EXTERNAL")) {
  s->ircv3_sasl.mech = IRCV3_SASL_MECH_EXTERNAL;
  s->ircv3_sasl.user = ((void *)0);
  s->ircv3_sasl.pass = ((void *)0);
 }
 if (!strcasecmp(mech, "PLAIN")) {
  s->ircv3_sasl.mech = IRCV3_SASL_MECH_PLAIN;
  s->ircv3_sasl.user = (user ? irc_strdup(user) : ((void *)0));
  s->ircv3_sasl.pass = (pass ? irc_strdup(pass) : ((void *)0));
 }
}

canonical_original_code:
void server_set_sasl(struct server *s, char *mech, char *user, char *pass)
{
 free((void *)s->ircv3_sasl.user);
 free((void *)s->ircv3_sasl.pass);
 if (!strcasecmp(mech, "EXTERNAL")) {
  s->ircv3_sasl.mech = IRCV3_SASL_MECH_EXTERNAL;
  s->ircv3_sasl.user = ((void *)0);
  s->ircv3_sasl.pass = ((void *)0);
 }
 if (!strcasecmp(mech, "PLAIN")) {
  s->ircv3_sasl.mech = IRCV3_SASL_MECH_PLAIN;
  s->ircv3_sasl.user = (user ? irc_strdup(user) : ((void *)0));
  s->ircv3_sasl.pass = (pass ? irc_strdup(pass) : ((void *)0));
 }
}

variable_types:
mech
char *

variable_types:
user
char *

variable_types:
pass
char *

user_defined_types: enum channel_type { CHANNEL_T_INVALID=0, CHANNEL_T_RIRC=1, CHANNEL_T_CHANNEL=2, CHANNEL_T_PRIVMSG=3, CHANNEL_T_SERVER=4, CHANNEL_T_SIZE=5 }

user_defined_types: struct input { char buf[410]; struct { char *ptrs[16]; unsigned short current; unsigned short head; unsigned short tail; } hist; unsigned short head; unsigned short tail; unsigned short window; }


decompiled_code:
__int64 __fastcall server_nick_set(__int64 a1, __int64 a2)
{
void *v3; // rdi
__int64 result; // rax

v3 = *(void **)(a1 + 40);
if ( v3 )
free(v3);
result = irc_strdup(a2);
*(_QWORD *)(a1 + 40) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
void *v3; // rdi
__int64 result; // rax

v3 = *(void **)(a1 + 40);
if ( v3 )
free(v3);
result = irc_strdup(a2);
*(_QWORD *)(a1 + 40) = result;
return result;
}

original_code:
void
server_nick_set(struct server *s, const char *nick)
{
 do { ; } while (0);
 if (s->nick)
  free((void *)s->nick);
 s->nick = irc_strdup(nick);
}

canonical_original_code:
void server_nick_set(struct server *s, char *nick)
{
 do { ; } while (0);
 if (s->nick)
  free((void *)s->nick);
 s->nick = irc_strdup(nick);
}

variable_types: struct server { char *host; char *port; char *pass; char *username; char *realname; char *nick; char *mode; enum casemapping { CASEMAPPING_INVALID=0, CASEMAPPING_ASCII=1, CASEMAPPING_RFC1459=2, CASEMAPPING_STRICT_RFC1459=3 } casemapping; struct { unsigned long next; unsigned long size; char *base; char **set; } nicks; struct channel { char *name; char *key; enum activity { ACTIVITY_DEFAULT=0, ACTIVITY_JPQ=1, ACTIVITY_ACTIVE=2, ACTIVITY_PINGED=3, ACTIVITY_T_SIZE=4 } activity; enum channel_type { CHANNEL_T_INVALID=0, CHANNEL_T_RIRC=1, CHANNEL_T_CHANNEL=2, CHANNEL_T_PRIVMSG=3, CHANNEL_T_SERVER=4, CHANNEL_T_SIZE=5 } type; unsigned long name_len; struct buffer { unsigned int head; unsigned int tail; unsigned int scrollback; unsigned long pad; struct buffer_line { enum buffer_line_type { BUFFER_LINE_OTHER=0, BUFFER_LINE_SERVER_INFO=1, BUFFER_LINE_SERVER_ERROR=2, BUFFER_LINE_JOIN=3, BUFFER_LINE_NICK=4, BUFFER_LINE_PART=5, BUFFER_LINE_QUIT=6, BUFFER_LINE_CHAT=7, BUFFER_LINE_PINGED=8, BUFFER_LINE_T_SIZE=9 } type; char prefix; char from[-1]; char text[-1]; unsigned long from_len; unsigned long text_len; long time; struct { unsigned int colour; unsigned int cols; unsigned int rows; unsigned int initialized; } cached; } buffer_lines[-1]; unsigned int buffer_i_bot; unsigned int buffer_i_top; long time_last; } buffer; struct channel *next; struct channel *prev; struct input { char buf[410]; struct { char *ptrs[16]; unsigned short current; unsigned short head; unsigned short tail; } hist; unsigned short head; unsigned short tail; unsigned short window; } input; struct mode { char prefix; unsigned int lower; unsigned int upper; } chanmodes; struct mode_str { char str[-1]; } chanmodes_str; struct server *server; struct user_list { struct user { struct { int height; struct user *tree_left; struct user *tree_right; } ul; char *nick; unsigned long nick_len; struct mode prfxmodes; char _[]; } *tree_root; unsigned int count; } users; unsigned int parted; unsigned int joined; char _[]; } *channel; struct channel_list { struct channel *head; struct channel *tail; unsigned int count; } clist; struct ircv3_caps { struct ircv3_cap { char *val; unsigned int req; unsigned int req_auto; unsigned int set; unsigned int supported; unsigned int supports_del; unsigned int supports_req; } account_notify; struct ircv3_cap away_notify; struct ircv3_cap chghost; struct ircv3_cap extended_join; struct ircv3_cap invite_notify; struct ircv3_cap multi_prefix; struct ircv3_cap sasl; } ircv3_caps; struct ircv3_sasl { enum { IRCV3_SASL_MECH_NONE=0, IRCV3_SASL_MECH_EXTERNAL=1, IRCV3_SASL_MECH_PLAIN=2 } mech; enum { IRCV3_SASL_STATE_NONE=0, IRCV3_SASL_STATE_REQ_MECH=1, IRCV3_SASL_STATE_AUTHENTICATED=2 } state; char *user; char *pass; } ircv3_sasl; struct mode usermodes; 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; } mode_cfg; struct mode_str mode_str; struct server *next; struct server *prev; unsigned int ping; unsigned int connected; unsigned int quitting; unsigned int registered; void *connection; struct { unsigned long i; char cl; char buf[-1]; } read; } *

variable_types:
nick
char *


decompiled_code:
__int64 __fastcall server_nicks_next(_QWORD *a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rdx
char *v3; // rbx
__int64 result; // rax
__int64 v5; // rax
char s[10]; // [rsp+6h] [rbp-42h] BYREF
__m128i v7; // [rsp+10h] [rbp-38h]
char v8; // [rsp+20h] [rbp-28h]

v1 = a1[9];
if ( v1 && (v2 = a1[8], v1 > v2) )
{
v5 = a1[11];
a1[8] = v2 + 1;
result = server_nick_set((__int64)a1, *(_QWORD *)(v5 + 8 * v2));
}
else
{
v8 = 0;
strcpy(s, "rirc*****");
v7 = _mm_load_si128((const __m128i *)&LC22);
v3 = strchr(s, 42);
if ( v3 )
{
while ( *v3 )
*v3++ = v7.m128i_i8[rand() & 0xF];
}
result = server_nick_set((__int64)a1, (__int64)s);
}
return result;
}

original_code:
void
server_nicks_next(struct server *s)
{
 if (s->nicks.size && s->nicks.next < s->nicks.size) {
  server_nick_set(s, s->nicks.set[s->nicks.next++]);
 } else {
  char nick_cset[] = "0123456789ABCDEF";
  char nick_rand[] = "rirc*****";
  for (char *p = strchr(nick_rand, '*'); p && *p; p++) {
   *p = nick_cset[rand() % strlen(nick_cset)];
  }
  server_nick_set(s, nick_rand);
 }
}

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

user_defined_types: struct user { struct { int height; struct user *tree_left; struct user *tree_right; } ul; char *nick; unsigned long nick_len; struct mode prfxmodes; char _[]; }


decompiled_code:
__int64 __fastcall mbedtls_rsa_deduce_primes(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v8; // eax
unsigned __int16 v10; // ax
unsigned __int16 v11; // r15
__int64 v12; // r14
int v13; // ebx
unsigned int v14; // [rsp+Ch] [rbp-BCh]
char v15[32]; // [rsp+10h] [rbp-B8h] BYREF
char v16[32]; // [rsp+30h] [rbp-98h] BYREF
__int128 v17[3]; // [rsp+50h] [rbp-78h]
int v18; // [rsp+80h] [rbp-48h]
__int16 v19; // [rsp+84h] [rbp-44h]

v18 = -269883933;
v17[0] = (__int128)_mm_load_si128((const __m128i *)&LC0);
v19 = -1039;
v17[1] = (__int128)_mm_load_si128((const __m128i *)&LC1);
v17[2] = (__int128)_mm_load_si128((const __m128i *)&LC2);
if ( !a4
|| !a5
|| *(_QWORD *)(a4 + 16)
|| *(_QWORD *)(a5 + 16)
|| (int)mbedtls_mpi_cmp_int(a1, 0LL) <= 0
|| (int)mbedtls_mpi_cmp_int(a3, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_mpi(a3, a1) >= 0
|| (int)mbedtls_mpi_cmp_int(a2, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_mpi(a2, a1) >= 0 )
{
return 4294967292LL;
}
mbedtls_mpi_init(v16);
mbedtls_mpi_init(v15);
v8 = mbedtls_mpi_mul_mpi(v15, a3, a2);
if ( !v8 )
{
v8 = mbedtls_mpi_sub_int(v15, v15, 1LL);
if ( !v8 )
{
v10 = mbedtls_mpi_lsb(v15);
v11 = v10;
if ( v10 )
{
v8 = mbedtls_mpi_shift_r(v15, v10);
if ( !v8 )
{
v12 = (**(_QWORD **)(a1 + 16) & 7LL) == 1;
while ( 1 )
{
mbedtls_mpi_lset(v16, *((unsigned __int8 *)v17 + v12));
v8 = mbedtls_mpi_gcd(a4, v16, a1);
if ( v8 )
break;
if ( !(unsigned int)mbedtls_mpi_cmp_int(a4, 1LL) )
{
v8 = mbedtls_mpi_exp_mod(v16, v16, v15, a1, a5);
if ( v8 )
break;
v13 = 1;
do
{
if ( !(unsigned int)mbedtls_mpi_cmp_int(v16, 1LL) )
break;
v8 = mbedtls_mpi_add_int(v16, v16, 1LL);
if ( v8 )
goto LABEL_11;
v8 = mbedtls_mpi_gcd(a4, v16, a1);
if ( v8 )
goto LABEL_11;
if ( (unsigned int)mbedtls_mpi_cmp_int(a4, 1LL) == 1 && (unsigned int)mbedtls_mpi_cmp_mpi(a4, a1) == -1 )
{
v8 = mbedtls_mpi_div_mpi(a5, 0LL, a1, a4);
goto LABEL_11;
}
v8 = mbedtls_mpi_sub_int(v16, v16, 1LL);
if ( v8 )
goto LABEL_11;
v8 = mbedtls_mpi_mul_mpi(v16, v16, v16);
if ( v8 )
goto LABEL_11;
v8 = mbedtls_mpi_mod_mpi(v16, v16, a1);
if ( v8 )
goto LABEL_11;
++v13;
}
while ( v11 >= (unsigned __int16)v13 );
if ( (unsigned int)mbedtls_mpi_cmp_int(v16, 1LL) )
goto LABEL_14;
}
if ( (unsigned __int16)++v12 > 0x35u )
goto LABEL_14;
}
}
}
else
{
LABEL_14:
v8 = -4;
}
}
}
LABEL_11:
v14 = v8;
mbedtls_mpi_free(v16);
mbedtls_mpi_free(v15);
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v8; // eax
unsigned __int16 v10; // ax
unsigned __int16 v11; // r15
__int64 v12; // r14
int v13; // ebx
unsigned int v14; // [rsp+Ch] [rbp-BCh]
char v15[32]; // [rsp+10h] [rbp-B8h] BYREF
char v16[32]; // [rsp+30h] [rbp-98h] BYREF
__int128 v17[3]; // [rsp+50h] [rbp-78h]
int v18; // [rsp+80h] [rbp-48h]
__int16 v19; // [rsp+84h] [rbp-44h]

v18 = -269883933;
v17[0] = (__int128)_mm_load_si128((const __m128i *)&LC0);
v19 = -1039;
v17[1] = (__int128)_mm_load_si128((const __m128i *)&LC1);
v17[2] = (__int128)_mm_load_si128((const __m128i *)&LC2);
if ( !a4
|| !a5
|| *(_QWORD *)(a4 + 16)
|| *(_QWORD *)(a5 + 16)
|| (int)mbedtls_mpi_cmp_int(a1, 0LL) <= 0
|| (int)mbedtls_mpi_cmp_int(a3, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_mpi(a3, a1) >= 0
|| (int)mbedtls_mpi_cmp_int(a2, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_mpi(a2, a1) >= 0 )
{
return 4294967292LL;
}
mbedtls_mpi_init(v16);
mbedtls_mpi_init(v15);
v8 = mbedtls_mpi_mul_mpi(v15, a3, a2);
if ( !v8 )
{
v8 = mbedtls_mpi_sub_int(v15, v15, 1LL);
if ( !v8 )
{
v10 = mbedtls_mpi_lsb(v15);
v11 = v10;
if ( v10 )
{
v8 = mbedtls_mpi_shift_r(v15, v10);
if ( !v8 )
{
v12 = (**(_QWORD **)(a1 + 16) & 7LL) == 1;
while ( 1 )
{
mbedtls_mpi_lset(v16, *((unsigned __int8 *)v17 + v12));
v8 = mbedtls_mpi_gcd(a4, v16, a1);
if ( v8 )
break;
if ( !(unsigned int)mbedtls_mpi_cmp_int(a4, 1LL) )
{
v8 = mbedtls_mpi_exp_mod(v16, v16, v15, a1, a5);
if ( v8 )
break;
v13 = 1;
do
{
if ( !(unsigned int)mbedtls_mpi_cmp_int(v16, 1LL) )
break;
v8 = mbedtls_mpi_add_int(v16, v16, 1LL);
if ( v8 )
goto LABEL_11;
v8 = mbedtls_mpi_gcd(a4, v16, a1);
if ( v8 )
goto LABEL_11;
if ( (unsigned int)mbedtls_mpi_cmp_int(a4, 1LL) == 1 && (unsigned int)mbedtls_mpi_cmp_mpi(a4, a1) == -1 )
{
v8 = mbedtls_mpi_div_mpi(a5, 0LL, a1, a4);
goto LABEL_11;
}
v8 = mbedtls_mpi_sub_int(v16, v16, 1LL);
if ( v8 )
goto LABEL_11;
v8 = mbedtls_mpi_mul_mpi(v16, v16, v16);
if ( v8 )
goto LABEL_11;
v8 = mbedtls_mpi_mod_mpi(v16, v16, a1);
if ( v8 )
goto LABEL_11;
++v13;
}
while ( v11 >= (unsigned __int16)v13 );
if ( (unsigned int)mbedtls_mpi_cmp_int(v16, 1LL) )
goto LABEL_14;
}
if ( (unsigned __int16)++v12 > 0x35u )
goto LABEL_14;
}
}
}
else
{
LABEL_14:
v8 = -4;
}
}
}
LABEL_11:
v14 = v8;
mbedtls_mpi_free(v16);
mbedtls_mpi_free(v15);
return v14;
}

original_code:
int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N,
                              mbedtls_mpi const *E, mbedtls_mpi const *D,
                              mbedtls_mpi *P, mbedtls_mpi *Q)
{
    int ret = 0;
    uint16_t attempt;
    uint16_t iter;
    uint16_t order;
    mbedtls_mpi T;
    mbedtls_mpi K;
    const unsigned char primes[] = { 2,
                                     3, 5, 7, 11, 13, 17, 19, 23,
                                     29, 31, 37, 41, 43, 47, 53, 59,
                                     61, 67, 71, 73, 79, 83, 89, 97,
                                     101, 103, 107, 109, 113, 127, 131, 137,
                                     139, 149, 151, 157, 163, 167, 173, 179,
                                     181, 191, 193, 197, 199, 211, 223, 227,
                                     229, 233, 239, 241, 251 };
    const size_t num_primes = sizeof(primes) / sizeof(*primes);
    if (P == ((void *)0) || Q == ((void *)0) || P->p != ((void *)0) || Q->p != ((void *)0)) {
        return -0x0004;
    }
    if (mbedtls_mpi_cmp_int(N, 0) <= 0 ||
        mbedtls_mpi_cmp_int(D, 1) <= 0 ||
        mbedtls_mpi_cmp_mpi(D, N) >= 0 ||
        mbedtls_mpi_cmp_int(E, 1) <= 0 ||
        mbedtls_mpi_cmp_mpi(E, N) >= 0) {
        return -0x0004;
    }
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&T);
    do { if ((ret = (mbedtls_mpi_mul_mpi(&T, D, E))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_sub_int(&T, &T, 1))) != 0) goto cleanup; } while (0);
    if ((order = (uint16_t) mbedtls_mpi_lsb(&T)) == 0) {
        ret = -0x0004;
        goto cleanup;
    }
    do { if ((ret = (mbedtls_mpi_shift_r(&T, order))) != 0) goto cleanup; } while (0);
    attempt = 0;
    if (N->p[0] % 8 == 1) {
        attempt = 1;
    }
    for (; attempt < num_primes; ++attempt) {
        mbedtls_mpi_lset(&K, primes[attempt]);
        do { if ((ret = (mbedtls_mpi_gcd(P, &K, N))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(P, 1) != 0) {
            continue;
        }
        do { if ((ret = (mbedtls_mpi_exp_mod(&K, &K, &T, N, Q ))) != 0) goto cleanup; } while (0);
        for (iter = 1; iter <= order; ++iter) {
            if (mbedtls_mpi_cmp_int(&K, 1) == 0) {
                break;
            }
            do { if ((ret = (mbedtls_mpi_add_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
            do { if ((ret = (mbedtls_mpi_gcd(P, &K, N))) != 0) goto cleanup; } while (0);
            if (mbedtls_mpi_cmp_int(P, 1) == 1 &&
                mbedtls_mpi_cmp_mpi(P, N) == -1) {
                do { if ((ret = (mbedtls_mpi_div_mpi(Q, ((void *)0), N, P))) != 0) goto cleanup; } while (0);
                goto cleanup;
            }
            do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
            do { if ((ret = (mbedtls_mpi_mul_mpi(&K, &K, &K))) != 0) goto cleanup; } while (0);
            do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, N))) != 0) goto cleanup; } while (0);
        }
        if (mbedtls_mpi_cmp_int(&K, 1) != 0) {
            break;
        }
    }
    ret = -0x0004;
cleanup:
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&T);
    return ret;
}

canonical_original_code:
int mbedtls_rsa_deduce_primes(struct mbedtls_mpi *N, struct mbedtls_mpi *E, struct mbedtls_mpi *D, struct mbedtls_mpi *P, struct mbedtls_mpi *Q)
{
    int ret = 0;
    unsigned short attempt;
    unsigned short iter;
    unsigned short order;
    struct mbedtls_mpi T;
    struct mbedtls_mpi K;
    unsigned char primes[] = { 2,
                                     3, 5, 7, 11, 13, 17, 19, 23,
                                     29, 31, 37, 41, 43, 47, 53, 59,
                                     61, 67, 71, 73, 79, 83, 89, 97,
                                     101, 103, 107, 109, 113, 127, 131, 137,
                                     139, 149, 151, 157, 163, 167, 173, 179,
                                     181, 191, 193, 197, 199, 211, 223, 227,
                                     229, 233, 239, 241, 251 };
    unsigned long num_primes = sizeof(primes) / sizeof(*primes);
    if (P == ((void *)0) || Q == ((void *)0) || P->p != ((void *)0) || Q->p != ((void *)0)) {
        return -0x0004;
    }
    if (mbedtls_mpi_cmp_int(N, 0) <= 0 ||
        mbedtls_mpi_cmp_int(D, 1) <= 0 ||
        mbedtls_mpi_cmp_mpi(D, N) >= 0 ||
        mbedtls_mpi_cmp_int(E, 1) <= 0 ||
        mbedtls_mpi_cmp_mpi(E, N) >= 0) {
        return -0x0004;
    }
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&T);
    do { if ((ret = (mbedtls_mpi_mul_mpi(&T, D, E))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_sub_int(&T, &T, 1))) != 0) goto cleanup; } while (0);
    if ((order = (unsigned short) mbedtls_mpi_lsb(&T)) == 0) {
        ret = -0x0004;
        goto cleanup;
    }
    do { if ((ret = (mbedtls_mpi_shift_r(&T, order))) != 0) goto cleanup; } while (0);
    attempt = 0;
    if (N->p[0] % 8 == 1) {
        attempt = 1;
    }
    for (; attempt < num_primes; ++attempt) {
        mbedtls_mpi_lset(&K, primes[attempt]);
        do { if ((ret = (mbedtls_mpi_gcd(P, &K, N))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(P, 1) != 0) {
            continue;
        }
        do { if ((ret = (mbedtls_mpi_exp_mod(&K, &K, &T, N, Q ))) != 0) goto cleanup; } while (0);
        for (iter = 1; iter <= order; ++iter) {
            if (mbedtls_mpi_cmp_int(&K, 1) == 0) {
                break;
            }
            do { if ((ret = (mbedtls_mpi_add_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
            do { if ((ret = (mbedtls_mpi_gcd(P, &K, N))) != 0) goto cleanup; } while (0);
            if (mbedtls_mpi_cmp_int(P, 1) == 1 &&
                mbedtls_mpi_cmp_mpi(P, N) == -1) {
                do { if ((ret = (mbedtls_mpi_div_mpi(Q, ((void *)0), N, P))) != 0) goto cleanup; } while (0);
                goto cleanup;
            }
            do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
            do { if ((ret = (mbedtls_mpi_mul_mpi(&K, &K, &K))) != 0) goto cleanup; } while (0);
            do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, N))) != 0) goto cleanup; } while (0);
        }
        if (mbedtls_mpi_cmp_int(&K, 1) != 0) {
            break;
        }
    }
    ret = -0x0004;
cleanup:
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&T);
    return ret;
}

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

variable_types:
E
struct mbedtls_mpi *

variable_types:
D
struct mbedtls_mpi *

variable_types:
P
struct mbedtls_mpi *

variable_types:
Q
struct mbedtls_mpi *

variable_types: ret int

variable_types:
attempt
unsigned short

variable_types:
iter
unsigned short

variable_types:
order
unsigned short

variable_types:
primes
unsigned char []


decompiled_code:
__int64 __fastcall mbedtls_rsa_deduce_private_exponent(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // er12
_BYTE v8[32]; // [rsp+0h] [rbp-68h] BYREF
char v9[72]; // [rsp+20h] [rbp-48h] BYREF

if ( !a4
|| (unsigned int)mbedtls_mpi_cmp_int(a4, 0LL)
|| (int)mbedtls_mpi_cmp_int(a1, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_int(a2, 1LL) <= 0
|| !(unsigned int)mbedtls_mpi_cmp_int(a3, 0LL) )
{
return (unsigned int)-4;
}
mbedtls_mpi_init(v8);
mbedtls_mpi_init(v9);
v6 = mbedtls_mpi_sub_int(v8, a1, 1LL);
if ( !v6 )
{
v6 = mbedtls_mpi_sub_int(v9, a2, 1LL);
if ( !v6 )
{
v6 = mbedtls_mpi_gcd(a4, v8, v9);
if ( !v6 )
{
v6 = mbedtls_mpi_mul_mpi(v8, v8, v9);
if ( !v6 )
{
v6 = mbedtls_mpi_div_mpi(v8, 0LL, v8, a4);
if ( !v6 )
v6 = mbedtls_mpi_inv_mod(a4, a3, v8);
}
}
}
}
mbedtls_mpi_free(v8);
mbedtls_mpi_free(v9);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // er12
_BYTE v8[32]; // [rsp+0h] [rbp-68h] BYREF
char v9[72]; // [rsp+20h] [rbp-48h] BYREF

if ( !a4
|| (unsigned int)mbedtls_mpi_cmp_int(a4, 0LL)
|| (int)mbedtls_mpi_cmp_int(a1, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_int(a2, 1LL) <= 0
|| !(unsigned int)mbedtls_mpi_cmp_int(a3, 0LL) )
{
return (unsigned int)-4;
}
mbedtls_mpi_init(v8);
mbedtls_mpi_init(v9);
v6 = mbedtls_mpi_sub_int(v8, a1, 1LL);
if ( !v6 )
{
v6 = mbedtls_mpi_sub_int(v9, a2, 1LL);
if ( !v6 )
{
v6 = mbedtls_mpi_gcd(a4, v8, v9);
if ( !v6 )
{
v6 = mbedtls_mpi_mul_mpi(v8, v8, v9);
if ( !v6 )
{
v6 = mbedtls_mpi_div_mpi(v8, 0LL, v8, a4);
if ( !v6 )
v6 = mbedtls_mpi_inv_mod(a4, a3, v8);
}
}
}
}
mbedtls_mpi_free(v8);
mbedtls_mpi_free(v9);
return v6;
}

original_code:
int mbedtls_rsa_deduce_private_exponent(mbedtls_mpi const *P,
                                        mbedtls_mpi const *Q,
                                        mbedtls_mpi const *E,
                                        mbedtls_mpi *D)
{
    int ret = 0;
    mbedtls_mpi K, L;
    if (D == ((void *)0) || mbedtls_mpi_cmp_int(D, 0) != 0) {
        return -0x0004;
    }
    if (mbedtls_mpi_cmp_int(P, 1) <= 0 ||
        mbedtls_mpi_cmp_int(Q, 1) <= 0 ||
        mbedtls_mpi_cmp_int(E, 0) == 0) {
        return -0x0004;
    }
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&L);
    do { if ((ret = (mbedtls_mpi_sub_int(&K, P, 1))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_sub_int(&L, Q, 1))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_gcd(D, &K, &L))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_mul_mpi(&K, &K, &L))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_div_mpi(&K, ((void *)0), &K, D))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_inv_mod(D, E, &K))) != 0) goto cleanup; } while (0);
cleanup:
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&L);
    return ret;
}

canonical_original_code:
int mbedtls_rsa_deduce_private_exponent(struct mbedtls_mpi *P, struct mbedtls_mpi *Q, struct mbedtls_mpi *E, struct mbedtls_mpi *D)
{
    int ret = 0;
    struct mbedtls_mpi K; struct mbedtls_mpi L;
    if (D == ((void *)0) || mbedtls_mpi_cmp_int(D, 0) != 0) {
        return -0x0004;
    }
    if (mbedtls_mpi_cmp_int(P, 1) <= 0 ||
        mbedtls_mpi_cmp_int(Q, 1) <= 0 ||
        mbedtls_mpi_cmp_int(E, 0) == 0) {
        return -0x0004;
    }
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&L);
    do { if ((ret = (mbedtls_mpi_sub_int(&K, P, 1))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_sub_int(&L, Q, 1))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_gcd(D, &K, &L))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_mul_mpi(&K, &K, &L))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_div_mpi(&K, ((void *)0), &K, D))) != 0) goto cleanup; } while (0);
    do { if ((ret = (mbedtls_mpi_inv_mod(D, E, &K))) != 0) goto cleanup; } while (0);
cleanup:
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&L);
    return ret;
}

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


decompiled_code:
__int64 __fastcall mbedtls_rsa_deduce_crt(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
unsigned int v10; // eax
unsigned int v12; // [rsp+Ch] [rbp-5Ch]
char v13[88]; // [rsp+10h] [rbp-58h] BYREF

mbedtls_mpi_init(v13);
if ( (!a4 || (v10 = mbedtls_mpi_sub_int(v13, a1, 1LL)) == 0 && (v10 = mbedtls_mpi_mod_mpi(a4, a3, v13)) == 0)
&& (!a5 || (v10 = mbedtls_mpi_sub_int(v13, a2, 1LL)) == 0 && (v10 = mbedtls_mpi_mod_mpi(a5, a3, v13)) == 0) )
{
v10 = 0;
if ( a6 )
v10 = mbedtls_mpi_inv_mod(a6, a2, a1);
}
v12 = v10;
mbedtls_mpi_free(v13);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
unsigned int v10; // eax
unsigned int v12; // [rsp+Ch] [rbp-5Ch]
char v13[88]; // [rsp+10h] [rbp-58h] BYREF

mbedtls_mpi_init(v13);
if ( (!a4 || (v10 = mbedtls_mpi_sub_int(v13, a1, 1LL)) == 0 && (v10 = mbedtls_mpi_mod_mpi(a4, a3, v13)) == 0)
&& (!a5 || (v10 = mbedtls_mpi_sub_int(v13, a2, 1LL)) == 0 && (v10 = mbedtls_mpi_mod_mpi(a5, a3, v13)) == 0) )
{
v10 = 0;
if ( a6 )
v10 = mbedtls_mpi_inv_mod(a6, a2, a1);
}
v12 = v10;
mbedtls_mpi_free(v13);
return v12;
}

original_code:
int mbedtls_rsa_deduce_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q,
                           const mbedtls_mpi *D, mbedtls_mpi *DP,
                           mbedtls_mpi *DQ, mbedtls_mpi *QP)
{
    int ret = 0;
    mbedtls_mpi K;
    mbedtls_mpi_init(&K);
    if (DP != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_sub_int(&K, P, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(DP, D, &K))) != 0) goto cleanup; } while (0);
    }
    if (DQ != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_sub_int(&K, Q, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(DQ, D, &K))) != 0) goto cleanup; } while (0);
    }
    if (QP != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_inv_mod(QP, Q, P))) != 0) goto cleanup; } while (0);
    }
cleanup:
    mbedtls_mpi_free(&K);
    return ret;
}

canonical_original_code:
int mbedtls_rsa_deduce_crt(struct mbedtls_mpi *P, struct mbedtls_mpi *Q, struct mbedtls_mpi *D, struct mbedtls_mpi *DP, struct mbedtls_mpi *DQ, struct mbedtls_mpi *QP)
{
    int ret = 0;
    struct mbedtls_mpi K;
    mbedtls_mpi_init(&K);
    if (DP != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_sub_int(&K, P, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(DP, D, &K))) != 0) goto cleanup; } while (0);
    }
    if (DQ != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_sub_int(&K, Q, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(DQ, D, &K))) != 0) goto cleanup; } while (0);
    }
    if (QP != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_inv_mod(QP, Q, P))) != 0) goto cleanup; } while (0);
    }
cleanup:
    mbedtls_mpi_free(&K);
    return ret;
}

variable_types:
DP
struct mbedtls_mpi *

variable_types:
DQ
struct mbedtls_mpi *

variable_types:
QP
struct mbedtls_mpi *

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


decompiled_code:
__int64 __fastcall mbedtls_rsa_validate_params(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
bool v11; // r10
bool v12; // r8
bool v13; // r9
unsigned int v14; // er12
int v16; // eax
int v17; // eax
bool v18; // r8
bool v19; // r9
bool v20; // [rsp+Eh] [rbp-7Ah]
bool v21; // [rsp+Eh] [rbp-7Ah]
char v22[32]; // [rsp+10h] [rbp-78h] BYREF
char v23[88]; // [rsp+30h] [rbp-58h] BYREF

mbedtls_mpi_init(v22);
mbedtls_mpi_init(v23);
v11 = a6 != 0;
v12 = a2 != 0;
if ( a6 )
{
if ( a2 )
{
v16 = mbedtls_mpi_is_prime_ext(a2, 50LL, a6, a7);
v11 = a6 != 0;
v12 = a2 != 0;
if ( v16 )
goto LABEL_15;
}
}
v13 = a3 != 0;
if ( v11 && a3 )
{
v21 = v12;
v17 = mbedtls_mpi_is_prime_ext(a3, 50LL, a6, a7);
v18 = v21;
v19 = a3 != 0;
if ( v17 )
goto LABEL_15;
v20 = v19 && v21;
if ( v19 && v18 )
goto LABEL_6;
LABEL_10:
if ( a4 == 0 || a5 == 0 || !a1 )
goto LABEL_27;
goto LABEL_12;
}
v20 = v13 && v12;
if ( !v13 || !v12 )
goto LABEL_10;
LABEL_6:
if ( !a1 )
{
if ( !a5 || !a4 )
goto LABEL_27;
goto LABEL_30;
}
v14 = mbedtls_mpi_mul_mpi(v22, a2, a3);
if ( v14 )
goto LABEL_8;
if ( (int)mbedtls_mpi_cmp_int(a1, 1LL) <= 0 || (unsigned int)mbedtls_mpi_cmp_mpi(v22, a1) )
goto LABEL_15;
if ( !a5 || !a4 )
goto LABEL_27;
LABEL_12:
if ( (int)mbedtls_mpi_cmp_int(a4, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_int(a5, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_mpi(a4, a1) >= 0
|| (int)mbedtls_mpi_cmp_mpi(a5, a1) >= 0 )
{
goto LABEL_15;
}
if ( !v20 )
goto LABEL_27;
LABEL_30:
if ( (int)mbedtls_mpi_cmp_int(a2, 1LL) <= 0 || (int)mbedtls_mpi_cmp_int(a3, 1LL) <= 0 )
goto LABEL_15;
v14 = mbedtls_mpi_mul_mpi(v22, a4, a5);
if ( v14 )
goto LABEL_8;
v14 = mbedtls_mpi_sub_int(v22, v22, 1LL);
if ( v14 )
goto LABEL_8;
v14 = mbedtls_mpi_sub_int(v23, a2, 1LL);
if ( v14 )
goto LABEL_8;
v14 = mbedtls_mpi_mod_mpi(v22, v22, v23);
if ( v14 )
goto LABEL_8;
if ( (unsigned int)mbedtls_mpi_cmp_int(v22, 0LL) )
{
LABEL_15:
v14 = -16896;
LABEL_16:
mbedtls_mpi_free(v22);
mbedtls_mpi_free(v23);
return v14;
}
v14 = mbedtls_mpi_mul_mpi(v22, a4, a5);
if ( !v14 )
{
v14 = mbedtls_mpi_sub_int(v22, v22, 1LL);
if ( !v14 )
{
v14 = mbedtls_mpi_sub_int(v23, a3, 1LL);
if ( !v14 )
{
v14 = mbedtls_mpi_mod_mpi(v22, v22, v23);
if ( !v14 )
{
if ( (unsigned int)mbedtls_mpi_cmp_int(v22, 0LL) )
goto LABEL_15;
LABEL_27:
v14 = 0;
goto LABEL_16;
}
}
}
}
LABEL_8:
mbedtls_mpi_free(v22);
mbedtls_mpi_free(v23);
if ( v14 != -16896 )
v14 -= 16896;
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
bool v11; // r10
bool v12; // r8
bool v13; // r9
unsigned int v14; // er12
int v16; // eax
int v17; // eax
bool v18; // r8
bool v19; // r9
bool v20; // [rsp+Eh] [rbp-7Ah]
bool v21; // [rsp+Eh] [rbp-7Ah]
char v22[32]; // [rsp+10h] [rbp-78h] BYREF
char v23[88]; // [rsp+30h] [rbp-58h] BYREF

mbedtls_mpi_init(v22);
mbedtls_mpi_init(v23);
v11 = a6 != 0;
v12 = a2 != 0;
if ( a6 )
{
if ( a2 )
{
v16 = mbedtls_mpi_is_prime_ext(a2, 50LL, a6, a7);
v11 = a6 != 0;
v12 = a2 != 0;
if ( v16 )
goto LABEL_15;
}
}
v13 = a3 != 0;
if ( v11 && a3 )
{
v21 = v12;
v17 = mbedtls_mpi_is_prime_ext(a3, 50LL, a6, a7);
v18 = v21;
v19 = a3 != 0;
if ( v17 )
goto LABEL_15;
v20 = v19 && v21;
if ( v19 && v18 )
goto LABEL_6;
LABEL_10:
if ( a4 == 0 || a5 == 0 || !a1 )
goto LABEL_27;
goto LABEL_12;
}
v20 = v13 && v12;
if ( !v13 || !v12 )
goto LABEL_10;
LABEL_6:
if ( !a1 )
{
if ( !a5 || !a4 )
goto LABEL_27;
goto LABEL_30;
}
v14 = mbedtls_mpi_mul_mpi(v22, a2, a3);
if ( v14 )
goto LABEL_8;
if ( (int)mbedtls_mpi_cmp_int(a1, 1LL) <= 0 || (unsigned int)mbedtls_mpi_cmp_mpi(v22, a1) )
goto LABEL_15;
if ( !a5 || !a4 )
goto LABEL_27;
LABEL_12:
if ( (int)mbedtls_mpi_cmp_int(a4, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_int(a5, 1LL) <= 0
|| (int)mbedtls_mpi_cmp_mpi(a4, a1) >= 0
|| (int)mbedtls_mpi_cmp_mpi(a5, a1) >= 0 )
{
goto LABEL_15;
}
if ( !v20 )
goto LABEL_27;
LABEL_30:
if ( (int)mbedtls_mpi_cmp_int(a2, 1LL) <= 0 || (int)mbedtls_mpi_cmp_int(a3, 1LL) <= 0 )
goto LABEL_15;
v14 = mbedtls_mpi_mul_mpi(v22, a4, a5);
if ( v14 )
goto LABEL_8;
v14 = mbedtls_mpi_sub_int(v22, v22, 1LL);
if ( v14 )
goto LABEL_8;
v14 = mbedtls_mpi_sub_int(v23, a2, 1LL);
if ( v14 )
goto LABEL_8;
v14 = mbedtls_mpi_mod_mpi(v22, v22, v23);
if ( v14 )
goto LABEL_8;
if ( (unsigned int)mbedtls_mpi_cmp_int(v22, 0LL) )
{
LABEL_15:
v14 = -16896;
LABEL_16:
mbedtls_mpi_free(v22);
mbedtls_mpi_free(v23);
return v14;
}
v14 = mbedtls_mpi_mul_mpi(v22, a4, a5);
if ( !v14 )
{
v14 = mbedtls_mpi_sub_int(v22, v22, 1LL);
if ( !v14 )
{
v14 = mbedtls_mpi_sub_int(v23, a3, 1LL);
if ( !v14 )
{
v14 = mbedtls_mpi_mod_mpi(v22, v22, v23);
if ( !v14 )
{
if ( (unsigned int)mbedtls_mpi_cmp_int(v22, 0LL) )
goto LABEL_15;
LABEL_27:
v14 = 0;
goto LABEL_16;
}
}
}
}
LABEL_8:
mbedtls_mpi_free(v22);
mbedtls_mpi_free(v23);
if ( v14 != -16896 )
v14 -= 16896;
return v14;
}

original_code:
int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P,
                                const mbedtls_mpi *Q, const mbedtls_mpi *D,
                                const mbedtls_mpi *E,
                                int (*f_rng)(void *, unsigned char *, size_t),
                                void *p_rng)
{
    int ret = 0;
    mbedtls_mpi K, L;
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&L);
    if (f_rng != ((void *)0) && P != ((void *)0) &&
        (ret = mbedtls_mpi_is_prime_ext(P, 50, f_rng, p_rng)) != 0) {
        ret = -0x4200;
        goto cleanup;
    }
    if (f_rng != ((void *)0) && Q != ((void *)0) &&
        (ret = mbedtls_mpi_is_prime_ext(Q, 50, f_rng, p_rng)) != 0) {
        ret = -0x4200;
        goto cleanup;
    }
    if (P != ((void *)0) && Q != ((void *)0) && N != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, P, Q))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(N, 1) <= 0 ||
            mbedtls_mpi_cmp_mpi(&K, N) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (N != ((void *)0) && D != ((void *)0) && E != ((void *)0)) {
        if (mbedtls_mpi_cmp_int(D, 1) <= 0 ||
            mbedtls_mpi_cmp_int(E, 1) <= 0 ||
            mbedtls_mpi_cmp_mpi(D, N) >= 0 ||
            mbedtls_mpi_cmp_mpi(E, N) >= 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (P != ((void *)0) && Q != ((void *)0) && D != ((void *)0) && E != ((void *)0)) {
        if (mbedtls_mpi_cmp_int(P, 1) <= 0 ||
            mbedtls_mpi_cmp_int(Q, 1) <= 0) {
            ret = -0x4200;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, D, E))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&L, P, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, &L))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, D, E))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&L, Q, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, &L))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
cleanup:
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&L);
    if (ret != 0 && ret != -0x4200) {
        ret += -0x4200;
    }
    return ret;
}

canonical_original_code:
int mbedtls_rsa_validate_params(struct mbedtls_mpi *N, struct mbedtls_mpi *P, struct mbedtls_mpi *Q, struct mbedtls_mpi *D, struct mbedtls_mpi *E, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    int ret = 0;
    struct mbedtls_mpi K; struct mbedtls_mpi L;
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&L);
    if (f_rng != ((void *)0) && P != ((void *)0) &&
        (ret = mbedtls_mpi_is_prime_ext(P, 50, f_rng, p_rng)) != 0) {
        ret = -0x4200;
        goto cleanup;
    }
    if (f_rng != ((void *)0) && Q != ((void *)0) &&
        (ret = mbedtls_mpi_is_prime_ext(Q, 50, f_rng, p_rng)) != 0) {
        ret = -0x4200;
        goto cleanup;
    }
    if (P != ((void *)0) && Q != ((void *)0) && N != ((void *)0)) {
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, P, Q))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(N, 1) <= 0 ||
            mbedtls_mpi_cmp_mpi(&K, N) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (N != ((void *)0) && D != ((void *)0) && E != ((void *)0)) {
        if (mbedtls_mpi_cmp_int(D, 1) <= 0 ||
            mbedtls_mpi_cmp_int(E, 1) <= 0 ||
            mbedtls_mpi_cmp_mpi(D, N) >= 0 ||
            mbedtls_mpi_cmp_mpi(E, N) >= 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (P != ((void *)0) && Q != ((void *)0) && D != ((void *)0) && E != ((void *)0)) {
        if (mbedtls_mpi_cmp_int(P, 1) <= 0 ||
            mbedtls_mpi_cmp_int(Q, 1) <= 0) {
            ret = -0x4200;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, D, E))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&L, P, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, &L))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, D, E))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&L, Q, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, &L))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
cleanup:
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&L);
    if (ret != 0 && ret != -0x4200) {
        ret += -0x4200;
    }
    return ret;
}

variable_types: int (*)(void *, unsigned char *, unsigned long)


decompiled_code:
__int64 __fastcall mbedtls_rsa_validate_crt(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
int v10; // eax
unsigned int v11; // er12
_BYTE v13[32]; // [rsp+0h] [rbp-78h] BYREF
char v14[88]; // [rsp+20h] [rbp-58h] BYREF

mbedtls_mpi_init(v13);
mbedtls_mpi_init(v14);
if ( a4 )
{
if ( !a1 )
{
LABEL_12:
v11 = -16512;
goto LABEL_13;
}
v10 = mbedtls_mpi_sub_int(v13, a1, 1LL);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_sub_mpi(v14, a4, a3);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_mod_mpi(v14, v14, v13);
if ( v10 )
goto LABEL_5;
if ( (unsigned int)mbedtls_mpi_cmp_int(v14, 0LL) )
goto LABEL_18;
}
if ( a5 )
{
if ( !a2 )
goto LABEL_12;
v10 = mbedtls_mpi_sub_int(v13, a2, 1LL);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_sub_mpi(v14, a5, a3);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_mod_mpi(v14, v14, v13);
if ( v10 )
goto LABEL_5;
if ( (unsigned int)mbedtls_mpi_cmp_int(v14, 0LL) )
goto LABEL_18;
}
if ( !a6 )
goto LABEL_26;
if ( !a1 || !a2 )
goto LABEL_12;
v10 = mbedtls_mpi_mul_mpi(v13, a6, a2);
if ( !v10 )
{
v10 = mbedtls_mpi_sub_int(v13, v13, 1LL);
if ( !v10 )
{
v10 = mbedtls_mpi_mod_mpi(v13, v13, a1);
if ( !v10 )
{
if ( (unsigned int)mbedtls_mpi_cmp_int(v13, 0LL) )
goto LABEL_18;
LABEL_26:
v11 = 0;
goto LABEL_13;
}
}
}
LABEL_5:
if ( v10 == -16896 )
{
LABEL_18:
v11 = -16896;
goto LABEL_13;
}
if ( v10 == -16512 )
goto LABEL_12;
v11 = v10 - 16896;
LABEL_13:
mbedtls_mpi_free(v13);
mbedtls_mpi_free(v14);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
int v10; // eax
unsigned int v11; // er12
_BYTE v13[32]; // [rsp+0h] [rbp-78h] BYREF
char v14[88]; // [rsp+20h] [rbp-58h] BYREF

mbedtls_mpi_init(v13);
mbedtls_mpi_init(v14);
if ( a4 )
{
if ( !a1 )
{
LABEL_12:
v11 = -16512;
goto LABEL_13;
}
v10 = mbedtls_mpi_sub_int(v13, a1, 1LL);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_sub_mpi(v14, a4, a3);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_mod_mpi(v14, v14, v13);
if ( v10 )
goto LABEL_5;
if ( (unsigned int)mbedtls_mpi_cmp_int(v14, 0LL) )
goto LABEL_18;
}
if ( a5 )
{
if ( !a2 )
goto LABEL_12;
v10 = mbedtls_mpi_sub_int(v13, a2, 1LL);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_sub_mpi(v14, a5, a3);
if ( v10 )
goto LABEL_5;
v10 = mbedtls_mpi_mod_mpi(v14, v14, v13);
if ( v10 )
goto LABEL_5;
if ( (unsigned int)mbedtls_mpi_cmp_int(v14, 0LL) )
goto LABEL_18;
}
if ( !a6 )
goto LABEL_26;
if ( !a1 || !a2 )
goto LABEL_12;
v10 = mbedtls_mpi_mul_mpi(v13, a6, a2);
if ( !v10 )
{
v10 = mbedtls_mpi_sub_int(v13, v13, 1LL);
if ( !v10 )
{
v10 = mbedtls_mpi_mod_mpi(v13, v13, a1);
if ( !v10 )
{
if ( (unsigned int)mbedtls_mpi_cmp_int(v13, 0LL) )
goto LABEL_18;
LABEL_26:
v11 = 0;
goto LABEL_13;
}
}
}
LABEL_5:
if ( v10 == -16896 )
{
LABEL_18:
v11 = -16896;
goto LABEL_13;
}
if ( v10 == -16512 )
goto LABEL_12;
v11 = v10 - 16896;
LABEL_13:
mbedtls_mpi_free(v13);
mbedtls_mpi_free(v14);
return v11;
}

original_code:
int mbedtls_rsa_validate_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q,
                             const mbedtls_mpi *D, const mbedtls_mpi *DP,
                             const mbedtls_mpi *DQ, const mbedtls_mpi *QP)
{
    int ret = 0;
    mbedtls_mpi K, L;
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&L);
    if (DP != ((void *)0)) {
        if (P == ((void *)0)) {
            ret = -0x4080;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_sub_int(&K, P, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_mpi(&L, DP, D))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&L, &L, &K))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&L, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (DQ != ((void *)0)) {
        if (Q == ((void *)0)) {
            ret = -0x4080;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_sub_int(&K, Q, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_mpi(&L, DQ, D))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&L, &L, &K))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&L, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (QP != ((void *)0)) {
        if (P == ((void *)0) || Q == ((void *)0)) {
            ret = -0x4080;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, QP, Q))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, P))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
cleanup:
    if (ret != 0 &&
        ret != -0x4200 &&
        ret != -0x4080) {
        ret += -0x4200;
    }
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&L);
    return ret;
}

canonical_original_code:
int mbedtls_rsa_validate_crt(struct mbedtls_mpi *P, struct mbedtls_mpi *Q, struct mbedtls_mpi *D, struct mbedtls_mpi *DP, struct mbedtls_mpi *DQ, struct mbedtls_mpi *QP)
{
    int ret = 0;
    struct mbedtls_mpi K; struct mbedtls_mpi L;
    mbedtls_mpi_init(&K);
    mbedtls_mpi_init(&L);
    if (DP != ((void *)0)) {
        if (P == ((void *)0)) {
            ret = -0x4080;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_sub_int(&K, P, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_mpi(&L, DP, D))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&L, &L, &K))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&L, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (DQ != ((void *)0)) {
        if (Q == ((void *)0)) {
            ret = -0x4080;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_sub_int(&K, Q, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_mpi(&L, DQ, D))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&L, &L, &K))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&L, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
    if (QP != ((void *)0)) {
        if (P == ((void *)0) || Q == ((void *)0)) {
            ret = -0x4080;
            goto cleanup;
        }
        do { if ((ret = (mbedtls_mpi_mul_mpi(&K, QP, Q))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_sub_int(&K, &K, 1))) != 0) goto cleanup; } while (0);
        do { if ((ret = (mbedtls_mpi_mod_mpi(&K, &K, P))) != 0) goto cleanup; } while (0);
        if (mbedtls_mpi_cmp_int(&K, 0) != 0) {
            ret = -0x4200;
            goto cleanup;
        }
    }
cleanup:
    if (ret != 0 &&
        ret != -0x4200 &&
        ret != -0x4080) {
        ret += -0x4200;
    }
    mbedtls_mpi_free(&K);
    mbedtls_mpi_free(&L);
    return ret;
}


decompiled_code:
__int64 __fastcall mbedtls_hash_info_get_size(int a1)
{
int v1; // eax
_DWORD *v2; // rcx

if ( a1 == 2 )
return 20LL;
v1 = 3;
v2 = &hash_table;
while ( a1 != v1 && v1 )
{
v1 = v2[7];
v2 += 3;
}
return *((unsigned __int8 *)v2 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
_DWORD *v2; // rcx

if ( a1 == 2 )
return 20LL;
v1 = 3;
v2 = &hash_table;
while ( a1 != v1 && v1 )
{
v1 = v2[7];
v2 += 3;
}
return *((unsigned __int8 *)v2 + 20);
}

original_code:
unsigned char mbedtls_hash_info_get_size(mbedtls_md_type_t md_type)
{
    const hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->md_type != md_type) {
        entry++;
    }
    return entry->size;
}

canonical_original_code:
unsigned char mbedtls_hash_info_get_size(enum mbedtls_md_type_t md_type)
{
    struct hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->md_type != md_type) {
        entry++;
    }
    return entry->size;
}

variable_types: struct hash_entry { unsigned int psa_alg; enum mbedtls_md_type_t { MBEDTLS_MD_NONE=0, MBEDTLS_MD_MD5=1, MBEDTLS_MD_SHA1=2, MBEDTLS_MD_SHA224=3, MBEDTLS_MD_SHA256=4, MBEDTLS_MD_SHA384=5, MBEDTLS_MD_SHA512=6, MBEDTLS_MD_RIPEMD160=7 } md_type; unsigned char size; unsigned char block_size; } *

return_type: unsigned char

user_defined_types: struct hash_entry { unsigned int psa_alg; enum mbedtls_md_type_t md_type; unsigned char size; unsigned char block_size; }


decompiled_code:
__int64 __fastcall mbedtls_hash_info_get_block_size(int a1)
{
int v1; // eax
_DWORD *v2; // rcx

if ( a1 == 2 )
return 64LL;
v1 = 3;
v2 = &hash_table;
while ( a1 != v1 && v1 )
{
v1 = v2[7];
v2 += 3;
}
return *((unsigned __int8 *)v2 + 21);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
_DWORD *v2; // rcx

if ( a1 == 2 )
return 64LL;
v1 = 3;
v2 = &hash_table;
while ( a1 != v1 && v1 )
{
v1 = v2[7];
v2 += 3;
}
return *((unsigned __int8 *)v2 + 21);
}

original_code:
unsigned char mbedtls_hash_info_get_block_size(mbedtls_md_type_t md_type)
{
    const hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->md_type != md_type) {
        entry++;
    }
    return entry->block_size;
}

canonical_original_code:
unsigned char mbedtls_hash_info_get_block_size(enum mbedtls_md_type_t md_type)
{
    struct hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->md_type != md_type) {
        entry++;
    }
    return entry->block_size;
}

variable_types: enum mbedtls_md_type_t { MBEDTLS_MD_NONE=0, MBEDTLS_MD_MD5=1, MBEDTLS_MD_SHA1=2, MBEDTLS_MD_SHA224=3, MBEDTLS_MD_SHA256=4, MBEDTLS_MD_SHA384=5, MBEDTLS_MD_SHA512=6, MBEDTLS_MD_RIPEMD160=7 }


decompiled_code:
__int64 __fastcall mbedtls_hash_info_psa_from_md(int a1)
{
int v1; // eax
_DWORD *v2; // rcx

if ( a1 == 2 )
return 33554437LL;
v1 = 3;
v2 = &hash_table;
while ( a1 != v1 && v1 )
{
v1 = v2[7];
v2 += 3;
}
return (unsigned int)v2[3];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // eax
_DWORD *v2; // rcx

if ( a1 == 2 )
return 33554437LL;
v1 = 3;
v2 = &hash_table;
while ( a1 != v1 && v1 )
{
v1 = v2[7];
v2 += 3;
}
return (unsigned int)v2[3];
}

original_code:
psa_algorithm_t mbedtls_hash_info_psa_from_md(mbedtls_md_type_t md_type)
{
    const hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->md_type != md_type) {
        entry++;
    }
    return entry->psa_alg;
}

canonical_original_code:
unsigned int mbedtls_hash_info_psa_from_md(enum mbedtls_md_type_t md_type)
{
    struct hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->md_type != md_type) {
        entry++;
    }
    return entry->psa_alg;
}

return_type: unsigned int

user_defined_types: enum mbedtls_md_type_t { MBEDTLS_MD_NONE=0, MBEDTLS_MD_MD5=1, MBEDTLS_MD_SHA1=2, MBEDTLS_MD_SHA224=3, MBEDTLS_MD_SHA256=4, MBEDTLS_MD_SHA384=5, MBEDTLS_MD_SHA512=6, MBEDTLS_MD_RIPEMD160=7 }


decompiled_code:
__int64 __fastcall mbedtls_hash_info_md_from_psa(int a1)
{
int v1; // edx
int *v2; // rax
unsigned int v3; // er8

v1 = 33554437;
v2 = (int *)&hash_table;
v3 = 2;
while ( a1 != v1 )
{
v3 = v2[4];
v2 += 3;
if ( !v3 )
break;
v1 = *v2;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // edx
int *v2; // rax
unsigned int v3; // er8

v1 = 33554437;
v2 = (int *)&hash_table;
v3 = 2;
while ( a1 != v1 )
{
v3 = v2[4];
v2 += 3;
if ( !v3 )
break;
v1 = *v2;
}
return v3;
}

original_code:
mbedtls_md_type_t mbedtls_hash_info_md_from_psa(psa_algorithm_t psa_alg)
{
    const hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->psa_alg != psa_alg) {
        entry++;
    }
    return entry->md_type;
}

canonical_original_code:
enum mbedtls_md_type_t mbedtls_hash_info_md_from_psa(unsigned int psa_alg)
{
    struct hash_entry *entry = hash_table;
    while (entry->md_type != MBEDTLS_MD_NONE &&
           entry->psa_alg != psa_alg) {
        entry++;
    }
    return entry->md_type;
}

return_type: enum mbedtls_md_type_t { MBEDTLS_MD_NONE=0, MBEDTLS_MD_MD5=1, MBEDTLS_MD_SHA1=2, MBEDTLS_MD_SHA224=3, MBEDTLS_MD_SHA256=4, MBEDTLS_MD_SHA384=5, MBEDTLS_MD_SHA512=6, MBEDTLS_MD_RIPEMD160=7 }


decompiled_code:
unsigned __int64 __fastcall mul64(unsigned int a1, unsigned int a2)
{
return a2 * (unsigned __int64)a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
return a2 * (unsigned __int64)a1;
}

original_code:
static inline uint64_t mul64(uint32_t a, uint32_t b)
{
    return (uint64_t) a * b;
}

canonical_original_code:
static inline unsigned long mul64(unsigned int a, unsigned int b)
{
    return (unsigned long) a * b;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

return_type: unsigned long