#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 my_atan2(double y, double x) {
  double a;
  if ((x == 0.0) && (y == 0.0))
    return 0.0;
  if (x == 0.0)
    if (y > 0)
      return 1.5707963268;
    else
      return -1.5707963268;
  a = atan(y / x);
  if (a > 0.0)
    if (x > 0)
      return a;
    else
      return (a + 3.1415926536);
  else if (x > 0)
    return (a + 6.2831853072);
  else
    return (a + 3.1415926536);
}


x86 assembly (clang, -O0):
<my_atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115f <my_atan2+0x4f>
jp     115f <my_atan2+0x4f>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115f <my_atan2+0x4f>
jp     115f <my_atan2+0x4f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <my_atan2+0x136>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ad <my_atan2+0x9d>
jp     11ad <my_atan2+0x9d>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    119b <my_atan2+0x8b>
movsd  0xe87(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <my_atan2+0x136>
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <my_atan2+0x136>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <atan@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    120b <my_atan2+0xfb>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11f4 <my_atan2+0xe4>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <my_atan2+0x136>
movsd  0xe04(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <my_atan2+0x136>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1234 <my_atan2+0x124>
movsd  0xde3(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1246 <my_atan2+0x136>
movsd  0xdc4(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_atan2>:
push   %rax
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jne    112f <my_atan2+0x1f>
jp     112f <my_atan2+0x1f>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jne    112f <my_atan2+0x1f>
jp     112f <my_atan2+0x1f>
pop    %rax
ret
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1152 <my_atan2+0x42>
jp     1152 <my_atan2+0x42>
xor    %eax,%eax
ucomisd %xmm0,%xmm3
seta   %al
lea    0xecd(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
pop    %rax
ret
movsd  %xmm1,(%rsp)
divsd  %xmm1,%xmm3
movapd %xmm3,%xmm0
call   1030 <atan@plt>
ucomisd 0xea4(%rip),%xmm0
jbe    117f <my_atan2+0x6f>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm2
ucomisd %xmm1,%xmm2
ja     112d <my_atan2+0x1d>
jmp    1198 <my_atan2+0x88>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm2
ucomisd %xmm1,%xmm2
jbe    1198 <my_atan2+0x88>
addsd  0xe72(%rip),%xmm0
pop    %rax
ret
addsd  0xe60(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @my_atan2(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* %5
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load double, double* %4
%11 = fcmp oeq double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %9
store double 0.000000e+00, double* %3
br label %45
13: ; preds = %9, %2
%14 = load double, double* %5
%15 = fcmp oeq double %14, 0.000000e+00
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load double, double* %4
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %20
19: ; preds = %16
store double 0x3FF921FB544486E0, double* %3
br label %45
20: ; preds = %16
store double 0xBFF921FB544486E0, double* %3
br label %45
21: ; preds = %13
%22 = load double, double* %4
%23 = load double, double* %5
%24 = fdiv double %22, %23
%25 = call double @atan(double %24)
store double %25, double* %6
%26 = load double, double* %6
%27 = fcmp ogt double %26, 0.000000e+00
br i1 %27, label %28, label %36
28: ; preds = %21
%29 = load double, double* %5
%30 = fcmp ogt double %29, 0.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = load double, double* %6
store double %32, double* %3
br label %45
33: ; preds = %28
%34 = load double, double* %6
%35 = fadd double %34, 0x400921FB544486E0
store double %35, double* %3
br label %45
36: ; preds = %21
%37 = load double, double* %5
%38 = fcmp ogt double %37, 0.000000e+00
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load double, double* %6
%41 = fadd double %40, 0x401921FB544486E0
store double %41, double* %3
br label %45
42: ; preds = %36
%43 = load double, double* %6
%44 = fadd double %43, 0x400921FB544486E0
store double %44, double* %3
br label %45
45: ; preds = %42, %39, %33, %31, %20, %19, %12
%46 = load double, double* %3
ret double %46
}

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