#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_13__ TYPE_5__;
typedef struct TYPE_12__ TYPE_4__;
typedef struct TYPE_11__ TYPE_3__;
typedef struct TYPE_10__ TYPE_2__;
typedef struct TYPE_9__ TYPE_1__;

/* Type definitions */
struct TYPE_10__ {
  TYPE_1__ *sequence;
};
struct TYPE_13__ {
  scalar_t__ type;
  TYPE_2__ value;
};
struct TYPE_12__ {
  TYPE_3__ *salt;
  int /*<<< orphan*/ iter;
};
struct TYPE_11__ {
  unsigned char *data;
  int length;
};
struct TYPE_9__ {
  unsigned char *data;
  int /*<<< orphan*/ length;
};
typedef TYPE_4__ PBEPARAM;
typedef int /*<<< orphan*/ EVP_MD;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;
typedef int /*<<< orphan*/ EVP_CIPHER;
typedef TYPE_5__ ASN1_TYPE;

/* Variables and functions */
int ASN1_INTEGER_get(int /*<<< orphan*/);
int /*<<< orphan*/ EVP_CIPHER_iv_length(int /*<<< orphan*/ const *);
int /*<<< orphan*/ EVP_CIPHER_key_length(int /*<<< orphan*/ const *);
int EVP_CipherInit_ex(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                      int /*<<< orphan*/ *, unsigned char *, unsigned char *,
                      int);
int EVP_MAX_IV_LENGTH;
int EVP_MAX_KEY_LENGTH;
int /*<<< orphan*/ PBEPARAM_free(TYPE_4__ *);
int /*<<< orphan*/ PKCS12_F_PKCS12_PBE_KEYIVGEN;
int /*<<< orphan*/ PKCS12_IV_ID;
int /*<<< orphan*/ PKCS12_KEY_ID;
int /*<<< orphan*/ PKCS12_R_DECODE_ERROR;
int /*<<< orphan*/ PKCS12_R_IV_GEN_ERROR;
int /*<<< orphan*/ PKCS12_R_KEY_GEN_ERROR;
int /*<<< orphan*/ PKCS12_key_gen(char const *, int, unsigned char *, int,
                                  int /*<<< orphan*/, int, int /*<<< orphan*/,
                                  unsigned char *, int /*<<< orphan*/ const *);
int /*<<< orphan*/ PKCS12err(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ V_ASN1_SEQUENCE;
TYPE_4__ *d2i_PBEPARAM(int /*<<< orphan*/ *, unsigned char const **,
                       int /*<<< orphan*/);
int /*<<< orphan*/ explicit_bzero(unsigned char *, int);
int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
                        ASN1_TYPE *param, const EVP_CIPHER *cipher,
                        const EVP_MD *md, int en_de) {
  PBEPARAM *pbe;
  int saltlen, iter, ret;
  unsigned char *salt;
  const unsigned char *pbuf;
  unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
  if (param == NULL || param->type != V_ASN1_SEQUENCE ||
      param->value.sequence == NULL) {
    PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR);
    return 0;
  }
  pbuf = param->value.sequence->data;
  if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) {
    PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR);
    return 0;
  }
  if (!pbe->iter)
    iter = 1;
  else
    iter = ASN1_INTEGER_get(pbe->iter);
  salt = pbe->salt->data;
  saltlen = pbe->salt->length;
  if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_KEY_ID, iter,
                      EVP_CIPHER_key_length(cipher), key, md)) {
    PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_KEY_GEN_ERROR);
    PBEPARAM_free(pbe);
    return 0;
  }
  if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_IV_ID, iter,
                      EVP_CIPHER_iv_length(cipher), iv, md)) {
    PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_IV_GEN_ERROR);
    PBEPARAM_free(pbe);
    return 0;
  }
  PBEPARAM_free(pbe);
  ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de);
  explicit_bzero(key, EVP_MAX_KEY_LENGTH);
  explicit_bzero(iv, EVP_MAX_IV_LENGTH);
  return ret;
}


