#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);
double sqrt(int);
double myhypot(double a, double b) {
  double r = 0;
  if (fabs(a) > fabs(b)) {
    r = b / a;
    r = fabs(a) * sqrt(1 + r * r);
  } else if (b != 0) {
    r = a / b;
    r = fabs(b) * sqrt(1 + r * r);
  }
  return r;
}


x86 assembly (clang, -O0):
<myhypot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xeca(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
movaps 0xeba(%rip),%xmm2
pand   %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b1 <myhypot+0xa1>
movsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xe91(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe82(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    122b <myhypot+0x11b>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ce <myhypot+0xbe>
jp     11ce <myhypot+0xbe>
jmp    1226 <myhypot+0x116>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xe17(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe08(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    122b <myhypot+0x11b>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myhypot>:
sub    $0x18,%rsp
movapd 0xee4(%rip),%xmm3
movapd %xmm0,%xmm2
andpd  %xmm3,%xmm2
andpd  %xmm1,%xmm3
ucomisd %xmm3,%xmm2
jbe    1145 <myhypot+0x35>
divsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xed2(%rip),%xmm1
movapd %xmm2,(%rsp)
jmp    116a <myhypot+0x5a>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    1151 <myhypot+0x41>
jnp    117c <myhypot+0x6c>
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
addsd  0xeaf(%rip),%xmm0
movapd %xmm0,%xmm1
movapd %xmm3,(%rsp)
cvttsd2si %xmm1,%edi
call   1030 <sqrt@plt>
movapd %xmm0,%xmm2
mulsd  (%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

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

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