#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fwrite(void const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ make_path(char const *);
int /*<<< orphan*/ stderr;
bool write_file(const char *name, const void *data, int len_bytes) {
  make_path(name);
  FILE *out_file = fopen(name, "wb");
  if (out_file == NULL) {
    fprintf(stderr, "Can't fopen() the file! %s\n", name);
    return false;
  }
  fwrite(data, 1, len_bytes, out_file);
  fclose(out_file);
  return true;
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <make_path@plt>
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b0 <write_file+0x60>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <write_file+0x85>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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,%rbx
call   1050 <make_path@plt>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     119e <write_file+0x4e>
mov    %rax,%rbp
mov    $0x1,%ebx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    11b8 <write_file+0x68>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Can't fopen() the file! %s\0A\00"
define i32 @write_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @make_path(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 0, i32* %4
br label %26
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = load i32*, i32** %8
%23 = call i32 @fwrite(i8* %20, i32 1, i32 %21, i32* %22)
%24 = load i32*, i32** %8
%25 = call i32 @fclose(i32* %24)
store i32 1, i32* %4
br label %26
26: ; preds = %19, %15
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"Can't fopen() the file! %s\0A\00"
define i32 @write_file(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @make_path(i8* %0)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
10: ; preds = %3
%11 = tail call i32 @fwrite(i8* %1, i32 1, i32 %2, i32* %5)
%12 = tail call i32 @fclose(i32* %5)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ 0, %7 ], [ 1, %10 ]
ret i32 %14
}