#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_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_assert(int);
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);
    goto err;
  }
  keylen = EVP_CIPHER_CTX_key_length(ctx);
  OPENSSL_assert(keylen <= sizeof key);
  if (!param || (param->type != V_ASN1_SEQUENCE)) {
    EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_DECODE_ERROR);
    goto err;
  }
  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);
    goto err;
  }
  keylen = EVP_CIPHER_CTX_key_length(ctx);
  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    $0x90,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x90(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
call   10d0 <EVP_CIPHER_CTX_cipher@plt>
cmp    $0x0,%rax
jne    1270 <PKCS5_v2_PBKDF2_keyivgen+0xa0>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x8(%rbp),%rdi
call   10e0 <EVP_CIPHER_CTX_key_length@plt>
mov    -0x90(%rbp),%rcx
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <OPENSSL_assert@plt>
cmpq   $0x0,-0x20(%rbp)
je     12b8 <PKCS5_v2_PBKDF2_keyivgen+0xe8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2ce1(%rip),%rcx
cmp    (%rcx),%rax
je     12d4 <PKCS5_v2_PBKDF2_keyivgen+0x104>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x50(%rbp),%rsi
call   10a0 <d2i_PBKDF2PARAM@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    132b <PKCS5_v2_PBKDF2_keyivgen+0x15b>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x8(%rbp),%rdi
call   10e0 <EVP_CIPHER_CTX_key_length@plt>
mov    %eax,-0x64(%rbp)
mov    -0x78(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     1378 <PKCS5_v2_PBKDF2_keyivgen+0x1a8>
mov    -0x78(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <ASN1_INTEGER_get@plt>
cmp    -0x64(%rbp),%eax
je     1378 <PKCS5_v2_PBKDF2_keyivgen+0x1a8>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
mov    0x2c5c(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x78(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     139e <PKCS5_v2_PBKDF2_keyivgen+0x1ce>
mov    -0x78(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%edi
call   1040 <OBJ_obj2nid@plt>
mov    %eax,-0x68(%rbp)
jmp    13aa <PKCS5_v2_PBKDF2_keyivgen+0x1da>
mov    0x2c13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
mov    -0x68(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x6c(%rbp),%rcx
xor    %r8d,%r8d
call   1030 <EVP_PBE_find@plt>
cmp    $0x0,%eax
jne    13eb <PKCS5_v2_PBKDF2_keyivgen+0x21b>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
mov    0x2bf1(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x6c(%rbp),%edi
call   1070 <EVP_get_digestbynid@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jne    141e <PKCS5_v2_PBKDF2_keyivgen+0x24e>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
mov    0x2bbe(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    0x2b78(%rip),%rcx
cmp    (%rcx),%rax
je     1455 <PKCS5_v2_PBKDF2_keyivgen+0x285>
mov    0x2bb0(%rip),%rax
mov    (%rax),%edi
mov    0x2b3f(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x78(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <ASN1_INTEGER_get@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
mov    %ecx,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x54(%rbp),%ecx
mov    -0x58(%rbp),%r8d
mov    -0x80(%rbp),%r9
mov    -0x64(%rbp),%r10d
sub    $0x10,%rsp
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <PKCS5_PBKDF2_HMAC@plt>
add    $0x10,%rsp
cmp    $0x0,%eax
jne    14d0 <PKCS5_v2_PBKDF2_keyivgen+0x300>
jmp    14f2 <PKCS5_v2_PBKDF2_keyivgen+0x322>
mov    -0x88(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    0x10(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
call   10f0 <EVP_CipherInit_ex@plt>
mov    %eax,-0x60(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1080 <OPENSSL_cleanse@plt>
mov    -0x78(%rbp),%rdi
call   10c0 <PBKDF2PARAM_free@plt>
mov    -0x60(%rbp),%eax
mov    -0x40(%rbp),%rcx
mov    %rcx,%rsp
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,%r15
mov    %edx,%r13d
mov    %rsi,-0x48(%rbp)
mov    %rdi,%r12
mov    0x2deb(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r14
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
call   10d0 <EVP_CIPHER_CTX_cipher@plt>
test   %rax,%rax
je     12c2 <PKCS5_v2_PBKDF2_keyivgen+0xf2>
mov    %r12,%rdi
call   10e0 <EVP_CIPHER_CTX_key_length@plt>
xor    %edi,%edi
cmp    %ebx,%eax
mov    %rax,%rbx
setbe  %dil
call   1050 <OPENSSL_assert@plt>
test   %r15,%r15
je     12a9 <PKCS5_v2_PBKDF2_keyivgen+0xd9>
mov    (%r15),%rax
mov    0x2d53(%rip),%rcx
cmp    (%rcx),%rax
jne    12a9 <PKCS5_v2_PBKDF2_keyivgen+0xd9>
mov    %r13d,-0x38(%rbp)
mov    0x8(%r15),%rax
mov    (%rax),%rcx
mov    %rcx,-0x50(%rbp)
mov    0x8(%rax),%edx
xor    %r13d,%r13d
lea    -0x50(%rbp),%rsi
xor    %edi,%edi
call   10a0 <d2i_PBKDF2PARAM@plt>
test   %rax,%rax
je     1305 <PKCS5_v2_PBKDF2_keyivgen+0x135>
mov    %rax,%r15
mov    %r12,%rdi
call   10e0 <EVP_CIPHER_CTX_key_length@plt>
mov    %eax,%ebx
mov    0x18(%r15),%rdi
test   %rdi,%rdi
je     128e <PKCS5_v2_PBKDF2_keyivgen+0xbe>
call   10b0 <ASN1_INTEGER_get@plt>
cmp    %ebx,%eax
jne    1321 <PKCS5_v2_PBKDF2_keyivgen+0x151>
mov    0x10(%r15),%rax
test   %rax,%rax
je     133a <PKCS5_v2_PBKDF2_keyivgen+0x16a>
mov    (%rax),%edi
call   1040 <OBJ_obj2nid@plt>
mov    %eax,%esi
jmp    1343 <PKCS5_v2_PBKDF2_keyivgen+0x173>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    12db <PKCS5_v2_PBKDF2_keyivgen+0x10b>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
xor    %ebx,%ebx
xor    %r15d,%r15d
xor    %r13d,%r13d
mov    %r14,%rdi
mov    %ebx,%esi
call   1080 <OPENSSL_cleanse@plt>
mov    %r15,%rdi
call   10c0 <PBKDF2PARAM_free@plt>
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
xor    %r15d,%r15d
jmp    12e1 <PKCS5_v2_PBKDF2_keyivgen+0x111>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
mov    0x2c97(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    12de <PKCS5_v2_PBKDF2_keyivgen+0x10e>
mov    0x2c77(%rip),%rax
mov    (%rax),%esi
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
xor    %r13d,%r13d
lea    -0x3c(%rbp),%rcx
xor    %edx,%edx
xor    %r8d,%r8d
call   1030 <EVP_PBE_find@plt>
test   %eax,%eax
je     13f2 <PKCS5_v2_PBKDF2_keyivgen+0x222>
mov    %rbx,-0x30(%rbp)
mov    -0x3c(%rbp),%edi
call   1070 <EVP_get_digestbynid@plt>
test   %rax,%rax
je     140e <PKCS5_v2_PBKDF2_keyivgen+0x23e>
mov    %rax,%rbx
mov    0x8(%r15),%rax
mov    (%rax),%rcx
mov    0x2c1d(%rip),%rdx
cmp    (%rdx),%rcx
jne    1420 <PKCS5_v2_PBKDF2_keyivgen+0x250>
mov    0x8(%rax),%rax
mov    (%rax),%r13
mov    0x8(%rax),%eax
mov    %eax,-0x34(%rbp)
mov    (%r15),%rdi
call   10b0 <ASN1_INTEGER_get@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    %r13,%rdx
mov    -0x34(%rbp),%ecx
mov    %eax,%r8d
mov    %rbx,%r9
push   %r14
mov    -0x30(%rbp),%rbx
push   %rbx
call   1060 <PKCS5_PBKDF2_HMAC@plt>
add    $0x10,%rsp
test   %eax,%eax
je     12de <PKCS5_v2_PBKDF2_keyivgen+0x10e>
mov    0x10(%rbp),%r9d
mov    %r12,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   10f0 <EVP_CipherInit_ex@plt>
mov    %eax,%r13d
jmp    12e1 <PKCS5_v2_PBKDF2_keyivgen+0x111>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
mov    0x2bce(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
jmp    12e1 <PKCS5_v2_PBKDF2_keyivgen+0x111>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
mov    0x2bb2(%rip),%rax
jmp    1430 <PKCS5_v2_PBKDF2_keyivgen+0x260>
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
mov    0x2b58(%rip),%rax
mov    (%rax),%esi
call   1090 <EVPerr@plt>
xor    %r13d,%r13d
mov    -0x30(%rbp),%rbx
jmp    12e1 <PKCS5_v2_PBKDF2_keyivgen+0x111>

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

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