#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 PEM_write_bio_PrivateKey(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ const *, unsigned char *, int,
                             int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ PEMerror(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) {
    PEMerror(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   1040 <BIO_new_fp@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    119e <PEM_write_PrivateKey+0x5e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <PEM_write_PrivateKey+0x95>
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   1040 <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    11ae <PEM_write_PrivateKey+0x6e>
mov    0x2e53(%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 @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 %25
22: ; preds = %7
%23 = load i32, i32* @ERR_R_BUF_LIB
%24 = call i32 @PEMerror(i32 %23)
store i32 0, i32* %8
br label %37
25: ; preds = %7
%26 = load i32*, i32** %16
%27 = load i32*, i32** %10
%28 = load i32*, i32** %11
%29 = load i8*, i8** %12
%30 = load i32, i32* %13
%31 = load i32*, i32** %14
%32 = load i8*, i8** %15
%33 = call i32 @PEM_write_bio_PrivateKey(i32* %26, i32* %27, i32* %28, i8* %29, i32 %30, i32* %31, i8* %32)
store i32 %33, i32* %17
%34 = load i32*, i32** %16
%35 = call i32 @BIO_free(i32* %34)
%36 = load i32, i32* %17
store i32 %36, i32* %8
br label %37
37: ; preds = %25, %22
%38 = load i32, i32* %8
ret i32 %38
}

LLVM IR (-O2):
@BIO_NOCLOSE = 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 %14
11: ; preds = %7
%12 = load i32, i32* @ERR_R_BUF_LIB
%13 = tail call i32 @PEMerror(i32 %12)
br label %17
14: ; preds = %7
%15 = tail call i32 @PEM_write_bio_PrivateKey(i32* %9, i32* %1, i32* %2, i8* %3, i32 %4, i32* %5, i8* %6)
%16 = tail call i32 @BIO_free(i32* %9)
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ 0, %11 ], [ %15, %14 ]
ret i32 %18
}