#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*/ i2d_of_void;
typedef int /*<<< orphan*/ FILE;
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(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file();
int /*<<< orphan*/ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_BUF_LIB;
int PEM_ASN1_write_bio(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/ *,
                       void *, int /*<<< orphan*/ const *, unsigned char *, int,
                       int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ PEMerror(int /*<<< orphan*/);
int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, void *x,
                   const EVP_CIPHER *enc, unsigned char *kstr, int klen,
                   pem_password_cb *callback, void *u) {
  BIO *b;
  int ret;
  if ((b = BIO_new(BIO_s_file())) == NULL) {
    PEMerror(ERR_R_BUF_LIB);
    return (0);
  }
  BIO_set_fp(b, fp, BIO_NOCLOSE);
  ret = PEM_ASN1_write_bio(i2d, name, b, x, enc, kstr, klen, callback, u);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<PEM_ASN1_write>:
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    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    $0x0,%al
call   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11c1 <PEM_ASN1_write+0x61>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1220 <PEM_ASN1_write+0xc0>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
call   1070 <BIO_set_fp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x38(%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   1040 <PEM_ASN1_write_bio@plt>
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PEM_ASN1_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %eax,%eax
call   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
test   %rax,%rax
je     11e4 <PEM_ASN1_write+0x84>
mov    %rax,%rbx
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <BIO_set_fp@plt>
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    0x8(%rsp),%r9
push   0x58(%rsp)
push   0x58(%rsp)
mov    0x58(%rsp),%eax
push   %rax
call   1040 <PEM_ASN1_write_bio@plt>
add    $0x20,%rsp
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <BIO_free@plt>
mov    %ebp,%eax
jmp    11f4 <PEM_ASN1_write+0x94>
mov    0x2e0d(%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):
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i32 @PEM_ASN1_write(i32* %0, i8* %1, i32* %2, i8* %3, i32* %4, i8* %5, i32 %6, i32* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i8*
%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 i8* %1, i8** %12
store i32* %2, i32** %13
store i8* %3, i8** %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 = call i32 (...) @BIO_s_file()
%23 = call i32* @BIO_new(i32 %22)
store i32* %23, i32** %20
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %9
%26 = load i32, i32* @ERR_R_BUF_LIB
%27 = call i32 @PEMerror(i32 %26)
store i32 0, i32* %10
br label %46
28: ; preds = %9
%29 = load i32*, i32** %20
%30 = load i32*, i32** %13
%31 = load i32, i32* @BIO_NOCLOSE
%32 = call i32 @BIO_set_fp(i32* %29, i32* %30, i32 %31)
%33 = load i32*, i32** %11
%34 = load i8*, i8** %12
%35 = load i32*, i32** %20
%36 = load i8*, i8** %14
%37 = load i32*, i32** %15
%38 = load i8*, i8** %16
%39 = load i32, i32* %17
%40 = load i32*, i32** %18
%41 = load i8*, i8** %19
%42 = call i32 @PEM_ASN1_write_bio(i32* %33, i8* %34, i32* %35, i8* %36, i32* %37, i8* %38, i32 %39, i32* %40, i8* %41)
store i32 %42, i32* %21
%43 = load i32*, i32** %20
%44 = call i32 @BIO_free(i32* %43)
%45 = load i32, i32* %21
store i32 %45, i32* %10
br label %46
46: ; preds = %28, %25
%47 = load i32, i32* %10
ret i32 %47
}

LLVM IR (-O2):
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i32 @PEM_ASN1_write(i32* %0, i8* %1, i32* %2, i8* %3, i32* %4, i8* %5, i32 %6, i32* %7, i8* %8) {
%10 = tail call i32 (...) @BIO_s_file()
%11 = tail call i32* @BIO_new(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 %21
16: ; preds = %9
%17 = load i32, i32* @BIO_NOCLOSE
%18 = tail call i32 @BIO_set_fp(i32* %11, i32* %2, i32 %17)
%19 = tail call i32 @PEM_ASN1_write_bio(i32* %0, i8* %1, i32* %11, i8* %3, i32* %4, i8* %5, i32 %6, i32* %7, i8* %8)
%20 = tail call i32 @BIO_free(i32* %11)
br label %21
21: ; preds = %16, %13
%22 = phi i32 [ 0, %13 ], [ %19, %16 ]
ret i32 %22
}