#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 *deriveEq(double *, size_t);
scalar_t__ fuzzyEquals(double, double);
double getValue(double *, size_t, double);
double getXNewtonRaphson(double *equation, size_t degree) {
  double *deriv = deriveEq(equation, degree), x = 1, f, d;
  for (int i = 0; i < 1000; i++) {
    f = getValue(equation, degree, x);
    d = getValue(deriv, degree - 1, x);
    if (fuzzyEquals(f, 0.0))
      return x;
    if (!fuzzyEquals(d, 0.0))
      x -= (f / d);
    else
      x++;
  }
  return x;
}


x86 assembly (clang, -O0):
<getXNewtonRaphson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <deriveEq@plt>
mov    %rax,-0x20(%rbp)
movsd  0xea7(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3e8,-0x3c(%rbp)
jge    1223 <getXNewtonRaphson+0xf3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x28(%rbp),%xmm0
call   1030 <getValue@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
movsd  -0x28(%rbp),%xmm0
call   1030 <getValue@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
call   1050 <fuzzyEquals@plt>
cmp    $0x0,%rax
je     11ca <getXNewtonRaphson+0x9a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122d <getXNewtonRaphson+0xfd>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
call   1050 <fuzzyEquals@plt>
cmp    $0x0,%rax
jne    11fe <getXNewtonRaphson+0xce>
movsd  -0x30(%rbp),%xmm1
divsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1210 <getXNewtonRaphson+0xe0>
movsd  0xdfa(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1215 <getXNewtonRaphson+0xe5>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1165 <getXNewtonRaphson+0x35>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getXNewtonRaphson>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <deriveEq@plt>
mov    %rax,%r15
lea    -0x1(%rbx),%r12
movsd  0xeaa(%rip),%xmm0
mov    $0x3e8,%ebp
jmp    1173 <getXNewtonRaphson+0x43>
nopl   (%rax)
movsd  0x8(%rsp),%xmm0
addsd  0xe92(%rip),%xmm0
add    $0xffffffff,%ebp
je     11ec <getXNewtonRaphson+0xbc>
mov    %r14,%rdi
mov    %rbx,%rsi
movsd  %xmm0,0x8(%rsp)
call   1030 <getValue@plt>
movsd  %xmm0,0x18(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
movsd  0x8(%rsp),%xmm0
call   1030 <getValue@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm1,%xmm1
movsd  0x18(%rsp),%xmm0
call   1050 <fuzzyEquals@plt>
test   %rax,%rax
jne    11e6 <getXNewtonRaphson+0xb6>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
call   1050 <fuzzyEquals@plt>
test   %rax,%rax
jne    1160 <getXNewtonRaphson+0x30>
movsd  0x18(%rsp),%xmm1
divsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0xffffffff,%ebp
jne    1173 <getXNewtonRaphson+0x43>
jmp    11ec <getXNewtonRaphson+0xbc>
movsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @getXNewtonRaphson(double* %0, i64 %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i64
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double* %0, double** %4
store i64 %1, i64* %5
%11 = load double*, double** %4
%12 = load i64, i64* %5
%13 = call double* @deriveEq(double* %11, i64 %12)
store double* %13, double** %6
store double 1.000000e+00, double* %7
store i32 0, i32* %10
br label %14
14: ; preds = %46, %2
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 1000
br i1 %16, label %17, label %49
17: ; preds = %14
%18 = load double*, double** %4
%19 = load i64, i64* %5
%20 = load double, double* %7
%21 = call double @getValue(double* %18, i64 %19, double %20)
store double %21, double* %8
%22 = load double*, double** %6
%23 = load i64, i64* %5
%24 = sub i64 %23, 1
%25 = load double, double* %7
%26 = call double @getValue(double* %22, i64 %24, double %25)
store double %26, double* %9
%27 = load double, double* %8
%28 = call i64 @fuzzyEquals(double %27, double 0.000000e+00)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = load double, double* %7
store double %31, double* %3
br label %51
32: ; preds = %17
%33 = load double, double* %9
%34 = call i64 @fuzzyEquals(double %33, double 0.000000e+00)
%35 = icmp ne i64 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %32
%37 = load double, double* %8
%38 = load double, double* %9
%39 = fdiv double %37, %38
%40 = load double, double* %7
%41 = fsub double %40, %39
store double %41, double* %7
br label %45
42: ; preds = %32
%43 = load double, double* %7
%44 = fadd double %43, 1.000000e+00
store double %44, double* %7
br label %45
45: ; preds = %42, %36
br label %46
46: ; preds = %45
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %14
49: ; preds = %14
%50 = load double, double* %7
store double %50, double* %3
br label %51
51: ; preds = %49, %30
%52 = load double, double* %3
ret double %52
}

LLVM IR (-O2):
define double @getXNewtonRaphson(double* %0, i64 %1) {
%3 = tail call double* @deriveEq(double* %0, i64 %1)
%4 = add i64 %1, -1
br label %5
5: ; preds = %2, %20
%6 = phi i32 [ 0, %2 ], [ %22, %20 ]
%7 = phi double [ 1.000000e+00, %2 ], [ %21, %20 ]
%8 = tail call double @getValue(double* %0, i64 %1, double %7)
%9 = tail call double @getValue(double* %3, i64 %4, double %7)
%10 = tail call i64 @fuzzyEquals(double %8, double 0.000000e+00)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %5
%13 = tail call i64 @fuzzyEquals(double %9, double 0.000000e+00)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = fdiv double %8, %9
%17 = fsub double %7, %16
br label %20
18: ; preds = %12
%19 = fadd double %7, 1.000000e+00
br label %20
20: ; preds = %15, %18
%21 = phi double [ %19, %18 ], [ %17, %15 ]
%22 = add nuw nsw i32 %6, 1
%23 = icmp eq i32 %22, 1000
br i1 %23, label %24, label %5
24: ; preds = %20, %5
%25 = phi double [ %21, %20 ], [ %7, %5 ]
ret double %25
}