#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 pythag2(double x, double y) {
  double ax = fabs(x);
  double ay = fabs(y);
  if (0 == ax && 0 == ay) {
    return 0;
  }
  if (ax > ay) {
    double r = ay / ax;
    return ax * sqrt(1 + r * r);
  } else {
    double r = ax / ay;
    return ay * sqrt(1 + r * r);
  }
}


x86 assembly (clang, -O0):
<pythag2>:
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)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1181 <pythag2+0x71>
jp     1181 <pythag2+0x71>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    1181 <pythag2+0x71>
jp     1181 <pythag2+0x71>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1230 <pythag2+0x120>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11e3 <pythag2+0xd3>
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe50(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1230 <pythag2+0x120>
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdfe(%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):
<pythag2>:
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jne    112d <pythag2+0x1d>
jp     112d <pythag2+0x1d>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    112d <pythag2+0x1d>
jp     112d <pythag2+0x1d>
ret
sub    $0x18,%rsp
movapd 0xec7(%rip),%xmm0
andpd  %xmm0,%xmm3
andpd  %xmm0,%xmm1
ucomisd %xmm1,%xmm3
jbe    115e <pythag2+0x4e>
divsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xeb9(%rip),%xmm1
movapd %xmm3,(%rsp)
jmp    117b <pythag2+0x6b>
movapd %xmm1,%xmm0
divsd  %xmm1,%xmm3
mulsd  %xmm3,%xmm3
addsd  0xe9e(%rip),%xmm3
movapd %xmm3,%xmm1
movapd %xmm0,(%rsp)
cvttsd2si %xmm1,%edi
call   1030 <sqrt@plt>
mulsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

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

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