#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);
int /*<<< orphan*/ sleep(int);
int main() {
  FILE *fp = NULL;
  int i = 0;
  fp = fopen("/tmp/file", "w");
  for (i = 0; i < 10; i++) {
    sleep(1);
    fprintf(fp, "%d\n", i);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11b1 <main+0x71>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117c <main+0x3c>
mov    -0x10(%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    0xeb5(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xea1(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/tmp/file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
store i32 0, i32* %3
%4 = 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* %4, i32** %2
store i32 0, i32* %3
br label %5
5: ; preds = %13, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = call i32 @sleep(i32 1)
%10 = load i32*, i32** %2
%11 = load i32, i32* %3
%12 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %8
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %5
16: ; preds = %5
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/tmp/file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\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 @sleep(i32 1)
%3 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%4 = tail call i32 @sleep(i32 1)
%5 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 1)
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 2)
%8 = tail call i32 @sleep(i32 1)
%9 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4)
%12 = tail call i32 @sleep(i32 1)
%13 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 5)
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 6)
%16 = tail call i32 @sleep(i32 1)
%17 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 7)
%18 = tail call i32 @sleep(i32 1)
%19 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 8)
%20 = tail call i32 @sleep(i32 1)
%21 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 9)
%22 = tail call i32 @fclose(i32* %1)
ret i32 0
}