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

/* 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*/ BN_print(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ CRYPTO_mem_leaks(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
void BN_printf(BIGNUM *num) {
  BIO *out = NULL;
  out = BIO_new(BIO_s_file());
  if (out == NULL)
    exit(1);
  BIO_set_fp(out, stdout, BIO_NOCLOSE);
  BN_print(out, num);
  printf("\n");
  BIO_free(out);
  CRYPTO_mem_leaks(out);
}


x86 assembly (clang, -O0):
<BN_printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <BN_printf+0x3b>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
call   1070 <BIO_set_fp@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <BN_print@plt>
lea    0xe16(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x10(%rbp),%rdi
call   1090 <CRYPTO_mem_leaks@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_printf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   10a0 <BIO_s_file@plt>
mov    %eax,%edi
call   1050 <BIO_new@plt>
test   %rax,%rax
je     11e3 <BN_printf+0x63>
mov    %rax,%rbx
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1070 <BIO_set_fp@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <BN_print@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <BIO_free@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <CRYPTO_mem_leaks@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@.str = [2 x i8] c"\0A\00"
define void @BN_printf(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
store i32* %0, i32** %2
store i32* null, i32** %3
%4 = call i32 (...) @BIO_s_file()
%5 = call i32* @BIO_new(i32 %4)
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = load i32, i32* @stdout
%13 = load i32, i32* @BIO_NOCLOSE
%14 = call i32 @BIO_set_fp(i32* %11, i32 %12, i32 %13)
%15 = load i32*, i32** %3
%16 = load i32*, i32** %2
%17 = call i32 @BN_print(i32* %15, i32* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** %3
%20 = call i32 @BIO_free(i32* %19)
%21 = load i32*, i32** %3
%22 = call i32 @CRYPTO_mem_leaks(i32* %21)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
define void @BN_printf(i32* %0) {
%2 = tail call i32 (...) @BIO_s_file()
%3 = tail call i32* @BIO_new(i32 %2)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = load i32, i32* @stdout
%9 = load i32, i32* @BIO_NOCLOSE
%10 = tail call i32 @BIO_set_fp(i32* %3, i32 %8, i32 %9)
%11 = tail call i32 @BN_print(i32* %3, i32* %0)
%12 = tail call i32 @putchar(i32 10)
%13 = tail call i32 @BIO_free(i32* %3)
%14 = tail call i32 @CRYPTO_mem_leaks(i32* %3)
ret void
}