#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 */

/* Type definitions */
typedef int /*<<< orphan*/ pem_password_cb;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_fp(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_BUF_LIB;
int /*<<< orphan*/ PEM_F_D2I_PKCS8PRIVATEKEY_FP;
int /*<<< orphan*/ PEMerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *d2i_PKCS8PrivateKey_bio(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ **,
                                            int /*<<< orphan*/ *, void *);
EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
                                 void *u) {
  BIO *bp;
  EVP_PKEY *ret;
  if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
    PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP, ERR_R_BUF_LIB);
    return NULL;
  }
  ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
  BIO_free(bp);
  return ret;
}


x86 assembly (clang, -O0):
<d2i_PKCS8PrivateKey_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    119c <d2i_PKCS8PrivateKey_fp+0x5c>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <d2i_PKCS8PrivateKey_fp+0x86>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1060 <d2i_PKCS8PrivateKey_bio@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2i_PKCS8PrivateKey_fp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
test   %rax,%rax
je     1188 <d2i_PKCS8PrivateKey_fp+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <d2i_PKCS8PrivateKey_bio@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <BIO_free@plt>
mov    %r14,%rax
jmp    11a1 <d2i_PKCS8PrivateKey_fp+0x61>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@BIO_NOCLOSE = global i32 0
@PEM_F_D2I_PKCS8PRIVATEKEY_FP = global i32 0
@ERR_R_BUF_LIB = global i32 0
define i32* @d2i_PKCS8PrivateKey_fp(i32* %0, i32** %1, i32* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32**
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
store i32* %0, i32** %6
store i32** %1, i32*** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%12 = load i32*, i32** %6
%13 = load i32, i32* @BIO_NOCLOSE
%14 = call i32* @BIO_new_fp(i32* %12, i32 %13)
store i32* %14, i32** %10
%15 = icmp ne i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %4
%17 = load i32, i32* @PEM_F_D2I_PKCS8PRIVATEKEY_FP
%18 = load i32, i32* @ERR_R_BUF_LIB
%19 = call i32 @PEMerr(i32 %17, i32 %18)
store i32* null, i32** %5
br label %29
20: ; preds = %4
%21 = load i32*, i32** %10
%22 = load i32**, i32*** %7
%23 = load i32*, i32** %8
%24 = load i8*, i8** %9
%25 = call i32* @d2i_PKCS8PrivateKey_bio(i32* %21, i32** %22, i32* %23, i8* %24)
store i32* %25, i32** %11
%26 = load i32*, i32** %10
%27 = call i32 @BIO_free(i32* %26)
%28 = load i32*, i32** %11
store i32* %28, i32** %5
br label %29
29: ; preds = %20, %16
%30 = load i32*, i32** %5
ret i32* %30
}

LLVM IR (-O2):
@BIO_NOCLOSE = global i32 0
@PEM_F_D2I_PKCS8PRIVATEKEY_FP = global i32 0
@ERR_R_BUF_LIB = global i32 0
define i32* @d2i_PKCS8PrivateKey_fp(i32* %0, i32** %1, i32* %2, i8* %3) {
%5 = load i32, i32* @BIO_NOCLOSE
%6 = tail call i32* @BIO_new_fp(i32* %0, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i32, i32* @PEM_F_D2I_PKCS8PRIVATEKEY_FP
%10 = load i32, i32* @ERR_R_BUF_LIB
%11 = tail call i32 @PEMerr(i32 %9, i32 %10)
br label %15
12: ; preds = %4
%13 = tail call i32* @d2i_PKCS8PrivateKey_bio(i32* %6, i32** %1, i32* %2, i8* %3)
%14 = tail call i32 @BIO_free(i32* %6)
br label %15
15: ; preds = %12, %8
%16 = phi i32* [ %13, %12 ], [ null, %8 ]
ret i32* %16
}