decompiled_code:
__int64 __fastcall irc_strncmp(int a1, char *a2, char *a3, __int64 a4)
{
char *v4; // rbx
char *v6; // r14
int v7; // ebp
__int64 result; // rax

if ( !a4 )
return 0LL;
v4 = a2;
v6 = &a2[a4];
while ( 1 )
{
v7 = irc_toupper(a1, *v4++);
result = irc_toupper(a1, *a3++);
if ( v7 != (_DWORD)result )
break;
if ( !(_DWORD)result )
return result;
if ( v6 == v4 )
return 0LL;
}
return (unsigned int)(result - v7);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, char *a2, char *a3, __int64 a4)
{
char *v4; // rbx
char *v6; // r14
int v7; // ebp
__int64 result; // rax

if ( !a4 )
return 0LL;
v4 = a2;
v6 = &a2[a4];
while ( 1 )
{
v7 = func2(a1, *v4++);
result = func2(a1, *a3++);
if ( v7 != (_DWORD)result )
break;
if ( !(_DWORD)result )
return result;
if ( v6 == v4 )
return 0LL;
}
return (unsigned int)(result - v7);
}

original_code:
int
irc_strncmp(enum casemapping cm, const char *s1, const char *s2, size_t n)
{
 int c1, c2;
 while (n > 0) {
  c1 = irc_toupper(cm, *s1++);
  c2 = irc_toupper(cm, *s2++);
  if ((c1 -= c2))
   return -c1;
  if (c2 == 0)
   break;
  n--;
 }
 return 0;
}

canonical_original_code:
int irc_strncmp(enum casemapping cm, char *s1, char *s2, unsigned long n)
{
 int c1; int c2;
 while (n > 0) {
  c1 = irc_toupper(cm, *s1++);
  c2 = irc_toupper(cm, *s2++);
  if ((c1 -= c2))
   return -c1;
  if (c2 == 0)
   break;
  n--;
 }
 return 0;
}

variable_types:
n
unsigned long


repo: rcr/rirc

decompiled_code:
__int64 __fastcall irc_pinged(int a1, char *a2, char *a3)
{
char *v4; // rbx
__int64 v6; // r13
__int64 result; // rax
char v8; // di
char v9; // bp

v4 = a2;
v6 = strlen(a3);
result = 0LL;
if ( *a2 )
{
do
{
v8 = *v4;
if ( *v4 )
{
v9 = *a3;
do
{
if ( v9 == v8 )
break;
if ( (unsigned int)irc_isnickchar(v8, 1) )
break;
v8 = *++v4;
}
while ( *v4 );
}
if ( !(unsigned int)irc_strncmp(a1, v4, a3, v6) && !(unsigned int)irc_isnickchar(v4[v6], 0) )
return 1LL;
for ( ; (*v4 & 0xDF) != 0; ++v4 )
;
}
while ( *v4 );
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char *a2, char *a3)
{
char *v4; // rbx
__int64 v6; // r13
__int64 result; // rax
char v8; // di
char v9; // bp

v4 = a2;
v6 = strlen(a3);
result = 0LL;
if ( *a2 )
{
do
{
v8 = *v4;
if ( *v4 )
{
v9 = *a3;
do
{
if ( v9 == v8 )
break;
if ( (unsigned int)func1(v8, 1) )
break;
v8 = *++v4;
}
while ( *v4 );
}
if ( !(unsigned int)func6(a1, v4, a3, v6) && !(unsigned int)func1(v4[v6], 0) )
return 1LL;
for ( ; (*v4 & 0xDF) != 0; ++v4 )
;
}
while ( *v4 );
result = 0LL;
}
return result;
}

original_code:
int
irc_pinged(enum casemapping cm, const char *mesg, const char *nick)
{
 size_t len = strlen(nick);
 while (*mesg) {
  while (*mesg && *mesg != *nick && !irc_isnickchar(*mesg, 1))
   mesg++;
  if (!irc_strncmp(cm, mesg, nick, len) && !irc_isnickchar(*(mesg + len), 0))
   return 1;
  while (*mesg && *mesg != ' ')
   mesg++;
 }
 return 0;
}

canonical_original_code:
int irc_pinged(enum casemapping cm, char *mesg, char *nick)
{
 unsigned long len = strlen(nick);
 while (*mesg) {
  while (*mesg && *mesg != *nick && !irc_isnickchar(*mesg, 1))
   mesg++;
  if (!irc_strncmp(cm, mesg, nick, len) && !irc_isnickchar(*(mesg + len), 0))
   return 1;
  while (*mesg && *mesg != ' ')
   mesg++;
 }
 return 0;
}

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

variable_types:
mesg
char *

variable_types:
nick
char *

variable_types:
len
unsigned long

return_type: int


original_code:
int
irc_message_split(struct irc_message *m, const char **params, const char **trailing)
{
 *params = m->params;
 *trailing = ((void *)0);
 if (!m->params)
  return 0;
 m->split = 1;
 for (char *p = m->params; *p;) {
  while (*p == ' ')
   p++;
  if (*p == 0)
   return 0;
  m->n_params++;
  if (m->n_params >= 15) {
   if (m->params == p) {
    *params = m->params = ((void *)0);
    *trailing = p;
   } else {
    *trailing = (*p) ? p : ((void *)0);
    do {
     if (p == m->params) {
      *params = m->params = ((void *)0);
      return 1;
     }
     p--;
    } while (*p == ' ');
    *(p + 1) = 0;
   }
   return 1;
  }
  if (*p == ':') {
   *p = 0;
   *trailing = (*(p + 1)) ? (p + 1) : ((void *)0);
   do {
    if (p == m->params) {
     *params = m->params = ((void *)0);
     return 1;
    }
    p--;
   } while (*p == ' ');
   *(p + 1) = 0;
   return 1;
  }
  while (*p && *p != ' ')
   p++;
 }
 return 0;
}

canonical_original_code:
int irc_message_split(struct irc_message *m, char **params, char **trailing)
{
 *params = m->params;
 *trailing = ((void *)0);
 if (!m->params)
  return 0;
 m->split = 1;
 for (char *p = m->params; *p;) {
  while (*p == ' ')
   p++;
  if (*p == 0)
   return 0;
  m->n_params++;
  if (m->n_params >= 15) {
   if (m->params == p) {
    *params = m->params = ((void *)0);
    *trailing = p;
   } else {
    *trailing = (*p) ? p : ((void *)0);
    do {
     if (p == m->params) {
      *params = m->params = ((void *)0);
      return 1;
     }
     p--;
    } while (*p == ' ');
    *(p + 1) = 0;
   }
   return 1;
  }
  if (*p == ':') {
   *p = 0;
   *trailing = (*(p + 1)) ? (p + 1) : ((void *)0);
   do {
    if (p == m->params) {
     *params = m->params = ((void *)0);
     return 1;
    }
    p--;
   } while (*p == ' ');
   *(p + 1) = 0;
   return 1;
  }
  while (*p && *p != ' ')
   p++;
 }
 return 0;
}

variable_types: struct irc_message { char *params; char *command; char *from; char *host; unsigned long len_command; unsigned long len_from; unsigned long len_host; unsigned int n_params; unsigned int split; } *

variable_types:
params
char **

variable_types:
trailing
char **

variable_types:
p
char *


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

result = strdup(a1);
if ( !result )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/utils/utils.c", 294LL, "irc_strdup");
fwrite("strdup", 1uLL, 6uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
return result;
}

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

result = strdup(a1);
if ( !result )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/utils/utils.c", 294LL, "irc_strdup");
fwrite("strdup", 1uLL, 6uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
return result;
}

original_code:
char*
irc_strdup(const char *str)
{
 char *ret;
 if (!(ret = strdup(str)))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/utils/utils.c", 294, __func__); fprintf(stderr, "strdup"); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 return ret;
}

canonical_original_code:
char *irc_strdup(char *str)
{
 char *ret;
 if (!(ret = strdup(str)))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/utils/utils.c", 294, __func__); fprintf(stderr, "strdup"); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 return ret;
}

variable_types:
str
char *

variable_types:
ret
char *

return_type: char *


original_code:
int
irc_message_param(struct irc_message *m, char **param)
{
 *param = ((void *)0);
 if (m->params == ((void *)0))
  return 0;
 if (!irc_strtrim(&m->params))
  return 0;
 if (!m->split && m->n_params >= 14) {
  *param = m->params;
  m->params = ((void *)0);
  return 1;
 }
 if (*m->params == ':') {
  *param = m->params + 1;
  m->params = ((void *)0);
  return 1;
 }
 m->n_params++;
 *param = m->params;
 while (*m->params && *m->params != ' ')
  m->params++;
 if (*m->params)
  *m->params++ = 0;
 return 1;
}

variable_types:
param
char **

user_defined_types: struct irc_message { char *params; char *command; char *from; char *host; unsigned long len_command; unsigned long len_from; unsigned long len_host; unsigned int n_params; unsigned int split; }


original_code:
int
irc_message_parse(struct irc_message *m, char *buf)
{
 memset(m, 0, sizeof(*m));
 if (!irc_strtrim(&buf))
  return -1;
 if (*buf == ':') {
  buf++;
  m->from = buf;
  while (*buf && *buf != ' ' && *buf != '!' && *buf != '@')
   buf++;
  m->len_from = buf - m->from;
  if (m->len_from == 0)
   return -1;
  if (*buf == '!' || *buf == '@') {
   *buf++ = 0;
   m->host = buf;
   while (*buf && *buf != ' ')
    buf++;
   m->len_host = buf - m->host;
  }
  if (*buf == ' ')
   *buf++ = 0;
 }
 if (!irc_strtrim(&buf))
  return -1;
 m->command = buf;
 while (*buf && *buf != ' ')
  buf++;
 m->len_command = buf - m->command;
 if (*buf == ' ')
  *buf++ = 0;
 if (irc_strtrim(&buf))
  m->params = buf;
 return 0;
}

variable_types:
buf
char *


decompiled_code:
_BOOL8 __fastcall mbedtls_aesni_has_support(int a1)
{
if ( done_1 )
return (c_0 & a1) != 0;
_RAX = 1LL;
__asm { cpuid }
c_0 = _RCX;
done_1 = 1;
return ((unsigned int)_RCX & a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
if ( done_1 )
return (c_0 & a1) != 0;
_RAX = 1LL;
__asm { cpuid }
c_0 = _RCX;
done_1 = 1;
return ((unsigned int)_RCX & a1) != 0;
}

original_code:
int mbedtls_aesni_has_support(unsigned int what)
{
    static int done = 0;
    static unsigned int c = 0;
    if (!done) {
        __asm__ ("movl  $1, %%eax   \n\t"
             "cpuid             \n\t"
             : "=c" (c)
             :
             : "eax", "ebx", "edx");
        done = 1;
    }
    return (c & what) != 0;
}

variable_types:
what
unsigned int

variable_types: done int

variable_types:
c
unsigned int


original_code:
void mbedtls_aesni_inverse_key(unsigned char *invkey,
                               const unsigned char *fwdkey, int nr)
{
    unsigned char *ik = invkey;
    const unsigned char *fk = fwdkey + 16 * nr;
    memcpy(ik, fk, 16);
    for (fk -= 16, ik += 16; fk > fwdkey; fk -= 16, ik += 16) {
        __asm__ ("movdqu (%0), %%xmm0       \n\t"
             ".byte 0x66,0x0F,0x38,0xDB," "0xC0" "\n\t"
             "movdqu %%xmm0, (%1)       \n\t"
             :
             : "r" (fk), "r" (ik)
             : "memory", "xmm0");
    }
    memcpy(ik, fk, 16);
}

canonical_original_code:
void mbedtls_aesni_inverse_key(unsigned char *invkey, unsigned char *fwdkey, int nr)
{
    unsigned char *ik = invkey;
    unsigned char *fk = fwdkey + 16 * nr;
    memcpy(ik, fk, 16);
    for (fk -= 16, ik += 16; fk > fwdkey; fk -= 16, ik += 16) {
        __asm__ ("movdqu (%0), %%xmm0       \n\t"
             ".byte 0x66,0x0F,0x38,0xDB," "0xC0" "\n\t"
             "movdqu %%xmm0, (%1)       \n\t"
             :
             : "r" (fk), "r" (ik)
             : "memory", "xmm0");
    }
    memcpy(ik, fk, 16);
}

variable_types:
invkey
unsigned char *

variable_types:
fwdkey
unsigned char *

variable_types: nr int

variable_types:
ik
unsigned char *

variable_types:
fk
unsigned char *

return_type: void


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

if ( a3 == 192 )
{
aesni_setkey_enc_192();
result = 0LL;
}
else if ( a3 == 256 )
{
aesni_setkey_enc_256();
result = 0LL;
}
else
{
result = 4294967264LL;
if ( a3 == 128 )
{
aesni_setkey_enc_128();
result = 0LL;
}
}
return result;
}

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

if ( a3 == 192 )
{
aesni_setkey_enc_192();
result = 0LL;
}
else if ( a3 == 256 )
{
aesni_setkey_enc_256();
result = 0LL;
}
else
{
result = 4294967264LL;
if ( a3 == 128 )
{
aesni_setkey_enc_128();
result = 0LL;
}
}
return result;
}

original_code:
int mbedtls_aesni_setkey_enc(unsigned char *rk,
                             const unsigned char *key,
                             size_t bits)
{
    switch (bits) {
        case 128: aesni_setkey_enc_128(rk, key); break;
        case 192: aesni_setkey_enc_192(rk, key); break;
        case 256: aesni_setkey_enc_256(rk, key); break;
        default: return -0x0020;
    }
    return 0;
}

