#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 */
double fabs(double);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  double currentFi = 2, lastFi = 1;
  int termPosition = 2;
  while (fabs(currentFi - lastFi) >= 0.000001) {
    lastFi = currentFi;
    currentFi = 1 + 1 / lastFi;
    termPosition++;
  }
  printf("Aproximacao de fi:%f \n", currentFi);
  printf("Calculada ate o termo:%d \n", termPosition);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xee1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xecc(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movaps 0xecf(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xeb3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     119d <main+0x8d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe87(%rip),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xe7a(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1140 <main+0x30>
cvttsd2si -0x10(%rbp),%esi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
mov    $0x11,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Aproximacao de fi:%f \0A\00"
@.str.1 = [27 x i8] c"Calculada ate o termo:%d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store i32 0, i32* %1
store double 2.000000e+00, double* %2
store double 1.000000e+00, double* %3
store i32 2, i32* %4
br label %5
5: ; preds = %11, %0
%6 = load double, double* %2
%7 = load double, double* %3
%8 = fsub double %6, %7
%9 = call double @llvm.fabs.f64(double %8)
%10 = fcmp oge double %9, 0x3EB0C6F7A0B5ED8D
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = load double, double* %2
store double %12, double* %3
%13 = load double, double* %3
%14 = fdiv double 1.000000e+00, %13
%15 = fadd double 1.000000e+00, %14
store double %15, double* %2
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %5
18: ; preds = %5
%19 = load double, double* %2
%20 = fptosi double %19 to i32
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %4
%23 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Aproximacao de fi:%f \0A\00"
@.str.1 = [27 x i8] c"Calculada ate o termo:%d \0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 1)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 17)
ret i32 0
}