#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 fabs(double const);
double sqrt(double const);
double d2norm(const double a, const double b) {
  double scale;
  const double zero = 0.0;
  scale = fabs(a) + fabs(b);
  if (scale == zero)
    return zero;
  else
    return scale * sqrt((a / scale) * (a / scale) + (b / scale) * (b / scale));
}


x86 assembly (clang, -O0):
<d2norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xeca(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movaps 0xeba(%rip),%xmm2
pand   %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1178 <d2norm+0x68>
jp     1178 <d2norm+0x68>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11cc <d2norm+0xbc>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
divsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm3
divsd  -0x20(%rbp),%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2norm>:
sub    $0x18,%rsp
movapd 0xee4(%rip),%xmm3
movapd %xmm0,%xmm2
andpd  %xmm3,%xmm2
andpd  %xmm1,%xmm3
addsd  %xmm2,%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm3
jne    1138 <d2norm+0x28>
jnp    1173 <d2norm+0x63>
divsd  %xmm3,%xmm0
divsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     115c <d2norm+0x4c>
sqrtsd %xmm0,%xmm0
jmp    116b <d2norm+0x5b>
movapd %xmm3,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm3,%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @d2norm(double %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = tail call double @llvm.fabs.f64(double %1)
%5 = fadd double %3, %4
%6 = fcmp oeq double %5, 0.000000e+00
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = fdiv double %0, %5
%9 = fdiv double %1, %5
%10 = fmul double %9, %9
%11 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %10)
%12 = tail call double @sqrt(double %11)
%13 = fmul double %5, %12
br label %14
14: ; preds = %2, %7
%15 = phi double [ %13, %7 ], [ 0.000000e+00, %2 ]
ret double %15
}