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


x86 assembly (clang, -O0):
<OnePointIteration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1199 <OnePointIteration+0x89>
movsd  -0x10(%rbp),%xmm0
call   1030 <TheFunction@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
movaps 0xeb4(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe98(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1181 <OnePointIteration+0x71>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1199 <OnePointIteration+0x89>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112b <OnePointIteration+0x1b>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OnePointIteration>:
push   %rbx
sub    $0x10,%rsp
mov    $0x63,%ebx
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
call   1030 <TheFunction@plt>
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
andpd  0xebf(%rip),%xmm1
sub    $0x1,%ebx
setb   %al
movsd  0xec1(%rip),%xmm2
ucomisd %xmm1,%xmm2
ja     1159 <OnePointIteration+0x49>
test   %al,%al
je     1120 <OnePointIteration+0x10>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @OnePointIteration(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store double %0, double* %3
store i32 100, i32* %4
store i32 1, i32* %5
br label %7
7: ; preds = %25, %1
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load double, double* %3
%13 = call double @TheFunction(double %12)
store double %13, double* %6
%14 = load double, double* %6
%15 = load double, double* %3
%16 = fsub double %14, %15
%17 = load double, double* %6
%18 = fdiv double %16, %17
%19 = call double @llvm.fabs.f64(double %18)
%20 = fcmp olt double %19, 1.000000e-04
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = load double, double* %6
store double %22, double* %2
br label %28
23: ; preds = %11
%24 = load double, double* %6
store double %24, double* %3
br label %25
25: ; preds = %23
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %7
28: ; preds = %21, %7
%29 = load double, double* %2
ret double %29
}

LLVM IR (-O2):
define double @OnePointIteration(double %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 1, %1 ], [ %10, %2 ]
%4 = phi double [ %0, %1 ], [ %5, %2 ]
%5 = tail call double @TheFunction(double %4)
%6 = fsub double %5, %4
%7 = fdiv double %6, %5
%8 = tail call double @llvm.fabs.f64(double %7)
%9 = fcmp olt double %8, 1.000000e-04
%10 = add nuw nsw i32 %3, 1
%11 = icmp eq i32 %10, 101
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %2
13: ; preds = %2
ret double %5
}