#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n, f1 = 1, f2 = 1, ft;
  double sum = 0;
  printf("Please input an integer:");
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    ft = f2;
    f2 += f1;
    f1 = ft;
    sum += (double)f2 / f1;
  }
  printf("The result is:%.2f\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <main+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116a <main+0x4a>
movsd  -0x20(%rbp),%xmm0
lea    0xe5f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    115d <main+0x3d>
cmp    $0x1,%eax
jne    1163 <main+0x43>
mov    $0x1,%ecx
xorpd  %xmm0,%xmm0
mov    $0x1,%edx
jmp    11b2 <main+0x92>
xorpd  %xmm0,%xmm0
jmp    11ce <main+0xae>
mov    %eax,%esi
and    $0xfffffffe,%esi
mov    $0x1,%ecx
xorpd  %xmm0,%xmm0
mov    $0x1,%edx
cs nopw 0x0(%rax,%rax,1)
add    %ecx,%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movapd %xmm1,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
add    %edx,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
add    $0xfffffffe,%esi
jne    1180 <main+0x60>
test   $0x1,%al
je     11ce <main+0xae>
add    %ecx,%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
lea    0xe47(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Please input an integer:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"The result is:%.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32 0, i32* %1
store i32 1, i32* %4
store i32 1, i32* %5
store double 0.000000e+00, double* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 0, i32* %2
br label %10
10: ; preds = %27, %0
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i32, i32* %5
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = add nsw i32 %17, %16
store i32 %18, i32* %5
%19 = load i32, i32* %6
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = sitofp i32 %20 to double
%22 = load i32, i32* %4
%23 = sitofp i32 %22 to double
%24 = fdiv double %21, %23
%25 = load double, double* %7
%26 = fadd double %25, %24
store double %26, double* %7
br label %27
27: ; preds = %14
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %10
30: ; preds = %10
%31 = load double, double* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [25 x i8] c"Please input an integer:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"The result is:%.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %41
7: ; preds = %0
%8 = and i32 %5, 1
%9 = icmp eq i32 %5, 1
br i1 %9, label %29, label %10
10: ; preds = %7
%11 = and i32 %5, -2
br label %12
12: ; preds = %12, %10
%13 = phi double [ 0.000000e+00, %10 ], [ %26, %12 ]
%14 = phi i32 [ 1, %10 ], [ %22, %12 ]
%15 = phi i32 [ 1, %10 ], [ %17, %12 ]
%16 = phi i32 [ 0, %10 ], [ %27, %12 ]
%17 = add nsw i32 %14, %15
%18 = sitofp i32 %17 to double
%19 = sitofp i32 %14 to double
%20 = fdiv double %18, %19
%21 = fadd double %13, %20
%22 = add nsw i32 %17, %14
%23 = sitofp i32 %22 to double
%24 = sitofp i32 %17 to double
%25 = fdiv double %23, %24
%26 = fadd double %21, %25
%27 = add i32 %16, 2
%28 = icmp eq i32 %27, %11
br i1 %28, label %29, label %12
29: ; preds = %12, %7
%30 = phi double [ undef, %7 ], [ %26, %12 ]
%31 = phi double [ 0.000000e+00, %7 ], [ %26, %12 ]
%32 = phi i32 [ 1, %7 ], [ %22, %12 ]
%33 = phi i32 [ 1, %7 ], [ %17, %12 ]
%34 = icmp eq i32 %8, 0
br i1 %34, label %41, label %35
35: ; preds = %29
%36 = add nsw i32 %32, %33
%37 = sitofp i32 %36 to double
%38 = sitofp i32 %32 to double
%39 = fdiv double %37, %38
%40 = fadd double %31, %39
br label %41
41: ; preds = %35, %29, %0
%42 = phi double [ 0.000000e+00, %0 ], [ %30, %29 ], [ %40, %35 ]
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %42)
ret i32 0
}