double solve(double (*fn)(double), double guess, double epsilon) {
  double delta, f0, factor;
  for (delta = guess ? guess : 1, f0 = fn(guess), factor = 2;
       delta > epsilon && guess != guess - delta; delta *= factor) {
    double nf = (*fn)(guess - delta);
    if (nf < f0) {
      f0 = nf;
      guess -= delta;
    } else {
      nf = fn(guess + delta);
      if (nf < f0) {
        f0 = nf;
        guess += delta;
      } else {
        factor = 0.5;
      }
    }
  }
  return guess;
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1133 <solve+0x33>
jp     1133 <solve+0x33>
jmp    1142 <solve+0x42>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1154 <solve+0x54>
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1154 <solve+0x54>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x28(%rbp)
movsd  0xe92(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
xor    %eax,%eax
ucomisd -0x18(%rbp),%xmm0
mov    %al,-0x41(%rbp)
jbe    11ae <solve+0xae>
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
setne  %al
setp   %cl
or     %cl,%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    11be <solve+0xbe>
jmp    127b <solve+0x17b>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1209 <solve+0x109>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1262 <solve+0x162>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1250 <solve+0x150>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    125d <solve+0x15d>
movsd  0xdb8(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1262 <solve+0x162>
jmp    1267 <solve+0x167>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    117b <solve+0x7b>
movsd  -0x10(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbx
sub    $0x50,%rsp
movsd  %xmm1,0x8(%rsp)
mov    %rdi,%rbx
xorpd  %xmm3,%xmm3
cmpneqsd %xmm0,%xmm3
movapd %xmm3,%xmm2
andpd  %xmm0,%xmm2
movsd  0xed9(%rip),%xmm1
andnpd %xmm1,%xmm3
orpd   %xmm2,%xmm3
movapd %xmm3,0x20(%rsp)
movapd %xmm0,0x10(%rsp)
call   *%rdi
movapd 0x20(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm2
jbe    1247 <solve+0x147>
movapd %xmm0,%xmm3
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,0x30(%rsp)
movapd 0x10(%rsp),%xmm0
movapd %xmm0,%xmm4
jmp    11c5 <solve+0xc5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm0,%xmm4
cmpltsd %xmm2,%xmm4
movapd 0x40(%rsp),%xmm1
andpd  %xmm4,%xmm1
andnpd 0x10(%rsp),%xmm4
orpd   %xmm1,%xmm4
minsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
mulsd  0x30(%rsp),%xmm2
ucomisd %xmm1,%xmm2
movapd %xmm0,%xmm3
movapd %xmm4,%xmm0
jbe    1253 <solve+0x153>
subsd  %xmm2,%xmm4
ucomisd %xmm4,%xmm0
jne    11d1 <solve+0xd1>
jnp    124f <solve+0x14f>
movapd %xmm0,0x10(%rsp)
movapd %xmm2,0x20(%rsp)
movapd %xmm4,0x40(%rsp)
movapd %xmm4,%xmm0
movsd  %xmm3,0x38(%rsp)
call   *%rbx
movsd  0x38(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1210 <solve+0x110>
movsd  0x8(%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
movapd 0x40(%rsp),%xmm4
jmp    11ad <solve+0xad>
nop
movapd 0x10(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
movapd %xmm0,0x40(%rsp)
call   *%rbx
movsd  0x38(%rsp),%xmm2
ucomisd %xmm0,%xmm2
ja     1180 <solve+0x80>
movsd  0xdd4(%rip),%xmm1
movsd  %xmm1,0x30(%rsp)
jmp    1180 <solve+0x80>
movapd 0x10(%rsp),%xmm4
jmp    1253 <solve+0x153>
movapd %xmm0,%xmm4
movapd %xmm4,%xmm0
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @solve(double (double)* %0, double %1, double %2) {
%4 = alloca double (double)*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double (double)* %0, double (double)** %4
store double %1, double* %5
store double %2, double* %6
%11 = load double, double* %5
%12 = fcmp une double %11, 0.000000e+00
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load double, double* %5
br label %16
15: ; preds = %3
br label %16
16: ; preds = %15, %13
%17 = phi double [ %14, %13 ], [ 1.000000e+00, %15 ]
store double %17, double* %7
%18 = load double (double)*, double (double)** %4
%19 = load double, double* %5
%20 = call double %18(double %19)
store double %20, double* %8
store double 2.000000e+00, double* %9
br label %21
21: ; preds = %64, %16
%22 = load double, double* %7
%23 = load double, double* %6
%24 = fcmp ogt double %22, %23
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load double, double* %5
%27 = load double, double* %5
%28 = load double, double* %7
%29 = fsub double %27, %28
%30 = fcmp une double %26, %29
br label %31
31: ; preds = %25, %21
%32 = phi i1 [ false, %21 ], [ %30, %25 ]
br i1 %32, label %33, label %68
33: ; preds = %31
%34 = load double (double)*, double (double)** %4
%35 = load double, double* %5
%36 = load double, double* %7
%37 = fsub double %35, %36
%38 = call double %34(double %37)
store double %38, double* %10
%39 = load double, double* %10
%40 = load double, double* %8
%41 = fcmp olt double %39, %40
br i1 %41, label %42, label %47
42: ; preds = %33
%43 = load double, double* %10
store double %43, double* %8
%44 = load double, double* %7
%45 = load double, double* %5
%46 = fsub double %45, %44
store double %46, double* %5
br label %63
47: ; preds = %33
%48 = load double (double)*, double (double)** %4
%49 = load double, double* %5
%50 = load double, double* %7
%51 = fadd double %49, %50
%52 = call double %48(double %51)
store double %52, double* %10
%53 = load double, double* %10
%54 = load double, double* %8
%55 = fcmp olt double %53, %54
br i1 %55, label %56, label %61
56: ; preds = %47
%57 = load double, double* %10
store double %57, double* %8
%58 = load double, double* %7
%59 = load double, double* %5
%60 = fadd double %59, %58
store double %60, double* %5
br label %62
61: ; preds = %47
store double 5.000000e-01, double* %9
br label %62
62: ; preds = %61, %56
br label %63
63: ; preds = %62, %42
br label %64
64: ; preds = %63
%65 = load double, double* %9
%66 = load double, double* %7
%67 = fmul double %66, %65
store double %67, double* %7
br label %21
68: ; preds = %31
%69 = load double, double* %5
ret double %69
}

LLVM IR (-O2):
define double @solve(double (double)* nocapture %0, double %1, double %2) {
%4 = fcmp une double %1, 0.000000e+00
%5 = select i1 %4, double %1, double 1.000000e+00
%6 = tail call double %0(double %1)
%7 = fcmp ogt double %5, %2
br i1 %7, label %8, label %31
8: ; preds = %3, %25
%9 = phi double [ %28, %25 ], [ 2.000000e+00, %3 ]
%10 = phi double [ %27, %25 ], [ %6, %3 ]
%11 = phi double [ %29, %25 ], [ %5, %3 ]
%12 = phi double [ %26, %25 ], [ %1, %3 ]
%13 = fsub double %12, %11
%14 = fcmp une double %12, %13
br i1 %14, label %15, label %31
15: ; preds = %8
%16 = tail call double %0(double %13)
%17 = fcmp olt double %16, %10
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = fadd double %12, %11
%20 = tail call double %0(double %19)
%21 = fcmp olt double %20, %10
%22 = select i1 %21, double %19, double %12
%23 = select i1 %21, double %20, double %10
%24 = select i1 %21, double %9, double 5.000000e-01
br label %25
25: ; preds = %18, %15
%26 = phi double [ %13, %15 ], [ %22, %18 ]
%27 = phi double [ %16, %15 ], [ %23, %18 ]
%28 = phi double [ %9, %15 ], [ %24, %18 ]
%29 = fmul double %11, %28
%30 = fcmp ogt double %29, %2
br i1 %30, label %8, label %31
31: ; preds = %8, %25, %3
%32 = phi double [ %1, %3 ], [ %26, %25 ], [ %12, %8 ]
ret double %32
}