#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 atan(double);
double checked_atan2(double y, double x) {
  double z;
  if (x == -0.0)
    x = 0.0;
  if (x != 0)
    z = atan(y / x);
  else if (y > 0)
    z = (3.1415926535897932384626433832795 / 2.0);
  else
    z = -(3.1415926535897932384626433832795 / 2.0);
  if (x < 0) {
    if (y < 0)
      z -= 3.1415926535897932384626433832795;
    else
      z += 3.1415926535897932384626433832795;
  }
  return z;
}


x86 assembly (clang, -O0):
<checked_atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1147 <checked_atan2+0x37>
jp     1147 <checked_atan2+0x37>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1164 <checked_atan2+0x54>
jp     1164 <checked_atan2+0x54>
jmp    117d <checked_atan2+0x6d>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11b3 <checked_atan2+0xa3>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11a1 <checked_atan2+0x91>
movsd  0xe79(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ae <checked_atan2+0x9e>
movsd  0xe5f(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11b3 <checked_atan2+0xa3>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1201 <checked_atan2+0xf1>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11ea <checked_atan2+0xda>
movsd  -0x18(%rbp),%xmm0
movsd  0xe3c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11fc <checked_atan2+0xec>
movsd  0xe26(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1201 <checked_atan2+0xf1>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checked_atan2>:
sub    $0x28,%rsp
xorpd  %xmm2,%xmm2
movapd %xmm1,%xmm3
cmpeqsd %xmm2,%xmm3
andnpd %xmm1,%xmm3
ucomisd %xmm2,%xmm3
movsd  %xmm0,0x8(%rsp)
jne    1133 <checked_atan2+0x23>
jnp    114a <checked_atan2+0x3a>
divsd  %xmm3,%xmm0
movapd %xmm3,0x10(%rsp)
call   1030 <atan@plt>
movapd 0x10(%rsp),%xmm3
jmp    115f <checked_atan2+0x4f>
xor    %eax,%eax
ucomisd %xmm2,%xmm0
seta   %al
lea    0xea6(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm3,%xmm1
jbe    1186 <checked_atan2+0x76>
ucomisd 0x8(%rsp),%xmm1
jbe    117e <checked_atan2+0x6e>
addsd  0xe9f(%rip),%xmm0
add    $0x28,%rsp
ret
addsd  0xe8a(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @checked_atan2(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 = fcmp oeq double %6, -0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %2
store double 0.000000e+00, double* %4
br label %9
9: ; preds = %8, %2
%10 = load double, double* %4
%11 = fcmp une double %10, 0.000000e+00
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load double, double* %3
%14 = load double, double* %4
%15 = fdiv double %13, %14
%16 = call double @atan(double %15)
store double %16, double* %5
br label %23
17: ; preds = %9
%18 = load double, double* %3
%19 = fcmp ogt double %18, 0.000000e+00
br i1 %19, label %20, label %21
20: ; preds = %17
store double 0x3FF921FB54442D18, double* %5
br label %22
21: ; preds = %17
store double 0xBFF921FB54442D18, double* %5
br label %22
22: ; preds = %21, %20
br label %23
23: ; preds = %22, %12
%24 = load double, double* %4
%25 = fcmp olt double %24, 0.000000e+00
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load double, double* %3
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load double, double* %5
%31 = fsub double %30, 0x400921FB54442D18
store double %31, double* %5
br label %35
32: ; preds = %26
%33 = load double, double* %5
%34 = fadd double %33, 0x400921FB54442D18
store double %34, double* %5
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35, %23
%37 = load double, double* %5
ret double %37
}

LLVM IR (-O2):
define double @checked_atan2(double %0, double %1) {
%3 = fcmp oeq double %1, 0.000000e+00
%4 = select i1 %3, double 0.000000e+00, double %1
%5 = fcmp une double %4, 0.000000e+00
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = fdiv double %0, %4
%8 = tail call double @atan(double %7)
br label %12
9: ; preds = %2
%10 = fcmp ogt double %0, 0.000000e+00
%11 = select i1 %10, double 0x3FF921FB54442D18, double 0xBFF921FB54442D18
br label %12
12: ; preds = %9, %6
%13 = phi double [ %8, %6 ], [ %11, %9 ]
%14 = fcmp olt double %4, 0.000000e+00
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = fcmp olt double %0, 0.000000e+00
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = fadd double %13, 0xC00921FB54442D18
br label %21
19: ; preds = %15
%20 = fadd double %13, 0x400921FB54442D18
br label %21
21: ; preds = %17, %19, %12
%22 = phi double [ %18, %17 ], [ %20, %19 ], [ %13, %12 ]
ret double %22
}