#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;
typedef int /*<<< orphan*/ ASN1_ITEM;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_ITEM_I2D_FP;
int ASN1_item_i2d_bio(int /*<<< orphan*/ const *, int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, 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_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) {
  BIO *b;
  int ret;
  if ((b = BIO_new(BIO_s_file())) == NULL) {
    ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);
    return (0);
  }
  BIO_set_fp(b, out, BIO_NOCLOSE);
  ret = ASN1_item_i2d_bio(it, b, x);
  BIO_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<ASN1_item_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   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b3 <ASN1_item_i2d_fp+0x53>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ec <ASN1_item_i2d_fp+0x8c>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
call   1070 <BIO_set_fp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <ASN1_item_i2d_bio@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <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_item_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   1080 <BIO_s_file@plt>
mov    %eax,%edi
call   1040 <BIO_new@plt>
test   %rax,%rax
je     11b7 <ASN1_item_i2d_fp+0x57>
mov    %rax,%rbx
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <BIO_set_fp@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <ASN1_item_i2d_bio@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <BIO_free@plt>
mov    %ebp,%eax
jmp    11d0 <ASN1_item_i2d_fp+0x70>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ASN1_F_ASN1_ITEM_I2D_FP = global i32 0
@ERR_R_BUF_LIB = global i32 0
@BIO_NOCLOSE = global i32 0
define i32 @ASN1_item_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 %17
13: ; preds = %3
%14 = load i32, i32* @ASN1_F_ASN1_ITEM_I2D_FP
%15 = load i32, i32* @ERR_R_BUF_LIB
%16 = call i32 @ASN1err(i32 %14, i32 %15)
store i32 0, i32* %4
br label %29
17: ; preds = %3
%18 = load i32*, i32** %8
%19 = load i32*, i32** %6
%20 = load i32, i32* @BIO_NOCLOSE
%21 = call i32 @BIO_set_fp(i32* %18, i32* %19, i32 %20)
%22 = load i32*, i32** %5
%23 = load i32*, i32** %8
%24 = load i8*, i8** %7
%25 = call i32 @ASN1_item_i2d_bio(i32* %22, i32* %23, i8* %24)
store i32 %25, i32* %9
%26 = load i32*, i32** %8
%27 = call i32 @BIO_free(i32* %26)
%28 = load i32, i32* %9
store i32 %28, i32* %4
br label %29
29: ; preds = %17, %13
%30 = load i32, i32* %4
ret i32 %30
}

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