#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_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*/ PKCS12error(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) {
    PKCS12error(PKCS12_R_DECODE_ERROR);
    return 0;
  }
  pbuf = param->value.sequence->data;
  if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) {
    PKCS12error(PKCS12_R_DECODE_ERROR);
    return 0;
  }
  if (!pbe->iter)
    iter = 1;
  else if ((iter = ASN1_INTEGER_get(pbe->iter)) <= 0) {
    PKCS12error(PKCS12_R_DECODE_ERROR);
    PBEPARAM_free(pbe);
    return 0;
  }
  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)) {
    PKCS12error(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)) {
    PKCS12error(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    0x2d7b(%rip),%rcx
cmp    (%rcx),%rax
jne    123d <PKCS12_PBE_keyivgen+0xad>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    125e <PKCS12_PBE_keyivgen+0xce>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1530 <PKCS12_PBE_keyivgen+0x3a0>
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    12b4 <PKCS12_PBE_keyivgen+0x124>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1530 <PKCS12_PBE_keyivgen+0x3a0>
mov    -0x40(%rbp),%rax
cmpl   $0x0,0x8(%rax)
jne    12ce <PKCS12_PBE_keyivgen+0x13e>
movl   $0x1,-0x48(%rbp)
jmp    1315 <PKCS12_PBE_keyivgen+0x185>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edi
call   1070 <ASN1_INTEGER_get@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jg     1310 <PKCS12_PBE_keyivgen+0x180>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
mov    -0x40(%rbp),%rdi
call   1050 <PBEPARAM_free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1530 <PKCS12_PBE_keyivgen+0x3a0>
jmp    1315 <PKCS12_PBE_keyivgen+0x185>
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    0x2c69(%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    13fd <PKCS12_PBE_keyivgen+0x26d>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
mov    -0x40(%rbp),%rdi
call   1050 <PBEPARAM_free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1530 <PKCS12_PBE_keyivgen+0x3a0>
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    0x2b84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc0(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <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    14ca <PKCS12_PBE_keyivgen+0x33a>
mov    0x2b19(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
mov    -0x40(%rbp),%rdi
call   1050 <PBEPARAM_free@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    1530 <PKCS12_PBE_keyivgen+0x3a0>
mov    -0x40(%rbp),%rdi
call   1050 <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    0x2ad9(%rip),%rax
mov    (%rax),%esi
call   1090 <explicit_bzero@plt>
mov    -0x88(%rbp),%rdi
mov    0x2acc(%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    $0x48,%rsp
mov    %rsp,%r15
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rcx,%rcx
je     1258 <PKCS12_PBE_keyivgen+0xc8>
mov    %rsi,%r14
mov    (%rcx),%rax
mov    0x2db6(%rip),%rsi
cmp    (%rsi),%rax
jne    1258 <PKCS12_PBE_keyivgen+0xc8>
mov    0x8(%rcx),%rax
test   %rax,%rax
je     1258 <PKCS12_PBE_keyivgen+0xc8>
mov    %edx,-0x34(%rbp)
mov    %r9,-0x58(%rbp)
mov    %rdi,-0x68(%rbp)
mov    %r8,-0x48(%rbp)
mov    (%rax),%rcx
mov    %rcx,-0x70(%rbp)
mov    0x8(%rax),%edx
xor    %r13d,%r13d
lea    -0x70(%rbp),%rsi
xor    %edi,%edi
call   10b0 <d2i_PBEPARAM@plt>
test   %rax,%rax
je     127e <PKCS12_PBE_keyivgen+0xee>
mov    0x8(%rax),%edi
test   %edi,%edi
je     128e <PKCS12_PBE_keyivgen+0xfe>
mov    %rax,%r13
call   1070 <ASN1_INTEGER_get@plt>
mov    %eax,%ecx
mov    %r13,%rax
mov    %ecx,-0x2c(%rbp)
test   %ecx,%ecx
jg     1295 <PKCS12_PBE_keyivgen+0x105>
mov    %rax,%rbx
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
mov    %rbx,%rdi
jmp    1397 <PKCS12_PBE_keyivgen+0x207>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
xor    %r13d,%r13d
mov    %r15,%rsp
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
jmp    1269 <PKCS12_PBE_keyivgen+0xd9>
movl   $0x1,-0x2c(%rbp)
mov    %rax,-0x40(%rbp)
mov    (%rax),%rax
mov    (%rax),%r13
mov    0x8(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
call   1080 <EVP_CIPHER_key_length@plt>
sub    $0x8,%rsp
mov    %r14,%rdi
mov    -0x34(%rbp),%esi
mov    %r13,-0x60(%rbp)
mov    %r13,%rdx
mov    -0x30(%rbp),%ecx
mov    -0x4c(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x58(%rbp),%r13
push   %r13
push   %r12
push   %rax
call   1030 <PKCS12_key_gen@plt>
add    $0x20,%rsp
test   %eax,%eax
je     137c <PKCS12_PBE_keyivgen+0x1ec>
mov    0x2cb9(%rip),%rax
mov    (%rax),%r13d
mov    -0x48(%rbp),%rdi
call   1060 <EVP_CIPHER_iv_length@plt>
sub    $0x8,%rsp
mov    %r14,%rdi
mov    -0x34(%rbp),%esi
mov    -0x60(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    %r13d,%r8d
mov    -0x2c(%rbp),%r9d
push   -0x58(%rbp)
push   %rbx
push   %rax
call   1030 <PKCS12_key_gen@plt>
add    $0x20,%rsp
test   %eax,%eax
je     1385 <PKCS12_PBE_keyivgen+0x1f5>
mov    0x10(%rbp),%r14d
mov    -0x40(%rbp),%rdi
call   1050 <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    0x2c84(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1090 <explicit_bzero@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <explicit_bzero@plt>
jmp    1269 <PKCS12_PBE_keyivgen+0xd9>
mov    0x2c55(%rip),%rax
jmp    138c <PKCS12_PBE_keyivgen+0x1fc>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
mov    -0x40(%rbp),%rdi
call   1050 <PBEPARAM_free@plt>
jmp    1266 <PKCS12_PBE_keyivgen+0xd6>

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_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 %50
47: ; preds = %41, %35, %7
%48 = load i32, i32* @PKCS12_R_DECODE_ERROR
%49 = call i32 @PKCS12error(i32 %48)
store i32 0, i32* %8
store i32 1, i32* %25
br label %142
50: ; preds = %41
%51 = load %struct.TYPE_13__*, %struct.TYPE_13__** %12
%52 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %51, i32 0, i32 1
%53 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %52, i32 0, i32 0
%54 = load %struct.TYPE_9__*, %struct.TYPE_9__** %53
%55 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %54, i32 0, i32 0
%56 = load i8*, i8** %55
store i8* %56, i8** %21
%57 = load %struct.TYPE_13__*, %struct.TYPE_13__** %12
%58 = getelementptr inbounds %struct.TYPE_13__, %struct.TYPE_13__* %57, i32 0, i32 1
%59 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %58, i32 0, i32 0
%60 = load %struct.TYPE_9__*, %struct.TYPE_9__** %59
%61 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %60, i32 0, i32 1
%62 = load i32, i32* %61
%63 = call %struct.TYPE_12__* @d2i_PBEPARAM(i32* null, i8** %21, i32 %62)
store %struct.TYPE_12__* %63, %struct.TYPE_12__** %16
%64 = icmp ne %struct.TYPE_12__* %63, null
br i1 %64, label %68, label %65
65: ; preds = %50
%66 = load i32, i32* @PKCS12_R_DECODE_ERROR
%67 = call i32 @PKCS12error(i32 %66)
store i32 0, i32* %8
store i32 1, i32* %25
br label %142
68: ; preds = %50
%69 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%70 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = icmp ne i32 %71, 0
br i1 %72, label %74, label %73
73: ; preds = %68
store i32 1, i32* %18
br label %86
74: ; preds = %68
%75 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%76 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %75, i32 0, i32 1
%77 = load i32, i32* %76
%78 = call i32 @ASN1_INTEGER_get(i32 %77)
store i32 %78, i32* %18
%79 = icmp sle i32 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %74
%81 = load i32, i32* @PKCS12_R_DECODE_ERROR
%82 = call i32 @PKCS12error(i32 %81)
%83 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%84 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %83)
store i32 0, i32* %8
store i32 1, i32* %25
br label %142
85: ; preds = %74
br label %86
86: ; preds = %85, %73
%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 0
%91 = load i8*, i8** %90
store i8* %91, i8** %20
%92 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%93 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %92, i32 0, i32 0
%94 = load %struct.TYPE_11__*, %struct.TYPE_11__** %93
%95 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %94, i32 0, i32 1
%96 = load i32, i32* %95
store i32 %96, i32* %17
%97 = load i8*, i8** %10
%98 = load i32, i32* %11
%99 = load i8*, i8** %20
%100 = load i32, i32* %17
%101 = load i32, i32* @PKCS12_KEY_ID
%102 = load i32, i32* %18
%103 = load i32*, i32** %13
%104 = call i32 @EVP_CIPHER_key_length(i32* %103)
%105 = load i32*, i32** %14
%106 = call i32 @PKCS12_key_gen(i8* %97, i32 %98, i8* %99, i32 %100, i32 %101, i32 %102, i32 %104, i8* %29, i32* %105)
%107 = icmp ne i32 %106, 0
br i1 %107, label %113, label %108
108: ; preds = %86
%109 = load i32, i32* @PKCS12_R_KEY_GEN_ERROR
%110 = call i32 @PKCS12error(i32 %109)
%111 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%112 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %111)
store i32 0, i32* %8
store i32 1, i32* %25
br label %142
113: ; preds = %86
%114 = load i8*, i8** %10
%115 = load i32, i32* %11
%116 = load i8*, i8** %20
%117 = load i32, i32* %17
%118 = load i32, i32* @PKCS12_IV_ID
%119 = load i32, i32* %18
%120 = load i32*, i32** %13
%121 = call i32 @EVP_CIPHER_iv_length(i32* %120)
%122 = load i32*, i32** %14
%123 = call i32 @PKCS12_key_gen(i8* %114, i32 %115, i8* %116, i32 %117, i32 %118, i32 %119, i32 %121, i8* %32, i32* %122)
%124 = icmp ne i32 %123, 0
br i1 %124, label %130, label %125
125: ; preds = %113
%126 = load i32, i32* @PKCS12_R_IV_GEN_ERROR
%127 = call i32 @PKCS12error(i32 %126)
%128 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%129 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %128)
store i32 0, i32* %8
store i32 1, i32* %25
br label %142
130: ; preds = %113
%131 = load %struct.TYPE_12__*, %struct.TYPE_12__** %16
%132 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %131)
%133 = load i32*, i32** %9
%134 = load i32*, i32** %13
%135 = load i32, i32* %15
%136 = call i32 @EVP_CipherInit_ex(i32* %133, i32* %134, i32* null, i8* %29, i8* %32, i32 %135)
store i32 %136, i32* %19
%137 = load i32, i32* @EVP_MAX_KEY_LENGTH
%138 = call i32 @explicit_bzero(i8* %29, i32 %137)
%139 = load i32, i32* @EVP_MAX_IV_LENGTH
%140 = call i32 @explicit_bzero(i8* %32, i32 %139)
%141 = load i32, i32* %19
store i32 %141, i32* %8
store i32 1, i32* %25
br label %142
142: ; preds = %130, %125, %108, %80, %65, %47
%143 = load i8*, i8** %22
%144 = load i32, i32* %8
ret i32 %144
}

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_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 %30
27: ; preds = %23, %18, %7
%28 = load i32, i32* @PKCS12_R_DECODE_ERROR
%29 = tail call i32 @PKCS12error(i32 %28)
br label %83
30: ; preds = %23
%31 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %25, i64 0, i32 0
%32 = load i8*, i8** %31
store i8* %32, i8** %8
%33 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %25, i64 0, i32 1
%34 = load i32, i32* %33
%35 = call %struct.TYPE_12__* @d2i_PBEPARAM(i32* null, i8** %8, i32 %34)
%36 = icmp eq %struct.TYPE_12__* %35, null
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = load i32, i32* @PKCS12_R_DECODE_ERROR
%39 = call i32 @PKCS12error(i32 %38)
br label %83
40: ; preds = %30
%41 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %35, i64 0, i32 1
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 0
br i1 %43, label %51, label %44
44: ; preds = %40
%45 = call i32 @ASN1_INTEGER_get(i32 %42)
%46 = icmp slt i32 %45, 1
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* @PKCS12_R_DECODE_ERROR
%49 = call i32 @PKCS12error(i32 %48)
%50 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %35)
br label %83
51: ; preds = %40, %44
%52 = phi i32 [ %45, %44 ], [ 1, %40 ]
%53 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %35, i64 0, i32 0
%54 = load %struct.TYPE_11__*, %struct.TYPE_11__** %53
%55 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %54, i64 0, i32 0
%56 = load i8*, i8** %55
%57 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %54, i64 0, i32 1
%58 = load i32, i32* %57
%59 = load i32, i32* @PKCS12_KEY_ID
%60 = call i32 @EVP_CIPHER_key_length(i32* %4)
%61 = call i32 @PKCS12_key_gen(i8* %1, i32 %2, i8* %56, i32 %58, i32 %59, i32 %52, i32 %60, i8* %13, i32* %5)
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %51
%64 = load i32, i32* @PKCS12_R_KEY_GEN_ERROR
%65 = call i32 @PKCS12error(i32 %64)
%66 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %35)
br label %83
67: ; preds = %51
%68 = load i32, i32* @PKCS12_IV_ID
%69 = call i32 @EVP_CIPHER_iv_length(i32* %4)
%70 = call i32 @PKCS12_key_gen(i8* %1, i32 %2, i8* %56, i32 %58, i32 %68, i32 %52, i32 %69, i8* %16, i32* %5)
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %67
%73 = load i32, i32* @PKCS12_R_IV_GEN_ERROR
%74 = call i32 @PKCS12error(i32 %73)
%75 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %35)
br label %83
76: ; preds = %67
%77 = call i32 @PBEPARAM_free(%struct.TYPE_12__* %35)
%78 = call i32 @EVP_CipherInit_ex(i32* %0, i32* %4, i32* null, i8* %13, i8* %16, i32 %6)
%79 = load i32, i32* @EVP_MAX_KEY_LENGTH
%80 = call i32 @explicit_bzero(i8* %13, i32 %79)
%81 = load i32, i32* @EVP_MAX_IV_LENGTH
%82 = call i32 @explicit_bzero(i8* %16, i32 %81)
br label %83
83: ; preds = %76, %72, %63, %47, %37, %27
%84 = phi i32 [ 0, %27 ], [ 0, %47 ], [ %78, %76 ], [ 0, %72 ], [ 0, %63 ], [ 0, %37 ]
ret i32 %84
}