#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 */
struct binary_exponential_buffer {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ binary_exponential_buffer_data(struct binary_exponential_buffer *);
int /*<<< orphan*/
binary_exponential_buffer_increment(struct binary_exponential_buffer *, int);
int binary_exponential_buffer_size(struct binary_exponential_buffer *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned char *);
int add_file_to_binary_exponential_buffer(
    struct binary_exponential_buffer *buffer, unsigned char *in_file) {
  FILE *f = NULL;
  int c = 0;
  if (!(f = fopen((char *)in_file, "rb"))) {
    printf("Failed to open file %s for read.\n", in_file);
    assert(0);
    return 1;
  }
  while (c != EOF) {
    c = getc(f);
    if (c == EOF)
      break;
    binary_exponential_buffer_increment(buffer, 1);
    ((unsigned char *)binary_exponential_buffer_data(
        buffer))[binary_exponential_buffer_size(buffer) - 1] = (unsigned char)c;
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<add_file_to_binary_exponential_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e0 <add_file_to_binary_exponential_buffer+0x60>
mov    -0x18(%rbp),%rsi
lea    0xe3b(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <assert@plt>
movl   $0x1,-0x4(%rbp)
jmp    126b <add_file_to_binary_exponential_buffer+0xeb>
jmp    11e5 <add_file_to_binary_exponential_buffer+0x65>
mov    -0x24(%rbp),%eax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%eax
je     125b <add_file_to_binary_exponential_buffer+0xdb>
mov    -0x20(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%eax
jne    121a <add_file_to_binary_exponential_buffer+0x9a>
jmp    125b <add_file_to_binary_exponential_buffer+0xdb>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    -0x24(%rbp),%eax
mov    %al,-0x31(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <binary_exponential_buffer_data@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <binary_exponential_buffer_size@plt>
mov    -0x31(%rbp),%dl
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11e5 <add_file_to_binary_exponential_buffer+0x65>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_file_to_binary_exponential_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xe6b(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1209 <add_file_to_binary_exponential_buffer+0x89>
mov    %rax,%r14
mov    0x2e3c(%rip),%r12
cmpl   $0x0,(%r12)
je     11fd <add_file_to_binary_exponential_buffer+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   10a0 <getc@plt>
cmp    (%r12),%eax
je     11fd <add_file_to_binary_exponential_buffer+0x7d>
mov    %eax,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    %r15,%rdi
call   1090 <binary_exponential_buffer_data@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <binary_exponential_buffer_size@plt>
cltq
mov    %bpl,-0x1(%rax,%rbx,1)
cmp    (%r12),%ebp
jne    11c0 <add_file_to_binary_exponential_buffer+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1224 <add_file_to_binary_exponential_buffer+0xa4>
lea    0xdf3(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <assert@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.binary_exponential_buffer = type { i32 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [34 x i8] c"Failed to open file %s for read.\0A\00"
@EOF = global i32 0
define i32 @add_file_to_binary_exponential_buffer(%struct.binary_exponential_buffer* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.binary_exponential_buffer*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store %struct.binary_exponential_buffer* %0, %struct.binary_exponential_buffer** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @assert(i32 0)
store i32 1, i32* %3
br label %43
15: ; preds = %2
br label %16
16: ; preds = %27, %15
%17 = load i32, i32* %7
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = call i32 @getc(i32* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
br label %40
27: ; preds = %20
%28 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%29 = call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %28, i32 1)
%30 = load i32, i32* %7
%31 = trunc i32 %30 to i8
%32 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%33 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %32)
%34 = inttoptr i64 %33 to i8*
%35 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%36 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %35)
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %34, i64 %38
store i8 %31, i8* %39
br label %16
40: ; preds = %26, %16
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.binary_exponential_buffer = type { i32 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [34 x i8] c"Failed to open file %s for read.\0A\00"
@EOF = global i32 0
define i32 @add_file_to_binary_exponential_buffer(%struct.binary_exponential_buffer* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %6, 0
br i1 %7, label %26, label %11
8: ; preds = %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = tail call i32 @assert(i32 0)
br label %28
11: ; preds = %5, %15
%12 = tail call i32 @getc(i32* %3)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %26, label %15
15: ; preds = %11
%16 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %0, i32 1)
%17 = trunc i32 %12 to i8
%18 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %0)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %0)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 %17, i8* %23
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %12, %24
br i1 %25, label %26, label %11
26: ; preds = %15, %11, %5
%27 = tail call i32 @fclose(i32* %3)
br label %28
28: ; preds = %26, %8
%29 = phi i32 [ 0, %26 ], [ 1, %8 ]
ret i32 %29
}