double NewtonRaphson() {
  double root = 0;
  double x1 = 1;
  double x2 = 0;
  int loopCounter = 0;
  while (1) {
    loopCounter++;
    x2 = x1 - ((((x1) * (x1) * (x1)) - (x1)-2) / ((3 * (x1) * (x1)) - 1));
    if ((((x2) * (x2) * (x2)) - (x2)-2) < 0.00001 &&
        (((x2) * (x2) * (x2)) - (x2)-2) > -0.00001) {
      root = x2;
      break;
    }
    x1 = x2;
  }
  printf("It took %d loops.\n", loopCounter);
  return root;
}


x86 assembly (clang, -O0):
<NewtonRaphson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xed8(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  0xe8b(%rip),%xmm2
subsd  %xmm2,%xmm1
movsd  0xe8f(%rip),%xmm2
mulsd  -0x10(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm3
mulsd  %xmm3,%xmm2
movsd  0xe71(%rip),%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe1d(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe09(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1269 <NewtonRaphson+0x159>
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdcc(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xdd8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1269 <NewtonRaphson+0x159>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1278 <NewtonRaphson+0x168>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    113c <NewtonRaphson+0x2c>
mov    -0x1c(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NewtonRaphson>:
push   %rax
xor    %esi,%esi
movsd  0xee5(%rip),%xmm7
movsd  0xee5(%rip),%xmm0
movsd  0xee5(%rip),%xmm1
movsd  0xee5(%rip),%xmm2
movsd  0xee5(%rip),%xmm3
movsd  0xee5(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%esi
movapd %xmm7,%xmm5
mulsd  %xmm7,%xmm5
mulsd  %xmm7,%xmm5
subsd  %xmm7,%xmm5
addsd  %xmm0,%xmm5
movapd %xmm7,%xmm6
mulsd  %xmm1,%xmm6
mulsd  %xmm7,%xmm6
addsd  %xmm2,%xmm6
divsd  %xmm6,%xmm5
subsd  %xmm5,%xmm7
movapd %xmm7,%xmm5
mulsd  %xmm7,%xmm5
mulsd  %xmm7,%xmm5
subsd  %xmm7,%xmm5
addsd  %xmm0,%xmm5
ucomisd %xmm5,%xmm3
jbe    1150 <NewtonRaphson+0x40>
ucomisd %xmm4,%xmm5
jbe    1150 <NewtonRaphson+0x40>
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
movsd  %xmm7,(%rsp)
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [19 x i8] c"It took %d loops.\0A\00"
define double @NewtonRaphson() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store double 0.000000e+00, double* %1
store double 1.000000e+00, double* %2
store double 0.000000e+00, double* %3
store i32 0, i32* %4
br label %5
5: ; preds = %0, %44
%6 = load i32, i32* %4
%7 = add nsw i32 %6, 1
store i32 %7, i32* %4
%8 = load double, double* %2
%9 = load double, double* %2
%10 = load double, double* %2
%11 = fmul double %9, %10
%12 = load double, double* %2
%13 = load double, double* %2
%14 = fneg double %13
%15 = call double @llvm.fmuladd.f64(double %11, double %12, double %14)
%16 = fsub double %15, 2.000000e+00
%17 = load double, double* %2
%18 = fmul double 3.000000e+00, %17
%19 = load double, double* %2
%20 = call double @llvm.fmuladd.f64(double %18, double %19, double -1.000000e+00)
%21 = fdiv double %16, %20
%22 = fsub double %8, %21
store double %22, double* %3
%23 = load double, double* %3
%24 = load double, double* %3
%25 = fmul double %23, %24
%26 = load double, double* %3
%27 = load double, double* %3
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %25, double %26, double %28)
%30 = fsub double %29, 2.000000e+00
%31 = fcmp olt double %30, 1.000000e-05
br i1 %31, label %32, label %44
32: ; preds = %5
%33 = load double, double* %3
%34 = load double, double* %3
%35 = fmul double %33, %34
%36 = load double, double* %3
%37 = load double, double* %3
%38 = fneg double %37
%39 = call double @llvm.fmuladd.f64(double %35, double %36, double %38)
%40 = fsub double %39, 2.000000e+00
%41 = fcmp ogt double %40, -1.000000e-05
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = load double, double* %3
store double %43, double* %1
br label %46
44: ; preds = %32, %5
%45 = load double, double* %3
store double %45, double* %2
br label %5
46: ; preds = %42
%47 = load i32, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = load double, double* %1
ret double %49
}

LLVM IR (-O2):
@.str = [19 x i8] c"It took %d loops.\0A\00"
define double @NewtonRaphson() {
br label %1
1: ; preds = %1, %0
%2 = phi double [ 1.000000e+00, %0 ], [ %12, %1 ]
%3 = phi i32 [ 0, %0 ], [ %4, %1 ]
%4 = add nuw nsw i32 %3, 1
%5 = fmul double %2, %2
%6 = fneg double %2
%7 = tail call double @llvm.fmuladd.f64(double %5, double %2, double %6)
%8 = fadd double %7, -2.000000e+00
%9 = fmul double %2, 3.000000e+00
%10 = tail call double @llvm.fmuladd.f64(double %9, double %2, double -1.000000e+00)
%11 = fdiv double %8, %10
%12 = fsub double %2, %11
%13 = fmul double %12, %12
%14 = fneg double %12
%15 = tail call double @llvm.fmuladd.f64(double %13, double %12, double %14)
%16 = fadd double %15, -2.000000e+00
%17 = fcmp olt double %16, 1.000000e-05
%18 = fcmp ogt double %16, -1.000000e-05
%19 = and i1 %17, %18
br i1 %19, label %20, label %1
20: ; preds = %1
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
ret double %12
}