decompiled_code:
__int64 __fastcall version_main(int a1, __int64 a2)
{
_BOOL4 v3; // edi
_QWORD *v4; // rax
unsigned int v5; // er12
int v6; // er14
__int64 v7; // rsi
int v8; // er13
int v9; // ebx
int v10; // ebp
_BYTE *v11; // rdx
const char *v13; // rax
const char *v14; // rax
const char *v15; // rax
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
const char *v19; // rax
const char *v20; // rax
const char *v21; // rax
const char *v22; // rax
__int64 v23; // rax
const char *v24; // rax

signal(13, (__sighandler_t)((char *)version_main + 1));
if ( !bio_err )
{
v23 = BIO_s_file();
bio_err = BIO_new(v23);
if ( bio_err )
BIO_ctrl(bio_err, 106LL, 16LL, stderr);
}
v3 = a1 == 1;
if ( a1 > 1 )
{
v4 = (_QWORD *)(a2 + 8);
v5 = 0;
v6 = 0;
v7 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
v8 = 0;
v9 = 0;
v10 = 0;
while ( 1 )
{
v11 = (_BYTE *)*v4;
if ( *(_BYTE *)*v4 != 45 )
{
LABEL_5:
v5 = 1;
BIO_printf(bio_err, "usage:version -[avbofpd]\n");
return v5;
}
if ( v11[1] != 118 || v11[2] )
{
if ( v11[1] != 98 || v11[2] )
{
if ( v11[1] != 102 || v11[2] )
{
if ( v11[1] == 111 && !v11[2] )
{
v8 = 1;
goto LABEL_18;
}
if ( v11[1] == 112 && !v11[2] )
{
v6 = 1;
goto LABEL_18;
}
if ( v11[1] == 100 )
{
v5 = 1;
if ( !v11[2] )
goto LABEL_18;
}
if ( v11[1] != 97 || v11[2] )
goto LABEL_5;
v5 = 1;
v6 = 1;
v8 = 1;
v9 = 1;
v3 = 1;
}
v10 = 1;
}
else
{
v9 = 1;
}
}
else
{
v3 = 1;
}
LABEL_18:
if ( ++v4 == (_QWORD *)v7 )
{
if ( !v3 )
goto LABEL_20;
goto LABEL_40;
}
}
}
v5 = 0;
if ( a1 != 1 )
return v5;
v6 = 0;
v10 = 0;
v8 = 0;
v9 = 0;
LABEL_40:
if ( SSLeay() == 268439775 )
{
v24 = (const char *)SSLeay_version(0LL);
puts(v24);
}
else
{
v22 = (const char *)SSLeay_version(0LL);
printf("%s (Library: %s)\n", "OpenSSL 1.0.1m 19 Mar 2015", v22);
}
LABEL_20:
if ( v9 )
{
v13 = (const char *)SSLeay_version(3LL);
puts(v13);
}
if ( v6 )
{
v14 = (const char *)SSLeay_version(4LL);
puts(v14);
}
if ( v8 )
{
printf("options: ");
v15 = (const char *)BN_options();
printf("%s ", v15);
v16 = (const char *)RC4_options();
printf("%s ", v16);
v17 = (const char *)DES_options();
printf("%s ", v17);
v18 = (const char *)idea_options();
printf("%s ", v18);
v19 = (const char *)BF_options();
printf("%s ", v19);
putchar(10);
}
if ( v10 )
{
v20 = (const char *)SSLeay_version(2LL);
puts(v20);
}
if ( !v5 )
return v5;
v21 = (const char *)SSLeay_version(5LL);
puts(v21);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
_BOOL4 v3; // edi
_QWORD *v4; // rax
unsigned int v5; // er12
int v6; // er14
__int64 v7; // rsi
int v8; // er13
int v9; // ebx
int v10; // ebp
_BYTE *v11; // rdx
const char *v13; // rax
const char *v14; // rax
const char *v15; // rax
const char *v16; // rax
const char *v17; // rax
const char *v18; // rax
const char *v19; // rax
const char *v20; // rax
const char *v21; // rax
const char *v22; // rax
__int64 v23; // rax
const char *v24; // rax

signal(13, (__sighandler_t)((char *)version_main + 1));
if ( !bio_err )
{
v23 = BIO_s_file();
bio_err = BIO_new(v23);
if ( bio_err )
BIO_ctrl(bio_err, 106LL, 16LL, stderr);
}
v3 = a1 == 1;
if ( a1 > 1 )
{
v4 = (_QWORD *)(a2 + 8);
v5 = 0;
v6 = 0;
v7 = a2 + 8LL * (unsigned int)(a1 - 2) + 16;
v8 = 0;
v9 = 0;
v10 = 0;
while ( 1 )
{
v11 = (_BYTE *)*v4;
if ( *(_BYTE *)*v4 != 45 )
{
LABEL_5:
v5 = 1;
BIO_printf(bio_err, "usage:version -[avbofpd]\n");
return v5;
}
if ( v11[1] != 118 || v11[2] )
{
if ( v11[1] != 98 || v11[2] )
{
if ( v11[1] != 102 || v11[2] )
{
if ( v11[1] == 111 && !v11[2] )
{
v8 = 1;
goto LABEL_18;
}
if ( v11[1] == 112 && !v11[2] )
{
v6 = 1;
goto LABEL_18;
}
if ( v11[1] == 100 )
{
v5 = 1;
if ( !v11[2] )
goto LABEL_18;
}
if ( v11[1] != 97 || v11[2] )
goto LABEL_5;
v5 = 1;
v6 = 1;
v8 = 1;
v9 = 1;
v3 = 1;
}
v10 = 1;
}
else
{
v9 = 1;
}
}
else
{
v3 = 1;
}
LABEL_18:
if ( ++v4 == (_QWORD *)v7 )
{
if ( !v3 )
goto LABEL_20;
goto LABEL_40;
}
}
}
v5 = 0;
if ( a1 != 1 )
return v5;
v6 = 0;
v10 = 0;
v8 = 0;
v9 = 0;
LABEL_40:
if ( SSLeay() == 268439775 )
{
v24 = (const char *)SSLeay_version(0LL);
puts(v24);
}
else
{
v22 = (const char *)SSLeay_version(0LL);
printf("%s (Library: %s)\n", "OpenSSL 1.0.1m 19 Mar 2015", v22);
}
LABEL_20:
if ( v9 )
{
v13 = (const char *)SSLeay_version(3LL);
puts(v13);
}
if ( v6 )
{
v14 = (const char *)SSLeay_version(4LL);
puts(v14);
}
if ( v8 )
{
printf("options: ");
v15 = (const char *)BN_options();
printf("%s ", v15);
v16 = (const char *)RC4_options();
printf("%s ", v16);
v17 = (const char *)DES_options();
printf("%s ", v17);
v18 = (const char *)idea_options();
printf("%s ", v18);
v19 = (const char *)BF_options();
printf("%s ", v19);
putchar(10);
}
if ( v10 )
{
v20 = (const char *)SSLeay_version(2LL);
puts(v20);
}
if ( !v5 )
return v5;
v21 = (const char *)SSLeay_version(5LL);
puts(v21);
return 0LL;
}

original_code:
int version_main(int argc,char **argv)
{
    int i, ret = 0;
    int cflags = 0, version = 0, date = 0, options = 0, platform = 0, dir = 0;
    signal(13,((__sighandler_t) 1));
    if (bio_err == ((void *)0))
        if ((bio_err = BIO_new(BIO_s_file())) != ((void *)0))
            BIO_ctrl(bio_err,106,0x00 | 0x10,(char *)stderr);
    if (argc == 1)
        version = 1;
    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-v") == 0)
            version = 1;
        else if (strcmp(argv[i], "-b") == 0)
            date = 1;
        else if (strcmp(argv[i], "-f") == 0)
            cflags = 1;
        else if (strcmp(argv[i], "-o") == 0)
            options = 1;
        else if (strcmp(argv[i], "-p") == 0)
            platform = 1;
        else if (strcmp(argv[i], "-d") == 0)
            dir = 1;
        else if (strcmp(argv[i], "-a") == 0)
            date = version = cflags = options = platform = dir = 1;
        else {
            BIO_printf(bio_err, "usage:version -[avbofpd]\n");
            ret = 1;
            goto end;
        }
    }
    if (version) {
        if (SSLeay() == 0x100010dfL) {
            printf("%s\n", SSLeay_version(0));
        } else {
            printf("%s (Library: %s)\n",
                   "OpenSSL 1.0.1m 19 Mar 2015", SSLeay_version(0));
        }
    }
    if (date)
        printf("%s\n", SSLeay_version(3));
    if (platform)
        printf("%s\n", SSLeay_version(4));
    if (options) {
        printf("options:  ");
        printf("%s ", BN_options());
        printf("%s ", RC4_options());
        printf("%s ", DES_options());
        printf("%s ", idea_options());
        printf("%s ", BF_options());
        printf("\n");
    }
    if (cflags)
        printf("%s\n", SSLeay_version(2));
    if (dir)
        printf("%s\n", SSLeay_version(5));
 end:
    ;
    return(ret);
}

canonical_original_code:
int version_main(int argc, char **argv)
{
    int i; int ret = 0;
    int cflags = 0; int version = 0; int date = 0; int options = 0; int platform = 0; int dir = 0;
    signal(13,((void (*)(int)) 1));
    if (bio_err == ((void *)0))
        if ((bio_err = BIO_new(BIO_s_file())) != ((void *)0))
            BIO_ctrl(bio_err,106,0x00 | 0x10,(char *)stderr);
    if (argc == 1)
        version = 1;
    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-v") == 0)
            version = 1;
        else if (strcmp(argv[i], "-b") == 0)
            date = 1;
        else if (strcmp(argv[i], "-f") == 0)
            cflags = 1;
        else if (strcmp(argv[i], "-o") == 0)
            options = 1;
        else if (strcmp(argv[i], "-p") == 0)
            platform = 1;
        else if (strcmp(argv[i], "-d") == 0)
            dir = 1;
        else if (strcmp(argv[i], "-a") == 0)
            date = version = cflags = options = platform = dir = 1;
        else {
            BIO_printf(bio_err, "usage:version -[avbofpd]\n");
            ret = 1;
            goto end;
        }
    }
    if (version) {
        if (SSLeay() == 0x100010dfL) {
            printf("%s\n", SSLeay_version(0));
        } else {
            printf("%s (Library: %s)\n",
                   "OpenSSL 1.0.1m 19 Mar 2015", SSLeay_version(0));
        }
    }
    if (date)
        printf("%s\n", SSLeay_version(3));
    if (platform)
        printf("%s\n", SSLeay_version(4));
    if (options) {
        printf("options:  ");
        printf("%s ", BN_options());
        printf("%s ", RC4_options());
        printf("%s ", DES_options());
        printf("%s ", idea_options());
        printf("%s ", BF_options());
        printf("\n");
    }
    if (cflags)
        printf("%s\n", SSLeay_version(2));
    if (dir)
        printf("%s\n", SSLeay_version(5));
 end:
    ;
    return(ret);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: ret int

variable_types: cflags int

variable_types: version int

variable_types: date int

variable_types: options int

variable_types: platform int

variable_types: dir int


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

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

original_code:
static int sig_sk_cmp(const nid_triple *const *a, const nid_triple *const *b)
{
    return (*a)->sign_id - (*b)->sign_id;
}

canonical_original_code:
static int sig_sk_cmp(struct nid_triple **a, struct nid_triple **b)
{
    return (*a)->sign_id - (*b)->sign_id;
}

variable_types: struct nid_triple { int sign_id; int hash_id; int pkey_id; } **

variable_types:
b
struct nid_triple **

return_type: int


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

result = (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL) - *(_DWORD *)(*(_QWORD *)a2 + 4LL));
if ( !(_DWORD)result )
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 8LL) - *(_DWORD *)(*(_QWORD *)a2 + 8LL));
return result;
}

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

result = (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL) - *(_DWORD *)(*(_QWORD *)a2 + 4LL));
if ( !(_DWORD)result )
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 8LL) - *(_DWORD *)(*(_QWORD *)a2 + 8LL));
return result;
}

original_code:
static int sigx_cmp(const nid_triple *const *a, const nid_triple *const *b)
{
    int ret;
    ret = (*a)->hash_id - (*b)->hash_id;
    if (ret)
        return ret;
    return (*a)->pkey_id - (*b)->pkey_id;
}

canonical_original_code:
static int sigx_cmp(struct nid_triple **a, struct nid_triple **b)
{
    int ret;
    ret = (*a)->hash_id - (*b)->hash_id;
    if (ret)
        return ret;
    return (*a)->pkey_id - (*b)->pkey_id;
}

user_defined_types: struct nid_triple { int sign_id; int hash_id; int pkey_id; }


decompiled_code:
// attributes: thunk
__int64 __fastcall sigx_cmp_BSEARCH_CMP_FN(__int64 a1, __int64 a2)
{
return sigx_cmp(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return func1(a1, a2);
}

original_code: static int sigx_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) { const nid_triple * const *a = a_; const nid_triple * const *b = b_; return sigx_cmp(a,b); }

canonical_original_code: static int sigx_cmp_BSEARCH_CMP_FN(void *a_, void *b_) { struct nid_triple **a = a_; struct nid_triple **b = b_; return sigx_cmp(a,b); }


decompiled_code:
// attributes: thunk
__int64 sid_free()
{
return CRYPTO_free();
}

canonical_decompiled_code:
__int64 func3()
{
return CRYPTO_free();
}

original_code:
static void sid_free(nid_triple *tt)
{
    CRYPTO_free(tt);
}

