#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 atan2(double, double);
double phase(double y, double x) {
  double pp = 0.;
  if (x == 0.) {
    if (y > 0)
      pp = 0.5 * 3.14159265358979323844;
    if (y == 0)
      pp = 0.;
    if (y < 0)
      pp = -0.5 * 3.14159265358979323844;
  } else {
    if (y != 0)
      pp = atan2(y, x);
    else
      pp = 0.;
  }
  return pp;
}


x86 assembly (clang, -O0):
<phase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a1 <phase+0x91>
jp     11a1 <phase+0x91>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1161 <phase+0x51>
movsd  0xea4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1181 <phase+0x71>
jp     1181 <phase+0x71>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    119c <phase+0x8c>
movsd  0xe71(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e4 <phase+0xd4>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11be <phase+0xae>
jp     11be <phase+0xae>
jmp    11d7 <phase+0xc7>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11df <phase+0xcf>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e4 <phase+0xd4>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<phase>:
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    1130 <phase+0x20>
jp     1130 <phase+0x20>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1142 <phase+0x32>
movsd  0xeda(%rip),%xmm2
jmp    113d <phase+0x2d>
ucomisd %xmm2,%xmm0
jne    1138 <phase+0x28>
jnp    113d <phase+0x2d>
jmp    1030 <atan2@plt>
movapd %xmm2,%xmm0
ret
xorpd  %xmm2,%xmm2
cmpltsd %xmm0,%xmm2
movsd  0xead(%rip),%xmm3
andpd  %xmm2,%xmm3
cmpeqsd %xmm1,%xmm0
andnpd %xmm3,%xmm0
ret

LLVM IR (-O0):
define double @phase(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double %1, double* %4
store double 0.000000e+00, double* %5
%6 = load double, double* %4
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %21
8: ; preds = %2
%9 = load double, double* %3
%10 = fcmp ogt double %9, 0.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %8
store double 0x3FF921FB54442D18, double* %5
br label %12
12: ; preds = %11, %8
%13 = load double, double* %3
%14 = fcmp oeq double %13, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %12
store double 0.000000e+00, double* %5
br label %16
16: ; preds = %15, %12
%17 = load double, double* %3
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %16
store double 0xBFF921FB54442D18, double* %5
br label %20
20: ; preds = %19, %16
br label %30
21: ; preds = %2
%22 = load double, double* %3
%23 = fcmp une double %22, 0.000000e+00
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load double, double* %3
%26 = load double, double* %4
%27 = call double @atan2(double %25, double %26)
store double %27, double* %5
br label %29
28: ; preds = %21
store double 0.000000e+00, double* %5
br label %29
29: ; preds = %28, %24
br label %30
30: ; preds = %29, %20
%31 = load double, double* %5
ret double %31
}

LLVM IR (-O2):
define double @phase(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = fcmp ogt double %0, 0.000000e+00
%6 = select i1 %5, double 0x3FF921FB54442D18, double 0.000000e+00
%7 = fcmp oeq double %0, 0.000000e+00
%8 = select i1 %7, double 0.000000e+00, double %6
%9 = fcmp olt double %0, 0.000000e+00
br i1 %9, label %10, label %15
10: ; preds = %4
br label %15
11: ; preds = %2
%12 = fcmp une double %0, 0.000000e+00
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call double @atan2(double %0, double %1)
br label %15
15: ; preds = %11, %13, %4, %10
%16 = phi double [ 0xBFF921FB54442D18, %10 ], [ %8, %4 ], [ %14, %13 ], [ 0.000000e+00, %11 ]
ret double %16
}