double FindLocalMin(double start, double sstep, int times,
                    double (*ExplFunc)(double, void *), void *data) {
  int time = 0;
  double sval, pos, step, nval;
  pos = start;
  step = sstep;
  sval = ExplFunc(pos, data);
  while (time < times) {
    nval = ExplFunc(pos + step, data);
    if (nval < sval) {
      sval = nval;
      pos += step;
    } else {
      step /= -2.;
      time++;
    }
  }
  return pos;
}


x86 assembly (clang, -O0):
<FindLocalMin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c7 <FindLocalMin+0xc7>
mov    -0x20(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a3 <FindLocalMin+0xa3>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11c2 <FindLocalMin+0xc2>
movsd  -0x48(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114c <FindLocalMin+0x4c>
movsd  -0x40(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindLocalMin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %rdx,%rdi
call   *%rsi
movsd  %xmm0,0x18(%rsp)
test   %ebp,%ebp
jle    119d <FindLocalMin+0x9d>
xor    %ebx,%ebx
movsd  0x8(%rsp),%xmm1
jmp    1159 <FindLocalMin+0x59>
nopw   0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
mulsd  0xeb2(%rip),%xmm0
add    $0x1,%ebx
movapd %xmm0,%xmm1
cmp    %ebp,%ebx
jge    119d <FindLocalMin+0x9d>
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    %r14,%rdi
call   *%r15
movsd  0x18(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1140 <FindLocalMin+0x40>
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
cmp    %ebp,%ebx
jl     1159 <FindLocalMin+0x59>
movsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @FindLocalMin(double %0, double %1, i32 %2, double (double, i8*)* %3, i8* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double (double, i8*)*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store double (double, i8*)* %3, double (double, i8*)** %9
store i8* %4, i8** %10
store i32 0, i32* %11
%16 = load double, double* %6
store double %16, double* %13
%17 = load double, double* %7
store double %17, double* %14
%18 = load double (double, i8*)*, double (double, i8*)** %9
%19 = load double, double* %13
%20 = load i8*, i8** %10
%21 = call double %18(double %19, i8* %20)
store double %21, double* %12
br label %22
22: ; preds = %46, %5
%23 = load i32, i32* %11
%24 = load i32, i32* %8
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %47
26: ; preds = %22
%27 = load double (double, i8*)*, double (double, i8*)** %9
%28 = load double, double* %13
%29 = load double, double* %14
%30 = fadd double %28, %29
%31 = load i8*, i8** %10
%32 = call double %27(double %30, i8* %31)
store double %32, double* %15
%33 = load double, double* %15
%34 = load double, double* %12
%35 = fcmp olt double %33, %34
br i1 %35, label %36, label %41
36: ; preds = %26
%37 = load double, double* %15
store double %37, double* %12
%38 = load double, double* %14
%39 = load double, double* %13
%40 = fadd double %39, %38
store double %40, double* %13
br label %46
41: ; preds = %26
%42 = load double, double* %14
%43 = fdiv double %42, -2.000000e+00
store double %43, double* %14
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %46
46: ; preds = %41, %36
br label %22
47: ; preds = %22
%48 = load double, double* %13
ret double %48
}

LLVM IR (-O2):
define double @FindLocalMin(double %0, double %1, i32 %2, double (double, i8*)* nocapture %3, i8* %4) {
%6 = tail call double %3(double %0, i8* %4)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %25
8: ; preds = %5, %19
%9 = phi i32 [ %23, %19 ], [ 0, %5 ]
%10 = phi double [ %22, %19 ], [ %1, %5 ]
%11 = phi double [ %21, %19 ], [ %0, %5 ]
%12 = phi double [ %20, %19 ], [ %6, %5 ]
%13 = fadd double %11, %10
%14 = tail call double %3(double %13, i8* %4)
%15 = fcmp olt double %14, %12
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = fmul double %10, -5.000000e-01
%18 = add nsw i32 %9, 1
br label %19
19: ; preds = %8, %16
%20 = phi double [ %12, %16 ], [ %14, %8 ]
%21 = phi double [ %11, %16 ], [ %13, %8 ]
%22 = phi double [ %17, %16 ], [ %10, %8 ]
%23 = phi i32 [ %18, %16 ], [ %9, %8 ]
%24 = icmp slt i32 %23, %2
br i1 %24, label %8, label %25
25: ; preds = %19, %5
%26 = phi double [ %0, %5 ], [ %21, %19 ]
ret double %26
}