#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 */
int /*<<< orphan*/ assert(int);
double fabs(double);
double g(double);
int /*<<< orphan*/ printf(char *, int, double);
double fixed(double guess, double epsilon, int iterations) {
  int i;
  double newGuess;
  assert(epsilon > 0.0);
  for (i = 0; i < iterations; i++) {
    printf("%d %g\n", i, guess);
    newGuess = g(guess);
    if (fabs(guess - newGuess) < epsilon)
      return newGuess;
    guess = newGuess;
  }
  return guess;
}


x86 assembly (clang, -O0):
<fixed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11df <fixed+0xaf>
mov    -0x20(%rbp),%esi
movsd  -0x10(%rbp),%xmm0
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
call   1050 <g@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movaps 0xe5b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c7 <fixed+0x97>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e9 <fixed+0xb9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1165 <fixed+0x35>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixed>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
movsd  %xmm0,(%rsp)
xorpd  %xmm0,%xmm0
xor    %edi,%edi
movsd  %xmm1,0x18(%rsp)
ucomisd %xmm0,%xmm1
seta   %dil
call   1040 <assert@plt>
test   %ebp,%ebp
jle    11ba <fixed+0x8a>
mov    $0x1,%ebx
lea    0xea8(%rip),%r14
movsd  (%rsp),%xmm1
nopl   (%rax)
movapd %xmm1,(%rsp)
lea    -0x1(%rbx),%esi
mov    %r14,%rdi
movapd %xmm1,%xmm0
call   1030 <printf@plt>
movapd (%rsp),%xmm0
call   1050 <g@plt>
movapd %xmm0,%xmm1
movapd (%rsp),%xmm2
subsd  %xmm0,%xmm2
andpd  0xe5d(%rip),%xmm2
movsd  0x18(%rsp),%xmm0
ucomisd %xmm2,%xmm0
ja     11bf <fixed+0x8f>
lea    0x1(%rbx),%eax
cmp    %ebp,%ebx
mov    %eax,%ebx
jl     1170 <fixed+0x40>
jmp    11bf <fixed+0x8f>
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d %g\0A\00"
define double @fixed(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
%10 = load double, double* %6
%11 = fcmp ogt double %10, 0.000000e+00
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
store i32 0, i32* %8
br label %14
14: ; preds = %34, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load i32, i32* %8
%20 = load double, double* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19, double %20)
%22 = load double, double* %5
%23 = call double @g(double %22)
store double %23, double* %9
%24 = load double, double* %5
%25 = load double, double* %9
%26 = fsub double %24, %25
%27 = call double @llvm.fabs.f64(double %26)
%28 = load double, double* %6
%29 = fcmp olt double %27, %28
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = load double, double* %9
store double %31, double* %4
br label %39
32: ; preds = %18
%33 = load double, double* %9
store double %33, double* %5
br label %34
34: ; preds = %32
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %14
37: ; preds = %14
%38 = load double, double* %5
store double %38, double* %4
br label %39
39: ; preds = %37, %30
%40 = load double, double* %4
ret double %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %g\0A\00"
define double @fixed(double %0, double %1, i32 %2) {
%4 = fcmp ogt double %1, 0.000000e+00
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %19
8: ; preds = %3, %8
%9 = phi i32 [ %16, %8 ], [ 0, %3 ]
%10 = phi double [ %12, %8 ], [ %0, %3 ]
%11 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, double %10)
%12 = tail call double @g(double %10)
%13 = fsub double %10, %12
%14 = tail call double @llvm.fabs.f64(double %13)
%15 = fcmp uge double %14, %1
%16 = add nuw nsw i32 %9, 1
%17 = icmp slt i32 %16, %2
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %8, label %19
19: ; preds = %8, %3
%20 = phi double [ %0, %3 ], [ %12, %8 ]
ret double %20
}