#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;
  int sum = 0;
  int add = 0;
  FILE *fout;
  fout = fopen("output.txt", "w");
  if (!fout) {
    fprintf(stdout, "Cannot create file!\n");
    return -1;
  }
  for (i = 0; i < 100; i++) {
    if (i > 0 && i % 2 == 0) {
      sum += i;
      add++;
    }
    fclose(fout);
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xea5(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <main+0x67>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <main+0xb8>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11e8 <main+0xb8>
cmpl   $0x0,-0x14(%rbp)
jle    11d8 <main+0xa8>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d8 <main+0xa8>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1155 <main+0x25>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%10 = 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* %10, i32** %9
%11 = load i32*, i32** %9
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = call i32 @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 %39
16: ; preds = %2
store i32 0, i32* %6
br label %17
17: ; preds = %36, %16
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %39
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* %6
%25 = srem i32 %24, 2
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = add nsw i32 %29, %28
store i32 %30, i32* %7
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %33
33: ; preds = %27, %23, %20
%34 = load i32*, i32** %9
%35 = call i32 @fclose(i32* %34)
store i32 0, i32* %3
br label %39
36: ; No predecessors!
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %17
39: ; preds = %13, %33, %17
%40 = load i32, i32* %3
ret i32 %40
}

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"
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 %8
5: ; preds = %2
%6 = load i32, i32* @stdout
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %8, %5
%11 = phi i32 [ 0, %8 ], [ -1, %5 ]
ret i32 %11
}