#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 acos(double);
double cbrt(double);
double cos(double);
double sqrt(double);
double cubic(double p, double q, double r) {
  double p_3, p_3sq;
  double u_3, v;
  double m, mcube, n, wsq, s, cosk;
  p_3 = p / 3.0;
  p_3sq = p_3 * p_3;
  v = r + p_3 * (2.0 * p_3sq - q);
  u_3 = q / 3.0 - p_3sq;
  wsq = 4.0 * u_3 * u_3 * u_3 + v * v;
  if (wsq >= 0.0) {
    if (v <= 0.0)
      mcube = 0.5 * (-v + sqrt(wsq));
    else
      mcube = 0.5 * (-v - sqrt(wsq));
    m = cbrt(mcube);
    if (m != 0.0)
      n = -u_3 / m;
    else
      n = 0.0;
    return m + n - p_3;
  } else {
    if (u_3 < 0.0) {
      s = sqrt(-u_3);
      cosk = cos(acos(0.5 * v / (s * u_3)) / 3.0);
      if (p_3 < 0.0)
        return 2.0 * s * cosk - p_3;
      else
        return s * (-cosk - sqrt(3.0 - 3.0 * cosk * cosk)) - p_3;
    } else
      return cbrt(v) - p_3;
  }
}


x86 assembly (clang, -O0):
<cubic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xea1(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
movq   %xmm3,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm3
addsd  %xmm2,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe3c(%rip),%xmm1
divsd  %xmm1,%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe1e(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     132f <cubic+0x1ef>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     1272 <cubic+0x132>
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  -0x78(%rbp),%xmm1
addsd  %xmm0,%xmm1
movsd  0xdac(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    12b7 <cubic+0x177>
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  -0x80(%rbp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xd62(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1040 <cbrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12e3 <cubic+0x1a3>
jp     12e3 <cubic+0x1a3>
jmp    130e <cubic+0x1ce>
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1316 <cubic+0x1d6>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    14af <cubic+0x36f>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    149b <cubic+0x35b>
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  0xca5(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1030 <acos@plt>
movsd  0xc7d(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    13e7 <cubic+0x2a7>
movsd  0xc69(%rip),%xmm0
mulsd  -0x68(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    14af <cubic+0x36f>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x70(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xbe8(%rip),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xbbb(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  -0x90(%rbp),%xmm2
ff
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
subsd  %xmm1,%xmm2
movsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    14af <cubic+0x36f>
movsd  -0x40(%rbp),%xmm0
call   1040 <cbrt@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cubic>:
sub    $0x38,%rsp
movapd %xmm0,%xmm3
movsd  0xeb0(%rip),%xmm0
divsd  %xmm0,%xmm3
movapd %xmm3,%xmm4
mulsd  %xmm3,%xmm4
movapd %xmm4,%xmm5
addsd  %xmm4,%xmm5
subsd  %xmm1,%xmm5
mulsd  %xmm3,%xmm5
addsd  %xmm2,%xmm5
divsd  %xmm0,%xmm1
subsd  %xmm4,%xmm1
movsd  0xe88(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movapd %xmm5,%xmm2
mulsd  %xmm5,%xmm2
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
movsd  %xmm3,0x8(%rsp)
jae    11ce <cubic+0x8e>
ucomisd %xmm1,%xmm2
jbe    1200 <cubic+0xc0>
movapd 0xe7a(%rip),%xmm0
xorpd  %xmm1,%xmm0
movsd  0xe56(%rip),%xmm2
ucomisd %xmm1,%xmm2
jb     1228 <cubic+0xe8>
sqrtsd %xmm0,%xmm0
jmp    1245 <cubic+0x105>
ucomisd %xmm5,%xmm2
movapd %xmm1,0x20(%rsp)
jae    120e <cubic+0xce>
xorpd  0xe4e(%rip),%xmm5
movapd %xmm5,%xmm4
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     12a0 <cubic+0x160>
xorps  %xmm5,%xmm5
sqrtsd %xmm0,%xmm5
jmp    12cc <cubic+0x18c>
movapd %xmm5,%xmm0
call   1040 <cbrt@plt>
jmp    1303 <cubic+0x1c3>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jb     12b7 <cubic+0x177>
xorps  %xmm4,%xmm4
sqrtsd %xmm0,%xmm4
jmp    12cc <cubic+0x18c>
movapd %xmm1,0x20(%rsp)
movapd %xmm5,0x10(%rsp)
call   1060 <sqrt@plt>
movapd 0x10(%rsp),%xmm5
movapd 0x20(%rsp),%xmm1
movsd  %xmm0,0x10(%rsp)
mulsd  0xdbd(%rip),%xmm5
mulsd  %xmm0,%xmm1
divsd  %xmm1,%xmm5
movapd %xmm5,%xmm0
call   1030 <acos@plt>
divsd  0xd94(%rip),%xmm0
call   1050 <cos@plt>
xorpd  %xmm2,%xmm2
movsd  0x8(%rsp),%xmm3
ucomisd %xmm3,%xmm2
jbe    130e <cubic+0x1ce>
movsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm1
subsd  %xmm3,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
ret
movsd  %xmm4,0x10(%rsp)
call   1060 <sqrt@plt>
movsd  0x10(%rsp),%xmm4
movapd %xmm0,%xmm5
jmp    12cc <cubic+0x18c>
movapd %xmm5,0x10(%rsp)
call   1060 <sqrt@plt>
movapd 0x10(%rsp),%xmm5
movapd %xmm0,%xmm4
subsd  %xmm5,%xmm4
mulsd  0xd38(%rip),%xmm4
movapd %xmm4,%xmm0
call   1040 <cbrt@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12ed <cubic+0x1ad>
jnp    12ff <cubic+0x1bf>
movapd 0x20(%rsp),%xmm1
xorpd  0xd35(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
ret
movapd 0xd1a(%rip),%xmm4
xorpd  %xmm0,%xmm4
movsd  0xcfe(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xcce(%rip),%xmm1
ucomisd %xmm2,%xmm1
jb     1341 <cubic+0x201>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    135c <cubic+0x21c>
movapd %xmm1,%xmm0
movapd %xmm4,0x20(%rsp)
call   1060 <sqrt@plt>
movapd 0x20(%rsp),%xmm4
movsd  0x8(%rsp),%xmm3
subsd  %xmm0,%xmm4
movsd  0x10(%rsp),%xmm0
mulsd  %xmm4,%xmm0
subsd  %xmm3,%xmm0
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
define double @cubic(double %0, double %1, double %2) {
%4 = fdiv double %0, 3.000000e+00
%5 = fmul double %4, %4
%6 = fneg double %1
%7 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double %6)
%8 = tail call double @llvm.fmuladd.f64(double %4, double %7, double %2)
%9 = fdiv double %1, 3.000000e+00
%10 = fsub double %9, %5
%11 = fmul double %10, 4.000000e+00
%12 = fmul double %10, %11
%13 = fmul double %8, %8
%14 = tail call double @llvm.fmuladd.f64(double %12, double %10, double %13)
%15 = fcmp ult double %14, 0.000000e+00
br i1 %15, label %37, label %16
16: ; preds = %3
%17 = fcmp ugt double %8, 0.000000e+00
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call double @sqrt(double %14)
br label %23
20: ; preds = %16
%21 = fneg double %8
%22 = tail call double @sqrt(double %14)
br label %23
23: ; preds = %20, %18
%24 = phi double [ %22, %20 ], [ %8, %18 ]
%25 = phi double [ %21, %20 ], [ %19, %18 ]
%26 = fsub double %25, %24
%27 = fmul double %26, 5.000000e-01
%28 = tail call double @cbrt(double %27)
%29 = fcmp une double %28, 0.000000e+00
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = fneg double %10
%32 = fdiv double %31, %28
br label %33
33: ; preds = %23, %30
%34 = phi double [ %32, %30 ], [ 0.000000e+00, %23 ]
%35 = fadd double %28, %34
%36 = fsub double %35, %4
br label %64
37: ; preds = %3
%38 = fcmp olt double %10, 0.000000e+00
br i1 %38, label %39, label %61
39: ; preds = %37
%40 = fneg double %10
%41 = tail call double @sqrt(double %40)
%42 = fmul double %8, 5.000000e-01
%43 = fmul double %10, %41
%44 = fdiv double %42, %43
%45 = tail call double @acos(double %44)
%46 = fdiv double %45, 3.000000e+00
%47 = tail call double @cos(double %46)
%48 = fcmp olt double %4, 0.000000e+00
br i1 %48, label %49, label %53
49: ; preds = %39
%50 = fmul double %41, 2.000000e+00
%51 = fneg double %4
%52 = tail call double @llvm.fmuladd.f64(double %50, double %47, double %51)
br label %64
53: ; preds = %39
%54 = fneg double %47
%55 = fmul double %47, -3.000000e+00
%56 = tail call double @llvm.fmuladd.f64(double %55, double %47, double 3.000000e+00)
%57 = tail call double @sqrt(double %56)
%58 = fsub double %54, %57
%59 = fneg double %4
%60 = tail call double @llvm.fmuladd.f64(double %41, double %58, double %59)
br label %64
61: ; preds = %37
%62 = tail call double @cbrt(double %8)
%63 = fsub double %62, %4
br label %64
64: ; preds = %61, %53, %49, %33
%65 = phi double [ %36, %33 ], [ %52, %49 ], [ %60, %53 ], [ %63, %61 ]
ret double %65
}