#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 fabs(double);
double bot_fasttrig_atan2_coarse(double y, double x) {
  double abs_y = fabs(y);
  double angle;
  if (x >= 0) {
    double r = (x - abs_y) / (x + abs_y);
    angle = M_PI / 4.0 * (1 - r);
  } else {
    double r = (x + abs_y) / (abs_y - x);
    angle = M_PI / 4.0 * (3 - r);
  }
  return y < 0 ? -angle : angle;
}


x86 assembly (clang, -O0):
<bot_fasttrig_atan2_coarse>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movaps 0xee6(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1184 <bot_fasttrig_atan2_coarse+0x84>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2e8f(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xeb3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xeaf(%rip),%xmm1
subsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11ce <bot_fasttrig_atan2_coarse+0xce>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    0x2e40(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xe64(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe50(%rip),%xmm1
subsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1202 <bot_fasttrig_atan2_coarse+0x102>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    120c <bot_fasttrig_atan2_coarse+0x10c>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_fasttrig_atan2_coarse>:
movapd 0xef8(%rip),%xmm2
andpd  %xmm0,%xmm2
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jae    1143 <bot_fasttrig_atan2_coarse+0x43>
movapd %xmm2,%xmm3
addsd  %xmm1,%xmm3
subsd  %xmm1,%xmm2
mov    0x2ebf(%rip),%rax
movsd  (%rax),%xmm4
mulsd  0xeeb(%rip),%xmm4
divsd  %xmm2,%xmm3
movsd  0xeef(%rip),%xmm1
jmp    116e <bot_fasttrig_atan2_coarse+0x6e>
movapd %xmm1,%xmm3
subsd  %xmm2,%xmm3
addsd  %xmm1,%xmm2
mov    0x2e92(%rip),%rax
movsd  (%rax),%xmm4
mulsd  0xebe(%rip),%xmm4
divsd  %xmm2,%xmm3
movsd  0xeba(%rip),%xmm1
subsd  %xmm3,%xmm1
mulsd  %xmm4,%xmm1
movapd 0xe92(%rip),%xmm2
xorpd  %xmm1,%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
ret

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

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @bot_fasttrig_atan2_coarse(double %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %0)
%4 = fcmp ult double %1, 0.000000e+00
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = fsub double %1, %3
%7 = fadd double %3, %1
%8 = fdiv double %6, %7
%9 = load double, double* @M_PI
%10 = fmul double %9, 2.500000e-01
%11 = fsub double 1.000000e+00, %8
%12 = fmul double %11, %10
br label %21
13: ; preds = %2
%14 = fadd double %3, %1
%15 = fsub double %3, %1
%16 = fdiv double %14, %15
%17 = load double, double* @M_PI
%18 = fmul double %17, 2.500000e-01
%19 = fsub double 3.000000e+00, %16
%20 = fmul double %19, %18
br label %21
21: ; preds = %13, %5
%22 = phi double [ %12, %5 ], [ %20, %13 ]
%23 = fcmp olt double %0, 0.000000e+00
%24 = fneg double %22
%25 = select i1 %23, double %24, double %22
ret double %25
}