#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 at = fabs(a), bt = fabs(b), ct, result;
  if (at > bt) {
    ct = bt / at;
    result = at * sqrt(1.0 + ct * ct);
  } else if (bt > 0.0) {
    ct = at / bt;
    result = bt * sqrt(1.0 + ct * ct);
  } else
    result = 0.0;
  return (result);
}


x86 assembly (clang, -O0):
<PYTHAG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xed2(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xebd(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11aa <PYTHAG+0x9a>
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe85(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1217 <PYTHAG+0x107>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    120a <PYTHAG+0xfa>
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe25(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1212 <PYTHAG+0x102>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1217 <PYTHAG+0x107>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%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    1163 <PYTHAG+0x53>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
je     1186 <PYTHAG+0x76>
movapd %xmm0,%xmm3
divsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm2
addsd  0xeb1(%rip),%xmm2
movapd %xmm2,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1173 <PYTHAG+0x63>
sqrtsd %xmm0,%xmm0
jmp    1182 <PYTHAG+0x72>
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
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store double %1, double* %4
%9 = load double, double* %3
%10 = call double @llvm.fabs.f64(double %9)
store double %10, double* %5
%11 = load double, double* %4
%12 = call double @llvm.fabs.f64(double %11)
store double %12, double* %6
%13 = load double, double* %5
%14 = load double, double* %6
%15 = fcmp ogt double %13, %14
br i1 %15, label %16, label %26
16: ; preds = %2
%17 = load double, double* %6
%18 = load double, double* %5
%19 = fdiv double %17, %18
store double %19, double* %7
%20 = load double, double* %5
%21 = load double, double* %7
%22 = load double, double* %7
%23 = call double @llvm.fmuladd.f64(double %21, double %22, double 1.000000e+00)
%24 = call double @sqrt(double %23)
%25 = fmul double %20, %24
store double %25, double* %8
br label %41
26: ; preds = %2
%27 = load double, double* %6
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load double, double* %5
%31 = load double, double* %6
%32 = fdiv double %30, %31
store double %32, double* %7
%33 = load double, double* %6
%34 = load double, double* %7
%35 = load double, double* %7
%36 = call double @llvm.fmuladd.f64(double %34, double %35, double 1.000000e+00)
%37 = call double @sqrt(double %36)
%38 = fmul double %33, %37
store double %38, double* %8
br label %40
39: ; preds = %26
store double 0.000000e+00, double* %8
br label %40
40: ; preds = %39, %29
br label %41
41: ; preds = %40, %16
%42 = load double, double* %8
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 ueq 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
}