canonical_original_code:
int mbedtls_aesni_setkey_enc(unsigned char *rk, unsigned char *key, unsigned long bits)
{
    switch (bits) {
        case 128: aesni_setkey_enc_128(rk, key); break;
        case 192: aesni_setkey_enc_192(rk, key); break;
        case 256: aesni_setkey_enc_256(rk, key); break;
        default: return -0x0020;
    }
    return 0;
}

variable_types:
rk
unsigned char *

variable_types:
key
unsigned char *

variable_types:
bits
unsigned long


decompiled_code:
__int64 __fastcall set_mont_const_square(_QWORD *a1, const void *a2, __int64 a3)
{
unsigned int v4; // ebx
_BYTE v6[16]; // [rsp+0h] [rbp-58h] BYREF
__int64 v7; // [rsp+10h] [rbp-48h]
char v8[16]; // [rsp+20h] [rbp-38h] BYREF
void *dest; // [rsp+30h] [rbp-28h]

*a1 = 0LL;
mbedtls_mpi_init(v8);
mbedtls_mpi_init(v6);
if ( (unsigned __int64)(a3 - 1) > 0x1384
|| !a2
|| (unsigned int)mbedtls_mpi_grow(v8, a3)
|| (memcpy(dest, a2, 8 * a3), (v4 = mbedtls_mpi_core_get_mont_r2_unsafe(v6, v8)) != 0) )
{
mbedtls_mpi_free(v8);
mbedtls_mpi_free(v6);
v4 = -110;
}
else
{
*a1 = v7;
v7 = 0LL;
mbedtls_mpi_free(v8);
mbedtls_mpi_free(v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const void *a2, __int64 a3)
{
unsigned int v4; // ebx
_BYTE v6[16]; // [rsp+0h] [rbp-58h] BYREF
__int64 v7; // [rsp+10h] [rbp-48h]
char v8[16]; // [rsp+20h] [rbp-38h] BYREF
void *dest; // [rsp+30h] [rbp-28h]

*a1 = 0LL;
mbedtls_mpi_init(v8);
mbedtls_mpi_init(v6);
if ( (unsigned __int64)(a3 - 1) > 0x1384
|| !a2
|| (unsigned int)mbedtls_mpi_grow(v8, a3)
|| (memcpy(dest, a2, 8 * a3), (v4 = mbedtls_mpi_core_get_mont_r2_unsafe(v6, v8)) != 0) )
{
mbedtls_mpi_free(v8);
mbedtls_mpi_free(v6);
v4 = -110;
}
else
{
*a1 = v7;
v7 = 0LL;
mbedtls_mpi_free(v8);
mbedtls_mpi_free(v6);
}
return v4;
}

original_code:
static int set_mont_const_square(const mbedtls_mpi_uint **X,
                                 const mbedtls_mpi_uint *A,
                                 size_t limbs)
{
    int ret = -0x006E;
    mbedtls_mpi N;
    mbedtls_mpi RR;
    *X = ((void *)0);
    mbedtls_mpi_init(&N);
    mbedtls_mpi_init(&RR);
    if (A == ((void *)0) || limbs == 0 || limbs >= (10000 / 2) - 2) {
        goto cleanup;
    }
    if (mbedtls_mpi_grow(&N, limbs)) {
        goto cleanup;
    }
    memcpy(N.p, A, sizeof(mbedtls_mpi_uint) * limbs);
    ret = mbedtls_mpi_core_get_mont_r2_unsafe(&RR, &N);
    if (ret == 0) {
        *X = RR.p;
        RR.p = ((void *)0);
    }
cleanup:
    mbedtls_mpi_free(&N);
    mbedtls_mpi_free(&RR);
    ret = (ret != 0) ? -0x006E : 0;
    return ret;
}

canonical_original_code:
static int set_mont_const_square(unsigned long **X, unsigned long *A, unsigned long limbs)
{
    int ret = -0x006E;
    struct mbedtls_mpi N;
    struct mbedtls_mpi RR;
    *X = ((void *)0);
    mbedtls_mpi_init(&N);
    mbedtls_mpi_init(&RR);
    if (A == ((void *)0) || limbs == 0 || limbs >= (10000 / 2) - 2) {
        goto cleanup;
    }
    if (mbedtls_mpi_grow(&N, limbs)) {
        goto cleanup;
    }
    memcpy(N.p, A, sizeof(mbedtls_mpi_uint) * limbs);
    ret = mbedtls_mpi_core_get_mont_r2_unsafe(&RR, &N);
    if (ret == 0) {
        *X = RR.p;
        RR.p = ((void *)0);
    }
cleanup:
    mbedtls_mpi_free(&N);
    mbedtls_mpi_free(&RR);
    ret = (ret != 0) ? -0x006E : 0;
    return ret;
}

variable_types:
X
unsigned long **

variable_types:
A
unsigned long *

variable_types:
limbs
unsigned long

variable_types: ret int

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


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_residue_setup(_QWORD *a1, _QWORD *a2, __int64 a3, __int64 a4)
{
if ( a2[1] != a4 )
return 4294967292LL;
if ( !(unsigned int)mbedtls_mpi_core_lt_ct(a3, *a2) )
return 4294967292LL;
a1[1] = a2[1];
*a1 = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _QWORD *a2, __int64 a3, __int64 a4)
{
if ( a2[1] != a4 )
return 4294967292LL;
if ( !(unsigned int)mbedtls_mpi_core_lt_ct(a3, *a2) )
return 4294967292LL;
a1[1] = a2[1];
*a1 = a3;
return 0LL;
}

original_code:
int mbedtls_mpi_mod_residue_setup(mbedtls_mpi_mod_residue *r,
                                  const mbedtls_mpi_mod_modulus *N,
                                  mbedtls_mpi_uint *p,
                                  size_t p_limbs)
{
    if (p_limbs != N->limbs || !mbedtls_mpi_core_lt_ct(p, N->p, N->limbs)) {
        return -0x0004;
    }
    r->limbs = N->limbs;
    r->p = p;
    return 0;
}

canonical_original_code:
int mbedtls_mpi_mod_residue_setup(struct mbedtls_mpi_mod_residue *r, struct mbedtls_mpi_mod_modulus *N, unsigned long *p, unsigned long p_limbs)
{
    if (p_limbs != N->limbs || !mbedtls_mpi_core_lt_ct(p, N->p, N->limbs)) {
        return -0x0004;
    }
    r->limbs = N->limbs;
    r->p = p;
    return 0;
}

variable_types: struct mbedtls_mpi_mod_residue { unsigned long *p; unsigned long limbs; } *

variable_types: struct mbedtls_mpi_mod_modulus { unsigned long *p; unsigned long limbs; unsigned long bits; enum mbedtls_mpi_mod_rep_selector { MBEDTLS_MPI_MOD_REP_INVALID=0, MBEDTLS_MPI_MOD_REP_MONTGOMERY=2, MBEDTLS_MPI_MOD_REP_OPT_RED=3 } int_rep; union rep { struct mbedtls_mpi_mont_struct { unsigned long *rr; unsigned long mm; } mont; void *ored; } rep; } *

variable_types:
p
unsigned long *

user_defined_types: struct mbedtls_mpi_mod_modulus { unsigned long *p; unsigned long limbs; unsigned long bits; enum mbedtls_mpi_mod_rep_selector int_rep; union rep rep; }

user_defined_types: union rep { struct mbedtls_mpi_mont_struct mont; void *ored; }


decompiled_code:
void __fastcall mbedtls_mpi_mod_modulus_init(__int64 a1)
{
if ( a1 )
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)(a1 + 24) = 0;
}
}

original_code:
void mbedtls_mpi_mod_modulus_init(mbedtls_mpi_mod_modulus *N)
{
    if (N == ((void *)0)) {
        return;
    }
    N->p = ((void *)0);
    N->limbs = 0;
    N->bits = 0;
    N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
}

canonical_original_code:
void mbedtls_mpi_mod_modulus_init(struct mbedtls_mpi_mod_modulus *N)
{
    if (N == ((void *)0)) {
        return;
    }
    N->p = ((void *)0);
    N->limbs = 0;
    N->bits = 0;
    N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
}

user_defined_types: enum mbedtls_mpi_mod_rep_selector { MBEDTLS_MPI_MOD_REP_INVALID=0, MBEDTLS_MPI_MOD_REP_MONTGOMERY=2, MBEDTLS_MPI_MOD_REP_OPT_RED=3 }

user_defined_types: struct mbedtls_mpi_mont_struct { unsigned long *rr; unsigned long mm; }


original_code:
void mbedtls_mpi_mod_modulus_free(mbedtls_mpi_mod_modulus *N)
{
    if (N == ((void *)0)) {
        return;
    }
    switch (N->int_rep) {
        case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
            if (N->rep.mont.rr != ((void *)0)) {
                mbedtls_platform_zeroize((mbedtls_mpi_uint *) N->rep.mont.rr,
                                         N->limbs * sizeof(mbedtls_mpi_uint));
                free((mbedtls_mpi_uint *) N->rep.mont.rr);
                N->rep.mont.rr = ((void *)0);
            }
            N->rep.mont.mm = 0;
            break;
        case MBEDTLS_MPI_MOD_REP_OPT_RED:
            free(N->rep.ored);
            break;
        case MBEDTLS_MPI_MOD_REP_INVALID:
            break;
    }
    N->p = ((void *)0);
    N->limbs = 0;
    N->bits = 0;
    N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
}

canonical_original_code:
void mbedtls_mpi_mod_modulus_free(struct mbedtls_mpi_mod_modulus *N)
{
    if (N == ((void *)0)) {
        return;
    }
    switch (N->int_rep) {
        case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
            if (N->rep.mont.rr != ((void *)0)) {
                mbedtls_platform_zeroize((unsigned long *) N->rep.mont.rr,
                                         N->limbs * sizeof(mbedtls_mpi_uint));
                free((unsigned long *) N->rep.mont.rr);
                N->rep.mont.rr = ((void *)0);
            }
            N->rep.mont.mm = 0;
            break;
        case MBEDTLS_MPI_MOD_REP_OPT_RED:
            free(N->rep.ored);
            break;
        case MBEDTLS_MPI_MOD_REP_INVALID:
            break;
    }
    N->p = ((void *)0);
    N->limbs = 0;
    N->bits = 0;
    N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
}


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_modulus_setup(__int64 a1, __int64 a2, __int64 a3, int a4)
{
unsigned int v5; // ebp

*(_QWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = mbedtls_mpi_core_bitlen(a2, a3);
if ( a4 == 2 )
{
*(_DWORD *)(a1 + 24) = 2;
*(_QWORD *)(a1 + 40) = mbedtls_mpi_core_montmul_init(*(_QWORD *)a1);
v5 = set_mont_const_square((_QWORD *)(a1 + 32), *(const void **)a1, *(_QWORD *)(a1 + 8));
if ( !v5 )
return v5;
}
else
{
if ( a4 == 3 )
{
*(_DWORD *)(a1 + 24) = 3;
*(_QWORD *)(a1 + 32) = 0LL;
return 0;
}
v5 = -4;
}
mbedtls_mpi_mod_modulus_free(a1);
return v5;
}

original_code:
int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *N,
                                  const mbedtls_mpi_uint *p,
                                  size_t p_limbs,
                                  mbedtls_mpi_mod_rep_selector int_rep)
{
    int ret = 0;
    N->p = p;
    N->limbs = p_limbs;
    N->bits = mbedtls_mpi_core_bitlen(p, p_limbs);
    switch (int_rep) {
        case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
            N->int_rep = int_rep;
            N->rep.mont.mm = mbedtls_mpi_core_montmul_init(N->p);
            ret = set_mont_const_square(&N->rep.mont.rr, N->p, N->limbs);
            break;
        case MBEDTLS_MPI_MOD_REP_OPT_RED:
            N->int_rep = int_rep;
            N->rep.ored = ((void *)0);
            break;
        default:
            ret = -0x0004;
            goto exit;
    }
exit:
    if (ret != 0) {
        mbedtls_mpi_mod_modulus_free(N);
    }
    return ret;
}

canonical_original_code:
int mbedtls_mpi_mod_modulus_setup(struct mbedtls_mpi_mod_modulus *N, unsigned long *p, unsigned long p_limbs, enum mbedtls_mpi_mod_rep_selector int_rep)
{
    int ret = 0;
    N->p = p;
    N->limbs = p_limbs;
    N->bits = mbedtls_mpi_core_bitlen(p, p_limbs);
    switch (int_rep) {
        case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
            N->int_rep = int_rep;
            N->rep.mont.mm = mbedtls_mpi_core_montmul_init(N->p);
            ret = set_mont_const_square(&N->rep.mont.rr, N->p, N->limbs);
            break;
        case MBEDTLS_MPI_MOD_REP_OPT_RED:
            N->int_rep = int_rep;
            N->rep.ored = ((void *)0);
            break;
        default:
            ret = -0x0004;
            goto exit;
    }
exit:
    if (ret != 0) {
        mbedtls_mpi_mod_modulus_free(N);
    }
    return ret;
}

