#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 FalsePosition(double a, double b) {
  int maxIterationNumber = 100, n = 1;
  double c, fa, fb, fc, nonChangingPoint;
  while (n <= maxIterationNumber) {
    fa = TheFunction(a);
    fb = TheFunction(b);
    c = b - ((fb * (a - b)) / (fa - fb));
    fc = TheFunction(c);
    if (c < 0) {
      a = c;
      nonChangingPoint = b;
    } else {
      b = c;
      nonChangingPoint = a;
    }
    if (fabs(nonChangingPoint - c) < 0.0001) {
      return c;
    }
    ++n;
  }
  return c;
}


x86 assembly (clang, -O0):
<FalsePosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x64,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1217 <FalsePosition+0x107>
movsd  -0x10(%rbp),%xmm0
call   1030 <TheFunction@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <TheFunction@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x38(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <TheFunction@plt>
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11bf <FalsePosition+0xaf>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    11d3 <FalsePosition+0xc3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movaps 0xe2c(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe10(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1209 <FalsePosition+0xf9>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1221 <FalsePosition+0x111>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1130 <FalsePosition+0x20>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FalsePosition>:
push   %rbx
sub    $0x30,%rsp
movapd %xmm1,(%rsp)
mov    $0x64,%ebx
jmp    1141 <FalsePosition+0x31>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
andpd  %xmm5,%xmm1
orpd   %xmm1,%xmm0
add    $0xffffffff,%ebx
je     11e7 <FalsePosition+0xd7>
movaps %xmm0,0x20(%rsp)
call   1030 <TheFunction@plt>
movsd  %xmm0,0x10(%rsp)
movapd (%rsp),%xmm0
call   1030 <TheFunction@plt>
movapd 0x20(%rsp),%xmm1
movapd (%rsp),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm3
subsd  %xmm0,%xmm3
divsd  %xmm3,%xmm1
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <TheFunction@plt>
movapd 0x10(%rsp),%xmm5
xorpd  %xmm3,%xmm3
movapd %xmm5,%xmm1
cmpltsd %xmm3,%xmm1
movapd %xmm1,%xmm2
andpd  (%rsp),%xmm2
movapd %xmm1,%xmm0
andnpd 0x20(%rsp),%xmm0
orpd   %xmm0,%xmm2
subsd  %xmm5,%xmm2
andpd  0xe3b(%rip),%xmm2
movsd  0xe43(%rip),%xmm4
ucomisd %xmm2,%xmm4
ja     11e7 <FalsePosition+0xd7>
ucomisd %xmm5,%xmm3
ja     1130 <FalsePosition+0x20>
movapd %xmm5,(%rsp)
jmp    1130 <FalsePosition+0x20>
movapd %xmm5,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @FalsePosition(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double %0, double* %4
store double %1, double* %5
store i32 100, i32* %6
store i32 1, i32* %7
br label %13
13: ; preds = %51, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %54
17: ; preds = %13
%18 = load double, double* %4
%19 = call double @TheFunction(double %18)
store double %19, double* %9
%20 = load double, double* %5
%21 = call double @TheFunction(double %20)
store double %21, double* %10
%22 = load double, double* %5
%23 = load double, double* %10
%24 = load double, double* %4
%25 = load double, double* %5
%26 = fsub double %24, %25
%27 = fmul double %23, %26
%28 = load double, double* %9
%29 = load double, double* %10
%30 = fsub double %28, %29
%31 = fdiv double %27, %30
%32 = fsub double %22, %31
store double %32, double* %8
%33 = load double, double* %8
%34 = call double @TheFunction(double %33)
store double %34, double* %11
%35 = load double, double* %8
%36 = fcmp olt double %35, 0.000000e+00
br i1 %36, label %37, label %40
37: ; preds = %17
%38 = load double, double* %8
store double %38, double* %4
%39 = load double, double* %5
store double %39, double* %12
br label %43
40: ; preds = %17
%41 = load double, double* %8
store double %41, double* %5
%42 = load double, double* %4
store double %42, double* %12
br label %43
43: ; preds = %40, %37
%44 = load double, double* %12
%45 = load double, double* %8
%46 = fsub double %44, %45
%47 = call double @llvm.fabs.f64(double %46)
%48 = fcmp olt double %47, 1.000000e-04
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = load double, double* %8
store double %50, double* %3
br label %56
51: ; preds = %43
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %13
54: ; preds = %13
%55 = load double, double* %8
store double %55, double* %3
br label %56
56: ; preds = %54, %49
%57 = load double, double* %3
ret double %57
}

LLVM IR (-O2):
define double @FalsePosition(double %0, double %1) {
br label %3
3: ; preds = %2, %20
%4 = phi double [ %0, %2 ], [ %21, %20 ]
%5 = phi double [ %1, %2 ], [ %22, %20 ]
%6 = phi i32 [ 1, %2 ], [ %23, %20 ]
%7 = tail call double @TheFunction(double %4)
%8 = tail call double @TheFunction(double %5)
%9 = fsub double %4, %5
%10 = fmul double %9, %8
%11 = fsub double %7, %8
%12 = fdiv double %10, %11
%13 = fsub double %5, %12
%14 = tail call double @TheFunction(double %13)
%15 = fcmp olt double %13, 0.000000e+00
%16 = select i1 %15, double %5, double %4
%17 = fsub double %16, %13
%18 = tail call double @llvm.fabs.f64(double %17)
%19 = fcmp olt double %18, 1.000000e-04
br i1 %19, label %25, label %20
20: ; preds = %3
%21 = select i1 %15, double %13, double %4
%22 = select i1 %15, double %5, double %13
%23 = add nuw nsw i32 %6, 1
%24 = icmp eq i32 %23, 101
br i1 %24, label %25, label %3
25: ; preds = %20, %3
ret double %13
}