#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*/ i2d_of_void;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int ASN1_i2d_bio(int /*<<< orphan*/ *, int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
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 ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) {
  BIO *b;
  int ret;
  if ((b = BIO_new(BIO_s_file())) == NULL) {
    ASN1error(ERR_R_BUF_LIB);
    return (0);
  }
  BIO_set_fp(b, out, BIO_NOCLOSE);
  ret = ASN1_i2d_bio(i2d, b, x);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<ASN1_i2d_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1070 <BIO_s_file@plt>
mov    %eax,%edi
call   1030 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11aa <ASN1_i2d_fp+0x4a>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1080 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <ASN1_i2d_fp+0x83>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
call   1060 <BIO_set_fp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <ASN1_i2d_bio@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <BIO_free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_i2d_fp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %eax,%eax
call   1070 <BIO_s_file@plt>
mov    %eax,%edi
call   1030 <BIO_new@plt>
test   %rax,%rax
je     11b7 <ASN1_i2d_fp+0x57>
mov    %rax,%rbx
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <BIO_set_fp@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <ASN1_i2d_bio@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <BIO_free@plt>
mov    %ebp,%eax
jmp    11c7 <ASN1_i2d_fp+0x67>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1080 <ASN1error@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i32 @ASN1_i2d_fp(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%10 = call i32 (...) @BIO_s_file()
%11 = call i32* @BIO_new(i32 %10)
store i32* %11, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i32, i32* @ERR_R_BUF_LIB
%15 = call i32 @ASN1error(i32 %14)
store i32 0, i32* %4
br label %28
16: ; preds = %3
%17 = load i32*, i32** %8
%18 = load i32*, i32** %6
%19 = load i32, i32* @BIO_NOCLOSE
%20 = call i32 @BIO_set_fp(i32* %17, i32* %18, i32 %19)
%21 = load i32*, i32** %5
%22 = load i32*, i32** %8
%23 = load i8*, i8** %7
%24 = call i32 @ASN1_i2d_bio(i32* %21, i32* %22, i8* %23)
store i32 %24, i32* %9
%25 = load i32*, i32** %8
%26 = call i32 @BIO_free(i32* %25)
%27 = load i32, i32* %9
store i32 %27, i32* %4
br label %28
28: ; preds = %16, %13
%29 = load i32, i32* %4
ret i32 %29
}

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