#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 */
float M_PI;
float abs(float);
float fastatan2(float y, float x) {
  float coeff_1 = M_PI / 4.0f;
  float coeff_2 = 3.0f * coeff_1;
  float abs_y = abs(y);
  float angle;
  if (x > 0.0f) {
    float r = (x - abs_y) / (x + abs_y);
    angle = coeff_1 - coeff_1 * r;
  } else {
    float r = (x + abs_y) / (abs_y - x);
    angle = coeff_2 - coeff_1 * r;
  }
  return y < 0.0f ? -angle : angle;
}


x86 assembly (clang, -O0):
<fastatan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    0x2ebf(%rip),%rax
movss  (%rax),%xmm0
movss  0xecf(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xeba(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <abs@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11bb <fastatan2+0xab>
movss  -0x8(%rbp),%xmm0
subss  -0x14(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
addss  -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0xc(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1201 <fastatan2+0xf1>
movss  -0x8(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
subss  -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x10(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    122a <fastatan2+0x11a>
movss  -0x18(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    1234 <fastatan2+0x124>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fastatan2>:
sub    $0x38,%rsp
movss  %xmm1,0xc(%rsp)
mov    0x2ec7(%rip),%rax
movss  (%rax),%xmm1
mulss  0xed3(%rip),%xmm1
movaps %xmm1,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
call   1030 <abs@plt>
movss  0xc(%rsp),%xmm4
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm4
jbe    1168 <fastatan2+0x58>
movaps %xmm4,%xmm1
subss  %xmm0,%xmm1
addss  %xmm4,%xmm0
divss  %xmm0,%xmm1
movaps 0x10(%rsp),%xmm3
mulss  %xmm3,%xmm1
subss  %xmm1,%xmm3
jmp    1193 <fastatan2+0x83>
movss  0xe94(%rip),%xmm1
movaps 0x10(%rsp),%xmm3
mulss  %xmm3,%xmm1
movaps %xmm0,%xmm2
addss  %xmm4,%xmm2
subss  %xmm4,%xmm0
divss  %xmm0,%xmm2
mulss  %xmm3,%xmm2
subss  %xmm2,%xmm1
movaps %xmm1,%xmm3
movaps 0xe76(%rip),%xmm2
xorps  %xmm3,%xmm2
xorps  %xmm1,%xmm1
movaps 0x20(%rsp),%xmm0
cmpltss %xmm1,%xmm0
andps  %xmm0,%xmm2
andnps %xmm3,%xmm0
orps   %xmm2,%xmm0
add    $0x38,%rsp
ret

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

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