#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 M_PI;
int /*<<< orphan*/ assert(int);
double fabs(double);
double function(float);
int /*<<< orphan*/ printf(char *, double, int, ...);
int main() {
  unsigned int num_iterations = 10;
  double x0 = 0.3f;
  double x1;
  double x2 = 3.1f;
  double tol = 1e-6f;
  double y0 = function(x0);
  double y1;
  double y2 = function(x2);
  double x_hat;
  double del = 0.0f;
  unsigned int i;
  for (i = 0; i < num_iterations; i++) {
    x1 = 0.5f * (x0 + x2);
    y1 = function(0.5f * (x0 + x2));
    assert(x2 > x1);
    assert(x1 > x0);
    double t0 = y0 * (x1 * x1 - x2 * x2) + y1 * (x2 * x2 - x0 * x0) +
                y2 * (x0 * x0 - x1 * x1);
    double t1 = y0 * (x1 - x2) + y1 * (x2 - x0) + y2 * (x0 - x1);
    x_hat = 0.5f * t0 / t1;
    del = x_hat - x1;
    printf("%4u : %12.8f, e=%12.4e\n", i, x_hat, x_hat - M_PI / 2);
    if (x_hat > x1) {
      x0 = x1;
      y0 = y1;
    } else {
      x2 = x1;
      y2 = y1;
    }
    if (fabs(del) < tol)
      break;
  }
  printf("estimated minimum : %f (%f)\n", x_hat, M_PI / 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movsd  0xec2(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xead(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe98(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <function@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <function@plt>
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1398 <main+0x268>
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe54(%rip),%xmm1
movsd  %xmm1,-0x70(%rbp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <function@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x70(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm4
movsd  -0x20(%rbp),%xmm6
mulsd  %xmm6,%xmm6
mulsd  %xmm4,%xmm4
movaps %xmm4,%xmm5
subsd  %xmm6,%xmm5
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm3
mulsd  %xmm3,%xmm3
subsd  %xmm3,%xmm6
mulsd  %xmm6,%xmm0
mulsd  %xmm5,%xmm2
addsd  %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
subsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm4
movsd  -0x20(%rbp),%xmm6
movaps %xmm4,%xmm5
subsd  %xmm6,%xmm5
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm3
subsd  %xmm3,%xmm6
mulsd  %xmm6,%xmm0
mulsd  %xmm5,%xmm2
addsd  %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
subsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x54(%rbp),%eax
cvtsi2sd %rax,%xmm0
cvttsd2si -0x48(%rbp),%esi
movsd  -0x48(%rbp),%xmm1
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm2
subsd  %xmm2,%xmm1
lea    0xd13(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x48(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    134d <main+0x21d>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1361 <main+0x231>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x50(%rbp),%xmm1
movaps 0xcb3(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1385 <main+0x255>
jmp    1398 <main+0x268>
jmp    138a <main+0x25a>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11a2 <main+0x72>
movsd  -0x48(%rbp),%xmm0
mov    0x2c44(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xc91(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
movss  0xec0(%rip),%xmm0
call   1050 <function@plt>
movsd  %xmm0,0x28(%rsp)
movss  0xeb1(%rip),%xmm0
call   1050 <function@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0xea2(%rip),%xmm0
movsd  %xmm0,(%rsp)
xor    %ebp,%ebp
movsd  0xe9b(%rip),%xmm0
mov    0x2e6c(%rip),%rbx
lea    0xebd(%rip),%r14
jmp    11c2 <main+0x92>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  %xmm2,(%rsp)
movapd %xmm2,%xmm0
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
add    $0x1,%ebp
cmp    $0xa,%ebp
je     1358 <main+0x228>
movapd %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0xe3f(%rip),%xmm0
mulsd  %xmm0,%xmm1
movapd %xmm1,0x30(%rsp)
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1050 <function@plt>
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
movsd  (%rsp),%xmm0
ucomisd 0x30(%rsp),%xmm0
seta   %dil
call   1040 <assert@plt>
xor    %edi,%edi
movapd 0x30(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
seta   %dil
call   1040 <assert@plt>
movapd 0x30(%rsp),%xmm9
movapd %xmm9,%xmm0
mulsd  %xmm9,%xmm0
movsd  (%rsp),%xmm6
movapd %xmm6,%xmm1
mulsd  %xmm6,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movapd 0x10(%rsp),%xmm5
mulsd  %xmm5,%xmm5
subsd  %xmm5,%xmm1
movsd  0x8(%rsp),%xmm7
mulsd  %xmm7,%xmm1
movsd  0x28(%rsp),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm0,%xmm5
movsd  0x20(%rsp),%xmm4
mulsd  %xmm4,%xmm5
addsd  %xmm2,%xmm5
movapd %xmm5,%xmm8
movapd %xmm9,%xmm2
movapd %xmm9,%xmm0
movapd %xmm6,%xmm1
subsd  %xmm6,%xmm0
subsd  0x10(%rsp),%xmm1
mulsd  %xmm7,%xmm1
mulsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
movapd 0x10(%rsp),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm4,%xmm1
addsd  %xmm0,%xmm1
mulsd  0xd54(%rip),%xmm8
divsd  %xmm1,%xmm8
movapd %xmm8,%xmm1
movapd %xmm8,0x40(%rsp)
subsd  %xmm2,%xmm1
mov    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
cvttsd2si %xmm8,%esi
andpd  0xd40(%rip),%xmm1
movapd %xmm1,0x50(%rsp)
mov    (%rbx),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movapd %xmm8,%xmm1
subsd  %xmm2,%xmm1
mov    %r14,%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movapd 0x40(%rsp),%xmm3
movapd 0x10(%rsp),%xmm1
movsd  0xcf1(%rip),%xmm0
ucomisd 0x50(%rsp),%xmm0
ja     1358 <main+0x228>
movapd 0x30(%rsp),%xmm2
ucomisd %xmm2,%xmm3
jbe    1190 <main+0x60>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
jmp    11a1 <main+0x71>
mov    (%rbx),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
lea    0xcee(%rip),%rdi
movapd %xmm3,%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%4u : %12.8f, e=%12.4e\0A\00"
@M_PI = global i32 0
@.str.1 = [29 x i8] c"estimated minimum : %f (%f)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i32 0, i32* %1
store i32 10, i32* %2
store double 0x3FD3333340000000, double* %3
store double 0x4008CCCCC0000000, double* %5
store double 0x3EB0C6F7A0000000, double* %6
%15 = load double, double* %3
%16 = fptrunc double %15 to float
%17 = call double @function(float %16)
store double %17, double* %7
%18 = load double, double* %5
%19 = fptrunc double %18 to float
%20 = call double @function(float %19)
store double %20, double* %9
store double 0.000000e+00, double* %11
store i32 0, i32* %12
br label %21
21: ; preds = %121, %0
%22 = load i32, i32* %12
%23 = load i32, i32* %2
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %124
25: ; preds = %21
%26 = load double, double* %3
%27 = load double, double* %5
%28 = fadd double %26, %27
%29 = fmul double 5.000000e-01, %28
store double %29, double* %4
%30 = load double, double* %3
%31 = load double, double* %5
%32 = fadd double %30, %31
%33 = fmul double 5.000000e-01, %32
%34 = fptrunc double %33 to float
%35 = call double @function(float %34)
store double %35, double* %8
%36 = load double, double* %5
%37 = load double, double* %4
%38 = fcmp ogt double %36, %37
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load double, double* %4
%42 = load double, double* %3
%43 = fcmp ogt double %41, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load double, double* %7
%47 = load double, double* %4
%48 = load double, double* %4
%49 = load double, double* %5
%50 = load double, double* %5
%51 = fmul double %49, %50
%52 = fneg double %51
%53 = call double @llvm.fmuladd.f64(double %47, double %48, double %52)
%54 = load double, double* %8
%55 = load double, double* %5
%56 = load double, double* %5
%57 = load double, double* %3
%58 = load double, double* %3
%59 = fmul double %57, %58
%60 = fneg double %59
%61 = call double @llvm.fmuladd.f64(double %55, double %56, double %60)
%62 = fmul double %54, %61
%63 = call double @llvm.fmuladd.f64(double %46, double %53, double %62)
%64 = load double, double* %9
%65 = load double, double* %3
%66 = load double, double* %3
%67 = load double, double* %4
%68 = load double, double* %4
%69 = fmul double %67, %68
%70 = fneg double %69
%71 = call double @llvm.fmuladd.f64(double %65, double %66, double %70)
%72 = call double @llvm.fmuladd.f64(double %64, double %71, double %63)
store double %72, double* %13
%73 = load double, double* %7
%74 = load double, double* %4
%75 = load double, double* %5
%76 = fsub double %74, %75
%77 = load double, double* %8
%78 = load double, double* %5
%79 = load double, double* %3
%80 = fsub double %78, %79
%81 = fmul double %77, %80
%82 = call double @llvm.fmuladd.f64(double %73, double %76, double %81)
%83 = load double, double* %9
%84 = load double, double* %3
%85 = load double, double* %4
%86 = fsub double %84, %85
%87 = call double @llvm.fmuladd.f64(double %83, double %86, double %82)
store double %87, double* %14
%88 = load double, double* %13
%89 = fmul double 5.000000e-01, %88
%90 = load double, double* %14
%91 = fdiv double %89, %90
store double %91, double* %10
%92 = load double, double* %10
%93 = load double, double* %4
%94 = fsub double %92, %93
store double %94, double* %11
%95 = load i32, i32* %12
%96 = uitofp i32 %95 to double
%97 = load double, double* %10
%98 = fptosi double %97 to i32
%99 = load double, double* %10
%100 = load i32, i32* @M_PI
%101 = sdiv i32 %100, 2
%102 = sitofp i32 %101 to double
%103 = fsub double %99, %102
%104 = call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %96, i32 %98, double %103)
%105 = load double, double* %10
%106 = load double, double* %4
%107 = fcmp ogt double %105, %106
br i1 %107, label %108, label %111
108: ; preds = %25
%109 = load double, double* %4
store double %109, double* %3
%110 = load double, double* %8
store double %110, double* %7
br label %114
111: ; preds = %25
%112 = load double, double* %4
store double %112, double* %5
%113 = load double, double* %8
store double %113, double* %9
br label %114
114: ; preds = %111, %108
%115 = load double, double* %11
%116 = call double @llvm.fabs.f64(double %115)
%117 = load double, double* %6
%118 = fcmp olt double %116, %117
br i1 %118, label %119, label %120
119: ; preds = %114
br label %124
120: ; preds = %114
br label %121
121: ; preds = %120
%122 = load i32, i32* %12
%123 = add i32 %122, 1
store i32 %123, i32* %12
br label %21
124: ; preds = %119, %21
%125 = load double, double* %10
%126 = load i32, i32* @M_PI
%127 = sdiv i32 %126, 2
%128 = call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %125, i32 %127)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"%4u : %12.8f, e=%12.4e\0A\00"
@M_PI = global i32 0
@.str.1 = [29 x i8] c"estimated minimum : %f (%f)\0A\00"
define i32 @main() {
%1 = tail call double @function(float 0x3FD3333340000000)
%2 = tail call double @function(float 0x4008CCCCC0000000)
br label %3
3: ; preds = %0, %50
%4 = phi double [ 0x3FD3333340000000, %0 ], [ %51, %50 ]
%5 = phi i32 [ 0, %0 ], [ %55, %50 ]
%6 = phi double [ %2, %0 ], [ %52, %50 ]
%7 = phi double [ 0x4008CCCCC0000000, %0 ], [ %53, %50 ]
%8 = phi double [ %1, %0 ], [ %54, %50 ]
%9 = fadd double %7, %4
%10 = fmul double %9, 5.000000e-01
%11 = fptrunc double %10 to float
%12 = tail call double @function(float %11)
%13 = fcmp ogt double %7, %10
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = fcmp ogt double %10, %4
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = fneg double %7
%20 = fmul double %7, %19
%21 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %20)
%22 = fneg double %4
%23 = fmul double %4, %22
%24 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %23)
%25 = fmul double %24, %12
%26 = tail call double @llvm.fmuladd.f64(double %8, double %21, double %25)
%27 = fneg double %10
%28 = fmul double %10, %27
%29 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %28)
%30 = tail call double @llvm.fmuladd.f64(double %6, double %29, double %26)
%31 = fsub double %10, %7
%32 = fsub double %7, %4
%33 = fmul double %32, %12
%34 = tail call double @llvm.fmuladd.f64(double %8, double %31, double %33)
%35 = fsub double %4, %10
%36 = tail call double @llvm.fmuladd.f64(double %6, double %35, double %34)
%37 = fmul double %30, 5.000000e-01
%38 = fdiv double %37, %36
%39 = fsub double %38, %10
%40 = uitofp i32 %5 to double
%41 = fptosi double %38 to i32
%42 = load i32, i32* @M_PI
%43 = sdiv i32 %42, 2
%44 = sitofp i32 %43 to double
%45 = fsub double %38, %44
%46 = tail call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %40, i32 %41, double %45)
%47 = fcmp ogt double %38, %10
%48 = tail call double @llvm.fabs.f64(double %39)
%49 = fcmp olt double %48, 0x3EB0C6F7A0000000
br i1 %49, label %57, label %50
50: ; preds = %3
%51 = select i1 %47, double %10, double %4
%52 = select i1 %47, double %6, double %12
%53 = select i1 %47, double %7, double %10
%54 = select i1 %47, double %12, double %8
%55 = add nuw nsw i32 %5, 1
%56 = icmp eq i32 %55, 10
br i1 %56, label %57, label %3
57: ; preds = %3, %50
%58 = load i32, i32* @M_PI
%59 = sdiv i32 %58, 2
%60 = tail call i32 (i8*, double, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %38, i32 %59)
ret i32 0
}