double hypot(x, y)
double x, y;
{
  if (x < 0)
    x = -x;
  if (y < 0)
    y = -y;
  if (x > y) {
    double t = y;
    y = x;
    x = t;
  }
  if (y == 0.0)
    return 0.0;
  x /= y;
  return y * sqrt(x * x + 1.0);
}


x86 assembly (clang, -O0):
<hypot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1151 <hypot+0x41>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1180 <hypot+0x70>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11ae <hypot+0x9e>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d3 <hypot+0xc3>
jp     11d3 <hypot+0xc3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1220 <hypot+0x110>
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdfa(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hypot>:
sub    $0x18,%rsp
movapd 0xee4(%rip),%xmm4
movapd %xmm0,%xmm5
xorpd  %xmm4,%xmm5
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm5
andnpd %xmm0,%xmm3
orpd   %xmm5,%xmm3
xorpd  %xmm1,%xmm4
movapd %xmm1,%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm4
andnpd %xmm1,%xmm0
orpd   %xmm4,%xmm0
movapd %xmm3,%xmm4
maxsd  %xmm0,%xmm4
ucomisd %xmm2,%xmm4
jne    1166 <hypot+0x56>
jnp    11a1 <hypot+0x91>
minsd  %xmm3,%xmm0
divsd  %xmm4,%xmm0
mulsd  %xmm0,%xmm0
addsd  0xe96(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     118a <hypot+0x7a>
sqrtsd %xmm0,%xmm0
jmp    1199 <hypot+0x89>
movapd %xmm4,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm4
mulsd  %xmm0,%xmm4
movapd %xmm4,%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

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

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