#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 */
int fabs(float);
float fast_atan2f(float y, float x) {
  const float coeff_1 = 3.14159265358979323846 / 4;
  const float coeff_2 = 3 * 3.14159265358979323846 / 4;
  float abs_y = fabs(y) + 1e-10;
  float r, angle;
  if (x >= 0) {
    r = (x - abs_y) / (x + abs_y);
    angle = coeff_1 - coeff_1 * r;
  } else {
    r = (x + abs_y) / (abs_y - x);
    angle = coeff_2 - coeff_1 * r;
  }
  if (y < 0)
    return (-angle);
  else
    return (angle);
}


x86 assembly (clang, -O0):
<fast_atan2f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  0xee2(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xed1(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xeae(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11b4 <fast_atan2f+0xa4>
movss  -0xc(%rbp),%xmm0
subss  -0x18(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
addss  -0x18(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  0xe76(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe66(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    11f3 <fast_atan2f+0xe3>
movss  -0xc(%rbp),%xmm0
addss  -0x18(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
subss  -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  0xe32(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe1e(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    121c <fast_atan2f+0x10c>
movss  -0x20(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1226 <fast_atan2f+0x116>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fast_atan2f>:
sub    $0x28,%rsp
movss  %xmm1,0xc(%rsp)
movaps %xmm0,0x10(%rsp)
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xecd(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
xorps  %xmm0,%xmm0
movss  0xc(%rsp),%xmm2
ucomiss %xmm0,%xmm2
movaps %xmm2,%xmm0
jae    116c <fast_atan2f+0x5c>
movaps %xmm1,%xmm3
addss  %xmm0,%xmm3
subss  %xmm0,%xmm1
divss  %xmm1,%xmm3
mulss  0xea6(%rip),%xmm3
addss  0xea6(%rip),%xmm3
jmp    118b <fast_atan2f+0x7b>
movaps %xmm0,%xmm3
subss  %xmm1,%xmm3
addss  %xmm0,%xmm1
divss  %xmm1,%xmm3
mulss  0xe85(%rip),%xmm3
addss  0xe81(%rip),%xmm3
movaps 0xe8e(%rip),%xmm1
xorps  %xmm3,%xmm1
xorps  %xmm2,%xmm2
movaps 0x10(%rsp),%xmm0
cmpltss %xmm2,%xmm0
andps  %xmm0,%xmm1
andnps %xmm3,%xmm0
orps   %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define float @fast_atan2f(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* %4
store float %1, float* %5
store float 0x3FE921FB60000000, float* %6
store float 0x4002D97C80000000, float* %7
%11 = load float, float* %4
%12 = call i32 @fabs(float %11)
%13 = sitofp i32 %12 to double
%14 = fadd double %13, 1.000000e-10
%15 = fptrunc double %14 to float
store float %15, float* %8
%16 = load float, float* %5
%17 = fcmp oge float %16, 0.000000e+00
br i1 %17, label %18, label %28
18: ; preds = %2
%19 = load float, float* %5
%20 = load float, float* %8
%21 = fsub float %19, %20
%22 = load float, float* %5
%23 = load float, float* %8
%24 = fadd float %22, %23
%25 = fdiv float %21, %24
store float %25, float* %9
%26 = load float, float* %9
%27 = call float @llvm.fmuladd.f32(float 0xBFE921FB60000000, float %26, float 0x3FE921FB60000000)
store float %27, float* %10
br label %38
28: ; preds = %2
%29 = load float, float* %5
%30 = load float, float* %8
%31 = fadd float %29, %30
%32 = load float, float* %8
%33 = load float, float* %5
%34 = fsub float %32, %33
%35 = fdiv float %31, %34
store float %35, float* %9
%36 = load float, float* %9
%37 = call float @llvm.fmuladd.f32(float 0xBFE921FB60000000, float %36, float 0x4002D97C80000000)
store float %37, float* %10
br label %38
38: ; preds = %28, %18
%39 = load float, float* %4
%40 = fcmp olt float %39, 0.000000e+00
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load float, float* %10
%43 = fneg float %42
store float %43, float* %3
br label %46
44: ; preds = %38
%45 = load float, float* %10
store float %45, float* %3
br label %46
46: ; preds = %44, %41
%47 = load float, float* %3
ret float %47
}

LLVM IR (-O2):
define float @fast_atan2f(float %0, float %1) {
%3 = tail call i32 @fabs(float %0)
%4 = sitofp i32 %3 to double
%5 = fadd double %4, 1.000000e-10
%6 = fptrunc double %5 to float
%7 = fcmp ult float %1, 0.000000e+00
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = fsub float %1, %6
%10 = fadd float %6, %1
%11 = fdiv float %9, %10
%12 = tail call float @llvm.fmuladd.f32(float %11, float 0xBFE921FB60000000, float 0x3FE921FB60000000)
br label %18
13: ; preds = %2
%14 = fadd float %6, %1
%15 = fsub float %6, %1
%16 = fdiv float %14, %15
%17 = tail call float @llvm.fmuladd.f32(float %16, float 0xBFE921FB60000000, float 0x4002D97C80000000)
br label %18
18: ; preds = %13, %8
%19 = phi float [ %12, %8 ], [ %17, %13 ]
%20 = fcmp olt float %0, 0.000000e+00
%21 = fneg float %19
%22 = select i1 %20, float %21, float %19
ret float %22
}