#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 fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double, int);
int /*<<< orphan*/ stdout;
double fixedPointIteration(double (*f)(double), double x) {
  int i;
  double err;
  i = 0;
  err = 1.0;
  while ((err > 1e-9) && (i < 200)) {
    x = f(x);
    err = fabs(f(x) - x);
    i++;
  }
  fprintf(stdout, "Fixed Point Iteration: %f %f %d\n", x, err, i);
  return x;
}


x86 assembly (clang, -O0):
<fixedPointIteration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xor    %eax,%eax
movsd  0xec4(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jbe    115e <fixedPointIteration+0x4e>
cmpl   $0xc8,-0x14(%rbp)
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    116e <fixedPointIteration+0x5e>
jmp    11ac <fixedPointIteration+0x9c>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
subsd  -0x10(%rbp),%xmm0
movaps 0xe7b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1135 <fixedPointIteration+0x25>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x14(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixedPointIteration>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
call   *%r14
movsd  %xmm0,(%rsp)
call   *%r14
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm0,%xmm1
andpd  0xec0(%rip),%xmm1
lea    0x1(%rbx),%edx
ucomisd 0xec5(%rip),%xmm1
jbe    1157 <fixedPointIteration+0x47>
cmp    $0xc7,%ebx
mov    %edx,%ebx
jb     1120 <fixedPointIteration+0x10>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xeb1(%rip),%rsi
call   1030 <fprintf@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [33 x i8] c"Fixed Point Iteration: %f %f %d\0A\00"
define double @fixedPointIteration(double (double)* %0, double %1) {
%3 = alloca double (double)*
%4 = alloca double
%5 = alloca i32
%6 = alloca double
store double (double)* %0, double (double)** %3
store double %1, double* %4
store i32 0, i32* %5
store double 1.000000e+00, double* %6
br label %7
7: ; preds = %15, %2
%8 = load double, double* %6
%9 = fcmp ogt double %8, 1.000000e-09
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 200
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ false, %7 ], [ %12, %10 ]
br i1 %14, label %15, label %27
15: ; preds = %13
%16 = load double (double)*, double (double)** %3
%17 = load double, double* %4
%18 = call double %16(double %17)
store double %18, double* %4
%19 = load double (double)*, double (double)** %3
%20 = load double, double* %4
%21 = call double %19(double %20)
%22 = load double, double* %4
%23 = fsub double %21, %22
%24 = call double @llvm.fabs.f64(double %23)
store double %24, double* %6
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %7
27: ; preds = %13
%28 = load i32, i32* @stdout
%29 = load double, double* %4
%30 = load double, double* %6
%31 = load i32, i32* %5
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %29, double %30, i32 %31)
%33 = load double, double* %4
ret double %33
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [33 x i8] c"Fixed Point Iteration: %f %f %d\0A\00"
define double @fixedPointIteration(double (double)* nocapture %0, double %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 0, %2 ], [ %10, %3 ]
%5 = phi double [ %1, %2 ], [ %6, %3 ]
%6 = tail call double %0(double %5)
%7 = tail call double %0(double %6)
%8 = fsub double %7, %6
%9 = tail call double @llvm.fabs.f64(double %8)
%10 = add nuw nsw i32 %4, 1
%11 = fcmp ogt double %9, 1.000000e-09
%12 = icmp ult i32 %4, 199
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %3, label %14
14: ; preds = %3
%15 = load i32, i32* @stdout
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %6, double %9, i32 %10)
ret double %6
}