#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 = fabs(x1 - x0);
  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(x1 - x0);
  x2 = x1 - f(x1) / (f(x1) - f(x0)) * (x1 - x0);
  fx2 = f(x2);
  maximoIteracoes = 100;
  iteracoes = 0;
  while ((largura > epsilon) && (fabs(fx2) > 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(x1 - x0);
    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)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x14(%rbp)
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe76(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%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
xor    %eax,%eax
ucomiss -0x10(%rbp),%xmm0
mov    %al,-0x41(%rbp)
jbe    12a0 <main+0x160>
movss  -0x1c(%rbp),%xmm0
call   1050 <fabs@plt>
ucomiss -0x10(%rbp),%xmm0
seta   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    12b0 <main+0x170>
jmp    13c2 <main+0x282>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x50(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x60(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x50(%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    136a <main+0x22a>
jp     136a <main+0x22a>
jmp    13c2 <main+0x282>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%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     13bd <main+0x27d>
mov    -0x20(%rbp),%esi
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13c2 <main+0x282>
jmp    1278 <main+0x138>
mov    -0x24(%rbp),%eax
mov    %eax,-0x6c(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <f@plt>
mov    -0x6c(%rbp),%esi
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
lea    0xcad(%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  (%rsp),%xmm0
movaps %xmm0,%xmm1
subss  0x4(%rsp),%xmm1
andps  0xe56(%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  0x14(%rsp),%xmm1
xor    %ebx,%ebx
movaps 0x20(%rsp),%xmm2
ucomiss %xmm1,%xmm2
jbe    1345 <main+0x205>
cvtsd2ss %xmm0,%xmm0
andps  0xdbd(%rip),%xmm0
ucomiss %xmm1,%xmm0
movss  0x8(%rsp),%xmm0
jbe    134b <main+0x20b>
xor    %ebx,%ebx
movss  (%rsp),%xmm0
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>
xorps  %xmm4,%xmm4
cvtsd2ss %xmm0,%xmm4
ucomiss 0xd2f(%rip),%xmm4
jne    12e5 <main+0x1a5>
jnp    1345 <main+0x205>
movss  (%rsp),%xmm1
movss  %xmm1,0x4(%rsp)
movss  0x8(%rsp),%xmm0
movss  %xmm0,(%rsp)
cmp    $0x63,%ebx
je     132d <main+0x1ed>
movaps %xmm0,%xmm2
subss  %xmm1,%xmm2
movaps 0xcf2(%rip),%xmm3
andps  %xmm3,%xmm2
movss  0x14(%rsp),%xmm1
add    $0x1,%ebx
ucomiss %xmm1,%xmm2
jbe    134b <main+0x20b>
andps  %xmm3,%xmm4
ucomiss %xmm1,%xmm4
ja     1260 <main+0x120>
jmp    134b <main+0x20b>
lea    0xce3(%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    0xcda(%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 = load float, float* %3
%11 = load float, float* %2
%12 = fsub float %10, %11
%13 = call float @fabs(float %12)
store float %13, float* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %3)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %4)
%20 = load float, float* %3
%21 = load float, float* %2
%22 = fsub float %20, %21
%23 = call float @fabs(float %22)
store float %23, float* %5
%24 = load float, float* %3
%25 = fpext float %24 to double
%26 = load float, float* %3
%27 = call double @f(float %26)
%28 = load float, float* %3
%29 = call double @f(float %28)
%30 = load float, float* %2
%31 = call double @f(float %30)
%32 = fsub double %29, %31
%33 = fdiv double %27, %32
%34 = load float, float* %3
%35 = load float, float* %2
%36 = fsub float %34, %35
%37 = fpext float %36 to double
%38 = fneg double %33
%39 = call double @llvm.fmuladd.f64(double %38, double %37, double %25)
%40 = fptrunc double %39 to float
store float %40, float* %6
%41 = load float, float* %6
%42 = call double @f(float %41)
%43 = fptrunc double %42 to float
store float %43, float* %7
store i32 100, i32* %8
store i32 0, i32* %9
br label %44
44: ; preds = %95, %0
%45 = load float, float* %5
%46 = load float, float* %4
%47 = fcmp ogt float %45, %46
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load float, float* %7
%50 = call float @fabs(float %49)
%51 = load float, float* %4
%52 = fcmp ogt float %50, %51
br label %53
53: ; preds = %48, %44
%54 = phi i1 [ false, %44 ], [ %52, %48 ]
br i1 %54, label %55, label %96
55: ; preds = %53
%56 = load float, float* %3
%57 = fpext float %56 to double
%58 = load float, float* %3
%59 = call double @f(float %58)
%60 = load float, float* %3
%61 = call double @f(float %60)
%62 = load float, float* %2
%63 = call double @f(float %62)
%64 = fsub double %61, %63
%65 = fdiv double %59, %64
%66 = load float, float* %3
%67 = load float, float* %2
%68 = fsub float %66, %67
%69 = fpext float %68 to double
%70 = fneg double %65
%71 = call double @llvm.fmuladd.f64(double %70, double %69, double %57)
%72 = fptrunc double %71 to float
store float %72, float* %6
%73 = load float, float* %6
%74 = call double @f(float %73)
%75 = fptrunc double %74 to float
store float %75, float* %7
%76 = load float, float* %7
%77 = fpext float %76 to double
%78 = fcmp oeq double %77, 0.000000e+00
br i1 %78, label %79, label %80
79: ; preds = %55
br label %96
80: ; preds = %55
%81 = load float, float* %3
store float %81, float* %2
%82 = load float, float* %6
store float %82, float* %3
%83 = load float, float* %3
%84 = load float, float* %2
%85 = fsub float %83, %84
%86 = call float @fabs(float %85)
store float %86, float* %5
%87 = load i32, i32* %9
%88 = add nsw i32 %87, 1
store i32 %88, i32* %9
%89 = load i32, i32* %9
%90 = load i32, i32* %8
%91 = icmp sge i32 %89, %90
br i1 %91, label %92, label %95
92: ; preds = %80
%93 = load i32, i32* %8
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %93)
br label %96
95: ; preds = %80
br label %44
96: ; preds = %92, %79, %53
%97 = load i32, i32* %9
%98 = load float, float* %6
%99 = fpext float %98 to double
%100 = load float, float* %6
%101 = call double @f(float %100)
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %97, double %99, double %101)
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* %2
%14 = load float, float* %1
%15 = fsub float %13, %14
%16 = call float @llvm.fabs.f32(float %15)
%17 = fpext float %13 to double
%18 = call double @f(float %13)
%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 = fptrunc double %32 to float
%34 = load float, float* %3
%35 = fcmp ogt float %16, %34
%36 = call float @llvm.fabs.f32(float %33)
%37 = fcmp ogt float %36, %34
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %39, label %76
39: ; preds = %0
%40 = load float, float* %2
br label %49
41: ; preds = %70
%42 = fsub float %66, %71
%43 = call float @llvm.fabs.f32(float %42)
%44 = load float, float* %3
%45 = fcmp ogt float %43, %44
%46 = call float @llvm.fabs.f32(float %68)
%47 = fcmp ogt float %46, %44
%48 = select i1 %45, i1 %47, i1 false
br i1 %48, label %49, label %76
49: ; preds = %39, %41
%50 = phi float [ %66, %41 ], [ %40, %39 ]
%51 = phi i32 [ %72, %41 ], [ 0, %39 ]
%52 = fpext float %50 to double
%53 = call double @f(float %50)
%54 = load float, float* %2
%55 = call double @f(float %54)
%56 = load float, float* %1
%57 = call double @f(float %56)
%58 = fsub double %55, %57
%59 = load float, float* %2
%60 = load float, float* %1
%61 = fsub float %59, %60
%62 = fpext float %61 to double
%63 = fneg double %53
%64 = fdiv double %63, %58
%65 = call double @llvm.fmuladd.f64(double %64, double %62, double %52)
%66 = fptrunc double %65 to float
%67 = call double @f(float %66)
%68 = fptrunc double %67 to float
%69 = fcmp oeq float %68, 0.000000e+00
br i1 %69, label %76, label %70
70: ; preds = %49
%71 = load float, float* %2
store float %71, float* %1
store float %66, float* %2
%72 = add nuw nsw i32 %51, 1
%73 = icmp eq i32 %51, 99
br i1 %73, label %74, label %41
74: ; preds = %70
%75 = 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 %76
76: ; preds = %49, %41, %0, %74
%77 = phi float [ %66, %74 ], [ %31, %0 ], [ %66, %41 ], [ %66, %49 ]
%78 = phi i32 [ 100, %74 ], [ 0, %0 ], [ %51, %49 ], [ %72, %41 ]
%79 = fpext float %77 to double
%80 = call double @f(float %77)
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %78, double %79, double %80)
ret i32 0
}