#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 main() {
  FILE *fp;
  int i;
  fp = fopen("foo.dat", "w");
  fprintf(fp, "\nSample Code\n\n");
  for (i = 1; i <= 10; i++)
    fprintf(fp, "i = %d\n", i);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jg     119c <main+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <main+0x3f>
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    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xea9(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
lea    0xe9f(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
xor    %eax,%eax
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 = [8 x i8] c"foo.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"\0ASample Code\0A\0A\00"
@.str.3 = [8 x i8] c"i = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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
%5 = load i32*, i32** %2
%6 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 10
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %3
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %7
17: ; preds = %7
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foo.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [15 x i8] c"\0ASample Code\0A\0A\00"
@.str.3 = [8 x i8] c"i = %d\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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 i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 14, i64 1, i32* %1)
%3 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1)
%4 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 2)
%5 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 3)
%6 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 4)
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 5)
%8 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 6)
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 8)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 9)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 10)
%13 = tail call i32 @fclose(i32* %1)
ret i32 0
}