decompiled_code:
unsigned __int64 __fastcall buffer_newline(__int64 a1, int a2, char *a3, const void *a4, __int64 a5, unsigned __int64 a6, char a7)
{
__int64 v10; // rbx
_BOOL8 v11; // rax
__int64 v12; // r8
_QWORD *v13; // rax
unsigned __int64 result; // rax

if ( !a3 )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/buffer.c", 76LL, "buffer_newline");
fwrite("from string is NULL", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
if ( !a4 )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/buffer.c", 79LL, "buffer_newline");
fwrite("text string is NULL", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
v10 = buffer_push((unsigned int *)a1);
*(_QWORD *)v10 = 0LL;
*(_QWORD *)(v10 + 656) = 0LL;
memset(
(void *)((v10 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v10 - (((_DWORD)v10 + 8) & 0xFFFFFFF8) + 664) >> 3));
v11 = a7 != 0;
v12 = v11 + a5;
if ( (unsigned __int64)(v11 + a5) > 0x64 )
v12 = 100LL;
*(_QWORD *)(v10 + 624) = v12;
if ( a6 > 0x1FE )
a6 = 510LL;
*(_QWORD *)(v10 + 632) = a6;
if ( a7 )
*(_BYTE *)(v10 + 5) = a7;
v13 = (_QWORD *)(v10 + v11 + 5);
if ( (unsigned int)v12 >= 8 )
{
*v13 = *(_QWORD *)a3;
*(_QWORD *)((char *)v13 + (unsigned int)v12 - 8) = *(_QWORD *)&a3[(unsigned int)v12 - 8];
qmemcpy(
(void *)((unsigned __int64)(v13 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v13 - ((unsigned __int64)(v13 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v12 + (_DWORD)v13 - (((_DWORD)v13 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v12 & 4) != 0 )
{
*(_DWORD *)v13 = *(_DWORD *)a3;
*(_DWORD *)((char *)v13 + (unsigned int)v12 - 4) = *(_DWORD *)&a3[(unsigned int)v12 - 4];
}
else if ( (_DWORD)v12 )
{
*(_BYTE *)v13 = *a3;
if ( (v12 & 2) != 0 )
*(_WORD *)((char *)v13 + (unsigned int)v12 - 2) = *(_WORD *)&a3[(unsigned int)v12 - 2];
}
memcpy((void *)(v10 + 106), a4, *(_QWORD *)(v10 + 632));
*(_BYTE *)(v10 + *(_QWORD *)(v10 + 624) + 5) = 0;
*(_BYTE *)(v10 + *(_QWORD *)(v10 + 632) + 106) = 0;
*(_QWORD *)(v10 + 640) = time(0LL);
*(_DWORD *)v10 = a2;
result = *(_QWORD *)(v10 + 624);
if ( result > *(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, int a2, char *a3, const void *a4, __int64 a5, unsigned __int64 a6, char a7)
{
__int64 v10; // rbx
_BOOL8 v11; // rax
__int64 v12; // r8
_QWORD *v13; // rax
unsigned __int64 result; // rax

if ( !a3 )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/buffer.c", 76LL, "buffer_newline");
fwrite("from string is NULL", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
if ( !a4 )
{
fprintf(stderr, "%s%s:%d:%s ", "FATAL ", "src/components/buffer.c", 79LL, "buffer_newline");
fwrite("text string is NULL", 1uLL, 0x13uLL, stderr);
fputc(10, stderr);
fflush(stderr);
exit(1);
}
v10 = func5((unsigned int *)a1);
*(_QWORD *)v10 = 0LL;
*(_QWORD *)(v10 + 656) = 0LL;
memset(
(void *)((v10 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v10 - (((_DWORD)v10 + 8) & 0xFFFFFFF8) + 664) >> 3));
v11 = a7 != 0;
v12 = v11 + a5;
if ( (unsigned __int64)(v11 + a5) > 0x64 )
v12 = 100LL;
*(_QWORD *)(v10 + 624) = v12;
if ( a6 > 0x1FE )
a6 = 510LL;
*(_QWORD *)(v10 + 632) = a6;
if ( a7 )
*(_BYTE *)(v10 + 5) = a7;
v13 = (_QWORD *)(v10 + v11 + 5);
if ( (unsigned int)v12 >= 8 )
{
*v13 = *(_QWORD *)a3;
*(_QWORD *)((char *)v13 + (unsigned int)v12 - 8) = *(_QWORD *)&a3[(unsigned int)v12 - 8];
qmemcpy(
(void *)((unsigned __int64)(v13 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v13 - ((unsigned __int64)(v13 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v12 + (_DWORD)v13 - (((_DWORD)v13 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v12 & 4) != 0 )
{
*(_DWORD *)v13 = *(_DWORD *)a3;
*(_DWORD *)((char *)v13 + (unsigned int)v12 - 4) = *(_DWORD *)&a3[(unsigned int)v12 - 4];
}
else if ( (_DWORD)v12 )
{
*(_BYTE *)v13 = *a3;
if ( (v12 & 2) != 0 )
*(_WORD *)((char *)v13 + (unsigned int)v12 - 2) = *(_WORD *)&a3[(unsigned int)v12 - 2];
}
memcpy((void *)(v10 + 106), a4, *(_QWORD *)(v10 + 632));
*(_BYTE *)(v10 + *(_QWORD *)(v10 + 624) + 5) = 0;
*(_BYTE *)(v10 + *(_QWORD *)(v10 + 632) + 106) = 0;
*(_QWORD *)(v10 + 640) = time(0LL);
*(_DWORD *)v10 = a2;
result = *(_QWORD *)(v10 + 624);
if ( result > *(_QWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void
buffer_newline(
  struct buffer *b,
  enum buffer_line_type type,
  const char *from_str,
  const char *text_str,
  size_t from_len,
  size_t text_len,
  char prefix)
{
 struct buffer_line *line;
 if (from_str == ((void *)0))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/buffer.c", 76, __func__); fprintf(stderr, "from string is NULL"); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 if (text_str == ((void *)0))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/buffer.c", 79, __func__); fprintf(stderr, "text string is NULL"); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 line = memset(buffer_push(b), 0, sizeof(*line));
 line->from_len = ((from_len + (!!prefix)) > (100) ? (100) : (from_len + (!!prefix)));
 line->text_len = ((text_len) > (510) ? (510) : (text_len));
 if (prefix)
  *line->from = prefix;
 memcpy(line->from + (!!prefix), from_str, line->from_len);
 memcpy(line->text, text_str, line->text_len);
 *(line->from + line->from_len) = '\0';
 *(line->text + line->text_len) = '\0';
 line->time = time(((void *)0));
 line->type = type;
 if (line->from_len > b->pad)
  b->pad = line->from_len;
}

canonical_original_code:
void buffer_newline(struct buffer *b, enum buffer_line_type type, char *from_str, char *text_str, unsigned long from_len, unsigned long text_len, char prefix)
{
 struct buffer_line *line;
 if (from_str == ((void *)0))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/buffer.c", 76, __func__); fprintf(stderr, "from string is NULL"); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 if (text_str == ((void *)0))
  do { fprintf(stderr, "%s%s:%d:%s ", ("FATAL "), "src/components/buffer.c", 79, __func__); fprintf(stderr, "text string is NULL"); fprintf(stderr, "\n"); fflush(stderr);; exit(1); } while (0);
 line = memset(buffer_push(b), 0, sizeof(*line));
 line->from_len = ((from_len + (!!prefix)) > (100) ? (100) : (from_len + (!!prefix)));
 line->text_len = ((text_len) > (510) ? (510) : (text_len));
 if (prefix)
  *line->from = prefix;
 memcpy(line->from + (!!prefix), from_str, line->from_len);
 memcpy(line->text, text_str, line->text_len);
 *(line->from + line->from_len) = '\0';
 *(line->text + line->text_len) = '\0';
 line->time = time(((void *)0));
 line->type = type;
 if (line->from_len > b->pad)
  b->pad = line->from_len;
}

variable_types: prefix char

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


repo: rcr/rirc

decompiled_code:
__int64 __fastcall check_fd(int a1, int a2)
{
if ( a1 < 0 )
return 4294967227LL;
if ( a2 && a1 > 1023 )
return 4294967225LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
if ( a1 < 0 )
return 4294967227LL;
if ( a2 && a1 > 1023 )
return 4294967225LL;
return 0LL;
}

original_code:
static int check_fd(int fd, int for_select)
{
    if (fd < 0) {
        return -0x0045;
    }
    if (for_select && fd >= 1024) {
        return -0x0047;
    }
    return 0;
}

variable_types: fd int

return_type: int


decompiled_code:
__int64 net_prepare()
{
_sysv_signal(13, (__sighandler_t)((char *)check_fd + 1));
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
_sysv_signal(13, (__sighandler_t)((char *)check_fd + 1));
return 0LL;
}

original_code:
static int net_prepare(void)
{
    signal(13, ((__sighandler_t) 1));
    return 0;
}

canonical_original_code:
static int net_prepare()
{
    signal(13, ((void (*)(int)) 1));
    return 0;
}


decompiled_code:
__int64 __fastcall mbedtls_net_connect(int *a1, const char *a2, const char *a3, int a4)
{
unsigned int v6; // ebp
int v8; // eax
struct addrinfo *v9; // rbx
int v10; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

v6 = net_prepare();
if ( !v6 )
{
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( a4 == 1 )
{
req.ai_socktype = 2;
v8 = 17;
}
else
{
req.ai_socktype = 1;
v8 = 6;
}
req.ai_protocol = v8;
if ( getaddrinfo(a2, a3, &req, &pai) )
{
v6 = -82;
}
else
{
v9 = pai;
if ( pai )
{
while ( 1 )
{
v10 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*a1 = v10;
if ( v10 < 0 )
{
v6 = -66;
}
else
{
v6 = connect(v10, v9->ai_addr, v9->ai_addrlen);
if ( !v6 )
goto LABEL_12;
close(*a1);
v6 = -68;
}
v9 = v9->ai_next;
if ( !v9 )
goto LABEL_12;
}
}
v6 = -82;
LABEL_12:
freeaddrinfo(pai);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, const char *a2, const char *a3, int a4)
{
unsigned int v6; // ebp
int v8; // eax
struct addrinfo *v9; // rbx
int v10; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

v6 = func1();
if ( !v6 )
{
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( a4 == 1 )
{
req.ai_socktype = 2;
v8 = 17;
}
else
{
req.ai_socktype = 1;
v8 = 6;
}
req.ai_protocol = v8;
if ( getaddrinfo(a2, a3, &req, &pai) )
{
v6 = -82;
}
else
{
v9 = pai;
if ( pai )
{
while ( 1 )
{
v10 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*a1 = v10;
if ( v10 < 0 )
{
v6 = -66;
}
else
{
v6 = connect(v10, v9->ai_addr, v9->ai_addrlen);
if ( !v6 )
goto LABEL_12;
close(*a1);
v6 = -68;
}
v9 = v9->ai_next;
if ( !v9 )
goto LABEL_12;
}
}
v6 = -82;
LABEL_12:
freeaddrinfo(pai);
}
}
return v6;
}

original_code:
int mbedtls_net_connect(mbedtls_net_context *ctx, const char *host,
                        const char *port, int proto)
{
    int ret = -0x006E;
    struct addrinfo hints, *addr_list, *cur;
    if ((ret = net_prepare()) != 0) {
        return ret;
    }
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = proto == 1 ? SOCK_DGRAM : SOCK_STREAM;
    hints.ai_protocol = proto == 1 ? IPPROTO_UDP : IPPROTO_TCP;
    if (getaddrinfo(host, port, &hints, &addr_list) != 0) {
        return -0x0052;
    }
    ret = -0x0052;
    for (cur = addr_list; cur != ((void *)0); cur = cur->ai_next) {
        ctx->fd = (int) socket(cur->ai_family, cur->ai_socktype,
                               cur->ai_protocol);
        if (ctx->fd < 0) {
            ret = -0x0042;
            continue;
        }
        if (connect(ctx->fd, cur->ai_addr, cur->ai_addrlen) == 0) {
            ret = 0;
            break;
        }
        close(ctx->fd);
        ret = -0x0044;
    }
    freeaddrinfo(addr_list);
    return ret;
}

canonical_original_code:
int mbedtls_net_connect(struct mbedtls_net_context *ctx, char *host, char *port, int proto)
{
    int ret = -0x006E;
    struct addrinfo hints; struct addrinfo *addr_list; struct addrinfo *cur;
    if ((ret = net_prepare()) != 0) {
        return ret;
    }
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = proto == 1 ? SOCK_DGRAM : SOCK_STREAM;
    hints.ai_protocol = proto == 1 ? IPPROTO_UDP : IPPROTO_TCP;
    if (getaddrinfo(host, port, &hints, &addr_list) != 0) {
        return -0x0052;
    }
    ret = -0x0052;
    for (cur = addr_list; cur != ((void *)0); cur = cur->ai_next) {
        ctx->fd = (int) socket(cur->ai_family, cur->ai_socktype,
                               cur->ai_protocol);
        if (ctx->fd < 0) {
            ret = -0x0042;
            continue;
        }
        if (connect(ctx->fd, cur->ai_addr, cur->ai_addrlen) == 0) {
            ret = 0;
            break;
        }
        close(ctx->fd);
        ret = -0x0044;
    }
    freeaddrinfo(addr_list);
    return ret;
}

variable_types: struct mbedtls_net_context { int fd; } *

variable_types:
host
char *

variable_types:
port
char *

variable_types: proto int

variable_types: ret int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall mbedtls_net_bind(int *a1, const char *a2, const char *a3, int a4)
{
unsigned int v6; // ebx
int v8; // eax
struct addrinfo *v9; // rbp
int v10; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-68h] BYREF
int optval[11]; // [rsp+4Ch] [rbp-2Ch] BYREF

v6 = net_prepare();
if ( !v6 )
{
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( a4 == 1 )
{
req.ai_socktype = 2;
v8 = 17;
}
else
{
req.ai_socktype = 1;
v8 = 6;
}
req.ai_protocol = v8;
if ( !a2 )
req.ai_flags = 1;
if ( getaddrinfo(a2, a3, &req, &pai) )
{
v6 = -82;
}
else
{
v9 = pai;
if ( pai )
{
while ( 1 )
{
v10 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*a1 = v10;
if ( v10 < 0 )
{
v6 = -66;
}
else
{
optval[0] = 1;
if ( setsockopt(v10, 1, 2, optval, 4u) )
{
close(*a1);
v6 = -66;
}
else
{
v6 = bind(*a1, v9->ai_addr, v9->ai_addrlen);
if ( v6 )
{
close(*a1);
v6 = -70;
}
else
{
if ( a4 )
goto LABEL_20;
v6 = listen(*a1, 10);
if ( !v6 )
goto LABEL_20;
close(*a1);
v6 = -72;
}
}
}
v9 = v9->ai_next;
if ( !v9 )
goto LABEL_20;
}
}
v6 = -82;
LABEL_20:
freeaddrinfo(pai);
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, const char *a2, const char *a3, int a4)
{
unsigned int v6; // ebx
int v8; // eax
struct addrinfo *v9; // rbp
int v10; // eax
struct addrinfo *pai; // [rsp+8h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-68h] BYREF
int optval[11]; // [rsp+4Ch] [rbp-2Ch] BYREF

v6 = func1();
if ( !v6 )
{
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( a4 == 1 )
{
req.ai_socktype = 2;
v8 = 17;
}
else
{
req.ai_socktype = 1;
v8 = 6;
}
req.ai_protocol = v8;
if ( !a2 )
req.ai_flags = 1;
if ( getaddrinfo(a2, a3, &req, &pai) )
{
v6 = -82;
}
else
{
v9 = pai;
if ( pai )
{
while ( 1 )
{
v10 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*a1 = v10;
if ( v10 < 0 )
{
v6 = -66;
}
else
{
optval[0] = 1;
if ( setsockopt(v10, 1, 2, optval, 4u) )
{
close(*a1);
v6 = -66;
}
else
{
v6 = bind(*a1, v9->ai_addr, v9->ai_addrlen);
if ( v6 )
{
close(*a1);
v6 = -70;
}
else
{
if ( a4 )
goto LABEL_20;
v6 = listen(*a1, 10);
if ( !v6 )
goto LABEL_20;
close(*a1);
v6 = -72;
}
}
}
v9 = v9->ai_next;
if ( !v9 )
goto LABEL_20;
}
}
v6 = -82;
LABEL_20:
freeaddrinfo(pai);
}
}
return v6;
}

original_code:
int mbedtls_net_bind(mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto)
{
    int n, ret;
    struct addrinfo hints, *addr_list, *cur;
    if ((ret = net_prepare()) != 0) {
        return ret;
    }
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = proto == 1 ? SOCK_DGRAM : SOCK_STREAM;
    hints.ai_protocol = proto == 1 ? IPPROTO_UDP : IPPROTO_TCP;
    if (bind_ip == ((void *)0)) {
        hints.ai_flags = 0x0001;
    }
    if (getaddrinfo(bind_ip, port, &hints, &addr_list) != 0) {
        return -0x0052;
    }
    ret = -0x0052;
    for (cur = addr_list; cur != ((void *)0); cur = cur->ai_next) {
        ctx->fd = (int) socket(cur->ai_family, cur->ai_socktype,
                               cur->ai_protocol);
        if (ctx->fd < 0) {
            ret = -0x0042;
            continue;
        }
        n = 1;
        if (setsockopt(ctx->fd, 1, 2,
                       (const char *) &n, sizeof(n)) != 0) {
            close(ctx->fd);
            ret = -0x0042;
            continue;
        }
        if (bind(ctx->fd, cur->ai_addr, cur->ai_addrlen) != 0) {
            close(ctx->fd);
            ret = -0x0046;
            continue;
        }
        if (proto == 0) {
            if (listen(ctx->fd, 10) != 0) {
                close(ctx->fd);
                ret = -0x0048;
                continue;
            }
        }
        ret = 0;
        break;
    }
    freeaddrinfo(addr_list);
    return ret;
}

canonical_original_code:
int mbedtls_net_bind(struct mbedtls_net_context *ctx, char *bind_ip, char *port, int proto)
{
    int n; int ret;
    struct addrinfo hints; struct addrinfo *addr_list; struct addrinfo *cur;
    if ((ret = net_prepare()) != 0) {
        return ret;
    }
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = proto == 1 ? SOCK_DGRAM : SOCK_STREAM;
    hints.ai_protocol = proto == 1 ? IPPROTO_UDP : IPPROTO_TCP;
    if (bind_ip == ((void *)0)) {
        hints.ai_flags = 0x0001;
    }
    if (getaddrinfo(bind_ip, port, &hints, &addr_list) != 0) {
        return -0x0052;
    }
    ret = -0x0052;
    for (cur = addr_list; cur != ((void *)0); cur = cur->ai_next) {
        ctx->fd = (int) socket(cur->ai_family, cur->ai_socktype,
                               cur->ai_protocol);
        if (ctx->fd < 0) {
            ret = -0x0042;
            continue;
        }
        n = 1;
        if (setsockopt(ctx->fd, 1, 2,
                       (char *) &n, sizeof(n)) != 0) {
            close(ctx->fd);
            ret = -0x0042;
            continue;
        }
        if (bind(ctx->fd, cur->ai_addr, cur->ai_addrlen) != 0) {
            close(ctx->fd);
            ret = -0x0046;
            continue;
        }
        if (proto == 0) {
            if (listen(ctx->fd, 10) != 0) {
                close(ctx->fd);
                ret = -0x0048;
                continue;
            }
        }
        ret = 0;
        break;
    }
    freeaddrinfo(addr_list);
    return ret;
}

variable_types: n int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall mbedtls_net_accept(int *a1, int *a2, __m128i *a3, unsigned __int64 a4, _QWORD *a5)
{
unsigned int v8; // ebx
int v9; // eax
int v11; // eax
int v12; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr buf[8]; // [rsp+10h] [rbp-158h] BYREF
socklen_t optlen; // [rsp+98h] [rbp-D0h] BYREF
socklen_t addr_len; // [rsp+9Ch] [rbp-CCh] BYREF
struct sockaddr addr; // [rsp+A0h] [rbp-C8h] BYREF
int optval[15]; // [rsp+12Ch] [rbp-3Ch] BYREF

addr_len = 128;
optlen = 4;
if ( getsockopt(*a1, 1, 3, optval, &optlen) )
return (unsigned int)-74;
v8 = 0;
if ( (unsigned int)(optval[0] - 1) > 1 )
return (unsigned int)-74;
if ( optval[0] == 1 )
{
v9 = accept(*a1, &addr, &addr_len);
*a2 = v9;
}
else
{
LOBYTE(buf[0].sa_family) = 0;
v9 = recvfrom(*a1, buf, 1uLL, 2, &addr, &addr_len);
}
if ( v9 < 0 )
return (unsigned int)((unsigned int)net_would_block((unsigned int *)a1) == 0 ? -74 : -26880);
if ( optval[0] != 1 )
{
v12 = 1;
if ( connect(*a1, &addr, addr_len) )
return (unsigned int)-74;
*a2 = *a1;
*a1 = -1;
addr_len = 128;
if ( getsockname(*a2, buf, &addr_len) )
return (unsigned int)-66;
v11 = socket(buf[0].sa_family, 2, 17);
*a1 = v11;
if ( v11 < 0 )
return (unsigned int)-66;
if ( setsockopt(v11, 1, 2, &v12, 4u) )
return (unsigned int)-66;
if ( bind(*a1, buf, addr_len) )
return (unsigned int)-70;
}
if ( a3 )
{
if ( addr.sa_family == 2 )
{
*a5 = 4LL;
if ( a4 <= 3 )
v8 = -67;
else
a3->m128i_i32[0] = *(_DWORD *)&addr.sa_data[2];
}
else
{
*a5 = 16LL;
if ( a4 <= 0xF )
v8 = -67;
else
*a3 = _mm_loadu_si128((const __m128i *)&addr.sa_data[6]);
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, int *a2, __m128i *a3, unsigned __int64 a4, _QWORD *a5)
{
unsigned int v8; // ebx
int v9; // eax
int v11; // eax
int v12; // [rsp+Ch] [rbp-15Ch] BYREF
struct sockaddr buf[8]; // [rsp+10h] [rbp-158h] BYREF
socklen_t optlen; // [rsp+98h] [rbp-D0h] BYREF
socklen_t addr_len; // [rsp+9Ch] [rbp-CCh] BYREF
struct sockaddr addr; // [rsp+A0h] [rbp-C8h] BYREF
int optval[15]; // [rsp+12Ch] [rbp-3Ch] BYREF

addr_len = 128;
optlen = 4;
if ( getsockopt(*a1, 1, 3, optval, &optlen) )
return (unsigned int)-74;
v8 = 0;
if ( (unsigned int)(optval[0] - 1) > 1 )
return (unsigned int)-74;
if ( optval[0] == 1 )
{
v9 = accept(*a1, &addr, &addr_len);
*a2 = v9;
}
else
{
LOBYTE(buf[0].sa_family) = 0;
v9 = recvfrom(*a1, buf, 1uLL, 2, &addr, &addr_len);
}
if ( v9 < 0 )
return (unsigned int)((unsigned int)func2((unsigned int *)a1) == 0 ? -74 : -26880);
if ( optval[0] != 1 )
{
v12 = 1;
if ( connect(*a1, &addr, addr_len) )
return (unsigned int)-74;
*a2 = *a1;
*a1 = -1;
addr_len = 128;
if ( getsockname(*a2, buf, &addr_len) )
return (unsigned int)-66;
v11 = socket(buf[0].sa_family, 2, 17);
*a1 = v11;
if ( v11 < 0 )
return (unsigned int)-66;
if ( setsockopt(v11, 1, 2, &v12, 4u) )
return (unsigned int)-66;
if ( bind(*a1, buf, addr_len) )
return (unsigned int)-70;
}
if ( a3 )
{
if ( addr.sa_family == 2 )
{
*a5 = 4LL;
if ( a4 <= 3 )
v8 = -67;
else
a3->m128i_i32[0] = *(_DWORD *)&addr.sa_data[2];
}
else
{
*a5 = 16LL;
if ( a4 <= 0xF )
v8 = -67;
else
*a3 = _mm_loadu_si128((const __m128i *)&addr.sa_data[6]);
}
}
return v8;
}

original_code:
int mbedtls_net_accept(mbedtls_net_context *bind_ctx,
                       mbedtls_net_context *client_ctx,
                       void *client_ip, size_t buf_size, size_t *ip_len)
{
    int ret = -0x006E;
    int type;
    struct sockaddr_storage client_addr;
    socklen_t n = (socklen_t) sizeof(client_addr);
    socklen_t type_len = (socklen_t) sizeof(type);
    if (getsockopt(bind_ctx->fd, 1, 3,
                   (void *) &type, &type_len) != 0 ||
        (type != SOCK_STREAM && type != SOCK_DGRAM)) {
        return -0x004A;
    }
    if (type == SOCK_STREAM) {
        ret = client_ctx->fd = (int) accept(bind_ctx->fd,
                                            (struct sockaddr *) &client_addr, &n);
    } else {
        char buf[1] = { 0 };
        ret = (int) recvfrom(bind_ctx->fd, buf, sizeof(buf), MSG_PEEK,
                             (struct sockaddr *) &client_addr, &n);
    }
    if (ret < 0) {
        if (net_would_block(bind_ctx) != 0) {
            return -0x6900;
        }
        return -0x004A;
    }
    if (type != SOCK_STREAM) {
        struct sockaddr_storage local_addr;
        int one = 1;
        if (connect(bind_ctx->fd, (struct sockaddr *) &client_addr, n) != 0) {
            return -0x004A;
        }
        client_ctx->fd = bind_ctx->fd;
        bind_ctx->fd = -1;
        n = sizeof(struct sockaddr_storage);
        if (getsockname(client_ctx->fd,
                        (struct sockaddr *) &local_addr, &n) != 0 ||
            (bind_ctx->fd = (int) socket(local_addr.ss_family,
                                         SOCK_DGRAM, IPPROTO_UDP)) < 0 ||
            setsockopt(bind_ctx->fd, 1, 2,
                       (const char *) &one, sizeof(one)) != 0) {
            return -0x0042;
        }
        if (bind(bind_ctx->fd, (struct sockaddr *) &local_addr, n) != 0) {
            return -0x0046;
        }
    }
    if (client_ip != ((void *)0)) {
        if (client_addr.ss_family == 2) {
            struct sockaddr_in *addr4 = (struct sockaddr_in *) &client_addr;
            *ip_len = sizeof(addr4->sin_addr.s_addr);
            if (buf_size < *ip_len) {
                return -0x0043;
            }
            memcpy(client_ip, &addr4->sin_addr.s_addr, *ip_len);
        } else {
            struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &client_addr;
            *ip_len = sizeof(addr6->sin6_addr.__in6_u.__u6_addr8);
            if (buf_size < *ip_len) {
                return -0x0043;
            }
            memcpy(client_ip, &addr6->sin6_addr.__in6_u.__u6_addr8, *ip_len);
        }
    }
    return 0;
}

canonical_original_code:
int mbedtls_net_accept(struct mbedtls_net_context *bind_ctx, struct mbedtls_net_context *client_ctx, void *client_ip, unsigned long buf_size, unsigned long *ip_len)
{
    int ret = -0x006E;
    int type;
    struct sockaddr_storage client_addr;
    unsigned int n = (socklen_t) sizeof(client_addr);
    unsigned int type_len = (socklen_t) sizeof(type);
    if (getsockopt(bind_ctx->fd, 1, 3,
                   (void *) &type, &type_len) != 0 ||
        (type != SOCK_STREAM && type != SOCK_DGRAM)) {
        return -0x004A;
    }
    if (type == SOCK_STREAM) {
        ret = client_ctx->fd = (int) accept(bind_ctx->fd,
                                            (struct sockaddr *) &client_addr, &n);
    } else {
        char buf[1] = { 0 };
        ret = (int) recvfrom(bind_ctx->fd, buf, sizeof(buf), MSG_PEEK,
                             (struct sockaddr *) &client_addr, &n);
    }
    if (ret < 0) {
        if (net_would_block(bind_ctx) != 0) {
            return -0x6900;
        }
        return -0x004A;
    }
    if (type != SOCK_STREAM) {
        struct sockaddr_storage local_addr;
        int one = 1;
        if (connect(bind_ctx->fd, (struct sockaddr *) &client_addr, n) != 0) {
            return -0x004A;
        }
        client_ctx->fd = bind_ctx->fd;
        bind_ctx->fd = -1;
        n = sizeof(struct sockaddr_storage);
        if (getsockname(client_ctx->fd,
                        (struct sockaddr *) &local_addr, &n) != 0 ||
            (bind_ctx->fd = (int) socket(local_addr.ss_family,
                                         SOCK_DGRAM, IPPROTO_UDP)) < 0 ||
            setsockopt(bind_ctx->fd, 1, 2,
                       (char *) &one, sizeof(one)) != 0) {
            return -0x0042;
        }
        if (bind(bind_ctx->fd, (struct sockaddr *) &local_addr, n) != 0) {
            return -0x0046;
        }
    }
    if (client_ip != ((void *)0)) {
        if (client_addr.ss_family == 2) {
            struct sockaddr_in *addr4 = (struct sockaddr_in *) &client_addr;
            *ip_len = sizeof(addr4->sin_addr.s_addr);
            if (buf_size < *ip_len) {
                return -0x0043;
            }
            memcpy(client_ip, &addr4->sin_addr.s_addr, *ip_len);
        } else {
            struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) &client_addr;
            *ip_len = sizeof(addr6->sin6_addr.__in6_u.__u6_addr8);
            if (buf_size < *ip_len) {
                return -0x0043;
            }
            memcpy(client_ip, &addr6->sin6_addr.__in6_u.__u6_addr8, *ip_len);
        }
    }
    return 0;
}

variable_types: type int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
n
unsigned int

variable_types:
buf
char [1]

variable_types: one int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall mbedtls_net_set_block(unsigned int *a1)
{
fcntl64(*a1, 3LL);
return fcntl64(*a1, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
fcntl64(*a1, 3LL);
return fcntl64(*a1, 4LL);
}

original_code:
int mbedtls_net_set_block(mbedtls_net_context *ctx)
{
    return fcntl(ctx->fd, 4, fcntl(ctx->fd, 3) & ~04000);
}

canonical_original_code:
int mbedtls_net_set_block(struct mbedtls_net_context *ctx)
{
    return fcntl(ctx->fd, 4, fcntl(ctx->fd, 3) & ~04000);
}


decompiled_code:
__int64 __fastcall mbedtls_net_set_nonblock(unsigned int *a1)
{
fcntl64(*a1, 3LL);
return fcntl64(*a1, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
fcntl64(*a1, 3LL);
return fcntl64(*a1, 4LL);
}

original_code:
int mbedtls_net_set_nonblock(mbedtls_net_context *ctx)
{
    return fcntl(ctx->fd, 4, fcntl(ctx->fd, 3) | 04000);
}

canonical_original_code:
int mbedtls_net_set_nonblock(struct mbedtls_net_context *ctx)
{
    return fcntl(ctx->fd, 4, fcntl(ctx->fd, 3) | 04000);
}


decompiled_code:
unsigned __int64 __fastcall mbedtls_net_poll(int *a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // ebp
int v5; // ebx
unsigned __int64 result; // rax
struct timeval *v7; // rbp
int v8; // eax
__int64 v9; // rcx
__int64 v10; // rdx
fd_set v11; // [rsp+0h] [rbp-128h] BYREF
fd_set readfds; // [rsp+80h] [rbp-A8h] BYREF
__int64 v13[5]; // [rsp+100h] [rbp-28h] BYREF

v3 = a2;
v5 = *a1;
result = check_fd(*a1, 1);
if ( !(_DWORD)result )
{
memset64(&readfds, result, 0x10uLL);
if ( (a2 & 1) != 0 )
{
v3 = a2 & 0xFFFFFFFE;
readfds.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
}
memset(&v11, 0, sizeof(v11));
if ( (v3 & 2) != 0 )
{
v3 &= 0xFFFFFFFD;
v11.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
}
if ( v3 )
{
result = 4294967223LL;
}
else
{
v13[0] = a3 / 0x3E8;
v13[1] = 1000 * (a3 % 0x3E8);
v7 = (struct timeval *)v13;
if ( a3 == -1 )
v7 = 0LL;
do
v8 = select(v5 + 1, &readfds, &v11, 0LL, v7);
while ( v8 == 4 );
if ( v8 < 0 )
{
result = 4294967225LL;
}
else
{
v9 = 1LL << (v5 % 64);
v10 = v5 / 64;
result = (readfds.fds_bits[v10] & v9) != 0;
if ( (v11.fds_bits[v10] & v9) != 0 )
result = (unsigned int)result | 2;
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(int *a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // ebp
int v5; // ebx
unsigned __int64 result; // rax
struct timeval *v7; // rbp
int v8; // eax
__int64 v9; // rcx
__int64 v10; // rdx
fd_set v11; // [rsp+0h] [rbp-128h] BYREF
fd_set readfds; // [rsp+80h] [rbp-A8h] BYREF
__int64 v13[5]; // [rsp+100h] [rbp-28h] BYREF

v3 = a2;
v5 = *a1;
result = func0(*a1, 1);
if ( !(_DWORD)result )
{
memset64(&readfds, result, 0x10uLL);
if ( (a2 & 1) != 0 )
{
v3 = a2 & 0xFFFFFFFE;
readfds.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
}
memset(&v11, 0, sizeof(v11));
if ( (v3 & 2) != 0 )
{
v3 &= 0xFFFFFFFD;
v11.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
}
if ( v3 )
{
result = 4294967223LL;
}
else
{
v13[0] = a3 / 0x3E8;
v13[1] = 1000 * (a3 % 0x3E8);
v7 = (struct timeval *)v13;
if ( a3 == -1 )
v7 = 0LL;
do
v8 = select(v5 + 1, &readfds, &v11, 0LL, v7);
while ( v8 == 4 );
if ( v8 < 0 )
{
result = 4294967225LL;
}
else
{
v9 = 1LL << (v5 % 64);
v10 = v5 / 64;
result = (readfds.fds_bits[v10] & v9) != 0;
if ( (v11.fds_bits[v10] & v9) != 0 )
result = (unsigned int)result | 2;
}
}
}
return result;
}

original_code:
int mbedtls_net_poll(mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout)
{
    int ret = -0x006E;
    struct timeval tv;
    fd_set read_fds;
    fd_set write_fds;
    int fd = ctx->fd;
    ret = check_fd(fd, 1);
    if (ret != 0) {
        return ret;
    }
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->fds_bits)[0]) : "memory"); } while (0);
    if (rw & 1) {
        rw &= ~1;
        ((void) (((&read_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    }
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_fds)->fds_bits)[0]) : "memory"); } while (0);
    if (rw & 2) {
        rw &= ~2;
        ((void) (((&write_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    }
    if (rw != 0) {
        return -0x0049;
    }
    tv.tv_sec = timeout / 1000;
    tv.tv_usec = (timeout % 1000) * 1000;
    do {
        ret = select(fd + 1, &read_fds, &write_fds, ((void *)0),
                     timeout == (uint32_t) -1 ? ((void *)0) : &tv);
    } while (((ret) == 4));
    if (ret < 0) {
        return -0x0047;
    }
    ret = 0;
    if (((((&read_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        ret |= 1;
    }
    if (((((&write_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        ret |= 2;
    }
    return ret;
}

canonical_original_code:
int mbedtls_net_poll(struct mbedtls_net_context *ctx, unsigned int rw, unsigned int timeout)
{
    int ret = -0x006E;
    struct timeval tv;
    struct fd_set read_fds;
    struct fd_set write_fds;
    int fd = ctx->fd;
    ret = check_fd(fd, 1);
    if (ret != 0) {
        return ret;
    }
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->fds_bits)[0]) : "memory"); } while (0);
    if (rw & 1) {
        rw &= ~1;
        ((void) (((&read_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    }
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_fds)->fds_bits)[0]) : "memory"); } while (0);
    if (rw & 2) {
        rw &= ~2;
        ((void) (((&write_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    }
    if (rw != 0) {
        return -0x0049;
    }
    tv.tv_sec = timeout / 1000;
    tv.tv_usec = (timeout % 1000) * 1000;
    do {
        ret = select(fd + 1, &read_fds, &write_fds, ((void *)0),
                     timeout == (unsigned int) -1 ? ((void *)0) : &tv);
    } while (((ret) == 4));
    if (ret < 0) {
        return -0x0047;
    }
    ret = 0;
    if (((((&read_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        ret |= 1;
    }
    if (((((&write_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
        ret |= 2;
    }
    return ret;
}

variable_types:
rw
unsigned int

variable_types:
timeout
unsigned int

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
int __fastcall mbedtls_net_usleep(__int64 a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240uLL;
v2.tv_usec = a1 % 1000000;
return select(0, 0LL, 0LL, 0LL, &v2);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 0xF4240uLL;
v2.tv_usec = a1 % 1000000;
return select(0, 0LL, 0LL, 0LL, &v2);
}

original_code:
void mbedtls_net_usleep(unsigned long usec)
{
    struct timeval tv;
    tv.tv_sec = usec / 1000000;
    tv.tv_usec = (suseconds_t) usec % 1000000;
    select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
}

canonical_original_code:
void mbedtls_net_usleep(unsigned long usec)
{
    struct timeval tv;
    tv.tv_sec = usec / 1000000;
    tv.tv_usec = (long) usec % 1000000;
    select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
}

variable_types:
usec
unsigned long

return_type: void

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall mbedtls_net_recv(int *a1, void *a2, size_t a3)
{
int v4; // er13
__int64 result; // rax
int v6; // eax
bool v7; // zf

v4 = *a1;
result = check_fd(*a1, 0);
if ( !(_DWORD)result )
{
result = read(v4, a2, a3);
if ( (int)result < 0 )
{
if ( (unsigned int)net_would_block((unsigned int *)a1) )
{
result = 4294940416LL;
}
else
{
v6 = *_errno_location();
if ( v6 == 32 || v6 == 104 )
{
result = 4294967216LL;
}
else
{
v7 = v6 == 4;
result = 4294940416LL;
if ( !v7 )
result = 4294967220LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, void *a2, size_t a3)
{
int v4; // er13
__int64 result; // rax
int v6; // eax
bool v7; // zf

v4 = *a1;
result = func0(*a1, 0);
if ( !(_DWORD)result )
{
result = read(v4, a2, a3);
if ( (int)result < 0 )
{
if ( (unsigned int)func2((unsigned int *)a1) )
{
result = 4294940416LL;
}
else
{
v6 = *_errno_location();
if ( v6 == 32 || v6 == 104 )
{
result = 4294967216LL;
}
else
{
v7 = v6 == 4;
result = 4294940416LL;
if ( !v7 )
result = 4294967220LL;
}
}
}
}
return result;
}

original_code:
int mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len)
{
    int ret = -0x006E;
    int fd = ((mbedtls_net_context *) ctx)->fd;
    ret = check_fd(fd, 0);
    if (ret != 0) {
        return ret;
    }
    ret = (int) read(fd, buf, len);
    if (ret < 0) {
        if (net_would_block(ctx) != 0) {
            return -0x6900;
        }
        if ((*__errno_location ()) == 32 || (*__errno_location ()) == 104) {
            return -0x0050;
        }
        if ((*__errno_location ()) == 4) {
            return -0x6900;
        }
        return -0x004C;
    }
    return ret;
}

canonical_original_code:
int mbedtls_net_recv(void *ctx, unsigned char *buf, unsigned long len)
{
    int ret = -0x006E;
    int fd = ((mbedtls_net_context *) ctx)->fd;
    ret = check_fd(fd, 0);
    if (ret != 0) {
        return ret;
    }
    ret = (int) read(fd, buf, len);
    if (ret < 0) {
        if (net_would_block(ctx) != 0) {
            return -0x6900;
        }
        if ((*__errno_location ()) == 32 || (*__errno_location ()) == 104) {
            return -0x0050;
        }
        if ((*__errno_location ()) == 4) {
            return -0x6900;
        }
        return -0x004C;
    }
    return ret;
}

variable_types:
ctx
void *

variable_types:
buf
unsigned char *

variable_types:
len
unsigned long

variable_types: fd int


decompiled_code:
__int64 __fastcall mbedtls_net_recv_timeout(int *a1, void *a2, size_t a3, unsigned int a4)
{
int v6; // ebx
__int64 result; // rax
struct timeval *v8; // r8
int v9; // eax
bool v10; // zf
fd_set v11; // [rsp+0h] [rbp-B8h] BYREF
__int64 v12[7]; // [rsp+80h] [rbp-38h] BYREF

v6 = *a1;
result = check_fd(*a1, 1);
if ( !(_DWORD)result )
{
memset64(&v11, result, 0x10uLL);
v11.fds_bits[v6 / 64] |= 1LL << (v6 % 64);
v12[0] = a4 / 0x3E8;
v12[1] = 1000 * (a4 % 0x3E8);
v8 = (struct timeval *)v12;
if ( !a4 )
v8 = 0LL;
v9 = select(v6 + 1, &v11, 0LL, 0LL, v8);
if ( v9 )
{
if ( v9 >= 0 )
{
result = mbedtls_net_recv(a1, a2, a3);
}
else
{
v10 = *_errno_location() == 4;
result = 4294940416LL;
if ( !v10 )
result = 4294967220LL;
}
}
else
{
result = 4294940672LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, void *a2, size_t a3, unsigned int a4)
{
int v6; // ebx
__int64 result; // rax
struct timeval *v8; // r8
int v9; // eax
bool v10; // zf
fd_set v11; // [rsp+0h] [rbp-B8h] BYREF
__int64 v12[7]; // [rsp+80h] [rbp-38h] BYREF

v6 = *a1;
result = func0(*a1, 1);
if ( !(_DWORD)result )
{
memset64(&v11, result, 0x10uLL);
v11.fds_bits[v6 / 64] |= 1LL << (v6 % 64);
v12[0] = a4 / 0x3E8;
v12[1] = 1000 * (a4 % 0x3E8);
v8 = (struct timeval *)v12;
if ( !a4 )
v8 = 0LL;
v9 = select(v6 + 1, &v11, 0LL, 0LL, v8);
if ( v9 )
{
if ( v9 >= 0 )
{
result = func11(a1, a2, a3);
}
else
{
v10 = *_errno_location() == 4;
result = 4294940416LL;
if ( !v10 )
result = 4294967220LL;
}
}
else
{
result = 4294940672LL;
}
}
return result;
}

original_code:
int mbedtls_net_recv_timeout(void *ctx, unsigned char *buf,
                             size_t len, uint32_t timeout)
{
    int ret = -0x006E;
    struct timeval tv;
    fd_set read_fds;
    int fd = ((mbedtls_net_context *) ctx)->fd;
    ret = check_fd(fd, 1);
    if (ret != 0) {
        return ret;
    }
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = timeout / 1000;
    tv.tv_usec = (timeout % 1000) * 1000;
    ret = select(fd + 1, &read_fds, ((void *)0), ((void *)0), timeout == 0 ? ((void *)0) : &tv);
    if (ret == 0) {
        return -0x6800;
    }
    if (ret < 0) {
        if ((*__errno_location ()) == 4) {
            return -0x6900;
        }
        return -0x004C;
    }
    return mbedtls_net_recv(ctx, buf, len);
}

canonical_original_code:
int mbedtls_net_recv_timeout(void *ctx, unsigned char *buf, unsigned long len, unsigned int timeout)
{
    int ret = -0x006E;
    struct timeval tv;
    struct fd_set read_fds;
    int fd = ((mbedtls_net_context *) ctx)->fd;
    ret = check_fd(fd, 1);
    if (ret != 0) {
        return ret;
    }
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_fds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
    tv.tv_sec = timeout / 1000;
    tv.tv_usec = (timeout % 1000) * 1000;
    ret = select(fd + 1, &read_fds, ((void *)0), ((void *)0), timeout == 0 ? ((void *)0) : &tv);
    if (ret == 0) {
        return -0x6800;
    }
    if (ret < 0) {
        if ((*__errno_location ()) == 4) {
            return -0x6900;
        }
        return -0x004C;
    }
    return mbedtls_net_recv(ctx, buf, len);
}

variable_types: ret int


decompiled_code:
__int64 __fastcall mbedtls_net_send(int *a1, const void *a2, size_t a3)
{
int v4; // er13
__int64 result; // rax
int v6; // eax
bool v7; // zf

v4 = *a1;
result = check_fd(*a1, 0);
if ( !(_DWORD)result )
{
result = write(v4, a2, a3);
if ( (int)result < 0 )
{
if ( (unsigned int)net_would_block((unsigned int *)a1) )
{
result = 4294940544LL;
}
else
{
v6 = *_errno_location();
if ( v6 == 32 || v6 == 104 )
{
result = 4294967216LL;
}
else
{
v7 = v6 == 4;
result = 4294940544LL;
if ( !v7 )
result = 4294967218LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int *a1, const void *a2, size_t a3)
{
int v4; // er13
__int64 result; // rax
int v6; // eax
bool v7; // zf

v4 = *a1;
result = func0(*a1, 0);
if ( !(_DWORD)result )
{
result = write(v4, a2, a3);
if ( (int)result < 0 )
{
if ( (unsigned int)func2((unsigned int *)a1) )
{
result = 4294940544LL;
}
else
{
v6 = *_errno_location();
if ( v6 == 32 || v6 == 104 )
{
result = 4294967216LL;
}
else
{
v7 = v6 == 4;
result = 4294940544LL;
if ( !v7 )
result = 4294967218LL;
}
}
}
}
return result;
}

original_code:
int mbedtls_net_send(void *ctx, const unsigned char *buf, size_t len)
{
    int ret = -0x006E;
    int fd = ((mbedtls_net_context *) ctx)->fd;
    ret = check_fd(fd, 0);
    if (ret != 0) {
        return ret;
    }
    ret = (int) write(fd, buf, len);
    if (ret < 0) {
        if (net_would_block(ctx) != 0) {
            return -0x6880;
        }
        if ((*__errno_location ()) == 32 || (*__errno_location ()) == 104) {
            return -0x0050;
        }
        if ((*__errno_location ()) == 4) {
            return -0x6880;
        }
        return -0x004E;
    }
    return ret;
}

canonical_original_code:
int mbedtls_net_send(void *ctx, unsigned char *buf, unsigned long len)
{
    int ret = -0x006E;
    int fd = ((mbedtls_net_context *) ctx)->fd;
    ret = check_fd(fd, 0);
    if (ret != 0) {
        return ret;
    }
    ret = (int) write(fd, buf, len);
    if (ret < 0) {
        if (net_would_block(ctx) != 0) {
            return -0x6880;
        }
        if ((*__errno_location ()) == 32 || (*__errno_location ()) == 104) {
            return -0x0050;
        }
        if ((*__errno_location ()) == 4) {
            return -0x6880;
        }
        return -0x004E;
    }
    return ret;
}


decompiled_code:
int __fastcall mbedtls_net_close(int *a1)
{
int v2; // edi
int result; // eax

v2 = *a1;
if ( v2 != -1 )
{
result = close(v2);
*a1 = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(int *a1)
{
int v2; // edi
int result; // eax

v2 = *a1;
if ( v2 != -1 )
{
result = close(v2);
*a1 = -1;
}
return result;
}

original_code:
void mbedtls_net_close(mbedtls_net_context *ctx)
{
    if (ctx->fd == -1) {
        return;
    }
    close(ctx->fd);
    ctx->fd = -1;
}

canonical_original_code:
void mbedtls_net_close(struct mbedtls_net_context *ctx)
{
    if (ctx->fd == -1) {
        return;
    }
    close(ctx->fd);
    ctx->fd = -1;
}

variable_types: struct mbedtls_net_context { int fd; } *


decompiled_code:
int __fastcall mbedtls_net_free(int *a1)
{
int v2; // edi
int result; // eax

v2 = *a1;
if ( v2 != -1 )
{
shutdown(v2, 2);
result = close(*a1);
*a1 = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(int *a1)
{
int v2; // edi
int result; // eax

v2 = *a1;
if ( v2 != -1 )
{
shutdown(v2, 2);
result = close(*a1);
*a1 = -1;
}
return result;
}

original_code:
void mbedtls_net_free(mbedtls_net_context *ctx)
{
    if (ctx->fd == -1) {
        return;
    }
    shutdown(ctx->fd, 2);
    close(ctx->fd);
    ctx->fd = -1;
}

canonical_original_code:
void mbedtls_net_free(struct mbedtls_net_context *ctx)
{
    if (ctx->fd == -1) {
        return;
    }
    shutdown(ctx->fd, 2);
    close(ctx->fd);
    ctx->fd = -1;
}


decompiled_code:
const char *__fastcall mbedtls_ssl_named_group_to_str(unsigned __int16 a1)
{
const char *result; // rax

if ( a1 > 0x1Eu )
{
if ( (unsigned __int16)(a1 - 256) > 4u )
{
result = "UNKOWN";
}
else
{
switch ( a1 )
{
case 0x100u:
result = "ffdhe2048";
break;
case 0x101u:
result = "ffdhe3072";
break;
case 0x102u:
result = "ffdhe4096";
break;
case 0x103u:
result = "ffdhe6144";
break;
case 0x104u:
result = "ffdhe8192";
break;
default:
result = "UNKOWN";
break;
}
}
}
else if ( a1 <= 0x11u )
{
result = "UNKOWN";
}
else
{
switch ( a1 )
{
case 0x12u:
result = "secp192k1";
break;
case 0x13u:
result = "secp192r1";
break;
case 0x14u:
result = "secp224k1";
break;
case 0x15u:
result = "secp224r1";
break;
case 0x16u:
result = "secp256k1";
break;
case 0x17u:
result = "secp256r1";
break;
case 0x18u:
result = "secp384r1";
break;
case 0x19u:
result = "secp521r1";
break;
case 0x1Au:
result = "bp256r1";
break;
case 0x1Bu:
result = "bp384r1";
break;
case 0x1Cu:
result = "bp512r1";
break;
case 0x1Du:
result = "x25519";
break;
case 0x1Eu:
result = "x448";
break;
default:
result = "UNKOWN";
break;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func0(unsigned __int16 a1)
{
const char *result; // rax

if ( a1 > 0x1Eu )
{
if ( (unsigned __int16)(a1 - 256) > 4u )
{
result = "UNKOWN";
}
else
{
switch ( a1 )
{
case 0x100u:
result = "ffdhe2048";
break;
case 0x101u:
result = "ffdhe3072";
break;
case 0x102u:
result = "ffdhe4096";
break;
case 0x103u:
result = "ffdhe6144";
break;
case 0x104u:
result = "ffdhe8192";
break;
default:
result = "UNKOWN";
break;
}
}
}
else if ( a1 <= 0x11u )
{
result = "UNKOWN";
}
else
{
switch ( a1 )
{
case 0x12u:
result = "secp192k1";
break;
case 0x13u:
result = "secp192r1";
break;
case 0x14u:
result = "secp224k1";
break;
case 0x15u:
result = "secp224r1";
break;
case 0x16u:
result = "secp256k1";
break;
case 0x17u:
result = "secp256r1";
break;
case 0x18u:
result = "secp384r1";
break;
case 0x19u:
result = "secp521r1";
break;
case 0x1Au:
result = "bp256r1";
break;
case 0x1Bu:
result = "bp384r1";
break;
case 0x1Cu:
result = "bp512r1";
break;
case 0x1Du:
result = "x25519";
break;
case 0x1Eu:
result = "x448";
break;
default:
result = "UNKOWN";
break;
}
}
return result;
}

original_code:
const char *mbedtls_ssl_named_group_to_str( uint16_t in )
{
    switch( in )
    {
    case 0x0012:
        return "secp192k1";
    case 0x0013:
        return "secp192r1";
    case 0x0014:
        return "secp224k1";
    case 0x0015:
        return "secp224r1";
    case 0x0016:
        return "secp256k1";
    case 0x0017:
        return "secp256r1";
    case 0x0018:
        return "secp384r1";
    case 0x0019:
        return "secp521r1";
    case 0x001A:
        return "bp256r1";
    case 0x001B:
        return "bp384r1";
    case 0x001C:
        return "bp512r1";
    case 0x001D:
        return "x25519";
    case 0x001E:
        return "x448";
    case 0x0100:
        return "ffdhe2048";
    case 0x0101:
        return "ffdhe3072";
    case 0x0102:
        return "ffdhe4096";
    case 0x0103:
        return "ffdhe6144";
    case 0x0104:
        return "ffdhe8192";
    };
    return "UNKOWN";
}

canonical_original_code:
char *mbedtls_ssl_named_group_to_str(unsigned short in)
{
    switch( in )
    {
    case 0x0012:
        return "secp192k1";
    case 0x0013:
        return "secp192r1";
    case 0x0014:
        return "secp224k1";
    case 0x0015:
        return "secp224r1";
    case 0x0016:
        return "secp256k1";
    case 0x0017:
        return "secp256r1";
    case 0x0018:
        return "secp384r1";
    case 0x0019:
        return "secp521r1";
    case 0x001A:
        return "bp256r1";
    case 0x001B:
        return "bp384r1";
    case 0x001C:
        return "bp512r1";
    case 0x001D:
        return "x25519";
    case 0x001E:
        return "x448";
    case 0x0100:
        return "ffdhe2048";
    case 0x0101:
        return "ffdhe3072";
    case 0x0102:
        return "ffdhe4096";
    case 0x0103:
        return "ffdhe6144";
    case 0x0104:
        return "ffdhe8192";
    };
    return "UNKOWN";
}

variable_types:
in
unsigned short

return_type: char *


decompiled_code:
const char *__fastcall mbedtls_ssl_sig_alg_to_str(unsigned __int16 a1)
{
const char *result; // rax

if ( a1 == 1539 )
return "ecdsa_secp521r1_sha512";
if ( a1 > 0x603u )
{
if ( (unsigned __int16)(a1 - 2052) > 7u )
{
result = "UNKNOWN";
}
else
{
switch ( a1 )
{
case 0x804u:
result = "rsa_pss_rsae_sha256";
break;
case 0x805u:
result = "rsa_pss_rsae_sha384";
break;
case 0x806u:
result = "rsa_pss_rsae_sha512";
break;
case 0x807u:
result = "ed25519";
break;
case 0x808u:
result = "ed448";
break;
case 0x809u:
result = "rsa_pss_pss_sha256";
break;
case 0x80Au:
result = "rsa_pss_pss_sha384";
break;
case 0x80Bu:
result = "rsa_pss_pss_sha512";
break;
default:
result = "UNKNOWN";
break;
}
}
}
else if ( a1 == 1027 )
{
result = "ecdsa_secp256r1_sha256";
}
else if ( a1 <= 0x403u )
{
result = "ecdsa_sha1";
if ( a1 != 515 )
{
if ( a1 <= 0x203u )
{
result = "none";
if ( a1 )
{
result = "UNKNOWN";
if ( a1 == 513 )
result = "rsa_pkcs1_sha1";
}
}
else
{
result = "UNKNOWN";
if ( a1 == 1025 )
result = "rsa_pkcs1_sha256";
}
}
}
else
{
result = "ecdsa_secp384r1_sha384";
if ( a1 != 1283 )
{
if ( a1 == 1537 )
{
result = "rsa_pkcs1_sha512";
}
else
{
result = "UNKNOWN";
if ( a1 == 1281 )
result = "rsa_pkcs1_sha384";
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned __int16 a1)
{
const char *result; // rax

if ( a1 == 1539 )
return "ecdsa_secp521r1_sha512";
if ( a1 > 0x603u )
{
if ( (unsigned __int16)(a1 - 2052) > 7u )
{
result = "UNKNOWN";
}
else
{
switch ( a1 )
{
case 0x804u:
result = "rsa_pss_rsae_sha256";
break;
case 0x805u:
result = "rsa_pss_rsae_sha384";
break;
case 0x806u:
result = "rsa_pss_rsae_sha512";
break;
case 0x807u:
result = "ed25519";
break;
case 0x808u:
result = "ed448";
break;
case 0x809u:
result = "rsa_pss_pss_sha256";
break;
case 0x80Au:
result = "rsa_pss_pss_sha384";
break;
case 0x80Bu:
result = "rsa_pss_pss_sha512";
break;
default:
result = "UNKNOWN";
break;
}
}
}
else if ( a1 == 1027 )
{
result = "ecdsa_secp256r1_sha256";
}
else if ( a1 <= 0x403u )
{
result = "ecdsa_sha1";
if ( a1 != 515 )
{
if ( a1 <= 0x203u )
{
result = "none";
if ( a1 )
{
result = "UNKNOWN";
if ( a1 == 513 )
result = "rsa_pkcs1_sha1";
}
}
else
{
result = "UNKNOWN";
if ( a1 == 1025 )
result = "rsa_pkcs1_sha256";
}
}
}
else
{
result = "ecdsa_secp384r1_sha384";
if ( a1 != 1283 )
{
if ( a1 == 1537 )
{
result = "rsa_pkcs1_sha512";
}
else
{
result = "UNKNOWN";
if ( a1 == 1281 )
result = "rsa_pkcs1_sha384";
}
}
}
return result;
}

original_code:
const char *mbedtls_ssl_sig_alg_to_str( uint16_t in )
{
    switch( in )
    {
    case 0x0401:
        return "rsa_pkcs1_sha256";
    case 0x0501:
        return "rsa_pkcs1_sha384";
    case 0x0601:
        return "rsa_pkcs1_sha512";
    case 0x0403:
        return "ecdsa_secp256r1_sha256";
    case 0x0503:
        return "ecdsa_secp384r1_sha384";
    case 0x0603:
        return "ecdsa_secp521r1_sha512";
    case 0x0804:
        return "rsa_pss_rsae_sha256";
    case 0x0805:
        return "rsa_pss_rsae_sha384";
    case 0x0806:
        return "rsa_pss_rsae_sha512";
    case 0x0807:
        return "ed25519";
    case 0x0808:
        return "ed448";
    case 0x0809:
        return "rsa_pss_pss_sha256";
    case 0x080A:
        return "rsa_pss_pss_sha384";
    case 0x080B:
        return "rsa_pss_pss_sha512";
    case 0x0201:
        return "rsa_pkcs1_sha1";
    case 0x0203:
        return "ecdsa_sha1";
    case 0x0:
        return "none";
    };
    return "UNKNOWN";
}

canonical_original_code:
char *mbedtls_ssl_sig_alg_to_str(unsigned short in)
{
    switch( in )
    {
    case 0x0401:
        return "rsa_pkcs1_sha256";
    case 0x0501:
        return "rsa_pkcs1_sha384";
    case 0x0601:
        return "rsa_pkcs1_sha512";
    case 0x0403:
        return "ecdsa_secp256r1_sha256";
    case 0x0503:
        return "ecdsa_secp384r1_sha384";
    case 0x0603:
        return "ecdsa_secp521r1_sha512";
    case 0x0804:
        return "rsa_pss_rsae_sha256";
    case 0x0805:
        return "rsa_pss_rsae_sha384";
    case 0x0806:
        return "rsa_pss_rsae_sha512";
    case 0x0807:
        return "ed25519";
    case 0x0808:
        return "ed448";
    case 0x0809:
        return "rsa_pss_pss_sha256";
    case 0x080A:
        return "rsa_pss_pss_sha384";
    case 0x080B:
        return "rsa_pss_pss_sha512";
    case 0x0201:
        return "rsa_pkcs1_sha1";
    case 0x0203:
        return "ecdsa_sha1";
    case 0x0:
        return "none";
    };
    return "UNKNOWN";
}


decompiled_code:
const char *__fastcall mbedtls_ssl_states_str(unsigned int a1)
{
const char *result; // rax
__int64 v2[30]; // [rsp+0h] [rbp-F0h]

v2[0] = (__int64)"MBEDTLS_SSL_HELLO_REQUEST";
v2[1] = (__int64)"MBEDTLS_SSL_CLIENT_HELLO";
v2[2] = (__int64)"MBEDTLS_SSL_SERVER_HELLO";
v2[3] = (__int64)"MBEDTLS_SSL_SERVER_CERTIFICATE";
v2[4] = (__int64)"MBEDTLS_SSL_SERVER_KEY_EXCHANGE";
v2[5] = (__int64)"MBEDTLS_SSL_CERTIFICATE_REQUEST";
v2[6] = (__int64)"MBEDTLS_SSL_SERVER_HELLO_DONE";
v2[7] = (__int64)"MBEDTLS_SSL_CLIENT_CERTIFICATE";
v2[8] = (__int64)"MBEDTLS_SSL_CLIENT_KEY_EXCHANGE";
v2[9] = (__int64)"MBEDTLS_SSL_CERTIFICATE_VERIFY";
v2[10] = (__int64)"MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC";
v2[11] = (__int64)"MBEDTLS_SSL_CLIENT_FINISHED";
v2[12] = (__int64)"MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC";
v2[13] = (__int64)"MBEDTLS_SSL_SERVER_FINISHED";
v2[14] = (__int64)"MBEDTLS_SSL_FLUSH_BUFFERS";
v2[15] = (__int64)"MBEDTLS_SSL_HANDSHAKE_WRAPUP";
v2[16] = (__int64)"MBEDTLS_SSL_NEW_SESSION_TICKET";
v2[17] = (__int64)"MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT";
v2[18] = (__int64)"MBEDTLS_SSL_HELLO_RETRY_REQUEST";
v2[19] = (__int64)"MBEDTLS_SSL_ENCRYPTED_EXTENSIONS";
v2[20] = (__int64)"MBEDTLS_SSL_END_OF_EARLY_DATA";
v2[21] = (__int64)"MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY";
v2[22] = (__int64)"MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED";
v2[23] = (__int64)"MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO";
v2[24] = (__int64)"MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO";
v2[25] = (__int64)"MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO";
v2[26] = (__int64)"MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST";
v2[27] = (__int64)"MBEDTLS_SSL_HANDSHAKE_OVER";
v2[28] = (__int64)"MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET";
v2[29] = (__int64)"MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH";
result = "UNKNOWN_VALUE";
if ( a1 <= 0x1D )
{
result = (const char *)v2[a1];
if ( !result )
result = "UNKNOWN_VALUE";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned int a1)
{
const char *result; // rax
__int64 v2[30]; // [rsp+0h] [rbp-F0h]

v2[0] = (__int64)"MBEDTLS_SSL_HELLO_REQUEST";
v2[1] = (__int64)"MBEDTLS_SSL_CLIENT_HELLO";
v2[2] = (__int64)"MBEDTLS_SSL_SERVER_HELLO";
v2[3] = (__int64)"MBEDTLS_SSL_SERVER_CERTIFICATE";
v2[4] = (__int64)"MBEDTLS_SSL_SERVER_KEY_EXCHANGE";
v2[5] = (__int64)"MBEDTLS_SSL_CERTIFICATE_REQUEST";
v2[6] = (__int64)"MBEDTLS_SSL_SERVER_HELLO_DONE";
v2[7] = (__int64)"MBEDTLS_SSL_CLIENT_CERTIFICATE";
v2[8] = (__int64)"MBEDTLS_SSL_CLIENT_KEY_EXCHANGE";
v2[9] = (__int64)"MBEDTLS_SSL_CERTIFICATE_VERIFY";
v2[10] = (__int64)"MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC";
v2[11] = (__int64)"MBEDTLS_SSL_CLIENT_FINISHED";
v2[12] = (__int64)"MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC";
v2[13] = (__int64)"MBEDTLS_SSL_SERVER_FINISHED";
v2[14] = (__int64)"MBEDTLS_SSL_FLUSH_BUFFERS";
v2[15] = (__int64)"MBEDTLS_SSL_HANDSHAKE_WRAPUP";
v2[16] = (__int64)"MBEDTLS_SSL_NEW_SESSION_TICKET";
v2[17] = (__int64)"MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT";
v2[18] = (__int64)"MBEDTLS_SSL_HELLO_RETRY_REQUEST";
v2[19] = (__int64)"MBEDTLS_SSL_ENCRYPTED_EXTENSIONS";
v2[20] = (__int64)"MBEDTLS_SSL_END_OF_EARLY_DATA";
v2[21] = (__int64)"MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY";
v2[22] = (__int64)"MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED";
v2[23] = (__int64)"MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO";
v2[24] = (__int64)"MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO";
v2[25] = (__int64)"MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO";
v2[26] = (__int64)"MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST";
v2[27] = (__int64)"MBEDTLS_SSL_HANDSHAKE_OVER";
v2[28] = (__int64)"MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET";
v2[29] = (__int64)"MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH";
result = "UNKNOWN_VALUE";
if ( a1 <= 0x1D )
{
result = (const char *)v2[a1];
if ( !result )
result = "UNKNOWN_VALUE";
}
return result;
}

original_code:
const char *mbedtls_ssl_states_str( mbedtls_ssl_states in )
{
    const char * in_to_str[]=
    {
        [MBEDTLS_SSL_HELLO_REQUEST] = "MBEDTLS_SSL_HELLO_REQUEST",
        [MBEDTLS_SSL_CLIENT_HELLO] = "MBEDTLS_SSL_CLIENT_HELLO",
        [MBEDTLS_SSL_SERVER_HELLO] = "MBEDTLS_SSL_SERVER_HELLO",
        [MBEDTLS_SSL_SERVER_CERTIFICATE] = "MBEDTLS_SSL_SERVER_CERTIFICATE",
        [MBEDTLS_SSL_SERVER_KEY_EXCHANGE] = "MBEDTLS_SSL_SERVER_KEY_EXCHANGE",
        [MBEDTLS_SSL_CERTIFICATE_REQUEST] = "MBEDTLS_SSL_CERTIFICATE_REQUEST",
        [MBEDTLS_SSL_SERVER_HELLO_DONE] = "MBEDTLS_SSL_SERVER_HELLO_DONE",
        [MBEDTLS_SSL_CLIENT_CERTIFICATE] = "MBEDTLS_SSL_CLIENT_CERTIFICATE",
        [MBEDTLS_SSL_CLIENT_KEY_EXCHANGE] = "MBEDTLS_SSL_CLIENT_KEY_EXCHANGE",
        [MBEDTLS_SSL_CERTIFICATE_VERIFY] = "MBEDTLS_SSL_CERTIFICATE_VERIFY",
        [MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC] = "MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC",
        [MBEDTLS_SSL_CLIENT_FINISHED] = "MBEDTLS_SSL_CLIENT_FINISHED",
        [MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC] = "MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC",
        [MBEDTLS_SSL_SERVER_FINISHED] = "MBEDTLS_SSL_SERVER_FINISHED",
        [MBEDTLS_SSL_FLUSH_BUFFERS] = "MBEDTLS_SSL_FLUSH_BUFFERS",
        [MBEDTLS_SSL_HANDSHAKE_WRAPUP] = "MBEDTLS_SSL_HANDSHAKE_WRAPUP",
        [MBEDTLS_SSL_NEW_SESSION_TICKET] = "MBEDTLS_SSL_NEW_SESSION_TICKET",
        [MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT] = "MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT",
        [MBEDTLS_SSL_HELLO_RETRY_REQUEST] = "MBEDTLS_SSL_HELLO_RETRY_REQUEST",
        [MBEDTLS_SSL_ENCRYPTED_EXTENSIONS] = "MBEDTLS_SSL_ENCRYPTED_EXTENSIONS",
        [MBEDTLS_SSL_END_OF_EARLY_DATA] = "MBEDTLS_SSL_END_OF_EARLY_DATA",
        [MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY] = "MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY",
        [MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED] = "MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED",
        [MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO] = "MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO",
        [MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO] = "MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO",
        [MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO] = "MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO",
        [MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST] = "MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST",
        [MBEDTLS_SSL_HANDSHAKE_OVER] = "MBEDTLS_SSL_HANDSHAKE_OVER",
        [MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET] = "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET",
        [MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH] = "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

canonical_original_code:
char *mbedtls_ssl_states_str(enum mbedtls_ssl_states in)
{
    char *in_to_str[] = {
        [MBEDTLS_SSL_HELLO_REQUEST] = "MBEDTLS_SSL_HELLO_REQUEST",
        [MBEDTLS_SSL_CLIENT_HELLO] = "MBEDTLS_SSL_CLIENT_HELLO",
        [MBEDTLS_SSL_SERVER_HELLO] = "MBEDTLS_SSL_SERVER_HELLO",
        [MBEDTLS_SSL_SERVER_CERTIFICATE] = "MBEDTLS_SSL_SERVER_CERTIFICATE",
        [MBEDTLS_SSL_SERVER_KEY_EXCHANGE] = "MBEDTLS_SSL_SERVER_KEY_EXCHANGE",
        [MBEDTLS_SSL_CERTIFICATE_REQUEST] = "MBEDTLS_SSL_CERTIFICATE_REQUEST",
        [MBEDTLS_SSL_SERVER_HELLO_DONE] = "MBEDTLS_SSL_SERVER_HELLO_DONE",
        [MBEDTLS_SSL_CLIENT_CERTIFICATE] = "MBEDTLS_SSL_CLIENT_CERTIFICATE",
        [MBEDTLS_SSL_CLIENT_KEY_EXCHANGE] = "MBEDTLS_SSL_CLIENT_KEY_EXCHANGE",
        [MBEDTLS_SSL_CERTIFICATE_VERIFY] = "MBEDTLS_SSL_CERTIFICATE_VERIFY",
        [MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC] = "MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC",
        [MBEDTLS_SSL_CLIENT_FINISHED] = "MBEDTLS_SSL_CLIENT_FINISHED",
        [MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC] = "MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC",
        [MBEDTLS_SSL_SERVER_FINISHED] = "MBEDTLS_SSL_SERVER_FINISHED",
        [MBEDTLS_SSL_FLUSH_BUFFERS] = "MBEDTLS_SSL_FLUSH_BUFFERS",
        [MBEDTLS_SSL_HANDSHAKE_WRAPUP] = "MBEDTLS_SSL_HANDSHAKE_WRAPUP",
        [MBEDTLS_SSL_NEW_SESSION_TICKET] = "MBEDTLS_SSL_NEW_SESSION_TICKET",
        [MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT] = "MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT",
        [MBEDTLS_SSL_HELLO_RETRY_REQUEST] = "MBEDTLS_SSL_HELLO_RETRY_REQUEST",
        [MBEDTLS_SSL_ENCRYPTED_EXTENSIONS] = "MBEDTLS_SSL_ENCRYPTED_EXTENSIONS",
        [MBEDTLS_SSL_END_OF_EARLY_DATA] = "MBEDTLS_SSL_END_OF_EARLY_DATA",
        [MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY] = "MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY",
        [MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED] = "MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED",
        [MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO] = "MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO",
        [MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO] = "MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO",
        [MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO] = "MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO",
        [MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST] = "MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST",
        [MBEDTLS_SSL_HANDSHAKE_OVER] = "MBEDTLS_SSL_HANDSHAKE_OVER",
        [MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET] = "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET",
        [MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH] = "MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

variable_types: enum mbedtls_ssl_states { MBEDTLS_SSL_HELLO_REQUEST=0, MBEDTLS_SSL_CLIENT_HELLO=1, MBEDTLS_SSL_SERVER_HELLO=2, MBEDTLS_SSL_SERVER_CERTIFICATE=3, MBEDTLS_SSL_SERVER_KEY_EXCHANGE=4, MBEDTLS_SSL_CERTIFICATE_REQUEST=5, MBEDTLS_SSL_SERVER_HELLO_DONE=6, MBEDTLS_SSL_CLIENT_CERTIFICATE=7, MBEDTLS_SSL_CLIENT_KEY_EXCHANGE=8, MBEDTLS_SSL_CERTIFICATE_VERIFY=9, MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC=10, MBEDTLS_SSL_CLIENT_FINISHED=11, MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC=12, MBEDTLS_SSL_SERVER_FINISHED=13, MBEDTLS_SSL_FLUSH_BUFFERS=14, MBEDTLS_SSL_HANDSHAKE_WRAPUP=15, MBEDTLS_SSL_NEW_SESSION_TICKET=16, MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT=17, MBEDTLS_SSL_HELLO_RETRY_REQUEST=18, MBEDTLS_SSL_ENCRYPTED_EXTENSIONS=19, MBEDTLS_SSL_END_OF_EARLY_DATA=20, MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY=21, MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED=22, MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO=23, MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO=24, MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO=25, MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST=26, MBEDTLS_SSL_HANDSHAKE_OVER=27, MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET=28, MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH=29 }


decompiled_code:
const char *__fastcall mbedtls_ssl_protocol_version_str(unsigned int a1)
{
const char *result; // rax
__int64 v2[774]; // [rsp+0h] [rbp-1830h] BYREF

memset(v2, 0, 0x1828uLL);
v2[0] = (__int64)"MBEDTLS_SSL_VERSION_UNKNOWN";
v2[771] = (__int64)"MBEDTLS_SSL_VERSION_TLS1_2";
v2[772] = (__int64)"MBEDTLS_SSL_VERSION_TLS1_3";
result = "UNKNOWN_VALUE";
if ( a1 <= 0x304 )
{
result = (const char *)v2[a1];
if ( !result )
result = "UNKNOWN_VALUE";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(unsigned int a1)
{
const char *result; // rax
__int64 v2[774]; // [rsp+0h] [rbp-1830h] BYREF

memset(v2, 0, 0x1828uLL);
v2[0] = (__int64)"MBEDTLS_SSL_VERSION_UNKNOWN";
v2[771] = (__int64)"MBEDTLS_SSL_VERSION_TLS1_2";
v2[772] = (__int64)"MBEDTLS_SSL_VERSION_TLS1_3";
result = "UNKNOWN_VALUE";
if ( a1 <= 0x304 )
{
result = (const char *)v2[a1];
if ( !result )
result = "UNKNOWN_VALUE";
}
return result;
}

original_code:
const char *mbedtls_ssl_protocol_version_str( mbedtls_ssl_protocol_version in )
{
    const char * in_to_str[]=
    {
        [MBEDTLS_SSL_VERSION_UNKNOWN] = "MBEDTLS_SSL_VERSION_UNKNOWN",
        [MBEDTLS_SSL_VERSION_TLS1_2] = "MBEDTLS_SSL_VERSION_TLS1_2",
        [MBEDTLS_SSL_VERSION_TLS1_3] = "MBEDTLS_SSL_VERSION_TLS1_3",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

canonical_original_code:
char *mbedtls_ssl_protocol_version_str(enum mbedtls_ssl_protocol_version in)
{
    char *in_to_str[] = {
        [MBEDTLS_SSL_VERSION_UNKNOWN] = "MBEDTLS_SSL_VERSION_UNKNOWN",
        [MBEDTLS_SSL_VERSION_TLS1_2] = "MBEDTLS_SSL_VERSION_TLS1_2",
        [MBEDTLS_SSL_VERSION_TLS1_3] = "MBEDTLS_SSL_VERSION_TLS1_3",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

variable_types: enum mbedtls_ssl_protocol_version { MBEDTLS_SSL_VERSION_UNKNOWN=0, MBEDTLS_SSL_VERSION_TLS1_2=771, MBEDTLS_SSL_VERSION_TLS1_3=772 }


decompiled_code:
const char *__fastcall mbedtls_tls_prf_types_str(unsigned int a1)
{
const char *result; // rax
__int64 v2[6]; // [rsp+0h] [rbp-30h]

v2[0] = (__int64)"MBEDTLS_SSL_TLS_PRF_NONE";
v2[1] = (__int64)"MBEDTLS_SSL_TLS_PRF_SHA384";
v2[2] = (__int64)"MBEDTLS_SSL_TLS_PRF_SHA256";
v2[3] = (__int64)"MBEDTLS_SSL_HKDF_EXPAND_SHA384";
v2[4] = (__int64)"MBEDTLS_SSL_HKDF_EXPAND_SHA256";
result = "UNKNOWN_VALUE";
if ( a1 <= 4 )
{
result = (const char *)v2[a1];
if ( !result )
result = "UNKNOWN_VALUE";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned int a1)
{
const char *result; // rax
__int64 v2[6]; // [rsp+0h] [rbp-30h]

v2[0] = (__int64)"MBEDTLS_SSL_TLS_PRF_NONE";
v2[1] = (__int64)"MBEDTLS_SSL_TLS_PRF_SHA384";
v2[2] = (__int64)"MBEDTLS_SSL_TLS_PRF_SHA256";
v2[3] = (__int64)"MBEDTLS_SSL_HKDF_EXPAND_SHA384";
v2[4] = (__int64)"MBEDTLS_SSL_HKDF_EXPAND_SHA256";
result = "UNKNOWN_VALUE";
if ( a1 <= 4 )
{
result = (const char *)v2[a1];
if ( !result )
result = "UNKNOWN_VALUE";
}
return result;
}

original_code:
const char *mbedtls_tls_prf_types_str( mbedtls_tls_prf_types in )
{
    const char * in_to_str[]=
    {
        [MBEDTLS_SSL_TLS_PRF_NONE] = "MBEDTLS_SSL_TLS_PRF_NONE",
        [MBEDTLS_SSL_TLS_PRF_SHA384] = "MBEDTLS_SSL_TLS_PRF_SHA384",
        [MBEDTLS_SSL_TLS_PRF_SHA256] = "MBEDTLS_SSL_TLS_PRF_SHA256",
        [MBEDTLS_SSL_HKDF_EXPAND_SHA384] = "MBEDTLS_SSL_HKDF_EXPAND_SHA384",
        [MBEDTLS_SSL_HKDF_EXPAND_SHA256] = "MBEDTLS_SSL_HKDF_EXPAND_SHA256",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

canonical_original_code:
char *mbedtls_tls_prf_types_str(enum mbedtls_tls_prf_types in)
{
    char *in_to_str[] = {
        [MBEDTLS_SSL_TLS_PRF_NONE] = "MBEDTLS_SSL_TLS_PRF_NONE",
        [MBEDTLS_SSL_TLS_PRF_SHA384] = "MBEDTLS_SSL_TLS_PRF_SHA384",
        [MBEDTLS_SSL_TLS_PRF_SHA256] = "MBEDTLS_SSL_TLS_PRF_SHA256",
        [MBEDTLS_SSL_HKDF_EXPAND_SHA384] = "MBEDTLS_SSL_HKDF_EXPAND_SHA384",
        [MBEDTLS_SSL_HKDF_EXPAND_SHA256] = "MBEDTLS_SSL_HKDF_EXPAND_SHA256",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

variable_types: enum mbedtls_tls_prf_types { MBEDTLS_SSL_TLS_PRF_NONE=0, MBEDTLS_SSL_TLS_PRF_SHA384=1, MBEDTLS_SSL_TLS_PRF_SHA256=2, MBEDTLS_SSL_HKDF_EXPAND_SHA384=3, MBEDTLS_SSL_HKDF_EXPAND_SHA256=4 }


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

result = "MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET";
if ( a1 )
result = "UNKNOWN_VALUE";
return result;
}

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

result = "MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET";
if ( a1 )
result = "UNKNOWN_VALUE";
return result;
}

original_code:
const char *mbedtls_ssl_key_export_type_str( mbedtls_ssl_key_export_type in )
{
    const char * in_to_str[]=
    {
        [MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET] = "MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

canonical_original_code:
char *mbedtls_ssl_key_export_type_str(enum mbedtls_ssl_key_export_type in)
{
    char *in_to_str[] = {
        [MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET] = "MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET",
    };
    if( in > ( sizeof( in_to_str )/sizeof( in_to_str[0]) - 1 ) ||
        in_to_str[ in ] == ((void *)0) )
    {
        return "UNKNOWN_VALUE";
    }
    return in_to_str[ in ];
}

variable_types: enum mbedtls_ssl_key_export_type { MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET=0 }


decompiled_code:
void __fastcall threading_mutex_init_pthread(pthread_mutex_t *a1)
{
if ( a1 )
a1[1].__size[0] = pthread_mutex_init(a1, 0LL) == 0;
}

canonical_decompiled_code:
void __fastcall func0(pthread_mutex_t *a1)
{
if ( a1 )
a1[1].__size[0] = pthread_mutex_init(a1, 0LL) == 0;
}

original_code:
static void threading_mutex_init_pthread(mbedtls_threading_mutex_t *mutex)
{
    if (mutex == ((void *)0)) {
        return;
    }
    mutex->is_valid = pthread_mutex_init(&mutex->mutex, ((void *)0)) == 0;
}

canonical_original_code:
static void threading_mutex_init_pthread(struct mbedtls_threading_mutex_t *mutex)
{
    if (mutex == ((void *)0)) {
        return;
    }
    mutex->is_valid = pthread_mutex_init(&mutex->mutex, ((void *)0)) == 0;
}

variable_types: struct mbedtls_threading_mutex_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; char is_valid; } *

user_defined_types: struct mbedtls_threading_mutex_t { union pthread_mutex_t mutex; char is_valid; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall threading_mutex_lock_pthread(pthread_mutex_t *a1)
{
int result; // eax

if ( !a1 )
return -28;
if ( !a1[1].__size[0] )
return -28;
result = pthread_mutex_lock(a1);
if ( result )
result = -30;
return result;
}

canonical_decompiled_code:
int __fastcall func2(pthread_mutex_t *a1)
{
int result; // eax

if ( !a1 )
return -28;
if ( !a1[1].__size[0] )
return -28;
result = pthread_mutex_lock(a1);
if ( result )
result = -30;
return result;
}

original_code:
static int threading_mutex_lock_pthread(mbedtls_threading_mutex_t *mutex)
{
    if (mutex == ((void *)0) || !mutex->is_valid) {
        return -0x001C;
    }
    if (pthread_mutex_lock(&mutex->mutex) != 0) {
        return -0x001E;
    }
    return 0;
}

canonical_original_code:
static int threading_mutex_lock_pthread(struct mbedtls_threading_mutex_t *mutex)
{
    if (mutex == ((void *)0) || !mutex->is_valid) {
        return -0x001C;
    }
    if (pthread_mutex_lock(&mutex->mutex) != 0) {
        return -0x001E;
    }
    return 0;
}

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
int __fastcall threading_mutex_unlock_pthread(pthread_mutex_t *a1)
{
int result; // eax

if ( !a1 )
return -28;
if ( !a1[1].__size[0] )
return -28;
result = pthread_mutex_unlock(a1);
if ( result )
result = -30;
return result;
}

canonical_decompiled_code:
int __fastcall func3(pthread_mutex_t *a1)
{
int result; // eax

if ( !a1 )
return -28;
if ( !a1[1].__size[0] )
return -28;
result = pthread_mutex_unlock(a1);
if ( result )
result = -30;
return result;
}

original_code:
static int threading_mutex_unlock_pthread(mbedtls_threading_mutex_t *mutex)
{
    if (mutex == ((void *)0) || !mutex->is_valid) {
        return -0x001C;
    }
    if (pthread_mutex_unlock(&mutex->mutex) != 0) {
        return -0x001E;
    }
    return 0;
}

canonical_original_code:
static int threading_mutex_unlock_pthread(struct mbedtls_threading_mutex_t *mutex)
{
    if (mutex == ((void *)0) || !mutex->is_valid) {
        return -0x001C;
    }
    if (pthread_mutex_unlock(&mutex->mutex) != 0) {
        return -0x001E;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall rsa_can_do(int a1)
{
return (a1 == 6) | (unsigned __int8)(a1 == 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (a1 == 6) | (unsigned __int8)(a1 == 1);
}

original_code:
static int rsa_can_do(mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_RSA ||
           type == MBEDTLS_PK_RSASSA_PSS;
}

canonical_original_code:
static int rsa_can_do(enum mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_RSA ||
           type == MBEDTLS_PK_RSASSA_PSS;
}

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


original_code:
static void rsa_debug(const void *ctx, mbedtls_pk_debug_item *items)
{
    items->type = MBEDTLS_PK_DEBUG_MPI;
    items->name = "rsa.N";
    items->value = &(((mbedtls_rsa_context *) ctx)->N);
    items++;
    items->type = MBEDTLS_PK_DEBUG_MPI;
    items->name = "rsa.E";
    items->value = &(((mbedtls_rsa_context *) ctx)->E);
}

canonical_original_code:
static void rsa_debug(void *ctx, struct mbedtls_pk_debug_item *items)
{
    items->type = MBEDTLS_PK_DEBUG_MPI;
    items->name = "rsa.N";
    items->value = &(((struct mbedtls_rsa_context *) ctx)->N);
    items++;
    items->type = MBEDTLS_PK_DEBUG_MPI;
    items->name = "rsa.E";
    items->value = &(((struct mbedtls_rsa_context *) ctx)->E);
}

variable_types: struct mbedtls_pk_debug_item { enum mbedtls_pk_debug_type { MBEDTLS_PK_DEBUG_NONE=0, MBEDTLS_PK_DEBUG_MPI=1, MBEDTLS_PK_DEBUG_ECP=2 } type; char *name; void *value; } *

user_defined_types: struct mbedtls_pk_debug_item { enum mbedtls_pk_debug_type type; char *name; void *value; }

user_defined_types: struct mbedtls_rsa_context { int ver; unsigned long len; struct mbedtls_mpi N; struct mbedtls_mpi E; struct mbedtls_mpi D; struct mbedtls_mpi P; struct mbedtls_mpi Q; struct mbedtls_mpi DP; struct mbedtls_mpi DQ; struct mbedtls_mpi QP; struct mbedtls_mpi RN; struct mbedtls_mpi RP; struct mbedtls_mpi RQ; struct mbedtls_mpi Vi; struct mbedtls_mpi Vf; int padding; int hash_id; struct mbedtls_threading_mutex_t mutex; }

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


decompiled_code:
_BOOL8 __fastcall eckey_can_do(int a1)
{
return (unsigned int)(a1 - 2) <= 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
return (unsigned int)(a1 - 2) <= 2;
}

original_code:
static int eckey_can_do(mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_ECKEY ||
           type == MBEDTLS_PK_ECKEY_DH ||
           type == MBEDTLS_PK_ECDSA;
}

canonical_original_code:
static int eckey_can_do(enum mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_ECKEY ||
           type == MBEDTLS_PK_ECKEY_DH ||
           type == MBEDTLS_PK_ECDSA;
}

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:
__int64 __fastcall eckey_get_bitlen(__int64 a1)
{
return *(_QWORD *)(a1 + 176);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 176);
}

original_code:
static size_t eckey_get_bitlen(const void *ctx)
{
    return ((mbedtls_ecp_keypair *) ctx)->grp.pbits;
}

canonical_original_code:
static unsigned long eckey_get_bitlen(void *ctx)
{
    return ((struct mbedtls_ecp_keypair *) ctx)->grp.pbits;
}

return_type: unsigned long

user_defined_types: struct mbedtls_ecp_keypair { struct mbedtls_ecp_group grp; struct mbedtls_mpi d; struct mbedtls_ecp_point Q; }

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

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

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


original_code:
static void eckey_debug(const void *ctx, mbedtls_pk_debug_item *items)
{
    items->type = MBEDTLS_PK_DEBUG_ECP;
    items->name = "eckey.Q";
    items->value = &(((mbedtls_ecp_keypair *) ctx)->Q);
}

canonical_original_code:
static void eckey_debug(void *ctx, struct mbedtls_pk_debug_item *items)
{
    items->type = MBEDTLS_PK_DEBUG_ECP;
    items->name = "eckey.Q";
    items->value = &(((struct mbedtls_ecp_keypair *) ctx)->Q);
}

user_defined_types: enum mbedtls_pk_debug_type { MBEDTLS_PK_DEBUG_NONE=0, MBEDTLS_PK_DEBUG_MPI=1, MBEDTLS_PK_DEBUG_ECP=2 }


decompiled_code:
_BOOL8 __fastcall eckeydh_can_do(int a1)
{
return (unsigned int)(a1 - 2) <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1)
{
return (unsigned int)(a1 - 2) <= 1;
}

original_code:
static int eckeydh_can_do(mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_ECKEY ||
           type == MBEDTLS_PK_ECKEY_DH;
}

canonical_original_code:
static int eckeydh_can_do(enum mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_ECKEY ||
           type == MBEDTLS_PK_ECKEY_DH;
}


decompiled_code:
_BOOL8 __fastcall ecdsa_can_do(int a1)
{
return a1 == 4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(int a1)
{
return a1 == 4;
}

original_code:
static int ecdsa_can_do(mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_ECDSA;
}

canonical_original_code:
static int ecdsa_can_do(enum mbedtls_pk_type_t type)
{
    return type == MBEDTLS_PK_ECDSA;
}


decompiled_code:
void __fastcall rsa_free_wrap(void *ptr)
{
mbedtls_rsa_free();
free(ptr);
}

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

original_code:
static void rsa_free_wrap(void *ctx)
{
    mbedtls_rsa_free((mbedtls_rsa_context *) ctx);
    free(ctx);
}

canonical_original_code:
static void rsa_free_wrap(void *ctx)
{
    mbedtls_rsa_free((struct mbedtls_rsa_context *) ctx);
    free(ctx);
}


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

v0 = calloc(1uLL, 0x180uLL);
v1 = v0;
if ( v0 )
mbedtls_rsa_init(v0);
return v1;
}

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

v0 = calloc(1uLL, 0x180uLL);
v1 = v0;
if ( v0 )
mbedtls_rsa_init(v0);
return v1;
}

original_code:
static void *rsa_alloc_wrap(void)
{
    void *ctx = calloc(1, sizeof(mbedtls_rsa_context));
    if (ctx != ((void *)0)) {
        mbedtls_rsa_init((mbedtls_rsa_context *) ctx);
    }
    return ctx;
}

canonical_original_code:
static void *rsa_alloc_wrap()
{
    void *ctx = calloc(1, sizeof(mbedtls_rsa_context));
    if (ctx != ((void *)0)) {
        mbedtls_rsa_init((struct mbedtls_rsa_context *) ctx);
    }
    return ctx;
}

return_type: void *


decompiled_code:
__int64 rsa_check_pair_wrap()
{
return mbedtls_rsa_check_pub_priv();
}

canonical_decompiled_code:
__int64 func9()
{
return mbedtls_rsa_check_pub_priv();
}

original_code:
static int rsa_check_pair_wrap(const void *pub, const void *prv,
                               int (*f_rng)(void *, unsigned char *, size_t),
                               void *p_rng)
{
    (void) f_rng;
    (void) p_rng;
    return mbedtls_rsa_check_pub_priv((const mbedtls_rsa_context *) pub,
                                      (const mbedtls_rsa_context *) prv);
}

canonical_original_code:
static int rsa_check_pair_wrap(void *pub, void *prv, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    (void) f_rng;
    (void) p_rng;
    return mbedtls_rsa_check_pub_priv((struct mbedtls_rsa_context *) pub,
                                      (struct mbedtls_rsa_context *) prv);
}

variable_types:
pub
void *

variable_types:
prv
void *

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


decompiled_code:
__int64 rsa_get_bitlen()
{
return 8 * mbedtls_rsa_get_len();
}

canonical_decompiled_code:
__int64 func10()
{
return 8 * mbedtls_rsa_get_len();
}

original_code:
static size_t rsa_get_bitlen(const void *ctx)
{
    const mbedtls_rsa_context *rsa = (const mbedtls_rsa_context *) ctx;
    return 8 * mbedtls_rsa_get_len(rsa);
}

canonical_original_code:
static unsigned long rsa_get_bitlen(void *ctx)
{
    struct mbedtls_rsa_context *rsa = (const mbedtls_rsa_context *) ctx;
    return 8 * mbedtls_rsa_get_len(rsa);
}

variable_types:
ctx
void *

variable_types: struct mbedtls_rsa_context { int ver; unsigned long len; struct mbedtls_mpi { int s; unsigned long n; unsigned long *p; } N; struct mbedtls_mpi E; struct mbedtls_mpi D; struct mbedtls_mpi P; struct mbedtls_mpi Q; struct mbedtls_mpi DP; struct mbedtls_mpi DQ; struct mbedtls_mpi QP; struct mbedtls_mpi RN; struct mbedtls_mpi RP; struct mbedtls_mpi RQ; struct mbedtls_mpi Vi; struct mbedtls_mpi Vf; int padding; int hash_id; struct mbedtls_threading_mutex_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; char is_valid; } mutex; } *


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

v12 = mbedtls_rsa_get_len();
*a5 = v12;
if ( v12 > a6 )
result = 4294949888LL;
else
result = mbedtls_rsa_pkcs1_encrypt(a1, a7, a8, a3, a2, a4);
return result;
}

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

v12 = mbedtls_rsa_get_len();
*a5 = v12;
if ( v12 > a6 )
result = 4294949888LL;
else
result = mbedtls_rsa_pkcs1_encrypt(a1, a7, a8, a3, a2, a4);
return result;
}

original_code:
static int rsa_encrypt_wrap(void *ctx,
                            const unsigned char *input, size_t ilen,
                            unsigned char *output, size_t *olen, size_t osize,
                            int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
{
    mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    *olen = mbedtls_rsa_get_len(rsa);
    if (*olen > osize) {
        return -0x4400;
    }
    return mbedtls_rsa_pkcs1_encrypt(rsa, f_rng, p_rng,
                                     ilen, input, output);
}

canonical_original_code:
static int rsa_encrypt_wrap(void *ctx, unsigned char *input, unsigned long ilen, unsigned char *output, unsigned long *olen, unsigned long osize, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    struct mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    *olen = mbedtls_rsa_get_len(rsa);
    if (*olen > osize) {
        return -0x4400;
    }
    return mbedtls_rsa_pkcs1_encrypt(rsa, f_rng, p_rng,
                                     ilen, input, output);
}

variable_types:
input
unsigned char *

variable_types:
ilen
unsigned long

variable_types:
output
unsigned char *

variable_types:
olen
unsigned long *

variable_types:
osize
unsigned long


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

if ( mbedtls_rsa_get_len() == a3 )
result = mbedtls_rsa_pkcs1_decrypt(a1, a7, a8, a5, a2, a4, a6);
else
result = 4294950784LL;
return result;
}

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

if ( mbedtls_rsa_get_len() == a3 )
result = mbedtls_rsa_pkcs1_decrypt(a1, a7, a8, a5, a2, a4, a6);
else
result = 4294950784LL;
return result;
}

original_code:
static int rsa_decrypt_wrap(void *ctx,
                            const unsigned char *input, size_t ilen,
                            unsigned char *output, size_t *olen, size_t osize,
                            int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
{
    mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    if (ilen != mbedtls_rsa_get_len(rsa)) {
        return -0x4080;
    }
    return mbedtls_rsa_pkcs1_decrypt(rsa, f_rng, p_rng,
                                     olen, input, output, osize);
}

canonical_original_code:
static int rsa_decrypt_wrap(void *ctx, unsigned char *input, unsigned long ilen, unsigned char *output, unsigned long *olen, unsigned long osize, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    struct mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    if (ilen != mbedtls_rsa_get_len(rsa)) {
        return -0x4080;
    }
    return mbedtls_rsa_pkcs1_decrypt(rsa, f_rng, p_rng,
                                     olen, input, output, osize);
}


decompiled_code:
__int64 __fastcall rsa_sign_wrap(__int64 a1, unsigned int a2, __int64 a3, unsigned __int64 a4, __int64 a5, unsigned __int64 a6, unsigned __int64 *a7, __int64 a8, __int64 a9)
{
unsigned int v10; // er12
unsigned __int64 v13; // rax
__int64 result; // rax

v10 = a4;
if ( !a2 && a4 > 0xFFFFFFFF )
return 4294951296LL;
v13 = mbedtls_rsa_get_len(a1);
*a7 = v13;
if ( v13 > a6 )
result = 4294952832LL;
else
result = mbedtls_rsa_pkcs1_sign(a1, a8, a9, a2, v10, a3, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, __int64 a3, unsigned __int64 a4, __int64 a5, unsigned __int64 a6, unsigned __int64 *a7, __int64 a8, __int64 a9)
{
unsigned int v10; // er12
unsigned __int64 v13; // rax
__int64 result; // rax

v10 = a4;
if ( !a2 && a4 > 0xFFFFFFFF )
return 4294951296LL;
v13 = mbedtls_rsa_get_len(a1);
*a7 = v13;
if ( v13 > a6 )
result = 4294952832LL;
else
result = mbedtls_rsa_pkcs1_sign(a1, a8, a9, a2, v10, a3, a5);
return result;
}

original_code:
static int rsa_sign_wrap(void *ctx, mbedtls_md_type_t md_alg,
                         const unsigned char *hash, size_t hash_len,
                         unsigned char *sig, size_t sig_size, size_t *sig_len,
                         int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
{
    mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    if (md_alg == MBEDTLS_MD_NONE && (0x7fffffff * 2U + 1U) < hash_len) {
        return -0x3E80;
    }
    *sig_len = mbedtls_rsa_get_len(rsa);
    if (sig_size < *sig_len) {
        return -0x3880;
    }
    return mbedtls_rsa_pkcs1_sign(rsa, f_rng, p_rng,
                                  md_alg, (unsigned int) hash_len,
                                  hash, sig);
}

canonical_original_code:
static int rsa_sign_wrap(void *ctx, enum mbedtls_md_type_t md_alg, unsigned char *hash, unsigned long hash_len, unsigned char *sig, unsigned long sig_size, unsigned long *sig_len, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    struct mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    if (md_alg == MBEDTLS_MD_NONE && (0x7fffffff * 2U + 1U) < hash_len) {
        return -0x3E80;
    }
    *sig_len = mbedtls_rsa_get_len(rsa);
    if (sig_size < *sig_len) {
        return -0x3880;
    }
    return mbedtls_rsa_pkcs1_sign(rsa, f_rng, p_rng,
                                  md_alg, (unsigned int) hash_len,
                                  hash, sig);
}

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

variable_types:
hash
unsigned char *

variable_types:
sig
unsigned char *


decompiled_code:
__int64 __fastcall rsa_verify_wrap(__int64 a1, unsigned int a2, __int64 a3, unsigned __int64 a4, __int64 a5, unsigned __int64 a6)
{
unsigned __int64 v9; // r13
__int64 result; // rax

v9 = mbedtls_rsa_get_len(a1);
if ( !a2 && a4 > 0xFFFFFFFF )
return 4294951296LL;
if ( v9 > a6 )
return 4294950016LL;
result = mbedtls_rsa_pkcs1_verify(a1, a2, (unsigned int)a4, a3, a5);
if ( !(_DWORD)result && v9 < a6 )
result = 4294952704LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2, __int64 a3, unsigned __int64 a4, __int64 a5, unsigned __int64 a6)
{
unsigned __int64 v9; // r13
__int64 result; // rax

v9 = mbedtls_rsa_get_len(a1);
if ( !a2 && a4 > 0xFFFFFFFF )
return 4294951296LL;
if ( v9 > a6 )
return 4294950016LL;
result = mbedtls_rsa_pkcs1_verify(a1, a2, (unsigned int)a4, a3, a5);
if ( !(_DWORD)result && v9 < a6 )
result = 4294952704LL;
return result;
}

original_code:
static int rsa_verify_wrap(void *ctx, mbedtls_md_type_t md_alg,
                           const unsigned char *hash, size_t hash_len,
                           const unsigned char *sig, size_t sig_len)
{
    int ret = -0x006E;
    mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    size_t rsa_len = mbedtls_rsa_get_len(rsa);
    if (md_alg == MBEDTLS_MD_NONE && (0x7fffffff * 2U + 1U) < hash_len) {
        return -0x3E80;
    }
    if (sig_len < rsa_len) {
        return -0x4380;
    }
    if ((ret = mbedtls_rsa_pkcs1_verify(rsa, md_alg,
                                        (unsigned int) hash_len,
                                        hash, sig)) != 0) {
        return ret;
    }
    if (sig_len > rsa_len) {
        return -0x3900;
    }
    return 0;
}

canonical_original_code:
static int rsa_verify_wrap(void *ctx, enum mbedtls_md_type_t md_alg, unsigned char *hash, unsigned long hash_len, unsigned char *sig, unsigned long sig_len)
{
    int ret = -0x006E;
    struct mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) ctx;
    unsigned long rsa_len = mbedtls_rsa_get_len(rsa);
    if (md_alg == MBEDTLS_MD_NONE && (0x7fffffff * 2U + 1U) < hash_len) {
        return -0x3E80;
    }
    if (sig_len < rsa_len) {
        return -0x4380;
    }
    if ((ret = mbedtls_rsa_pkcs1_verify(rsa, md_alg,
                                        (unsigned int) hash_len,
                                        hash, sig)) != 0) {
        return ret;
    }
    if (sig_len > rsa_len) {
        return -0x3900;
    }
    return 0;
}

variable_types: ret int

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


decompiled_code:
void __fastcall eckey_free_wrap(void *ptr)
{
mbedtls_ecp_keypair_free();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
mbedtls_ecp_keypair_free();
free(ptr);
}

original_code:
static void eckey_free_wrap(void *ctx)
{
    mbedtls_ecp_keypair_free((mbedtls_ecp_keypair *) ctx);
    free(ctx);
}

canonical_original_code:
static void eckey_free_wrap(void *ctx)
{
    mbedtls_ecp_keypair_free((struct mbedtls_ecp_keypair *) ctx);
    free(ctx);
}


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

v0 = calloc(1uLL, 0x158uLL);
v1 = v0;
if ( v0 )
mbedtls_ecp_keypair_init(v0);
return v1;
}

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

v0 = calloc(1uLL, 0x158uLL);
v1 = v0;
if ( v0 )
mbedtls_ecp_keypair_init(v0);
return v1;
}

original_code:
static void *eckey_alloc_wrap(void)
{
    void *ctx = calloc(1, sizeof(mbedtls_ecp_keypair));
    if (ctx != ((void *)0)) {
        mbedtls_ecp_keypair_init(ctx);
    }
    return ctx;
}

canonical_original_code:
static void *eckey_alloc_wrap()
{
    void *ctx = calloc(1, sizeof(mbedtls_ecp_keypair));
    if (ctx != ((void *)0)) {
        mbedtls_ecp_keypair_init(ctx);
    }
    return ctx;
}


decompiled_code:
__int64 eckey_check_pair()
{
return mbedtls_ecp_check_pub_priv();
}

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

original_code:
static int eckey_check_pair(const void *pub, const void *prv,
                            int (*f_rng)(void *, unsigned char *, size_t),
                            void *p_rng)
{
    return mbedtls_ecp_check_pub_priv((const mbedtls_ecp_keypair *) pub,
                                      (const mbedtls_ecp_keypair *) prv,
                                      f_rng, p_rng);
}

canonical_original_code:
static int eckey_check_pair(void *pub, void *prv, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    return mbedtls_ecp_check_pub_priv((struct mbedtls_ecp_keypair *) pub,
                                      (struct mbedtls_ecp_keypair *) prv,
                                      f_rng, p_rng);
}


decompiled_code:
__int64 __fastcall ecdsa_sign_wrap(__int64 a1, __int64 a2, __int64 a3)
{
return mbedtls_ecdsa_write_signature(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2, __int64 a3)
{
return mbedtls_ecdsa_write_signature(a1, a2, a3);
}

original_code:
static int ecdsa_sign_wrap(void *ctx, mbedtls_md_type_t md_alg,
                           const unsigned char *hash, size_t hash_len,
                           unsigned char *sig, size_t sig_size, size_t *sig_len,
                           int (*f_rng)(void *, unsigned char *, size_t), void *p_rng)
{
    return mbedtls_ecdsa_write_signature((mbedtls_ecdsa_context *) ctx,
                                         md_alg, hash, hash_len,
                                         sig, sig_size, sig_len,
                                         f_rng, p_rng);
}

canonical_original_code:
static int ecdsa_sign_wrap(void *ctx, enum mbedtls_md_type_t md_alg, unsigned char *hash, unsigned long hash_len, unsigned char *sig, unsigned long sig_size, unsigned long *sig_len, int (*f_rng)(void *, unsigned char *, unsigned long), void *p_rng)
{
    return mbedtls_ecdsa_write_signature((struct mbedtls_ecp_keypair *) ctx,
                                         md_alg, hash, hash_len,
                                         sig, sig_size, sig_len,
                                         f_rng, p_rng);
}


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

result = mbedtls_ecdsa_read_signature(a1, a3, a4, a5, a6);
if ( (_DWORD)result == -19456 )
result = 4294952704LL;
return result;
}

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

result = mbedtls_ecdsa_read_signature(a1, a3, a4, a5, a6);
if ( (_DWORD)result == -19456 )
result = 4294952704LL;
return result;
}

original_code:
static int ecdsa_verify_wrap(void *ctx, mbedtls_md_type_t md_alg,
                             const unsigned char *hash, size_t hash_len,
                             const unsigned char *sig, size_t sig_len)
{
    int ret = -0x006E;
    ((void) md_alg);
    ret = mbedtls_ecdsa_read_signature((mbedtls_ecdsa_context *) ctx,
                                       hash, hash_len, sig, sig_len);
    if (ret == -0x4C00) {
        return -0x3900;
    }
    return ret;
}

canonical_original_code:
static int ecdsa_verify_wrap(void *ctx, enum mbedtls_md_type_t md_alg, unsigned char *hash, unsigned long hash_len, unsigned char *sig, unsigned long sig_len)
{
    int ret = -0x006E;
    ((void) md_alg);
    ret = mbedtls_ecdsa_read_signature((struct mbedtls_ecp_keypair *) ctx,
                                       hash, hash_len, sig, sig_len);
    if (ret == -0x4C00) {
        return -0x3900;
    }
    return ret;
}