#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 M_PI;
double atan(double);
double get_phase(double i, double q) {
  double phi = atan(q / i);
  if (i < 0 && q > 0)
    phi += M_PI;
  else if (i < 0 && q < 0)
    phi += M_PI;
  else if (i > 0 && q < 0)
    phi += 2 * M_PI;
  else if (i == 0 && q > 0)
    phi = M_PI / 2;
  else if (i == 0 && q < 0)
    phi = 3 * (M_PI / 2);
  else if (i < 0 && q == 0)
    phi = M_PI;
  else if (i > 0 && q == 0)
    phi = 0;
  return phi;
}


x86 assembly (clang, -O0):
<get_phase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1170 <get_phase+0x60>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1170 <get_phase+0x60>
mov    0x2e8b(%rip),%rax
movsd  (%rax),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1311 <get_phase+0x201>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11a6 <get_phase+0x96>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11a6 <get_phase+0x96>
mov    0x2e55(%rip),%rax
movsd  (%rax),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    130c <get_phase+0x1fc>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11e8 <get_phase+0xd8>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11e8 <get_phase+0xd8>
mov    0x2e1b(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x18(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1307 <get_phase+0x1f7>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1233 <get_phase+0x123>
jp     1233 <get_phase+0x123>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1233 <get_phase+0x123>
mov    0x2dcf(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xde3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1302 <get_phase+0x1f2>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1286 <get_phase+0x176>
jp     1286 <get_phase+0x176>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1286 <get_phase+0x176>
mov    0x2d88(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xd9c(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd88(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12fd <get_phase+0x1ed>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    12c1 <get_phase+0x1b1>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12c1 <get_phase+0x1b1>
jp     12c1 <get_phase+0x1b1>
mov    0x2d35(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12f8 <get_phase+0x1e8>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12f3 <get_phase+0x1e3>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12f3 <get_phase+0x1e3>
jp     12f3 <get_phase+0x1e3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12f8 <get_phase+0x1e8>
jmp    12fd <get_phase+0x1ed>
jmp    1302 <get_phase+0x1f2>
jmp    1307 <get_phase+0x1f7>
jmp    130c <get_phase+0x1fc>
jmp    1311 <get_phase+0x201>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_phase>:
sub    $0x28,%rsp
movapd %xmm1,0x10(%rsp)
movapd %xmm0,%xmm2
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
call   1030 <atan@plt>
movsd  0x8(%rsp),%xmm3
movapd 0x10(%rsp),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm3,%xmm1
jbe    114d <get_phase+0x3d>
ucomisd %xmm1,%xmm2
ja     115d <get_phase+0x4d>
ucomisd %xmm3,%xmm1
jbe    1175 <get_phase+0x65>
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
jbe    1175 <get_phase+0x65>
mov    0x2e84(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm3
jbe    1196 <get_phase+0x86>
ucomisd %xmm2,%xmm1
jbe    1196 <get_phase+0x86>
mov    0x2e5c(%rip),%rax
movsd  (%rax),%xmm1
addsd  %xmm1,%xmm1
jmp    1168 <get_phase+0x58>
ucomisd %xmm1,%xmm3
jne    11bd <get_phase+0xad>
jp     11bd <get_phase+0xad>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jbe    11bd <get_phase+0xad>
mov    0x2e39(%rip),%rax
movsd  (%rax),%xmm1
mulsd  0xe45(%rip),%xmm1
jmp    116c <get_phase+0x5c>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm3
jne    11ec <get_phase+0xdc>
jp     11ec <get_phase+0xdc>
ucomisd %xmm2,%xmm1
jbe    11ec <get_phase+0xdc>
mov    0x2e12(%rip),%rax
movsd  (%rax),%xmm1
mulsd  0xe1e(%rip),%xmm1
mulsd  0xe1e(%rip),%xmm1
jmp    116c <get_phase+0x5c>
ucomisd %xmm3,%xmm1
jbe    120e <get_phase+0xfe>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    120e <get_phase+0xfe>
jp     120e <get_phase+0xfe>
mov    0x2de3(%rip),%rax
movsd  (%rax),%xmm1
jmp    116c <get_phase+0x5c>
xorpd  %xmm1,%xmm1
cmpeqsd %xmm1,%xmm2
cmpltsd %xmm3,%xmm1
andnpd %xmm0,%xmm2
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
jmp    116c <get_phase+0x5c>

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @get_phase(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double %1, double* %4
%6 = load double, double* %4
%7 = load double, double* %3
%8 = fdiv double %6, %7
%9 = call double @atan(double %8)
store double %9, double* %5
%10 = load double, double* %3
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load double, double* %4
%14 = fcmp ogt double %13, 0.000000e+00
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load double, double* @M_PI
%17 = load double, double* %5
%18 = fadd double %17, %16
store double %18, double* %5
br label %79
19: ; preds = %12, %2
%20 = load double, double* %3
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load double, double* %4
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load double, double* @M_PI
%27 = load double, double* %5
%28 = fadd double %27, %26
store double %28, double* %5
br label %78
29: ; preds = %22, %19
%30 = load double, double* %3
%31 = fcmp ogt double %30, 0.000000e+00
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load double, double* %4
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load double, double* @M_PI
%37 = load double, double* %5
%38 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %36, double %37)
store double %38, double* %5
br label %77
39: ; preds = %32, %29
%40 = load double, double* %3
%41 = fcmp oeq double %40, 0.000000e+00
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = load double, double* %4
%44 = fcmp ogt double %43, 0.000000e+00
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load double, double* @M_PI
%47 = fdiv double %46, 2.000000e+00
store double %47, double* %5
br label %76
48: ; preds = %42, %39
%49 = load double, double* %3
%50 = fcmp oeq double %49, 0.000000e+00
br i1 %50, label %51, label %58
51: ; preds = %48
%52 = load double, double* %4
%53 = fcmp olt double %52, 0.000000e+00
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load double, double* @M_PI
%56 = fdiv double %55, 2.000000e+00
%57 = fmul double 3.000000e+00, %56
store double %57, double* %5
br label %75
58: ; preds = %51, %48
%59 = load double, double* %3
%60 = fcmp olt double %59, 0.000000e+00
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load double, double* %4
%63 = fcmp oeq double %62, 0.000000e+00
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = load double, double* @M_PI
store double %65, double* %5
br label %74
66: ; preds = %61, %58
%67 = load double, double* %3
%68 = fcmp ogt double %67, 0.000000e+00
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load double, double* %4
%71 = fcmp oeq double %70, 0.000000e+00
br i1 %71, label %72, label %73
72: ; preds = %69
store double 0.000000e+00, double* %5
br label %73
73: ; preds = %72, %69, %66
br label %74
74: ; preds = %73, %64
br label %75
75: ; preds = %74, %54
br label %76
76: ; preds = %75, %45
br label %77
77: ; preds = %76, %35
br label %78
78: ; preds = %77, %25
br label %79
79: ; preds = %78, %15
%80 = load double, double* %5
ret double %80
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @get_phase(double %0, double %1) {
%3 = fdiv double %1, %0
%4 = tail call double @atan(double %3)
%5 = fcmp olt double %0, 0.000000e+00
%6 = fcmp ogt double %1, 0.000000e+00
%7 = and i1 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load double, double* @M_PI
%10 = fadd double %4, %9
br label %43
11: ; preds = %2
%12 = fcmp olt double %1, 0.000000e+00
%13 = and i1 %5, %12
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load double, double* @M_PI
%16 = fadd double %4, %15
br label %43
17: ; preds = %11
%18 = fcmp ogt double %0, 0.000000e+00
%19 = and i1 %18, %12
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load double, double* @M_PI
%22 = tail call double @llvm.fmuladd.f64(double %21, double 2.000000e+00, double %4)
br label %43
23: ; preds = %17
%24 = fcmp oeq double %0, 0.000000e+00
%25 = and i1 %24, %6
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load double, double* @M_PI
%28 = fmul double %27, 5.000000e-01
br label %43
29: ; preds = %23
%30 = and i1 %24, %12
br i1 %30, label %31, label %35
31: ; preds = %29
%32 = load double, double* @M_PI
%33 = fmul double %32, 5.000000e-01
%34 = fmul double %33, 3.000000e+00
br label %43
35: ; preds = %29
%36 = fcmp oeq double %1, 0.000000e+00
%37 = and i1 %5, %36
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load double, double* @M_PI
br label %43
40: ; preds = %35
%41 = and i1 %18, %36
%42 = select i1 %41, double 0.000000e+00, double %4
br label %43
43: ; preds = %40, %14, %26, %38, %31, %20, %8
%44 = phi double [ %10, %8 ], [ %16, %14 ], [ %22, %20 ], [ %28, %26 ], [ %34, %31 ], [ %39, %38 ], [ %42, %40 ]
ret double %44
}