#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 /*<<< orphan*/ PEM_F_PEM_READ;
int PEM_read_bio(int /*<<< orphan*/ *, char **, char **, unsigned char **,
                 long *);
int /*<<< orphan*/ PEMerr(int /*<<< orphan*/, int /*<<< orphan*/);
int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
             long *len) {
  BIO *b;
  int ret;
  if ((b = BIO_new(BIO_s_file())) == NULL) {
    PEMerr(PEM_F_PEM_READ, ERR_R_BUF_LIB);
    return (0);
  }
  BIO_set_fp(b, fp, BIO_NOCLOSE);
  ret = PEM_read_bio(b, name, header, data, len);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<PEM_read>:
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    11bb <PEM_read+0x5b>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1030 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <PEM_read+0x9c>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
call   1060 <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   1070 <PEM_read_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_read>:
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_read+0x66>
mov    %rax,%rbx
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <BIO_set_fp@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <PEM_read_bio@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <BIO_free@plt>
mov    %ebp,%eax
jmp    11df <PEM_read+0x7f>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1030 <PEMerr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PEM_F_PEM_READ = global i32 0
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i32 @PEM_read(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 %21
17: ; preds = %5
%18 = load i32, i32* @PEM_F_PEM_READ
%19 = load i32, i32* @ERR_R_BUF_LIB
%20 = call i32 @PEMerr(i32 %18, i32 %19)
store i32 0, i32* %6
br label %35
21: ; preds = %5
%22 = load i32*, i32** %12
%23 = load i32*, i32** %7
%24 = load i32, i32* @BIO_NOCLOSE
%25 = call i32 @BIO_set_fp(i32* %22, i32* %23, i32 %24)
%26 = load i32*, i32** %12
%27 = load i8**, i8*** %8
%28 = load i8**, i8*** %9
%29 = load i8**, i8*** %10
%30 = load i64*, i64** %11
%31 = call i32 @PEM_read_bio(i32* %26, i8** %27, i8** %28, i8** %29, i64* %30)
store i32 %31, i32* %13
%32 = load i32*, i32** %12
%33 = call i32 @BIO_free(i32* %32)
%34 = load i32, i32* %13
store i32 %34, i32* %6
br label %35
35: ; preds = %21, %17
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
@PEM_F_PEM_READ = global i32 0
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i32 @PEM_read(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 %13
9: ; preds = %5
%10 = load i32, i32* @PEM_F_PEM_READ
%11 = load i32, i32* @ERR_R_BUF_LIB
%12 = tail call i32 @PEMerr(i32 %10, i32 %11)
br label %18
13: ; preds = %5
%14 = load i32, i32* @BIO_NOCLOSE
%15 = tail call i32 @BIO_set_fp(i32* %7, i32* %0, i32 %14)
%16 = tail call i32 @PEM_read_bio(i32* %7, i8** %1, i8** %2, i8** %3, i64* %4)
%17 = tail call i32 @BIO_free(i32* %7)
br label %18
18: ; preds = %13, %9
%19 = phi i32 [ 0, %9 ], [ %16, %13 ]
ret i32 %19
}