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


x86 assembly (clang, -O0):
<rms>:
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    117a <rms+0x6a>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119f <rms+0x8f>
jp     119f <rms+0x8f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e8 <rms+0xd8>
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe42(%rip),%xmm1
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):
<rms>:
sub    $0x18,%rsp
movapd 0xee4(%rip),%xmm2
andpd  %xmm2,%xmm0
andpd  %xmm2,%xmm1
movapd %xmm0,%xmm3
maxsd  %xmm1,%xmm3
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm3
jne    1138 <rms+0x28>
jnp    117a <rms+0x6a>
minsd  %xmm0,%xmm1
divsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm1
addsd  0xec4(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     115f <rms+0x4f>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    1172 <rms+0x62>
movapd %xmm1,%xmm0
movapd %xmm3,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm3,%xmm2
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @rms(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* %4
store double %1, double* %5
%9 = load double, double* %4
%10 = call double @llvm.fabs.f64(double %9)
store double %10, double* %6
%11 = load double, double* %5
%12 = call double @llvm.fabs.f64(double %11)
store double %12, double* %7
%13 = load double, double* %6
%14 = load double, double* %7
%15 = fcmp ogt double %13, %14
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load double, double* %6
store double %17, double* %8
%18 = load double, double* %7
store double %18, double* %6
%19 = load double, double* %8
store double %19, double* %7
br label %20
20: ; preds = %16, %2
%21 = load double, double* %7
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %20
store double 0.000000e+00, double* %3
br label %34
24: ; preds = %20
%25 = load double, double* %6
%26 = load double, double* %7
%27 = fdiv double %25, %26
store double %27, double* %8
%28 = load double, double* %7
%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 = call double @sqrt(double %31)
%33 = fmul double %28, %32
store double %33, double* %3
br label %34
34: ; preds = %24, %23
%35 = load double, double* %3
ret double %35
}

LLVM IR (-O2):
define double @rms(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
%6 = select i1 %5, double %3, double %4
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = select i1 %5, double %4, double %3
%10 = fdiv double %9, %6
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double 1.000000e+00)
%12 = tail call double @sqrt(double %11)
%13 = fmul double %6, %12
br label %14
14: ; preds = %2, %8
%15 = phi double [ %13, %8 ], [ 0.000000e+00, %2 ]
ret double %15
}