#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_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ X509_ALGOR;
struct TYPE_3__ {
  int /*<<< orphan*/ length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ ASN1_OCTET_STRING;
typedef int /*<<< orphan*/ ASN1_ITEM;

/* Variables and functions */
void *ASN1_item_d2i(int /*<<< orphan*/ *, unsigned char const **, int,
                    int /*<<< orphan*/ const *);
int /*<<< orphan*/ PKCS12_R_DECODE_ERROR;
int /*<<< orphan*/ PKCS12_R_PKCS12_PBE_CRYPT_ERROR;
int /*<<< orphan*/ PKCS12_pbe_crypt(int /*<<< orphan*/ const *, char const *,
                                    int, int /*<<< orphan*/, int /*<<< orphan*/,
                                    unsigned char **, int *,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ PKCS12error(int /*<<< orphan*/);
int /*<<< orphan*/ explicit_bzero(unsigned char *, int);
int /*<<< orphan*/ free(unsigned char *);
void *PKCS12_item_decrypt_d2i(const X509_ALGOR *algor, const ASN1_ITEM *it,
                              const char *pass, int passlen,
                              const ASN1_OCTET_STRING *oct, int zbuf) {
  unsigned char *out;
  const unsigned char *p;
  void *ret;
  int outlen;
  if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length, &out,
                        &outlen, 0)) {
    PKCS12error(PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
    return NULL;
  }
  p = out;
  ret = ASN1_item_d2i(NULL, &p, outlen, it);
  if (zbuf)
    explicit_bzero(out, outlen);
  if (!ret)
    PKCS12error(PKCS12_R_DECODE_ERROR);
  free(out);
  return ret;
}


x86 assembly (clang, -O0):
<PKCS12_item_decrypt_d2i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x30(%rbp),%rax
mov    (%rax),%r8d
lea    -0x40(%rbp),%r9
lea    -0x54(%rbp),%rax
xor    %r10d,%r10d
mov    %rax,(%rsp)
movl   $0x0,0x8(%rsp)
call   1060 <PKCS12_pbe_crypt@plt>
cmp    $0x0,%eax
jne    11c8 <PKCS12_item_decrypt_d2i+0x78>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1228 <PKCS12_item_decrypt_d2i+0xd8>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x54(%rbp),%edx
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x48(%rbp),%rsi
call   1050 <ASN1_item_d2i@plt>
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11fe <PKCS12_item_decrypt_d2i+0xae>
mov    -0x40(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1070 <explicit_bzero@plt>
cmpq   $0x0,-0x50(%rbp)
jne    1217 <PKCS12_item_decrypt_d2i+0xc7>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PKCS12_item_decrypt_d2i>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r9d,%r14d
mov    %rsi,%r15
mov    (%r8),%eax
mov    0x4(%r8),%ebp
lea    0x4(%rsp),%rbx
lea    0x8(%rsp),%r9
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
push   $0x0
push   %rbx
call   1060 <PKCS12_pbe_crypt@plt>
add    $0x10,%rsp
test   %eax,%eax
je     11dd <PKCS12_item_decrypt_d2i+0x8d>
mov    0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    0x4(%rsp),%edx
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    %r15,%rcx
call   1050 <ASN1_item_d2i@plt>
mov    %rax,%rbx
test   %r14d,%r14d
je     11be <PKCS12_item_decrypt_d2i+0x6e>
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%esi
call   1070 <explicit_bzero@plt>
test   %rbx,%rbx
jne    11d1 <PKCS12_item_decrypt_d2i+0x81>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    11ed <PKCS12_item_decrypt_d2i+0x9d>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1040 <PKCS12error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@PKCS12_R_PKCS12_PBE_CRYPT_ERROR = global i32 0
@PKCS12_R_DECODE_ERROR = global i32 0
define i8* @PKCS12_item_decrypt_d2i(i32* %0, i32* %1, i8* %2, i32 %3, %struct.TYPE_3__* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.TYPE_3__*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store %struct.TYPE_3__* %4, %struct.TYPE_3__** %12
store i32 %5, i32* %13
%18 = load i32*, i32** %8
%19 = load i8*, i8** %10
%20 = load i32, i32* %11
%21 = load %struct.TYPE_3__*, %struct.TYPE_3__** %12
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %12
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @PKCS12_pbe_crypt(i32* %18, i8* %19, i32 %20, i32 %23, i32 %26, i8** %14, i32* %17, i32 0)
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %6
%30 = load i32, i32* @PKCS12_R_PKCS12_PBE_CRYPT_ERROR
%31 = call i32 @PKCS12error(i32 %30)
store i8* null, i8** %7
br label %53
32: ; preds = %6
%33 = load i8*, i8** %14
store i8* %33, i8** %15
%34 = load i32, i32* %17
%35 = load i32*, i32** %9
%36 = call i8* @ASN1_item_d2i(i32* null, i8** %15, i32 %34, i32* %35)
store i8* %36, i8** %16
%37 = load i32, i32* %13
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %32
%40 = load i8*, i8** %14
%41 = load i32, i32* %17
%42 = call i32 @explicit_bzero(i8* %40, i32 %41)
br label %43
43: ; preds = %39, %32
%44 = load i8*, i8** %16
%45 = icmp ne i8* %44, null
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* @PKCS12_R_DECODE_ERROR
%48 = call i32 @PKCS12error(i32 %47)
br label %49
49: ; preds = %46, %43
%50 = load i8*, i8** %14
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %16
store i8* %52, i8** %7
br label %53
53: ; preds = %49, %29
%54 = load i8*, i8** %7
ret i8* %54
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@PKCS12_R_PKCS12_PBE_CRYPT_ERROR = global i32 0
@PKCS12_R_DECODE_ERROR = global i32 0
define i8* @PKCS12_item_decrypt_d2i(i32* %0, i32* %1, i8* %2, i32 %3, %struct.TYPE_3__* nocapture %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = bitcast i8** %7 to i8*
%11 = bitcast i8** %8 to i8*
%12 = bitcast i32* %9 to i8*
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @PKCS12_pbe_crypt(i32* %0, i8* %2, i32 %3, i32 %14, i32 %16, i8** %7, i32* %9, i32 0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %6
%20 = load i32, i32* @PKCS12_R_PKCS12_PBE_CRYPT_ERROR
%21 = call i32 @PKCS12error(i32 %20)
br label %39
22: ; preds = %6
%23 = load i8*, i8** %7
store i8* %23, i8** %8
%24 = load i32, i32* %9
%25 = call i8* @ASN1_item_d2i(i32* null, i8** %8, i32 %24, i32* %1)
%26 = icmp eq i32 %5, 0
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i32, i32* %9
%30 = call i32 @explicit_bzero(i8* %28, i32 %29)
br label %31
31: ; preds = %27, %22
%32 = icmp eq i8* %25, null
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i32, i32* @PKCS12_R_DECODE_ERROR
%35 = call i32 @PKCS12error(i32 %34)
br label %36
36: ; preds = %33, %31
%37 = load i8*, i8** %7
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %36, %19
%40 = phi i8* [ %25, %36 ], [ null, %19 ]
ret i8* %40
}