canonical_original_code:
static void sid_free(struct nid_triple *tt)
{
    CRYPTO_free(tt);
}

variable_types: struct nid_triple { int sign_id; int hash_id; int pkey_id; } *

return_type: void


decompiled_code:
__int64 __fastcall sig_cmp_BSEARCH_CMP_FN(int *a1, int *a2)
{
return sig_cmp_isra_0(*a1, *a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1, int *a2)
{
return func6(*a1, *a2);
}

original_code: static int sig_cmp_BSEARCH_CMP_FN(const void *a_, const void *b_) { nid_triple const *a = a_; nid_triple const *b = b_; return sig_cmp(a,b); }

canonical_original_code: static int sig_cmp_BSEARCH_CMP_FN(void *a_, void *b_) { struct nid_triple *a = a_; struct nid_triple *b = b_; return sig_cmp(a,b); }


decompiled_code:
__int64 __fastcall OBJ_find_sigid_algs(int a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
__int64 v5; // rax
unsigned int v6; // er8
int v8[9]; // [rsp+4h] [rbp-24h] BYREF

v8[0] = a1;
if ( sig_app && (v4 = sk_find(sig_app, v8), v4 >= 0) && (v5 = sk_value(sig_app, (unsigned int)v4)) != 0
|| (v5 = OBJ_bsearch_sig_constprop_0((__int64)v8), v6 = 0, v5) )
{
if ( a2 )
*a2 = *(_DWORD *)(v5 + 4);
v6 = 1;
if ( a3 )
*a3 = *(_DWORD *)(v5 + 8);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
__int64 v5; // rax
unsigned int v6; // er8
int v8[9]; // [rsp+4h] [rbp-24h] BYREF

v8[0] = a1;
if ( sig_app && (v4 = sk_find(sig_app, v8), v4 >= 0) && (v5 = sk_value(sig_app, (unsigned int)v4)) != 0
|| (v5 = func5((__int64)v8), v6 = 0, v5) )
{
if ( a2 )
*a2 = *(_DWORD *)(v5 + 4);
v6 = 1;
if ( a3 )
*a3 = *(_DWORD *)(v5 + 8);
}
return v6;
}

original_code:
int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
{
    nid_triple tmp;
    const nid_triple *rv = ((void *)0);
    tmp.sign_id = signid;
    if (sig_app) {
        int idx = sk_find(((_STACK*) (1 ? (sig_app) : (struct stack_st_nid_triple*)0)), ((void*) (1 ? (&tmp) : (nid_triple*)0)));
        if (idx >= 0)
            rv = ((nid_triple *)sk_value(((_STACK*) (1 ? (sig_app) : (struct stack_st_nid_triple*)0)), (idx)));
    }
    if (rv == ((void *)0)) {
        rv = OBJ_bsearch_sig(&tmp, sigoid_srt,
                             sizeof(sigoid_srt) / sizeof(nid_triple));
    }
    if (rv == ((void *)0))
        return 0;
    if (pdig_nid)
        *pdig_nid = rv->hash_id;
    if (ppkey_nid)
        *ppkey_nid = rv->pkey_id;
    return 1;
}

canonical_original_code:
int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid)
{
    struct nid_triple tmp;
    struct nid_triple *rv = ((void *)0);
    tmp.sign_id = signid;
    if (sig_app) {
        int idx = sk_find(((_STACK*) (1 ? (sig_app) : (struct stack_st_nid_triple*)0)), ((void*) (1 ? (&tmp) : (nid_triple*)0)));
        if (idx >= 0)
            rv = ((struct nid_triple *)sk_value(((struct stack_st *) (1 ? (sig_app) : (struct stack_st_nid_triple *)0)), (idx)));
    }
    if (rv == ((void *)0)) {
        rv = OBJ_bsearch_sig(&tmp, sigoid_srt,
                             sizeof(sigoid_srt) / sizeof(nid_triple));
    }
    if (rv == ((void *)0))
        return 0;
    if (pdig_nid)
        *pdig_nid = rv->hash_id;
    if (ppkey_nid)
        *ppkey_nid = rv->pkey_id;
    return 1;
}

variable_types: signid int

variable_types: struct nid_triple { int sign_id; int hash_id; int pkey_id; }

variable_types: idx int

user_defined_types: struct stack_st { int num; char **data; int sorted; int num_alloc; int (*comp)(void *, void *); }

user_defined_types: struct stack_st_nid_triple { struct stack_st stack; }


decompiled_code:
__int64 __fastcall OBJ_find_sigid_by_algs(_DWORD *a1, int a2, int a3)
{
int v3; // eax
char **v4; // rax
unsigned int v5; // er8
char *v7; // [rsp+8h] [rbp-20h] BYREF
char v8[4]; // [rsp+14h] [rbp-14h] BYREF
int v9; // [rsp+18h] [rbp-10h]
int v10; // [rsp+1Ch] [rbp-Ch]

v9 = a2;
v7 = v8;
v10 = a3;
if ( sigx_app && (v3 = sk_find(sigx_app, v8), v3 >= 0) )
{
v7 = (char *)sk_value(sigx_app, (unsigned int)v3);
v4 = &v7;
}
else
{
v4 = (char **)OBJ_bsearch_sigx_constprop_0((__int64)&v7);
v5 = 0;
if ( !v4 )
return v5;
}
v5 = 1;
if ( a1 )
*a1 = *(_DWORD *)*v4;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, int a2, int a3)
{
int v3; // eax
char **v4; // rax
unsigned int v5; // er8
char *v7; // [rsp+8h] [rbp-20h] BYREF
char v8[4]; // [rsp+14h] [rbp-14h] BYREF
int v9; // [rsp+18h] [rbp-10h]
int v10; // [rsp+1Ch] [rbp-Ch]

v9 = a2;
v7 = v8;
v10 = a3;
if ( sigx_app && (v3 = sk_find(sigx_app, v8), v3 >= 0) )
{
v7 = (char *)sk_value(sigx_app, (unsigned int)v3);
v4 = &v7;
}
else
{
v4 = (char **)func4((__int64)&v7);
v5 = 0;
if ( !v4 )
return v5;
}
v5 = 1;
if ( a1 )
*a1 = *(_DWORD *)*v4;
return v5;
}

original_code:
int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid)
{
    nid_triple tmp;
    const nid_triple *t = &tmp;
    const nid_triple **rv = ((void *)0);
    tmp.hash_id = dig_nid;
    tmp.pkey_id = pkey_nid;
    if (sigx_app) {
        int idx = sk_find(((_STACK*) (1 ? (sigx_app) : (struct stack_st_nid_triple*)0)), ((void*) (1 ? (&tmp) : (nid_triple*)0)));
        if (idx >= 0) {
            t = ((nid_triple *)sk_value(((_STACK*) (1 ? (sigx_app) : (struct stack_st_nid_triple*)0)), (idx)));
            rv = &t;
        }
    }
    if (rv == ((void *)0)) {
        rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref,
                              sizeof(sigoid_srt_xref) / sizeof(nid_triple *)
            );
    }
    if (rv == ((void *)0))
        return 0;
    if (psignid)
        *psignid = (*rv)->sign_id;
    return 1;
}

canonical_original_code:
int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid)
{
    struct nid_triple tmp;
    struct nid_triple *t = &tmp;
    struct nid_triple **rv = ((void *)0);
    tmp.hash_id = dig_nid;
    tmp.pkey_id = pkey_nid;
    if (sigx_app) {
        int idx = sk_find(((_STACK*) (1 ? (sigx_app) : (struct stack_st_nid_triple*)0)), ((void*) (1 ? (&tmp) : (nid_triple*)0)));
        if (idx >= 0) {
            t = ((struct nid_triple *)sk_value(((struct stack_st *) (1 ? (sigx_app) : (struct stack_st_nid_triple *)0)), (idx)));
            rv = &t;
        }
    }
    if (rv == ((void *)0)) {
        rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref,
                              sizeof(sigoid_srt_xref) / sizeof(struct nid_triple *)
            );
    }
    if (rv == ((void *)0))
        return 0;
    if (psignid)
        *psignid = (*rv)->sign_id;
    return 1;
}

variable_types:
psignid
int *


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

if ( sig_app )
{
result = sk_pop_free(sig_app, sid_free);
sig_app = 0LL;
}
if ( sigx_app )
{
result = sk_free();
sigx_app = 0LL;
}
return result;
}

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

if ( sig_app )
{
result = sk_pop_free(sig_app, sid_free);
sig_app = 0LL;
}
if ( sigx_app )
{
result = sk_free();
sigx_app = 0LL;
}
return result;
}

original_code:
void OBJ_sigid_free(void)
{
    if (sig_app) {
        sk_nid_triple_pop_free(sig_app, sid_free);
        sig_app = NULL;
    }
    if (sigx_app) {
        sk_nid_triple_free(sigx_app);
        sigx_app = NULL;
    }
}

canonical_original_code:
void OBJ_sigid_free()
{
    if (sig_app) {
        sk_nid_triple_pop_free(sig_app, sid_free);
        sig_app = NULL;
    }
    if (sigx_app) {
        sk_nid_triple_free(sigx_app);
        sigx_app = NULL;
    }
}


decompiled_code:
int __fastcall find_profile_by_name(char *s2, char ***a2, unsigned int a3)
{
const char *v3; // rbp
size_t v4; // r12
char **i; // rbx
int result; // eax

v3 = srtp_known_profiles;
if ( !srtp_known_profiles )
return 1;
v4 = a3;
for ( i = &srtp_known_profiles; ; i += 2 )
{
if ( strlen(v3) == v4 )
{
result = strncmp(v3, s2, v4);
if ( !result )
break;
}
v3 = i[2];
if ( !v3 )
return 1;
}
*a2 = i;
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s2, char ***a2, unsigned int a3)
{
const char *v3; // rbp
size_t v4; // r12
char **i; // rbx
int result; // eax

v3 = srtp_known_profiles;
if ( !srtp_known_profiles )
return 1;
v4 = a3;
for ( i = &srtp_known_profiles; ; i += 2 )
{
if ( strlen(v3) == v4 )
{
result = strncmp(v3, s2, v4);
if ( !result )
break;
}
v3 = i[2];
if ( !v3 )
return 1;
}
*a2 = i;
return result;
}

original_code:
static int find_profile_by_name(char *profile_name,
                                SRTP_PROTECTION_PROFILE **pptr, unsigned len)
{
    SRTP_PROTECTION_PROFILE *p;
    p = srtp_known_profiles;
    while (p->name) {
        if ((len == strlen(p->name)) && !strncmp(p->name, profile_name, len)) {
            *pptr = p;
            return 0;
        }
        p++;
    }
    return 1;
}

canonical_original_code:
static int find_profile_by_name(char *profile_name, struct srtp_protection_profile_st **pptr, unsigned int len)
{
    struct srtp_protection_profile_st *p;
    p = srtp_known_profiles;
    while (p->name) {
        if ((len == strlen(p->name)) && !strncmp(p->name, profile_name, len)) {
            *pptr = p;
            return 0;
        }
        p++;
    }
    return 1;
}

variable_types: struct srtp_protection_profile_st { char *name; unsigned long id; } **

variable_types:
len
unsigned int


decompiled_code:
__int64 __fastcall ssl_ctx_make_profiles(char *s2, __int64 *a2)
{
__int64 v3; // rbp
char *v4; // rax
char *v5; // rbx
unsigned int v6; // edx
unsigned int v7; // er12
__int64 v8; // r8
__int64 v9; // rdx
char **v11; // [rsp+8h] [rbp-30h] BYREF

v3 = sk_new_null();
if ( v3 )
{
while ( 1 )
{
v4 = strchr(s2, 58);
v5 = v4;
v6 = v4 ? (_DWORD)v4 - (_DWORD)s2 : (unsigned int)strlen(s2);
v7 = find_profile_by_name(s2, &v11, v6);
if ( v7 )
break;
if ( (int)sk_find(v3, v11) >= 0 )
{
v8 = 187LL;
v9 = 353LL;
goto LABEL_10;
}
sk_push(v3, v11);
if ( !v5 )
{
*a2 = v3;
return v7;
}
s2 = v5 + 1;
}
v8 = 195LL;
v9 = 364LL;
LABEL_10:
ERR_put_error(20LL, 309LL, v9, "d1_srtp.c", v8);
sk_free(v3);
return 1LL;
}
ERR_put_error(20LL, 309LL, 362LL, "d1_srtp.c", 176LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2, __int64 *a2)
{
__int64 v3; // rbp
char *v4; // rax
char *v5; // rbx
unsigned int v6; // edx
unsigned int v7; // er12
__int64 v8; // r8
__int64 v9; // rdx
char **v11; // [rsp+8h] [rbp-30h] BYREF

v3 = sk_new_null();
if ( v3 )
{
while ( 1 )
{
v4 = strchr(s2, 58);
v5 = v4;
v6 = v4 ? (_DWORD)v4 - (_DWORD)s2 : (unsigned int)strlen(s2);
v7 = func0(s2, &v11, v6);
if ( v7 )
break;
if ( (int)sk_find(v3, v11) >= 0 )
{
v8 = 187LL;
v9 = 353LL;
goto LABEL_10;
}
sk_push(v3, v11);
if ( !v5 )
{
*a2 = v3;
return v7;
}
s2 = v5 + 1;
}
v8 = 195LL;
v9 = 364LL;
LABEL_10:
ERR_put_error(20LL, 309LL, v9, "d1_srtp.c", v8);
sk_free(v3);
return 1LL;
}
ERR_put_error(20LL, 309LL, 362LL, "d1_srtp.c", 176LL);
return 1LL;
}

original_code:
static int ssl_ctx_make_profiles(const char *profiles_string,
                                 struct stack_st_SRTP_PROTECTION_PROFILE **out)
{
    struct stack_st_SRTP_PROTECTION_PROFILE *profiles;
    char *col;
    char *ptr = (char *)profiles_string;
    SRTP_PROTECTION_PROFILE *p;
    if (!(profiles = ((struct stack_st_SRTP_PROTECTION_PROFILE *)sk_new_null()))) {
        ERR_put_error(20,(309),(362),"d1_srtp.c",176);
        return 1;
    }
    do {
        col = strchr(ptr, ':');
        if (!find_profile_by_name(ptr, &p,
                                  col ? col - ptr : (int)strlen(ptr))) {
            if (sk_find(((_STACK*) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE*)0)), ((void*) (1 ? (p) : (SRTP_PROTECTION_PROFILE*)0))) >= 0) {
                ERR_put_error(20,(309),(353),"d1_srtp.c",187);
                sk_free(((_STACK*) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE*)0)));
                return 1;
            }
            sk_push(((_STACK*) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE*)0)), ((void*) (1 ? (p) : (SRTP_PROTECTION_PROFILE*)0)));
        } else {
            ERR_put_error(20,(309),(364),"d1_srtp.c",195);
            sk_free(((_STACK*) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE*)0)));
            return 1;
        }
        if (col)
            ptr = col + 1;
    } while (col);
    *out = profiles;
    return 0;
}

