#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
long long fib(long);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ snprintf(char *, int, char *, long);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncat(char *, char *, int);
int main() {
  long long fibonacci = 1, temp = 0;
  long n = 1;
  while (fibonacci > 0) {
    temp = fibonacci;
    fibonacci = fib(n);
    n++;
  }
  fibonacci = temp;
  printf("%lld\n", fibonacci);
  char fileName[7];
  snprintf(fileName, 3, "%ld", n);
  strncat(fileName, ".txt", 4);
  FILE *fp = fopen(fileName, "w");
  if (!fp) {
    fprintf(stderr, "Could not create file!");
    exit(0);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    11d8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <fib@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a7 <main+0x27>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
lea    -0x27(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x3,%esi
lea    0xe02(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x27(%rbp),%rdi
lea    0xdf6(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncat@plt>
lea    -0x27(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1259 <main+0xd9>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
mov    $0x1,%ebx
xchg   %ax,%ax
mov    %rax,%r14
mov    %rbx,%rdi
call   1080 <fib@plt>
add    $0x1,%rbx
test   %rax,%rax
jg     1190 <main+0x10>
lea    0xe55(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe4c(%rip),%rdx
lea    0x1(%rsp),%r14
mov    %r14,%rdi
mov    $0x3,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
lea    0xe34(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1060 <strncat@plt>
lea    0xe25(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1209 <main+0x89>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%lld\0A\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [5 x i8] c".txt\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [23 x i8] c"Could not create file!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca [7 x i8]
%6 = alloca i32*
store i32 0, i32* %1
store i64 1, i64* %2
store i64 0, i64* %3
store i64 1, i64* %4
br label %7
7: ; preds = %10, %0
%8 = load i64, i64* %2
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i64, i64* %2
store i64 %11, i64* %3
%12 = load i64, i64* %4
%13 = call i64 @fib(i64 %12)
store i64 %13, i64* %2
%14 = load i64, i64* %4
%15 = add nsw i64 %14, 1
store i64 %15, i64* %4
br label %7
16: ; preds = %7
%17 = load i64, i64* %3
store i64 %17, i64* %2
%18 = load i64, i64* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%21 = load i64, i64* %4
%22 = call i32 @snprintf(i8* %20, i32 3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %21)
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%24 = call i32 @strncat(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%25 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i32*, i32** %6
%28 = icmp ne i32* %27, null
br i1 %28, label %33, label %29
29: ; preds = %16
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %16
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lld\0A\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [5 x i8] c".txt\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [23 x i8] c"Could not create file!\00"
define i32 @main() {
%1 = alloca [7 x i8]
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 1, %0 ], [ %5, %2 ]
%4 = phi i64 [ 1, %0 ], [ %6, %2 ]
%5 = tail call i64 @fib(i64 %4)
%6 = add nuw nsw i64 %4, 1
%7 = icmp sgt i64 %5, 0
br i1 %7, label %2, label %8
8: ; preds = %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %3)
%10 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%12 = call i32 @strncat(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%13 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %8
%20 = call i32 @fclose(i32* %13)
ret i32 0
}