#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 */
scalar_t__ fabs(double);
double stub1(void *, double);
double stub2(void *, double);
double stub3(void *, double);
double stub4(void *, double);
int zbrac(double *x1p, double *x2p, double (*func)(void *fdata, double tp),
          void *fdata) {
  int i;
  double x1, x2;
  double f1, f2;
  x1 = *x1p;
  x2 = *x2p;
  if (x1 == x2)
    return -1;
  f1 = (*func)(fdata, x1);
  f2 = (*func)(fdata, x2);
  for (i = 0; i < 40; i++) {
    if ((f1 * f2) < 0.0) {
      *x1p = x1;
      *x2p = x2;
      return 0;
    }
    if (fabs(f2) > fabs(f1)) {
      x1 += 1.618034 * (x1 - x2);
      f1 = (*func)(fdata, x1);
    } else {
      x2 += 1.618034 * (x2 - x1);
      f2 = (*func)(fdata, x2);
    }
  }
  return -2;
}


x86 assembly (clang, -O0):
<zbrac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jne    1164 <zbrac+0x54>
jp     1164 <zbrac+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    1291 <zbrac+0x181>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x28,-0x2c(%rbp)
jge    128a <zbrac+0x17a>
movsd  -0x48(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11da <zbrac+0xca>
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1291 <zbrac+0x181>
movsd  -0x50(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
jle    123f <zbrac+0x12f>
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  0xde7(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
jmp    1277 <zbrac+0x167>
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  0xdaa(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rdi
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
jmp    127c <zbrac+0x16c>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1193 <zbrac+0x83>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zbrac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  (%rdi),%xmm0
movsd  (%rsi),%xmm1
mov    $0xffffffff,%eax
ucomisd %xmm1,%xmm0
jne    1137 <zbrac+0x27>
jnp    1240 <zbrac+0x130>
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rcx,%rdi
movsd  %xmm0,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
call   *%rdx
movsd  %xmm0,0x18(%rsp)
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm0
call   *%r13
movsd  0x18(%rsp),%xmm2
mov    $0x28,%ebp
jmp    11b3 <zbrac+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
mulsd  0xe68(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    %r15,%rdi
movsd  %xmm0,0x8(%rsp)
call   *%r13
movsd  0x18(%rsp),%xmm2
add    $0xffffffff,%ebp
je     1220 <zbrac+0x110>
movapd %xmm2,%xmm3
mulsd  %xmm0,%xmm3
xorpd  %xmm1,%xmm1
ucomisd %xmm3,%xmm1
ja     1227 <zbrac+0x117>
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
call   1030 <fabs@plt>
mov    %rax,%rbx
movsd  0x18(%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%rbx
jle    1180 <zbrac+0x70>
movsd  0x10(%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
mulsd  0xdff(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    %r15,%rdi
movsd  %xmm0,0x10(%rsp)
call   *%r13
movapd %xmm0,%xmm2
movsd  0x20(%rsp),%xmm0
add    $0xffffffff,%ebp
jne    11b3 <zbrac+0xa3>
mov    $0xfffffffe,%eax
jmp    1240 <zbrac+0x130>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r12)
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @zbrac(double* nocapture %0, double* nocapture %1, double (i8*, double)* nocapture %2, i8* %3) {
%5 = load double, double* %0
%6 = load double, double* %1
%7 = fcmp oeq double %5, %6
br i1 %7, label %39, label %8
8: ; preds = %4
%9 = tail call double %2(i8* %3, double %5)
%10 = tail call double %2(i8* %3, double %6)
br label %11
11: ; preds = %8, %32
%12 = phi double [ %10, %8 ], [ %36, %32 ]
%13 = phi double [ %9, %8 ], [ %35, %32 ]
%14 = phi double [ %6, %8 ], [ %34, %32 ]
%15 = phi double [ %5, %8 ], [ %33, %32 ]
%16 = phi i32 [ 0, %8 ], [ %37, %32 ]
%17 = fmul double %13, %12
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %11
store double %15, double* %0
store double %14, double* %1
br label %39
20: ; preds = %11
%21 = tail call i64 @fabs(double %12)
%22 = tail call i64 @fabs(double %13)
%23 = icmp sgt i64 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = fsub double %15, %14
%26 = tail call double @llvm.fmuladd.f64(double %25, double 0x3FF9E3779E9D0E99, double %15)
%27 = tail call double %2(i8* %3, double %26)
br label %32
28: ; preds = %20
%29 = fsub double %14, %15
%30 = tail call double @llvm.fmuladd.f64(double %29, double 0x3FF9E3779E9D0E99, double %14)
%31 = tail call double %2(i8* %3, double %30)
br label %32
32: ; preds = %24, %28
%33 = phi double [ %26, %24 ], [ %15, %28 ]
%34 = phi double [ %14, %24 ], [ %30, %28 ]
%35 = phi double [ %27, %24 ], [ %13, %28 ]
%36 = phi double [ %12, %24 ], [ %31, %28 ]
%37 = add nuw nsw i32 %16, 1
%38 = icmp eq i32 %37, 40
br i1 %38, label %39, label %11
39: ; preds = %32, %4, %19
%40 = phi i32 [ 0, %19 ], [ -1, %4 ], [ -2, %32 ]
ret i32 %40
}