#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 */
typedef int /*<<< orphan*/ x;

/* Variables and functions */
double cbrt(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
double FixedPoint() {
  double root = 0;
  double x = 1;
  int loopCounter = 0;
  while (1) {
    loopCounter++;
    if ((x - (cbrt((x) + 2))) < 0.00001 && (x - (cbrt((x) + 2))) > -0.00001) {
      root = x;
      break;
    }
    x = (cbrt((x) + 2));
  }
  printf("It took %d loops.\n", loopCounter);
  return root;
}


x86 assembly (clang, -O0):
<FixedPoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xec8(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xeb1(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cbrt@plt>
movsd  -0x20(%rbp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d5 <FixedPoint+0xb5>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe76(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cbrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d5 <FixedPoint+0xb5>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f5 <FixedPoint+0xd5>
movsd  0xe33(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cbrt@plt>
movsd  %xmm0,-0x10(%rbp)
jmp    1144 <FixedPoint+0x24>
mov    -0x14(%rbp),%esi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FixedPoint>:
push   %rbp
push   %rbx
push   %rax
movsd  0xed5(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1,%ebx
jmp    114f <FixedPoint+0x2f>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <cbrt@plt>
movsd  %xmm0,(%rsp)
add    $0x1,%ebx
movsd  (%rsp),%xmm0
addsd  0xeac(%rip),%xmm0
cvttsd2si %xmm0,%ebp
mov    %ebp,%edi
call   1040 <cbrt@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xe98(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1140 <FixedPoint+0x20>
mov    %ebp,%edi
call   1040 <cbrt@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
ucomisd 0xe82(%rip),%xmm1
jbe    1140 <FixedPoint+0x20>
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"It took %d loops.\0A\00"
define double @FixedPoint() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
store double 0.000000e+00, double* %1
store double 1.000000e+00, double* %2
store i32 0, i32* %3
br label %4
4: ; preds = %0, %24
%5 = load i32, i32* %3
%6 = add nsw i32 %5, 1
store i32 %6, i32* %3
%7 = load double, double* %2
%8 = load double, double* %2
%9 = fadd double %8, 2.000000e+00
%10 = fptosi double %9 to i32
%11 = call double @cbrt(i32 %10)
%12 = fsub double %7, %11
%13 = fcmp olt double %12, 1.000000e-05
br i1 %13, label %14, label %24
14: ; preds = %4
%15 = load double, double* %2
%16 = load double, double* %2
%17 = fadd double %16, 2.000000e+00
%18 = fptosi double %17 to i32
%19 = call double @cbrt(i32 %18)
%20 = fsub double %15, %19
%21 = fcmp ogt double %20, -1.000000e-05
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = load double, double* %2
store double %23, double* %1
br label %29
24: ; preds = %14, %4
%25 = load double, double* %2
%26 = fadd double %25, 2.000000e+00
%27 = fptosi double %26 to i32
%28 = call double @cbrt(i32 %27)
store double %28, double* %2
br label %4
29: ; preds = %22
%30 = load i32, i32* %3
%31 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load double, double* %1
ret double %32
}

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