#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 */
int /*<<< orphan*/ condicoes(double, double, double, double, double);
double fabs(double);
double max_err(int);
double brent(double x0, double x1, int p, double (*f)(double x)) {
  double xm, fxm, x2, fx2;
  double maxerr = max_err(p);
  double fx0 = f(x0);
  double fx1 = f(x1);
  do {
    xm = (x0 + x1) / 2;
    fxm = f(xm);
    x2 = x0 * fx1 * fxm / (fx0 - fx1) / (fx0 - fxm) +
         x1 * fx0 * fxm / (fx1 - fx0) / (fx1 - fxm) +
         xm * fx0 * fx1 / (fxm - fx0) / (fxm - fx1);
    if (!condicoes(x0, x1, x2, fx2, fxm)) {
      x2 = x1 - fx1 * (x1 - x0) / (fx1 - fx0);
      if (!condicoes(x0, x1, x2, fx2, fxm)) {
        x2 = xm;
      }
    }
    fx2 = f(x2);
    if (fx0 * fx2 < 0) {
      x1 = x2;
      fx1 = fx2;
    } else {
      x0 = x2;
      fx0 = fx2;
    }
  } while (fabs(fx2) >= maxerr);
  return x2;
}


x86 assembly (clang, -O0):
<brent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <max_err@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe88(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
subsd  -0x58(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x50(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
subsd  -0x50(%rbp),%xmm2
divsd  %xmm2,%xmm1
movsd  -0x58(%rbp),%xmm2
subsd  -0x30(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x50(%rbp),%xmm2
divsd  %xmm2,%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x58(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm3
movsd  -0x30(%rbp),%xmm4
call   1030 <condicoes@plt>
cmp    $0x0,%eax
jne    12ab <brent+0x18b>
movsd  -0x10(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
subsd  -0x8(%rbp),%xmm2
mulsd  %xmm2,%xmm1
movsd  -0x58(%rbp),%xmm2
subsd  -0x50(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm3
movsd  -0x30(%rbp),%xmm4
call   1030 <condicoes@plt>
cmp    $0x0,%eax
jne    12a6 <brent+0x186>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    12ab <brent+0x18b>
mov    -0x20(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
movsd  -0x50(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12eb <brent+0x1cb>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    12ff <brent+0x1df>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1304 <brent+0x1e4>
movsd  -0x40(%rbp),%xmm0
movaps 0xd00(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x48(%rbp),%xmm0
jae    1166 <brent+0x46>
movsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brent>:
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%rbx
movsd  %xmm1,0x8(%rsp)
movaps %xmm0,0x10(%rsp)
call   1040 <max_err@plt>
movsd  %xmm0,0x48(%rsp)
movaps 0x10(%rsp),%xmm0
call   *%rbx
movaps %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
call   *%rbx
movsd  0x8(%rsp),%xmm2
movapd 0x20(%rsp),%xmm4
unpcklpd 0x10(%rsp),%xmm4
jmp    11c4 <brent+0xa4>
nopl   0x0(%rax)
mov    %cl,%al
movd   %eax,%xmm2
pshufd $0x44,%xmm2,%xmm2
psllq  $0x3f,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
movapd %xmm5,%xmm3
unpcklpd %xmm6,%xmm3
andpd  %xmm2,%xmm4
andnpd %xmm3,%xmm2
orpd   %xmm2,%xmm4
movapd %xmm5,%xmm2
andpd  0xe66(%rip),%xmm2
ucomisd 0x48(%rsp),%xmm2
movapd %xmm0,%xmm2
movapd %xmm1,%xmm0
movapd %xmm5,0x70(%rsp)
jb     135e <brent+0x23e>
movsd  %xmm2,0x8(%rsp)
movapd %xmm4,0x20(%rsp)
movapd %xmm0,0x30(%rsp)
movapd %xmm4,%xmm1
unpckhpd %xmm4,%xmm1
movapd %xmm1,0x50(%rsp)
addsd  %xmm2,%xmm1
mulsd  0xe10(%rip),%xmm1
movapd %xmm1,0x60(%rsp)
movapd %xmm1,%xmm0
call   *%rbx
movapd %xmm0,%xmm6
movsd  0x8(%rsp),%xmm7
movapd %xmm7,%xmm0
movapd 0x20(%rsp),%xmm4
mulsd  %xmm4,%xmm0
mulsd  %xmm6,%xmm0
movapd 0x30(%rsp),%xmm5
movapd %xmm5,%xmm1
subsd  %xmm4,%xmm1
movapd %xmm1,0x80(%rsp)
divsd  %xmm1,%xmm0
movapd %xmm5,%xmm1
subsd  %xmm6,%xmm1
divsd  %xmm1,%xmm0
movapd 0x60(%rsp),%xmm1
unpcklpd %xmm5,%xmm1
mulpd  %xmm4,%xmm1
movapd %xmm5,%xmm2
unpcklpd %xmm6,%xmm2
mulpd  %xmm2,%xmm1
movapd %xmm6,%xmm3
unpcklpd %xmm4,%xmm3
unpcklpd %xmm5,%xmm4
movapd %xmm3,%xmm5
subpd  %xmm4,%xmm5
divpd  %xmm5,%xmm1
subpd  %xmm2,%xmm3
divpd  %xmm3,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movapd %xmm2,0x10(%rsp)
movaps 0x50(%rsp),%xmm0
movapd %xmm7,%xmm1
movaps 0x70(%rsp),%xmm3
movapd %xmm6,0x90(%rsp)
movapd %xmm6,%xmm4
call   1030 <condicoes@plt>
movapd 0x10(%rsp),%xmm0
test   %eax,%eax
jne    1310 <brent+0x1f0>
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm3
movapd 0x50(%rsp),%xmm0
subsd  %xmm0,%xmm3
mulsd  0x30(%rsp),%xmm3
divsd  0x80(%rsp),%xmm3
movapd %xmm1,%xmm2
subsd  %xmm3,%xmm2
movsd  %xmm2,0x10(%rsp)
movaps 0x70(%rsp),%xmm3
movapd 0x90(%rsp),%xmm4
call   1030 <condicoes@plt>
test   %eax,%eax
movapd 0x60(%rsp),%xmm0
je     1310 <brent+0x1f0>
movsd  0x10(%rsp),%xmm0
nopl   (%rax)
movapd %xmm0,0x10(%rsp)
call   *%rbx
movapd 0x10(%rsp),%xmm6
movapd %xmm0,%xmm5
movapd 0x20(%rsp),%xmm4
movapd %xmm4,%xmm0
mulsd  %xmm5,%xmm0
xor    %eax,%eax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
seta   %cl
movapd %xmm6,%xmm0
ja     1349 <brent+0x229>
movsd  0x8(%rsp),%xmm0
movapd %xmm5,%xmm1
ja     1170 <brent+0x50>
movapd 0x30(%rsp),%xmm1
jmp    1170 <brent+0x50>
movapd %xmm6,%xmm0
add    $0xa0,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @brent(double %0, double %1, i32 %2, double (double)* nocapture %3) {
%5 = tail call double @max_err(i32 %2)
%6 = tail call double %3(double %0)
%7 = tail call double %3(double %1)
%8 = insertelement <2 x double> poison, double %0, i64 1
%9 = insertelement <2 x double> %8, double %6, i64 0
br label %10
10: ; preds = %53, %4
%11 = phi double [ %1, %4 ], [ %58, %53 ]
%12 = phi double [ undef, %4 ], [ %55, %53 ]
%13 = phi double [ %7, %4 ], [ %64, %53 ]
%14 = phi <2 x double> [ %9, %4 ], [ %63, %53 ]
%15 = extractelement <2 x double> %14, i64 1
%16 = fadd double %11, %15
%17 = fmul double %16, 5.000000e-01
%18 = tail call double %3(double %17)
%19 = extractelement <2 x double> %14, i64 0
%20 = fmul double %11, %19
%21 = fmul double %20, %18
%22 = fsub double %13, %19
%23 = fdiv double %21, %22
%24 = fsub double %13, %18
%25 = fdiv double %23, %24
%26 = insertelement <2 x double> poison, double %17, i64 0
%27 = insertelement <2 x double> %26, double %13, i64 1
%28 = fmul <2 x double> %14, %27
%29 = insertelement <2 x double> poison, double %13, i64 0
%30 = insertelement <2 x double> %29, double %18, i64 1
%31 = fmul <2 x double> %30, %28
%32 = insertelement <2 x double> poison, double %18, i64 0
%33 = shufflevector <2 x double> %32, <2 x double> %14, <2 x i32> <i32 0, i32 2>
%34 = insertelement <2 x double> %14, double %13, i64 1
%35 = fsub <2 x double> %33, %34
%36 = fdiv <2 x double> %31, %35
%37 = fsub <2 x double> %33, %30
%38 = fdiv <2 x double> %36, %37
%39 = extractelement <2 x double> %38, i64 1
%40 = fadd double %39, %25
%41 = extractelement <2 x double> %38, i64 0
%42 = fadd double %41, %40
%43 = tail call i32 @condicoes(double %15, double %11, double %42, double %12, double %18)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %10
%46 = fsub double %11, %15
%47 = fmul double %46, %13
%48 = fdiv double %47, %22
%49 = fsub double %11, %48
%50 = tail call i32 @condicoes(double %15, double %11, double %49, double %12, double %18)
%51 = icmp eq i32 %50, 0
%52 = select i1 %51, double %17, double %49
br label %53
53: ; preds = %45, %10
%54 = phi double [ %42, %10 ], [ %52, %45 ]
%55 = tail call double %3(double %54)
%56 = fmul double %19, %55
%57 = fcmp olt double %56, 0.000000e+00
%58 = select i1 %57, double %54, double %11
%59 = insertelement <2 x i1> poison, i1 %57, i64 0
%60 = shufflevector <2 x i1> %59, <2 x i1> poison, <2 x i32> zeroinitializer
%61 = insertelement <2 x double> poison, double %55, i64 0
%62 = insertelement <2 x double> %61, double %54, i64 1
%63 = select <2 x i1> %60, <2 x double> %14, <2 x double> %62
%64 = select i1 %57, double %55, double %13
%65 = tail call double @llvm.fabs.f64(double %55)
%66 = fcmp ult double %65, %5
br i1 %66, label %67, label %10
67: ; preds = %53
ret double %54
}