#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(int);
double xhypot(const double x, const double y) {
  double xabs = fabs(x);
  double yabs = fabs(y);
  double min, max;
  if (xabs < yabs) {
    min = xabs;
    max = yabs;
  } else {
    min = yabs;
    max = xabs;
  }
  if (min == 0) {
    return max;
  }
  {
    double u = min / max;
    return max * sqrt(1 + u * u);
  }
}


x86 assembly (clang, -O0):
<xhypot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xed2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xebd(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1179 <xhypot+0x69>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    118d <xhypot+0x7d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b4 <xhypot+0xa4>
jp     11b4 <xhypot+0xa4>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1201 <xhypot+0xf1>
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xhypot>:
sub    $0x18,%rsp
movapd %xmm1,%xmm2
movapd 0xee0(%rip),%xmm1
andpd  %xmm1,%xmm0
andpd  %xmm1,%xmm2
movapd %xmm0,%xmm1
minsd  %xmm2,%xmm1
maxsd  %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1140 <xhypot+0x30>
jnp    1167 <xhypot+0x57>
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xec0(%rip),%xmm1
cvttsd2si %xmm1,%edi
movapd %xmm2,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

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

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