#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*/ golden_section_probe(int *, double *, double, double,
                                        double);
int /*<<< orphan*/ insert_new_trap_point(double *, double *, double *, double *,
                                         double *, double *, double, double);
scalar_t__ numcmp(double, double);
double stub1(double);
void trap_minimum(double *pf0, double *pf1, double *pf2, double *px0,
                  double *px1, double *px2, double f_goal,
                  double (*pfunction)(double x), int max_iterations) {
  double xnew, fnew;
  int success;
  int improvement_count;
  improvement_count = 0;
  if ((numcmp(*pf0, f_goal) <= 0) || (numcmp(*pf2, f_goal) <= 0))
    ++improvement_count;
  while ((numcmp(*pf0, *pf1) > 0) || (numcmp(*pf2, *pf1) > 0)) {
    if (improvement_count >= max_iterations)
      break;
    golden_section_probe(&success, &xnew, *px0, *px1, *px2);
    if (!success)
      break;
    fnew = (*pfunction)(xnew);
    insert_new_trap_point(pf0, pf1, pf2, px0, px1, px2, xnew, fnew);
    if ((numcmp(*pf1, f_goal) <= 0) && (numcmp(fnew, f_goal) <= 0))
      ++improvement_count;
  }
}


x86 assembly (clang, -O0):
<trap_minimum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <numcmp@plt>
cmp    $0x0,%rax
jle    119b <trap_minimum+0x6b>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <numcmp@plt>
cmp    $0x0,%rax
jg     11a4 <trap_minimum+0x74>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11a9 <trap_minimum+0x79>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <numcmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x51(%rbp)
jg     11ef <trap_minimum+0xbf>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
call   1030 <numcmp@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    11ff <trap_minimum+0xcf>
jmp    12be <trap_minimum+0x18e>
mov    -0x50(%rbp),%eax
cmp    0x18(%rbp),%eax
jl     1210 <trap_minimum+0xe0>
jmp    12be <trap_minimum+0x18e>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm2
lea    -0x4c(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <golden_section_probe@plt>
cmpl   $0x0,-0x4c(%rbp)
jne    1244 <trap_minimum+0x114>
jmp    12be <trap_minimum+0x18e>
mov    0x10(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
call   1040 <insert_new_trap_point@plt>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <numcmp@plt>
cmp    $0x0,%rax
jg     12b9 <trap_minimum+0x189>
movsd  -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <numcmp@plt>
cmp    $0x0,%rax
jg     12b9 <trap_minimum+0x189>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11a9 <trap_minimum+0x79>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trap_minimum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movaps %xmm0,%xmm1
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r13
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rbp
movsd  (%rdi),%xmm0
movsd  %xmm1,0x8(%rsp)
call   1030 <numcmp@plt>
test   %rax,%rax
jle    1185 <trap_minimum+0x55>
movsd  (%r12),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <numcmp@plt>
movl   $0x0,0x4(%rsp)
test   %rax,%rax
jg     1190 <trap_minimum+0x60>
movl   $0x1,0x4(%rsp)
nopl   (%rax)
movsd  0x0(%rbp),%xmm0
movsd  (%rbx),%xmm1
call   1030 <numcmp@plt>
test   %rax,%rax
jg     11bb <trap_minimum+0x8b>
movsd  (%r12),%xmm0
movsd  (%rbx),%xmm1
call   1030 <numcmp@plt>
test   %rax,%rax
jle    1259 <trap_minimum+0x129>
mov    0x68(%rsp),%eax
cmp    %eax,0x4(%rsp)
jge    1259 <trap_minimum+0x129>
movsd  0x0(%r13),%xmm0
movsd  (%r15),%xmm1
movsd  (%r14),%xmm2
lea    0x14(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1050 <golden_section_probe@plt>
cmpl   $0x0,0x14(%rsp)
je     1259 <trap_minimum+0x129>
movsd  0x18(%rsp),%xmm0
call   *0x60(%rsp)
movaps %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %r15,%r8
mov    %r14,%r9
movsd  %xmm1,0x20(%rsp)
call   1040 <insert_new_trap_point@plt>
movsd  (%rbx),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <numcmp@plt>
test   %rax,%rax
jg     1190 <trap_minimum+0x60>
movsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <numcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setle  %cl
add    %ecx,0x4(%rsp)
jmp    1190 <trap_minimum+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @trap_minimum(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5, double %6, double (double)* %7, i32 %8) {
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double
%17 = alloca double (double)*
%18 = alloca i32
%19 = alloca double
%20 = alloca double
%21 = alloca i32
%22 = alloca i32
store double* %0, double** %10
store double* %1, double** %11
store double* %2, double** %12
store double* %3, double** %13
store double* %4, double** %14
store double* %5, double** %15
store double %6, double* %16
store double (double)* %7, double (double)** %17
store i32 %8, i32* %18
store i32 0, i32* %22
%23 = load double*, double** %10
%24 = load double, double* %23
%25 = load double, double* %16
%26 = call i64 @numcmp(double %24, double %25)
%27 = icmp sle i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %9
%29 = load double*, double** %12
%30 = load double, double* %29
%31 = load double, double* %16
%32 = call i64 @numcmp(double %30, double %31)
%33 = icmp sle i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %28, %9
%35 = load i32, i32* %22
%36 = add nsw i32 %35, 1
store i32 %36, i32* %22
br label %37
37: ; preds = %34, %28
br label %38
38: ; preds = %96, %37
%39 = load double*, double** %10
%40 = load double, double* %39
%41 = load double*, double** %11
%42 = load double, double* %41
%43 = call i64 @numcmp(double %40, double %42)
%44 = icmp sgt i64 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %38
%46 = load double*, double** %12
%47 = load double, double* %46
%48 = load double*, double** %11
%49 = load double, double* %48
%50 = call i64 @numcmp(double %47, double %49)
%51 = icmp sgt i64 %50, 0
br label %52
52: ; preds = %45, %38
%53 = phi i1 [ true, %38 ], [ %51, %45 ]
br i1 %53, label %54, label %97
54: ; preds = %52
%55 = load i32, i32* %22
%56 = load i32, i32* %18
%57 = icmp sge i32 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %54
br label %97
59: ; preds = %54
%60 = load double*, double** %13
%61 = load double, double* %60
%62 = load double*, double** %14
%63 = load double, double* %62
%64 = load double*, double** %15
%65 = load double, double* %64
%66 = call i32 @golden_section_probe(i32* %21, double* %19, double %61, double %63, double %65)
%67 = load i32, i32* %21
%68 = icmp ne i32 %67, 0
br i1 %68, label %70, label %69
69: ; preds = %59
br label %97
70: ; preds = %59
%71 = load double (double)*, double (double)** %17
%72 = load double, double* %19
%73 = call double %71(double %72)
store double %73, double* %20
%74 = load double*, double** %10
%75 = load double*, double** %11
%76 = load double*, double** %12
%77 = load double*, double** %13
%78 = load double*, double** %14
%79 = load double*, double** %15
%80 = load double, double* %19
%81 = load double, double* %20
%82 = call i32 @insert_new_trap_point(double* %74, double* %75, double* %76, double* %77, double* %78, double* %79, double %80, double %81)
%83 = load double*, double** %11
%84 = load double, double* %83
%85 = load double, double* %16
%86 = call i64 @numcmp(double %84, double %85)
%87 = icmp sle i64 %86, 0
br i1 %87, label %88, label %96
88: ; preds = %70
%89 = load double, double* %20
%90 = load double, double* %16
%91 = call i64 @numcmp(double %89, double %90)
%92 = icmp sle i64 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %88
%94 = load i32, i32* %22
%95 = add nsw i32 %94, 1
store i32 %95, i32* %22
br label %96
96: ; preds = %93, %88, %70
br label %38
97: ; preds = %69, %58, %52
ret void
}

LLVM IR (-O2):
define void @trap_minimum(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5, double %6, double (double)* nocapture %7, i32 %8) {
%10 = alloca double
%11 = alloca i32
%12 = bitcast double* %10 to i8*
%13 = bitcast i32* %11 to i8*
%14 = load double, double* %0
%15 = tail call i64 @numcmp(double %14, double %6)
%16 = icmp slt i64 %15, 1
br i1 %16, label %21, label %17
17: ; preds = %9
%18 = load double, double* %2
%19 = tail call i64 @numcmp(double %18, double %6)
%20 = icmp slt i64 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %17, %9
br label %22
22: ; preds = %21, %17
%23 = phi i32 [ 0, %17 ], [ 1, %21 ]
br label %24
24: ; preds = %22, %55
%25 = phi i32 [ %23, %22 ], [ %59, %55 ]
%26 = icmp slt i32 %25, %8
%27 = icmp slt i32 %25, %8
br label %28
28: ; preds = %24, %47
%29 = load double, double* %0
%30 = load double, double* %1
%31 = call i64 @numcmp(double %29, double %30)
%32 = icmp sgt i64 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %28
%34 = load double, double* %2
%35 = load double, double* %1
%36 = call i64 @numcmp(double %34, double %35)
%37 = icmp sgt i64 %36, 0
%38 = select i1 %37, i1 %26, i1 false
br i1 %38, label %40, label %60
39: ; preds = %28
br i1 %27, label %40, label %60
40: ; preds = %33, %39
%41 = load double, double* %3
%42 = load double, double* %4
%43 = load double, double* %5
%44 = call i32 @golden_section_probe(i32* %11, double* %10, double %41, double %42, double %43)
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, 0
br i1 %46, label %60, label %47
47: ; preds = %40
%48 = load double, double* %10
%49 = call double %7(double %48)
%50 = load double, double* %10
%51 = call i32 @insert_new_trap_point(double* %0, double* %1, double* %2, double* %3, double* %4, double* %5, double %50, double %49)
%52 = load double, double* %1
%53 = call i64 @numcmp(double %52, double %6)
%54 = icmp slt i64 %53, 1
br i1 %54, label %55, label %28
55: ; preds = %47
%56 = call i64 @numcmp(double %49, double %6)
%57 = icmp slt i64 %56, 1
%58 = zext i1 %57 to i32
%59 = add nuw nsw i32 %25, %58
br label %24
60: ; preds = %40, %39, %33
ret void
}