#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 */
double roots_eval(int, double volatile);
int roots_find(int deriv, double d0, double d1, double *dr) {
  double p0, p1, db, de, pm;
  volatile double dm;
  p0 = roots_eval(deriv, d0);
  p1 = roots_eval(deriv, d1);
  if (p1 == 0.) {
    *dr = d1;
    return 1;
  }
  if (p0 == 0.)
    return 0;
  if (p0 * p1 > 0.)
    return 1;
  db = d0;
  de = d1;
  while (de > db) {
    dm = (db + de) / 2.;
    if ((dm == db) || (dm == de))
      break;
    pm = roots_eval(deriv, dm);
    if (pm == 0.)
      break;
    if (p0 * pm > 0.) {
      db = dm;
      p0 = pm;
    } else {
      de = dm;
      p1 = pm;
    }
  }
  *dr = dm;
  return 1;
}


x86 assembly (clang, -O0):
<roots_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x8(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
call   1030 <roots_eval@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   1030 <roots_eval@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117e <roots_find+0x6e>
jp     117e <roots_find+0x6e>
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12c6 <roots_find+0x1b6>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a2 <roots_find+0x92>
jp     11a2 <roots_find+0x92>
movl   $0x0,-0x4(%rbp)
jmp    12c6 <roots_find+0x1b6>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c5 <roots_find+0xb5>
movl   $0x1,-0x4(%rbp)
jmp    12c6 <roots_find+0x1b6>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    12b2 <roots_find+0x1a2>
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  0xe05(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jne    121f <roots_find+0x10f>
jp     121f <roots_find+0x10f>
jmp    1235 <roots_find+0x125>
movsd  -0x50(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jne    123a <roots_find+0x12a>
jp     123a <roots_find+0x12a>
jmp    12b2 <roots_find+0x1a2>
mov    -0x8(%rbp),%edi
movsd  -0x50(%rbp),%xmm0
call   1030 <roots_eval@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1269 <roots_find+0x159>
jp     1269 <roots_find+0x159>
jmp    12b2 <roots_find+0x1a2>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1299 <roots_find+0x189>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12ad <roots_find+0x19d>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11d9 <roots_find+0xc9>
movsd  -0x50(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roots_find>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
movsd  %xmm1,0x8(%rsp)
mov    %edi,%ebp
movsd  %xmm0,0x18(%rsp)
call   1030 <roots_eval@plt>
movaps %xmm0,0x20(%rsp)
mov    %ebp,%edi
movsd  0x8(%rsp),%xmm0
call   1030 <roots_eval@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115b <roots_find+0x4b>
jp     115b <roots_find+0x4b>
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
mov    $0x1,%eax
jmp    1184 <roots_find+0x74>
movsd  0x18(%rsp),%xmm5
xor    %eax,%eax
movapd 0x20(%rsp),%xmm3
ucomisd %xmm1,%xmm3
jne    1171 <roots_find+0x61>
jnp    1184 <roots_find+0x74>
mulsd  %xmm3,%xmm0
mov    $0x1,%eax
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    118b <roots_find+0x7b>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret
movsd  0x8(%rsp),%xmm4
ucomisd %xmm5,%xmm4
ja     11be <roots_find+0xae>
movsd  0x10(%rsp),%xmm0
jmp    1150 <roots_find+0x40>
movapd %xmm1,%xmm4
xorpd  %xmm3,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm6,%xmm3
orpd   %xmm0,%xmm3
ucomisd %xmm5,%xmm1
jbe    1197 <roots_find+0x87>
movapd %xmm5,%xmm0
addsd  %xmm4,%xmm0
mulsd  0xe32(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
ucomisd %xmm5,%xmm0
jne    11e2 <roots_find+0xd2>
jnp    1197 <roots_find+0x87>
movsd  0x10(%rsp),%xmm0
ucomisd %xmm4,%xmm0
jne    11f0 <roots_find+0xe0>
jnp    1197 <roots_find+0x87>
movsd  0x10(%rsp),%xmm0
mov    %ebp,%edi
movsd  %xmm4,0x8(%rsp)
movsd  %xmm5,0x18(%rsp)
movapd %xmm3,0x20(%rsp)
call   1030 <roots_eval@plt>
xorpd  %xmm1,%xmm1
movapd 0x20(%rsp),%xmm6
movsd  0x18(%rsp),%xmm5
movsd  0x8(%rsp),%xmm4
ucomisd %xmm1,%xmm0
jne    1231 <roots_find+0x121>
jnp    1197 <roots_find+0x87>
movapd %xmm6,%xmm2
mulsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
movsd  0x10(%rsp),%xmm1
jbe    119f <roots_find+0x8f>
movapd %xmm1,%xmm5
movapd %xmm4,%xmm1
jmp    11a3 <roots_find+0x93>

LLVM IR (-O0):
define i32 @roots_find(i32 %0, double %1, double %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store i32 %0, i32* %6
store double %1, double* %7
store double %2, double* %8
store double* %3, double** %9
%16 = load i32, i32* %6
%17 = load double, double* %7
%18 = call double @roots_eval(i32 %16, double %17)
store double %18, double* %10
%19 = load i32, i32* %6
%20 = load double, double* %8
%21 = call double @roots_eval(i32 %19, double %20)
store double %21, double* %11
%22 = load double, double* %11
%23 = fcmp oeq double %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %4
%25 = load double, double* %8
%26 = load double*, double** %9
store double %25, double* %26
store i32 1, i32* %5
br label %79
27: ; preds = %4
%28 = load double, double* %10
%29 = fcmp oeq double %28, 0.000000e+00
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 0, i32* %5
br label %79
31: ; preds = %27
%32 = load double, double* %10
%33 = load double, double* %11
%34 = fmul double %32, %33
%35 = fcmp ogt double %34, 0.000000e+00
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 1, i32* %5
br label %79
37: ; preds = %31
%38 = load double, double* %7
store double %38, double* %12
%39 = load double, double* %8
store double %39, double* %13
br label %40
40: ; preds = %75, %37
%41 = load double, double* %13
%42 = load double, double* %12
%43 = fcmp ogt double %41, %42
br i1 %43, label %44, label %76
44: ; preds = %40
%45 = load double, double* %12
%46 = load double, double* %13
%47 = fadd double %45, %46
%48 = fdiv double %47, 2.000000e+00
store volatile double %48, double* %15
%49 = load volatile double, double* %15
%50 = load double, double* %12
%51 = fcmp oeq double %49, %50
br i1 %51, label %56, label %52
52: ; preds = %44
%53 = load volatile double, double* %15
%54 = load double, double* %13
%55 = fcmp oeq double %53, %54
br i1 %55, label %56, label %57
56: ; preds = %52, %44
br label %76
57: ; preds = %52
%58 = load i32, i32* %6
%59 = load volatile double, double* %15
%60 = call double @roots_eval(i32 %58, double %59)
store double %60, double* %14
%61 = load double, double* %14
%62 = fcmp oeq double %61, 0.000000e+00
br i1 %62, label %63, label %64
63: ; preds = %57
br label %76
64: ; preds = %57
%65 = load double, double* %10
%66 = load double, double* %14
%67 = fmul double %65, %66
%68 = fcmp ogt double %67, 0.000000e+00
br i1 %68, label %69, label %72
69: ; preds = %64
%70 = load volatile double, double* %15
store double %70, double* %12
%71 = load double, double* %14
store double %71, double* %10
br label %75
72: ; preds = %64
%73 = load volatile double, double* %15
store double %73, double* %13
%74 = load double, double* %14
store double %74, double* %11
br label %75
75: ; preds = %72, %69
br label %40
76: ; preds = %63, %56, %40
%77 = load volatile double, double* %15
%78 = load double*, double** %9
store double %77, double* %78
store i32 1, i32* %5
br label %79
79: ; preds = %76, %36, %30, %24
%80 = load i32, i32* %5
ret i32 %80
}

LLVM IR (-O2):
define i32 @roots_find(i32 %0, double %1, double %2, double* nocapture writeonly %3) {
%5 = alloca double
%6 = bitcast double* %5 to i8*
%7 = tail call double @roots_eval(i32 %0, double %1)
%8 = tail call double @roots_eval(i32 %0, double %2)
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %42, label %10
10: ; preds = %4
%11 = fcmp oeq double %7, 0.000000e+00
br i1 %11, label %44, label %12
12: ; preds = %10
%13 = fmul double %7, %8
%14 = fcmp ogt double %13, 0.000000e+00
br i1 %14, label %44, label %15
15: ; preds = %12
%16 = fcmp ogt double %2, %1
br i1 %16, label %17, label %40
17: ; preds = %15, %32
%18 = phi double [ %38, %32 ], [ %2, %15 ]
%19 = phi double [ %37, %32 ], [ %1, %15 ]
%20 = phi double [ %36, %32 ], [ %7, %15 ]
%21 = fadd double %19, %18
%22 = fmul double %21, 5.000000e-01
store volatile double %22, double* %5
%23 = load volatile double, double* %5
%24 = fcmp oeq double %23, %19
br i1 %24, label %40, label %25
25: ; preds = %17
%26 = load volatile double, double* %5
%27 = fcmp oeq double %26, %18
br i1 %27, label %40, label %28
28: ; preds = %25
%29 = load volatile double, double* %5
%30 = tail call double @roots_eval(i32 %0, double %29)
%31 = fcmp oeq double %30, 0.000000e+00
br i1 %31, label %40, label %32
32: ; preds = %28
%33 = fmul double %20, %30
%34 = fcmp ogt double %33, 0.000000e+00
%35 = load volatile double, double* %5
%36 = select i1 %34, double %30, double %20
%37 = select i1 %34, double %35, double %19
%38 = select i1 %34, double %18, double %35
%39 = fcmp ogt double %38, %37
br i1 %39, label %17, label %40
40: ; preds = %32, %25, %17, %28, %15
%41 = load volatile double, double* %5
br label %42
42: ; preds = %4, %40
%43 = phi double [ %41, %40 ], [ %2, %4 ]
store double %43, double* %3
br label %44
44: ; preds = %42, %12, %10
%45 = phi i32 [ 0, %10 ], [ 1, %12 ], [ 1, %42 ]
ret i32 %45
}