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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int file_write_b(char *o_file_name, int *buffer, size_t size) {
  FILE *o_file = NULL;
  o_file = fopen(o_file_name, "wb+");
  if (o_file == NULL) {
    fputs("File error", stderr);
    exit(4);
  }
  fwrite(buffer, sizeof(int), size, o_file);
  fclose(o_file);
  return 0;
}


x86 assembly (clang, -O0):
<file_write_b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11aa <file_write_b+0x5a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x4,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_write_b>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1192 <file_write_b+0x42>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x4,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x4,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"wb+\00"
@.str.1 = [11 x i8] c"File error\00"
@stderr = global i32 0
define i32 @file_write_b(i8* %0, i32* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
store i32* null, i32** %7
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 4)
unreachable
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = load i64, i64* %6
%19 = load i32*, i32** %7
%20 = call i32 @fwrite(i32* %17, i32 4, i64 %18, i32* %19)
%21 = load i32*, i32** %7
%22 = call i32 @fclose(i32* %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"wb+\00"
@.str.1 = [11 x i8] c"File error\00"
@stderr = global i32 0
define i32 @file_write_b(i8* nocapture %0, i32* nocapture %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @exit(i32 4)
unreachable
10: ; preds = %3
%11 = tail call i32 @fwrite(i32* %1, i32 4, i64 %2, i32* %4)
%12 = tail call i32 @fclose(i32* %4)
ret i32 0
}