#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_19__ TYPE_8__;
typedef struct TYPE_18__ TYPE_7__;
typedef struct TYPE_17__ TYPE_6__;
typedef struct TYPE_16__ TYPE_5__;
typedef struct TYPE_15__ TYPE_4__;
typedef struct TYPE_14__ TYPE_3__;
typedef struct TYPE_13__ TYPE_2__;
typedef struct TYPE_12__ TYPE_1__;

/* Type definitions */
struct TYPE_13__ {
  TYPE_1__ *sequence;
};
struct TYPE_19__ {
  scalar_t__ type;
  TYPE_2__ value;
};
struct TYPE_18__ {
  scalar_t__ iter;
  TYPE_6__ *salt;
  TYPE_3__ *prf;
  scalar_t__ keylength;
};
struct TYPE_16__ {
  TYPE_4__ *octet_string;
};
struct TYPE_17__ {
  scalar_t__ type;
  TYPE_5__ value;
};
struct TYPE_15__ {
  unsigned char *data;
  int length;
};
struct TYPE_14__ {
  int /*<<< orphan*/ algorithm;
};
struct TYPE_12__ {
  unsigned char *data;
  int length;
};
typedef TYPE_7__ PBKDF2PARAM;
typedef int /*<<< orphan*/ EVP_MD;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;
typedef int /*<<< orphan*/ EVP_CIPHER;
typedef TYPE_8__ ASN1_TYPE;

/* Variables and functions */
int ASN1_INTEGER_get(scalar_t__);
int /*<<< orphan*/ *EVP_CIPHER_CTX_cipher(int /*<<< orphan*/ *);
unsigned int EVP_CIPHER_CTX_key_length(int /*<<< orphan*/ *);
int EVP_CipherInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ *, unsigned char *,
                      int /*<<< orphan*/ *, int);
int /*<<< orphan*/ EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN;
int EVP_MAX_KEY_LENGTH;
int /*<<< orphan*/ EVP_PBE_TYPE_PRF;
int /*<<< orphan*/ EVP_PBE_find(int /*<<< orphan*/, int, int /*<<< orphan*/ *,
                                int *, int /*<<< orphan*/);
int /*<<< orphan*/ EVP_R_BAD_KEY_LENGTH;
int /*<<< orphan*/ EVP_R_DECODE_ERROR;
int /*<<< orphan*/ EVP_R_NO_CIPHER_SET;
int /*<<< orphan*/ EVP_R_UNSUPPORTED_KEYLENGTH;
int /*<<< orphan*/ EVP_R_UNSUPPORTED_PRF;
int /*<<< orphan*/ EVP_R_UNSUPPORTED_SALT_TYPE;
int /*<<< orphan*/ *EVP_get_digestbynid(int);
int /*<<< orphan*/ EVPerr(int /*<<< orphan*/, int /*<<< orphan*/);
int NID_hmacWithSHA1;
int OBJ_obj2nid(int /*<<< orphan*/);
int /*<<< orphan*/ OPENSSL_cleanse(unsigned char *, unsigned int);
int /*<<< orphan*/ PBKDF2PARAM_free(TYPE_7__ *);
int /*<<< orphan*/ PKCS5_PBKDF2_HMAC(char const *, int, unsigned char *, int,
                                     int, int /*<<< orphan*/ const *,
                                     unsigned int, unsigned char *);