canonical_original_code:
static int ssl_ctx_make_profiles(char *profiles_string, struct stack_st_SRTP_PROTECTION_PROFILE **out)
{
    struct stack_st_SRTP_PROTECTION_PROFILE *profiles;
    char *col;
    char *ptr = (char *)profiles_string;
    struct srtp_protection_profile_st *p;
    if (!(profiles = ((struct stack_st_SRTP_PROTECTION_PROFILE *)sk_new_null()))) {
        ERR_put_error(20,(309),(362),"d1_srtp.c",176);
        return 1;
    }
    do {
        col = strchr(ptr, ':');
        if (!find_profile_by_name(ptr, &p,
                                  col ? col - ptr : (int)strlen(ptr))) {
            if (sk_find(((struct stack_st *) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE *)0)), ((void *) (1 ? (p) : (struct srtp_protection_profile_st *)0))) >= 0) {
                ERR_put_error(20,(309),(353),"d1_srtp.c",187);
                sk_free(((struct stack_st *) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE *)0)));
                return 1;
            }
            sk_push(((struct stack_st *) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE *)0)), ((void *) (1 ? (p) : (struct srtp_protection_profile_st *)0)));
        } else {
            ERR_put_error(20,(309),(364),"d1_srtp.c",195);
            sk_free(((struct stack_st *) (1 ? (profiles) : (struct stack_st_SRTP_PROTECTION_PROFILE *)0)));
            return 1;
        }
        if (col)
            ptr = col + 1;
    } while (col);
    *out = profiles;
    return 0;
}

variable_types: struct stack_st_SRTP_PROTECTION_PROFILE { struct stack_st { int num; char **data; int sorted; int num_alloc; int (*comp)(void *, void *); } stack; } **

variable_types:
col
char *

variable_types:
ptr
char *

variable_types: struct srtp_protection_profile_st { char *name; unsigned long id; } *

user_defined_types: struct stack_st_SRTP_PROTECTION_PROFILE { struct stack_st stack; }


decompiled_code:
__int64 ssl_sock_init()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
static int ssl_sock_init(void)
{
    return (1);
}

canonical_original_code:
static int ssl_sock_init()
{
    return (1);
}


GetHostByName

original_code:
static struct hostent *GetHostByName(char *name)
{
    struct hostent *ret;
    int i, lowi = 0;
    unsigned long low = (unsigned long)-1;
    for (i = 0; i < 4; i++) {
        if (low > ghbn_cache[i].order) {
            low = ghbn_cache[i].order;
            lowi = i;
        }
        if (ghbn_cache[i].order > 0) {
            if (strncmp(name, ghbn_cache[i].name, 128) == 0)
                break;
        }
    }
    if (i == 4) {
        ghbn_miss++;
        ret = gethostbyname(name);
        if (ret == ((void *)0))
            return (((void *)0));
        if (strlen(name) < sizeof ghbn_cache[0].name) {
            strcpy(ghbn_cache[lowi].name, name);
            memcpy((char *)&(ghbn_cache[lowi].ent), ret,
                   sizeof(struct hostent));
            ghbn_cache[lowi].order = ghbn_miss + ghbn_hits;
        }
        return (ret);
    } else {
        ghbn_hits++;
        ret = &(ghbn_cache[i].ent);
        ghbn_cache[i].order = ghbn_miss + ghbn_hits;
        return (ret);
    }
}

canonical_original_code:
static struct hostent *GetHostByName(char *name)
{
    struct hostent *ret;
    int i; int lowi = 0;
    unsigned long low = (unsigned long)-1;
    for (i = 0; i < 4; i++) {
        if (low > ghbn_cache[i].order) {
            low = ghbn_cache[i].order;
            lowi = i;
        }
        if (ghbn_cache[i].order > 0) {
            if (strncmp(name, ghbn_cache[i].name, 128) == 0)
                break;
        }
    }
    if (i == 4) {
        ghbn_miss++;
        ret = gethostbyname(name);
        if (ret == ((void *)0))
            return (((void *)0));
        if (strlen(name) < sizeof ghbn_cache[0].name) {
            strcpy(ghbn_cache[lowi].name, name);
            memcpy((char *)&(ghbn_cache[lowi].ent), ret,
                   sizeof(struct hostent));
            ghbn_cache[lowi].order = ghbn_miss + ghbn_hits;
        }
        return (ret);
    } else {
        ghbn_hits++;
        ret = &(ghbn_cache[i].ent);
        ghbn_cache[i].order = ghbn_miss + ghbn_hits;
        return (ret);
    }
}

variable_types:
name
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: i int

variable_types: lowi int

variable_types:
low
unsigned long


