#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(double);
int /*<<< orphan*/ printf(char *, double, int, ...);
int main() {
  unsigned int num_iterations = 10;
  double x0;
  double x1 = 1.2f;
  double x2;
  double dx = 2.0f;
  double gamma = 0.7f;
  double tol = 1e-6f;
  x0 = x1 - dx;
  x2 = x1 + dx;
  double y0, y1, y2;
  double x_hat;
  double del = 0.0f;
  unsigned int i;
  for (i = 0; i < num_iterations; i++) {
    x1 = 0.5f * (x0 + x2);
    y0 = function(x0);
    y1 = function(x1);
    y2 = function(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, del: %12.4e\n", i, x_hat, x_hat - M_PI / 2,
           del);
    dx *= gamma;
    x0 = x_hat - dx;
    x2 = x_hat + dx;
    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    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movsd  0xec7(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe88(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    13a2 <main+0x272>
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe54(%rip),%xmm1
movsd  %xmm1,-0x80(%rbp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <function@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <function@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <function@plt>
movsd  %xmm0,-0x50(%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  -0x80(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm4
movsd  -0x20(%rbp),%xmm6
mulsd  %xmm6,%xmm6
mulsd  %xmm4,%xmm4
movaps %xmm4,%xmm5
subsd  %xmm6,%xmm5
movsd  -0x48(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm3
mulsd  %xmm3,%xmm3
subsd  %xmm3,%xmm6
mulsd  %xmm6,%xmm0
mulsd  %xmm5,%xmm2
addsd  %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
subsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm4
movsd  -0x20(%rbp),%xmm6
movaps %xmm4,%xmm5
subsd  %xmm6,%xmm5
movsd  -0x48(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm3
subsd  %xmm3,%xmm6
mulsd  %xmm6,%xmm0
mulsd  %xmm5,%xmm2
addsd  %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
subsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x78(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x64(%rbp),%eax
cvtsi2sd %rax,%xmm0
cvttsd2si -0x58(%rbp),%esi
movsd  -0x58(%rbp),%xmm1
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm2
subsd  %xmm2,%xmm1
movsd  -0x60(%rbp),%xmm2
lea    0xd09(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x60(%rbp),%xmm1
movaps 0xcb9(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    138f <main+0x25f>
jmp    13a2 <main+0x272>
jmp    1394 <main+0x264>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11aa <main+0x7a>
movsd  -0x58(%rbp),%xmm0
mov    0x2c3a(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xca4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
movsd  0xec0(%rip),%xmm3
movsd  0xec0(%rip),%xmm2
xor    %ebp,%ebp
movsd  0xebe(%rip),%xmm1
mov    0x2e8f(%rip),%rbx
lea    0xee0(%rip),%r14
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x28(%rsp)
movsd  %xmm3,0x48(%rsp)
movapd %xmm2,%xmm3
addsd  %xmm1,%xmm3
movsd  0xe96(%rip),%xmm0
mulsd  %xmm0,%xmm3
movsd  %xmm3,0x10(%rsp)
movapd %xmm1,%xmm0
call   1050 <function@plt>
movsd  %xmm0,0x40(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <function@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <function@plt>
movsd  %xmm0,0x38(%rsp)
xor    %edi,%edi
movsd  0x8(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
seta   %dil
call   1040 <assert@plt>
xor    %edi,%edi
movsd  0x10(%rsp),%xmm0
ucomisd 0x28(%rsp),%xmm0
seta   %dil
call   1040 <assert@plt>
movsd  0x10(%rsp),%xmm8
movapd %xmm8,%xmm0
mulsd  %xmm8,%xmm0
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  0x28(%rsp),%xmm9
movapd %xmm9,%xmm4
mulsd  %xmm9,%xmm4
subsd  %xmm4,%xmm1
movsd  0x30(%rsp),%xmm6
mulsd  %xmm6,%xmm1
movsd  0x40(%rsp),%xmm5
mulsd  %xmm5,%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm0,%xmm4
movsd  0x38(%rsp),%xmm7
mulsd  %xmm7,%xmm4
addsd  %xmm2,%xmm4
movapd %xmm8,%xmm1
movapd %xmm8,%xmm0
subsd  %xmm3,%xmm0
movapd %xmm9,%xmm2
subsd  %xmm9,%xmm3
mulsd  %xmm6,%xmm3
mulsd  %xmm5,%xmm0
addsd  %xmm3,%xmm0
subsd  %xmm1,%xmm2
mulsd  %xmm7,%xmm2
addsd  %xmm0,%xmm2
mulsd  0xd8f(%rip),%xmm4
divsd  %xmm2,%xmm4
movapd %xmm4,%xmm2
mov    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
cvttsd2si %xmm4,%esi
movsd  %xmm4,0x8(%rsp)
subsd  %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
mov    (%rbx),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm3,%xmm3
cvtsi2sd %ecx,%xmm3
movapd %xmm4,%xmm1
subsd  %xmm3,%xmm1
mov    %r14,%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x48(%rsp),%xmm3
mulsd  0xd39(%rip),%xmm3
movapd 0x10(%rsp),%xmm2
andpd  0xd3b(%rip),%xmm2
movsd  0xd2b(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     131f <main+0x1ef>
movapd %xmm3,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm0,%xmm1
subsd  %xmm3,%xmm1
add    $0x1,%ebp
cmp    $0xa,%ebp
jne    1160 <main+0x30>
mov    (%rbx),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
lea    0xd34(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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