#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 hypot(double, double);
double my_sqrt(double);
void c_sqrt(double *aa) {
  double mag = hypot(aa[0], aa[1]);
  double rr = my_sqrt((mag + aa[0]) * 0.5);
  double ii = my_sqrt((mag - aa[0]) * 0.5);
  if (aa[1] < 0.0)
    ii = -ii;
  aa[0] = rr;
  aa[1] = ii;
}


x86 assembly (clang, -O0):
<c_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
call   1030 <hypot@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
addsd  (%rax),%xmm0
movsd  0xea4(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <my_sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm0
movsd  0xe81(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <my_sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd 0x8(%rax),%xmm0
jbe    11c0 <c_sqrt+0xa0>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_sqrt>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
call   1030 <hypot@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movsd  (%rbx),%xmm0
addsd  %xmm1,%xmm0
mulsd  0xeb1(%rip),%xmm0
call   1040 <my_sqrt@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
subsd  (%rbx),%xmm0
mulsd  0xe95(%rip),%xmm0
call   1040 <my_sqrt@plt>
movsd  0x8(%rbx),%xmm1
movapd 0xe93(%rip),%xmm2
xorpd  %xmm0,%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm1
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rbx)
movlpd %xmm1,0x8(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @c_sqrt(double* %0) {
%2 = alloca double*
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double* %0, double** %2
%6 = load double*, double** %2
%7 = getelementptr inbounds double, double* %6, i64 0
%8 = load double, double* %7
%9 = load double*, double** %2
%10 = getelementptr inbounds double, double* %9, i64 1
%11 = load double, double* %10
%12 = call double @hypot(double %8, double %11)
store double %12, double* %3
%13 = load double, double* %3
%14 = load double*, double** %2
%15 = getelementptr inbounds double, double* %14, i64 0
%16 = load double, double* %15
%17 = fadd double %13, %16
%18 = fmul double %17, 5.000000e-01
%19 = call double @my_sqrt(double %18)
store double %19, double* %4
%20 = load double, double* %3
%21 = load double*, double** %2
%22 = getelementptr inbounds double, double* %21, i64 0
%23 = load double, double* %22
%24 = fsub double %20, %23
%25 = fmul double %24, 5.000000e-01
%26 = call double @my_sqrt(double %25)
store double %26, double* %5
%27 = load double*, double** %2
%28 = getelementptr inbounds double, double* %27, i64 1
%29 = load double, double* %28
%30 = fcmp olt double %29, 0.000000e+00
br i1 %30, label %31, label %34
31: ; preds = %1
%32 = load double, double* %5
%33 = fneg double %32
store double %33, double* %5
br label %34
34: ; preds = %31, %1
%35 = load double, double* %4
%36 = load double*, double** %2
%37 = getelementptr inbounds double, double* %36, i64 0
store double %35, double* %37
%38 = load double, double* %5
%39 = load double*, double** %2
%40 = getelementptr inbounds double, double* %39, i64 1
store double %38, double* %40
ret void
}

LLVM IR (-O2):
define void @c_sqrt(double* nocapture %0) {
%2 = load double, double* %0
%3 = getelementptr inbounds double, double* %0, i64 1
%4 = load double, double* %3
%5 = tail call double @hypot(double %2, double %4)
%6 = load double, double* %0
%7 = fadd double %5, %6
%8 = fmul double %7, 5.000000e-01
%9 = tail call double @my_sqrt(double %8)
%10 = load double, double* %0
%11 = fsub double %5, %10
%12 = fmul double %11, 5.000000e-01
%13 = tail call double @my_sqrt(double %12)
%14 = load double, double* %3
%15 = fcmp olt double %14, 0.000000e+00
%16 = fneg double %13
%17 = select i1 %15, double %16, double %13
store double %9, double* %0
store double %17, double* %3
ret void
}