#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 dd_is_zero(double const *);
int /*<<< orphan*/ dd_sqr_d(double, double *);
int /*<<< orphan*/ dd_sub(double const *, double *, double *);
double dd_two_sum(double, double, double *);
double sqrt(double const);
void dd_sqrt(const double *a, double *b) {
  if (dd_is_zero(a) == 1) {
    b[0] = 0.0;
    b[1] = 0.0;
  } else if (a[0] < 0.0) {
    b[0] = -1.0;
    b[0] = 0.0;
  } else {
    const double x = 1.0 / sqrt(a[0]);
    double ax = a[0] * x;
    double ddax[2];
    double sqax[2];
    double y[2];
    dd_sqr_d(ax, sqax);
    dd_sub(a, sqax, y);
    b[0] = dd_two_sum(ax, y[0] * (x * 0.5), &b[1]);
  }
}


x86 assembly (clang, -O0):
<dd_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <dd_is_zero@plt>
cmp    $0x1,%eax
jne    118e <dd_sqrt+0x3e>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
jmp    1246 <dd_sqrt+0xf6>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    11bf <dd_sqrt+0x6f>
mov    -0x10(%rbp),%rax
movsd  0xe65(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    1241 <dd_sqrt+0xf1>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe31(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    -0x40(%rbp),%rdi
call   1070 <dd_sqr_d@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <dd_sub@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  0xddd(%rip),%xmm2
mulsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm1
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1050 <dd_two_sum@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1246 <dd_sqrt+0xf6>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dd_sqrt>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <dd_is_zero@plt>
cmp    $0x1,%eax
jne    1177 <dd_sqrt+0x27>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%r14)
jmp    1202 <dd_sqrt+0xb2>
movsd  (%rbx),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    118e <dd_sqrt+0x3e>
movq   $0x0,(%r14)
jmp    1202 <dd_sqrt+0xb2>
ucomisd %xmm1,%xmm0
jb     119a <dd_sqrt+0x4a>
sqrtsd %xmm0,%xmm0
jmp    119f <dd_sqrt+0x4f>
call   1060 <sqrt@plt>
movsd  0xe59(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rbx),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1070 <dd_sqr_d@plt>
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <dd_sub@plt>
movsd  (%rsp),%xmm1
mulsd  0xe20(%rip),%xmm1
mulsd  0x10(%rsp),%xmm1
lea    0x8(%r14),%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <dd_two_sum@plt>
movsd  %xmm0,(%r14)
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @dd_sqrt(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca [2 x double]
%8 = alloca [2 x double]
%9 = alloca [2 x double]
store double* %0, double** %3
store double* %1, double** %4
%10 = load double*, double** %3
%11 = call i32 @dd_is_zero(double* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 0
store double 0.000000e+00, double* %15
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 1
store double 0.000000e+00, double* %17
br label %58
18: ; preds = %2
%19 = load double*, double** %3
%20 = getelementptr inbounds double, double* %19, i64 0
%21 = load double, double* %20
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load double*, double** %4
%25 = getelementptr inbounds double, double* %24, i64 0
store double -1.000000e+00, double* %25
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i64 0
store double 0.000000e+00, double* %27
br label %57
28: ; preds = %18
%29 = load double*, double** %3
%30 = getelementptr inbounds double, double* %29, i64 0
%31 = load double, double* %30
%32 = call double @sqrt(double %31)
%33 = fdiv double 1.000000e+00, %32
store double %33, double* %5
%34 = load double*, double** %3
%35 = getelementptr inbounds double, double* %34, i64 0
%36 = load double, double* %35
%37 = load double, double* %5
%38 = fmul double %36, %37
store double %38, double* %6
%39 = load double, double* %6
%40 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 0
%41 = call i32 @dd_sqr_d(double %39, double* %40)
%42 = load double*, double** %3
%43 = getelementptr inbounds [2 x double], [2 x double]* %8, i64 0, i64 0
%44 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%45 = call i32 @dd_sub(double* %42, double* %43, double* %44)
%46 = load double, double* %6
%47 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%48 = load double, double* %47
%49 = load double, double* %5
%50 = fmul double %49, 5.000000e-01
%51 = fmul double %48, %50
%52 = load double*, double** %4
%53 = getelementptr inbounds double, double* %52, i64 1
%54 = call double @dd_two_sum(double %46, double %51, double* %53)
%55 = load double*, double** %4
%56 = getelementptr inbounds double, double* %55, i64 0
store double %54, double* %56
br label %57
57: ; preds = %28, %23
br label %58
58: ; preds = %57, %13
ret void
}

LLVM IR (-O2):
define void @dd_sqrt(double* %0, double* %1) {
%3 = alloca [2 x double]
%4 = alloca [2 x double]
%5 = tail call i32 @dd_is_zero(double* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = bitcast double* %1 to i8*
br label %29
9: ; preds = %2
%10 = load double, double* %0
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %9
store double 0.000000e+00, double* %1
br label %29
13: ; preds = %9
%14 = tail call double @sqrt(double %10)
%15 = fdiv double 1.000000e+00, %14
%16 = load double, double* %0
%17 = fmul double %16, %15
%18 = bitcast [2 x double]* %3 to i8*
%19 = bitcast [2 x double]* %4 to i8*
%20 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 0
%21 = call i32 @dd_sqr_d(double %17, double* %20)
%22 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%23 = call i32 @dd_sub(double* %0, double* %20, double* %22)
%24 = load double, double* %22
%25 = fmul double %15, 5.000000e-01
%26 = fmul double %25, %24
%27 = getelementptr inbounds double, double* %1, i64 1
%28 = call double @dd_two_sum(double %17, double %26, double* %27)
store double %28, double* %1
br label %29
29: ; preds = %12, %13, %7
ret void
}