#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*/ fputs(char *, int /*<<< orphan*/ *);
int main(void) {
  FILE *file_local = fopen("local.asc", "w");
  FILE *file_level_uno = fopen("./level_uno/level_uno.asc", "w");
  FILE *file_level_dos = fopen("./level_uno/level_dos/level_dos.asc", "w");
  FILE *file_level_tres = fopen(
      "/Users/deaddork/Programming/projects/DeadDork/learning_c/experiments/"
      "fopen_uno/level_uno/level_dos/level_tres/level_tres.asc",
      "w");
  fputs("Printing to a local file\n", file_local);
  fputs("Printing to a file one directory down from local\n", file_level_uno);
  fputs("Printing to a file two directories down from local\n", file_level_dos);
  fputs("Printering to a file using an absolute address\n", file_level_tres);
  fclose(file_local);
  fclose(file_level_uno);
  fclose(file_level_dos);
  fclose(file_level_tres);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xeaf(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xeb2(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xebf(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xf21(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rsi
lea    0xf2b(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x20(%rbp),%rsi
lea    0xf4d(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x28(%rbp),%rsi
lea    0xf71(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
lea    0xec4(%rip),%rbx
mov    %rbx,%rsi
call   1040 <fopen@plt>
mov    %rax,%r14
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fopen@plt>
mov    %rax,%r15
lea    0xebc(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fopen@plt>
mov    %rax,%r12
lea    0xece(%rip),%rdi
mov    %rbx,%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
lea    0xf39(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
lea    0xf3a(%rip),%rdi
mov    $0x31,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fwrite@plt>
lea    0xf53(%rip),%rdi
mov    $0x33,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1050 <fwrite@plt>
lea    0xf6e(%rip),%rdi
mov    $0x2f,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"local.asc\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"./level_uno/level_uno.asc\00"
@.str.3 = [36 x i8] c"./level_uno/level_dos/level_dos.asc\00"
@.str.4 = [125 x i8] c"/Users/deaddork/Programming/projects/DeadDork/learning_c/experiments/fopen_uno/level_uno/level_dos/level_tres/level_tres.asc\00"
@.str.5 = [26 x i8] c"Printing to a local file\0A\00"
@.str.6 = [50 x i8] c"Printing to a file one directory down from local\0A\00"
@.str.7 = [52 x i8] c"Printing to a file two directories down from local\0A\00"
@.str.8 = [48 x i8] c"Printering to a file using an absolute address\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %4
%9 = call i32* @fopen(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %2
%11 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32* %10)
%12 = load i32*, i32** %3
%13 = call i32 @fputs(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i32* %12)
%14 = load i32*, i32** %4
%15 = call i32 @fputs(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i32* %14)
%16 = load i32*, i32** %5
%17 = call i32 @fputs(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0), i32* %16)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"local.asc\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"./level_uno/level_uno.asc\00"
@.str.3 = [36 x i8] c"./level_uno/level_dos/level_dos.asc\00"
@.str.4 = [125 x i8] c"/Users/deaddork/Programming/projects/DeadDork/learning_c/experiments/fopen_uno/level_uno/level_dos/level_tres/level_tres.asc\00"
@.str.5 = [26 x i8] c"Printing to a local file\0A\00"
@.str.6 = [50 x i8] c"Printing to a file one directory down from local\0A\00"
@.str.7 = [52 x i8] c"Printing to a file two directories down from local\0A\00"
@.str.8 = [48 x i8] c"Printering to a file using an absolute address\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i64 25, i64 1, i32* %1)
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i64 49, i64 1, i32* %2)
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i64 51, i64 1, i32* %3)
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0), i64 47, i64 1, i32* %4)
%9 = tail call i32 @fclose(i32* %1)
%10 = tail call i32 @fclose(i32* %2)
%11 = tail call i32 @fclose(i32* %3)
%12 = tail call i32 @fclose(i32* %4)
ret i32 0
}