#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ binary_exponential_buffer_data(struct binary_exponential_buffer *);
unsigned int binary_exponential_buffer_size(struct binary_exponential_buffer *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned char *);
int output_binary_exponential_buffer_to_file(
    struct binary_exponential_buffer *buffer, unsigned char *out_file) {
  FILE *f = NULL;
  unsigned char *data = (unsigned char *)binary_exponential_buffer_data(buffer);
  unsigned int size = binary_exponential_buffer_size(buffer);
  unsigned int i;
  if (!(f = fopen((char *)out_file, "w"))) {
    printf("Failed to open file %s for write.\n", out_file);
    assert(0);
    return 1;
  }
  for (i = 0; i < size; i++) {
    fputc(data[i], f);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<output_binary_exponential_buffer_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <binary_exponential_buffer_data@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <binary_exponential_buffer_size@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e2 <output_binary_exponential_buffer_to_file+0x72>
mov    -0x18(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <assert@plt>
movl   $0x1,-0x4(%rbp)
jmp    1229 <output_binary_exponential_buffer_to_file+0xb9>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    1219 <output_binary_exponential_buffer_to_file+0xa9>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e9 <output_binary_exponential_buffer_to_file+0x79>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_binary_exponential_buffer_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1090 <binary_exponential_buffer_data@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <binary_exponential_buffer_size@plt>
mov    %eax,%ebp
lea    0xe69(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d2 <output_binary_exponential_buffer_to_file+0x62>
mov    %rax,%r12
test   %ebp,%ebp
je     11c6 <output_binary_exponential_buffer_to_file+0x56>
mov    %ebp,%ebp
xor    %ebx,%ebx
nop
movzbl (%r14,%rbx,1),%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <output_binary_exponential_buffer_to_file+0x40>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11ed <output_binary_exponential_buffer_to_file+0x7d>
lea    0xe29(%rip),%rdi
mov    %r15,%rsi
call   1040 <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 = [2 x i8] c"w\00"
@.str.1 = [35 x i8] c"Failed to open file %s for write.\0A\00"
define i32 @output_binary_exponential_buffer_to_file(%struct.binary_exponential_buffer* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.binary_exponential_buffer*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store %struct.binary_exponential_buffer* %0, %struct.binary_exponential_buffer** %4
store i8* %1, i8** %5
store i32* null, i32** %6
%10 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%11 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%14 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %13)
store i32 %14, i32* %8
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @assert(i32 0)
store i32 1, i32* %3
br label %41
22: ; preds = %2
store i32 0, i32* %9
br label %23
23: ; preds = %35, %22
%24 = load i32, i32* %9
%25 = load i32, i32* %8
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = load i32, i32* %9
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = load i32*, i32** %6
%34 = call i32 @fputc(i8 zeroext %32, i32* %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %9
%37 = add i32 %36, 1
store i32 %37, i32* %9
br label %23
38: ; preds = %23
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %18
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.binary_exponential_buffer = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [35 x i8] c"Failed to open file %s for write.\0A\00"
define i32 @output_binary_exponential_buffer_to_file(%struct.binary_exponential_buffer* %0, i8* %1) {
%3 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %0)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %0)
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = icmp eq i32 %5, 0
br i1 %9, label %22, label %10
10: ; preds = %8
%11 = zext i32 %5 to i64
br label %15
12: ; preds = %2
%13 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%14 = tail call i32 @assert(i32 0)
br label %24
15: ; preds = %10, %15
%16 = phi i64 [ 0, %10 ], [ %20, %15 ]
%17 = getelementptr inbounds i8, i8* %4, i64 %16
%18 = load i8, i8* %17
%19 = tail call i32 @fputc(i8 zeroext %18, i32* %6)
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, %11
br i1 %21, label %22, label %15
22: ; preds = %15, %8
%23 = tail call i32 @fclose(i32* %6)
br label %24
24: ; preds = %22, %12
%25 = phi i32 [ 0, %22 ], [ 1, %12 ]
ret i32 %25
}