#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 f_atan2(float y, float x) {
  float r, angle;
  float coeff_1 = (3.141592653589793) / 4;
  float coeff_2 = 3 * coeff_1;
  float abs_y = fabs(y) + 1e-10;
  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):
<f_atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  0xee2(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xed1(%rip),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xea9(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11c0 <f_atan2+0xb0>
movss  -0xc(%rbp),%xmm0
subss  -0x20(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
addss  -0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x18(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1206 <f_atan2+0xf6>
movss  -0xc(%rbp),%xmm0
addss  -0x20(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
subss  -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
movss  -0x10(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    122f <f_atan2+0x11f>
movss  -0x14(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1239 <f_atan2+0x129>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_atan2>:
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 <f_atan2+0x5c>
movaps %xmm1,%xmm3
addss  %xmm0,%xmm3
subss  %xmm0,%xmm1
divss  %xmm1,%xmm3
mulss  0xea6(%rip),%xmm3
addss  0xea6(%rip),%xmm3
jmp    118b <f_atan2+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 @f_atan2(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* %8
%11 = load float, float* %8
%12 = fmul float 3.000000e+00, %11
store float %12, float* %9
%13 = load float, float* %4
%14 = call i32 @fabs(float %13)
%15 = sitofp i32 %14 to double
%16 = fadd double %15, 1.000000e-10
%17 = fptrunc double %16 to float
store float %17, float* %10
%18 = load float, float* %5
%19 = fcmp oge float %18, 0.000000e+00
br i1 %19, label %20, label %33
20: ; preds = %2
%21 = load float, float* %5
%22 = load float, float* %10
%23 = fsub float %21, %22
%24 = load float, float* %5
%25 = load float, float* %10
%26 = fadd float %24, %25
%27 = fdiv float %23, %26
store float %27, float* %6
%28 = load float, float* %8
%29 = load float, float* %8
%30 = load float, float* %6
%31 = fneg float %29
%32 = call float @llvm.fmuladd.f32(float %31, float %30, float %28)
store float %32, float* %7
br label %46
33: ; preds = %2
%34 = load float, float* %5
%35 = load float, float* %10
%36 = fadd float %34, %35
%37 = load float, float* %10
%38 = load float, float* %5
%39 = fsub float %37, %38
%40 = fdiv float %36, %39
store float %40, float* %6
%41 = load float, float* %9
%42 = load float, float* %8
%43 = load float, float* %6
%44 = fneg float %42
%45 = call float @llvm.fmuladd.f32(float %44, float %43, float %41)
store float %45, float* %7
br label %46
46: ; preds = %33, %20
%47 = load float, float* %4
%48 = fcmp olt float %47, 0.000000e+00
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load float, float* %7
%51 = fneg float %50
store float %51, float* %3
br label %54
52: ; preds = %46
%53 = load float, float* %7
store float %53, float* %3
br label %54
54: ; preds = %52, %49
%55 = load float, float* %3
ret float %55
}

LLVM IR (-O2):
define float @f_atan2(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
}