variable_types: enum mbedtls_mpi_mod_rep_selector { MBEDTLS_MPI_MOD_REP_INVALID=0, MBEDTLS_MPI_MOD_REP_MONTGOMERY=2, MBEDTLS_MPI_MOD_REP_OPT_RED=3 }


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_inv_non_mont(_QWORD *a1, _QWORD *a2, __int64 *a3, __int64 a4)
{
unsigned int v6; // ebx
__int64 v8; // [rsp+0h] [rbp-58h] BYREF
__int64 v9; // [rsp+8h] [rbp-50h]
__int64 v10; // [rsp+20h] [rbp-38h]
__int64 v11; // [rsp+28h] [rbp-30h]

mbedtls_mpi_mod_modulus_init((__int64)&v8);
v6 = mbedtls_mpi_mod_modulus_setup((__int64)&v8, *a3, a3[1], 2);
if ( !v6 )
{
mbedtls_mpi_core_to_mont_rep(*a1, *a2, v8, v9, v11, v10, a4);
mbedtls_mpi_mod_raw_inv_prime(*a1, *a1, v8, v9, v10, a4);
mbedtls_mpi_core_from_mont_rep(*a1, *a1, v8, v9, v11, a4);
}
mbedtls_mpi_mod_modulus_free((__int64)&v8);
return v6;
}

original_code:
static int mbedtls_mpi_mod_inv_non_mont(mbedtls_mpi_mod_residue *X,
                                        const mbedtls_mpi_mod_residue *A,
                                        const mbedtls_mpi_mod_modulus *N,
                                        mbedtls_mpi_uint *working_memory)
{
    int ret = -0x006E;
    mbedtls_mpi_mod_modulus Nmont;
    mbedtls_mpi_mod_modulus_init(&Nmont);
    do { if ((ret = (mbedtls_mpi_mod_modulus_setup(&Nmont, N->p, N->limbs, MBEDTLS_MPI_MOD_REP_MONTGOMERY))) != 0) goto cleanup; } while (0);
    mbedtls_mpi_core_to_mont_rep(X->p, A->p, Nmont.p, Nmont.limbs,
                                 Nmont.rep.mont.mm, Nmont.rep.mont.rr,
                                 working_memory);
    mbedtls_mpi_mod_raw_inv_prime(X->p, X->p,
                                  Nmont.p, Nmont.limbs,
                                  Nmont.rep.mont.rr,
                                  working_memory);
    mbedtls_mpi_core_from_mont_rep(X->p, X->p, Nmont.p, Nmont.limbs,
                                   Nmont.rep.mont.mm, working_memory);
cleanup:
    mbedtls_mpi_mod_modulus_free(&Nmont);
    return ret;
}

canonical_original_code:
static int mbedtls_mpi_mod_inv_non_mont(struct mbedtls_mpi_mod_residue *X, struct mbedtls_mpi_mod_residue *A, struct mbedtls_mpi_mod_modulus *N, unsigned long *working_memory)
{
    int ret = -0x006E;
    struct mbedtls_mpi_mod_modulus Nmont;
    mbedtls_mpi_mod_modulus_init(&Nmont);
    do { if ((ret = (mbedtls_mpi_mod_modulus_setup(&Nmont, N->p, N->limbs, MBEDTLS_MPI_MOD_REP_MONTGOMERY))) != 0) goto cleanup; } while (0);
    mbedtls_mpi_core_to_mont_rep(X->p, A->p, Nmont.p, Nmont.limbs,
                                 Nmont.rep.mont.mm, Nmont.rep.mont.rr,
                                 working_memory);
    mbedtls_mpi_mod_raw_inv_prime(X->p, X->p,
                                  Nmont.p, Nmont.limbs,
                                  Nmont.rep.mont.rr,
                                  working_memory);
    mbedtls_mpi_core_from_mont_rep(X->p, X->p, Nmont.p, Nmont.limbs,
                                   Nmont.rep.mont.mm, working_memory);
cleanup:
    mbedtls_mpi_mod_modulus_free(&Nmont);
    return ret;
}

variable_types:
A
struct mbedtls_mpi_mod_residue *

variable_types: struct mbedtls_mpi_mod_modulus { unsigned long *p; unsigned long limbs; unsigned long bits; enum mbedtls_mpi_mod_rep_selector { MBEDTLS_MPI_MOD_REP_INVALID=0, MBEDTLS_MPI_MOD_REP_MONTGOMERY=2, MBEDTLS_MPI_MOD_REP_OPT_RED=3 } int_rep; union rep { struct mbedtls_mpi_mont_struct { unsigned long *rr; unsigned long mm; } mont; void *ored; } rep; }

user_defined_types: struct mbedtls_mpi_mod_residue { unsigned long *p; unsigned long limbs; }


original_code:
int mbedtls_mpi_mod_mul(mbedtls_mpi_mod_residue *X,
                        const mbedtls_mpi_mod_residue *A,
                        const mbedtls_mpi_mod_residue *B,
                        const mbedtls_mpi_mod_modulus *N)
{
    if (N->limbs == 0) {
        return -0x0004;
    }
    if (X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs) {
        return -0x0004;
    }
    mbedtls_mpi_uint *T = calloc(N->limbs * 2 + 1, (sizeof(mbedtls_mpi_uint)));
    if (T == ((void *)0)) {
        return -0x0010;
    }
    mbedtls_mpi_mod_raw_mul(X->p, A->p, B->p, N, T);
    free(T);
    return 0;
}

canonical_original_code:
int mbedtls_mpi_mod_mul(struct mbedtls_mpi_mod_residue *X, struct mbedtls_mpi_mod_residue *A, struct mbedtls_mpi_mod_residue *B, struct mbedtls_mpi_mod_modulus *N)
{
    if (N->limbs == 0) {
        return -0x0004;
    }
    if (X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs) {
        return -0x0004;
    }
    unsigned long *T = calloc(N->limbs * 2 + 1, (sizeof(mbedtls_mpi_uint)));
    if (T == ((void *)0)) {
        return -0x0010;
    }
    mbedtls_mpi_mod_raw_mul(X->p, A->p, B->p, N, T);
    free(T);
    return 0;
}

variable_types:
B
struct mbedtls_mpi_mod_residue *

variable_types:
T
unsigned long *


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_sub(_QWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4)
{
__int64 v4; // rax

v4 = *(_QWORD *)(a4 + 8);
if ( a1[1] != v4 )
return 4294967292LL;
if ( v4 != a2[1] )
return 4294967292LL;
if ( v4 != a3[1] )
return 4294967292LL;
mbedtls_mpi_mod_raw_sub(*a1, *a2, *a3);
return 0LL;
}

original_code:
int mbedtls_mpi_mod_sub(mbedtls_mpi_mod_residue *X,
                        const mbedtls_mpi_mod_residue *A,
                        const mbedtls_mpi_mod_residue *B,
                        const mbedtls_mpi_mod_modulus *N)
{
    if (X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs) {
        return -0x0004;
    }
    mbedtls_mpi_mod_raw_sub(X->p, A->p, B->p, N);
    return 0;
}

canonical_original_code:
int mbedtls_mpi_mod_sub(struct mbedtls_mpi_mod_residue *X, struct mbedtls_mpi_mod_residue *A, struct mbedtls_mpi_mod_residue *B, struct mbedtls_mpi_mod_modulus *N)
{
    if (X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs) {
        return -0x0004;
    }
    mbedtls_mpi_mod_raw_sub(X->p, A->p, B->p, N);
    return 0;
}


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_inv(_QWORD *a1, _QWORD *a2, __int64 a3)
{
__int64 v3; // rax
size_t v5; // rbp
void *v6; // r14
int v7; // eax
unsigned int v8; // ebx

v3 = *(_QWORD *)(a3 + 8);
if ( a1[1] != v3 )
return (unsigned int)-4;
if ( v3 != a2[1] )
return (unsigned int)-4;
if ( !mbedtls_mpi_core_check_zero_ct(*a2) )
return (unsigned int)-4;
v5 = mbedtls_mpi_mod_raw_inv_prime_working_limbs(*(_QWORD *)(a3 + 8));
v6 = calloc(v5, 8uLL);
if ( !v6 )
return (unsigned int)-16;
v7 = *(_DWORD *)(a3 + 24);
if ( v7 == 2 )
{
v8 = mbedtls_mpi_mod_inv_mont(a1, a2, (_QWORD *)a3, (__int64)v6);
}
else if ( v7 == 3 )
{
v8 = mbedtls_mpi_mod_inv_non_mont(a1, a2, (__int64 *)a3, (__int64)v6);
}
else
{
v8 = -4;
}
mbedtls_platform_zeroize(v6, 8 * v5);
free(v6);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, _QWORD *a2, __int64 a3)
{
__int64 v3; // rax
size_t v5; // rbp
void *v6; // r14
int v7; // eax
unsigned int v8; // ebx

v3 = *(_QWORD *)(a3 + 8);
if ( a1[1] != v3 )
return (unsigned int)-4;
if ( v3 != a2[1] )
return (unsigned int)-4;
if ( !mbedtls_mpi_core_check_zero_ct(*a2) )
return (unsigned int)-4;
v5 = mbedtls_mpi_mod_raw_inv_prime_working_limbs(*(_QWORD *)(a3 + 8));
v6 = calloc(v5, 8uLL);
if ( !v6 )
return (unsigned int)-16;
v7 = *(_DWORD *)(a3 + 24);
if ( v7 == 2 )
{
v8 = func1(a1, a2, (_QWORD *)a3, (__int64)v6);
}
else if ( v7 == 3 )
{
v8 = func7(a1, a2, (__int64 *)a3, (__int64)v6);
}
else
{
v8 = -4;
}
mbedtls_platform_zeroize(v6, 8 * v5);
free(v6);
return v8;
}

original_code:
int mbedtls_mpi_mod_inv(mbedtls_mpi_mod_residue *X,
                        const mbedtls_mpi_mod_residue *A,
                        const mbedtls_mpi_mod_modulus *N)
{
    if (X->limbs != N->limbs || A->limbs != N->limbs) {
        return -0x0004;
    }
    if (mbedtls_mpi_core_check_zero_ct(A->p, A->limbs) == 0) {
        return -0x0004;
    }
    size_t working_limbs =
        mbedtls_mpi_mod_raw_inv_prime_working_limbs(N->limbs);
    mbedtls_mpi_uint *working_memory = calloc(working_limbs,
                                                      sizeof(mbedtls_mpi_uint));
    if (working_memory == ((void *)0)) {
        return -0x0010;
    }
    int ret = -0x006E;
    switch (N->int_rep) {
        case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
            ret = mbedtls_mpi_mod_inv_mont(X, A, N, working_memory);
            break;
        case MBEDTLS_MPI_MOD_REP_OPT_RED:
            ret = mbedtls_mpi_mod_inv_non_mont(X, A, N, working_memory);
            break;
        default:
            ret = -0x0004;
            break;
    }
    mbedtls_platform_zeroize(working_memory,
                             working_limbs * sizeof(mbedtls_mpi_uint));
    free(working_memory);
    return ret;
}

canonical_original_code:
int mbedtls_mpi_mod_inv(struct mbedtls_mpi_mod_residue *X, struct mbedtls_mpi_mod_residue *A, struct mbedtls_mpi_mod_modulus *N)
{
    if (X->limbs != N->limbs || A->limbs != N->limbs) {
        return -0x0004;
    }
    if (mbedtls_mpi_core_check_zero_ct(A->p, A->limbs) == 0) {
        return -0x0004;
    }
    unsigned long working_limbs = mbedtls_mpi_mod_raw_inv_prime_working_limbs(N->limbs);
    unsigned long *working_memory = calloc(working_limbs,
                                                      sizeof(mbedtls_mpi_uint));
    if (working_memory == ((void *)0)) {
        return -0x0010;
    }
    int ret = -0x006E;
    switch (N->int_rep) {
        case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
            ret = mbedtls_mpi_mod_inv_mont(X, A, N, working_memory);
            break;
        case MBEDTLS_MPI_MOD_REP_OPT_RED:
            ret = mbedtls_mpi_mod_inv_non_mont(X, A, N, working_memory);
            break;
        default:
            ret = -0x0004;
            break;
    }
    mbedtls_platform_zeroize(working_memory,
                             working_limbs * sizeof(mbedtls_mpi_uint));
    free(working_memory);
    return ret;
}


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_add(_QWORD *a1, _QWORD *a2, _QWORD *a3, __int64 a4)
{
__int64 v4; // rax

v4 = *(_QWORD *)(a4 + 8);
if ( a1[1] != v4 )
return 4294967292LL;
if ( v4 != a2[1] )
return 4294967292LL;
if ( v4 != a3[1] )
return 4294967292LL;
mbedtls_mpi_mod_raw_add(*a1, *a2, *a3);
return 0LL;
}

original_code:
int mbedtls_mpi_mod_add(mbedtls_mpi_mod_residue *X,
                        const mbedtls_mpi_mod_residue *A,
                        const mbedtls_mpi_mod_residue *B,
                        const mbedtls_mpi_mod_modulus *N)
{
    if (X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs) {
        return -0x0004;
    }
    mbedtls_mpi_mod_raw_add(X->p, A->p, B->p, N);
    return 0;
}

canonical_original_code:
int mbedtls_mpi_mod_add(struct mbedtls_mpi_mod_residue *X, struct mbedtls_mpi_mod_residue *A, struct mbedtls_mpi_mod_residue *B, struct mbedtls_mpi_mod_modulus *N)
{
    if (X->limbs != N->limbs || A->limbs != N->limbs || B->limbs != N->limbs) {
        return -0x0004;
    }
    mbedtls_mpi_mod_raw_add(X->p, A->p, B->p, N);
    return 0;
}


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

