#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 *);
void ex6() {
  int terms, temp;
  float fibo1 = 1, fibo2 = 2, div = 0;
  printf("Digite ate quantos termos deseja calcular: ");
  scanf("%d", &terms);
  while (terms > 0) {
    div += fibo2 / fibo1;
    temp = fibo2;
    fibo2 += fibo1;
    fibo1 = temp;
    terms--;
  }
  printf("%f", div);
}


x86 assembly (clang, -O0):
<ex6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  0xed4(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xec3(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
jle    11b5 <ex6+0x95>
movss  -0x10(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
cvttss2si -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
movss  -0xc(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
cvtsi2ssl -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1168 <ex6+0x48>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe72(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex6>:
push   %rax
lea    0xef0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    11aa <ex6+0x8a>
test   $0x1,%cl
jne    11af <ex6+0x8f>
movss  0xeab(%rip),%xmm1
movss  0xea7(%rip),%xmm0
xorps  %xmm2,%xmm2
mov    %ecx,%eax
cmp    $0x1,%ecx
je     11ca <ex6+0xaa>
add    $0xffffffff,%eax
nopw   0x0(%rax,%rax,1)
movaps %xmm0,%xmm3
divss  %xmm1,%xmm3
addss  %xmm2,%xmm3
addss  %xmm0,%xmm1
cvttps2dq %xmm0,%xmm0
cvtdq2ps %xmm0,%xmm0
movaps %xmm1,%xmm2
divss  %xmm0,%xmm2
addss  %xmm3,%xmm2
addss  %xmm1,%xmm0
cvttps2dq %xmm1,%xmm1
cvtdq2ps %xmm1,%xmm1
add    $0xfffffffe,%eax
jb     1170 <ex6+0x50>
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
jmp    11d2 <ex6+0xb2>
xorps  %xmm0,%xmm0
jmp    11da <ex6+0xba>
lea    -0x1(%rcx),%eax
movss  0xe4e(%rip),%xmm0
movss  0xe42(%rip),%xmm2
movaps %xmm2,%xmm1
cmp    $0x1,%ecx
jne    1167 <ex6+0x47>
movsd  0xe3e(%rip),%xmm0
movl   $0x0,0x4(%rsp)
lea    0xe66(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Digite ate quantos termos deseja calcular: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%f\00"
define void @ex6() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
store float 1.000000e+00, float* %3
store float 2.000000e+00, float* %4
store float 0.000000e+00, float* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load float, float* %4
%13 = load float, float* %3
%14 = fdiv float %12, %13
%15 = load float, float* %5
%16 = fadd float %15, %14
store float %16, float* %5
%17 = load float, float* %4
%18 = fptosi float %17 to i32
store i32 %18, i32* %2
%19 = load float, float* %3
%20 = load float, float* %4
%21 = fadd float %20, %19
store float %21, float* %4
%22 = load i32, i32* %2
%23 = sitofp i32 %22 to float
store float %23, float* %3
%24 = load i32, i32* %1
%25 = add nsw i32 %24, -1
store i32 %25, i32* %1
br label %8
26: ; preds = %8
%27 = load float, float* %5
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %28)
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"Digite ate quantos termos deseja calcular: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%f\00"
define void @ex6() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 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 %40
7: ; preds = %0
%8 = and i32 %5, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = add nsw i32 %5, -1
br label %12
12: ; preds = %10, %7
%13 = phi float [ 0.000000e+00, %7 ], [ 2.000000e+00, %10 ]
%14 = phi float [ 2.000000e+00, %7 ], [ 3.000000e+00, %10 ]
%15 = phi float [ 1.000000e+00, %7 ], [ 2.000000e+00, %10 ]
%16 = phi i32 [ %5, %7 ], [ %11, %10 ]
%17 = icmp eq i32 %5, 1
br i1 %17, label %38, label %18
18: ; preds = %12, %18
%19 = phi float [ %29, %18 ], [ %13, %12 ]
%20 = phi float [ %31, %18 ], [ %14, %12 ]
%21 = phi float [ %32, %18 ], [ %15, %12 ]
%22 = phi i32 [ %33, %18 ], [ %16, %12 ]
%23 = fdiv float %20, %21
%24 = fadd float %19, %23
%25 = fptosi float %20 to i32
%26 = fadd float %21, %20
%27 = sitofp i32 %25 to float
%28 = fdiv float %26, %27
%29 = fadd float %24, %28
%30 = fptosi float %26 to i32
%31 = fadd float %26, %27
%32 = sitofp i32 %30 to float
%33 = add nsw i32 %22, -2
%34 = add i32 %22, -3
%35 = icmp ult i32 %34, -2
br i1 %35, label %18, label %36
36: ; preds = %18
%37 = fpext float %29 to double
br label %38
38: ; preds = %12, %36
%39 = phi double [ 2.000000e+00, %12 ], [ %37, %36 ]
store i32 0, i32* %1
br label %40
40: ; preds = %38, %0
%41 = phi double [ %39, %38 ], [ 0.000000e+00, %0 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), double %41)
ret void
}