#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*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int main() {
  char *filename = "numbers.txt";
  FILE *fp = fopen(filename, "w");
  int a = 1;
  if (fp) {
    while (a <= 10) {
      fprintf(fp, "%d", a);
      a++;
    }
    fclose(fp);
  } else {
    printf("Opening %s failed\n", filename);
  }
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ce <main+0x7e>
jmp    1195 <main+0x45>
cmpl   $0xa,-0x1c(%rbp)
jg     11c0 <main+0x70>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe61(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1195 <main+0x45>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11de <main+0x8e>
mov    -0x10(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
lea    0xe3e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1224 <main+0xd4>
mov    %rax,%rbx
lea    0xe94(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x9,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1237 <main+0xe7>
lea    0xde6(%rip),%rdi
lea    0xdce(%rip),%rsi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"numbers.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
@.str.4 = [1 x i8] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
store i32 1, i32* %4
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %22
9: ; preds = %0
br label %10
10: ; preds = %13, %9
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 10
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = load i32, i32* %4
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %10
19: ; preds = %10
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
br label %25
22: ; preds = %0
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %19
%26 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"numbers.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"Opening %s failed\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %15, label %3
3: ; preds = %0
%4 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 1)
%5 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%6 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%7 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 4)
%8 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 5)
%9 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 6)
%10 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 7)
%11 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 8)
%12 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 9)
%13 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 10)
%14 = tail call i32 @fclose(i32* %1)
br label %17
15: ; preds = %0
%16 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %3
%18 = tail call i32 @putchar(i32 10)
ret i32 0
}