#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 num = 2, denum = 1, n, i = 0;
  float termo;
  printf("Calcular os termos ate n=");
  scanf("%d", &n);
  while (i++ < n) {
    termo = (float)num / denum;
    printf("O termo n%d e: %.8f\n", i, termo);
    num += denum;
    denum = num - denum;
  }
}


x86 assembly (clang, -O0):
<ex6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cmp    -0xc(%rbp),%eax
jge    11b3 <ex6+0x93>
cvtsi2ssl -0x4(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x10(%rbp),%esi
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe88(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    115b <ex6+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex6>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1196 <ex6+0x76>
mov    $0x1,%ebp
mov    $0x2,%eax
lea    0xebd(%rip),%r14
mov    %eax,%r15d
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %ebp,%xmm1
add    $0x1,%ebx
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
add    %r15d,%ebp
mov    %ebp,%eax
mov    %r15d,%ebp
cmp    0x4(%rsp),%ebx
jl     1160 <ex6+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Calcular os termos ate n=\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"O termo n%d e: %.8f\0A\00"
define void @ex6() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
store i32 2, i32* %1
store i32 1, i32* %2
store i32 0, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 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* %3)
br label %8
8: ; preds = %13, %0
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = load i32, i32* %1
%15 = sitofp i32 %14 to float
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to float
%18 = fdiv float %15, %17
store float %18, float* %5
%19 = load i32, i32* %4
%20 = load float, float* %5
%21 = fpext float %20 to double
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %19, double %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %1
%25 = add nsw i32 %24, %23
store i32 %25, i32* %1
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = sub nsw i32 %26, %27
store i32 %28, i32* %2
br label %8
29: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"Calcular os termos ate n=\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"O termo n%d e: %.8f\0A\00"
define void @ex6() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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 %20
7: ; preds = %0, %7
%8 = phi i32 [ %17, %7 ], [ 1, %0 ]
%9 = phi i32 [ %16, %7 ], [ 2, %0 ]
%10 = phi i32 [ %9, %7 ], [ 1, %0 ]
%11 = sitofp i32 %9 to float
%12 = sitofp i32 %10 to float
%13 = fdiv float %11, %12
%14 = fpext float %13 to double
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %8, double %14)
%16 = add nsw i32 %9, %10
%17 = add nuw nsw i32 %8, 1
%18 = load i32, i32* %1
%19 = icmp slt i32 %8, %18
br i1 %19, label %7, label %20
20: ; preds = %7, %0
ret void
}