#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(double);
double pythag(double a, double b) {
  double absa, absb;
  absa = fabs(a);
  absb = fabs(b);
  if (absa > absb)
    return absa * sqrt(1.0 + (absb * absb) / (absa * absa));
  else if (absb == 0.0)
    return 0.0;
  else
    return absb * sqrt(1.0 + (absa * absa) / (absb * absb));
}


x86 assembly (clang, -O0):
<pythag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11a5 <pythag+0x95>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe8a(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120e <pythag+0xfe>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ca <pythag+0xba>
jp     11ca <pythag+0xba>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120e <pythag+0xfe>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe1c(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pythag>:
sub    $0x18,%rsp
movapd 0xee4(%rip),%xmm2
movapd %xmm0,%xmm3
andpd  %xmm2,%xmm3
andpd  %xmm1,%xmm2
ucomisd %xmm2,%xmm3
jbe    113c <pythag+0x2c>
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
divsd  %xmm0,%xmm1
jmp    115c <pythag+0x4c>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    1148 <pythag+0x38>
jnp    118e <pythag+0x7e>
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
movapd %xmm2,%xmm3
addsd  0xeac(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     1177 <pythag+0x67>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    118a <pythag+0x7a>
movapd %xmm1,%xmm0
movapd %xmm3,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @pythag(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 %10
6: ; preds = %2
%7 = fmul double %1, %1
%8 = fmul double %0, %0
%9 = fdiv double %7, %8
br label %16
10: ; preds = %2
%11 = fcmp oeq double %1, 0.000000e+00
br i1 %11, label %22, label %12
12: ; preds = %10
%13 = fmul double %0, %0
%14 = fmul double %1, %1
%15 = fdiv double %13, %14
br label %16
16: ; preds = %6, %12
%17 = phi double [ %15, %12 ], [ %9, %6 ]
%18 = phi double [ %4, %12 ], [ %3, %6 ]
%19 = fadd double %17, 1.000000e+00
%20 = tail call double @sqrt(double %19)
%21 = fmul double %18, %20
br label %22
22: ; preds = %16, %10
%23 = phi double [ 0.000000e+00, %10 ], [ %21, %16 ]
ret double %23
}