#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 NumericalDifferantiation(double);
double TheFunction(double);
int fabs(double);
double NewtonRaphson(double x) {
  int maxIterationNumber = 100, n = 1;
  double xNext, fx, fprimex;
  while (n <= maxIterationNumber) {
    fx = TheFunction(x);
    fprimex = NumericalDifferantiation(x);
    xNext = x - fx / fprimex;
    if (fabs((xNext - x) / xNext) * 100 < 0.0001) {
      return xNext;
    } else {
      x = xNext;
    }
    n++;
  }
  return xNext;
}


x86 assembly (clang, -O0):
<NewtonRaphson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11e1 <NewtonRaphson+0xb1>
movsd  -0x10(%rbp),%xmm0
call   1030 <TheFunction@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <NumericalDifferantiation@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
divsd  -0x30(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
imul   $0x64,%eax,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe50(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c9 <NewtonRaphson+0x99>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11eb <NewtonRaphson+0xbb>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <NewtonRaphson+0x1b>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NewtonRaphson>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x8(%rsp)
mov    $0x63,%ebx
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1030 <TheFunction@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <NumericalDifferantiation@plt>
movsd  0x18(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm1
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
divsd  %xmm1,%xmm0
call   1040 <fabs@plt>
sub    $0x1,%ebx
setb   %cl
test   %eax,%eax
jle    119d <NewtonRaphson+0x6d>
test   %cl,%cl
je     1140 <NewtonRaphson+0x10>
movsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @NewtonRaphson(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store i32 100, i32* %4
store i32 1, i32* %5
br label %9
9: ; preds = %36, %1
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
%14 = load double, double* %3
%15 = call double @TheFunction(double %14)
store double %15, double* %7
%16 = load double, double* %3
%17 = call double @NumericalDifferantiation(double %16)
store double %17, double* %8
%18 = load double, double* %3
%19 = load double, double* %7
%20 = load double, double* %8
%21 = fdiv double %19, %20
%22 = fsub double %18, %21
store double %22, double* %6
%23 = load double, double* %6
%24 = load double, double* %3
%25 = fsub double %23, %24
%26 = load double, double* %6
%27 = fdiv double %25, %26
%28 = call i32 @fabs(double %27)
%29 = mul nsw i32 %28, 100
%30 = sitofp i32 %29 to double
%31 = fcmp olt double %30, 1.000000e-04
br i1 %31, label %32, label %34
32: ; preds = %13
%33 = load double, double* %6
store double %33, double* %2
br label %41
34: ; preds = %13
%35 = load double, double* %6
store double %35, double* %3
br label %36
36: ; preds = %34
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %9
39: ; preds = %9
%40 = load double, double* %6
store double %40, double* %2
br label %41
41: ; preds = %39, %32
%42 = load double, double* %2
ret double %42
}

LLVM IR (-O2):
define double @NewtonRaphson(double %0) {
br label %2
2: ; preds = %2, %1
%3 = phi double [ %0, %1 ], [ %8, %2 ]
%4 = phi i32 [ 1, %1 ], [ %13, %2 ]
%5 = tail call double @TheFunction(double %3)
%6 = tail call double @NumericalDifferantiation(double %3)
%7 = fdiv double %5, %6
%8 = fsub double %3, %7
%9 = fsub double %8, %3
%10 = fdiv double %9, %8
%11 = tail call i32 @fabs(double %10)
%12 = icmp slt i32 %11, 1
%13 = add nuw nsw i32 %4, 1
%14 = icmp eq i32 %13, 101
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %16, label %2
16: ; preds = %2
ret double %8
}