decompiled_code:
__int64 __fastcall host_ip(char *s, _BYTE *a2)
{
__int64 result; // rax
const __m128i *v3; // rax
__int64 v4; // rdx
char *v5; // rax
int v6; // [rsp+0h] [rbp-28h] BYREF
int v7; // [rsp+4h] [rbp-24h] BYREF
int v8; // [rsp+8h] [rbp-20h] BYREF
int v9; // [rsp+Ch] [rbp-1Ch] BYREF
char v10[24]; // [rsp+10h] [rbp-18h] BYREF

if ( (unsigned int)_isoc99_sscanf(s, "%u.%u.%u.%u", &v6, &v7, &v8, &v9) == 4 )
{
v5 = (char *)&v6;
while ( *(_DWORD *)v5 <= 0xFFu )
{
v5 += 4;
if ( v5 == v10 )
{
*a2 = v6;
a2[1] = v7;
a2[2] = v8;
a2[3] = v9;
return 1LL;
}
}
BIO_printf(bio_err, "invalid IP address\n", v10);
result = 0LL;
}
else
{
result = ssl_sock_init();
if ( (_DWORD)result )
{
v3 = GetHostByName(s);
if ( v3 )
{
if ( v3[1].m128i_i16[0] == 2 )
{
*a2 = **(_BYTE **)v3[1].m128i_i64[1];
a2[1] = *(_BYTE *)(*(_QWORD *)v3[1].m128i_i64[1] + 1LL);
a2[2] = *(_BYTE *)(*(_QWORD *)v3[1].m128i_i64[1] + 2LL);
a2[3] = *(_BYTE *)(*(_QWORD *)v3[1].m128i_i64[1] + 3LL);
result = 1LL;
}
else
{
BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n", v4);
result = 0LL;
}
}
else
{
BIO_printf(bio_err, "gethostbyname failure\n", v4);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s, _BYTE *a2)
{
__int64 result; // rax
const __m128i *v3; // rax
__int64 v4; // rdx
char *v5; // rax
int v6; // [rsp+0h] [rbp-28h] BYREF
int v7; // [rsp+4h] [rbp-24h] BYREF
int v8; // [rsp+8h] [rbp-20h] BYREF
int v9; // [rsp+Ch] [rbp-1Ch] BYREF
char v10[24]; // [rsp+10h] [rbp-18h] BYREF

if ( (unsigned int)_isoc99_sscanf(s, "%u.%u.%u.%u", &v6, &v7, &v8, &v9) == 4 )
{
v5 = (char *)&v6;
while ( *(_DWORD *)v5 <= 0xFFu )
{
v5 += 4;
if ( v5 == v10 )
{
*a2 = v6;
a2[1] = v7;
a2[2] = v8;
a2[3] = v9;
return 1LL;
}
}
BIO_printf(bio_err, "invalid IP address\n", v10);
result = 0LL;
}
else
{
result = func0();
if ( (_DWORD)result )
{
v3 = func1(s);
if ( v3 )
{
if ( v3[1].m128i_i16[0] == 2 )
{
*a2 = **(_BYTE **)v3[1].m128i_i64[1];
a2[1] = *(_BYTE *)(*(_QWORD *)v3[1].m128i_i64[1] + 1LL);
a2[2] = *(_BYTE *)(*(_QWORD *)v3[1].m128i_i64[1] + 2LL);
a2[3] = *(_BYTE *)(*(_QWORD *)v3[1].m128i_i64[1] + 3LL);
result = 1LL;
}
else
{
BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n", v4);
result = 0LL;
}
}
else
{
BIO_printf(bio_err, "gethostbyname failure\n", v4);
result = 0LL;
}
}
}
return result;
}

original_code:
static int host_ip(char *str, unsigned char ip[4])
{
    unsigned int in[4];
    int i;
    if (sscanf(str, "%u.%u.%u.%u", &(in[0]), &(in[1]), &(in[2]), &(in[3])) ==
        4) {
        for (i = 0; i < 4; i++)
            if (in[i] > 255) {
                BIO_printf(bio_err, "invalid IP address\n");
                goto err;
            }
        ip[0] = in[0];
        ip[1] = in[1];
        ip[2] = in[2];
        ip[3] = in[3];
    } else {
        struct hostent *he;
        if (!ssl_sock_init())
            return (0);
        he = GetHostByName(str);
        if (he == ((void *)0)) {
            BIO_printf(bio_err, "gethostbyname failure\n");
            goto err;
        }
        if ((short)he->h_addrtype != 2) {
            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
            return (0);
        }
        ip[0] = he->h_addr_list[0][0];
        ip[1] = he->h_addr_list[0][1];
        ip[2] = he->h_addr_list[0][2];
        ip[3] = he->h_addr_list[0][3];
    }
    return (1);
 err:
    return (0);
}

variable_types:
str
char *

variable_types:
ip
unsigned char [4]

variable_types:
in
unsigned int [4]

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


decompiled_code:
__int64 __fastcall init_client_ip(int *a1, unsigned int *a2)
{
__int64 result; // rax
__int16 v3; // dx
__int16 v5; // ax
unsigned int v6; // edi
int v7; // ecx
int v8; // ebp
int v9; // eax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

result = ssl_sock_init();
if ( (_DWORD)result )
{
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
v5 = _bswap_16(v3);
v6 = *a2;
*(_WORD *)addr.sa_data = v5;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(_byteswap_ulong(v6));
if ( v7 == 1 )
{
v9 = socket(2, 1, 6);
v8 = v9;
if ( v9 != -1 )
{
optval = 0;
optval = setsockopt(v9, 1, 9, &optval, 4u);
if ( optval < 0 )
{
close(v8);
perror("keepalive");
return 0LL;
}
goto LABEL_4;
}
}
else
{
v8 = socket(2, 2, 17);
if ( v8 != -1 )
{
LABEL_4:
if ( connect(v8, &addr, 0x10u) == -1 )
{
close(v8);
perror("connect");
result = 0LL;
}
else
{
*a1 = v8;
result = 1LL;
}
return result;
}
}
perror("socket");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, unsigned int *a2)
{
__int64 result; // rax
__int16 v3; // dx
__int16 v5; // ax
unsigned int v6; // edi
int v7; // ecx
int v8; // ebp
int v9; // eax
int optval; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

result = func0();
if ( (_DWORD)result )
{
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
v5 = func3(v3);
v6 = *a2;
*(_WORD *)addr.sa_data = v5;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func4(_byteswap_ulong(v6));
if ( v7 == 1 )
{
v9 = socket(2, 1, 6);
v8 = v9;
if ( v9 != -1 )
{
optval = 0;
optval = setsockopt(v9, 1, 9, &optval, 4u);
if ( optval < 0 )
{
close(v8);
perror("keepalive");
return 0LL;
}
goto LABEL_4;
}
}
else
{
v8 = socket(2, 2, 17);
if ( v8 != -1 )
{
LABEL_4:
if ( connect(v8, &addr, 0x10u) == -1 )
{
close(v8);
perror("connect");
result = 0LL;
}
else
{
*a1 = v8;
result = 1LL;
}
return result;
}
}
perror("socket");
result = 0LL;
}
return result;
}

original_code:
static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
{
    unsigned long addr;
    struct sockaddr_in them;
    int s, i;
    if (!ssl_sock_init())
        return (0);
    memset((char *)&them, 0, sizeof(them));
    them.sin_family = 2;
    them.sin_port = htons((unsigned short)port);
    addr = (unsigned long)
        ((unsigned long)ip[0] << 24L) |
        ((unsigned long)ip[1] << 16L) |
        ((unsigned long)ip[2] << 8L) | ((unsigned long)ip[3]);
    them.sin_addr.s_addr = htonl(addr);
    if (type == SOCK_STREAM)
        s = socket(2, SOCK_STREAM, IPPROTO_TCP);
    else
        s = socket(2, SOCK_DGRAM, IPPROTO_UDP);
    if (s == (-1)) {
        perror("socket");
        return (0);
    }
    if (type == SOCK_STREAM) {
        i = 0;
        i = setsockopt(s, 1, 9, (char *)&i, sizeof(i));
        if (i < 0) {
            close(s);
            perror("keepalive");
            return (0);
        }
    }
    if (connect(s, (struct sockaddr *)&them, sizeof(them)) == -1) {
        close(s);
        perror("connect");
        return (0);
    }
    *sock = s;
    return (1);
}

canonical_original_code:
static int init_client_ip(int *sock, unsigned char ip[4], int port, int type)
{
    unsigned long addr;
    struct sockaddr_in them;
    int s; int i;
    if (!ssl_sock_init())
        return (0);
    memset((char *)&them, 0, sizeof(them));
    them.sin_family = 2;
    them.sin_port = htons((unsigned short)port);
    addr = (unsigned long)
        ((unsigned long)ip[0] << 24L) |
        ((unsigned long)ip[1] << 16L) |
        ((unsigned long)ip[2] << 8L) | ((unsigned long)ip[3]);
    them.sin_addr.s_addr = htonl(addr);
    if (type == SOCK_STREAM)
        s = socket(2, SOCK_STREAM, IPPROTO_TCP);
    else
        s = socket(2, SOCK_DGRAM, IPPROTO_UDP);
    if (s == (-1)) {
        perror("socket");
        return (0);
    }
    if (type == SOCK_STREAM) {
        i = 0;
        i = setsockopt(s, 1, 9, (char *)&i, sizeof(i));
        if (i < 0) {
            close(s);
            perror("keepalive");
            return (0);
        }
    }
    if (connect(s, (struct sockaddr *)&them, sizeof(them)) == -1) {
        close(s);
        perror("connect");
        return (0);
    }
    *sock = s;
    return (1);
}

variable_types:
sock
int *

variable_types: port int

variable_types: type int

variable_types:
addr
unsigned long

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: s int

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 { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall do_accept(__int64 fd, int *a2)
{
__int64 result; // rax
char **v3; // rdx
char **v4; // r12
__int64 v5; // rdx
int v6; // ebp
struct hostent *v7; // rax
__int64 v8; // rdx
const char **v9; // rbx
int v10; // eax
__int64 v11; // rax
__int64 v12; // r14
const char *v13; // r15
size_t v14; // rax
const __m128i *v15; // rax
__int64 v16; // rdx
socklen_t addr_len[15]; // [rsp+Ch] [rbp-3Ch] BYREF

result = ssl_sock_init(fd);
if ( (_DWORD)result )
{
v4 = v3;
while ( 1 )
{
addr_len[0] = 16;
from_0 = 0LL;
v6 = accept(fd, &from_0, addr_len);
if ( v6 != -1 )
break;
v5 = (unsigned int)*_errno_location();
if ( (_DWORD)v5 != 4 )
{
fprintf(stderr, "errno=%d ", v5);
perror("accept");
return 0LL;
}
}
v7 = gethostbyaddr(&from_0.sa_data[2], 4u, 2);
v9 = (const char **)&v7->h_name;
if ( !v7 )
{
BIO_printf(bio_err, "bad gethostbyaddr\n", v8);
*v4 = 0LL;
goto LABEL_9;
}
v10 = strlen(v7->h_name);
v11 = CRYPTO_malloc((unsigned int)(v10 + 1), "s_socket.c", 453LL);
*v4 = (char *)v11;
v12 = v11;
if ( v11 )
{
v13 = *v9;
v14 = strlen(*v9);
BUF_strlcpy(v12, v13, v14 + 1);
v15 = GetHostByName(*v4);
if ( v15 )
{
if ( v15[1].m128i_i32[0] == 2 )
{
LABEL_9:
*a2 = v6;
return 1LL;
}
BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n", v16);
close(v6);
result = 0LL;
}
else
{
BIO_printf(bio_err, "gethostbyname failure\n", v16);
close(v6);
result = 0LL;
}
}
else
{
perror("OPENSSL_malloc");
close(v6);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 fd, int *a2)
{
__int64 result; // rax
char **v3; // rdx
char **v4; // r12
__int64 v5; // rdx
int v6; // ebp
struct hostent *v7; // rax
__int64 v8; // rdx
const char **v9; // rbx
int v10; // eax
__int64 v11; // rax
__int64 v12; // r14
const char *v13; // r15
size_t v14; // rax
const __m128i *v15; // rax
__int64 v16; // rdx
socklen_t addr_len[15]; // [rsp+Ch] [rbp-3Ch] BYREF

result = func0(fd);
if ( (_DWORD)result )
{
v4 = v3;
while ( 1 )
{
addr_len[0] = 16;
from_0 = 0LL;
v6 = accept(fd, &from_0, addr_len);
if ( v6 != -1 )
break;
v5 = (unsigned int)*_errno_location();
if ( (_DWORD)v5 != 4 )
{
fprintf(stderr, "errno=%d ", v5);
perror("accept");
return 0LL;
}
}
v7 = gethostbyaddr(&from_0.sa_data[2], 4u, 2);
v9 = (const char **)&v7->h_name;
if ( !v7 )
{
BIO_printf(bio_err, "bad gethostbyaddr\n", v8);
*v4 = 0LL;
goto LABEL_9;
}
v10 = strlen(v7->h_name);
v11 = CRYPTO_malloc((unsigned int)(v10 + 1), "s_socket.c", 453LL);
*v4 = (char *)v11;
v12 = v11;
if ( v11 )
{
v13 = *v9;
v14 = strlen(*v9);
BUF_strlcpy(v12, v13, v14 + 1);
v15 = func1(*v4);
if ( v15 )
{
if ( v15[1].m128i_i32[0] == 2 )
{
LABEL_9:
*a2 = v6;
return 1LL;
}
BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n", v16);
close(v6);
result = 0LL;
}
else
{
BIO_printf(bio_err, "gethostbyname failure\n", v16);
close(v6);
result = 0LL;
}
}
else
{
perror("OPENSSL_malloc");
close(v6);
result = 0LL;
}
}
return result;
}

original_code:
static int do_accept(int acc_sock, int *sock, char **host)
{
    int ret;
    struct hostent *h1, *h2;
    static struct sockaddr_in from;
    int len;
    if (!ssl_sock_init())
        return (0);
 redoit:
    memset((char *)&from, 0, sizeof(from));
    len = sizeof(from);
    ret = accept(acc_sock, (struct sockaddr *)&from, (void *)&len);
    if (ret == (-1)) {
        if ((*__errno_location ()) == 4) {
            goto redoit;
        }
        fprintf(stderr, "errno=%d ", (*__errno_location ()));
        perror("accept");
        return (0);
    }
    if (host == ((void *)0))
        goto end;
    h1 = gethostbyaddr((char *)&from.sin_addr.s_addr,
                       sizeof(from.sin_addr.s_addr), 2);
    if (h1 == ((void *)0)) {
        BIO_printf(bio_err, "bad gethostbyaddr\n");
        *host = ((void *)0);
    } else {
        if ((*host = (char *)CRYPTO_malloc((int)strlen(h1->h_name) + 1,"s_socket.c",453)) == ((void *)0)) {
            perror("OPENSSL_malloc");
            close(ret);
            return (0);
        }
        BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1);
        h2 = GetHostByName(*host);
        if (h2 == ((void *)0)) {
            BIO_printf(bio_err, "gethostbyname failure\n");
            close(ret);
            return (0);
        }
        if (h2->h_addrtype != 2) {
            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
            close(ret);
            return (0);
        }
    }
 end:
    *sock = ret;
    return (1);
}

canonical_original_code:
static int do_accept(int acc_sock, int *sock, char **host)
{
    int ret;
    struct hostent *h1; struct hostent *h2;
    static struct sockaddr_in from;
    int len;
    if (!ssl_sock_init())
        return (0);
 redoit:
    memset((char *)&from, 0, sizeof(from));
    len = sizeof(from);
    ret = accept(acc_sock, (struct sockaddr *)&from, (void *)&len);
    if (ret == (-1)) {
        if ((*__errno_location ()) == 4) {
            goto redoit;
        }
        fprintf(stderr, "errno=%d ", (*__errno_location ()));
        perror("accept");
        return (0);
    }
    if (host == ((void *)0))
        goto end;
    h1 = gethostbyaddr((char *)&from.sin_addr.s_addr,
                       sizeof(from.sin_addr.s_addr), 2);
    if (h1 == ((void *)0)) {
        BIO_printf(bio_err, "bad gethostbyaddr\n");
        *host = ((void *)0);
    } else {
        if ((*host = (char *)CRYPTO_malloc((int)strlen(h1->h_name) + 1,"s_socket.c",453)) == ((void *)0)) {
            perror("OPENSSL_malloc");
            close(ret);
            return (0);
        }
        BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1);
        h2 = GetHostByName(*host);
        if (h2 == ((void *)0)) {
            BIO_printf(bio_err, "gethostbyname failure\n");
            close(ret);
            return (0);
        }
        if (h2->h_addrtype != 2) {
            BIO_printf(bio_err, "gethostbyname addr is not AF_INET\n");
            close(ret);
            return (0);
        }
    }
 end:
    *sock = ret;
    return (1);
}

variable_types:
host
char **

variable_types: ret int

variable_types: len int


decompiled_code:
__int64 __fastcall init_client(int *a1, char *a2)
{
__int64 result; // rax
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3[0] = 0;
result = host_ip(a2, v3);
if ( (_DWORD)result )
result = init_client_ip(a1, v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, char *a2)
{
__int64 result; // rax
unsigned int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3[0] = 0;
result = func2(a2, v3);
if ( (_DWORD)result )
result = func5(a1, v3);
return result;
}

original_code:
int init_client(int *sock, char *host, int port, int type)
{
    unsigned char ip[4];
    memset(ip, '\0', sizeof ip);
    if (!host_ip(host, &(ip[0])))
        return 0;
    return init_client_ip(sock, ip, port, type);
}

variable_types:
host
char *


decompiled_code:
__int64 __fastcall do_server(__int16 a1, int a2, int *a3, __int64 (__fastcall *a4)(__int64, _QWORD, __int64), __int64 a5)
{
int v8; // er12
unsigned int v9; // er8
int fd; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+4h] [rbp-34h] BYREF
__int64 v13; // [rsp+8h] [rbp-30h]

v12 = 0;
v13 = 0LL;
v8 = init_server_constprop_0(&v12, a1);
if ( v8 )
{
v9 = v12;
if ( !a3 )
goto LABEL_7;
*a3 = v12;
if ( a2 == 1 )
goto LABEL_8;
while ( 1 )
{
fd = v9;
v8 = a4(v13, v9, a5);
if ( v13 )
CRYPTO_free();
v9 = v12;
if ( v8 < 0 )
break;
LABEL_7:
while ( a2 == 1 )
{
LABEL_8:
if ( !(unsigned int)do_accept(v9, &fd) )
{
shutdown(v12, 0);
close(v12);
return 0LL;
}
v8 = a4(v13, (unsigned int)fd, a5);
if ( v13 )
CRYPTO_free();
shutdown(fd, 2);
close(fd);
v9 = v12;
if ( v8 < 0 )
goto LABEL_12;
}
}
LABEL_12:
shutdown(v9, 2);
close(v12);
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int16 a1, int a2, int *a3, __int64 (__fastcall *a4)(__int64, _QWORD, __int64), __int64 a5)
{
int v8; // er12
unsigned int v9; // er8
int fd; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+4h] [rbp-34h] BYREF
__int64 v13; // [rsp+8h] [rbp-30h]

v12 = 0;
v13 = 0LL;
v8 = func8(&v12, a1);
if ( v8 )
{
v9 = v12;
if ( !a3 )
goto LABEL_7;
*a3 = v12;
if ( a2 == 1 )
goto LABEL_8;
while ( 1 )
{
fd = v9;
v8 = a4(v13, v9, a5);
if ( v13 )
CRYPTO_free();
v9 = v12;
if ( v8 < 0 )
break;
LABEL_7:
while ( a2 == 1 )
{
LABEL_8:
if ( !(unsigned int)func6(v9, &fd) )
{
shutdown(v12, 0);
close(v12);
return 0LL;
}
v8 = a4(v13, (unsigned int)fd, a5);
if ( v13 )
CRYPTO_free();
shutdown(fd, 2);
close(fd);
v9 = v12;
if ( v8 < 0 )
goto LABEL_12;
}
}
LABEL_12:
shutdown(v9, 2);
close(v12);
}
return (unsigned int)v8;
}

original_code:
int do_server(int port, int type, int *ret,
              int (*cb) (char *hostname, int s, unsigned char *context),
              unsigned char *context)
{
    int sock;
    char *name = ((void *)0);
    int accept_socket = 0;
    int i;
    if (!init_server(&accept_socket, port, type))
        return (0);
    if (ret != ((void *)0)) {
        *ret = accept_socket;
    }
    for (;;) {
        if (type == SOCK_STREAM) {
            if (do_accept(accept_socket, &sock, &name) == 0) {
                { shutdown((accept_socket),0); close((accept_socket)); };
                return (0);
            }
        } else
            sock = accept_socket;
        i = (*cb) (name, sock, context);
        if (name != ((void *)0))
            CRYPTO_free(name);
        if (type == SOCK_STREAM)
            { shutdown((sock),2); close((sock)); };
        if (i < 0) {
            { shutdown((accept_socket),2); close((accept_socket)); };
            return (i);
        }
    }
}

canonical_original_code:
int do_server(int port, int type, int *ret, int (*cb)(char *hostname, int s, unsigned char *context), unsigned char *context)
{
    int sock;
    char *name = ((void *)0);
    int accept_socket = 0;
    int i;
    if (!init_server(&accept_socket, port, type))
        return (0);
    if (ret != ((void *)0)) {
        *ret = accept_socket;
    }
    for (;;) {
        if (type == SOCK_STREAM) {
            if (do_accept(accept_socket, &sock, &name) == 0) {
                { shutdown((accept_socket),0); close((accept_socket)); };
                return (0);
            }
        } else
            sock = accept_socket;
        i = (*cb) (name, sock, context);
        if (name != ((void *)0))
            CRYPTO_free(name);
        if (type == SOCK_STREAM)
            { shutdown((sock),2); close((sock)); };
        if (i < 0) {
            { shutdown((accept_socket),2); close((accept_socket)); };
            return (i);
        }
    }
}

variable_types:
ret
int *

variable_types: int (*)(char *hostname, int s, unsigned char *context)

variable_types:
context
unsigned char *

variable_types: sock int

variable_types:
name
char *


decompiled_code:
__int64 __fastcall extract_port(char *name, __int16 *a2)
{
int v2; // eax
unsigned int v3; // er12
struct servent *v5; // rax

v2 = atoi(name);
v3 = v2;
if ( v2 )
{
*a2 = v2;
return 1;
}
v5 = getservbyname(name, "tcp");
if ( !v5 )
{
BIO_printf(bio_err, "getservbyname failure for %s\n", name);
return v3;
}
*a2 = _bswap_16(v5->s_port);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *name, __int16 *a2)
{
int v2; // eax
unsigned int v3; // er12
struct servent *v5; // rax

v2 = atoi(name);
v3 = v2;
if ( v2 )
{
*a2 = v2;
return 1;
}
v5 = getservbyname(name, "tcp");
if ( !v5 )
{
BIO_printf(bio_err, "getservbyname failure for %s\n", name);
return v3;
}
*a2 = func3(v5->s_port);
return 1LL;
}

original_code:
int extract_port(char *str, short *port_ptr)
{
    int i;
    struct servent *s;
    i = atoi(str);
    if (i != 0)
        *port_ptr = (unsigned short)i;
    else {
        s = getservbyname(str, "tcp");
        if (s == ((void *)0)) {
            BIO_printf(bio_err, "getservbyname failure for %s\n", str);
            return (0);
        }
        *port_ptr = ntohs((unsigned short)s->s_port);
    }
    return (1);
}

variable_types:
str
char *

variable_types: i int

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; } *


decompiled_code:
__int64 __fastcall extract_host_port(char *s, char **a2, _BYTE *a3, __int16 *a4)
{
char *v6; // rax
char *v7; // r14
__int64 result; // rax

v6 = strchr(s, 58);
if ( v6 )
{
*v6 = 0;
v7 = v6 + 1;
if ( !a3 || (result = host_ip(s, a3), (_DWORD)result) )
{
if ( a2 )
*a2 = s;
result = (unsigned int)extract_port(v7, a4) != 0;
}
}
else
{
BIO_printf(bio_err, "no port defined\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s, char **a2, _BYTE *a3, __int16 *a4)
{
char *v6; // rax
char *v7; // r14
__int64 result; // rax

v6 = strchr(s, 58);
if ( v6 )
{
*v6 = 0;
v7 = v6 + 1;
if ( !a3 || (result = func2(s, a3), (_DWORD)result) )
{
if ( a2 )
*a2 = s;
result = (unsigned int)func11(v7, a4) != 0;
}
}
else
{
BIO_printf(bio_err, "no port defined\n");
result = 0LL;
}
return result;
}

original_code:
int extract_host_port(char *str, char **host_ptr, unsigned char *ip,
                      short *port_ptr)
{
    char *h, *p;
    h = str;
    p = strchr(str, ':');
    if (p == ((void *)0)) {
        BIO_printf(bio_err, "no port defined\n");
        return (0);
    }
    *(p++) = '\0';
    if ((ip != ((void *)0)) && !host_ip(str, ip))
        goto err;
    if (host_ptr != ((void *)0))
        *host_ptr = h;
    if (!extract_port(p, port_ptr))
        goto err;
    return (1);
 err:
    return (0);
}

canonical_original_code:
int extract_host_port(char *str, char **host_ptr, unsigned char *ip, short *port_ptr)
{
    char *h; char *p;
    h = str;
    p = strchr(str, ':');
    if (p == ((void *)0)) {
        BIO_printf(bio_err, "no port defined\n");
        return (0);
    }
    *(p++) = '\0';
    if ((ip != ((void *)0)) && !host_ip(str, ip))
        goto err;
    if (host_ptr != ((void *)0))
        *host_ptr = h;
    if (!extract_port(p, port_ptr))
        goto err;
    return (1);
 err:
    return (0);
}

variable_types:
ip
unsigned char *

variable_types:
h
char *

variable_types:
p
char *


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

switch ( (int)a1 )
{
case 0:
result = (const char *)&unk_404;
break;
case 2:
result = "unable to get issuer certificate";
break;
case 3:
result = "unable to get certificate CRL";
break;
case 4:
result = "unable to decrypt certificate's signature";
break;
case 5:
result = "unable to decrypt CRL's signature";
break;
case 6:
result = "unable to decode issuer public key";
break;
case 7:
result = "certificate signature failure";
break;
case 8:
result = "CRL signature failure";
break;
case 9:
result = "certificate is not yet valid";
break;
case 10:
result = "certificate has expired";
break;
case 11:
result = "CRL is not yet valid";
break;
case 12:
result = "CRL has expired";
break;
case 13:
result = "format error in certificate's notBefore field";
break;
case 14:
result = "format error in certificate's notAfter field";
break;
case 15:
result = "format error in CRL's lastUpdate field";
break;
case 16:
result = "format error in CRL's nextUpdate field";
break;
case 17:
result = "out of memory";
break;
case 18:
result = "self signed certificate";
break;
case 19:
result = "self signed certificate in certificate chain";
break;
case 20:
result = "unable to get local issuer certificate";
break;
case 21:
result = "unable to verify the first certificate";
break;
case 22:
result = "certificate chain too long";
break;
case 23:
result = "certificate revoked";
break;
case 24:
result = "invalid CA certificate";
break;
case 25:
result = "path length constraint exceeded";
break;
case 26:
result = "unsupported certificate purpose";
break;
case 27:
result = "certificate not trusted";
break;
case 28:
result = "certificate rejected";
break;
case 29:
result = "subject issuer mismatch";
break;
case 30:
result = "authority and subject key identifier mismatch";
break;
case 31:
result = "authority and issuer serial number mismatch";
break;
case 32:
result = "key usage does not include certificate signing";
break;
case 33:
result = "unable to get CRL issuer certificate";
break;
case 34:
result = "unhandled critical extension";
break;
case 35:
result = "key usage does not include CRL signing";
break;
case 36:
result = "unhandled critical CRL extension";
break;
case 37:
result = "invalid non-CA certificate (has CA markings)";
break;
case 38:
result = "proxy path length constraint exceeded";
break;
case 39:
result = "key usage does not include digital signature";
break;
case 40:
result = "proxy certificates not allowed, please set the appropriate flag";
break;
case 41:
result = "invalid or inconsistent certificate extension";
break;
case 42:
result = "invalid or inconsistent certificate policy extension";
break;
case 43:
result = "no explicit policy";
break;
case 44:
result = "Different CRL scope";
break;
case 45:
result = "Unsupported extension feature";
break;
case 46:
result = "RFC 3779 resource not subset of parent's resources";
break;
case 47:
result = "permitted subtree violation";
break;
case 48:
result = "excluded subtree violation";
break;
case 49:
result = "name constraints minimum and maximum not supported";
break;
case 50:
result = "application verification failure";
break;
case 51:
result = "unsupported name constraint type";
break;
case 52:
result = "unsupported or invalid name constraint syntax";
break;
case 53:
result = "unsupported or invalid name syntax";
break;
case 54:
result = "CRL path validation error";
break;
default:
BIO_snprintf(&buf_0, 100LL, "error number %ld", a1);
result = (const char *)&buf_0;
break;
}
return result;
}

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

switch ( (int)a1 )
{
case 0:
result = (const char *)&unk_404;
break;
case 2:
result = "unable to get issuer certificate";
break;
case 3:
result = "unable to get certificate CRL";
break;
case 4:
result = "unable to decrypt certificate's signature";
break;
case 5:
result = "unable to decrypt CRL's signature";
break;
case 6:
result = "unable to decode issuer public key";
break;
case 7:
result = "certificate signature failure";
break;
case 8:
result = "CRL signature failure";
break;
case 9:
result = "certificate is not yet valid";
break;
case 10:
result = "certificate has expired";
break;
case 11:
result = "CRL is not yet valid";
break;
case 12:
result = "CRL has expired";
break;
case 13:
result = "format error in certificate's notBefore field";
break;
case 14:
result = "format error in certificate's notAfter field";
break;
case 15:
result = "format error in CRL's lastUpdate field";
break;
case 16:
result = "format error in CRL's nextUpdate field";
break;
case 17:
result = "out of memory";
break;
case 18:
result = "self signed certificate";
break;
case 19:
result = "self signed certificate in certificate chain";
break;
case 20:
result = "unable to get local issuer certificate";
break;
case 21:
result = "unable to verify the first certificate";
break;
case 22:
result = "certificate chain too long";
break;
case 23:
result = "certificate revoked";
break;
case 24:
result = "invalid CA certificate";
break;
case 25:
result = "path length constraint exceeded";
break;
case 26:
result = "unsupported certificate purpose";
break;
case 27:
result = "certificate not trusted";
break;
case 28:
result = "certificate rejected";
break;
case 29:
result = "subject issuer mismatch";
break;
case 30:
result = "authority and subject key identifier mismatch";
break;
case 31:
result = "authority and issuer serial number mismatch";
break;
case 32:
result = "key usage does not include certificate signing";
break;
case 33:
result = "unable to get CRL issuer certificate";
break;
case 34:
result = "unhandled critical extension";
break;
case 35:
result = "key usage does not include CRL signing";
break;
case 36:
result = "unhandled critical CRL extension";
break;
case 37:
result = "invalid non-CA certificate (has CA markings)";
break;
case 38:
result = "proxy path length constraint exceeded";
break;
case 39:
result = "key usage does not include digital signature";
break;
case 40:
result = "proxy certificates not allowed, please set the appropriate flag";
break;
case 41:
result = "invalid or inconsistent certificate extension";
break;
case 42:
result = "invalid or inconsistent certificate policy extension";
break;
case 43:
result = "no explicit policy";
break;
case 44:
result = "Different CRL scope";
break;
case 45:
result = "Unsupported extension feature";
break;
case 46:
result = "RFC 3779 resource not subset of parent's resources";
break;
case 47:
result = "permitted subtree violation";
break;
case 48:
result = "excluded subtree violation";
break;
case 49:
result = "name constraints minimum and maximum not supported";
break;
case 50:
result = "application verification failure";
break;
case 51:
result = "unsupported name constraint type";
break;
case 52:
result = "unsupported or invalid name constraint syntax";
break;
case 53:
result = "unsupported or invalid name syntax";
break;
case 54:
result = "CRL path validation error";
break;
default:
BIO_snprintf(&buf_0, 100LL, "error number %ld", a1);
result = (const char *)&buf_0;
break;
}
return result;
}

original_code:
const char *X509_verify_cert_error_string(long n)
{
    static char buf[100];

    switch ((int)n) {
    case X509_V_OK:
        return ("ok");
    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
        return ("unable to get issuer certificate");
    case X509_V_ERR_UNABLE_TO_GET_CRL:
        return ("unable to get certificate CRL");
    case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
        return ("unable to decrypt certificate's signature");
    case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
        return ("unable to decrypt CRL's signature");
    case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
        return ("unable to decode issuer public key");
    case X509_V_ERR_CERT_SIGNATURE_FAILURE:
        return ("certificate signature failure");
    case X509_V_ERR_CRL_SIGNATURE_FAILURE:
        return ("CRL signature failure");
    case X509_V_ERR_CERT_NOT_YET_VALID:
        return ("certificate is not yet valid");
    case X509_V_ERR_CRL_NOT_YET_VALID:
        return ("CRL is not yet valid");
    case X509_V_ERR_CERT_HAS_EXPIRED:
        return ("certificate has expired");
    case X509_V_ERR_CRL_HAS_EXPIRED:
        return ("CRL has expired");
    case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
        return ("format error in certificate's notBefore field");
    case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
        return ("format error in certificate's notAfter field");
    case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
        return ("format error in CRL's lastUpdate field");
    case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
        return ("format error in CRL's nextUpdate field");
    case X509_V_ERR_OUT_OF_MEM:
        return ("out of memory");
    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
        return ("self signed certificate");
    case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
        return ("self signed certificate in certificate chain");
    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
        return ("unable to get local issuer certificate");
    case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
        return ("unable to verify the first certificate");
    case X509_V_ERR_CERT_CHAIN_TOO_LONG:
        return ("certificate chain too long");
    case X509_V_ERR_CERT_REVOKED:
        return ("certificate revoked");
    case X509_V_ERR_INVALID_CA:
        return ("invalid CA certificate");
    case X509_V_ERR_INVALID_NON_CA:
        return ("invalid non-CA certificate (has CA markings)");
    case X509_V_ERR_PATH_LENGTH_EXCEEDED:
        return ("path length constraint exceeded");
    case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED:
        return ("proxy path length constraint exceeded");
    case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED:
        return
            ("proxy certificates not allowed, please set the appropriate flag");
    case X509_V_ERR_INVALID_PURPOSE:
        return ("unsupported certificate purpose");
    case X509_V_ERR_CERT_UNTRUSTED:
        return ("certificate not trusted");
    case X509_V_ERR_CERT_REJECTED:
        return ("certificate rejected");
    case X509_V_ERR_APPLICATION_VERIFICATION:
        return ("application verification failure");
    case X509_V_ERR_SUBJECT_ISSUER_MISMATCH:
        return ("subject issuer mismatch");
    case X509_V_ERR_AKID_SKID_MISMATCH:
        return ("authority and subject key identifier mismatch");
    case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
        return ("authority and issuer serial number mismatch");
    case X509_V_ERR_KEYUSAGE_NO_CERTSIGN:
        return ("key usage does not include certificate signing");
    case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
        return ("unable to get CRL issuer certificate");
    case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION:
        return ("unhandled critical extension");
    case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN:
        return ("key usage does not include CRL signing");
    case X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE:
        return ("key usage does not include digital signature");
    case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
        return ("unhandled critical CRL extension");
    case X509_V_ERR_INVALID_EXTENSION:
        return ("invalid or inconsistent certificate extension");
    case X509_V_ERR_INVALID_POLICY_EXTENSION:
        return ("invalid or inconsistent certificate policy extension");
    case X509_V_ERR_NO_EXPLICIT_POLICY:
        return ("no explicit policy");
    case X509_V_ERR_DIFFERENT_CRL_SCOPE:
        return ("Different CRL scope");
    case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE:
        return ("Unsupported extension feature");
    case X509_V_ERR_UNNESTED_RESOURCE:
        return ("RFC 3779 resource not subset of parent's resources");

    case X509_V_ERR_PERMITTED_VIOLATION:
        return ("permitted subtree violation");
    case X509_V_ERR_EXCLUDED_VIOLATION:
        return ("excluded subtree violation");
    case X509_V_ERR_SUBTREE_MINMAX:
        return ("name constraints minimum and maximum not supported");
    case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE:
        return ("unsupported name constraint type");
    case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX:
        return ("unsupported or invalid name constraint syntax");
    case X509_V_ERR_UNSUPPORTED_NAME_SYNTAX:
        return ("unsupported or invalid name syntax");
    case X509_V_ERR_CRL_PATH_VALIDATION_ERROR:
        return ("CRL path validation error");

    default:
        BIO_snprintf(buf, sizeof buf, "error number %ld", n);
        return (buf);
    }
}

variable_types: n long

variable_types:
buf
char [100]

return_type: char *


decompiled_code:
void *__fastcall MD5(__int64 a1, __int64 a2, void *a3)
{
void *v3; // rbx
int v4; // er8
void *result; // rax
_BYTE v6[120]; // [rsp+0h] [rbp-78h] BYREF

v3 = a3;
if ( !a3 )
v3 = &m_0;
v4 = MD5_Init(v6);
result = 0LL;
if ( v4 )
{
MD5_Update(v6, a1, a2);
MD5_Final(v3, v6);
OPENSSL_cleanse(v6, 92LL);
result = v3;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, __int64 a2, void *a3)
{
void *v3; // rbx
int v4; // er8
void *result; // rax
_BYTE v6[120]; // [rsp+0h] [rbp-78h] BYREF

v3 = a3;
if ( !a3 )
v3 = &m_0;
v4 = MD5_Init(v6);
result = 0LL;
if ( v4 )
{
MD5_Update(v6, a1, a2);
MD5_Final(v3, v6);
OPENSSL_cleanse(v6, 92LL);
result = v3;
}
return result;
}

original_code:
unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
{
    MD5_CTX c;
    static unsigned char m[16];
    if (md == ((void *)0))
        md = m;
    if (!MD5_Init(&c))
        return ((void *)0);
    MD5_Update(&c, d, n);
    MD5_Final(md, &c);
    OPENSSL_cleanse(&c, sizeof(c));
    return (md);
}

canonical_original_code:
unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md)
{
    struct MD5state_st c;
    static unsigned char m[16];
    if (md == ((void *)0))
        md = m;
    if (!MD5_Init(&c))
        return ((void *)0);
    MD5_Update(&c, d, n);
    MD5_Final(md, &c);
    OPENSSL_cleanse(&c, sizeof(c));
    return (md);
}

variable_types:
d
unsigned char *

variable_types:
n
unsigned long

variable_types:
md
unsigned char *

variable_types: struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; }

variable_types:
m
unsigned char [16]

return_type: unsigned char *


decompiled_code:
__int64 engine_unregister_all_RAND()
{
return engine_table_cleanup(&rand_table);
}

canonical_decompiled_code:
__int64 func0()
{
return engine_table_cleanup(&rand_table);
}

original_code:
static void engine_unregister_all_RAND(void)
{
    engine_table_cleanup(&rand_table);
}

canonical_original_code:
static void engine_unregister_all_RAND()
{
    engine_table_cleanup(&rand_table);
}


decompiled_code:
// attributes: thunk
int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n)
{
return strncasecmp(s1, s2, n);
}

canonical_decompiled_code:
int func0(const char *s1, const char *s2, size_t n)
{
return strncasecmp(s1, s2, n);
}

original_code:
int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n)
{
    return strncasecmp(str1, str2, n);
}

canonical_original_code:
int OPENSSL_strncasecmp(char *str1, char *str2, unsigned long n)
{
    return strncasecmp(str1, str2, n);
}


decompiled_code:
// attributes: thunk
int OPENSSL_strcasecmp(const char *s1, const char *s2)
{
return strcasecmp(s1, s2);
}

canonical_decompiled_code:
int func1(const char *s1, const char *s2)
{
return strcasecmp(s1, s2);
}

original_code:
int OPENSSL_strcasecmp(const char *str1, const char *str2)
{
    return strcasecmp(str1, str2);
}

canonical_original_code:
int OPENSSL_strcasecmp(char *str1, char *str2)
{
    return strcasecmp(str1, str2);
}


decompiled_code:
__int64 __fastcall OPENSSL_memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v6; // rax
unsigned int v7; // edx

v6 = 0LL;
v7 = 0;
if ( a3 )
{
do
{
v7 = *(unsigned __int8 *)(a1 + v6) - *(unsigned __int8 *)(a2 + v6);
if ( v7 )
break;
++v6;
}
while ( a3 != v6 );
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v6; // rax
unsigned int v7; // edx

v6 = 0LL;
v7 = 0;
if ( a3 )
{
do
{
v7 = *(unsigned __int8 *)(a1 + v6) - *(unsigned __int8 *)(a2 + v6);
if ( v7 )
break;
++v6;
}
while ( a3 != v6 );
}
return v7;
}

original_code:
int OPENSSL_memcmp(const void *v1, const void *v2, size_t n)
{
    const unsigned char *c1 = v1, *c2 = v2;
    int ret = 0;
    while (n && (ret = *c1 - *c2) == 0)
        n--, c1++, c2++;
    return ret;
}

canonical_original_code:
int OPENSSL_memcmp(void *v1, void *v2, unsigned long n)
{
    unsigned char *c1 = v1; unsigned char *c2 = v2;
    int ret = 0;
    while (n && (ret = *c1 - *c2) == 0)
        n--, c1++, c2++;
    return ret;
}

variable_types: ret int


decompiled_code:
__int64 ssl23_default_timeout()
{
return 300LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 300LL;
}

original_code:
long ssl23_default_timeout(void)
{
    return (300);
}

canonical_original_code:
long ssl23_default_timeout()
{
    return (300);
}

return_type: long


decompiled_code:
__int64 ssl23_num_ciphers()
{
int v0; // ebx

v0 = ssl3_num_ciphers();
return v0 + (unsigned int)ssl2_num_ciphers();
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx

v0 = ssl3_num_ciphers();
return v0 + (unsigned int)ssl2_num_ciphers();
}

original_code:
int ssl23_num_ciphers(void)
{
    return (ssl3_num_ciphers()
            + ssl2_num_ciphers()
        );
}

canonical_original_code:
int ssl23_num_ciphers()
{
    return (ssl3_num_ciphers()
            + ssl2_num_ciphers()
        );
}


decompiled_code:
__int64 __fastcall ssl23_get_cipher(unsigned int a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = ssl3_num_ciphers();
if ( v1 <= a1 )
result = ssl2_get_cipher(a1 - v1);
else
result = ssl3_get_cipher(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = ssl3_num_ciphers();
if ( v1 <= a1 )
result = ssl2_get_cipher(a1 - v1);
else
result = ssl3_get_cipher(a1);
return result;
}

original_code:
const SSL_CIPHER *ssl23_get_cipher(unsigned int u)
{
    unsigned int uu = ssl3_num_ciphers();
    if (u < uu)
        return (ssl3_get_cipher(u));
    else
        return (ssl2_get_cipher(u - uu));
}

canonical_original_code:
struct ssl_cipher_st *ssl23_get_cipher(unsigned int u)
{
    unsigned int uu = ssl3_num_ciphers();
    if (u < uu)
        return (ssl3_get_cipher(u));
    else
        return (ssl2_get_cipher(u - uu));
}

variable_types:
u
unsigned int

variable_types:
uu
unsigned int

return_type: struct ssl_cipher_st { int valid; char *name; unsigned long id; unsigned long algorithm_mkey; unsigned long algorithm_auth; unsigned long algorithm_enc; unsigned long algorithm_mac; unsigned long algorithm_ssl; unsigned long algo_strength; unsigned long algorithm2; int strength_bits; int alg_bits; } *


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

result = ssl3_get_cipher_by_char();
if ( !result )
result = ssl2_get_cipher_by_char(a1);
return result;
}

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

result = ssl3_get_cipher_by_char();
if ( !result )
result = ssl2_get_cipher_by_char(a1);
return result;
}

original_code:
const SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p)
{
    const SSL_CIPHER *cp;
    cp = ssl3_get_cipher_by_char(p);
    if (cp == ((void *)0))
        cp = ssl2_get_cipher_by_char(p);
    return (cp);
}