if ( a1[1] == *(_QWORD *)(a3 + 8) )
result = mbedtls_mpi_mod_raw_random(*a1);
else
result = 4294967292LL;
return result;
}

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

if ( a1[1] == *(_QWORD *)(a3 + 8) )
result = mbedtls_mpi_mod_raw_random(*a1);
else
result = 4294967292LL;
return result;
}

original_code:
int mbedtls_mpi_mod_random(mbedtls_mpi_mod_residue *X,
                           mbedtls_mpi_uint min,
                           const mbedtls_mpi_mod_modulus *N,
                           int (*f_rng)(void *, unsigned char *, size_t),
                           void *p_rng)
{
    if (X->limbs != N->limbs) {
        return -0x0004;
    }
    return mbedtls_mpi_mod_raw_random(X->p, min, N, f_rng, p_rng);
}

canonical_original_code:
int mbedtls_mpi_mod_random(struct mbedtls_mpi_mod_residue *X, unsigned long min, struct mbedtls_mpi_mod_modulus *N, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    if (X->limbs != N->limbs) {
        return -0x0004;
    }
    return mbedtls_mpi_mod_raw_random(X->p, min, N, f_rng, p_rng);
}

variable_types:
min
unsigned long

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


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_read(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v4; // rsi
__int64 result; // rax

v2 = a1[1];
if ( !v2 )
return 4294967292LL;
v4 = *(_QWORD *)(a2 + 8);
if ( v2 != v4 || !v4 )
return 4294967292LL;
result = mbedtls_mpi_mod_raw_read(*a1, a2);
if ( !(_DWORD)result )
{
a1[1] = *(_QWORD *)(a2 + 8);
result = mbedtls_mpi_mod_raw_canonical_to_modulus_rep(*a1, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v4; // rsi
__int64 result; // rax

v2 = a1[1];
if ( !v2 )
return 4294967292LL;
v4 = *(_QWORD *)(a2 + 8);
if ( v2 != v4 || !v4 )
return 4294967292LL;
result = mbedtls_mpi_mod_raw_read(*a1, a2);
if ( !(_DWORD)result )
{
a1[1] = *(_QWORD *)(a2 + 8);
result = mbedtls_mpi_mod_raw_canonical_to_modulus_rep(*a1, a2);
}
return result;
}

original_code:
int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r,
                         const mbedtls_mpi_mod_modulus *N,
                         const unsigned char *buf,
                         size_t buflen,
                         mbedtls_mpi_mod_ext_rep ext_rep)
{
    int ret = -0x0004;
    if (r->limbs == 0 || N->limbs == 0) {
        goto cleanup;
    }
    if (r->limbs != N->limbs) {
        goto cleanup;
    }
    ret = mbedtls_mpi_mod_raw_read(r->p, N, buf, buflen, ext_rep);
    if (ret != 0) {
        goto cleanup;
    }
    r->limbs = N->limbs;
    ret = mbedtls_mpi_mod_raw_canonical_to_modulus_rep(r->p, N);
cleanup:
    return ret;
}

canonical_original_code:
int mbedtls_mpi_mod_read(struct mbedtls_mpi_mod_residue *r, struct mbedtls_mpi_mod_modulus *N, unsigned char *buf, unsigned long buflen, enum mbedtls_mpi_mod_ext_rep ext_rep)
{
    int ret = -0x0004;
    if (r->limbs == 0 || N->limbs == 0) {
        goto cleanup;
    }
    if (r->limbs != N->limbs) {
        goto cleanup;
    }
    ret = mbedtls_mpi_mod_raw_read(r->p, N, buf, buflen, ext_rep);
    if (ret != 0) {
        goto cleanup;
    }
    r->limbs = N->limbs;
    ret = mbedtls_mpi_mod_raw_canonical_to_modulus_rep(r->p, N);
cleanup:
    return ret;
}

variable_types:
buf
unsigned char *

variable_types:
buflen
unsigned long

variable_types: enum mbedtls_mpi_mod_ext_rep { MBEDTLS_MPI_MOD_EXT_REP_INVALID=0, MBEDTLS_MPI_MOD_EXT_REP_LE=8, MBEDTLS_MPI_MOD_EXT_REP_BE=9 }


decompiled_code:
__int64 __fastcall mbedtls_mpi_mod_write(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 v5; // rax
__int64 v9; // rdx
unsigned int v10; // ebp
unsigned int v12; // eax

v5 = a1[1];
if ( !v5 )
return (unsigned int)-4;
v9 = *(_QWORD *)(a2 + 8);
if ( v5 != v9 || !v9 )
return (unsigned int)-4;
if ( *(_DWORD *)(a2 + 24) != 2 || (v10 = mbedtls_mpi_mod_raw_from_mont_rep(*a1)) == 0 )
{
v10 = mbedtls_mpi_mod_raw_write(*a1, a2, a3, a4, a5);
if ( *(_DWORD *)(a2 + 24) == 2 )
{
v12 = mbedtls_mpi_mod_raw_to_mont_rep(*a1, a2);
if ( !v10 )
v10 = v12;
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func14(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 v5; // rax
__int64 v9; // rdx
unsigned int v10; // ebp
unsigned int v12; // eax

v5 = a1[1];
if ( !v5 )
return (unsigned int)-4;
v9 = *(_QWORD *)(a2 + 8);
if ( v5 != v9 || !v9 )
return (unsigned int)-4;
if ( *(_DWORD *)(a2 + 24) != 2 || (v10 = mbedtls_mpi_mod_raw_from_mont_rep(*a1)) == 0 )
{
v10 = mbedtls_mpi_mod_raw_write(*a1, a2, a3, a4, a5);
if ( *(_DWORD *)(a2 + 24) == 2 )
{
v12 = mbedtls_mpi_mod_raw_to_mont_rep(*a1, a2);
if ( !v10 )
v10 = v12;
}
}
return v10;
}

original_code:
int mbedtls_mpi_mod_write(const mbedtls_mpi_mod_residue *r,
                          const mbedtls_mpi_mod_modulus *N,
                          unsigned char *buf,
                          size_t buflen,
                          mbedtls_mpi_mod_ext_rep ext_rep)
{
    int ret = -0x0004;
    if (r->limbs == 0 || N->limbs == 0) {
        goto cleanup;
    }
    if (r->limbs != N->limbs) {
        goto cleanup;
    }
    if (N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
        ret = mbedtls_mpi_mod_raw_from_mont_rep(r->p, N);
        if (ret != 0) {
            goto cleanup;
        }
    }
    ret = mbedtls_mpi_mod_raw_write(r->p, N, buf, buflen, ext_rep);
    if (N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
        int conv_ret = mbedtls_mpi_mod_raw_to_mont_rep(r->p, N);
        if (ret == 0) {
            ret = conv_ret;
        }
    }
cleanup:
    return ret;
}

canonical_original_code:
int mbedtls_mpi_mod_write(struct mbedtls_mpi_mod_residue *r, struct mbedtls_mpi_mod_modulus *N, unsigned char *buf, unsigned long buflen, enum mbedtls_mpi_mod_ext_rep ext_rep)
{
    int ret = -0x0004;
    if (r->limbs == 0 || N->limbs == 0) {
        goto cleanup;
    }
    if (r->limbs != N->limbs) {
        goto cleanup;
    }
    if (N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
        ret = mbedtls_mpi_mod_raw_from_mont_rep(r->p, N);
        if (ret != 0) {
            goto cleanup;
        }
    }
    ret = mbedtls_mpi_mod_raw_write(r->p, N, buf, buflen, ext_rep);
    if (N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
        int conv_ret = mbedtls_mpi_mod_raw_to_mont_rep(r->p, N);
        if (ret == 0) {
            ret = conv_ret;
        }
    }
cleanup:
    return ret;
}

user_defined_types: enum mbedtls_mpi_mod_ext_rep { MBEDTLS_MPI_MOD_EXT_REP_INVALID=0, MBEDTLS_MPI_MOD_EXT_REP_LE=8, MBEDTLS_MPI_MOD_EXT_REP_BE=9 }


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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

original_code:
static inline size_t mbedtls_cipher_info_get_key_bitlen(
    const mbedtls_cipher_info_t *info)
{
    if (info == ((void *)0)) {
        return 0;
    } else {
        return info->key_bitlen;
    }
}

canonical_original_code:
static inline unsigned long mbedtls_cipher_info_get_key_bitlen(struct mbedtls_cipher_info_t *info)
{
    if (info == ((void *)0)) {
        return 0;
    } else {
        return info->key_bitlen;
    }
}

variable_types: struct mbedtls_cipher_info_t { enum mbedtls_cipher_type_t { MBEDTLS_CIPHER_NONE=0, MBEDTLS_CIPHER_NULL=1, MBEDTLS_CIPHER_AES_128_ECB=2, MBEDTLS_CIPHER_AES_192_ECB=3, MBEDTLS_CIPHER_AES_256_ECB=4, MBEDTLS_CIPHER_AES_128_CBC=5, MBEDTLS_CIPHER_AES_192_CBC=6, MBEDTLS_CIPHER_AES_256_CBC=7, MBEDTLS_CIPHER_AES_128_CFB128=8, MBEDTLS_CIPHER_AES_192_CFB128=9, MBEDTLS_CIPHER_AES_256_CFB128=10, MBEDTLS_CIPHER_AES_128_CTR=11, MBEDTLS_CIPHER_AES_192_CTR=12, MBEDTLS_CIPHER_AES_256_CTR=13, MBEDTLS_CIPHER_AES_128_GCM=14, MBEDTLS_CIPHER_AES_192_GCM=15, MBEDTLS_CIPHER_AES_256_GCM=16, MBEDTLS_CIPHER_CAMELLIA_128_ECB=17, MBEDTLS_CIPHER_CAMELLIA_192_ECB=18, MBEDTLS_CIPHER_CAMELLIA_256_ECB=19, MBEDTLS_CIPHER_CAMELLIA_128_CBC=20, MBEDTLS_CIPHER_CAMELLIA_192_CBC=21, MBEDTLS_CIPHER_CAMELLIA_256_CBC=22, MBEDTLS_CIPHER_CAMELLIA_128_CFB128=23, MBEDTLS_CIPHER_CAMELLIA_192_CFB128=24, MBEDTLS_CIPHER_CAMELLIA_256_CFB128=25, MBEDTLS_CIPHER_CAMELLIA_128_CTR=26, MBEDTLS_CIPHER_CAMELLIA_192_CTR=27, MBEDTLS_CIPHER_CAMELLIA_256_CTR=28, MBEDTLS_CIPHER_CAMELLIA_128_GCM=29, MBEDTLS_CIPHER_CAMELLIA_192_GCM=30, MBEDTLS_CIPHER_CAMELLIA_256_GCM=31, MBEDTLS_CIPHER_DES_ECB=32, MBEDTLS_CIPHER_DES_CBC=33, MBEDTLS_CIPHER_DES_EDE_ECB=34, MBEDTLS_CIPHER_DES_EDE_CBC=35, MBEDTLS_CIPHER_DES_EDE3_ECB=36, MBEDTLS_CIPHER_DES_EDE3_CBC=37, MBEDTLS_CIPHER_AES_128_CCM=38, MBEDTLS_CIPHER_AES_192_CCM=39, MBEDTLS_CIPHER_AES_256_CCM=40, MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG=41, MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG=42, MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG=43, MBEDTLS_CIPHER_CAMELLIA_128_CCM=44, MBEDTLS_CIPHER_CAMELLIA_192_CCM=45, MBEDTLS_CIPHER_CAMELLIA_256_CCM=46, MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG=47, MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG=48, MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG=49, MBEDTLS_CIPHER_ARIA_128_ECB=50, MBEDTLS_CIPHER_ARIA_192_ECB=51, MBEDTLS_CIPHER_ARIA_256_ECB=52, MBEDTLS_CIPHER_ARIA_128_CBC=53, MBEDTLS_CIPHER_ARIA_192_CBC=54, MBEDTLS_CIPHER_ARIA_256_CBC=55, MBEDTLS_CIPHER_ARIA_128_CFB128=56, MBEDTLS_CIPHER_ARIA_192_CFB128=57, MBEDTLS_CIPHER_ARIA_256_CFB128=58, MBEDTLS_CIPHER_ARIA_128_CTR=59, MBEDTLS_CIPHER_ARIA_192_CTR=60, MBEDTLS_CIPHER_ARIA_256_CTR=61, MBEDTLS_CIPHER_ARIA_128_GCM=62, MBEDTLS_CIPHER_ARIA_192_GCM=63, MBEDTLS_CIPHER_ARIA_256_GCM=64, MBEDTLS_CIPHER_ARIA_128_CCM=65, MBEDTLS_CIPHER_ARIA_192_CCM=66, MBEDTLS_CIPHER_ARIA_256_CCM=67, MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG=68, MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG=69, MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG=70, MBEDTLS_CIPHER_AES_128_OFB=71, MBEDTLS_CIPHER_AES_192_OFB=72, MBEDTLS_CIPHER_AES_256_OFB=73, MBEDTLS_CIPHER_AES_128_XTS=74, MBEDTLS_CIPHER_AES_256_XTS=75, MBEDTLS_CIPHER_CHACHA20=76, MBEDTLS_CIPHER_CHACHA20_POLY1305=77, MBEDTLS_CIPHER_AES_128_KW=78, MBEDTLS_CIPHER_AES_192_KW=79, MBEDTLS_CIPHER_AES_256_KW=80, MBEDTLS_CIPHER_AES_128_KWP=81, MBEDTLS_CIPHER_AES_192_KWP=82, MBEDTLS_CIPHER_AES_256_KWP=83 } type; enum mbedtls_cipher_mode_t { MBEDTLS_MODE_NONE=0, MBEDTLS_MODE_ECB=1, MBEDTLS_MODE_CBC=2, MBEDTLS_MODE_CFB=3, MBEDTLS_MODE_OFB=4, MBEDTLS_MODE_CTR=5, MBEDTLS_MODE_GCM=6, MBEDTLS_MODE_STREAM=7, MBEDTLS_MODE_CCM=8, MBEDTLS_MODE_CCM_STAR_NO_TAG=9, MBEDTLS_MODE_XTS=10, MBEDTLS_MODE_CHACHAPOLY=11, MBEDTLS_MODE_KW=12, MBEDTLS_MODE_KWP=13 } mode; unsigned int key_bitlen; char *name; unsigned int iv_size; int flags; unsigned int block_size; struct mbedtls_cipher_base_t { enum mbedtls_cipher_id_t { MBEDTLS_CIPHER_ID_NONE=0, MBEDTLS_CIPHER_ID_NULL=1, MBEDTLS_CIPHER_ID_AES=2, MBEDTLS_CIPHER_ID_DES=3, MBEDTLS_CIPHER_ID_3DES=4, MBEDTLS_CIPHER_ID_CAMELLIA=5, MBEDTLS_CIPHER_ID_ARIA=6, MBEDTLS_CIPHER_ID_CHACHA20=7 } cipher; int (*ecb_func)(void *ctx, enum mbedtls_operation_t { MBEDTLS_OPERATION_NONE=-1, MBEDTLS_DECRYPT=0, MBEDTLS_ENCRYPT=1 } mode, unsigned char *input, unsigned char *output); int (*stream_func)(void *ctx, unsigned long length, unsigned char *input, unsigned char *output); int (*setkey_enc_func)(void *ctx, unsigned char *key, unsigned int key_bitlen); int (*setkey_dec_func)(void *ctx, unsigned char *key, unsigned int key_bitlen); void *(*ctx_alloc_func)(); void (*ctx_free_func)(void *ctx); } *base; } *

return_type: unsigned long

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

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


decompiled_code:
void *mbedtls_ssl_list_ciphersuites()
{
return &ciphersuite_preference;
}

canonical_decompiled_code:
void *func1()
{
return &ciphersuite_preference;
}

original_code:
const int *mbedtls_ssl_list_ciphersuites(void)
{
    return ciphersuite_preference;
}

canonical_original_code:
int *mbedtls_ssl_list_ciphersuites()
{
    return ciphersuite_preference;
}

return_type: int *


decompiled_code:
const char **__fastcall mbedtls_ssl_ciphersuite_from_string(char *s2)
{
const char **v1; // rbx

if ( !s2 )
return 0LL;
v1 = (const char **)&ciphersuite_definitions;
while ( strcmp(v1[1], s2) )
{
v1 += 3;
if ( !*(_DWORD *)v1 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
const char **__fastcall func2(char *s2)
{
const char **v1; // rbx

if ( !s2 )
return 0LL;
v1 = (const char **)&ciphersuite_definitions;
while ( strcmp(v1[1], s2) )
{
v1 += 3;
if ( !*(_DWORD *)v1 )
return 0LL;
}
return v1;
}

original_code:
const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_string(
    const char *ciphersuite_name)
{
    const mbedtls_ssl_ciphersuite_t *cur = ciphersuite_definitions;
    if (((void *)0) == ciphersuite_name) {
        return ((void *)0);
    }
    while (cur->id != 0) {
        if (0 == strcmp(cur->name, ciphersuite_name)) {
            return cur;
        }
        cur++;
    }
    return ((void *)0);
}

canonical_original_code:
struct mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_string(char *ciphersuite_name)
{
    struct mbedtls_ssl_ciphersuite_t *cur = ciphersuite_definitions;
    if (((void *)0) == ciphersuite_name) {
        return ((void *)0);
    }
    while (cur->id != 0) {
        if (0 == strcmp(cur->name, ciphersuite_name)) {
            return cur;
        }
        cur++;
    }
    return ((void *)0);
}

variable_types: struct mbedtls_ssl_ciphersuite_t { int id; char *name; unsigned char cipher; unsigned char mac; unsigned char key_exchange; unsigned char flags; unsigned short min_tls_version; unsigned short max_tls_version; } *


decompiled_code:
const char *__fastcall mbedtls_ssl_get_ciphersuite_name(int a1)
{
int *v1; // rax
const char *result; // rax

v1 = mbedtls_ssl_ciphersuite_from_id(a1);
if ( v1 )
result = (const char *)*((_QWORD *)v1 + 1);
else
result = "unknown";
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(int a1)
{
int *v1; // rax
const char *result; // rax

v1 = func3(a1);
if ( v1 )
result = (const char *)*((_QWORD *)v1 + 1);
else
result = "unknown";
return result;
}

original_code:
const char *mbedtls_ssl_get_ciphersuite_name(const int ciphersuite_id)
{
    const mbedtls_ssl_ciphersuite_t *cur;
    cur = mbedtls_ssl_ciphersuite_from_id(ciphersuite_id);
    if (cur == ((void *)0)) {
        return "unknown";
    }
    return cur->name;
}

canonical_original_code:
char *mbedtls_ssl_get_ciphersuite_name(int ciphersuite_id)
{
    struct mbedtls_ssl_ciphersuite_t *cur;
    cur = mbedtls_ssl_ciphersuite_from_id(ciphersuite_id);
    if (cur == ((void *)0)) {
        return "unknown";
    }
    return cur->name;
}

user_defined_types: struct mbedtls_ssl_ciphersuite_t { int id; char *name; unsigned char cipher; unsigned char mac; unsigned char key_exchange; unsigned char flags; unsigned short min_tls_version; unsigned short max_tls_version; }


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

v1 = mbedtls_ssl_ciphersuite_from_string(a1);
if ( v1 )
result = *(unsigned int *)v1;
else
result = 0LL;
return result;
}

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

v1 = func2(a1);
if ( v1 )
result = *(unsigned int *)v1;
else
result = 0LL;
return result;
}

original_code:
int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name)
{
    const mbedtls_ssl_ciphersuite_t *cur;
    cur = mbedtls_ssl_ciphersuite_from_string(ciphersuite_name);
    if (cur == ((void *)0)) {
        return 0;
    }
    return cur->id;
}

canonical_original_code:
int mbedtls_ssl_get_ciphersuite_id(char *ciphersuite_name)
{
    struct mbedtls_ssl_ciphersuite_t *cur;
    cur = mbedtls_ssl_ciphersuite_from_string(ciphersuite_name);
    if (cur == ((void *)0)) {
        return 0;
    }
    return cur->id;
}


decompiled_code:
__int64 __fastcall mbedtls_ssl_get_ciphersuite_sig_pk_alg(__int64 a1)
{
unsigned __int8 v1; // al

v1 = *(_BYTE *)(a1 + 18);
if ( v1 == 7 )
return 1LL;
if ( v1 > 7u )
return 2 * (unsigned int)((unsigned __int8)(v1 - 9) < 2u);
if ( v1 <= 3u )
return v1 != 0;
return 4 * (unsigned int)(v1 == 4);
}

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

v1 = *(_BYTE *)(a1 + 18);
if ( v1 == 7 )
return 1LL;
if ( v1 > 7u )
return 2 * (unsigned int)((unsigned __int8)(v1 - 9) < 2u);
if ( v1 <= 3u )
return v1 != 0;
return 4 * (unsigned int)(v1 == 4);
}

original_code:
mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_pk_alg(const mbedtls_ssl_ciphersuite_t *info)
{
    switch (info->key_exchange) {
        case MBEDTLS_KEY_EXCHANGE_RSA:
        case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_RSA_PSK:
            return MBEDTLS_PK_RSA;
        case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
            return MBEDTLS_PK_ECDSA;
        case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
            return MBEDTLS_PK_ECKEY;
        default:
            return MBEDTLS_PK_NONE;
    }
}

canonical_original_code:
enum mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_pk_alg(struct mbedtls_ssl_ciphersuite_t *info)
{
    switch (info->key_exchange) {
        case MBEDTLS_KEY_EXCHANGE_RSA:
        case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_RSA_PSK:
            return MBEDTLS_PK_RSA;
        case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
            return MBEDTLS_PK_ECDSA;
        case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
            return MBEDTLS_PK_ECKEY;
        default:
            return MBEDTLS_PK_NONE;
    }
}

return_type: enum mbedtls_pk_type_t { MBEDTLS_PK_NONE=0, MBEDTLS_PK_RSA=1, MBEDTLS_PK_ECKEY=2, MBEDTLS_PK_ECKEY_DH=3, MBEDTLS_PK_ECDSA=4, MBEDTLS_PK_RSA_ALT=5, MBEDTLS_PK_RSASSA_PSS=6, MBEDTLS_PK_OPAQUE=7 }


decompiled_code:
__int64 __fastcall mbedtls_ssl_get_ciphersuite_sig_alg(__int64 a1)
{
unsigned __int8 v1; // al
__int64 result; // rax

v1 = *(_BYTE *)(a1 + 18);
if ( v1 <= 3u )
result = v1 > 1u;
else
result = 4 * (unsigned int)(v1 == 4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned __int8 v1; // al
__int64 result; // rax

v1 = *(_BYTE *)(a1 + 18);
if ( v1 <= 3u )
result = v1 > 1u;
else
result = 4 * (unsigned int)(v1 == 4);
return result;
}

original_code:
mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_alg(const mbedtls_ssl_ciphersuite_t *info)
{
    switch (info->key_exchange) {
        case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
            return MBEDTLS_PK_RSA;
        case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
            return MBEDTLS_PK_ECDSA;
        default:
            return MBEDTLS_PK_NONE;
    }
}

canonical_original_code:
enum mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_alg(struct mbedtls_ssl_ciphersuite_t *info)
{
    switch (info->key_exchange) {
        case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
            return MBEDTLS_PK_RSA;
        case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
            return MBEDTLS_PK_ECDSA;
        default:
            return MBEDTLS_PK_NONE;
    }
}

user_defined_types: enum mbedtls_pk_type_t { MBEDTLS_PK_NONE=0, MBEDTLS_PK_RSA=1, MBEDTLS_PK_ECKEY=2, MBEDTLS_PK_ECKEY_DH=3, MBEDTLS_PK_ECDSA=4, MBEDTLS_PK_RSA_ALT=5, MBEDTLS_PK_RSASSA_PSS=6, MBEDTLS_PK_OPAQUE=7 }


decompiled_code:
_BOOL8 __fastcall mbedtls_ssl_ciphersuite_uses_ec(__int64 a1)
{
unsigned __int8 v1; // al
_BOOL8 result; // rax

v1 = *(_BYTE *)(a1 + 18);
if ( v1 > 4u )
result = (unsigned __int8)(v1 - 8) <= 3u;
else
result = v1 > 2u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
unsigned __int8 v1; // al
_BOOL8 result; // rax

v1 = *(_BYTE *)(a1 + 18);
if ( v1 > 4u )
result = (unsigned __int8)(v1 - 8) <= 3u;
else
result = v1 > 2u;
return result;
}

original_code:
int mbedtls_ssl_ciphersuite_uses_ec(const mbedtls_ssl_ciphersuite_t *info)
{
    switch (info->key_exchange) {
        case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
        case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
        case MBEDTLS_KEY_EXCHANGE_ECJPAKE:
            return 1;
        default:
            return 0;
    }
}

canonical_original_code:
int mbedtls_ssl_ciphersuite_uses_ec(struct mbedtls_ssl_ciphersuite_t *info)
{
    switch (info->key_exchange) {
        case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
        case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
        case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
        case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
        case MBEDTLS_KEY_EXCHANGE_ECJPAKE:
            return 1;
        default:
            return 0;
    }
}


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

for ( result = *(unsigned __int16 *)(a1 + 548);
(_WORD)result != *(_WORD *)(a1 + 546);
result = *(unsigned __int16 *)(a1 + 548) )
{
*(_WORD *)(a1 + 548) = result + 1;
free(*(void **)(a1 + 8 * (result & 0xF) + 416));
}
return result;
}

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

for ( result = *(unsigned __int16 *)(a1 + 548);
(_WORD)result != *(_WORD *)(a1 + 546);
result = *(unsigned __int16 *)(a1 + 548) )
{
*(_WORD *)(a1 + 548) = result + 1;
free(*(void **)(a1 + 8 * (result & 0xF) + 416));
}
return result;
}

original_code:
void
input_free(struct input *inp)
{
 while (inp->hist.tail != inp->hist.head)
  free(((inp)->hist.ptrs[(((inp->hist.tail++)) & (16 - 1))]));
}

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


original_code:
int
input_cursor_back(struct input *inp)
{
 if (inp->head == 0)
  return 0;
 inp->buf[--inp->tail] = inp->buf[--inp->head];
 return 1;
}

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


original_code:
int
input_cursor_forw(struct input *inp)
{
 if (inp->tail == 410)
  return 0;
 inp->buf[inp->head++] = inp->buf[inp->tail++];
 return 1;
}


original_code:
int
input_delete_back(struct input *inp)
{
 if (inp->head == 0)
  return 0;
 inp->head--;
 return 1;
}


original_code:
int
input_delete_forw(struct input *inp)
{
 if (inp->tail == 410)
  return 0;
 inp->tail++;
 return 1;
}


original_code:
int
input_insert(struct input *inp, const char *c, size_t count)
{
 if (input_text_isfull(inp))
  return 0;
 while (!input_text_isfull(inp) && count--) {
  if (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _IScntrl))
   inp->buf[inp->head++] = ' ';
  if (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISprint))
   inp->buf[inp->head++] = *c;
  c++;
 }
 return 1;
}

canonical_original_code:
int input_insert(struct input *inp, char *c, unsigned long count)
{
 if (input_text_isfull(inp))
  return 0;
 while (!input_text_isfull(inp) && count--) {
  if (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _IScntrl))
   inp->buf[inp->head++] = ' ';
  if (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISprint))
   inp->buf[inp->head++] = *c;
  c++;
 }
 return 1;
}

