#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*/ EVP_CIPHER;
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*/ PEMerror(int /*<<< orphan*/);
int do_pk8pkey(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int, int,
               int /*<<< orphan*/ const *, char *, int, int /*<<< orphan*/ *,
               void *);
int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid,
                  const EVP_CIPHER *enc, char *kstr, int klen,
                  pem_password_cb *cb, void *u) {
  BIO *bp;
  int ret;
  if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
    PEMerror(ERR_R_BUF_LIB);
    return (0);
  }
  ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
  BIO_free(bp);
  return ret;
}


x86 assembly (clang, -O0):
<do_pk8pkey_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1040 <BIO_new_fp@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11a3 <do_pk8pkey_fp+0x63>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ea <do_pk8pkey_fp+0xaa>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%r11d
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1050 <do_pk8pkey@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_pk8pkey_fp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%rbp
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
call   1040 <BIO_new_fp@plt>
test   %rax,%rax
je     11aa <do_pk8pkey_fp+0x6a>
mov    %rax,%rbx
mov    0x40(%rsp),%eax
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
mov    %r15,%r8
mov    %r14,%r9
push   0x58(%rsp)
push   0x58(%rsp)
push   %rax
call   1050 <do_pk8pkey@plt>
add    $0x20,%rsp
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <BIO_free@plt>
mov    %ebp,%eax
jmp    11ba <do_pk8pkey_fp+0x7a>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BIO_NOCLOSE = global i32 0
@ERR_R_BUF_LIB = global i32 0
define i32 @do_pk8pkey_fp(i32* %0, i32* %1, i32 %2, i32 %3, i32* %4, i8* %5, i32 %6, i32* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32*
%19 = alloca i8*
%20 = alloca i32*
%21 = alloca i32
store i32* %0, i32** %11
store i32* %1, i32** %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32* %4, i32** %15
store i8* %5, i8** %16
store i32 %6, i32* %17
store i32* %7, i32** %18
store i8* %8, i8** %19
%22 = load i32*, i32** %11
%23 = load i32, i32* @BIO_NOCLOSE
%24 = call i32* @BIO_new_fp(i32* %22, i32 %23)
store i32* %24, i32** %20
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %9
%27 = load i32, i32* @ERR_R_BUF_LIB
%28 = call i32 @PEMerror(i32 %27)
store i32 0, i32* %10
br label %43
29: ; preds = %9
%30 = load i32*, i32** %20
%31 = load i32*, i32** %12
%32 = load i32, i32* %13
%33 = load i32, i32* %14
%34 = load i32*, i32** %15
%35 = load i8*, i8** %16
%36 = load i32, i32* %17
%37 = load i32*, i32** %18
%38 = load i8*, i8** %19
%39 = call i32 @do_pk8pkey(i32* %30, i32* %31, i32 %32, i32 %33, i32* %34, i8* %35, i32 %36, i32* %37, i8* %38)
store i32 %39, i32* %21
%40 = load i32*, i32** %20
%41 = call i32 @BIO_free(i32* %40)
%42 = load i32, i32* %21
store i32 %42, i32* %10
br label %43
43: ; preds = %29, %26
%44 = load i32, i32* %10
ret i32 %44
}

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