#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 derivada(double);
double funcao(double);
int /*<<< orphan*/ printf(char *, int, double, double, double);
double sqrt(double);
double NewtonRaphson(double x, double epsilon) {
  int i;
  for (i = 0; i < 100; i++) {
    x = x - (funcao(x) / derivada(x));
    printf("iteração n %d. X= %lf. Valor da funcao: f(%lf)=%lf\n", i, x, x,
           funcao(x));
    if (sqrt(funcao(x) * funcao(x)) < epsilon)
      return (x);
  }
  return (x);
}


x86 assembly (clang, -O0):
<NewtonRaphson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    123e <NewtonRaphson+0xfe>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <funcao@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <derivada@plt>
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <funcao@plt>
mov    -0x3c(%rbp),%esi
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
call   1040 <funcao@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <funcao@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    122b <NewtonRaphson+0xeb>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1248 <NewtonRaphson+0x108>
jmp    1230 <NewtonRaphson+0xf0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <NewtonRaphson+0x19>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NewtonRaphson>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
lea    0xead(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsd  (%rsp),%xmm0
call   1040 <funcao@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1050 <derivada@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
call   1040 <funcao@plt>
movapd %xmm0,%xmm2
mov    %r14,%rdi
mov    %ebx,%esi
movsd  (%rsp),%xmm0
movaps %xmm0,%xmm1
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
call   1040 <funcao@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <funcao@plt>
mulsd  0x8(%rsp),%xmm0
ucomisd 0xe2b(%rip),%xmm0
jb     11e0 <NewtonRaphson+0xa0>
sqrtsd %xmm0,%xmm0
jmp    11e5 <NewtonRaphson+0xa5>
nopl   (%rax)
call   1060 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     11ff <NewtonRaphson+0xbf>
lea    0x1(%rbx),%eax
cmp    $0x63,%ebx
mov    %eax,%ebx
jne    1160 <NewtonRaphson+0x20>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [54 x i8] c"itera\C3\A7\C3\A3o n %d. X= %lf. Valor da funcao: f(%lf)=%lf\0A\00"
define double @NewtonRaphson(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store double %0, double* %4
store double %1, double* %5
store i32 0, i32* %6
br label %7
7: ; preds = %35, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %38
10: ; preds = %7
%11 = load double, double* %4
%12 = load double, double* %4
%13 = call double @funcao(double %12)
%14 = load double, double* %4
%15 = call double @derivada(double %14)
%16 = fdiv double %13, %15
%17 = fsub double %11, %16
store double %17, double* %4
%18 = load i32, i32* %6
%19 = load double, double* %4
%20 = load double, double* %4
%21 = load double, double* %4
%22 = call double @funcao(double %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %18, double %19, double %20, double %22)
%24 = load double, double* %4
%25 = call double @funcao(double %24)
%26 = load double, double* %4
%27 = call double @funcao(double %26)
%28 = fmul double %25, %27
%29 = call double @sqrt(double %28)
%30 = load double, double* %5
%31 = fcmp olt double %29, %30
br i1 %31, label %32, label %34
32: ; preds = %10
%33 = load double, double* %4
store double %33, double* %3
br label %40
34: ; preds = %10
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %7
38: ; preds = %7
%39 = load double, double* %4
store double %39, double* %3
br label %40
40: ; preds = %38, %32
%41 = load double, double* %3
ret double %41
}

LLVM IR (-O2):
@.str = [54 x i8] c"itera\C3\A7\C3\A3o n %d. X= %lf. Valor da funcao: f(%lf)=%lf\0A\00"
define double @NewtonRaphson(double %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 0, %2 ], [ %17, %3 ]
%5 = phi double [ %0, %2 ], [ %9, %3 ]
%6 = tail call double @funcao(double %5)
%7 = tail call double @derivada(double %5)
%8 = fdiv double %6, %7
%9 = fsub double %5, %8
%10 = tail call double @funcao(double %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %4, double %9, double %9, double %10)
%12 = tail call double @funcao(double %9)
%13 = tail call double @funcao(double %9)
%14 = fmul double %12, %13
%15 = tail call double @sqrt(double %14)
%16 = fcmp olt double %15, %1
%17 = add nuw nsw i32 %4, 1
%18 = icmp eq i32 %17, 100
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %3
20: ; preds = %3
ret double %9
}