canonical_original_code:
struct ssl_cipher_st *ssl23_get_cipher_by_char(unsigned char *p)
{
    struct ssl_cipher_st *cp;
    cp = ssl3_get_cipher_by_char(p);
    if (cp == ((void *)0))
        cp = ssl2_get_cipher_by_char(p);
    return (cp);
}

variable_types:
p
unsigned char *

variable_types: struct ssl_cipher_st { int valid; char *name; unsigned long id; unsigned long algorithm_mkey; unsigned long algorithm_auth; unsigned long algorithm_enc; unsigned long algorithm_mac; unsigned long algorithm_ssl; unsigned long algo_strength; unsigned long algorithm2; int strength_bits; int alg_bits; } *


original_code:
int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
{
    long l;
    if (c->algorithm_mkey == 0x00000020L ||
        c->algorithm_mkey == 0x00000040L ||
        c->algorithm_mkey == 0x00000080L ||
        c->algorithm_auth == 0x00000010L || c->algorithm_auth == 0x00000040L)
        return 0;
    if (p != ((void *)0)) {
        l = c->id;
        p[0] = ((unsigned char)(l >> 16L)) & 0xFF;
        p[1] = ((unsigned char)(l >> 8L)) & 0xFF;
        p[2] = ((unsigned char)(l)) & 0xFF;
    }
    return (3);
}

