#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*/ free(double *);
double macheps();
scalar_t__ malloc(int);
int nel_min(double (*)(double *, int), double *, int, double *, double, int,
            int *, double, double *);
int fminsearch(double (*funcpt)(double *, int), int N, double *xi, double *xf) {
  int i, retval, MAXITER, niter;
  double fsval, eps;
  double *dx;
  dx = (double *)malloc(sizeof(double) * N);
  fsval = 1.0;
  MAXITER = 200 * N;
  niter = 0;
  eps = macheps();
  for (i = 0; i < N; ++i) {
    dx[i] = 1.0;
  }
  retval = nel_min(funcpt, xi, N, dx, fsval, MAXITER, &niter, eps, xf);
  free(dx);
  return retval;
}


x86 assembly (clang, -O0):
<fminsearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
movsd  0xe8e(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
imul   $0xc8,-0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1060 <macheps@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ca <fminsearch+0x8a>
mov    -0x48(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe49(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119b <fminsearch+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x48(%rbp),%rcx
movsd  -0x38(%rbp),%xmm0
mov    -0x2c(%rbp),%r8d
movsd  -0x40(%rbp),%xmm1
mov    -0x20(%rbp),%rax
lea    -0x30(%rbp),%r9
mov    %rax,(%rsp)
call   1040 <nel_min@plt>
mov    %eax,-0x28(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fminsearch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
lea    0x0(,%r15,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x0,0x14(%rsp)
xor    %eax,%eax
call   1060 <macheps@plt>
movaps %xmm0,%xmm1
test   %r15d,%r15d
jle    129d <fminsearch+0x15d>
mov    %r15d,%eax
cmp    $0x4,%r15d
jae    1195 <fminsearch+0x55>
xor    %ecx,%ecx
jmp    1277 <fminsearch+0x137>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdi
mov    %rdi,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%edx
and    $0x7,%edx
cmp    $0x1c,%rdi
jae    11bb <fminsearch+0x7b>
xor    %edi,%edi
jmp    1241 <fminsearch+0x101>
and    $0xfffffffffffffff8,%rsi
xor    %edi,%edi
movaps 0xe38(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
movups %xmm0,(%rbx,%rdi,8)
movups %xmm0,0x10(%rbx,%rdi,8)
movups %xmm0,0x20(%rbx,%rdi,8)
movups %xmm0,0x30(%rbx,%rdi,8)
movups %xmm0,0x40(%rbx,%rdi,8)
movups %xmm0,0x50(%rbx,%rdi,8)
movups %xmm0,0x60(%rbx,%rdi,8)
movups %xmm0,0x70(%rbx,%rdi,8)
movups %xmm0,0x80(%rbx,%rdi,8)
movups %xmm0,0x90(%rbx,%rdi,8)
movups %xmm0,0xa0(%rbx,%rdi,8)
movups %xmm0,0xb0(%rbx,%rdi,8)
movups %xmm0,0xc0(%rbx,%rdi,8)
movups %xmm0,0xd0(%rbx,%rdi,8)
movups %xmm0,0xe0(%rbx,%rdi,8)
movups %xmm0,0xf0(%rbx,%rdi,8)
add    $0x20,%rdi
add    $0xfffffffffffffff8,%rsi
jne    11d0 <fminsearch+0x90>
test   %rdx,%rdx
je     1272 <fminsearch+0x132>
lea    (%rbx,%rdi,8),%rsi
add    $0x10,%rsi
shl    $0x5,%rdx
xor    %edi,%edi
movaps 0xda5(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
movups %xmm0,-0x10(%rsi,%rdi,1)
movups %xmm0,(%rsi,%rdi,1)
add    $0x20,%rdi
cmp    %rdi,%rdx
jne    1260 <fminsearch+0x120>
cmp    %rax,%rcx
je     129d <fminsearch+0x15d>
movabs $0x3ff0000000000000,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdx,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1290 <fminsearch+0x150>
imul   $0xc8,%r15d,%r8d
mov    %r13,(%rsp)
movsd  0xd60(%rip),%xmm0
lea    0x14(%rsp),%r9
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1040 <nel_min@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fminsearch(double (double*, i32)* %0, i32 %1, double* %2, double* %3) {
%5 = alloca double (double*, i32)*
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double*
store double (double*, i32)* %0, double (double*, i32)** %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = mul i64 8, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to double*
store double* %21, double** %15
store double 1.000000e+00, double* %13
%22 = load i32, i32* %6
%23 = mul nsw i32 200, %22
store i32 %23, i32* %11
store i32 0, i32* %12
%24 = call double (...) @macheps()
store double %24, double* %14
store i32 0, i32* %9
br label %25
25: ; preds = %34, %4
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load double*, double** %15
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double 1.000000e+00, double* %33
br label %34
34: ; preds = %29
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %25
37: ; preds = %25
%38 = load double (double*, i32)*, double (double*, i32)** %5
%39 = load double*, double** %7
%40 = load i32, i32* %6
%41 = load double*, double** %15
%42 = load double, double* %13
%43 = load i32, i32* %11
%44 = load double, double* %14
%45 = load double*, double** %8
%46 = call i32 @nel_min(double (double*, i32)* %38, double* %39, i32 %40, double* %41, double %42, i32 %43, i32* %12, double %44, double* %45)
store i32 %46, i32* %10
%47 = load double*, double** %15
%48 = call i32 @free(double* %47)
%49 = load i32, i32* %10
ret i32 %49
}

LLVM IR (-O2):
define i32 @fminsearch(double (double*, i32)* %0, i32 %1, double* %2, double* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = shl i32 %1, 3
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
store i32 0, i32* %5
%10 = tail call double (...) @macheps()
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %91
12: ; preds = %4
%13 = zext i32 %1 to i64
%14 = icmp ult i32 %1, 4
br i1 %14, label %84, label %15
15: ; preds = %12
%16 = and i64 %13, 4294967292
%17 = add nsw i64 %16, -4
%18 = lshr exact i64 %17, 2
%19 = add nuw nsw i64 %18, 1
%20 = and i64 %19, 7
%21 = icmp ult i64 %17, 28
br i1 %21, label %69, label %22
22: ; preds = %15
%23 = and i64 %19, 9223372036854775800
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %66, %24 ]
%26 = phi i64 [ 0, %22 ], [ %67, %24 ]
%27 = getelementptr inbounds double, double* %9, i64 %25
%28 = bitcast double* %27 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %28
%29 = getelementptr inbounds double, double* %27, i64 2
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %30
%31 = or i64 %25, 4
%32 = getelementptr inbounds double, double* %9, i64 %31
%33 = bitcast double* %32 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %33
%34 = getelementptr inbounds double, double* %32, i64 2
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %35
%36 = or i64 %25, 8
%37 = getelementptr inbounds double, double* %9, i64 %36
%38 = bitcast double* %37 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %38
%39 = getelementptr inbounds double, double* %37, i64 2
%40 = bitcast double* %39 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %40
%41 = or i64 %25, 12
%42 = getelementptr inbounds double, double* %9, i64 %41
%43 = bitcast double* %42 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %43
%44 = getelementptr inbounds double, double* %42, i64 2
%45 = bitcast double* %44 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %45
%46 = or i64 %25, 16
%47 = getelementptr inbounds double, double* %9, i64 %46
%48 = bitcast double* %47 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %48
%49 = getelementptr inbounds double, double* %47, i64 2
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %50
%51 = or i64 %25, 20
%52 = getelementptr inbounds double, double* %9, i64 %51
%53 = bitcast double* %52 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %53
%54 = getelementptr inbounds double, double* %52, i64 2
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %55
%56 = or i64 %25, 24
%57 = getelementptr inbounds double, double* %9, i64 %56
%58 = bitcast double* %57 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %58
%59 = getelementptr inbounds double, double* %57, i64 2
%60 = bitcast double* %59 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %60
%61 = or i64 %25, 28
%62 = getelementptr inbounds double, double* %9, i64 %61
%63 = bitcast double* %62 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %63
%64 = getelementptr inbounds double, double* %62, i64 2
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %65
%66 = add nuw i64 %25, 32
%67 = add i64 %26, 8
%68 = icmp eq i64 %67, %23
br i1 %68, label %69, label %24
69: ; preds = %24, %15
%70 = phi i64 [ 0, %15 ], [ %66, %24 ]
%71 = icmp eq i64 %20, 0
br i1 %71, label %82, label %72
72: ; preds = %69, %72
%73 = phi i64 [ %79, %72 ], [ %70, %69 ]
%74 = phi i64 [ %80, %72 ], [ 0, %69 ]
%75 = getelementptr inbounds double, double* %9, i64 %73
%76 = bitcast double* %75 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %76
%77 = getelementptr inbounds double, double* %75, i64 2
%78 = bitcast double* %77 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double>* %78
%79 = add nuw i64 %73, 4
%80 = add i64 %74, 1
%81 = icmp eq i64 %80, %20
br i1 %81, label %82, label %72
82: ; preds = %72, %69
%83 = icmp eq i64 %16, %13
br i1 %83, label %91, label %84
84: ; preds = %12, %82
%85 = phi i64 [ 0, %12 ], [ %16, %82 ]
br label %86
86: ; preds = %84, %86
%87 = phi i64 [ %89, %86 ], [ %85, %84 ]
%88 = getelementptr inbounds double, double* %9, i64 %87
store double 1.000000e+00, double* %88
%89 = add nuw nsw i64 %87, 1
%90 = icmp eq i64 %89, %13
br i1 %90, label %91, label %86
91: ; preds = %86, %82, %4
%92 = mul nsw i32 %1, 200
%93 = call i32 @nel_min(double (double*, i32)* %0, double* %2, i32 %1, double* %9, double 1.000000e+00, i32 %92, i32* %5, double %10, double* %3)
%94 = call i32 @free(double* %9)
ret i32 %93
}