#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(int);
double Zabs(double real, double imag) {
  double abs, val;
  if (real == 0.0) {
    abs = fabs(imag);
  } else if (imag == 0.0) {
    abs = fabs(real);
  } else if (real >= imag) {
    val = imag / real;
    abs = fabs(real) * sqrt(1 + val * val);
  } else {
    val = real / imag;
    abs = fabs(imag) * sqrt(1 + val * val);
  }
  return (abs);
}


x86 assembly (clang, -O0):
<Zabs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1154 <Zabs+0x44>
jp     1154 <Zabs+0x44>
movsd  -0x10(%rbp),%xmm0
movaps 0xeca(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1255 <Zabs+0x145>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1186 <Zabs+0x76>
jp     1186 <Zabs+0x76>
movsd  -0x8(%rbp),%xmm0
movaps 0xe98(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1250 <Zabs+0x140>
movsd  -0x8(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11f3 <Zabs+0xe3>
movsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xe5f(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe30(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    124b <Zabs+0x13b>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xe02(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdd3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1250 <Zabs+0x140>
jmp    1255 <Zabs+0x145>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Zabs>:
sub    $0x18,%rsp
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jne    112f <Zabs+0x1f>
jp     112f <Zabs+0x1f>
andps  0xed9(%rip),%xmm1
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret
ucomisd %xmm2,%xmm1
jne    1144 <Zabs+0x34>
jp     1144 <Zabs+0x34>
andpd  0xec1(%rip),%xmm0
add    $0x18,%rsp
ret
ucomisd %xmm1,%xmm0
jae    116d <Zabs+0x5d>
divsd  %xmm1,%xmm0
andpd  0xeaa(%rip),%xmm1
movapd %xmm1,(%rsp)
mulsd  %xmm0,%xmm0
addsd  0xea9(%rip),%xmm0
cvttsd2si %xmm0,%edi
jmp    118e <Zabs+0x7e>
divsd  %xmm0,%xmm1
andpd  0xe87(%rip),%xmm0
movapd %xmm0,(%rsp)
mulsd  %xmm1,%xmm1
addsd  0xe86(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1030 <sqrt@plt>
mulsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

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

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