#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*/ int8_t;
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 /*<<< orphan*/ *, size_t, size_t,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int file_write_b(char *o_file_name, int8_t *buffer, size_t size, size_t count) {
  FILE *o_file = NULL;
  o_file = fopen(o_file_name, "wb+");
  if (o_file == NULL) {
    fputs("File error", stderr);
    exit(4);
  }
  fwrite(buffer, size, count, o_file);
  fclose(o_file);
  return 0;
}


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

x86 assembly (clang, -O2):
<file_write_b>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
lea    0xe98(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119c <file_write_b+0x4c>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%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, i64 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store i32* null, i32** %9
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @exit(i32 4)
unreachable
18: ; preds = %4
%19 = load i32*, i32** %6
%20 = load i64, i64* %7
%21 = load i64, i64* %8
%22 = load i32*, i32** %9
%23 = call i32 @fwrite(i32* %19, i64 %20, i64 %21, i32* %22)
%24 = load i32*, i32** %9
%25 = call i32 @fclose(i32* %24)
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, i64 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 @exit(i32 4)
unreachable
11: ; preds = %4
%12 = tail call i32 @fwrite(i32* %1, i64 %2, i64 %3, i32* %5)
%13 = tail call i32 @fclose(i32* %5)
ret i32 0
}