double cabs(real, imag)
double real, imag;
{
  double temp, sqrt();
  if (real < 0)
    real = -real;
  if (imag < 0)
    imag = -imag;
  if (imag > real) {
    temp = real;
    real = imag;
    imag = temp;
  }
  if ((real + imag) == real)
    return (real);
  temp = imag / real;
  temp = real * sqrt(1.0 + temp * temp);
  return (temp);
}


x86 assembly (clang, -O0):
<cabs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1151 <cabs+0x41>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1180 <cabs+0x70>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11ae <cabs+0x9e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11d8 <cabs+0xc8>
jp     11d8 <cabs+0xc8>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122b <cabs+0x11b>
movsd  -0x18(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdf9(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cabs>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
movapd 0xee0(%rip),%xmm4
movapd %xmm0,%xmm5
xorpd  %xmm4,%xmm5
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm5
andnpd %xmm2,%xmm0
orpd   %xmm5,%xmm0
xorpd  %xmm1,%xmm4
movapd %xmm1,%xmm2
cmpltsd %xmm3,%xmm2
andpd  %xmm2,%xmm4
andnpd %xmm1,%xmm2
orpd   %xmm4,%xmm2
movapd %xmm2,%xmm4
maxsd  %xmm0,%xmm4
minsd  %xmm2,%xmm0
movapd %xmm4,%xmm1
addsd  %xmm0,%xmm1
ucomisd %xmm4,%xmm1
jne    1172 <cabs+0x62>
jnp    11a1 <cabs+0x91>
divsd  %xmm4,%xmm0
mulsd  %xmm0,%xmm0
addsd  0xe8e(%rip),%xmm0
ucomisd %xmm3,%xmm0
jb     118e <cabs+0x7e>
sqrtsd %xmm0,%xmm0
jmp    119d <cabs+0x8d>
movapd %xmm4,(%rsp)
call   1030 <sqrt@plt>
movapd (%rsp),%xmm4
mulsd  %xmm0,%xmm4
movapd %xmm4,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @cabs(double %0, double %1) {
%3 = fcmp olt double %0, 0.000000e+00
%4 = fneg double %0
%5 = select i1 %3, double %4, double %0
%6 = fcmp olt double %1, 0.000000e+00
%7 = fneg double %1
%8 = select i1 %6, double %7, double %1
%9 = fcmp ogt double %8, %5
%10 = select i1 %9, double %8, double %5
%11 = select i1 %9, double %5, double %8
%12 = fadd double %10, %11
%13 = fcmp oeq double %12, %10
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = fdiv double %11, %10
%16 = tail call double @llvm.fmuladd.f64(double %15, double %15, double 1.000000e+00)
%17 = tail call double @sqrt(double %16)
%18 = fmul double %10, %17
br label %19
19: ; preds = %2, %14
%20 = phi double [ %18, %14 ], [ %10, %2 ]
ret double %20
}