#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*/ exit(int);
double fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
double stub1(double);
double stub2(double);
double stub3(double);
double stub4(double);
double stub5(double);
double fmin_golden(double (*f)(double), double a, double b, double eps,
                   double *xmin) {
  double fx;
  int success = 0;
  double x1 = 0.6180339887498948482046 * a + 0.3819660112501051517954 * b;
  double x2 = 0.3819660112501051517954 * a + 0.6180339887498948482046 * b;
  double fx1 = (*f)(x1);
  double fx2 = (*f)(x2);
  for (int i = 0; i < 100; ++i) {
    if (fx1 < fx2) {
      b = x2;
      x2 = x1;
      fx2 = fx1;
      x1 = 0.6180339887498948482046 * a + 0.3819660112501051517954 * b;
      fx1 = (*f)(x1);
    } else {
      a = x1;
      x1 = x2;
      fx1 = fx2;
      x2 = 0.3819660112501051517954 * a + 0.6180339887498948482046 * b;
      fx2 = (*f)(x2);
    }
    if (fabs(b - a) < eps) {
      success = 1;
      break;
    }
  }
  if (success == 0) {
    fprintf(stderr, "fmin: Accuracy not reached in %i interations!", 100);
    exit(1);
  } else {
    *xmin = a + (b - a) / 2;
    fx = (*f)(*xmin);
    return fx;
  }
}