canonical_original_code:
int ssl23_put_cipher_by_char(struct ssl_cipher_st *c, unsigned char *p)
{
    long l;
    if (c->algorithm_mkey == 0x00000020L ||
        c->algorithm_mkey == 0x00000040L ||
        c->algorithm_mkey == 0x00000080L ||
        c->algorithm_auth == 0x00000010L || c->algorithm_auth == 0x00000040L)
        return 0;
    if (p != ((void *)0)) {
        l = c->id;
        p[0] = ((unsigned char)(l >> 16L)) & 0xFF;
        p[1] = ((unsigned char)(l >> 8L)) & 0xFF;
        p[2] = ((unsigned char)(l)) & 0xFF;
    }
    return (3);
}

variable_types: l long

user_defined_types: struct ssl_cipher_st { int valid; char *name; unsigned long id; unsigned long algorithm_mkey; unsigned long algorithm_auth; unsigned long algorithm_enc; unsigned long algorithm_mac; unsigned long algorithm_ssl; unsigned long algo_strength; unsigned long algorithm2; int strength_bits; int alg_bits; }


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

result = sk_pop_free(pbe_algs, free_evp_pbe_ctl);
pbe_algs = 0LL;
return result;
}

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

result = sk_pop_free(pbe_algs, free_evp_pbe_ctl);
pbe_algs = 0LL;
return result;
}

original_code:
void EVP_PBE_cleanup(void)
{
    sk_EVP_PBE_CTL_pop_free(pbe_algs, free_evp_pbe_ctl);
    pbe_algs = NULL;
}

canonical_original_code:
void EVP_PBE_cleanup()
{
    sk_EVP_PBE_CTL_pop_free(pbe_algs, free_evp_pbe_ctl);
    pbe_algs = NULL;
}


fbytes

