double solve(double (*f)(double), double a, double b, double err, int *code) {
  int signa, signb, signc;
  double fa, fb, fc, c, signaling_nan();
  double dist;
  fa = (*f)(a);
  signa = fa > 0;
  fb = (*f)(b);
  signb = fb > 0;
  if (signa == signb) {
    if (signa == 1)
      *code = 1;
    else
      *code = -1;
    return (0.0);
  } else
    *code = 0;
  if ((dist = b - a) < 0)
    dist = -dist;
  while (dist > err) {
    c = (b + a) / 2;
    fc = (*f)(c);
    signc = fc > 0;
    if (signa == signc) {
      a = c;
      fa = fc;
    } else {
      b = c;
      fb = fc;
    }
    if ((dist = b - a) < 0)
      dist = -dist;
  }
  if ((fb - fa) == 0)
    return (a);
  else {
    c = (a * fb - b * fa) / (fb - fa);
    return (c);
  }
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    11a9 <solve+0xa9>
cmpl   $0x1,-0x34(%rbp)
jne    1192 <solve+0x92>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
jmp    119c <solve+0x9c>
mov    -0x30(%rbp),%rax
movl   $0xffffffff,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <solve+0x23e>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  %xmm1,-0x68(%rbp)
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11f0 <solve+0xf0>
movsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    11f5 <solve+0xf5>
movsd  -0x68(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    12c2 <solve+0x1c2>
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xde9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x60(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jne    126c <solve+0x16c>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1280 <solve+0x180>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  %xmm1,-0x68(%rbp)
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12bd <solve+0x1bd>
movsd  -0x68(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    11f5 <solve+0xf5>
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12ee <solve+0x1ee>
jp     12ee <solve+0x1ee>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    133e <solve+0x23e>
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x50(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x10(%rsp)
mov    %rdi,%rbp
movsd  %xmm0,0x30(%rsp)
call   *%rdi
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%rsp)
ucomisd %xmm1,%xmm0
seta   %bl
movsd  0x10(%rsp),%xmm0
call   *%rbp
xorpd  %xmm4,%xmm4
movsd  %xmm0,0x20(%rsp)
ucomisd %xmm4,%xmm0
setbe  %al
cmp    %al,%bl
je     116c <solve+0x6c>
xor    %eax,%eax
movsd  0x8(%rsp),%xmm0
ucomisd %xmm4,%xmm0
seta   %al
add    %eax,%eax
add    $0xffffffff,%eax
mov    %eax,(%r14)
jmp    12b6 <solve+0x1b6>
movl   $0x0,(%r14)
movsd  0x10(%rsp),%xmm5
movapd %xmm5,%xmm0
movsd  0x30(%rsp),%xmm3
subsd  %xmm3,%xmm0
movapd 0xe71(%rip),%xmm1
xorpd  %xmm0,%xmm1
movapd %xmm0,%xmm2
cmpltsd %xmm4,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
movsd  0x28(%rsp),%xmm6
ucomisd %xmm6,%xmm2
movapd %xmm3,%xmm4
jbe    127a <solve+0x17a>
xorpd  %xmm7,%xmm7
movsd  0x8(%rsp),%xmm8
movsd  %xmm8,0x18(%rsp)
jmp    121e <solve+0x11e>
movsd  0x38(%rsp),%xmm5
movsd  %xmm0,0x20(%rsp)
movsd  0x30(%rsp),%xmm4
movsd  0x28(%rsp),%xmm6
movsd  0x8(%rsp),%xmm8
movapd %xmm5,%xmm1
subsd  %xmm4,%xmm1
movapd %xmm1,%xmm2
xorpd  0xdfd(%rip),%xmm2
movapd %xmm1,%xmm3
cmpltsd %xmm7,%xmm3
andpd  %xmm3,%xmm2
andnpd %xmm1,%xmm3
orpd   %xmm2,%xmm3
ucomisd %xmm6,%xmm3
jbe    128c <solve+0x18c>
movsd  %xmm5,0x10(%rsp)
movsd  %xmm4,0x30(%rsp)
ucomisd %xmm7,%xmm8
seta   %bl
movapd %xmm5,%xmm0
addsd  %xmm4,%xmm0
mulsd  0xdce(%rip),%xmm0
movsd  %xmm0,0x38(%rsp)
call   *%rbp
xorpd  %xmm7,%xmm7
ucomisd %xmm7,%xmm0
setbe  %al
xor    %bl,%al
je     11d0 <solve+0xd0>
movsd  0x38(%rsp),%xmm4
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm5
jmp    11e2 <solve+0xe2>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
movapd %xmm0,%xmm1
movsd  0x18(%rsp),%xmm3
subsd  %xmm3,%xmm1
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    12a6 <solve+0x1a6>
jnp    12b6 <solve+0x1b6>
mulsd  %xmm5,%xmm3
mulsd  %xmm0,%xmm4
subsd  %xmm3,%xmm4
divsd  %xmm1,%xmm4
movapd %xmm4,%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @solve(double (double)* %0, double %1, double %2, double %3, i32* %4) {
%6 = alloca double
%7 = alloca double (double)*
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store double (double)* %0, double (double)** %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store i32* %4, i32** %11
%20 = load double (double)*, double (double)** %7
%21 = load double, double* %8
%22 = call double %20(double %21)
store double %22, double* %15
%23 = load double, double* %15
%24 = fcmp ogt double %23, 0.000000e+00
%25 = zext i1 %24 to i32
store i32 %25, i32* %12
%26 = load double (double)*, double (double)** %7
%27 = load double, double* %9
%28 = call double %26(double %27)
store double %28, double* %16
%29 = load double, double* %16
%30 = fcmp ogt double %29, 0.000000e+00
%31 = zext i1 %30 to i32
store i32 %31, i32* %13
%32 = load i32, i32* %12
%33 = load i32, i32* %13
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %43
35: ; preds = %5
%36 = load i32, i32* %12
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i32*, i32** %11
store i32 1, i32* %39
br label %42
40: ; preds = %35
%41 = load i32*, i32** %11
store i32 -1, i32* %41
br label %42
42: ; preds = %40, %38
store double 0.000000e+00, double* %6
br label %107
43: ; preds = %5
%44 = load i32*, i32** %11
store i32 0, i32* %44
br label %45
45: ; preds = %43
%46 = load double, double* %9
%47 = load double, double* %8
%48 = fsub double %46, %47
store double %48, double* %19
%49 = fcmp olt double %48, 0.000000e+00
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load double, double* %19
%52 = fneg double %51
store double %52, double* %19
br label %53
53: ; preds = %50, %45
br label %54
54: ; preds = %86, %53
%55 = load double, double* %19
%56 = load double, double* %10
%57 = fcmp ogt double %55, %56
br i1 %57, label %58, label %87
58: ; preds = %54
%59 = load double, double* %9
%60 = load double, double* %8
%61 = fadd double %59, %60
%62 = fdiv double %61, 2.000000e+00
store double %62, double* %18
%63 = load double (double)*, double (double)** %7
%64 = load double, double* %18
%65 = call double %63(double %64)
store double %65, double* %17
%66 = load double, double* %17
%67 = fcmp ogt double %66, 0.000000e+00
%68 = zext i1 %67 to i32
store i32 %68, i32* %14
%69 = load i32, i32* %12
%70 = load i32, i32* %14
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %75
72: ; preds = %58
%73 = load double, double* %18
store double %73, double* %8
%74 = load double, double* %17
store double %74, double* %15
br label %78
75: ; preds = %58
%76 = load double, double* %18
store double %76, double* %9
%77 = load double, double* %17
store double %77, double* %16
br label %78
78: ; preds = %75, %72
%79 = load double, double* %9
%80 = load double, double* %8
%81 = fsub double %79, %80
store double %81, double* %19
%82 = fcmp olt double %81, 0.000000e+00
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load double, double* %19
%85 = fneg double %84
store double %85, double* %19
br label %86
86: ; preds = %83, %78
br label %54
87: ; preds = %54
%88 = load double, double* %16
%89 = load double, double* %15
%90 = fsub double %88, %89
%91 = fcmp oeq double %90, 0.000000e+00
br i1 %91, label %92, label %94
92: ; preds = %87
%93 = load double, double* %8
store double %93, double* %6
br label %107
94: ; preds = %87
%95 = load double, double* %8
%96 = load double, double* %16
%97 = load double, double* %9
%98 = load double, double* %15
%99 = fmul double %97, %98
%100 = fneg double %99
%101 = call double @llvm.fmuladd.f64(double %95, double %96, double %100)
%102 = load double, double* %16
%103 = load double, double* %15
%104 = fsub double %102, %103
%105 = fdiv double %101, %104
store double %105, double* %18
%106 = load double, double* %18
store double %106, double* %6
br label %107
107: ; preds = %94, %92, %42
%108 = load double, double* %6
ret double %108
}

LLVM IR (-O2):
define double @solve(double (double)* nocapture %0, double %1, double %2, double %3, i32* nocapture writeonly %4) {
%6 = tail call double %0(double %1)
%7 = fcmp ogt double %6, 0.000000e+00
%8 = tail call double %0(double %2)
%9 = fcmp ule double %8, 0.000000e+00
%10 = xor i1 %7, %9
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = select i1 %7, i32 1, i32 -1
store i32 %12, i32* %4
br label %50
13: ; preds = %5
store i32 0, i32* %4
%14 = fsub double %2, %1
%15 = fcmp olt double %14, 0.000000e+00
%16 = fneg double %14
%17 = select i1 %15, double %16, double %14
%18 = fcmp ogt double %17, %3
br i1 %18, label %19, label %38
19: ; preds = %13, %19
%20 = phi double [ %32, %19 ], [ %8, %13 ]
%21 = phi double [ %31, %19 ], [ %6, %13 ]
%22 = phi double [ %30, %19 ], [ %1, %13 ]
%23 = phi double [ %29, %19 ], [ %2, %13 ]
%24 = fadd double %23, %22
%25 = fmul double %24, 5.000000e-01
%26 = tail call double %0(double %25)
%27 = fcmp ule double %26, 0.000000e+00
%28 = xor i1 %7, %27
%29 = select i1 %28, double %23, double %25
%30 = select i1 %28, double %25, double %22
%31 = select i1 %28, double %26, double %21
%32 = select i1 %28, double %20, double %26
%33 = fsub double %29, %30
%34 = fcmp olt double %33, 0.000000e+00
%35 = fneg double %33
%36 = select i1 %34, double %35, double %33
%37 = fcmp ogt double %36, %3
br i1 %37, label %19, label %38
38: ; preds = %19, %13
%39 = phi double [ %2, %13 ], [ %29, %19 ]
%40 = phi double [ %1, %13 ], [ %30, %19 ]
%41 = phi double [ %6, %13 ], [ %31, %19 ]
%42 = phi double [ %8, %13 ], [ %32, %19 ]
%43 = fsub double %42, %41
%44 = fcmp oeq double %43, 0.000000e+00
br i1 %44, label %50, label %45
45: ; preds = %38
%46 = fneg double %39
%47 = fmul double %41, %46
%48 = tail call double @llvm.fmuladd.f64(double %40, double %42, double %47)
%49 = fdiv double %48, %43
br label %50
50: ; preds = %38, %45, %11
%51 = phi double [ 0.000000e+00, %11 ], [ %49, %45 ], [ %40, %38 ]
ret double %51
}