#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 fabs(double const);
int sqrt(double const);
double rat_root(const double a, const double b, const double c,
                const double sign) {
  double bh = (fabs(b) + sqrt(b * b + 4 * a * c)) / 2;
  return sign * (b * sign <= 0 ? bh / a : c / bh);
}


x86 assembly (clang, -O0):
<rat_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  0xea5(%rip),%xmm1
mulsd  -0x8(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jb     11bf <rat_root+0x9f>
movsd  -0x28(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11ce <rat_root+0xae>
movsd  -0x18(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rat_root>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,(%rsp)
movaps %xmm1,%xmm0
call   1030 <fabs@plt>
mov    %eax,%ebx
movsd  0xeb2(%rip),%xmm1
mulsd  (%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  0x18(%rsp),%xmm2
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x10(%rsp),%xmm3
mulsd  %xmm2,%xmm3
xorpd  %xmm1,%xmm1
ucomisd %xmm3,%xmm1
jae    11a8 <rat_root+0x88>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    11ad <rat_root+0x8d>
divsd  (%rsp),%xmm0
mulsd  %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @rat_root(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%10 = load double, double* %6
%11 = call i32 @fabs(double %10)
%12 = load double, double* %6
%13 = load double, double* %6
%14 = load double, double* %5
%15 = fmul double 4.000000e+00, %14
%16 = load double, double* %7
%17 = fmul double %15, %16
%18 = call double @llvm.fmuladd.f64(double %12, double %13, double %17)
%19 = call i32 @sqrt(double %18)
%20 = add nsw i32 %11, %19
%21 = sdiv i32 %20, 2
%22 = sitofp i32 %21 to double
store double %22, double* %9
%23 = load double, double* %8
%24 = load double, double* %6
%25 = load double, double* %8
%26 = fmul double %24, %25
%27 = fcmp ole double %26, 0.000000e+00
br i1 %27, label %28, label %32
28: ; preds = %4
%29 = load double, double* %9
%30 = load double, double* %5
%31 = fdiv double %29, %30
br label %36
32: ; preds = %4
%33 = load double, double* %7
%34 = load double, double* %9
%35 = fdiv double %33, %34
br label %36
36: ; preds = %32, %28
%37 = phi double [ %31, %28 ], [ %35, %32 ]
%38 = fmul double %23, %37
ret double %38
}

LLVM IR (-O2):
define double @rat_root(double %0, double %1, double %2, double %3) {
%5 = tail call i32 @fabs(double %1)
%6 = fmul double %0, 4.000000e+00
%7 = fmul double %6, %2
%8 = tail call double @llvm.fmuladd.f64(double %1, double %1, double %7)
%9 = tail call i32 @sqrt(double %8)
%10 = add nsw i32 %9, %5
%11 = sdiv i32 %10, 2
%12 = sitofp i32 %11 to double
%13 = fmul double %1, %3
%14 = fcmp ugt double %13, 0.000000e+00
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = fdiv double %12, %0
br label %19
17: ; preds = %4
%18 = fdiv double %2, %12
br label %19
19: ; preds = %17, %15
%20 = phi double [ %16, %15 ], [ %18, %17 ]
%21 = fmul double %20, %3
ret double %21
}