decompiled_code:
__int64 __fastcall fbytes(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax
int v4; // edx
int v5; // eax
unsigned int v6; // [rsp+Ch] [rbp-2Ch]
__int64 v7[4]; // [rsp+18h] [rbp-20h] BYREF

v7[0] = 0LL;
if ( fbytes_counter > 7 )
return 0LL;
v7[0] = BN_new();
if ( !v7[0] )
return 0LL;
if ( (unsigned int)BN_dec2bn(v7, numbers[fbytes_counter]) )
{
++fbytes_counter;
v3 = BN_num_bits(v7[0]);
v4 = v3 + 14;
v5 = v3 + 7;
if ( v5 >= 0 )
v4 = v5;
result = 0LL;
if ( v4 >> 3 == a2 )
result = (unsigned int)BN_bn2bin(v7[0], a1) != 0;
if ( v7[0] )
{
v6 = result;
BN_free(v7[0]);
result = v6;
}
}
else
{
BN_free(v7[0]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // eax
int v4; // edx
int v5; // eax
unsigned int v6; // [rsp+Ch] [rbp-2Ch]
__int64 v7[4]; // [rsp+18h] [rbp-20h] BYREF

v7[0] = 0LL;
if ( fbytes_counter > 7 )
return 0LL;
v7[0] = BN_new();
if ( !v7[0] )
return 0LL;
if ( (unsigned int)BN_dec2bn(v7, numbers[fbytes_counter]) )
{
++fbytes_counter;
v3 = BN_num_bits(v7[0]);
v4 = v3 + 14;
v5 = v3 + 7;
if ( v5 >= 0 )
v4 = v5;
result = 0LL;
if ( v4 >> 3 == a2 )
result = (unsigned int)BN_bn2bin(v7[0], a1) != 0;
if ( v7[0] )
{
v6 = result;
BN_free(v7[0]);
result = v6;
}
}
else
{
BN_free(v7[0]);
result = 0LL;
}
return result;
}

original_code:
int fbytes(unsigned char *buf, int num)
{
    int ret;
    BIGNUM *tmp = ((void *)0);
    if (fbytes_counter >= 8)
        return 0;
    tmp = BN_new();
    if (!tmp)
        return 0;
    if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) {
        BN_free(tmp);
        return 0;
    }
    fbytes_counter++;
    if (num != ((BN_num_bits(tmp)+7)/8) || !BN_bn2bin(tmp, buf))
        ret = 0;
    else
        ret = 1;
    if (tmp)
        BN_free(tmp);
    return ret;
}

canonical_original_code:
int fbytes(unsigned char *buf, int num)
{
    int ret;
    struct bignum_st *tmp = ((void *)0);
    if (fbytes_counter >= 8)
        return 0;
    tmp = BN_new();
    if (!tmp)
        return 0;
    if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) {
        BN_free(tmp);
        return 0;
    }
    fbytes_counter++;
    if (num != ((BN_num_bits(tmp)+7)/8) || !BN_bn2bin(tmp, buf))
        ret = 0;
    else
        ret = 1;
    if (tmp)
        BN_free(tmp);
    return ret;
}

variable_types:
buf
unsigned char *

variable_types: num int

variable_types: struct bignum_st { unsigned long *d; int top; int dmax; int neg; int flags; } *


