#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fwrite(void *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ makeDirectory(char *);
int /*<<< orphan*/ stderr;
void writeFile(char *filename, void *data, long bytes) {
  FILE *out;
  int i;
  for (i = 0; filename[i]; i++) {
    if (filename[i] != '/')
      continue;
    filename[i] = '\0';
    if (!makeDirectory(filename)) {
      fprintf(stderr, "Couldn't create subdirectory %s!\n", filename);
      return;
    }
    filename[i] = '/';
  }
  if (!i || filename[i - 1] == '/')
    return;
  out = fopen(filename, "wb");
  if (out != NULL) {
    fwrite(data, 1, bytes, out);
    fclose(out);
  } else {
    fprintf(stderr, "Couldn't open %s for writing!\n", filename);
  }
}


x86 assembly (clang, -O0):
<writeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11ed <writeFile+0x9d>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1197 <writeFile+0x47>
jmp    11df <writeFile+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1070 <makeDirectory@plt>
cmp    $0x0,%eax
jne    11d3 <writeFile+0x83>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe37(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1272 <writeFile+0x122>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <writeFile+0x1b>
cmpl   $0x0,-0x24(%rbp)
je     1211 <writeFile+0xc1>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1216 <writeFile+0xc6>
jmp    1272 <writeFile+0x122>
mov    -0x8(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1259 <writeFile+0x109>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1272 <writeFile+0x122>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdb8(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
movabs $0xffffffff00000000,%r12
ff ff ff
xor    %ebx,%ebx
movabs $0x100000000,%rbp
jmp    118b <writeFile+0x3b>
nopl   0x0(%rax)
test   %al,%al
je     11af <writeFile+0x5f>
add    $0x1,%rbx
add    %rbp,%r12
movzbl 0x0(%r13,%rbx,1),%eax
cmp    $0x2f,%al
jne    1180 <writeFile+0x30>
movb   $0x0,0x0(%r13,%rbx,1)
mov    %r13,%rdi
call   1070 <makeDirectory@plt>
test   %eax,%eax
je     11ce <writeFile+0x7e>
movb   $0x2f,0x0(%r13,%rbx,1)
jmp    1184 <writeFile+0x34>
test   %ebx,%ebx
je     11bf <writeFile+0x6f>
sar    $0x20,%r12
cmpb   $0x2f,0x0(%r13,%r12,1)
jne    11f4 <writeFile+0xa4>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
mov    %r13,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>
lea    0xe27(%rip),%rsi
mov    %r13,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1234 <writeFile+0xe4>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
jmp    11de <writeFile+0x8e>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Couldn't create subdirectory %s!\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [31 x i8] c"Couldn't open %s for writing!\0A\00"
define void @writeFile(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %8
br label %9
9: ; preds = %42, %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %8
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %45
16: ; preds = %9
%17 = load i8*, i8** %4
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 47
br i1 %23, label %24, label %25
24: ; preds = %16
br label %42
25: ; preds = %16
%26 = load i8*, i8** %4
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %4
%31 = call i32 @makeDirectory(i8* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %25
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %4
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %35)
br label %74
37: ; preds = %25
%38 = load i8*, i8** %4
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 47, i8* %41
br label %42
42: ; preds = %37, %24
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %9
45: ; preds = %9
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %45
%49 = load i8*, i8** %4
%50 = load i32, i32* %8
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 47
br i1 %56, label %57, label %58
57: ; preds = %48, %45
br label %74
58: ; preds = %48
%59 = load i8*, i8** %4
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %60, i32** %7
%61 = load i32*, i32** %7
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %70
63: ; preds = %58
%64 = load i8*, i8** %5
%65 = load i64, i64* %6
%66 = load i32*, i32** %7
%67 = call i32 @fwrite(i8* %64, i32 1, i64 %65, i32* %66)
%68 = load i32*, i32** %7
%69 = call i32 @fclose(i32* %68)
br label %74
70: ; preds = %58
%71 = load i32, i32* @stderr
%72 = load i8*, i8** %4
%73 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %33, %57, %70, %63
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Couldn't create subdirectory %s!\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [31 x i8] c"Couldn't open %s for writing!\0A\00"
define void @writeFile(i8* %0, i8* nocapture %1, i64 %2) {
br label %4
4: ; preds = %15, %3
%5 = phi i64 [ %16, %15 ], [ 0, %3 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %15 [
i8 0, label %17
i8 47, label %8
]
8: ; preds = %4
store i8 0, i8* %6
%9 = tail call i32 @makeDirectory(i8* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %36
14: ; preds = %8
store i8 47, i8* %6
br label %15
15: ; preds = %4, %14
%16 = add nuw i64 %5, 1
br label %4
17: ; preds = %4
%18 = trunc i64 %5 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %36, label %20
20: ; preds = %17
%21 = shl i64 %5, 32
%22 = add i64 %21, -4294967296
%23 = ashr exact i64 %22, 32
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 47
br i1 %26, label %36, label %27
27: ; preds = %20
%28 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = tail call i32 @fwrite(i8* %1, i32 1, i64 %2, i32* %28)
%32 = tail call i32 @fclose(i32* %28)
br label %36
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %36
36: ; preds = %30, %33, %17, %20, %11
ret void
}