#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  FILE *f = fopen("a", "w");
  if (f == NULL) {
    printf("Error opening file!\n");
    exit(1);
  }
  const char *text = "Write this to the file";
  fprintf(f, "%s,%s,%s\n", "Bytes", "Random test", "All appends");
  fprintf(f, "%d,%d,%d\n", 1, 23, 121);
  fprintf(f, "%d,%d,%d\n", 2, 213, 234);
  fprintf(f, "%d,%d,%d\n", 3, 124, 176);
  fprintf(f, "%d,%d,%d\n", 4, 43, 37);
  fprintf(f, "%d,%d,%d\n", 5, 12, 5);
  fprintf(f, "%d,%d,%d\n", 6, 3, 2);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119e <main+0x4e>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe74(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7c(%rip),%rsi
lea    0xe7f(%rip),%rdx
lea    0xe7e(%rip),%rcx
lea    0xe83(%rip),%r8
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x1,%edx
mov    $0x17,%ecx
mov    $0x79,%r8d
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x2,%edx
mov    $0xd5,%ecx
mov    $0xea,%r8d
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
mov    $0x3,%edx
mov    $0x7c,%ecx
mov    $0xb0,%r8d
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0x4,%edx
mov    $0x2b,%ecx
mov    $0x25,%r8d
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf5(%rip),%rsi
mov    $0x5,%r8d
mov    $0xc,%ecx
mov    %r8d,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdd5(%rip),%rsi
mov    $0x6,%edx
mov    $0x3,%ecx
mov    $0x2,%r8d
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1260 <main+0x110>
mov    %rax,%rbx
lea    0xe8a(%rip),%rsi
lea    0xe8d(%rip),%rdx
lea    0xe8c(%rip),%rcx
lea    0xe91(%rip),%r8
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe8c(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0x17,%ecx
mov    $0x79,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
mov    $0xd5,%ecx
mov    $0xea,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
mov    $0x7c,%ecx
mov    $0xb0,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
mov    $0x2b,%ecx
mov    $0x25,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
mov    $0xc,%ecx
mov    $0x5,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
mov    $0x3,%ecx
mov    $0x2,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdcf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"Error opening file!\0A\00"
@.str.3 = [23 x i8] c"Write this to the file\00"
@.str.4 = [10 x i8] c"%s,%s,%s\0A\00"
@.str.5 = [6 x i8] c"Bytes\00"
@.str.6 = [12 x i8] c"Random test\00"
@.str.7 = [12 x i8] c"All appends\00"
@.str.8 = [10 x i8] c"%d,%d,%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8** %7
%15 = load i32*, i32** %6
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%17 = load i32*, i32** %6
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 1, i32 23, i32 121)
%19 = load i32*, i32** %6
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 2, i32 213, i32 234)
%21 = load i32*, i32** %6
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 3, i32 124, i32 176)
%23 = load i32*, i32** %6
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 4, i32 43, i32 37)
%25 = load i32*, i32** %6
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 5, i32 12, i32 5)
%27 = load i32*, i32** %6
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 6, i32 3, i32 2)
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"w\00"
@.str.4 = [10 x i8] c"%s,%s,%s\0A\00"
@.str.5 = [6 x i8] c"Bytes\00"
@.str.6 = [12 x i8] c"Random test\00"
@.str.7 = [12 x i8] c"All appends\00"
@.str.8 = [10 x i8] c"%d,%d,%d\0A\00"
@str = [20 x i8] c"Error opening file!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 1, i32 23, i32 121)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 2, i32 213, i32 234)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 3, i32 124, i32 176)
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 4, i32 43, i32 37)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 5, i32 12, i32 5)
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 6, i32 3, i32 2)
%16 = tail call i32 @fclose(i32* %3)
ret i32 0
}