scalar_t__ V_ASN1_OCTET_STRING;
scalar_t__ V_ASN1_SEQUENCE;
TYPE_7__ *d2i_PBKDF2PARAM(int /*<<< orphan*/ *, unsigned char const **, int);
int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
                             ASN1_TYPE *param, const EVP_CIPHER *c,
                             const EVP_MD *md, int en_de) {
  unsigned char *salt, key[EVP_MAX_KEY_LENGTH];
  const unsigned char *pbuf;
  int saltlen, iter, plen;
  int rv = 0;
  unsigned int keylen = 0;
  int prf_nid, hmac_md_nid;
  PBKDF2PARAM *kdf = NULL;
  const EVP_MD *prfmd;
  if (EVP_CIPHER_CTX_cipher(ctx) == NULL) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_NO_CIPHER_SET);
    return 0;
  }
  keylen = EVP_CIPHER_CTX_key_length(ctx);
  if (keylen > sizeof key) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_BAD_KEY_LENGTH);
    return 0;
  }
  if (!param || (param->type != V_ASN1_SEQUENCE)) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_DECODE_ERROR);
    return 0;
  }
  pbuf = param->value.sequence->data;
  plen = param->value.sequence->length;
  if (!(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen))) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_DECODE_ERROR);
    return 0;
  }
  if (kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != (int)keylen)) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_KEYLENGTH);
    goto err;
  }
  if (kdf->prf)
    prf_nid = OBJ_obj2nid(kdf->prf->algorithm);
  else
    prf_nid = NID_hmacWithSHA1;
  if (!EVP_PBE_find(EVP_PBE_TYPE_PRF, prf_nid, NULL, &hmac_md_nid, 0)) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
    goto err;
  }
  prfmd = EVP_get_digestbynid(hmac_md_nid);
  if (prfmd == NULL) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
    goto err;
  }
  if (kdf->salt->type != V_ASN1_OCTET_STRING) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_SALT_TYPE);
    goto err;
  }
  salt = kdf->salt->value.octet_string->data;
  saltlen = kdf->salt->value.octet_string->length;
  iter = ASN1_INTEGER_get(kdf->iter);
  if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, prfmd, keylen,
                         key))
    goto err;
  rv = EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
err:
  OPENSSL_cleanse(key, keylen);
  PBKDF2PARAM_free(kdf);
  return rv;
}


