#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);
int main() {
  FILE *p = fopen("D:\\temp\\a.txt", "w");
  int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int i;
  for (i = 0; i < 10; i++) {
    fprintf(p, "array[%d] = %d\n", i, array[i]);
  }
  fclose(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0xa,-0x44(%rbp)
jge    11b5 <main+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x44(%rbp),%edx
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%ecx
lea    0xe6e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1182 <main+0x42>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xebf(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
mov    $0x3,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
mov    $0x4,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
mov    $0x5,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
mov    $0x6,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
mov    $0x7,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
mov    $0x8,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
mov    $0x9,%ecx
call   1040 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
mov    $0xa,%ecx
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 = [14 x i8] c"D:\\temp\\a.txt\00"
@.str.1 = [2 x i8] c"w\00"
@__const.main.array = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@.str.2 = [16 x i8] c"array[%d] = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [10 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = bitcast [10 x i32]* %3 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %4
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %16)
br label %18
18: ; preds = %10
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %7
21: ; preds = %7
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
ret i32 0
}

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