#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*/ X509;
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 X509_print_ex(int /*<<< orphan*/ *, int /*<<< orphan*/ *, unsigned long,
                  unsigned long);
int /*<<< orphan*/ X509error(int /*<<< orphan*/);
int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag,
                     unsigned long cflag) {
  BIO *b;
  int ret;
  if ((b = BIO_new(BIO_s_file())) == NULL) {
    X509error(ERR_R_BUF_LIB);
    return (0);
  }
  BIO_set_fp(b, fp, BIO_NOCLOSE);
  ret = X509_print_ex(b, x, nmflag, cflag);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<X509_print_ex_fp>:
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    $0x0,%al
call   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ae <X509_print_ex_fp+0x4e>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1040 <X509error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11eb <X509_print_ex_fp+0x8b>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
call   1070 <BIO_set_fp@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <X509_print_ex@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

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

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