#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);
int /*<<< orphan*/ frexp(double, int *);
double ldexp(double, int);
double sqrt(double);
double hypot(double x, double y) {
  double scale;
  int n1, n2;
  if (x == 0.0)
    return fabs(y);
  else if (y == 0.0)
    return fabs(x);
  (void)frexp(x, &n1);
  (void)frexp(y, &n2);
  if (n2 > n1)
    n1 = n2;
  scale = ldexp(1.0, n1);
  x /= scale;
  y /= scale;
  return scale * sqrt(x * x + y * y);
}


x86 assembly (clang, -O0):
<hypot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1174 <hypot+0x44>
jp     1174 <hypot+0x44>
movsd  -0x18(%rbp),%xmm0
movaps 0xeaa(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1250 <hypot+0x120>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a6 <hypot+0x76>
jp     11a6 <hypot+0x76>
movsd  -0x10(%rbp),%xmm0
movaps 0xe78(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1250 <hypot+0x120>
jmp    11ab <hypot+0x7b>
movsd  -0x10(%rbp),%xmm0
lea    -0x24(%rbp),%rdi
call   1040 <frexp@plt>
movsd  -0x18(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
call   1040 <frexp@plt>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    11d9 <hypot+0xa9>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
movsd  0xe1c(%rip),%xmm0
call   1030 <ldexp@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <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):
<hypot>:
sub    $0x38,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    114f <hypot+0x1f>
jp     114f <hypot+0x1f>
andps  0xec9(%rip),%xmm1
movaps %xmm1,%xmm0
add    $0x38,%rsp
ret
ucomisd %xmm2,%xmm1
jne    1164 <hypot+0x34>
jp     1164 <hypot+0x34>
andpd  0xeb1(%rip),%xmm0
add    $0x38,%rsp
ret
lea    0xc(%rsp),%rdi
movapd %xmm0,0x20(%rsp)
movapd %xmm1,0x10(%rsp)
call   1040 <frexp@plt>
lea    0x8(%rsp),%rdi
movaps 0x10(%rsp),%xmm0
call   1040 <frexp@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%edi
cmp    %edi,%eax
cmovg  %eax,%edi
movsd  0xe62(%rip),%xmm0
call   1030 <ldexp@plt>
movapd 0x20(%rsp),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
divsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     11da <hypot+0xaa>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    11ef <hypot+0xbf>
movapd %xmm1,%xmm0
movsd  %xmm2,0x10(%rsp)
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
define double @hypot(double %0, double %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = fcmp oeq double %0, 0.000000e+00
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call double @llvm.fabs.f64(double %1)
br label %28
10: ; preds = %2
%11 = fcmp oeq double %1, 0.000000e+00
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call double @llvm.fabs.f64(double %0)
br label %28
14: ; preds = %10
%15 = call i32 @frexp(double %0, i32* %3)
%16 = call i32 @frexp(double %1, i32* %4)
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp sgt i32 %17, %18
%20 = select i1 %19, i32 %17, i32 %18
%21 = tail call double @ldexp(double 1.000000e+00, i32 %20)
%22 = fdiv double %0, %21
%23 = fdiv double %1, %21
%24 = fmul double %23, %23
%25 = tail call double @llvm.fmuladd.f64(double %22, double %22, double %24)
%26 = tail call double @sqrt(double %25)
%27 = fmul double %21, %26
br label %28
28: ; preds = %14, %12, %8
%29 = phi double [ %9, %8 ], [ %13, %12 ], [ %27, %14 ]
ret double %29
}