variable_types:
c
char *

variable_types:
count
unsigned long


decompiled_code:
__int64 __fastcall input_reset(_WORD *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

v1 = input_text_iszero((__int64)a1);
result = 0LL;
if ( !v1 )
{
a1[272] = a1[273];
a1[276] = 0;
a1[277] = 410;
a1[278] = 0;
result = 1LL;
}
return result;
}

original_code:
int
input_reset(struct input *inp)
{
 if (input_text_iszero(inp))
  return 0;
 inp->hist.current = inp->hist.head;
 inp->head = 0;
 inp->tail = 410;
 inp->window = 0;
 return 1;
}


original_code:
int
input_complete(struct input *inp, f_completion_cb cb)
{
 uint16_t head, tail, ret;
 if (input_text_iszero(inp))
  return 0;
 head = inp->head;
 tail = inp->tail;
 while (head && inp->buf[head - 1] != ' ')
  head--;
 if (inp->buf[head] == ' ')
  return 0;
 while (tail < 410 && inp->buf[tail] != ' ')
  tail++;
 ret = (*cb)(
  (inp->buf + head),
  (inp->head - head - inp->tail + tail),
  (410 - input_text_size(inp)),
  (head == 0));
 if (ret) {
  inp->head = head + ret;
  inp->tail = tail;
 }
 return (ret != 0);
}

