#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 */
float f(float);
float fabs(float);
float fl(float);
float pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
float valorInicial(int, int);
void main() {
  int k = 0, flg = 1;
  float xAnt, xAtual, erro;
  float xk = valorInicial(1, 2);
  printf("\nFuncao: 2x^3+ln(x)-5\n\n");
  printf("k\txk\t\tf(xk)\t\tf'(xk)\t\tE\n");
  while (flg == 1) {
    if (k == 0) {
      printf("%d\t%.8f\t%.8f\t%.8f\t----\n", k, xk, f(xk), fl(xk));
      xAnt = xk;
      xAtual = xk;
    } else {
      xAnt = xAtual;
      xAtual = xk;
      erro = fabs((xAtual - xAnt) / xAtual);
      printf("%d\t%.8f\t%.8f\t%.8f\t%.8f\n", k, xk, f(xk), fl(xk), erro);
      if (erro <= pow(10, -7))
        flg = 0;
    }
    xk = xk - (f(xk) / fl(xk));
    k++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    $0x1,%edi
mov    $0x2,%esi
call   1070 <valorInicial@plt>
movss  %xmm0,-0x18(%rbp)
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    132d <main+0x1cd>
cmpl   $0x0,-0x4(%rbp)
jne    1226 <main+0xc6>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
call   1040 <f@plt>
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <fl@plt>
mov    -0x2c(%rbp),%esi
movsd  -0x28(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
cvtss2sd %xmm2,%xmm2
lea    0xe2a(%rip),%rdi
mov    $0x3,%al
call   1050 <printf@plt>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    12e2 <main+0x182>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
call   1060 <fabs@plt>
movss  %xmm0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0x18(%rbp),%xmm0
call   1040 <f@plt>
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <fl@plt>
mov    -0x44(%rbp),%esi
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
cvtss2sd %xmm2,%xmm2
movss  -0x14(%rbp),%xmm3
cvtss2sd %xmm3,%xmm3
lea    0xda0(%rip),%rdi
mov    $0x4,%al
call   1050 <printf@plt>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1080 <pow@plt>
movss  -0x30(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jb     12dd <main+0x17d>
movl   $0x0,-0x8(%rbp)
jmp    12e2 <main+0x182>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x18(%rbp),%xmm0
call   1040 <f@plt>
movss  %xmm0,-0x4c(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <fl@plt>
movss  -0x4c(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x48(%rbp),%xmm0
divss  %xmm2,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <main+0x46>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0x2,%esi
call   1070 <valorInicial@plt>
movss  %xmm0,0x4(%rsp)
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
lea    0xec3(%rip),%rdi
call   1040 <puts@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1050 <f@plt>
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
movss  0x4(%rsp),%xmm0
call   1030 <fl@plt>
cvtss2sd %xmm0,%xmm2
lea    0xe42(%rip),%rdi
xor    %esi,%esi
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mov    $0x3,%al
call   1060 <printf@plt>
movss  0x4(%rsp),%xmm0
call   1050 <f@plt>
movss  %xmm0,0x20(%rsp)
movss  0x4(%rsp),%xmm0
call   1030 <fl@plt>
movss  0x4(%rsp),%xmm1
movss  0x20(%rsp),%xmm2
divss  %xmm0,%xmm2
movaps %xmm1,%xmm0
subss  %xmm2,%xmm0
lea    0xe0b(%rip),%r14
nopl   (%rax)
movss  %xmm0,0x18(%rsp)
movss  %xmm0,0x4(%rsp)
movaps %xmm0,%xmm2
subss  %xmm1,%xmm2
divss  %xmm0,%xmm2
andps  0xdc2(%rip),%xmm2
movaps %xmm2,0x20(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1050 <f@plt>
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm0
call   1030 <fl@plt>
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
movaps 0x20(%rsp),%xmm0
xorps  %xmm3,%xmm3
cvtss2sd %xmm0,%xmm3
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x4,%al
call   1060 <printf@plt>
mov    $0xa,%edi
mov    $0xfffffff9,%esi
call   1080 <pow@plt>
movss  %xmm0,0x10(%rsp)
movss  0x4(%rsp),%xmm0
call   1050 <f@plt>
movss  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm0
call   1030 <fl@plt>
add    $0x1,%ebx
movss  0x10(%rsp),%xmm1
ucomiss 0x20(%rsp),%xmm1
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0x18(%rsp),%xmm0
subss  %xmm1,%xmm0
movss  0x4(%rsp),%xmm1
jb     1220 <main+0xc0>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"\0AFuncao: 2x^3+ln(x)-5\0A\0A\00"
@.str.1 = [24 x i8] c"k\09xk\09\09f(xk)\09\09f'(xk)\09\09E\0A\00"
@.str.2 = [24 x i8] c"%d\09%.8f\09%.8f\09%.8f\09----\0A\00"
@.str.3 = [24 x i8] c"%d\09%.8f\09%.8f\09%.8f\09%.8f\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
store i32 1, i32* %2
%7 = call float @valorInicial(i32 1, i32 2)
store float %7, float* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %55, %0
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %65
13: ; preds = %10
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i32, i32* %1
%18 = load float, float* %6
%19 = fpext float %18 to double
%20 = load float, float* %6
%21 = call float @f(float %20)
%22 = fpext float %21 to double
%23 = load float, float* %6
%24 = call float @fl(float %23)
%25 = fpext float %24 to double
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %17, double %19, double %22, double %25)
%27 = load float, float* %6
store float %27, float* %3
%28 = load float, float* %6
store float %28, float* %4
br label %55
29: ; preds = %13
%30 = load float, float* %4
store float %30, float* %3
%31 = load float, float* %6
store float %31, float* %4
%32 = load float, float* %4
%33 = load float, float* %3
%34 = fsub float %32, %33
%35 = load float, float* %4
%36 = fdiv float %34, %35
%37 = call float @fabs(float %36)
store float %37, float* %5
%38 = load i32, i32* %1
%39 = load float, float* %6
%40 = fpext float %39 to double
%41 = load float, float* %6
%42 = call float @f(float %41)
%43 = fpext float %42 to double
%44 = load float, float* %6
%45 = call float @fl(float %44)
%46 = fpext float %45 to double
%47 = load float, float* %5
%48 = fpext float %47 to double
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %38, double %40, double %43, double %46, double %48)
%50 = load float, float* %5
%51 = call float @pow(i32 10, i32 -7)
%52 = fcmp ole float %50, %51
br i1 %52, label %53, label %54
53: ; preds = %29
store i32 0, i32* %2
br label %54
54: ; preds = %53, %29
br label %55
55: ; preds = %54, %16
%56 = load float, float* %6
%57 = load float, float* %6
%58 = call float @f(float %57)
%59 = load float, float* %6
%60 = call float @fl(float %59)
%61 = fdiv float %58, %60
%62 = fsub float %56, %61
store float %62, float* %6
%63 = load i32, i32* %1
%64 = add nsw i32 %63, 1
store i32 %64, i32* %1
br label %10
65: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str.2 = [24 x i8] c"%d\09%.8f\09%.8f\09%.8f\09----\0A\00"
@.str.3 = [24 x i8] c"%d\09%.8f\09%.8f\09%.8f\09%.8f\0A\00"
@str = [23 x i8] c"\0AFuncao: 2x^3+ln(x)-5\0A\00"
@str.4 = [23 x i8] c"k\09xk\09\09f(xk)\09\09f'(xk)\09\09E\00"
define void @main() {
%1 = tail call float @valorInicial(i32 1, i32 2)
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
%4 = fpext float %1 to double
%5 = tail call float @f(float %1)
%6 = fpext float %5 to double
%7 = tail call float @fl(float %1)
%8 = fpext float %7 to double
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 0, double %4, double %6, double %8)
%10 = tail call float @f(float %1)
%11 = tail call float @fl(float %1)
%12 = fdiv float %10, %11
%13 = fsub float %1, %12
br label %14
14: ; preds = %14, %0
%15 = phi float [ %13, %0 ], [ %33, %14 ]
%16 = phi i32 [ 1, %0 ], [ %34, %14 ]
%17 = phi float [ %1, %0 ], [ %15, %14 ]
%18 = fsub float %15, %17
%19 = fdiv float %18, %15
%20 = tail call float @llvm.fabs.f32(float %19)
%21 = fpext float %15 to double
%22 = tail call float @f(float %15)
%23 = fpext float %22 to double
%24 = tail call float @fl(float %15)
%25 = fpext float %24 to double
%26 = fpext float %20 to double
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %16, double %21, double %23, double %25, double %26)
%28 = tail call float @pow(i32 10, i32 -7)
%29 = fcmp ugt float %20, %28
%30 = tail call float @f(float %15)
%31 = tail call float @fl(float %15)
%32 = fdiv float %30, %31
%33 = fsub float %15, %32
%34 = add nuw nsw i32 %16, 1
br i1 %29, label %14, label %35
35: ; preds = %14
ret void
}