#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 *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int i;
  FILE *fout;
  fout = fopen("output.txt", "w");
  if (!fout) {
    fprintf(stdout, "Cannot create file!\n");
    return -1;
  }
  for (i = 0; i < 100; i++) {
    fprintf(fout, " %d\n", i);
  }
  fclose(fout);
  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    0xeb3(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118c <main+0x5c>
mov    0x2e71(%rip),%rax
movslq (%rax),%rdi
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <main+0xa0>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11c0 <main+0x90>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <main+0x63>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1193 <main+0x53>
mov    %rax,%rbx
lea    0xebc(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1170 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11b8 <main+0x78>
mov    0x2e46(%rip),%rax
movslq (%rax),%rcx
lea    0xe69(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"output.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.2 = [21 x i8] c"Cannot create file!\0A\00"
@.str.3 = [5 x i8] c" %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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** %7
%9 = load i32*, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @stdout
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
16: ; preds = %2
store i32 0, i32* %6
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32*, i32** %7
%22 = load i32, i32* %6
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %17
27: ; preds = %17
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %3
br label %30
30: ; preds = %27, %11
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [11 x i8] c"output.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.2 = [21 x i8] c"Cannot create file!\0A\00"
@.str.3 = [5 x i8] c" %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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 %10
5: ; preds = %2
%6 = load i32, i32* @stdout
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 20, i64 1, i32* %8)
br label %17
10: ; preds = %2, %10
%11 = phi i32 [ %13, %10 ], [ 0, %2 ]
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, 100
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = tail call i32 @fclose(i32* %3)
br label %17
17: ; preds = %15, %5
%18 = phi i32 [ 0, %15 ], [ -1, %5 ]
ret i32 %18
}