#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 S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ chmod(char const *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, unsigned int,
                          int /*<<< orphan*/ *);
void write_file(const char *out_file, unsigned char *byte_buffer,
                unsigned int buf_size) {
  FILE *file;
  file = fopen(out_file, "w");
  fwrite(byte_buffer, 1, buf_size, file);
  fclose(file);
  chmod(out_file, S_IRWXU | S_IRWXG | S_IRWXO);
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e3f(%rip),%rax
or     (%rax),%esi
mov    0x2e4e(%rip),%rax
or     (%rax),%esi
call   1040 <chmod@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e5f(%rip),%rax
mov    0x2e50(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e5d(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <chmod@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
define void @write_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = load i32*, i32** %7
%13 = call i32 @fwrite(i8* %10, i32 1, i32 %11, i32* %12)
%14 = load i32*, i32** %7
%15 = call i32 @fclose(i32* %14)
%16 = load i8*, i8** %4
%17 = load i32, i32* @S_IRWXU
%18 = load i32, i32* @S_IRWXG
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IRWXO
%21 = or i32 %19, %20
%22 = call i32 @chmod(i8* %16, i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
define void @write_file(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @fwrite(i8* %1, i32 1, i32 %2, i32* %4)
%6 = tail call i32 @fclose(i32* %4)
%7 = load i32, i32* @S_IRWXU
%8 = load i32, i32* @S_IRWXG
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRWXO
%11 = or i32 %9, %10
%12 = tail call i32 @chmod(i8* %0, i32 %11)
ret void
}