#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 */
int /*<<< orphan*/ RSWAP(double *, double *);
double fabs(double);
double sqrt(double);
double COMABS(double ar, double ai) {
  if (ar == 0.0 && ai == 0.0)
    return 0.0;
  ar = fabs(ar);
  ai = fabs(ai);
  if (ai > ar)
    RSWAP(&ai, &ar);
  if (ai == 0.0)
    return ar;
  else
    return ar * sqrt(1.0 + ai / ar * ai / ar);
}


x86 assembly (clang, -O0):
<COMABS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116f <COMABS+0x4f>
jp     116f <COMABS+0x4f>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116f <COMABS+0x4f>
jp     116f <COMABS+0x4f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <COMABS+0xfd>
movsd  -0x10(%rbp),%xmm0
movaps 0xe85(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xe70(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b6 <COMABS+0x96>
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <RSWAP@plt>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11dd <COMABS+0xbd>
jp     11dd <COMABS+0xbd>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121d <COMABS+0xfd>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
movsd  0xe0d(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<COMABS>:
sub    $0x18,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jne    113c <COMABS+0x1c>
jp     113c <COMABS+0x1c>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    113c <COMABS+0x1c>
jnp    11ba <COMABS+0x9a>
movapd 0xebc(%rip),%xmm2
andpd  %xmm2,%xmm0
movlpd %xmm0,0x8(%rsp)
andpd  %xmm2,%xmm1
movlpd %xmm1,(%rsp)
ucomisd %xmm0,%xmm1
jbe    116f <COMABS+0x4f>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1030 <RSWAP@plt>
movsd  (%rsp),%xmm1
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
movsd  0x8(%rsp),%xmm3
jne    1181 <COMABS+0x61>
jnp    11ba <COMABS+0x9a>
movapd %xmm1,%xmm0
divsd  %xmm3,%xmm0
mulsd  %xmm1,%xmm0
divsd  %xmm3,%xmm0
addsd  0xe77(%rip),%xmm0
ucomisd %xmm2,%xmm0
jb     11a5 <COMABS+0x85>
sqrtsd %xmm0,%xmm0
jmp    11b6 <COMABS+0x96>
movsd  %xmm3,0x10(%rsp)
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm3
mulsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @COMABS(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = fcmp oeq double %0, 0.000000e+00
%6 = fcmp oeq double %1, 0.000000e+00
%7 = and i1 %5, %6
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = tail call double @llvm.fabs.f64(double %0)
store double %9, double* %3
%10 = tail call double @llvm.fabs.f64(double %1)
store double %10, double* %4
%11 = fcmp ogt double %10, %9
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @RSWAP(double* %4, double* %3)
%14 = load double, double* %4
br label %15
15: ; preds = %12, %8
%16 = phi double [ %14, %12 ], [ %10, %8 ]
%17 = fcmp oeq double %16, 0.000000e+00
%18 = load double, double* %3
br i1 %17, label %26, label %19
19: ; preds = %15
%20 = fdiv double %16, %18
%21 = fmul double %16, %20
%22 = fdiv double %21, %18
%23 = fadd double %22, 1.000000e+00
%24 = call double @sqrt(double %23)
%25 = fmul double %18, %24
br label %26
26: ; preds = %15, %2, %19
%27 = phi double [ %25, %19 ], [ 0.000000e+00, %2 ], [ %18, %15 ]
ret double %27
}