canonical_original_code:
int input_complete(struct input *inp, unsigned short (*cb)(char *, unsigned short, unsigned short, int))
{
 unsigned short head; unsigned short tail; unsigned short ret;
 if (input_text_iszero(inp))
  return 0;
 head = inp->head;
 tail = inp->tail;
 while (head && inp->buf[head - 1] != ' ')
  head--;
 if (inp->buf[head] == ' ')
  return 0;
 while (tail < 410 && inp->buf[tail] != ' ')
  tail++;
 ret = (*cb)(
  (inp->buf + head),
  (inp->head - head - inp->tail + tail),
  (410 - input_text_size(inp)),
  (head == 0));
 if (ret) {
  inp->head = head + ret;
  inp->tail = tail;
 }
 return (ret != 0);
}

variable_types: unsigned short (*)(char *, unsigned short, unsigned short, int)

variable_types:
head
unsigned short

variable_types:
tail
unsigned short

variable_types:
ret
unsigned short


decompiled_code:
__int64 __fastcall input_hist_back(void *dest)
{
__int16 v1; // ax
unsigned int v2; // edx
__int16 v3; // ax
__int16 v4; // ax
const char *v5; // r12
size_t v6; // rax
__int16 v7; // bp

v1 = input_hist_size((__int64)dest);
v2 = 0;
if ( v1 )
{
v3 = *((_WORD *)dest + 272);
if ( v3 != *((_WORD *)dest + 274) )
{
v4 = v3 - 1;
*((_WORD *)dest + 272) = v4;
v5 = (const char *)*((_QWORD *)dest + (v4 & 0xF) + 52);
v6 = strlen(v5);
v7 = v6;
memcpy(dest, v5, v6);
*((_WORD *)dest + 276) = v7;
*((_WORD *)dest + 277) = 410;
v2 = 1;
}
}
return v2;
}

original_code:
int
input_hist_back(struct input *inp)
{
 size_t len;
 if (input_hist_size(inp) == 0 || inp->hist.current == inp->hist.tail)
  return 0;
 inp->hist.current--;
 len = strlen(((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]));
 memcpy(inp->buf, ((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]), len);
 inp->head = len;
 inp->tail = 410;
 return 1;
}

canonical_original_code:
int input_hist_back(struct input *inp)
{
 unsigned long len;
 if (input_hist_size(inp) == 0 || inp->hist.current == inp->hist.tail)
  return 0;
 inp->hist.current--;
 len = strlen(((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]));
 memcpy(inp->buf, ((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]), len);
 inp->head = len;
 inp->tail = 410;
 return 1;
}

variable_types:
len
unsigned long


original_code:
int
input_hist_forw(struct input *inp)
{
 size_t len;
 if (input_hist_size(inp) == 0 || inp->hist.current == inp->hist.head)
  return 0;
 inp->hist.current++;
 if (inp->hist.current == inp->hist.head) {
  len = 0;
 } else {
  len = strlen(((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]));
  memcpy(inp->buf, ((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]), len);
 }
 inp->head = len;
 inp->tail = 410;
 return 1;
}

canonical_original_code:
int input_hist_forw(struct input *inp)
{
 unsigned long len;
 if (input_hist_size(inp) == 0 || inp->hist.current == inp->hist.head)
  return 0;
 inp->hist.current++;
 if (inp->hist.current == inp->hist.head) {
  len = 0;
 } else {
  len = strlen(((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]));
  memcpy(inp->buf, ((inp)->hist.ptrs[(((inp->hist.current)) & (16 - 1))]), len);
 }
 inp->head = len;
 inp->tail = 410;
 return 1;
}


decompiled_code:
__int64 __fastcall input_write(__int64 a1, _BYTE *a2, int a3, unsigned __int16 a4)
{
_BYTE *v4; // r9
__int16 v6; // r8
_BYTE *v7; // rdx
unsigned int v8; // er10
__int64 result; // rax
unsigned __int16 i; // dx
unsigned __int16 v11; // si
unsigned __int16 v12; // cx

v4 = a2;
v6 = a3;
if ( (unsigned __int16)a3 <= 1u )
{
v8 = 0;
LABEL_12:
result = v8;
}
else
{
v7 = a2;
v8 = a3 - 1;
result = 0LL;
while ( *(_WORD *)(a1 + 552) > a4 )
{
result = (unsigned int)(result + 1);
*v7++ = *(_BYTE *)(a1 + a4);
if ( (_WORD)v8 == (_WORD)result )
goto LABEL_12;
++a4;
}
for ( i = *(_WORD *)(a1 + 554); (unsigned __int16)(v6 - result) > 1u && i <= 0x199u; v4[v12] = *(_BYTE *)(a1 + v11) )
{
v11 = i++;
v12 = result;
result = (unsigned int)(result + 1);
}
}
v4[(unsigned __int16)result] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _BYTE *a2, int a3, unsigned __int16 a4)
{
_BYTE *v4; // r9
__int16 v6; // r8
_BYTE *v7; // rdx
unsigned int v8; // er10
__int64 result; // rax
unsigned __int16 i; // dx
unsigned __int16 v11; // si
unsigned __int16 v12; // cx

v4 = a2;
v6 = a3;
if ( (unsigned __int16)a3 <= 1u )
{
v8 = 0;
LABEL_12:
result = v8;
}
else
{
v7 = a2;
v8 = a3 - 1;
result = 0LL;
while ( *(_WORD *)(a1 + 552) > a4 )
{
result = (unsigned int)(result + 1);
*v7++ = *(_BYTE *)(a1 + a4);
if ( (_WORD)v8 == (_WORD)result )
goto LABEL_12;
++a4;
}
for ( i = *(_WORD *)(a1 + 554); (unsigned __int16)(v6 - result) > 1u && i <= 0x199u; v4[v12] = *(_BYTE *)(a1 + v11) )
{
v11 = i++;
v12 = result;
result = (unsigned int)(result + 1);
}
}
v4[(unsigned __int16)result] = 0;
return result;
}

original_code:
uint16_t
input_write(struct input *inp, char *buf, uint16_t max, uint16_t pos)
{
 uint16_t buf_len = 0;
 while (max > 1 && pos < inp->head) {
  buf[buf_len++] = inp->buf[pos++];
  max--;
 }
 pos = inp->tail;
 while (max > 1 && pos < 410) {
  buf[buf_len++] = inp->buf[pos++];
  max--;
 }
 buf[buf_len] = 0;
 return buf_len;
}

canonical_original_code:
unsigned short input_write(struct input *inp, char *buf, unsigned short max, unsigned short pos)
{
 unsigned short buf_len = 0;
 while (max > 1 && pos < inp->head) {
  buf[buf_len++] = inp->buf[pos++];
  max--;
 }
 pos = inp->tail;
 while (max > 1 && pos < 410) {
  buf[buf_len++] = inp->buf[pos++];
  max--;
 }
 buf[buf_len] = 0;
 return buf_len;
}

variable_types:
buf
char *

variable_types:
max
unsigned short

variable_types:
pos
unsigned short

return_type: unsigned short


original_code:
int
input_hist_push(struct input *inp)
{
 char *hist;
 if ((hist = input_text_copy(inp)) == ((void *)0))
  return 0;
 if (input_hist_size(inp) == 16)
  free(((inp)->hist.ptrs[(((inp->hist.tail++)) & (16 - 1))]));
 ((inp)->hist.ptrs[(((inp->hist.head++)) & (16 - 1))]) = hist;
 return input_reset(inp);
}

variable_types:
hist
char *


original_code:
uint16_t
input_frame(struct input *inp, char *buf, uint16_t max)
{
 if (inp->window >= inp->head || (inp->window + (max - 1)) <= inp->head)
  inp->window = (((max - 1) * 2 / 3) >= inp->head) ? 0 : inp->head - ((max - 1) * 2 / 3);
 input_write(inp, buf, max, inp->window);
 return (inp->head - inp->window);
}

canonical_original_code:
unsigned short input_frame(struct input *inp, char *buf, unsigned short max)
{
 if (inp->window >= inp->head || (inp->window + (max - 1)) <= inp->head)
  inp->window = (((max - 1) * 2 / 3) >= inp->head) ? 0 : inp->head - ((max - 1) * 2 / 3);
 input_write(inp, buf, max, inp->window);
 return (inp->head - inp->window);
}


decompiled_code:
void __fastcall user_list_AVL_INIT(__int64 a1)
{
*(_DWORD *)a1 = 1;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code: static inline void user_list_AVL_INIT(struct user *elm) { (elm)->ul.height = 1; (elm)->ul.tree_right = (elm)->ul.tree_left = ((void *)0); }

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

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 user_list_AVL_GET_HEIGHT(unsigned int *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = *a1;
return result;
}

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

result = 0LL;
if ( a1 )
result = *a1;
return result;
}

original_code: static inline int user_list_AVL_GET_HEIGHT(struct user *elm) { return (elm == ((void *)0)) ? 0 : (elm)->ul.height; }

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


decompiled_code:
__int64 __fastcall user_list_AVL_BALANCE(__int64 a1)
{
int v1; // ebp

user_list_AVL_SET_HEIGHT(a1);
v1 = user_list_AVL_GET_HEIGHT(*(unsigned int **)(a1 + 8));
return (unsigned int)user_list_AVL_GET_HEIGHT(*(unsigned int **)(a1 + 16)) - v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebp

func2(a1);
v1 = func1(*(unsigned int **)(a1 + 8));
return (unsigned int)func1(*(unsigned int **)(a1 + 16)) - v1;
}

original_code: static inline int user_list_AVL_BALANCE(struct user *elm) { user_list_AVL_SET_HEIGHT(elm); int hL = user_list_AVL_GET_HEIGHT((elm)->ul.tree_left), hR = user_list_AVL_GET_HEIGHT((elm)->ul.tree_right); return (hR - hL); }

canonical_original_code: static inline int user_list_AVL_BALANCE(struct user *elm) { user_list_AVL_SET_HEIGHT(elm); int hL = user_list_AVL_GET_HEIGHT((elm)->ul.tree_left); int hR = user_list_AVL_GET_HEIGHT((elm)->ul.tree_right); return (hR - hL); }

variable_types: hL int

variable_types: hR int


decompiled_code:
__int64 __fastcall user_list_AVL_ROTATE_LEFT(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax

v1 = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(v1 + 8);
*(_QWORD *)(v1 + 8) = a1;
*(_QWORD *)(a1 + 16) = v2;
user_list_AVL_SET_HEIGHT(a1);
user_list_AVL_SET_HEIGHT(v1);
return v1;
}

original_code: static inline struct user* user_list_AVL_ROTATE_LEFT(struct user *n) { struct user *p = (n)->ul.tree_right; struct user *b = (p)->ul.tree_left; (p)->ul.tree_left = n; (n)->ul.tree_right = b; user_list_AVL_SET_HEIGHT(n); user_list_AVL_SET_HEIGHT(p); return p; }

canonical_original_code: static inline struct user *user_list_AVL_ROTATE_LEFT(struct user *n) { struct user *p = (n)->ul.tree_right; struct user *b = (p)->ul.tree_left; (p)->ul.tree_left = n; (n)->ul.tree_right = b; user_list_AVL_SET_HEIGHT(n); user_list_AVL_SET_HEIGHT(p); return p; }

