#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 f(float);
float fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
main() {
  float x0;
  float x1;
  float epsilon;
  float largura;
  float x2;
  float fx2;
  int maximoIteracoes;
  int iteracoes;
  printf("Digite a primeira aproximação inicial:\n");
  scanf("%f", &x0);
  printf("Digite a segunda aproximação inicial:\n");
  scanf("%f", &x1);
  printf("Digite a precisão requerida:\n");
  scanf("%f", &epsilon);
  largura = fabs(x0 - x1);
  x2 = x1 - f(x1) / (f(x1) - f(x0)) * (x1 - x0);
  fx2 = f(x2);
  maximoIteracoes = 100;
  iteracoes = 0;
  while (largura > epsilon) {
    x2 = x1 - f(x1) / (f(x1) - f(x0)) * (x1 - x0);
    fx2 = f(x2);
    if (fx2 == 0.0) {
      break;
    }
    x0 = x1;
    x1 = x2;
    largura = fabs(x0 - x1);
    iteracoes = iteracoes + 1;
    if (iteracoes >= maximoIteracoes) {
      printf("Limite de iterações (=%d) atingido!!!\n\n", maximoIteracoes);
      break;
    }
  }
  printf("Após %d iterações foi obtido x = %.10f e f(x) = %.10f\n", iteracoes,
         x2, f(x2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8a(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x40(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
movss  -0xc(%rbp),%xmm2
subss  -0x8(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <f@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movl   $0x64,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
ucomiss -0x10(%rbp),%xmm0
jbe    1385 <main+0x245>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x48(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x58(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x58(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
subsd  %xmm3,%xmm2
divsd  %xmm2,%xmm0
movss  -0xc(%rbp),%xmm2
subss  -0x8(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <f@plt>
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    132d <main+0x1ed>
jp     132d <main+0x1ed>
jmp    1385 <main+0x245>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x14(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     1380 <main+0x240>
mov    -0x20(%rbp),%esi
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1385 <main+0x245>
jmp    1264 <main+0x124>
mov    -0x24(%rbp),%eax
mov    %eax,-0x64(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <f@plt>
mov    -0x64(%rbp),%esi
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
lea    0xcea(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xf2f(%rip),%rdi
call   1030 <puts@plt>
lea    0xebc(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xf49(%rip),%rdi
call   1030 <puts@plt>
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
movss  0x4(%rsp),%xmm1
movss  (%rsp),%xmm0
subss  %xmm0,%xmm1
andps  0xe55(%rip),%xmm1
movaps %xmm1,0x20(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <f@plt>
movsd  %xmm0,0x18(%rsp)
movss  (%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x38(%rsp)
movss  0x4(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x38(%rsp),%xmm2
subsd  %xmm0,%xmm2
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0x18(%rsp),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
call   1040 <f@plt>
movss  0x8(%rsp),%xmm0
xor    %ebx,%ebx
movaps 0x20(%rsp),%xmm1
ucomiss 0x14(%rsp),%xmm1
jbe    1326 <main+0x1e6>
xor    %ebx,%ebx
movss  (%rsp),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <f@plt>
movsd  %xmm0,0x20(%rsp)
movss  (%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x18(%rsp)
movss  0x4(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x18(%rsp),%xmm2
subsd  %xmm0,%xmm2
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0x20(%rsp),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
call   1040 <f@plt>
cvtsd2ss %xmm0,%xmm0
ucomiss 0xd42(%rip),%xmm0
jne    12d2 <main+0x192>
jnp    1320 <main+0x1e0>
movss  (%rsp),%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x8(%rsp),%xmm0
movss  %xmm0,(%rsp)
cmp    $0x63,%ebx
je     1308 <main+0x1c8>
subss  %xmm0,%xmm1
andps  0xd08(%rip),%xmm1
add    $0x1,%ebx
ucomiss 0x14(%rsp),%xmm1
ja     1250 <main+0x110>
jmp    1326 <main+0x1e6>
lea    0xd08(%rip),%rdi
mov    $0x64,%ebx
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movss  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <f@plt>
movaps %xmm0,%xmm1
lea    0xcff(%rip),%rdi
mov    %ebx,%esi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Digite a primeira aproxima\C3\A7\C3\A3o inicial:\0A\00"
@.str.1 = [3 x i8] c"%f\00"
@.str.2 = [41 x i8] c"Digite a segunda aproxima\C3\A7\C3\A3o inicial:\0A\00"
@.str.3 = [31 x i8] c"Digite a precis\C3\A3o requerida:\0A\00"
@.str.4 = [42 x i8] c"Limite de itera\C3\A7\C3\B5es (=%d) atingido!!!\0A\0A\00"
@.str.5 = [58 x i8] c"Ap\C3\B3s %d itera\C3\A7\C3\B5es foi obtido x = %.10f e f(x) = %.10f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
%16 = load float, float* %2
%17 = load float, float* %3
%18 = fsub float %16, %17
%19 = call float @fabs(float %18)
store float %19, float* %5
%20 = load float, float* %3
%21 = fpext float %20 to double
%22 = load float, float* %3
%23 = call double @f(float %22)
%24 = load float, float* %3
%25 = call double @f(float %24)
%26 = load float, float* %2
%27 = call double @f(float %26)
%28 = fsub double %25, %27
%29 = fdiv double %23, %28
%30 = load float, float* %3
%31 = load float, float* %2
%32 = fsub float %30, %31
%33 = fpext float %32 to double
%34 = fneg double %29
%35 = call double @llvm.fmuladd.f64(double %34, double %33, double %21)
%36 = fptrunc double %35 to float
store float %36, float* %6
%37 = load float, float* %6
%38 = call double @f(float %37)
%39 = fptrunc double %38 to float
store float %39, float* %7
store i32 100, i32* %8
store i32 0, i32* %9
br label %40
40: ; preds = %84, %0
%41 = load float, float* %5
%42 = load float, float* %4
%43 = fcmp ogt float %41, %42
br i1 %43, label %44, label %85
44: ; preds = %40
%45 = load float, float* %3
%46 = fpext float %45 to double
%47 = load float, float* %3
%48 = call double @f(float %47)
%49 = load float, float* %3
%50 = call double @f(float %49)
%51 = load float, float* %2
%52 = call double @f(float %51)
%53 = fsub double %50, %52
%54 = fdiv double %48, %53
%55 = load float, float* %3
%56 = load float, float* %2
%57 = fsub float %55, %56
%58 = fpext float %57 to double
%59 = fneg double %54
%60 = call double @llvm.fmuladd.f64(double %59, double %58, double %46)
%61 = fptrunc double %60 to float
store float %61, float* %6
%62 = load float, float* %6
%63 = call double @f(float %62)
%64 = fptrunc double %63 to float
store float %64, float* %7
%65 = load float, float* %7
%66 = fpext float %65 to double
%67 = fcmp oeq double %66, 0.000000e+00
br i1 %67, label %68, label %69
68: ; preds = %44
br label %85
69: ; preds = %44
%70 = load float, float* %3
store float %70, float* %2
%71 = load float, float* %6
store float %71, float* %3
%72 = load float, float* %2
%73 = load float, float* %3
%74 = fsub float %72, %73
%75 = call float @fabs(float %74)
store float %75, float* %5
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
%78 = load i32, i32* %9
%79 = load i32, i32* %8
%80 = icmp sge i32 %78, %79
br i1 %80, label %81, label %84
81: ; preds = %69
%82 = load i32, i32* %8
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %82)
br label %85
84: ; preds = %69
br label %40
85: ; preds = %81, %68, %40
%86 = load i32, i32* %9
%87 = load float, float* %6
%88 = fpext float %87 to double
%89 = load float, float* %6
%90 = call double @f(float %89)
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %86, double %88, double %90)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%f\00"
@.str.4 = [42 x i8] c"Limite de itera\C3\A7\C3\B5es (=%d) atingido!!!\0A\0A\00"
@.str.5 = [58 x i8] c"Ap\C3\B3s %d itera\C3\A7\C3\B5es foi obtido x = %.10f e f(x) = %.10f\0A\00"
@str = [41 x i8] c"Digite a primeira aproxima\C3\A7\C3\A3o inicial:\00"
@str.6 = [40 x i8] c"Digite a segunda aproxima\C3\A7\C3\A3o inicial:\00"
@str.7 = [30 x i8] c"Digite a precis\C3\A3o requerida:\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast float* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.6, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%13 = load float, float* %1
%14 = load float, float* %2
%15 = fsub float %13, %14
%16 = call float @llvm.fabs.f32(float %15)
%17 = fpext float %14 to double
%18 = call double @f(float %14)
%19 = load float, float* %2
%20 = call double @f(float %19)
%21 = load float, float* %1
%22 = call double @f(float %21)
%23 = fsub double %20, %22
%24 = load float, float* %2
%25 = load float, float* %1
%26 = fsub float %24, %25
%27 = fpext float %26 to double
%28 = fneg double %18
%29 = fdiv double %28, %23
%30 = call double @llvm.fmuladd.f64(double %29, double %27, double %17)
%31 = fptrunc double %30 to float
%32 = call double @f(float %31)
%33 = load float, float* %3
%34 = fcmp ogt float %16, %33
br i1 %34, label %35, label %69
35: ; preds = %0
%36 = load float, float* %2
br label %42
37: ; preds = %63
%38 = fsub float %64, %59
%39 = call float @llvm.fabs.f32(float %38)
%40 = load float, float* %3
%41 = fcmp ogt float %39, %40
br i1 %41, label %42, label %69
42: ; preds = %35, %37
%43 = phi float [ %59, %37 ], [ %36, %35 ]
%44 = phi i32 [ %65, %37 ], [ 0, %35 ]
%45 = fpext float %43 to double
%46 = call double @f(float %43)
%47 = load float, float* %2
%48 = call double @f(float %47)
%49 = load float, float* %1
%50 = call double @f(float %49)
%51 = fsub double %48, %50
%52 = load float, float* %2
%53 = load float, float* %1
%54 = fsub float %52, %53
%55 = fpext float %54 to double
%56 = fneg double %46
%57 = fdiv double %56, %51
%58 = call double @llvm.fmuladd.f64(double %57, double %55, double %45)
%59 = fptrunc double %58 to float
%60 = call double @f(float %59)
%61 = fptrunc double %60 to float
%62 = fcmp oeq float %61, 0.000000e+00
br i1 %62, label %69, label %63
63: ; preds = %42
%64 = load float, float* %2
store float %64, float* %1
store float %59, float* %2
%65 = add nuw nsw i32 %44, 1
%66 = icmp eq i32 %44, 99
br i1 %66, label %67, label %37
67: ; preds = %63
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 100)
br label %69
69: ; preds = %37, %42, %0, %67
%70 = phi float [ %59, %67 ], [ %31, %0 ], [ %59, %42 ], [ %59, %37 ]
%71 = phi i32 [ 100, %67 ], [ 0, %0 ], [ %65, %37 ], [ %44, %42 ]
%72 = fpext float %70 to double
%73 = call double @f(float %70)
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %71, double %72, double %73)
ret i32 0
}