#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 fabs(double);
double g(double, double);
double gprima(double);
int /*<<< orphan*/ printf(char *, double, ...);
void newton(double r, double xnext, double epsilon, int MAX_ITE) {
  int n = 0;
  double x = 0.00;
  while (fabs(xnext - x) / fabs(xnext) >= epsilon &&
         fabs(g(r, xnext)) >= epsilon && n < MAX_ITE) {
    x = xnext;
    xnext = x - (g(r, x) / gprima(x));
    n++;
  }
  printf("El numero de iteraciones realizadas es: %d\n", n);
  printf("El valor final de la aproximacion de la raiz es: %lf\n", xnext);
  printf("El error relativo es: %lf\n", fabs(xnext - x) / (float)fabs(xnext));
  printf("El valor de |f(%lf)| es: %lf\n", xnext, g(r, xnext));
}


x86 assembly (clang, -O0):
<newton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
movss  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
xor    %eax,%eax
ucomisd -0x18(%rbp),%xmm0
mov    %al,-0x29(%rbp)
jb     11db <newton+0x9b>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1050 <g@plt>
call   1040 <fabs@plt>
cvtss2sd %xmm0,%xmm0
xor    %eax,%eax
ucomisd -0x18(%rbp),%xmm0
mov    %al,-0x29(%rbp)
jb     11db <newton+0x9b>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11eb <newton+0xab>
jmp    1245 <newton+0x105>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1050 <g@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <gprima@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1169 <newton+0x29>
cvtsi2sdl -0x20(%rbp),%xmm0
lea    0xdaf(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xdc8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
movss  %xmm0,-0x4c(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movss  -0x4c(%rbp),%xmm0
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc2(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1050 <g@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
lea    0xdae(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newton>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x20(%rsp)
movaps %xmm1,%xmm0
call   1040 <fabs@plt>
movss  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <fabs@plt>
movsd  0x18(%rsp),%xmm2
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
cvtss2sd %xmm1,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm2,%xmm1
jae    119e <newton+0x5e>
movsd  (%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
jmp    128f <newton+0x14f>
movsd  0x20(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1050 <g@plt>
call   1040 <fabs@plt>
cvtss2sd %xmm0,%xmm0
ucomisd 0x18(%rsp),%xmm0
jb     1280 <newton+0x140>
test   %ebp,%ebp
jle    1280 <newton+0x140>
mov    $0x1,%eax
movsd  (%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %eax,%ebx
movsd  0x20(%rsp),%xmm0
call   1050 <g@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <gprima@plt>
movsd  0x10(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  (%rsp),%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,(%rsp)
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <fabs@plt>
movss  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <fabs@plt>
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
ucomisd 0x18(%rsp),%xmm0
jb     1277 <newton+0x137>
movsd  0x20(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1050 <g@plt>
call   1040 <fabs@plt>
cvtss2sd %xmm0,%xmm0
ucomisd 0x18(%rsp),%xmm0
jb     1277 <newton+0x137>
lea    0x1(%rbx),%eax
cmp    %ebp,%ebx
jl     11d0 <newton+0x90>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
jmp    128f <newton+0x14f>
movsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
lea    0xd6a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xd88(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x10(%rsp),%xmm0
call   1040 <fabs@plt>
movss  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <fabs@plt>
movss  0x8(%rsp),%xmm1
divss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
lea    0xd7f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x20(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1050 <g@plt>
movaps %xmm0,%xmm1
lea    0xd79(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x2,%al
add    $0x28,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"El numero de iteraciones realizadas es: %d\0A\00"
@.str.1 = [54 x i8] c"El valor final de la aproximacion de la raiz es: %lf\0A\00"
@.str.2 = [27 x i8] c"El error relativo es: %lf\0A\00"
@.str.3 = [30 x i8] c"El valor de |f(%lf)| es: %lf\0A\00"
define void @newton(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store double 0.000000e+00, double* %10
br label %11
11: ; preds = %36, %4
%12 = load double, double* %6
%13 = load double, double* %10
%14 = fsub double %12, %13
%15 = call float @fabs(double %14)
%16 = load double, double* %6
%17 = call float @fabs(double %16)
%18 = fdiv float %15, %17
%19 = fpext float %18 to double
%20 = load double, double* %7
%21 = fcmp oge double %19, %20
br i1 %21, label %22, label %34
22: ; preds = %11
%23 = load double, double* %5
%24 = load double, double* %6
%25 = call double @g(double %23, double %24)
%26 = call float @fabs(double %25)
%27 = fpext float %26 to double
%28 = load double, double* %7
%29 = fcmp oge double %27, %28
br i1 %29, label %30, label %34
30: ; preds = %22
%31 = load i32, i32* %9
%32 = load i32, i32* %8
%33 = icmp slt i32 %31, %32
br label %34
34: ; preds = %30, %22, %11
%35 = phi i1 [ false, %22 ], [ false, %11 ], [ %33, %30 ]
br i1 %35, label %36, label %48
36: ; preds = %34
%37 = load double, double* %6
store double %37, double* %10
%38 = load double, double* %10
%39 = load double, double* %5
%40 = load double, double* %10
%41 = call double @g(double %39, double %40)
%42 = load double, double* %10
%43 = call double @gprima(double %42)
%44 = fdiv double %41, %43
%45 = fsub double %38, %44
store double %45, double* %6
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %11
48: ; preds = %34
%49 = load i32, i32* %9
%50 = sitofp i32 %49 to double
%51 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), double %50)
%52 = load double, double* %6
%53 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), double %52)
%54 = load double, double* %6
%55 = load double, double* %10
%56 = fsub double %54, %55
%57 = call float @fabs(double %56)
%58 = load double, double* %6
%59 = call float @fabs(double %58)
%60 = fdiv float %57, %59
%61 = fpext float %60 to double
%62 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %61)
%63 = load double, double* %6
%64 = load double, double* %5
%65 = load double, double* %6
%66 = call double @g(double %64, double %65)
%67 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), double %63, double %66)
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"El numero de iteraciones realizadas es: %d\0A\00"
@.str.1 = [54 x i8] c"El valor final de la aproximacion de la raiz es: %lf\0A\00"
@.str.2 = [27 x i8] c"El error relativo es: %lf\0A\00"
@.str.3 = [30 x i8] c"El valor de |f(%lf)| es: %lf\0A\00"
define void @newton(double %0, double %1, double %2, i32 %3) {
%5 = tail call float @fabs(double %1)
%6 = tail call float @fabs(double %1)
%7 = fdiv float %5, %6
%8 = fpext float %7 to double
%9 = fcmp ult double %8, %2
br i1 %9, label %40, label %10
10: ; preds = %4
%11 = tail call double @g(double %0, double %1)
%12 = tail call float @fabs(double %11)
%13 = fpext float %12 to double
%14 = fcmp oge double %13, %2
%15 = icmp sgt i32 %3, 0
%16 = and i1 %14, %15
br i1 %16, label %24, label %40
17: ; preds = %24
%18 = tail call double @g(double %0, double %30)
%19 = tail call float @fabs(double %18)
%20 = fpext float %19 to double
%21 = fcmp oge double %20, %2
%22 = icmp slt i32 %31, %3
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %38
24: ; preds = %10, %17
%25 = phi double [ %30, %17 ], [ %1, %10 ]
%26 = phi i32 [ %31, %17 ], [ 0, %10 ]
%27 = tail call double @g(double %0, double %25)
%28 = tail call double @gprima(double %25)
%29 = fdiv double %27, %28
%30 = fsub double %25, %29
%31 = add nuw nsw i32 %26, 1
%32 = fsub double %30, %25
%33 = tail call float @fabs(double %32)
%34 = tail call float @fabs(double %30)
%35 = fdiv float %33, %34
%36 = fpext float %35 to double
%37 = fcmp ult double %36, %2
br i1 %37, label %38, label %17
38: ; preds = %17, %24
%39 = sitofp i32 %31 to double
br label %40
40: ; preds = %38, %10, %4
%41 = phi double [ %1, %4 ], [ %1, %10 ], [ %30, %38 ]
%42 = phi double [ 0.000000e+00, %4 ], [ 0.000000e+00, %10 ], [ %39, %38 ]
%43 = phi double [ %1, %4 ], [ %1, %10 ], [ %32, %38 ]
%44 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), double %42)
%45 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), double %41)
%46 = tail call float @fabs(double %43)
%47 = tail call float @fabs(double %41)
%48 = fdiv float %46, %47
%49 = fpext float %48 to double
%50 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %49)
%51 = tail call double @g(double %0, double %41)
%52 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), double %41, double %51)
ret void
}