variable_types:
n
struct user *

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


decompiled_code:
__int64 __fastcall user_list_AVL_ROTATE_RIGHT(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(v1 + 16);
*(_QWORD *)(v1 + 16) = a1;
*(_QWORD *)(a1 + 8) = v2;
user_list_AVL_SET_HEIGHT(a1);
user_list_AVL_SET_HEIGHT(v1);
return v1;
}

original_code: static inline struct user* user_list_AVL_ROTATE_RIGHT(struct user *n) { struct user *p = (n)->ul.tree_left; struct user *b = (p)->ul.tree_right; (p)->ul.tree_right = n; (n)->ul.tree_left = b; user_list_AVL_SET_HEIGHT(n); user_list_AVL_SET_HEIGHT(p); return p; }

canonical_original_code: static inline struct user *user_list_AVL_ROTATE_RIGHT(struct user *n) { struct user *p = (n)->ul.tree_left; struct user *b = (p)->ul.tree_right; (p)->ul.tree_right = n; (n)->ul.tree_left = b; user_list_AVL_SET_HEIGHT(n); user_list_AVL_SET_HEIGHT(p); return p; }


decompiled_code:
__int64 __fastcall user_cmp(__int64 a1, __int64 a2, unsigned int *a3)
{
return irc_strcmp(*a3, *(_QWORD *)(a1 + 24), *(_QWORD *)(a2 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned int *a3)
{
return irc_strcmp(*a3, *(_QWORD *)(a1 + 24), *(_QWORD *)(a2 + 24));
}

original_code:
static inline int
user_cmp(struct user *u1, struct user *u2, void *arg)
{
 return irc_strcmp(*(enum casemapping*)arg, u1->nick, u2->nick);
}

canonical_original_code:
static inline int user_cmp(struct user *u1, struct user *u2, void *arg)
{
 return irc_strcmp(*(enum casemapping *)arg, u1->nick, u2->nick);
}

variable_types:
arg
void *

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


decompiled_code:
__int64 __fastcall user_list_AVL_ADD_REC(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 result; // rax
int v5; // eax
int v6; // edx

result = a2;
if ( a1 )
{
v5 = user_cmp(a2, a1, a3);
if ( !v5 )
return 0LL;
if ( v5 > 0 )
{
result = user_list_AVL_ADD_REC(*(_QWORD *)(a1 + 16), a2, a3);
if ( !result )
return result;
*(_QWORD *)(a1 + 16) = result;
}
else
{
result = user_list_AVL_ADD_REC(*(_QWORD *)(a1 + 8), a2, a3);
if ( !result )
return result;
*(_QWORD *)(a1 + 8) = result;
}
v6 = user_list_AVL_BALANCE(a1);
if ( v6 > 1 )
{
if ( (int)user_cmp(a2, *(_QWORD *)(a1 + 16), a3) < 0 )
*(_QWORD *)(a1 + 16) = user_list_AVL_ROTATE_RIGHT(*(_QWORD *)(a1 + 16));
result = user_list_AVL_ROTATE_LEFT(a1);
}
else
{
result = a1;
if ( v6 < -1 )
{
if ( (int)user_cmp(a2, *(_QWORD *)(a1 + 8), a3) > 0 )
*(_QWORD *)(a1 + 8) = user_list_AVL_ROTATE_LEFT(*(_QWORD *)(a1 + 8));
result = user_list_AVL_ROTATE_RIGHT(a1);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned int *a3)
{
__int64 result; // rax
int v5; // eax
int v6; // edx

result = a2;
if ( a1 )
{
v5 = func8(a2, a1, a3);
if ( !v5 )
return 0LL;
if ( v5 > 0 )
{
result = func9(*(_QWORD *)(a1 + 16), a2, a3);
if ( !result )
return result;
*(_QWORD *)(a1 + 16) = result;
}
else
{
result = func9(*(_QWORD *)(a1 + 8), a2, a3);
if ( !result )
return result;
*(_QWORD *)(a1 + 8) = result;
}
v6 = func3(a1);
if ( v6 > 1 )
{
if ( (int)func8(a2, *(_QWORD *)(a1 + 16), a3) < 0 )
*(_QWORD *)(a1 + 16) = func5(*(_QWORD *)(a1 + 16));
result = func4(a1);
}
else
{
result = a1;
if ( v6 < -1 )
{
if ( (int)func8(a2, *(_QWORD *)(a1 + 8), a3) > 0 )
*(_QWORD *)(a1 + 8) = func4(*(_QWORD *)(a1 + 8));
result = func5(a1);
}
}
}
return result;
}

original_code: static struct user* user_list_AVL_ADD_REC(struct user *n, struct user *elm, void *arg) { int comp, balance; struct user *tmp; if (n == ((void *)0)) return elm; if ((comp = user_cmp(elm, n, arg)) == 0) { return ((void *)0); } else if (comp > 0) { if ((tmp = user_list_AVL_ADD_REC((n)->ul.tree_right, elm, arg)) == ((void *)0)) return ((void *)0); (n)->ul.tree_right = tmp; } else if (comp < 0) { if ((tmp = user_list_AVL_ADD_REC((n)->ul.tree_left, elm, arg)) == ((void *)0)) return ((void *)0); (n)->ul.tree_left = tmp; } balance = user_list_AVL_BALANCE(n); if (balance > 1) { if ((user_cmp(elm, (n)->ul.tree_right, arg)) < 0) (n)->ul.tree_right = user_list_AVL_ROTATE_RIGHT((n)->ul.tree_right); return user_list_AVL_ROTATE_LEFT(n); } if (balance < -1) { if ((user_cmp(elm, (n)->ul.tree_left, arg)) > 0) (n)->ul.tree_left = user_list_AVL_ROTATE_LEFT((n)->ul.tree_left); return user_list_AVL_ROTATE_RIGHT(n); } return n; }

canonical_original_code: static struct user *user_list_AVL_ADD_REC(struct user *n, struct user *elm, void *arg) { int comp; int balance; struct user *tmp; if (n == ((void *)0)) return elm; if ((comp = user_cmp(elm, n, arg)) == 0) { return ((void *)0); } else if (comp > 0) { if ((tmp = user_list_AVL_ADD_REC((n)->ul.tree_right, elm, arg)) == ((void *)0)) return ((void *)0); (n)->ul.tree_right = tmp; } else if (comp < 0) { if ((tmp = user_list_AVL_ADD_REC((n)->ul.tree_left, elm, arg)) == ((void *)0)) return ((void *)0); (n)->ul.tree_left = tmp; } balance = user_list_AVL_BALANCE(n); if (balance > 1) { if ((user_cmp(elm, (n)->ul.tree_right, arg)) < 0) (n)->ul.tree_right = user_list_AVL_ROTATE_RIGHT((n)->ul.tree_right); return user_list_AVL_ROTATE_LEFT(n); } if (balance < -1) { if ((user_cmp(elm, (n)->ul.tree_left, arg)) > 0) (n)->ul.tree_left = user_list_AVL_ROTATE_LEFT((n)->ul.tree_left); return user_list_AVL_ROTATE_RIGHT(n); } return n; }

variable_types:
elm
struct user *

variable_types: comp int

variable_types: balance int


original_code: static struct user* user_list_AVL_DEL_REC(struct user **p, struct user *elm, void *arg) { int comp, balance; struct user *n = *p; struct user *ret = ((void *)0); if (n == ((void *)0)) return ((void *)0); if ((comp = user_cmp(elm, n, arg)) == 0) { ret = n; if ((n)->ul.tree_left && (n)->ul.tree_right) { struct user *swap = (n)->ul.tree_right, *swap_p = (n)->ul.tree_right; while ((swap)->ul.tree_left) { swap_p = swap; swap = (swap)->ul.tree_left; } if (swap_p == swap) { (swap)->ul.tree_left = (n)->ul.tree_left; } else { struct user *swap_l = (swap)->ul.tree_left, *swap_r = (swap)->ul.tree_right; (swap)->ul.tree_left = (n)->ul.tree_left; (swap)->ul.tree_right = (n)->ul.tree_right; (n)->ul.tree_left = swap_l; (n)->ul.tree_right = swap_r; (swap_p)->ul.tree_left = n; user_list_AVL_DEL_REC(&(swap)->ul.tree_right, elm, arg); } *p = n = swap; } else if ((n)->ul.tree_left) { *p = (n)->ul.tree_left; } else if ((n)->ul.tree_right) { *p = (n)->ul.tree_right; } else { *p = ((void *)0); } } else if (comp < 0) { ret = user_list_AVL_DEL_REC(&(n)->ul.tree_left, elm, arg); } else if (comp > 0) { ret = user_list_AVL_DEL_REC(&(n)->ul.tree_right, elm, arg); } if (ret == ((void *)0)) return ((void *)0); balance = user_list_AVL_BALANCE(n); if (balance > 1) { int hrl = user_list_AVL_GET_HEIGHT(((n)->ul.tree_right)->ul.tree_left), hrr = user_list_AVL_GET_HEIGHT(((n)->ul.tree_right)->ul.tree_right); if ((hrl - hrr) > 0) { (n)->ul.tree_right = user_list_AVL_ROTATE_RIGHT((n)->ul.tree_right); } *p = user_list_AVL_ROTATE_LEFT(n); } if (balance < -1) { int hll = user_list_AVL_GET_HEIGHT(((n)->ul.tree_left)->ul.tree_left), hlr = user_list_AVL_GET_HEIGHT(((n)->ul.tree_left)->ul.tree_right); if ((hll - hlr) < 0) { (n)->ul.tree_left = user_list_AVL_ROTATE_LEFT((n)->ul.tree_left); } *p = user_list_AVL_ROTATE_RIGHT(n); } return ret; }

canonical_original_code: static struct user *user_list_AVL_DEL_REC(struct user **p, struct user *elm, void *arg) { int comp; int balance; struct user *n = *p; struct user *ret = ((void *)0); if (n == ((void *)0)) return ((void *)0); if ((comp = user_cmp(elm, n, arg)) == 0) { ret = n; if ((n)->ul.tree_left && (n)->ul.tree_right) { struct user *swap = (n)->ul.tree_right; struct user *swap_p = (n)->ul.tree_right; while ((swap)->ul.tree_left) { swap_p = swap; swap = (swap)->ul.tree_left; } if (swap_p == swap) { (swap)->ul.tree_left = (n)->ul.tree_left; } else { struct user *swap_l = (swap)->ul.tree_left; struct user *swap_r = (swap)->ul.tree_right; (swap)->ul.tree_left = (n)->ul.tree_left; (swap)->ul.tree_right = (n)->ul.tree_right; (n)->ul.tree_left = swap_l; (n)->ul.tree_right = swap_r; (swap_p)->ul.tree_left = n; user_list_AVL_DEL_REC(&(swap)->ul.tree_right, elm, arg); } *p = n = swap; } else if ((n)->ul.tree_left) { *p = (n)->ul.tree_left; } else if ((n)->ul.tree_right) { *p = (n)->ul.tree_right; } else { *p = ((void *)0); } } else if (comp < 0) { ret = user_list_AVL_DEL_REC(&(n)->ul.tree_left, elm, arg); } else if (comp > 0) { ret = user_list_AVL_DEL_REC(&(n)->ul.tree_right, elm, arg); } if (ret == ((void *)0)) return ((void *)0); balance = user_list_AVL_BALANCE(n); if (balance > 1) { int hrl = user_list_AVL_GET_HEIGHT(((n)->ul.tree_right)->ul.tree_left); int hrr = user_list_AVL_GET_HEIGHT(((n)->ul.tree_right)->ul.tree_right); if ((hrl - hrr) > 0) { (n)->ul.tree_right = user_list_AVL_ROTATE_RIGHT((n)->ul.tree_right); } *p = user_list_AVL_ROTATE_LEFT(n); } if (balance < -1) { int hll = user_list_AVL_GET_HEIGHT(((n)->ul.tree_left)->ul.tree_left); int hlr = user_list_AVL_GET_HEIGHT(((n)->ul.tree_left)->ul.tree_right); if ((hll - hlr) < 0) { (n)->ul.tree_left = user_list_AVL_ROTATE_LEFT((n)->ul.tree_left); } *p = user_list_AVL_ROTATE_RIGHT(n); } return ret; }

variable_types:
p
struct user **

variable_types: hrl int

variable_types: hrr int

variable_types: hll int

variable_types: hlr int


decompiled_code:
void __fastcall user_free(void *a1)
{
free(a1);
}

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

original_code:
static inline void
user_free(struct user *u)
{
 free(u);
}


decompiled_code:
__int64 __fastcall user_ncmp(__int64 a1, __int64 a2, unsigned int *a3)
{
return irc_strncmp(*a3, *(_QWORD *)(a1 + 24), *(_QWORD *)(a2 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, unsigned int *a3)
{
return irc_strncmp(*a3, *(_QWORD *)(a1 + 24), *(_QWORD *)(a2 + 24));
}

original_code:
static inline int
user_ncmp(struct user *u1, struct user *u2, void *arg, size_t n)
{
 return irc_strncmp(*(enum casemapping*)arg, u1->nick, u2->nick, n);
}

canonical_original_code:
static inline int user_ncmp(struct user *u1, struct user *u2, void *arg, unsigned long n)
{
 return irc_strncmp(*(enum casemapping *)arg, u1->nick, u2->nick, n);
}

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall user_list_get(__int64 *a1, unsigned int a2, __int64 a3, __int64 a4)
{
unsigned int v5; // [rsp+Ch] [rbp-4Ch] BYREF
__int64 v6[9]; // [rsp+10h] [rbp-48h] BYREF

v5 = a2;
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v6[6] = 0LL;
v6[3] = a3;
return user_list_AVL_GET(a1, (__int64)v6, &v5, a4);
}

original_code:
struct user*
user_list_get(struct user_list *ul, enum casemapping cm, const char *nick, size_t prefix_len)
{
 struct user u = { .nick = nick };
 return user_list_AVL_GET(ul, &u, &cm, prefix_len);
}

canonical_original_code:
struct user *user_list_get(struct user_list *ul, enum casemapping cm, char *nick, unsigned long prefix_len)
{
 struct user u = { .nick = nick };
 return user_list_AVL_GET(ul, &u, &cm, prefix_len);
}

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

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

variable_types:
nick
char *

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


decompiled_code:
__int64 __fastcall user_list_add(__int64 a1, unsigned int a2, void *a3, __int64 a4, int a5)
{
_QWORD *v6; // rax
unsigned int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v10[0] = a2;
if ( user_list_get((__int64 *)a1, a2, (__int64)a3, 0LL) )
return 4294967294LL;
v6 = user(a3, a4, a5);
user_list_AVL_ADD((__int64 *)a1, (__int64)v6, v10);
++*(_DWORD *)(a1 + 8);
return 0LL;
}

original_code:
enum user_err
user_list_add(struct user_list *ul, enum casemapping cm, const char *nick, struct mode prfxmodes)
{
 if (user_list_get(ul, cm, nick, 0) != ((void *)0))
  return USER_ERR_DUPLICATE;
 user_list_AVL_ADD(ul, user(nick, prfxmodes), &cm);
 ul->count++;
 return USER_ERR_NONE;
}

canonical_original_code:
enum user_err user_list_add(struct user_list *ul, enum casemapping cm, char *nick, struct mode prfxmodes)
{
 if (user_list_get(ul, cm, nick, 0) != ((void *)0))
  return USER_ERR_DUPLICATE;
 user_list_AVL_ADD(ul, user(nick, prfxmodes), &cm);
 ul->count++;
 return USER_ERR_NONE;
}

variable_types: 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 { char prefix; unsigned int lower; unsigned int upper; } prfxmodes; char _[]; } *tree_root; unsigned int count; } *

variable_types:
prfxmodes
struct mode

return_type: enum user_err { USER_ERR_DUPLICATE=-2, USER_ERR_NOT_FOUND=-1, USER_ERR_NONE=0 }

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


decompiled_code:
__int64 __fastcall user_list_del(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // rax
void *v4; // rbp
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = a2;
v3 = user_list_get((__int64 *)a1, a2, a3, 0LL);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = (void *)v3;
user_list_AVL_DEL((__int64 *)a1, v3, v6);
--*(_DWORD *)(a1 + 8);
user_free(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // rax
void *v4; // rbp
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = a2;
v3 = func16((__int64 *)a1, a2, a3, 0LL);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = (void *)v3;
func12((__int64 *)a1, v3, v6);
--*(_DWORD *)(a1 + 8);
func13(v4);
return 0LL;
}

original_code:
enum user_err
user_list_del(struct user_list *ul, enum casemapping cm, const char *nick)
{
 struct user *u;
 if ((u = user_list_get(ul, cm, nick, 0)) == ((void *)0))
  return USER_ERR_NOT_FOUND;
 user_list_AVL_DEL(ul, u, &cm);
 ul->count--;
 user_free(u);
 return USER_ERR_NONE;
}

canonical_original_code:
enum user_err user_list_del(struct user_list *ul, enum casemapping cm, char *nick)
{
 struct user *u;
 if ((u = user_list_get(ul, cm, nick, 0)) == ((void *)0))
  return USER_ERR_NOT_FOUND;
 user_list_AVL_DEL(ul, u, &cm);
 ul->count--;
 user_free(u);
 return USER_ERR_NONE;
}

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

user_defined_types: enum user_err { USER_ERR_DUPLICATE=-2, USER_ERR_NOT_FOUND=-1, USER_ERR_NONE=0 }


decompiled_code:
__int64 __fastcall user_list_rpl(__int64 *a1, unsigned int a2, __int64 a3, void *a4)
{
__int64 v5; // rbx
__int64 v6; // rax
_QWORD *v7; // r12
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v9[0] = a2;
v5 = user_list_get(a1, a2, a3, 0LL);
v6 = user_list_get(a1, a2, (__int64)a4, 0LL);
if ( !v5 )
return 0xFFFFFFFFLL;
if ( v6 && (unsigned int)irc_strcmp(v9[0], *(_QWORD *)(v5 + 24), *(_QWORD *)(v6 + 24)) )
return 4294967294LL;
v7 = user(a4, *(_QWORD *)(v5 + 40), *(_DWORD *)(v5 + 48));
user_list_AVL_DEL(a1, v5, v9);
user_list_AVL_ADD(a1, (__int64)v7, v9);
user_free((void *)v5);
return 0LL;
}

original_code:
enum user_err
user_list_rpl(struct user_list *ul, enum casemapping cm, const char *nick_old, const char *nick_new)
{
 struct user *old, *new;
 old = user_list_get(ul, cm, nick_old, 0);
 new = user_list_get(ul, cm, nick_new, 0);
 if (old == ((void *)0))
  return USER_ERR_NOT_FOUND;
 if (new != ((void *)0) && irc_strcmp(cm, old->nick, new->nick))
  return USER_ERR_DUPLICATE;
 new = user(nick_new, old->prfxmodes);
 user_list_AVL_DEL(ul, old, &cm);
 user_list_AVL_ADD(ul, new, &cm);
 user_free(old);
 return USER_ERR_NONE;
}

canonical_original_code:
enum user_err user_list_rpl(struct user_list *ul, enum casemapping cm, char *nick_old, char *nick_new)
{
 struct user *old; struct user *new;
 old = user_list_get(ul, cm, nick_old, 0);
 new = user_list_get(ul, cm, nick_new, 0);
 if (old == ((void *)0))
  return USER_ERR_NOT_FOUND;
 if (new != ((void *)0) && irc_strcmp(cm, old->nick, new->nick))
  return USER_ERR_DUPLICATE;
 new = user(nick_new, old->prfxmodes);
 user_list_AVL_DEL(ul, old, &cm);
 user_list_AVL_ADD(ul, new, &cm);
 user_free(old);
 return USER_ERR_NONE;
}


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

result = user_list_AVL_FOREACH(a1, (__int64 (__fastcall *)(__int64))user_free);
*a1 = 0LL;
a1[1] = 0LL;
return result;
}

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

result = func7(a1, (__int64 (__fastcall *)(__int64))user_free);
*a1 = 0LL;
a1[1] = 0LL;
return result;
}

original_code:
void
user_list_free(struct user_list *ul)
{
 user_list_AVL_FOREACH(ul, user_free);
 memset(ul, 0, sizeof(*ul));
}


buffer

decompiled_code:
void *__fastcall buffer(void *a1)
{
return memset(a1, 0, 0xA6028uLL);
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
return memset(a1, 0, 0xA6028uLL);
}

original_code:
void
buffer(struct buffer *b)
{
 memset(b, 0, sizeof(*b));
}

variable_types: 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; } *

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 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 buffer_size(_DWORD *a1)
{
return (unsigned int)(*a1 - a1[1]);
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
return (unsigned int)(*a1 - a1[1]);
}

original_code:
unsigned
buffer_size(struct buffer *b)
{
 return b->head - b->tail;
}

canonical_original_code:
unsigned int buffer_size(struct buffer *b)
{
 return b->head - b->tail;
}

return_type: unsigned int

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:
__int64 __fastcall buffer_head(_DWORD *a1)
{
int v1; // edx
__int64 result; // rax

v1 = buffer_size(a1);
result = 0LL;
if ( v1 )
result = (__int64)&a1[166 * (((unsigned __int16)*a1 - 1) & 0x3FF) + 6];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
int v1; // edx
__int64 result; // rax

v1 = func1(a1);
result = 0LL;
if ( v1 )
result = (__int64)&a1[166 * (((unsigned __int16)*a1 - 1) & 0x3FF) + 6];
return result;
}

original_code:
struct buffer_line*
buffer_head(struct buffer *b)
{
 return buffer_size(b) == 0 ? ((void *)0) : &b->buffer_lines[((b->head - 1) & ((1 << 10) - 1))];
}

canonical_original_code:
struct buffer_line *buffer_head(struct buffer *b)
{
 return buffer_size(b) == 0 ? ((void *)0) : &b->buffer_lines[((b->head - 1) & ((1 << 10) - 1))];
}

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

return_type: 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; } *


decompiled_code:
__int64 __fastcall buffer_tail(_DWORD *a1)
{
int v1; // edx
__int64 result; // rax

v1 = buffer_size(a1);
result = 0LL;
if ( v1 )
result = (__int64)&a1[166 * (a1[1] & 0x3FF) + 6];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
int v1; // edx
__int64 result; // rax

v1 = func1(a1);
result = 0LL;
if ( v1 )
result = (__int64)&a1[166 * (a1[1] & 0x3FF) + 6];
return result;
}

original_code:
struct buffer_line*
buffer_tail(struct buffer *b)
{
 return buffer_size(b) == 0 ? ((void *)0) : &b->buffer_lines[((b->tail) & ((1 << 10) - 1))];
}

canonical_original_code:
struct buffer_line *buffer_tail(struct buffer *b)
{
 return buffer_size(b) == 0 ? ((void *)0) : &b->buffer_lines[((b->tail) & ((1 << 10) - 1))];
}


decompiled_code:
__int64 __fastcall buffer_line(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // edx
unsigned int v5; // ecx

if ( (unsigned int)buffer_size(a1) )
{
v2 = *a1;
v3 = a1[1];
if ( *a1 <= v3 )
{
v5 = a2;
if ( v2 >= a2 )
v5 = *a1;
if ( v3 <= v5 || v2 > a2 )
return (__int64)&a1[166 * (a2 & 0x3FF) + 6];
}
else if ( v2 > a2 && v3 <= a2 )
{
return (__int64)&a1[166 * (a2 & 0x3FF) + 6];
}
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/buffer.c", 58LL, "buffer_line");
fprintf(stderr, "invalid index: %d", a2);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // edx
unsigned int v5; // ecx

if ( (unsigned int)func1(a1) )
{
v2 = *a1;
v3 = a1[1];
if ( *a1 <= v3 )
{
v5 = a2;
if ( v2 >= a2 )
v5 = *a1;
if ( v3 <= v5 || v2 > a2 )
return (__int64)&a1[166 * (a2 & 0x3FF) + 6];
}
else if ( v2 > a2 && v3 <= a2 )
{
return (__int64)&a1[166 * (a2 & 0x3FF) + 6];
}
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/buffer.c", 58LL, "buffer_line");
fprintf(stderr, "invalid index: %d", a2);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
return 0LL;
}

original_code:
struct buffer_line*
buffer_line(struct buffer *b, unsigned i)
{
 if (buffer_size(b) == 0)
  return ((void *)0);
 if (((b->head > b->tail) && (i < b->tail || i >= b->head)) ||
     ((b->tail > b->head) && (i < b->tail && i >= b->head)))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/buffer.c", 58, __func__); fprintf(stderr, "invalid index: %d", i); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 return &b->buffer_lines[((i) & ((1 << 10) - 1))];
}

canonical_original_code:
struct buffer_line *buffer_line(struct buffer *b, unsigned int i)
{
 if (buffer_size(b) == 0)
  return ((void *)0);
 if (((b->head > b->tail) && (i < b->tail || i >= b->head)) ||
     ((b->tail > b->head) && (i < b->tail && i >= b->head)))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/buffer.c", 58, __func__); fprintf(stderr, "invalid index: %d", i); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 return &b->buffer_lines[((i) & ((1 << 10) - 1))];
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall buffer_push(unsigned int *a1)
{
__int64 v1; // rbp
unsigned int v2; // eax
unsigned int v4; // edx
unsigned int v5; // eax

v1 = buffer_line(a1, a1[2]);
if ( v1 == buffer_head(a1) )
a1[2] = *a1;
if ( (unsigned int)buffer_size(a1) == 1024 )
{
v4 = a1[2];
v5 = a1[1];
if ( v4 == v5 )
a1[2] = v4 + 1;
a1[1] = v5 + 1;
}
v2 = (*a1)++;
return (__int64)&a1[166 * (v2 & 0x3FF) + 6];
}

original_code:
static struct buffer_line*
buffer_push(struct buffer *b)
{
 if (buffer_line(b, b->scrollback) == buffer_head(b))
  b->scrollback = b->head;
 if (buffer_size(b) == (1 << 10)) {
  if (b->scrollback == b->tail)
   b->scrollback++;
  b->tail++;
 }
 return &(b->buffer_lines[((b->head++) & ((1 << 10) - 1))]);
}

canonical_original_code:
static struct buffer_line *buffer_push(struct buffer *b)
{
 if (buffer_line(b, b->scrollback) == buffer_head(b))
  b->scrollback = b->head;
 if (buffer_size(b) == (1 << 10)) {
  if (b->scrollback == b->tail)
   b->scrollback++;
  b->tail++;
 }
 return &(b->buffer_lines[((b->head++) & ((1 << 10) - 1))]);
}