#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;

/* Variables and functions */
int /*<<< orphan*/ BIO_CTRL_INFO;
scalar_t__ BIO_ctrl(int /*<<< orphan*/ *, int /*<<< orphan*/,
                    int /*<<< orphan*/, char *);
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int BIO_pending(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
main() {
  int i;
  BIO *mbio, *b64bio, *bio;
  char buf[512];
  char *p;
  mbio = BIO_new(BIO_s_mem());
  b64bio = BIO_new(BIO_f_base64());
  bio = BIO_push(b64bio, mbio);
  for (;;) {
    i = fread(buf, 1, 512, stdin);
    if (i <= 0)
      break;
    BIO_write(bio, buf, i);
  }
  BIO_flush(bio);
  printf("We have %d bytes available\n", BIO_pending(mbio));
  i = (int)BIO_ctrl(mbio, BIO_CTRL_INFO, 0, (char *)&p);
  printf("%d\n", i);
  fwrite("---\n", 1, 4, stdout);
  fwrite(p, 1, i, stdout);
  fwrite("---\n", 1, 4, stdout);
  BIO_free_all(bio);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10d0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <BIO_push@plt>
mov    %rax,-0x20(%rbp)
lea    -0x220(%rbp),%rdi
mov    0x2dd3(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1238 <main+0x78>
jmp    1250 <main+0x90>
mov    -0x20(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   10c0 <BIO_write@plt>
jmp    1207 <main+0x47>
mov    -0x20(%rbp),%rdi
call   10e0 <BIO_flush@plt>
mov    -0x10(%rbp),%rdi
call   1070 <BIO_pending@plt>
mov    %eax,%esi
lea    0xd95(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
lea    -0x228(%rbp),%rcx
xor    %edx,%edx
call   1090 <BIO_ctrl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd84(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%ecx
lea    0xd73(%rip),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    -0x228(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    0x2d03(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%ecx
lea    0xd37(%rip),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <BIO_free_all@plt>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x218,%rsp
xor    %eax,%eax
call   10d0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <BIO_f_base64@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <BIO_push@plt>
mov    %rax,%r15
mov    0x2de6(%rip),%r12
mov    (%r12),%ecx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
test   %eax,%eax
jle    1257 <main+0x97>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10c0 <BIO_write@plt>
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
test   %eax,%eax
jg     1230 <main+0x70>
mov    %r15,%rdi
call   10e0 <BIO_flush@plt>
mov    %r14,%rdi
call   1070 <BIO_pending@plt>
lea    0xd92(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
xor    %edx,%edx
call   1090 <BIO_ctrl@plt>
mov    %rax,%rbx
lea    0xd85(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
mov    0x2d2b(%rip),%r12
mov    (%r12),%ecx
lea    0xd70(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    0x8(%rsp),%rdi
mov    (%r12),%ecx
mov    $0x1,%esi
mov    %ebx,%edx
call   10b0 <fwrite@plt>
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    %r15,%rdi
call   10a0 <BIO_free_all@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [28 x i8] c"We have %d bytes available\0A\00"
@BIO_CTRL_INFO = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [5 x i8] c"---\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [512 x i8]
%7 = alloca i8*
store i32 0, i32* %1
%8 = call i32 (...) @BIO_s_mem()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %3
%10 = call i32 (...) @BIO_f_base64()
%11 = call i32* @BIO_new(i32 %10)
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = load i32*, i32** %3
%14 = call i32* @BIO_push(i32* %12, i32* %13)
store i32* %14, i32** %5
br label %15
15: ; preds = %22, %0
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32 @fread(i8* %16, i32 1, i32 512, i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
br label %27
22: ; preds = %15
%23 = load i32*, i32** %5
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %2
%26 = call i32 @BIO_write(i32* %23, i8* %24, i32 %25)
br label %15
27: ; preds = %21
%28 = load i32*, i32** %5
%29 = call i32 @BIO_flush(i32* %28)
%30 = load i32*, i32** %3
%31 = call i32 @BIO_pending(i32* %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %3
%34 = load i32, i32* @BIO_CTRL_INFO
%35 = bitcast i8** %7 to i8*
%36 = call i64 @BIO_ctrl(i32* %33, i32 %34, i32 0, i8* %35)
%37 = trunc i64 %36 to i32
store i32 %37, i32* %2
%38 = load i32, i32* %2
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @stdout
%41 = call i32 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 4, i32 %40)
%42 = load i8*, i8** %7
%43 = load i32, i32* %2
%44 = load i32, i32* @stdout
%45 = call i32 @fwrite(i8* %42, i32 1, i32 %43, i32 %44)
%46 = load i32, i32* @stdout
%47 = call i32 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 4, i32 %46)
%48 = load i32*, i32** %5
%49 = call i32 @BIO_free_all(i32* %48)
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [28 x i8] c"We have %d bytes available\0A\00"
@BIO_CTRL_INFO = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [5 x i8] c"---\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca [512 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
%5 = tail call i32 (...) @BIO_s_mem()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = tail call i32 (...) @BIO_f_base64()
%8 = tail call i32* @BIO_new(i32 %7)
%9 = tail call i32* @BIO_push(i32* %8, i32* %6)
%10 = load i32, i32* @stdin
%11 = call i32 @fread(i8* %3, i32 1, i32 512, i32 %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %19, label %13
13: ; preds = %0, %13
%14 = phi i32 [ %17, %13 ], [ %11, %0 ]
%15 = call i32 @BIO_write(i32* %9, i8* %3, i32 %14)
%16 = load i32, i32* @stdin
%17 = call i32 @fread(i8* %3, i32 1, i32 512, i32 %16)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %13
19: ; preds = %13, %0
%20 = call i32 @BIO_flush(i32* %9)
%21 = call i32 @BIO_pending(i32* %6)
%22 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @BIO_CTRL_INFO
%24 = call i64 @BIO_ctrl(i32* %6, i32 %23, i32 0, i8* %4)
%25 = trunc i64 %24 to i32
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @stdout
%28 = call i32 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 4, i32 %27)
%29 = load i8*, i8** %2
%30 = load i32, i32* @stdout
%31 = call i32 @fwrite(i8* %29, i32 1, i32 %25, i32 %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 4, i32 %32)
%34 = call i32 @BIO_free_all(i32* %9)
ret i32 0
}