#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 sqroot(double);
double magntd(double *z) {
  if ((!z[1]))
    return ((z[0]) >= 0 ? (z[0]) : -(z[0]));
  else if ((!z[0]))
    return ((z[1]) >= 0 ? (z[1]) : -(z[1]));
  else {
    double r;
    r = z[0] * z[0] + z[1] * z[1];
    return sqroot(r);
  }
}


x86 assembly (clang, -O0):
<magntd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1192 <magntd+0x82>
jp     1192 <magntd+0x82>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     115f <magntd+0x4f>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1183 <magntd+0x73>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1248 <magntd+0x138>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    120a <magntd+0xfa>
jp     120a <magntd+0xfa>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d6 <magntd+0xc6>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11fb <magntd+0xeb>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1248 <magntd+0x138>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <sqroot@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magntd>:
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1125 <magntd+0x15>
jnp    1142 <magntd+0x32>
ucomisd %xmm0,%xmm1
jne    112d <magntd+0x1d>
jnp    1160 <magntd+0x50>
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
jmp    1030 <sqroot@plt>
movapd 0xeb6(%rip),%xmm2
xorpd  %xmm1,%xmm2
cmpnlesd %xmm1,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
ret
movapd 0xe98(%rip),%xmm1
xorpd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
cmpnlesd %xmm2,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @magntd(double* %0) {
%2 = alloca double
%3 = alloca double*
%4 = alloca double
store double* %0, double** %3
%5 = load double*, double** %3
%6 = getelementptr inbounds double, double* %5, i64 1
%7 = load double, double* %6
%8 = fcmp une double %7, 0.000000e+00
br i1 %8, label %25, label %9
9: ; preds = %1
%10 = load double*, double** %3
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = fcmp oge double %12, 0.000000e+00
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load double*, double** %3
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
br label %23
18: ; preds = %9
%19 = load double*, double** %3
%20 = getelementptr inbounds double, double* %19, i64 0
%21 = load double, double* %20
%22 = fneg double %21
br label %23
23: ; preds = %18, %14
%24 = phi double [ %17, %14 ], [ %22, %18 ]
store double %24, double* %2
br label %63
25: ; preds = %1
%26 = load double*, double** %3
%27 = getelementptr inbounds double, double* %26, i64 0
%28 = load double, double* %27
%29 = fcmp une double %28, 0.000000e+00
br i1 %29, label %46, label %30
30: ; preds = %25
%31 = load double*, double** %3
%32 = getelementptr inbounds double, double* %31, i64 1
%33 = load double, double* %32
%34 = fcmp oge double %33, 0.000000e+00
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load double*, double** %3
%37 = getelementptr inbounds double, double* %36, i64 1
%38 = load double, double* %37
br label %44
39: ; preds = %30
%40 = load double*, double** %3
%41 = getelementptr inbounds double, double* %40, i64 1
%42 = load double, double* %41
%43 = fneg double %42
br label %44
44: ; preds = %39, %35
%45 = phi double [ %38, %35 ], [ %43, %39 ]
store double %45, double* %2
br label %63
46: ; preds = %25
%47 = load double*, double** %3
%48 = getelementptr inbounds double, double* %47, i64 0
%49 = load double, double* %48
%50 = load double*, double** %3
%51 = getelementptr inbounds double, double* %50, i64 0
%52 = load double, double* %51
%53 = load double*, double** %3
%54 = getelementptr inbounds double, double* %53, i64 1
%55 = load double, double* %54
%56 = load double*, double** %3
%57 = getelementptr inbounds double, double* %56, i64 1
%58 = load double, double* %57
%59 = fmul double %55, %58
%60 = call double @llvm.fmuladd.f64(double %49, double %52, double %59)
store double %60, double* %4
%61 = load double, double* %4
%62 = call double @sqroot(double %61)
store double %62, double* %2
br label %63
63: ; preds = %46, %44, %23
%64 = load double, double* %2
ret double %64
}

LLVM IR (-O2):
define double @magntd(double* nocapture %0) {
%2 = getelementptr inbounds double, double* %0, i64 1
%3 = load double, double* %2
%4 = fcmp une double %3, 0.000000e+00
%5 = load double, double* %0
br i1 %4, label %10, label %6
6: ; preds = %1
%7 = fcmp ult double %5, 0.000000e+00
%8 = fneg double %5
%9 = select i1 %7, double %8, double %5
br label %20
10: ; preds = %1
%11 = fcmp une double %5, 0.000000e+00
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = fcmp ult double %3, 0.000000e+00
%14 = fneg double %3
%15 = select i1 %13, double %14, double %3
br label %20
16: ; preds = %10
%17 = fmul double %3, %3
%18 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %17)
%19 = tail call double @sqroot(double %18)
br label %20
20: ; preds = %16, %12, %6
%21 = phi double [ %19, %16 ], [ %15, %12 ], [ %9, %6 ]
ret double %21
}