x86 assembly (clang, -O0):
<fmin_golden>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  0xea8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  0xe79(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x64,-0x5c(%rbp)
jge    12cb <fmin_golden+0x1ab>
movsd  -0x50(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1233 <fmin_golden+0x113>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdfc(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  0xdf7(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
jmp    1288 <fmin_golden+0x168>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xdaa(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  0xd95(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xd87(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12b8 <fmin_golden+0x198>
movl   $0x1,-0x34(%rbp)
jmp    12cb <fmin_golden+0x1ab>
jmp    12bd <fmin_golden+0x19d>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11bb <fmin_golden+0x9b>
cmpl   $0x0,-0x34(%rbp)
jne    12f9 <fmin_golden+0x1d9>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
mov    $0x64,%edx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  0xd00(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rcx),%xmm0
call   *%rax
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmin_golden>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
movsd  %xmm2,0x28(%rsp)
mov    %rdi,%rbp
movsd  0xec4(%rip),%xmm4
movapd %xmm1,%xmm3
mulsd  %xmm4,%xmm3
movsd  0xebc(%rip),%xmm2
movapd %xmm0,%xmm5
mulsd  %xmm2,%xmm5
addsd  %xmm3,%xmm5
movsd  %xmm5,0x20(%rsp)
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm3
mulsd  %xmm2,%xmm3
movsd  %xmm0,0x10(%rsp)
mulsd  %xmm4,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
movapd %xmm5,%xmm0
call   *%rdi
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
mov    %rbp,%rbx
call   *%rbp
movsd  0x20(%rsp),%xmm1
movsd  0x18(%rsp),%xmm8
movapd %xmm0,%xmm7
movsd  (%rsp),%xmm0
mov    $0x64,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
ucomisd %xmm0,%xmm7
movsd  %xmm8,0x18(%rsp)
movsd  %xmm1,0x20(%rsp)
jbe    1220 <fmin_golden+0x100>
movsd  %xmm0,(%rsp)
movapd %xmm8,%xmm3
mulsd  0xe1b(%rip),%xmm3
movsd  0x10(%rsp),%xmm0
mulsd  0xe15(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
call   *%rbx
movsd  0x8(%rsp),%xmm6
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm5
movsd  0x20(%rsp),%xmm8
movsd  (%rsp),%xmm7
jmp    126d <fmin_golden+0x14d>
nop
movsd  0x8(%rsp),%xmm2
mulsd  0xdda(%rip),%xmm2
movapd %xmm1,%xmm0
mulsd  0xdc6(%rip),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  %xmm7,(%rsp)
call   *%rbx
movsd  0x8(%rsp),%xmm5
movapd %xmm0,%xmm7
movsd  (%rsp),%xmm0
movsd  0x20(%rsp),%xmm4
movsd  0x18(%rsp),%xmm6
movsd  0x10(%rsp),%xmm8
movapd %xmm5,%xmm1
subsd  %xmm4,%xmm1
movapd %xmm1,%xmm2
andpd  0xd9f(%rip),%xmm2
movsd  0x28(%rsp),%xmm3
ucomisd %xmm2,%xmm3
ja     12ca <fmin_golden+0x1aa>
movsd  %xmm5,0x8(%rsp)
movsd  %xmm4,0x10(%rsp)
movapd %xmm6,%xmm1
add    $0xffffffff,%ebp
jne    11c0 <fmin_golden+0xa0>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
mov    $0x64,%edx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mulsd  0xd3e(%rip),%xmm1
addsd  %xmm1,%xmm4
movsd  %xmm4,(%r14)
movapd %xmm4,%xmm0
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    *%rax

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"fmin: Accuracy not reached in %i interations!\00"
define double @fmin_golden(double (double)* %0, double %1, double %2, double %3, double* %4) {
%6 = alloca double (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
%15 = alloca double
%16 = alloca double
%17 = alloca i32
store double (double)* %0, double (double)** %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double* %4, double** %10
store i32 0, i32* %12
%18 = load double, double* %7
%19 = load double, double* %8
%20 = fmul double 0x3FD8722191A02D61, %19
%21 = call double @llvm.fmuladd.f64(double 0x3FE3C6EF372FE950, double %18, double %20)
store double %21, double* %13
%22 = load double, double* %7
%23 = load double, double* %8
%24 = fmul double 0x3FE3C6EF372FE950, %23
%25 = call double @llvm.fmuladd.f64(double 0x3FD8722191A02D61, double %22, double %24)
store double %25, double* %14
%26 = load double (double)*, double (double)** %6
%27 = load double, double* %13
%28 = call double %26(double %27)
store double %28, double* %15
%29 = load double (double)*, double (double)** %6
%30 = load double, double* %14
%31 = call double %29(double %30)
store double %31, double* %16
store i32 0, i32* %17
br label %32
32: ; preds = %70, %5
%33 = load i32, i32* %17
%34 = icmp slt i32 %33, 100
br i1 %34, label %35, label %73
35: ; preds = %32
%36 = load double, double* %15
%37 = load double, double* %16
%38 = fcmp olt double %36, %37
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = load double, double* %14
store double %40, double* %8
%41 = load double, double* %13
store double %41, double* %14
%42 = load double, double* %15
store double %42, double* %16
%43 = load double, double* %7
%44 = load double, double* %8
%45 = fmul double 0x3FD8722191A02D61, %44
%46 = call double @llvm.fmuladd.f64(double 0x3FE3C6EF372FE950, double %43, double %45)
store double %46, double* %13
%47 = load double (double)*, double (double)** %6
%48 = load double, double* %13
%49 = call double %47(double %48)
store double %49, double* %15
br label %61
50: ; preds = %35
%51 = load double, double* %13
store double %51, double* %7
%52 = load double, double* %14
store double %52, double* %13
%53 = load double, double* %16
store double %53, double* %15
%54 = load double, double* %7
%55 = load double, double* %8
%56 = fmul double 0x3FE3C6EF372FE950, %55
%57 = call double @llvm.fmuladd.f64(double 0x3FD8722191A02D61, double %54, double %56)
store double %57, double* %14
%58 = load double (double)*, double (double)** %6
%59 = load double, double* %14
%60 = call double %58(double %59)
store double %60, double* %16
br label %61
61: ; preds = %50, %39
%62 = load double, double* %8
%63 = load double, double* %7
%64 = fsub double %62, %63
%65 = call double @llvm.fabs.f64(double %64)
%66 = load double, double* %9
%67 = fcmp olt double %65, %66
br i1 %67, label %68, label %69
68: ; preds = %61
store i32 1, i32* %12
br label %73
69: ; preds = %61
br label %70
70: ; preds = %69
%71 = load i32, i32* %17
%72 = add nsw i32 %71, 1
store i32 %72, i32* %17
br label %32
73: ; preds = %68, %32
%74 = load i32, i32* %12
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 100)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %73
%81 = load double, double* %7
%82 = load double, double* %8
%83 = load double, double* %7
%84 = fsub double %82, %83
%85 = fdiv double %84, 2.000000e+00
%86 = fadd double %81, %85
%87 = load double*, double** %10
store double %86, double* %87
%88 = load double (double)*, double (double)** %6
%89 = load double*, double** %10
%90 = load double, double* %89
%91 = call double %88(double %90)
store double %91, double* %11
%92 = load double, double* %11
ret double %92
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"fmin: Accuracy not reached in %i interations!\00"
define double @fmin_golden(double (double)* nocapture %0, double %1, double %2, double %3, double* nocapture writeonly %4) {
%6 = fmul double %2, 0x3FD8722191A02D61
%7 = tail call double @llvm.fmuladd.f64(double %1, double 0x3FE3C6EF372FE950, double %6)
%8 = fmul double %2, 0x3FE3C6EF372FE950
%9 = tail call double @llvm.fmuladd.f64(double %1, double 0x3FD8722191A02D61, double %8)
%10 = tail call double %0(double %7)
%11 = tail call double %0(double %9)
br label %15
12: ; preds = %32
%13 = add nuw nsw i32 %16, 1
%14 = icmp eq i32 %13, 100
br i1 %14, label %42, label %15
15: ; preds = %5, %12
%16 = phi i32 [ 0, %5 ], [ %13, %12 ]
%17 = phi double [ %11, %5 ], [ %38, %12 ]
%18 = phi double [ %10, %5 ], [ %37, %12 ]
%19 = phi double [ %9, %5 ], [ %36, %12 ]
%20 = phi double [ %7, %5 ], [ %35, %12 ]
%21 = phi double [ %1, %5 ], [ %34, %12 ]
%22 = phi double [ %2, %5 ], [ %33, %12 ]
%23 = fcmp olt double %18, %17
br i1 %23, label %24, label %28
24: ; preds = %15
%25 = fmul double %19, 0x3FD8722191A02D61
%26 = tail call double @llvm.fmuladd.f64(double %21, double 0x3FE3C6EF372FE950, double %25)
%27 = tail call double %0(double %26)
br label %32
28: ; preds = %15
%29 = fmul double %22, 0x3FE3C6EF372FE950
%30 = tail call double @llvm.fmuladd.f64(double %20, double 0x3FD8722191A02D61, double %29)
%31 = tail call double %0(double %30)
br label %32
32: ; preds = %28, %24
%33 = phi double [ %19, %24 ], [ %22, %28 ]
%34 = phi double [ %21, %24 ], [ %20, %28 ]
%35 = phi double [ %26, %24 ], [ %19, %28 ]
%36 = phi double [ %20, %24 ], [ %30, %28 ]
%37 = phi double [ %27, %24 ], [ %17, %28 ]
%38 = phi double [ %18, %24 ], [ %31, %28 ]
%39 = fsub double %33, %34
%40 = tail call double @llvm.fabs.f64(double %39)
%41 = fcmp olt double %40, %3
br i1 %41, label %46, label %12
42: ; preds = %12
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 100)
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %32
%47 = fmul double %39, 5.000000e-01
%48 = fadd double %34, %47
store double %48, double* %4
%49 = tail call double %0(double %48)
ret double %49
}