#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*/ PEM_F_PEM_WRITE_PRIVATEKEY;
int PEM_write_bio_PrivateKey(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ const *, unsigned char *, int,
                             int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ PEMerr(int /*<<< orphan*/, int /*<<< orphan*/);
int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
                         unsigned char *kstr, int klen, pem_password_cb *cb,
                         void *u) {
  BIO *b;
  int ret;
  if ((b = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) {
    PEMerr(PEM_F_PEM_WRITE_PRIVATEKEY, ERR_R_BUF_LIB);
    return 0;
  }
  ret = PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u);
  BIO_free(b);
  return ret;
}


x86 assembly (clang, -O0):
<PEM_write_PrivateKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11a7 <PEM_write_PrivateKey+0x67>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    11de <PEM_write_PrivateKey+0x9e>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    -0x38(%rbp),%r9
mov    0x10(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <PEM_write_bio_PrivateKey@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PEM_write_PrivateKey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
test   %rax,%rax
je     119e <PEM_write_PrivateKey+0x5e>
mov    %rax,%rbp
mov    0x40(%rsp),%rax
mov    %rax,(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15d,%r8d
mov    %r14,%r9
call   1060 <PEM_write_bio_PrivateKey@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <BIO_free@plt>
mov    %ebx,%eax
jmp    11b7 <PEM_write_PrivateKey+0x77>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@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
@PEM_F_PEM_WRITE_PRIVATEKEY = global i32 0
@ERR_R_BUF_LIB = global i32 0
define i32 @PEM_write_PrivateKey(i32* %0, i32* %1, i32* %2, i8* %3, i32 %4, i32* %5, i8* %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i32
store i32* %0, i32** %9
store i32* %1, i32** %10
store i32* %2, i32** %11
store i8* %3, i8** %12
store i32 %4, i32* %13
store i32* %5, i32** %14
store i8* %6, i8** %15
%18 = load i32*, i32** %9
%19 = load i32, i32* @BIO_NOCLOSE
%20 = call i32* @BIO_new_fp(i32* %18, i32 %19)
store i32* %20, i32** %16
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %7
%23 = load i32, i32* @PEM_F_PEM_WRITE_PRIVATEKEY
%24 = load i32, i32* @ERR_R_BUF_LIB
%25 = call i32 @PEMerr(i32 %23, i32 %24)
store i32 0, i32* %8
br label %38
26: ; preds = %7
%27 = load i32*, i32** %16
%28 = load i32*, i32** %10
%29 = load i32*, i32** %11
%30 = load i8*, i8** %12
%31 = load i32, i32* %13
%32 = load i32*, i32** %14
%33 = load i8*, i8** %15
%34 = call i32 @PEM_write_bio_PrivateKey(i32* %27, i32* %28, i32* %29, i8* %30, i32 %31, i32* %32, i8* %33)
store i32 %34, i32* %17
%35 = load i32*, i32** %16
%36 = call i32 @BIO_free(i32* %35)
%37 = load i32, i32* %17
store i32 %37, i32* %8
br label %38
38: ; preds = %26, %22
%39 = load i32, i32* %8
ret i32 %39
}

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