decompiled_code:
_BOOL8 __fastcall change_rand(__int64 a1, __int64 a2)
{
__int64 *v2; // rax
__int64 v3; // rcx
_BOOL4 v4; // er8
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rax

v2 = (__int64 *)RAND_get_rand_method();
v4 = 0;
old_rand = (__int64)v2;
if ( v2 )
{
v5 = *v2;
fake_rand[1] = (__int64)fbytes;
fake_rand[0] = v5;
fake_rand[2] = v2[2];
fake_rand[3] = v2[3];
v6 = v2[5];
v7 = v2[1];
fake_rand[5] = v6;
fake_rand[4] = v7;
v4 = RAND_set_rand_method(fake_rand, a2, v6, v3, 0LL) != 0;
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 *v2; // rax
__int64 v3; // rcx
_BOOL4 v4; // er8
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rax

v2 = (__int64 *)RAND_get_rand_method();
v4 = 0;
old_rand = (__int64)v2;
if ( v2 )
{
v5 = *v2;
fake_rand[1] = (__int64)fbytes;
fake_rand[0] = v5;
fake_rand[2] = v2[2];
fake_rand[3] = v2[3];
v6 = v2[5];
v7 = v2[1];
fake_rand[5] = v6;
fake_rand[4] = v7;
v4 = RAND_set_rand_method(fake_rand, a2, v6, v3, 0LL) != 0;
}
return v4;
}

original_code:
int change_rand(void)
{
    if ((old_rand = RAND_get_rand_method()) == ((void *)0))
        return 0;
    fake_rand.seed = old_rand->seed;
    fake_rand.cleanup = old_rand->cleanup;
    fake_rand.add = old_rand->add;
    fake_rand.status = old_rand->status;
    fake_rand.bytes = fbytes;
    fake_rand.pseudorand = old_rand->bytes;
    if (!RAND_set_rand_method(&fake_rand))
        return 0;
    return 1;
}

canonical_original_code:
int change_rand()
{
    if ((old_rand = RAND_get_rand_method()) == ((void *)0))
        return 0;
    fake_rand.seed = old_rand->seed;
    fake_rand.cleanup = old_rand->cleanup;
    fake_rand.add = old_rand->add;
    fake_rand.status = old_rand->status;
    fake_rand.bytes = fbytes;
    fake_rand.pseudorand = old_rand->bytes;
    if (!RAND_set_rand_method(&fake_rand))
        return 0;
    return 1;
}


decompiled_code:
_BOOL8 __fastcall restore_rand(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return (unsigned int)RAND_set_rand_method(old_rand, a2, a3, a4, a5) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return (unsigned int)RAND_set_rand_method(old_rand, a2, a3, a4, a5) != 0;
}

original_code:
int restore_rand(void)
{
    if (!RAND_set_rand_method(old_rand))
        return 0;
    else
        return 1;
}

canonical_original_code:
int restore_rand()
{
    if (!RAND_set_rand_method(old_rand))
        return 0;
    else
        return 1;
}


variable_types: struct bio_st { struct bio_method_st { int type; char *name; int (*bwrite)(struct bio_st *, char *, int); int (*bread)(struct bio_st *, char *, int); int (*bputs)(struct bio_st *, char *); int (*bgets)(struct bio_st *, char *, int); long (*ctrl)(struct bio_st *, int, long, void *); int (*create)(struct bio_st *); int (*destroy)(struct bio_st *); long (*callback_ctrl)(struct bio_st *, int, void (*)(struct bio_st *, int, char *, int, long, long)); } *method; long (*callback)(struct bio_st *, int, char *, int, long, long); char *cb_arg; int init; int shutdown; int flags; int retry_reason; int num; void *ptr; struct bio_st *next_bio; struct bio_st *prev_bio; int references; unsigned long num_read; unsigned long num_write; struct crypto_ex_data_st { struct stack_st_void { struct stack_st { int num; char **data; int sorted; int num_alloc; int (*comp)(void *, void *); } stack; } *sk; int dummy; } ex_data; } *

user_defined_types: struct bio_st { struct bio_method_st *method; long (*callback)(struct bio_st *, int, char *, int, long, long); char *cb_arg; int init; int shutdown; int flags; int retry_reason; int num; void *ptr; struct bio_st *next_bio; struct bio_st *prev_bio; int references; unsigned long num_read; unsigned long num_write; struct crypto_ex_data_st ex_data; }

user_defined_types: struct crypto_ex_data_st { struct stack_st_void *sk; int dummy; }

user_defined_types: struct stack_st_void { struct stack_st stack; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v4; // er12

v3 = BIO_new_fp(stdout, 0LL, envp);
if ( getenv("OPENSSL_DEBUG_MEMORY") && !strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off") )
{
CRYPTO_set_mem_debug_functions(0LL, 0LL, 0LL, 0LL, 0LL);
}
else
{
CRYPTO_set_mem_debug_functions(
&CRYPTO_dbg_malloc,
&CRYPTO_dbg_realloc,
&CRYPTO_dbg_free,
&CRYPTO_dbg_set_options,
&CRYPTO_dbg_get_options);
CRYPTO_set_mem_debug_options(3LL);
}
CRYPTO_mem_ctrl(1LL);
ERR_load_crypto_strings();
RAND_seed("string to make the random number generator think it has entropy", 64LL);
if ( x9_62_tests(v3) && (unsigned int)test_builtin(v3) )
{
v4 = 0;
BIO_printf(v3, "\nECDSA test passed\n");
}
else
{
v4 = 1;
BIO_printf(v3, "\nECDSA test failed\n");
ERR_print_errors(v3);
}
CRYPTO_cleanup_all_ex_data();
ERR_remove_thread_state(0LL);
ERR_free_strings();
CRYPTO_mem_leaks(v3);
if ( v3 )
BIO_free(v3);
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v4; // er12

v3 = BIO_new_fp(stdout, 0LL, envp);
if ( getenv("OPENSSL_DEBUG_MEMORY") && !strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off") )
{
CRYPTO_set_mem_debug_functions(0LL, 0LL, 0LL, 0LL, 0LL);
}
else
{
CRYPTO_set_mem_debug_functions(
&CRYPTO_dbg_malloc,
&CRYPTO_dbg_realloc,
&CRYPTO_dbg_free,
&CRYPTO_dbg_set_options,
&CRYPTO_dbg_get_options);
CRYPTO_set_mem_debug_options(3LL);
}
CRYPTO_mem_ctrl(1LL);
ERR_load_crypto_strings();
RAND_seed("string to make the random number generator think it has entropy", 64LL);
if ( func4(v3) && (unsigned int)func5(v3) )
{
v4 = 0;
BIO_printf(v3, "\nECDSA test passed\n");
}
else
{
v4 = 1;
BIO_printf(v3, "\nECDSA test failed\n");
ERR_print_errors(v3);
}
CRYPTO_cleanup_all_ex_data();
ERR_remove_thread_state(0LL);
ERR_free_strings();
CRYPTO_mem_leaks(v3);
if ( v3 )
BIO_free(v3);
return v4;
}

original_code:
int main(void)
{
    int ret = 1;
    BIO *out;
    out = BIO_new_fp(stdout, 0x00);
    if (!((getenv("OPENSSL_DEBUG_MEMORY") != ((void *)0)) &&
          (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) {
        do { CRYPTO_set_mem_debug_functions( CRYPTO_dbg_malloc, CRYPTO_dbg_realloc, CRYPTO_dbg_free, CRYPTO_dbg_set_options, CRYPTO_dbg_get_options); } while(0);
        CRYPTO_set_mem_debug_options((0x1 | 0x2));
    } else {
        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
    }
    CRYPTO_mem_ctrl(0x1);
    ERR_load_crypto_strings();
    RAND_seed(rnd_seed, sizeof(rnd_seed));
    if (!x9_62_tests(out))
        goto err;
    if (!test_builtin(out))
        goto err;
    ret = 0;
 err:
    if (ret)
        BIO_printf(out, "\nECDSA test failed\n");
    else
        BIO_printf(out, "\nECDSA test passed\n");
    if (ret)
        ERR_print_errors(out);
    CRYPTO_cleanup_all_ex_data();
    ERR_remove_thread_state(((void *)0));
    ERR_free_strings();
    CRYPTO_mem_leaks(out);
    if (out != ((void *)0))
        BIO_free(out);
    return ret;
}

canonical_original_code:
int main()
{
    int ret = 1;
    struct bio_st *out;
    out = BIO_new_fp(stdout, 0x00);
    if (!((getenv("OPENSSL_DEBUG_MEMORY") != ((void *)0)) &&
          (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))) {
        do { CRYPTO_set_mem_debug_functions( CRYPTO_dbg_malloc, CRYPTO_dbg_realloc, CRYPTO_dbg_free, CRYPTO_dbg_set_options, CRYPTO_dbg_get_options); } while(0);
        CRYPTO_set_mem_debug_options((0x1 | 0x2));
    } else {
        CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
    }
    CRYPTO_mem_ctrl(0x1);
    ERR_load_crypto_strings();
    RAND_seed(rnd_seed, sizeof(rnd_seed));
    if (!x9_62_tests(out))
        goto err;
    if (!test_builtin(out))
        goto err;
    ret = 0;
 err:
    if (ret)
        BIO_printf(out, "\nECDSA test failed\n");
    else
        BIO_printf(out, "\nECDSA test passed\n");
    if (ret)
        ERR_print_errors(out);
    CRYPTO_cleanup_all_ex_data();
    ERR_remove_thread_state(((void *)0));
    ERR_free_strings();
    CRYPTO_mem_leaks(out);
    if (out != ((void *)0))
        BIO_free(out);
    return ret;
}

user_defined_types: struct bio_method_st { int type; char *name; int (*bwrite)(struct bio_st *, char *, int); int (*bread)(struct bio_st *, char *, int); int (*bputs)(struct bio_st *, char *); int (*bgets)(struct bio_st *, char *, int); long (*ctrl)(struct bio_st *, int, long, void *); int (*create)(struct bio_st *); int (*destroy)(struct bio_st *); long (*callback_ctrl)(struct bio_st *, int, void (*)(struct bio_st *, int, char *, int, long, long)); }


decompiled_code:
const char *idea_options()
{
return "idea(int)";
}

canonical_decompiled_code:
const char *func0()
{
return "idea(int)";
}

original_code:
const char *idea_options(void)
{
    if (sizeof(short) != sizeof(IDEA_INT))
        return ("idea(int)");
    else
        return ("idea(short)");
}

canonical_original_code:
char *idea_options()
{
    if (sizeof(short) != sizeof(IDEA_INT))
        return ("idea(int)");
    else
        return ("idea(short)");
}


decompiled_code:
__int64 print_test_data()
{
char *v0; // r13
char *v1; // r12
char *v2; // rbp
char *v3; // rbx
__int64 v4; // rsi
char *v5; // rbx
__int64 v6; // rsi
char *v7; // rbx
__int64 v8; // rsi
char *v9; // rbx
__int64 v10; // rsi
char *v11; // rbp
__int64 v12; // r12
char *v13; // rbx
__int64 v14; // rsi
__int64 v15; // rbx
__int64 v16; // rsi
__int64 *v17; // rbx
__int64 v18; // rsi
unsigned __int8 *v19; // rbx
__int64 i; // rsi
size_t v21; // rbx
int v22; // eax
int v23; // eax
__int64 v24; // rsi
char *v25; // rbx
__int64 v26; // rsi
size_t v27; // rbx
int v28; // eax
__int64 v29; // rsi
size_t v30; // rbx
int v31; // eax
__int64 v32; // rsi

v0 = (char *)&unk_EC8;
v1 = (char *)&unk_FE8;
v2 = (char *)&unk_1108;
puts("ecb test data");
puts("key bytes\t\tclear bytes\t\tcipher bytes");
do
{
v3 = v2 - 8;
do
{
v4 = (unsigned __int8)*v3++;
printf("%02X", v4);
}
while ( v3 != v2 );
v5 = v1 - 8;
putchar(9);
do
{
v6 = (unsigned __int8)*v5++;
printf("%02X", v6);
}
while ( v5 != v1 );
v7 = v0 - 8;
putchar(9);
do
{
v8 = (unsigned __int8)*v7++;
printf("%02X", v8);
}
while ( v7 != v0 );
v0 = v7 + 8;
v1 += 8;
v2 += 8;
putchar(10);
}
while ( v7 != (char *)&unk_FD0 );
v9 = (char *)&key_data;
puts("set_key test data");
printf("data[8]= ");
do
{
v10 = (unsigned __int8)*v9++;
printf("%02X", v10);
}
while ( v9 != key_test );
v11 = (char *)&unk_D28;
v12 = 1LL;
putchar(10);
do
{
v13 = v11 - 8;
printf("c=");
do
{
v14 = (unsigned __int8)*v13++;
printf("%02X", v14);
}
while ( v13 != v11 );
v15 = 0LL;
printf(" k[%2u]=", (unsigned int)v12);
do
{
v16 = (unsigned __int8)key_test[v15++];
printf("%02X", v16);
}
while ( v15 != v12 );
v12 = v15 + 1;
v11 += 8;
putchar(10);
}
while ( v15 != 24 );
v17 = (__int64 *)&cbc_key;
puts("\nchaining mode test data");
printf("key[16] = ");
do
{
v18 = *(unsigned __int8 *)v17;
v17 = (__int64 *)((char *)v17 + 1);
printf("%02X", v18);
}
while ( &cipher_data != v17 );
v19 = (unsigned __int8 *)&unk_15B1;
printf("\niv[8] = ");
for ( i = 254LL; ; i = *v19++ )
{
printf("%02X", i);
if ( &unk_15B8 == (_UNKNOWN *)v19 )
break;
}
v21 = 0LL;
v22 = strlen(cbc_data);
printf("\ndata[%d] = '%s'", (unsigned int)(v22 + 1), cbc_data);
v23 = strlen(cbc_data);
printf("\ndata[%d] = ", (unsigned int)(v23 + 1));
do
{
v24 = (unsigned int)cbc_data[v21++];
printf("%02X", v24);
}
while ( strlen(cbc_data) + 1 > v21 );
v25 = (char *)&cbc_ok;
putchar(10);
puts("cbc cipher text");
printf("cipher[%d]= ", 32LL);
do
{
v26 = (unsigned __int8)*v25++;
printf("%02X", v26);
}
while ( v25 != cbc_data );
v27 = 0LL;
putchar(10);
puts("cfb64 cipher text");
v28 = strlen(cbc_data);
printf("cipher[%d]= ", (unsigned int)(v28 + 1));
do
{
v29 = (unsigned __int8)cfb64_ok[v27++];
printf("%02X", v29);
}
while ( strlen(cbc_data) + 1 > v27 );
v30 = 0LL;
putchar(10);
puts("ofb64 cipher text");
v31 = strlen(cbc_data);
printf("cipher[%d]= ", (unsigned int)(v31 + 1));
do
{
v32 = (unsigned __int8)ofb64_ok[v30++];
printf("%02X", v32);
}
while ( strlen(cbc_data) + 1 > v30 );
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
char *v0; // r13
char *v1; // r12
char *v2; // rbp
char *v3; // rbx
__int64 v4; // rsi
char *v5; // rbx
__int64 v6; // rsi
char *v7; // rbx
__int64 v8; // rsi
char *v9; // rbx
__int64 v10; // rsi
char *v11; // rbp
__int64 v12; // r12
char *v13; // rbx
__int64 v14; // rsi
__int64 v15; // rbx
__int64 v16; // rsi
__int64 *v17; // rbx
__int64 v18; // rsi
unsigned __int8 *v19; // rbx
__int64 i; // rsi
size_t v21; // rbx
int v22; // eax
int v23; // eax
__int64 v24; // rsi
char *v25; // rbx
__int64 v26; // rsi
size_t v27; // rbx
int v28; // eax
__int64 v29; // rsi
size_t v30; // rbx
int v31; // eax
__int64 v32; // rsi

v0 = (char *)&unk_EC8;
v1 = (char *)&unk_FE8;
v2 = (char *)&unk_1108;
puts("ecb test data");
puts("key bytes\t\tclear bytes\t\tcipher bytes");
do
{
v3 = v2 - 8;
do
{
v4 = (unsigned __int8)*v3++;
printf("%02X", v4);
}
while ( v3 != v2 );
v5 = v1 - 8;
putchar(9);
do
{
v6 = (unsigned __int8)*v5++;
printf("%02X", v6);
}
while ( v5 != v1 );
v7 = v0 - 8;
putchar(9);
do
{
v8 = (unsigned __int8)*v7++;
printf("%02X", v8);
}
while ( v7 != v0 );
v0 = v7 + 8;
v1 += 8;
v2 += 8;
putchar(10);
}
while ( v7 != (char *)&unk_FD0 );
v9 = (char *)&key_data;
puts("set_key test data");
printf("data[8]= ");
do
{
v10 = (unsigned __int8)*v9++;
printf("%02X", v10);
}
while ( v9 != key_test );
v11 = (char *)&unk_D28;
v12 = 1LL;
putchar(10);
do
{
v13 = v11 - 8;
printf("c=");
do
{
v14 = (unsigned __int8)*v13++;
printf("%02X", v14);
}
while ( v13 != v11 );
v15 = 0LL;
printf(" k[%2u]=", (unsigned int)v12);
do
{
v16 = (unsigned __int8)key_test[v15++];
printf("%02X", v16);
}
while ( v15 != v12 );
v12 = v15 + 1;
v11 += 8;
putchar(10);
}
while ( v15 != 24 );
v17 = (__int64 *)&cbc_key;
puts("\nchaining mode test data");
printf("key[16] = ");
do
{
v18 = *(unsigned __int8 *)v17;
v17 = (__int64 *)((char *)v17 + 1);
printf("%02X", v18);
}
while ( &cipher_data != v17 );
v19 = (unsigned __int8 *)&unk_15B1;
printf("\niv[8] = ");
for ( i = 254LL; ; i = *v19++ )
{
printf("%02X", i);
if ( &unk_15B8 == (_UNKNOWN *)v19 )
break;
}
v21 = 0LL;
v22 = strlen(cbc_data);
printf("\ndata[%d] = '%s'", (unsigned int)(v22 + 1), cbc_data);
v23 = strlen(cbc_data);
printf("\ndata[%d] = ", (unsigned int)(v23 + 1));
do
{
v24 = (unsigned int)cbc_data[v21++];
printf("%02X", v24);
}
while ( strlen(cbc_data) + 1 > v21 );
v25 = (char *)&cbc_ok;
putchar(10);
puts("cbc cipher text");
printf("cipher[%d]= ", 32LL);
do
{
v26 = (unsigned __int8)*v25++;
printf("%02X", v26);
}
while ( v25 != cbc_data );
v27 = 0LL;
putchar(10);
puts("cfb64 cipher text");
v28 = strlen(cbc_data);
printf("cipher[%d]= ", (unsigned int)(v28 + 1));
do
{
v29 = (unsigned __int8)cfb64_ok[v27++];
printf("%02X", v29);
}
while ( strlen(cbc_data) + 1 > v27 );
v30 = 0LL;
putchar(10);
puts("ofb64 cipher text");
v31 = strlen(cbc_data);
printf("cipher[%d]= ", (unsigned int)(v31 + 1));
do
{
v32 = (unsigned __int8)ofb64_ok[v30++];
printf("%02X", v32);
}
while ( strlen(cbc_data) + 1 > v30 );
putchar(10);
return 0LL;
}

original_code:
static int print_test_data(void)
{
    unsigned int i, j;
    printf("ecb test data\n");
    printf("key bytes\t\tclear bytes\t\tcipher bytes\n");
    for (i = 0; i < 34; i++) {
        for (j = 0; j < 8; j++)
            printf("%02X", ecb_data[i][j]);
        printf("\t");
        for (j = 0; j < 8; j++)
            printf("%02X", plain_data[i][j]);
        printf("\t");
        for (j = 0; j < 8; j++)
            printf("%02X", cipher_data[i][j]);
        printf("\n");
    }
    printf("set_key test data\n");
    printf("data[8]= ");
    for (j = 0; j < 8; j++)
        printf("%02X", key_data[j]);
    printf("\n");
    for (i = 0; i < 25 - 1; i++) {
        printf("c=");
        for (j = 0; j < 8; j++)
            printf("%02X", key_out[i][j]);
        printf(" k[%2u]=", i + 1);
        for (j = 0; j < i + 1; j++)
            printf("%02X", key_test[j]);
        printf("\n");
    }
    printf("\nchaining mode test data\n");
    printf("key[16]   = ");
    for (j = 0; j < 16; j++)
        printf("%02X", cbc_key[j]);
    printf("\niv[8]     = ");
    for (j = 0; j < 8; j++)
        printf("%02X", cbc_iv[j]);
    printf("\ndata[%d]  = '%s'", (int)strlen(cbc_data) + 1, cbc_data);
    printf("\ndata[%d]  = ", (int)strlen(cbc_data) + 1);
    for (j = 0; j < strlen(cbc_data) + 1; j++)
        printf("%02X", cbc_data[j]);
    printf("\n");
    printf("cbc cipher text\n");
    printf("cipher[%d]= ", 32);
    for (j = 0; j < 32; j++)
        printf("%02X", cbc_ok[j]);
    printf("\n");
    printf("cfb64 cipher text\n");
    printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
    for (j = 0; j < strlen(cbc_data) + 1; j++)
        printf("%02X", cfb64_ok[j]);
    printf("\n");
    printf("ofb64 cipher text\n");
    printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
    for (j = 0; j < strlen(cbc_data) + 1; j++)
        printf("%02X", ofb64_ok[j]);
    printf("\n");
    return (0);
}

canonical_original_code:
static int print_test_data()
{
    unsigned int i; unsigned int j;
    printf("ecb test data\n");
    printf("key bytes\t\tclear bytes\t\tcipher bytes\n");
    for (i = 0; i < 34; i++) {
        for (j = 0; j < 8; j++)
            printf("%02X", ecb_data[i][j]);
        printf("\t");
        for (j = 0; j < 8; j++)
            printf("%02X", plain_data[i][j]);
        printf("\t");
        for (j = 0; j < 8; j++)
            printf("%02X", cipher_data[i][j]);
        printf("\n");
    }
    printf("set_key test data\n");
    printf("data[8]= ");
    for (j = 0; j < 8; j++)
        printf("%02X", key_data[j]);
    printf("\n");
    for (i = 0; i < 25 - 1; i++) {
        printf("c=");
        for (j = 0; j < 8; j++)
            printf("%02X", key_out[i][j]);
        printf(" k[%2u]=", i + 1);
        for (j = 0; j < i + 1; j++)
            printf("%02X", key_test[j]);
        printf("\n");
    }
    printf("\nchaining mode test data\n");
    printf("key[16]   = ");
    for (j = 0; j < 16; j++)
        printf("%02X", cbc_key[j]);
    printf("\niv[8]     = ");
    for (j = 0; j < 8; j++)
        printf("%02X", cbc_iv[j]);
    printf("\ndata[%d]  = '%s'", (int)strlen(cbc_data) + 1, cbc_data);
    printf("\ndata[%d]  = ", (int)strlen(cbc_data) + 1);
    for (j = 0; j < strlen(cbc_data) + 1; j++)
        printf("%02X", cbc_data[j]);
    printf("\n");
    printf("cbc cipher text\n");
    printf("cipher[%d]= ", 32);
    for (j = 0; j < 32; j++)
        printf("%02X", cbc_ok[j]);
    printf("\n");
    printf("cfb64 cipher text\n");
    printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
    for (j = 0; j < strlen(cbc_data) + 1; j++)
        printf("%02X", cfb64_ok[j]);
    printf("\n");
    printf("ofb64 cipher text\n");
    printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
    for (j = 0; j < strlen(cbc_data) + 1; j++)
        printf("%02X", ofb64_ok[j]);
    printf("\n");
    return (0);
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int