x86 assembly (clang, -O0):
<PKCS12_PBE_keyivgen>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%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    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123d <PKCS12_PBE_keyivgen+0xad>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2d73(%rip),%rcx
cmp    (%rcx),%rax
jne    123d <PKCS12_PBE_keyivgen+0xad>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1267 <PKCS12_PBE_keyivgen+0xd7>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
call   1060 <PKCS12err@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    151c <PKCS12_PBE_keyivgen+0x38c>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%edx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x60(%rbp),%rsi
call   10b0 <d2i_PBEPARAM@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    12c6 <PKCS12_PBE_keyivgen+0x136>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
call   1060 <PKCS12err@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    151c <PKCS12_PBE_keyivgen+0x38c>
mov    -0x40(%rbp),%rax
cmpl   $0x0,0x8(%rax)
jne    12e0 <PKCS12_PBE_keyivgen+0x150>
movl   $0x1,-0x48(%rbp)
jmp    12ef <PKCS12_PBE_keyivgen+0x15f>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edi
call   1070 <ASN1_INTEGER_get@plt>
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    0x2c8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <EVP_CIPHER_key_length@plt>
mov    -0xb8(%rbp),%rdi
mov    -0xac(%rbp),%esi
mov    -0xa8(%rbp),%rdx
mov    -0x9c(%rbp),%ecx
mov    -0x98(%rbp),%r8d
mov    -0x94(%rbp),%r9d
mov    -0x90(%rbp),%r10
mov    %eax,%r11d
mov    -0x38(%rbp),%rax
sub    $0x20,%rsp
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <PKCS12_key_gen@plt>
add    $0x20,%rsp
cmp    $0x0,%eax
jne    13e0 <PKCS12_PBE_keyivgen+0x250>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
mov    0x2c1b(%rip),%rax
mov    (%rax),%esi
call   1060 <PKCS12err@plt>
mov    -0x40(%rbp),%rdi
call   1040 <PBEPARAM_free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    151c <PKCS12_PBE_keyivgen+0x38c>
mov    -0x18(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xd4(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0xc4(%rbp)
mov    0x2b99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc0(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <EVP_CIPHER_iv_length@plt>
mov    -0xe0(%rbp),%rdi
mov    -0xd4(%rbp),%esi
mov    -0xd0(%rbp),%rdx
mov    -0xc4(%rbp),%ecx
mov    -0xc0(%rbp),%r8d
mov    -0xbc(%rbp),%r9d
mov    -0x88(%rbp),%r10
mov    %eax,%r11d
mov    -0x38(%rbp),%rax
sub    $0x20,%rsp
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <PKCS12_key_gen@plt>
add    $0x20,%rsp
cmp    $0x0,%eax
jne    14b6 <PKCS12_PBE_keyivgen+0x326>
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
mov    0x2b2d(%rip),%rax
mov    (%rax),%esi
call   1060 <PKCS12err@plt>
mov    -0x40(%rbp),%rdi
call   1040 <PBEPARAM_free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    151c <PKCS12_PBE_keyivgen+0x38c>
mov    -0x40(%rbp),%rdi
call   1040 <PBEPARAM_free@plt>
mov    -0x90(%rbp),%rcx
mov    -0x88(%rbp),%r8
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    0x10(%rbp),%r9d
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <EVP_CipherInit_ex@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,-0x4c(%rbp)
mov    0x2aed(%rip),%rax
mov    (%rax),%esi
call   1090 <explicit_bzero@plt>
mov    -0x88(%rbp),%rdi
mov    0x2ae0(%rip),%rax
mov    (%rax),%esi
call   1090 <explicit_bzero@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS12_PBE_keyivgen>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsp,-0x38(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rcx,%rcx
je     123c <PKCS12_PBE_keyivgen+0xac>
mov    %rsi,%r15
mov    (%rcx),%rax
mov    0x2dad(%rip),%rsi
cmp    (%rsi),%rax
jne    123c <PKCS12_PBE_keyivgen+0xac>
mov    0x8(%rcx),%rax
test   %rax,%rax
je     123c <PKCS12_PBE_keyivgen+0xac>
mov    %edx,-0x3c(%rbp)
mov    %r9,-0x70(%rbp)
mov    %rdi,-0x68(%rbp)
mov    %r8,-0x48(%rbp)
mov    (%rax),%rcx
mov    %rcx,-0x78(%rbp)
mov    0x8(%rax),%edx
xor    %r13d,%r13d
lea    -0x78(%rbp),%rsi
xor    %edi,%edi
call   10b0 <d2i_PBEPARAM@plt>
test   %rax,%rax
je     126f <PKCS12_PBE_keyivgen+0xdf>
mov    0x8(%rax),%edi
test   %edi,%edi
je     1288 <PKCS12_PBE_keyivgen+0xf8>
mov    %rax,%r13
call   1070 <ASN1_INTEGER_get@plt>
mov    %eax,-0x2c(%rbp)
mov    %r13,%rax
jmp    128f <PKCS12_PBE_keyivgen+0xff>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
call   1060 <PKCS12err@plt>
xor    %r13d,%r13d
mov    -0x38(%rbp),%r15
mov    %r15,%rsp
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
call   1060 <PKCS12err@plt>
jmp    1256 <PKCS12_PBE_keyivgen+0xc6>
movl   $0x1,-0x2c(%rbp)
mov    -0x48(%rbp),%rdi
mov    %rax,-0x50(%rbp)
mov    (%rax),%rax
mov    (%rax),%r13
mov    0x8(%rax),%r14d
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
call   1080 <EVP_CIPHER_key_length@plt>
sub    $0x8,%rsp
mov    %r15,%rdi
mov    -0x3c(%rbp),%esi
mov    %r13,-0x60(%rbp)
mov    %r13,%rdx
mov    %r14d,-0x54(%rbp)
mov    %r14d,%ecx
mov    -0x58(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x70(%rbp),%r13
push   %r13
push   %r12
push   %rax
call   1030 <PKCS12_key_gen@plt>
add    $0x20,%rsp
test   %eax,%eax
je     137a <PKCS12_PBE_keyivgen+0x1ea>
mov    0x2cb5(%rip),%rax
mov    %r13,%r14
mov    (%rax),%r13d
mov    -0x48(%rbp),%rdi
call   1050 <EVP_CIPHER_iv_length@plt>
sub    $0x8,%rsp
mov    %r15,%rdi
mov    -0x3c(%rbp),%esi
mov    -0x60(%rbp),%rdx
mov    -0x54(%rbp),%ecx
mov    %r13d,%r8d
mov    -0x2c(%rbp),%r9d
push   %r14
push   %rbx
push   %rax
call   1030 <PKCS12_key_gen@plt>
add    $0x20,%rsp
test   %eax,%eax
je     138c <PKCS12_PBE_keyivgen+0x1fc>
mov    0x10(%rbp),%r14d
mov    -0x50(%rbp),%rdi
call   1040 <PBEPARAM_free@plt>
mov    -0x68(%rbp),%rdi
mov    -0x48(%rbp),%rsi
xor    %edx,%edx
mov    %r12,%rcx
mov    %rbx,%r8
mov    %r14d,%r9d
call   10a0 <EVP_CipherInit_ex@plt>
mov    %eax,%r13d
mov    0x2c86(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1090 <explicit_bzero@plt>
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <explicit_bzero@plt>
jmp    1256 <PKCS12_PBE_keyivgen+0xc6>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    0x2c4e(%rip),%rax
jmp    139c <PKCS12_PBE_keyivgen+0x20c>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
mov    0x2c24(%rip),%rax
mov    (%rax),%esi
call   1060 <PKCS12err@plt>
mov    -0x50(%rbp),%rdi
call   1040 <PBEPARAM_free@plt>
jmp    1253 <PKCS12_PBE_keyivgen+0xc3>

LLVM IR (-O0):
%struct.TYPE_13__ = type { i64, %struct.TYPE_10__ }
%struct.TYPE_10__ = type { %struct.TYPE_9__* }
%struct.TYPE_9__ = type { i8*, i32 }
%struct.TYPE_12__ = type { %struct.TYPE_11__*, i32 }
%struct.TYPE_11__ = type { i8*, i32 }
@EVP_MAX_KEY_LENGTH = global i32 0
@EVP_MAX_IV_LENGTH = global i32 0
@V_ASN1_SEQUENCE = global i64 0
@PKCS12_F_PKCS12_PBE_KEYIVGEN = global i32 0
@PKCS12_R_DECODE_ERROR = global i32 0
@PKCS12_KEY_ID = global i32 0
@PKCS12_R_KEY_GEN_ERROR = global i32 0
@PKCS12_IV_ID = global i32 0
@PKCS12_R_IV_GEN_ERROR = global i32 0
define i32 @PKCS12_PBE_keyivgen(i32* %0, i8* %1, i32 %2, %struct.TYPE_13__* %3, i32* %4, i32* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.TYPE_13__*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
%16 = alloca %struct.TYPE_12__*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i64
%24 = alloca i64
%25 = alloca i32
store i32* %0, i32** %9
store i8* %1, i8** %10
store i32 %2, i32* %11
store %struct.TYPE_13__* %3, %struct.TYPE_13__** %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i32 %6, i32* %15
%26 = load i32, i32* @EVP_MAX_KEY_LENGTH
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %22
%29 = alloca i8, i64 %27
store i64 %27, i64* %23
%30 = load i32, i32* @EVP_MAX_IV_LENGTH
%31 = zext i32 %30 to i64
%32 = alloca i8, i64 %31
store i64 %31, i64* %24
%33 = load %struct.TYPE_13__*, %struct.TYPE_13__** %12
%34 = icmp eq %struct.TYPE_13__* %33, null
br i1 %34, label %47, label %35
35: ; preds = %7
%36 = load %struct.TYPE_13__*, %struct.TYPE_13__** %12
%37 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %36, i32 0, i32 0
%38 = load i64, i64* %37
%39 = load i64, i64* @V_ASN1_SEQUENCE
%40 = icmp ne i64 %38, %39
br i1 %40, label %47, label %41
41: ; preds = %35
%42 = load %struct.TYPE_13__*, %struct.TYPE_13__** %12
%43 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %42, i32 0, i32 1
%44 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %43, i32 0, i32 0
%45 = load %struct.TYPE_9__*, %struct.TYPE_9__** %44
%46 = icmp eq %struct.TYPE_9__* %45, null
br i1 %46, label %47, label %51
47: ; preds = %41, %35, %7
%48 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%49 = load i32, i32* @PKCS12_R_DECODE_ERROR
%50 = call i32 @PKCS12err(i32 %48, i32 %49)
store i32 0, i32* %8
store i32 1, i32* %25
br label %139
51: ; preds = %41
%52 = load %struct.TYPE_13__*, %struct.TYPE_13__** %12
%53 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %52, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %53, i32 0, i32 0
%55 = load %struct.TYPE_9__*, %struct.TYPE_9__** %54
%56 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %55, i32 0, i32 0
%57 = load i8*, i8** %56
store i8* %57, i8** %21
%58 = load %struct.TYPE_13__*, %struct.TYPE_13__** %12
%59 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %58, i32 0, i32 1
%60 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %59, i32 0, i32 0
%61 = load %struct.TYPE_9__*, %struct.TYPE_9__** %60
%62 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = call %struct.TYPE_12__* @d2i_PBEPARAM(i32* null, i8** %21, i32 %63)
store %struct.TYPE_12__* %64, %struct.TYPE_12__** %16
%65 = icmp ne %struct.TYPE_12__* %64, null
br i1 %65, label %70, label %66
66: ; preds = %51
%67 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%68 = load i32, i32* @PKCS12_R_DECODE_ERROR
%69 = call i32 @PKCS12err(i32 %67, i32 %68)
store i32 0, i32* %8
store i32 1, i32* %25
br label %139
70: ; preds = %51
%71 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%72 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %71, i32 0, i32 1
%73 = load i32, i32* %72
%74 = icmp ne i32 %73, 0
br i1 %74, label %76, label %75
75: ; preds = %70
store i32 1, i32* %18
br label %81
76: ; preds = %70
%77 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%78 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %77, i32 0, i32 1
%79 = load i32, i32* %78
%80 = call i32 @ASN1_INTEGER_get(i32 %79)
store i32 %80, i32* %18
br label %81
81: ; preds = %76, %75
%82 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%83 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %82, i32 0, i32 0
%84 = load %struct.TYPE_11__*, %struct.TYPE_11__** %83
%85 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %84, i32 0, i32 0
%86 = load i8*, i8** %85
store i8* %86, i8** %20
%87 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%88 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %87, i32 0, i32 0
%89 = load %struct.TYPE_11__*, %struct.TYPE_11__** %88
%90 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %89, i32 0, i32 1
%91 = load i32, i32* %90
store i32 %91, i32* %17
%92 = load i8*, i8** %10
%93 = load i32, i32* %11
%94 = load i8*, i8** %20
%95 = load i32, i32* %17
%96 = load i32, i32* @PKCS12_KEY_ID
%97 = load i32, i32* %18
%98 = load i32*, i32** %13
%99 = call i32 @EVP_CIPHER_key_length(i32* %98)
%100 = load i32*, i32** %14
%101 = call i32 @PKCS12_key_gen(i8* %92, i32 %93, i8* %94, i32 %95, i32 %96, i32 %97, i32 %99, i8* %29, i32* %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %109, label %103
103: ; preds = %81
%104 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%105 = load i32, i32* @PKCS12_R_KEY_GEN_ERROR
%106 = call i32 @PKCS12err(i32 %104, i32 %105)
%107 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%108 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %107)
store i32 0, i32* %8
store i32 1, i32* %25
br label %139
109: ; preds = %81
%110 = load i8*, i8** %10
%111 = load i32, i32* %11
%112 = load i8*, i8** %20
%113 = load i32, i32* %17
%114 = load i32, i32* @PKCS12_IV_ID
%115 = load i32, i32* %18
%116 = load i32*, i32** %13
%117 = call i32 @EVP_CIPHER_iv_length(i32* %116)
%118 = load i32*, i32** %14
%119 = call i32 @PKCS12_key_gen(i8* %110, i32 %111, i8* %112, i32 %113, i32 %114, i32 %115, i32 %117, i8* %32, i32* %118)
%120 = icmp ne i32 %119, 0
br i1 %120, label %127, label %121
121: ; preds = %109
%122 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%123 = load i32, i32* @PKCS12_R_IV_GEN_ERROR
%124 = call i32 @PKCS12err(i32 %122, i32 %123)
%125 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%126 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %125)
store i32 0, i32* %8
store i32 1, i32* %25
br label %139
127: ; preds = %109
%128 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%129 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %128)
%130 = load i32*, i32** %9
%131 = load i32*, i32** %13
%132 = load i32, i32* %15
%133 = call i32 @EVP_CipherInit_ex(i32* %130, i32* %131, i32* null, i8* %29, i8* %32, i32 %132)
store i32 %133, i32* %19
%134 = load i32, i32* @EVP_MAX_KEY_LENGTH
%135 = call i32 @explicit_bzero(i8* %29, i32 %134)
%136 = load i32, i32* @EVP_MAX_IV_LENGTH
%137 = call i32 @explicit_bzero(i8* %32, i32 %136)
%138 = load i32, i32* %19
store i32 %138, i32* %8
store i32 1, i32* %25
br label %139
139: ; preds = %127, %121, %103, %66, %47
%140 = load i8*, i8** %22
%141 = load i32, i32* %8
ret i32 %141
}

LLVM IR (-O2):
%struct.TYPE_13__ = type { i64, %struct.TYPE_10__ }
%struct.TYPE_10__ = type { %struct.TYPE_9__* }
%struct.TYPE_9__ = type { i8*, i32 }
%struct.TYPE_12__ = type { %struct.TYPE_11__*, i32 }
%struct.TYPE_11__ = type { i8*, i32 }
@EVP_MAX_KEY_LENGTH = global i32 0
@EVP_MAX_IV_LENGTH = global i32 0
@V_ASN1_SEQUENCE = global i64 0
@PKCS12_F_PKCS12_PBE_KEYIVGEN = global i32 0
@PKCS12_R_DECODE_ERROR = global i32 0
@PKCS12_KEY_ID = global i32 0
@PKCS12_R_KEY_GEN_ERROR = global i32 0
@PKCS12_IV_ID = global i32 0
@PKCS12_R_IV_GEN_ERROR = global i32 0
define i32 @PKCS12_PBE_keyivgen(i32* %0, i8* %1, i32 %2, %struct.TYPE_13__* %3, i32* %4, i32* %5, i32 %6) {
%8 = alloca i8*
%9 = bitcast i8** %8 to i8*
%10 = load i32, i32* @EVP_MAX_KEY_LENGTH
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = load i32, i32* @EVP_MAX_IV_LENGTH
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
%17 = icmp eq %struct.TYPE_13__* %3, null
br i1 %17, label %27, label %18
18: ; preds = %7
%19 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %3, i64 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* @V_ASN1_SEQUENCE
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %3, i64 0, i32 1, i32 0
%25 = load %struct.TYPE_9__*, %struct.TYPE_9__** %24
%26 = icmp eq %struct.TYPE_9__* %25, null
br i1 %26, label %27, label %31
27: ; preds = %23, %18, %7
%28 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%29 = load i32, i32* @PKCS12_R_DECODE_ERROR
%30 = tail call i32 @PKCS12err(i32 %28, i32 %29)
br label %82
31: ; preds = %23
%32 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %25, i64 0, i32 0
%33 = load i8*, i8** %32
store i8* %33, i8** %8
%34 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %25, i64 0, i32 1
%35 = load i32, i32* %34
%36 = call %struct.TYPE_12__* @d2i_PBEPARAM(i32* null, i8** %8, i32 %35)
%37 = icmp eq %struct.TYPE_12__* %36, null
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%40 = load i32, i32* @PKCS12_R_DECODE_ERROR
%41 = call i32 @PKCS12err(i32 %39, i32 %40)
br label %82
42: ; preds = %31
%43 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %36, i64 0, i32 1
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %42
%47 = call i32 @ASN1_INTEGER_get(i32 %44)
br label %48
48: ; preds = %42, %46
%49 = phi i32 [ %47, %46 ], [ 1, %42 ]
%50 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %36, i64 0, i32 0
%51 = load %struct.TYPE_11__*, %struct.TYPE_11__** %50
%52 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %51, i64 0, i32 0
%53 = load i8*, i8** %52
%54 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %51, i64 0, i32 1
%55 = load i32, i32* %54
%56 = load i32, i32* @PKCS12_KEY_ID
%57 = call i32 @EVP_CIPHER_key_length(i32* %4)
%58 = call i32 @PKCS12_key_gen(i8* %1, i32 %2, i8* %53, i32 %55, i32 %56, i32 %49, i32 %57, i8* %13, i32* %5)
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %48
%61 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%62 = load i32, i32* @PKCS12_R_KEY_GEN_ERROR
%63 = call i32 @PKCS12err(i32 %61, i32 %62)
%64 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %36)
br label %82
65: ; preds = %48
%66 = load i32, i32* @PKCS12_IV_ID
%67 = call i32 @EVP_CIPHER_iv_length(i32* %4)
%68 = call i32 @PKCS12_key_gen(i8* %1, i32 %2, i8* %53, i32 %55, i32 %66, i32 %49, i32 %67, i8* %16, i32* %5)
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %65
%71 = load i32, i32* @PKCS12_F_PKCS12_PBE_KEYIVGEN
%72 = load i32, i32* @PKCS12_R_IV_GEN_ERROR
%73 = call i32 @PKCS12err(i32 %71, i32 %72)
%74 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %36)
br label %82
75: ; preds = %65
%76 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %36)
%77 = call i32 @EVP_CipherInit_ex(i32* %0, i32* %4, i32* null, i8* %13, i8* %16, i32 %6)
%78 = load i32, i32* @EVP_MAX_KEY_LENGTH
%79 = call i32 @explicit_bzero(i8* %13, i32 %78)
%80 = load i32, i32* @EVP_MAX_IV_LENGTH
%81 = call i32 @explicit_bzero(i8* %16, i32 %80)
br label %82
82: ; preds = %75, %70, %60, %38, %27
%83 = phi i32 [ 0, %27 ], [ %77, %75 ], [ 0, %70 ], [ 0, %60 ], [ 0, %38 ]
ret i32 %83
}