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


x86 assembly (clang, -O0):
<rq_pythag>:
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)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11ac <rq_pythag+0x9c>
movsd  -0x28(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe84(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1226 <rq_pythag+0x116>
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ef <rq_pythag+0xdf>
jp     11ef <rq_pythag+0xdf>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    121c <rq_pythag+0x10c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe0f(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rq_pythag>:
push   %rax
movapd %xmm0,%xmm2
movapd 0xee3(%rip),%xmm0
andpd  %xmm0,%xmm2
andpd  %xmm1,%xmm0
ucomisd %xmm0,%xmm2
jbe    1139 <rq_pythag+0x29>
divsd  %xmm2,%xmm0
mulsd  %xmm0,%xmm0
movapd %xmm2,%xmm3
jmp    1155 <rq_pythag+0x45>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    1145 <rq_pythag+0x35>
jnp    1180 <rq_pythag+0x70>
movapd %xmm0,%xmm3
divsd  %xmm0,%xmm2
mulsd  %xmm2,%xmm2
movapd %xmm2,%xmm0
addsd  0xeb3(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     116d <rq_pythag+0x5d>
sqrtsd %xmm0,%xmm0
jmp    117c <rq_pythag+0x6c>
movsd  %xmm3,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @rq_pythag(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 = load double, double* %7
%16 = fcmp ogt double %14, %15
br i1 %16, label %17, label %29
17: ; preds = %2
%18 = load double, double* %7
%19 = load double, double* %6
%20 = fdiv double %18, %19
store double %20, double* %8
%21 = load double, double* %8
%22 = load double, double* %8
%23 = fmul double %22, %21
store double %23, double* %8
%24 = load double, double* %6
%25 = load double, double* %8
%26 = fadd double 1.000000e+00, %25
%27 = call double @sqrt(double %26)
%28 = fmul double %24, %27
store double %28, double* %3
br label %47
29: ; preds = %2
%30 = load double, double* %6
%31 = load double, double* %7
%32 = fdiv double %30, %31
store double %32, double* %9
%33 = load double, double* %9
%34 = load double, double* %9
%35 = fmul double %34, %33
store double %35, double* %9
%36 = load double, double* %7
%37 = fcmp oeq double %36, 0.000000e+00
br i1 %37, label %38, label %39
38: ; preds = %29
br label %45
39: ; preds = %29
%40 = load double, double* %7
%41 = load double, double* %9
%42 = fadd double 1.000000e+00, %41
%43 = call double @sqrt(double %42)
%44 = fmul double %40, %43
br label %45
45: ; preds = %39, %38
%46 = phi double [ 0.000000e+00, %38 ], [ %44, %39 ]
store double %46, double* %3
br label %47
47: ; preds = %45, %17
%48 = load double, double* %3
ret double %48
}

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