#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ filesize(int);
int open(char *);
int main() {
  int handle = 2;
  int i = 0;
  handle = open("sample.txt");
  if (handle < 2)
    return -1;
  for (i = 0; i < 5000000; i++) {
    filesize(handle);
  }
  close(handle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeac(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1172 <main+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <main+0x7b>
movl   $0x0,-0xc(%rbp)
cmpl   $0x4c4b40,-0xc(%rbp)
jge    119c <main+0x6c>
mov    -0x8(%rbp),%edi
call   1050 <filesize@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <main+0x49>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%ebx
mov    $0xffffffff,%eax
cmp    $0x2,%ebx
jl     1165 <main+0x35>
mov    $0x4c4b40,%ebp
mov    %ebx,%edi
call   1050 <filesize@plt>
add    $0xffffffff,%ebp
jne    1150 <main+0x20>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"sample.txt\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %2
store i32 0, i32* %3
%4 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %21
8: ; preds = %0
store i32 0, i32* %3
br label %9
9: ; preds = %15, %8
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 5000000
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32, i32* %2
%14 = call i32 @filesize(i32 %13)
br label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %9
18: ; preds = %9
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
store i32 0, i32* %1
br label %21
21: ; preds = %18, %7
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [11 x i8] c"sample.txt\00"
define i32 @main() {
%1 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp slt i32 %1, 2
br i1 %2, label %10, label %3
3: ; preds = %0, %3
%4 = phi i32 [ %6, %3 ], [ 0, %0 ]
%5 = tail call i32 @filesize(i32 %1)
%6 = add nuw nsw i32 %4, 1
%7 = icmp eq i32 %6, 5000000
br i1 %7, label %8, label %3
8: ; preds = %3
%9 = tail call i32 @close(i32 %1)
br label %10
10: ; preds = %0, %8
%11 = phi i32 [ 0, %8 ], [ -1, %0 ]
ret i32 %11
}