#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 M_PI;
int fabs(double);
double pp_atan2(double x, double y) {
  double coeff_1 = M_PI / 4;
  double coeff_2 = 3 * coeff_1;
  double abs_y = fabs(y) + 1e-10;
  double angle, r;
  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):
<pp_atan2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    0x2ebf(%rip),%rax
mov    (%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec4(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe9c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d4 <pp_atan2+0xc4>
movsd  -0x10(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1224 <pp_atan2+0x114>
movsd  -0x10(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1258 <pp_atan2+0x148>
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1262 <pp_atan2+0x152>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pp_atan2>:
sub    $0x38,%rsp
mov    0x2ecd(%rip),%rax
mov    (%rax),%eax
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
movsd  %xmm0,0x8(%rsp)
sar    $0x2,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm1,0x20(%rsp)
movapd %xmm1,%xmm0
call   1030 <fabs@plt>
movsd  0x8(%rsp),%xmm4
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xea1(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm4
jbe    1189 <pp_atan2+0x79>
movapd %xmm4,%xmm1
subsd  %xmm0,%xmm1
addsd  %xmm4,%xmm0
divsd  %xmm0,%xmm1
movapd 0x10(%rsp),%xmm3
mulsd  %xmm3,%xmm1
subsd  %xmm1,%xmm3
jmp    11b7 <pp_atan2+0xa7>
movsd  0xe77(%rip),%xmm1
movapd 0x10(%rsp),%xmm3
mulsd  %xmm3,%xmm1
movapd %xmm0,%xmm2
addsd  %xmm4,%xmm2
subsd  %xmm4,%xmm0
divsd  %xmm0,%xmm2
mulsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm3
movapd 0xe51(%rip),%xmm2
xorpd  %xmm3,%xmm2
xorpd  %xmm1,%xmm1
movapd 0x20(%rsp),%xmm0
cmpltsd %xmm1,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm3,%xmm0
orpd   %xmm2,%xmm0
add    $0x38,%rsp
ret

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

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