#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) {
  a = fabs(a);
  b = fabs(b);
  if (a > b)
    return a * sqrt(1.0 + (b / a) * (b / a));
  else
    return (b == 0.0 ? 0.0 : b * sqrt(1.0 + (a / b) * (a / b)));
}


x86 assembly (clang, -O0):
<PYTHAG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xed2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xebd(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11a5 <PYTHAG+0x95>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe8a(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1218 <PYTHAG+0x108>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ca <PYTHAG+0xba>
jp     11ca <PYTHAG+0xba>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    120e <PYTHAG+0xfe>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe1c(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PYTHAG>:
push   %rax
movapd %xmm0,%xmm2
movapd 0xee3(%rip),%xmm0
andpd  %xmm0,%xmm2
andpd  %xmm1,%xmm0
ucomisd %xmm0,%xmm2
jbe    1141 <PYTHAG+0x31>
divsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
addsd  0xed5(%rip),%xmm0
movapd %xmm2,%xmm3
jmp    1165 <PYTHAG+0x55>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    114d <PYTHAG+0x3d>
jnp    1188 <PYTHAG+0x78>
movapd %xmm0,%xmm3
divsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm2
addsd  0xeaf(%rip),%xmm2
movapd %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1175 <PYTHAG+0x65>
sqrtsd %xmm0,%xmm0
jmp    1184 <PYTHAG+0x74>
movsd  %xmm3,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
pop    %rax
ret

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

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 %9
6: ; preds = %2
%7 = fdiv double %4, %3
%8 = tail call double @llvm.fmuladd.f64(double %7, double %7, double 1.000000e+00)
br label %14
9: ; preds = %2
%10 = fcmp oeq double %1, 0.000000e+00
br i1 %10, label %19, label %11
11: ; preds = %9
%12 = fdiv double %3, %4
%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 = tail call double @sqrt(double %15)
%18 = fmul double %16, %17
br label %19
19: ; preds = %14, %9
%20 = phi double [ 0.000000e+00, %9 ], [ %18, %14 ]
ret double %20
}