#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*/ FILE;
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_write_bio(int /*<<< orphan*/ *, char const *, char const *,
                  unsigned char const *, long);
int /*<<< orphan*/ PEMerror(int /*<<< orphan*/);
int PEM_write(FILE *fp, const char *name, const char *header,
              const unsigned char *data, long len) {
  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_write_bio(b, name, header, data, len);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<PEM_write>:
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    %r8,-0x30(%rbp)
mov    $0x0,%al
call   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11b2 <PEM_write+0x52>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <PEM_write+0x93>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
call   1070 <BIO_set_fp@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1060 <PEM_write_bio@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PEM_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %eax,%eax
call   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
test   %rax,%rax
je     11c6 <PEM_write+0x66>
mov    %rax,%rbx
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <BIO_set_fp@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <PEM_write_bio@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <BIO_free@plt>
mov    %ebp,%eax
jmp    11d6 <PEM_write+0x76>
mov    0x2e2b(%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_write(i32* %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%14 = call i32 (...) @BIO_s_file()
%15 = call i32* @BIO_new(i32 %14)
store i32* %15, i32** %12
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = load i32, i32* @ERR_R_BUF_LIB
%19 = call i32 @PEMerror(i32 %18)
store i32 0, i32* %6
br label %34
20: ; preds = %5
%21 = load i32*, i32** %12
%22 = load i32*, i32** %7
%23 = load i32, i32* @BIO_NOCLOSE
%24 = call i32 @BIO_set_fp(i32* %21, i32* %22, i32 %23)
%25 = load i32*, i32** %12
%26 = load i8*, i8** %8
%27 = load i8*, i8** %9
%28 = load i8*, i8** %10
%29 = load i64, i64* %11
%30 = call i32 @PEM_write_bio(i32* %25, i8* %26, i8* %27, i8* %28, i64 %29)
store i32 %30, i32* %13
%31 = load i32*, i32** %12
%32 = call i32 @BIO_free(i32* %31)
%33 = load i32, i32* %13
store i32 %33, i32* %6
br label %34
34: ; preds = %20, %17
%35 = load i32, i32* %6
ret i32 %35
}

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