x86 assembly (clang, -O0):
<PKCS5_v2_PBKDF2_keyivgen>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xa0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movq   $0x0,-0x80(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <EVP_CIPHER_CTX_cipher@plt>
cmp    $0x0,%rax
jne    1271 <PKCS5_v2_PBKDF2_keyivgen+0xb1>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1560 <PKCS5_v2_PBKDF2_keyivgen+0x3a0>
mov    -0x10(%rbp),%rdi
call   10d0 <EVP_CIPHER_CTX_key_length@plt>
mov    -0xa0(%rbp),%rcx
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    %rcx,%rax
jbe    12bd <PKCS5_v2_PBKDF2_keyivgen+0xfd>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    0x2d20(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1560 <PKCS5_v2_PBKDF2_keyivgen+0x3a0>
cmpq   $0x0,-0x28(%rbp)
je     12df <PKCS5_v2_PBKDF2_keyivgen+0x11f>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2cb2(%rip),%rcx
cmp    (%rcx),%rax
je     130c <PKCS5_v2_PBKDF2_keyivgen+0x14c>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
mov    0x2cb9(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1560 <PKCS5_v2_PBKDF2_keyivgen+0x3a0>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x58(%rbp),%rsi
call   1090 <d2i_PBKDF2PARAM@plt>
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
jne    1374 <PKCS5_v2_PBKDF2_keyivgen+0x1b4>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
mov    0x2c51(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
jmp    1560 <PKCS5_v2_PBKDF2_keyivgen+0x3a0>
mov    -0x80(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     13b5 <PKCS5_v2_PBKDF2_keyivgen+0x1f5>
mov    -0x80(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <ASN1_INTEGER_get@plt>
cmp    -0x6c(%rbp),%eax
je     13b5 <PKCS5_v2_PBKDF2_keyivgen+0x1f5>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
mov    0x2c1f(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
jmp    1538 <PKCS5_v2_PBKDF2_keyivgen+0x378>
mov    -0x80(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     13db <PKCS5_v2_PBKDF2_keyivgen+0x21b>
mov    -0x80(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%edi
call   1040 <OBJ_obj2nid@plt>
mov    %eax,-0x70(%rbp)
jmp    13e7 <PKCS5_v2_PBKDF2_keyivgen+0x227>
mov    0x2bce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2baa(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x74(%rbp),%rcx
xor    %r8d,%r8d
call   1030 <EVP_PBE_find@plt>
cmp    $0x0,%eax
jne    1428 <PKCS5_v2_PBKDF2_keyivgen+0x268>
mov    0x2bdd(%rip),%rax
mov    (%rax),%edi
mov    0x2bb4(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
jmp    1538 <PKCS5_v2_PBKDF2_keyivgen+0x378>
mov    -0x74(%rbp),%edi
call   1060 <EVP_get_digestbynid@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    1461 <PKCS5_v2_PBKDF2_keyivgen+0x2a1>
mov    0x2ba4(%rip),%rax
mov    (%rax),%edi
mov    0x2b7b(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
jmp    1538 <PKCS5_v2_PBKDF2_keyivgen+0x378>
mov    -0x80(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    0x2b2d(%rip),%rcx
cmp    (%rcx),%rax
je     1498 <PKCS5_v2_PBKDF2_keyivgen+0x2d8>
mov    0x2b6d(%rip),%rax
mov    (%rax),%edi
mov    0x2af4(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
jmp    1538 <PKCS5_v2_PBKDF2_keyivgen+0x378>
mov    -0x80(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x80(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x80(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <ASN1_INTEGER_get@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
mov    %ecx,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x5c(%rbp),%ecx
mov    -0x60(%rbp),%r8d
mov    -0x88(%rbp),%r9
mov    -0x6c(%rbp),%r10d
sub    $0x10,%rsp
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <PKCS5_PBKDF2_HMAC@plt>
add    $0x10,%rsp
cmp    $0x0,%eax
jne    1516 <PKCS5_v2_PBKDF2_keyivgen+0x356>
jmp    1538 <PKCS5_v2_PBKDF2_keyivgen+0x378>
mov    -0x98(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    0x10(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
call   10e0 <EVP_CipherInit_ex@plt>
mov    %eax,-0x68(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x6c(%rbp),%esi
call   1070 <OPENSSL_cleanse@plt>
mov    -0x80(%rbp),%rdi
call   10b0 <PBKDF2PARAM_free@plt>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x8c(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS5_v2_PBKDF2_keyivgen>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %edx,-0x40(%rbp)
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2dfc(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r13
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
call   10c0 <EVP_CIPHER_CTX_cipher@plt>
test   %rax,%rax
je     1222 <PKCS5_v2_PBKDF2_keyivgen+0x62>
mov    %r12,%rdi
call   10d0 <EVP_CIPHER_CTX_key_length@plt>
cmp    %ebx,%eax
jbe    1234 <PKCS5_v2_PBKDF2_keyivgen+0x74>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    0x2da3(%rip),%rax
jmp    12a7 <PKCS5_v2_PBKDF2_keyivgen+0xe7>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
jmp    12a7 <PKCS5_v2_PBKDF2_keyivgen+0xe7>
test   %r14,%r14
je     1297 <PKCS5_v2_PBKDF2_keyivgen+0xd7>
mov    (%r14),%rdx
mov    0x2d45(%rip),%rcx
cmp    (%rcx),%rdx
jne    1297 <PKCS5_v2_PBKDF2_keyivgen+0xd7>
mov    %rax,-0x30(%rbp)
mov    0x8(%r14),%rax
mov    (%rax),%rcx
mov    %rcx,-0x50(%rbp)
mov    0x8(%rax),%edx
xor    %r14d,%r14d
lea    -0x50(%rbp),%rsi
xor    %edi,%edi
call   1090 <d2i_PBKDF2PARAM@plt>
test   %rax,%rax
je     12c3 <PKCS5_v2_PBKDF2_keyivgen+0x103>
mov    %rax,%rbx
mov    0x18(%rax),%rdi
test   %rdi,%rdi
je     1283 <PKCS5_v2_PBKDF2_keyivgen+0xc3>
call   10a0 <ASN1_INTEGER_get@plt>
cmp    -0x30(%rbp),%eax
jne    12dc <PKCS5_v2_PBKDF2_keyivgen+0x11c>
mov    0x10(%rbx),%rax
test   %rax,%rax
je     12f1 <PKCS5_v2_PBKDF2_keyivgen+0x131>
mov    (%rax),%edi
call   1040 <OBJ_obj2nid@plt>
mov    %eax,%esi
jmp    12fa <PKCS5_v2_PBKDF2_keyivgen+0x13a>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
jmp    12b1 <PKCS5_v2_PBKDF2_keyivgen+0xf1>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    0x2cdc(%rip),%rax
jmp    13f7 <PKCS5_v2_PBKDF2_keyivgen+0x237>
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
xor    %r14d,%r14d
lea    -0x44(%rbp),%rcx
xor    %edx,%edx
xor    %r8d,%r8d
call   1030 <EVP_PBE_find@plt>
test   %eax,%eax
je     13a3 <PKCS5_v2_PBKDF2_keyivgen+0x1e3>
mov    %rbx,-0x38(%rbp)
mov    -0x44(%rbp),%edi
call   1060 <EVP_get_digestbynid@plt>
test   %rax,%rax
je     13c0 <PKCS5_v2_PBKDF2_keyivgen+0x200>
mov    %rax,%rbx
mov    -0x38(%rbp),%rsi
mov    0x8(%rsi),%rax
mov    (%rax),%rcx
mov    0x2c5a(%rip),%rdx
cmp    (%rdx),%rcx
jne    13e4 <PKCS5_v2_PBKDF2_keyivgen+0x224>
mov    0x8(%rax),%rax
mov    (%rax),%r14
mov    0x8(%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    (%rsi),%rdi
call   10a0 <ASN1_INTEGER_get@plt>
mov    %r15,%rdi
mov    -0x40(%rbp),%esi
mov    %r14,%rdx
mov    -0x3c(%rbp),%ecx
mov    %eax,%r8d
mov    %rbx,%r9
push   %r13
push   -0x30(%rbp)
call   1050 <PKCS5_PBKDF2_HMAC@plt>
add    $0x10,%rsp
test   %eax,%eax
je     13d7 <PKCS5_v2_PBKDF2_keyivgen+0x217>
mov    0x10(%rbp),%r9d
mov    %r12,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r13,%rcx
xor    %r8d,%r8d
call   10e0 <EVP_CipherInit_ex@plt>
mov    %eax,%r14d
jmp    13da <PKCS5_v2_PBKDF2_keyivgen+0x21a>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
mov    -0x30(%rbp),%rsi
jmp    1405 <PKCS5_v2_PBKDF2_keyivgen+0x245>
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
mov    0x2c00(%rip),%rax
mov    (%rax),%esi
call   1080 <EVPerr@plt>
xor    %r14d,%r14d
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rbx
jmp    1405 <PKCS5_v2_PBKDF2_keyivgen+0x245>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
mov    0x2b8c(%rip),%rax
mov    %rsi,%rbx
mov    (%rax),%esi
call   1080 <EVPerr@plt>
xor    %r14d,%r14d
mov    -0x30(%rbp),%rsi
mov    %r13,%rdi
call   1070 <OPENSSL_cleanse@plt>
mov    %rbx,%rdi
call   10b0 <PBKDF2PARAM_free@plt>
jmp    12b1 <PKCS5_v2_PBKDF2_keyivgen+0xf1>

LLVM IR (-O0):
%struct.TYPE_19__ = type { i64, %struct.TYPE_13__ }
%struct.TYPE_13__ = type { %struct.TYPE_12__* }
%struct.TYPE_12__ = type { i8*, i32 }
%struct.TYPE_18__ = type { i64, %struct.TYPE_17__*, %struct.TYPE_14__*, i64 }
%struct.TYPE_17__ = type { i64, %struct.TYPE_16__ }
%struct.TYPE_16__ = type { %struct.TYPE_15__* }
%struct.TYPE_15__ = type { i8*, i32 }
%struct.TYPE_14__ = type { i32 }
@EVP_MAX_KEY_LENGTH = global i32 0
@EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN = global i32 0
@EVP_R_NO_CIPHER_SET = global i32 0
@EVP_R_BAD_KEY_LENGTH = global i32 0
@V_ASN1_SEQUENCE = global i64 0
@EVP_R_DECODE_ERROR = global i32 0
@EVP_R_UNSUPPORTED_KEYLENGTH = global i32 0
@NID_hmacWithSHA1 = global i32 0
@EVP_PBE_TYPE_PRF = global i32 0
@EVP_R_UNSUPPORTED_PRF = global i32 0
@V_ASN1_OCTET_STRING = global i64 0
@EVP_R_UNSUPPORTED_SALT_TYPE = global i32 0
define i32 @PKCS5_v2_PBKDF2_keyivgen(i32* %0, i8* %1, i32 %2, %struct.TYPE_19__* %3, i32* %4, i32* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.TYPE_19__*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca %struct.TYPE_18__*
%28 = alloca i32*
%29 = alloca i32
store i32* %0, i32** %9
store i8* %1, i8** %10
store i32 %2, i32* %11
store %struct.TYPE_19__* %3, %struct.TYPE_19__** %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i32 %6, i32* %15
%30 = load i32, i32* @EVP_MAX_KEY_LENGTH
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %17
%33 = alloca i8, i64 %31
store i64 %31, i64* %18
store i32 0, i32* %23
store i32 0, i32* %24
store %struct.TYPE_18__* null, %struct.TYPE_18__** %27
%34 = load i32*, i32** %9
%35 = call i32* @EVP_CIPHER_CTX_cipher(i32* %34)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %7
%38 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%39 = load i32, i32* @EVP_R_NO_CIPHER_SET
%40 = call i32 @EVPerr(i32 %38, i32 %39)
store i32 0, i32* %8
store i32 1, i32* %29
br label %185
41: ; preds = %7
%42 = load i32*, i32** %9
%43 = call i32 @EVP_CIPHER_CTX_key_length(i32* %42)
store i32 %43, i32* %24
%44 = load i32, i32* %24
%45 = zext i32 %44 to i64
%46 = icmp ugt i64 %45, %31
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%49 = load i32, i32* @EVP_R_BAD_KEY_LENGTH
%50 = call i32 @EVPerr(i32 %48, i32 %49)
store i32 0, i32* %8
store i32 1, i32* %29
br label %185
51: ; preds = %41
%52 = load %struct.TYPE_19__*, %struct.TYPE_19__** %12
%53 = icmp ne %struct.TYPE_19__* %52, null
br i1 %53, label %54, label %60
54: ; preds = %51
%55 = load %struct.TYPE_19__*, %struct.TYPE_19__** %12
%56 = getelementptr inbounds %struct.TYPE_19__, %struct.TYPE_19__* %55, i32 0, i32 0
%57 = load i64, i64* %56
%58 = load i64, i64* @V_ASN1_SEQUENCE
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %64
60: ; preds = %54, %51
%61 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%62 = load i32, i32* @EVP_R_DECODE_ERROR
%63 = call i32 @EVPerr(i32 %61, i32 %62)
store i32 0, i32* %8
store i32 1, i32* %29
br label %185
64: ; preds = %54
%65 = load %struct.TYPE_19__*, %struct.TYPE_19__** %12
%66 = getelementptr inbounds %struct.TYPE_19__, %struct.TYPE_19__* %65, i32 0, i32 1
%67 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %66, i32 0, i32 0
%68 = load %struct.TYPE_12__*, %struct.TYPE_12__** %67
%69 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %68, i32 0, i32 0
%70 = load i8*, i8** %69
store i8* %70, i8** %19
%71 = load %struct.TYPE_19__*, %struct.TYPE_19__** %12
%72 = getelementptr inbounds %struct.TYPE_19__, %struct.TYPE_19__* %71, i32 0, i32 1
%73 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %72, i32 0, i32 0
%74 = load %struct.TYPE_12__*, %struct.TYPE_12__** %73
%75 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %74, i32 0, i32 1
%76 = load i32, i32* %75
store i32 %76, i32* %22
%77 = load i32, i32* %22
%78 = call %struct.TYPE_18__* @d2i_PBKDF2PARAM(i32* null, i8** %19, i32 %77)
store %struct.TYPE_18__* %78, %struct.TYPE_18__** %27
%79 = icmp ne %struct.TYPE_18__* %78, null
br i1 %79, label %84, label %80
80: ; preds = %64
%81 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%82 = load i32, i32* @EVP_R_DECODE_ERROR
%83 = call i32 @EVPerr(i32 %81, i32 %82)
store i32 0, i32* %8
store i32 1, i32* %29
br label %185
84: ; preds = %64
%85 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%86 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %85, i32 0, i32 3
%87 = load i64, i64* %86
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %100
89: ; preds = %84
%90 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%91 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %90, i32 0, i32 3
%92 = load i64, i64* %91
%93 = call i32 @ASN1_INTEGER_get(i64 %92)
%94 = load i32, i32* %24
%95 = icmp ne i32 %93, %94
br i1 %95, label %96, label %100
96: ; preds = %89
%97 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%98 = load i32, i32* @EVP_R_UNSUPPORTED_KEYLENGTH
%99 = call i32 @EVPerr(i32 %97, i32 %98)
br label %179
100: ; preds = %89, %84
%101 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%102 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %101, i32 0, i32 2
%103 = load %struct.TYPE_14__*, %struct.TYPE_14__** %102
%104 = icmp ne %struct.TYPE_14__* %103, null
br i1 %104, label %105, label %112
105: ; preds = %100
%106 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%107 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %106, i32 0, i32 2
%108 = load %struct.TYPE_14__*, %struct.TYPE_14__** %107
%109 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %108, i32 0, i32 0
%110 = load i32, i32* %109
%111 = call i32 @OBJ_obj2nid(i32 %110)
store i32 %111, i32* %25
br label %114
112: ; preds = %100
%113 = load i32, i32* @NID_hmacWithSHA1
store i32 %113, i32* %25
br label %114
114: ; preds = %112, %105
%115 = load i32, i32* @EVP_PBE_TYPE_PRF
%116 = load i32, i32* %25
%117 = call i32 @EVP_PBE_find(i32 %115, i32 %116, i32* null, i32* %26, i32 0)
%118 = icmp ne i32 %117, 0
br i1 %118, label %123, label %119
119: ; preds = %114
%120 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%121 = load i32, i32* @EVP_R_UNSUPPORTED_PRF
%122 = call i32 @EVPerr(i32 %120, i32 %121)
br label %179
123: ; preds = %114
%124 = load i32, i32* %26
%125 = call i32* @EVP_get_digestbynid(i32 %124)
store i32* %125, i32** %28
%126 = load i32*, i32** %28
%127 = icmp eq i32* %126, null
br i1 %127, label %128, label %132
128: ; preds = %123
%129 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%130 = load i32, i32* @EVP_R_UNSUPPORTED_PRF
%131 = call i32 @EVPerr(i32 %129, i32 %130)
br label %179
132: ; preds = %123
%133 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%134 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %133, i32 0, i32 1
%135 = load %struct.TYPE_17__*, %struct.TYPE_17__** %134
%136 = getelementptr inbounds %struct.TYPE_17__, %struct.TYPE_17__* %135, i32 0, i32 0
%137 = load i64, i64* %136
%138 = load i64, i64* @V_ASN1_OCTET_STRING
%139 = icmp ne i64 %137, %138
br i1 %139, label %140, label %144
140: ; preds = %132
%141 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%142 = load i32, i32* @EVP_R_UNSUPPORTED_SALT_TYPE
%143 = call i32 @EVPerr(i32 %141, i32 %142)
br label %179
144: ; preds = %132
%145 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%146 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %145, i32 0, i32 1
%147 = load %struct.TYPE_17__*, %struct.TYPE_17__** %146
%148 = getelementptr inbounds %struct.TYPE_17__, %struct.TYPE_17__* %147, i32 0, i32 1
%149 = getelementptr inbounds %struct.TYPE_16__, %struct.TYPE_16__* %148, i32 0, i32 0
%150 = load %struct.TYPE_15__*, %struct.TYPE_15__** %149
%151 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %150, i32 0, i32 0
%152 = load i8*, i8** %151
store i8* %152, i8** %16
%153 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%154 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %153, i32 0, i32 1
%155 = load %struct.TYPE_17__*, %struct.TYPE_17__** %154
%156 = getelementptr inbounds %struct.TYPE_17__, %struct.TYPE_17__* %155, i32 0, i32 1
%157 = getelementptr inbounds %struct.TYPE_16__, %struct.TYPE_16__* %156, i32 0, i32 0
%158 = load %struct.TYPE_15__*, %struct.TYPE_15__** %157
%159 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %158, i32 0, i32 1
%160 = load i32, i32* %159
store i32 %160, i32* %20
%161 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%162 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %161, i32 0, i32 0
%163 = load i64, i64* %162
%164 = call i32 @ASN1_INTEGER_get(i64 %163)
store i32 %164, i32* %21
%165 = load i8*, i8** %10
%166 = load i32, i32* %11
%167 = load i8*, i8** %16
%168 = load i32, i32* %20
%169 = load i32, i32* %21
%170 = load i32*, i32** %28
%171 = load i32, i32* %24
%172 = call i32 @PKCS5_PBKDF2_HMAC(i8* %165, i32 %166, i8* %167, i32 %168, i32 %169, i32* %170, i32 %171, i8* %33)
%173 = icmp ne i32 %172, 0
br i1 %173, label %175, label %174
174: ; preds = %144
br label %179
175: ; preds = %144
%176 = load i32*, i32** %9
%177 = load i32, i32* %15
%178 = call i32 @EVP_CipherInit_ex(i32* %176, i32* null, i32* null, i8* %33, i32* null, i32 %177)
store i32 %178, i32* %23
br label %179
179: ; preds = %175, %174, %140, %128, %119, %96
%180 = load i32, i32* %24
%181 = call i32 @OPENSSL_cleanse(i8* %33, i32 %180)
%182 = load %struct.TYPE_18__*, %struct.TYPE_18__** %27
%183 = call i32 @PBKDF2PARAM_free(%struct.TYPE_18__* %182)
%184 = load i32, i32* %23
store i32 %184, i32* %8
store i32 1, i32* %29
br label %185
185: ; preds = %179, %80, %60, %47, %37
%186 = load i8*, i8** %17
%187 = load i32, i32* %8
ret i32 %187
}

LLVM IR (-O2):
%struct.TYPE_19__ = type { i64, %struct.TYPE_13__ }
%struct.TYPE_13__ = type { %struct.TYPE_12__* }
%struct.TYPE_12__ = type { i8*, i32 }
%struct.TYPE_18__ = type { i64, %struct.TYPE_17__*, %struct.TYPE_14__*, i64 }
%struct.TYPE_17__ = type { i64, %struct.TYPE_16__ }
%struct.TYPE_16__ = type { %struct.TYPE_15__* }
%struct.TYPE_15__ = type { i8*, i32 }
%struct.TYPE_14__ = type { i32 }
@EVP_MAX_KEY_LENGTH = global i32 0
@EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN = global i32 0
@EVP_R_NO_CIPHER_SET = global i32 0
@EVP_R_BAD_KEY_LENGTH = global i32 0
@V_ASN1_SEQUENCE = global i64 0
@EVP_R_DECODE_ERROR = global i32 0
@EVP_R_UNSUPPORTED_KEYLENGTH = global i32 0
@NID_hmacWithSHA1 = global i32 0
@EVP_PBE_TYPE_PRF = global i32 0
@EVP_R_UNSUPPORTED_PRF = global i32 0
@V_ASN1_OCTET_STRING = global i64 0
@EVP_R_UNSUPPORTED_SALT_TYPE = global i32 0
define i32 @PKCS5_v2_PBKDF2_keyivgen(i32* %0, i8* %1, i32 %2, %struct.TYPE_19__* %3, i32* nocapture readnone %4, i32* nocapture readnone %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = load i32, i32* @EVP_MAX_KEY_LENGTH
%11 = zext i32 %10 to i64
%12 = alloca i8, i64 %11
%13 = bitcast i8** %8 to i8*
%14 = bitcast i32* %9 to i8*
%15 = tail call i32* @EVP_CIPHER_CTX_cipher(i32* %0)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %7
%18 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%19 = load i32, i32* @EVP_R_NO_CIPHER_SET
%20 = tail call i32 @EVPerr(i32 %18, i32 %19)
br label %119
21: ; preds = %7
%22 = tail call i32 @EVP_CIPHER_CTX_key_length(i32* %0)
%23 = icmp ugt i32 %22, %10
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%26 = load i32, i32* @EVP_R_BAD_KEY_LENGTH
%27 = tail call i32 @EVPerr(i32 %25, i32 %26)
br label %119
28: ; preds = %21
%29 = icmp eq %struct.TYPE_19__* %3, null
br i1 %29, label %35, label %30
30: ; preds = %28
%31 = getelementptr inbounds %struct.TYPE_19__, %struct.TYPE_19__* %3, i64 0, i32 0
%32 = load i64, i64* %31
%33 = load i64, i64* @V_ASN1_SEQUENCE
%34 = icmp eq i64 %32, %33
br i1 %34, label %39, label %35
35: ; preds = %30, %28
%36 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%37 = load i32, i32* @EVP_R_DECODE_ERROR
%38 = tail call i32 @EVPerr(i32 %36, i32 %37)
br label %119
39: ; preds = %30
%40 = getelementptr inbounds %struct.TYPE_19__, %struct.TYPE_19__* %3, i64 0, i32 1, i32 0
%41 = load %struct.TYPE_12__*, %struct.TYPE_12__** %40
%42 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %41, i64 0, i32 0
%43 = load i8*, i8** %42
store i8* %43, i8** %8
%44 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %41, i64 0, i32 1
%45 = load i32, i32* %44
%46 = call %struct.TYPE_18__* @d2i_PBKDF2PARAM(i32* null, i8** %8, i32 %45)
%47 = icmp eq %struct.TYPE_18__* %46, null
br i1 %47, label %48, label %52
48: ; preds = %39
%49 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%50 = load i32, i32* @EVP_R_DECODE_ERROR
%51 = call i32 @EVPerr(i32 %49, i32 %50)
br label %119
52: ; preds = %39
%53 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %46, i64 0, i32 3
%54 = load i64, i64* %53
%55 = icmp eq i64 %54, 0
br i1 %55, label %63, label %56
56: ; preds = %52
%57 = call i32 @ASN1_INTEGER_get(i64 %54)
%58 = icmp eq i32 %57, %22
br i1 %58, label %63, label %59
59: ; preds = %56
%60 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%61 = load i32, i32* @EVP_R_UNSUPPORTED_KEYLENGTH
%62 = call i32 @EVPerr(i32 %60, i32 %61)
br label %115
63: ; preds = %56, %52
%64 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %46, i64 0, i32 2
%65 = load %struct.TYPE_14__*, %struct.TYPE_14__** %64
%66 = icmp eq %struct.TYPE_14__* %65, null
br i1 %66, label %71, label %67
67: ; preds = %63
%68 = getelementptr inbounds %struct.TYPE_14__, %struct.TYPE_14__* %65, i64 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @OBJ_obj2nid(i32 %69)
br label %73
71: ; preds = %63
%72 = load i32, i32* @NID_hmacWithSHA1
br label %73
73: ; preds = %71, %67
%74 = phi i32 [ %70, %67 ], [ %72, %71 ]
%75 = load i32, i32* @EVP_PBE_TYPE_PRF
%76 = call i32 @EVP_PBE_find(i32 %75, i32 %74, i32* null, i32* %9, i32 0)
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %73
%79 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%80 = load i32, i32* @EVP_R_UNSUPPORTED_PRF
%81 = call i32 @EVPerr(i32 %79, i32 %80)
br label %115
82: ; preds = %73
%83 = load i32, i32* %9
%84 = call i32* @EVP_get_digestbynid(i32 %83)
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %90
86: ; preds = %82
%87 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%88 = load i32, i32* @EVP_R_UNSUPPORTED_PRF
%89 = call i32 @EVPerr(i32 %87, i32 %88)
br label %115
90: ; preds = %82
%91 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %46, i64 0, i32 1
%92 = load %struct.TYPE_17__*, %struct.TYPE_17__** %91
%93 = getelementptr inbounds %struct.TYPE_17__, %struct.TYPE_17__* %92, i64 0, i32 0
%94 = load i64, i64* %93
%95 = load i64, i64* @V_ASN1_OCTET_STRING
%96 = icmp eq i64 %94, %95
br i1 %96, label %101, label %97
97: ; preds = %90
%98 = load i32, i32* @EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN
%99 = load i32, i32* @EVP_R_UNSUPPORTED_SALT_TYPE
%100 = call i32 @EVPerr(i32 %98, i32 %99)
br label %115
101: ; preds = %90
%102 = getelementptr inbounds %struct.TYPE_17__, %struct.TYPE_17__* %92, i64 0, i32 1, i32 0
%103 = load %struct.TYPE_15__*, %struct.TYPE_15__** %102
%104 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %103, i64 0, i32 0
%105 = load i8*, i8** %104
%106 = getelementptr inbounds %struct.TYPE_15__, %struct.TYPE_15__* %103, i64 0, i32 1
%107 = load i32, i32* %106
%108 = getelementptr inbounds %struct.TYPE_18__, %struct.TYPE_18__* %46, i64 0, i32 0
%109 = load i64, i64* %108
%110 = call i32 @ASN1_INTEGER_get(i64 %109)
%111 = call i32 @PKCS5_PBKDF2_HMAC(i8* %1, i32 %2, i8* %105, i32 %107, i32 %110, i32* %84, i32 %22, i8* %12)
%112 = icmp eq i32 %111, 0
br i1 %112, label %115, label %113
113: ; preds = %101
%114 = call i32 @EVP_CipherInit_ex(i32* %0, i32* null, i32* null, i8* %12, i32* null, i32 %6)
br label %115
115: ; preds = %101, %113, %97, %86, %78, %59
%116 = phi i32 [ 0, %59 ], [ 0, %86 ], [ 0, %97 ], [ %114, %113 ], [ 0, %101 ], [ 0, %78 ]
%117 = call i32 @OPENSSL_cleanse(i8* %12, i32 %22)
%118 = call i32 @PBKDF2PARAM_free(%struct.TYPE_18__* %46)
br label %119
119: ; preds = %115, %48, %35, %24, %17
%120 = phi i32 [ 0, %17 ], [ 0, %24 ], [ 0, %35 ], [ %116, %115 ], [ 0, %48 ]
ret i32 %120
}