#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 */
typedef int /*<<< orphan*/ const mpf_t;
typedef double mp_bitcnt_t;

/* Variables and functions */
int /*<<< orphan*/ atan_series(int /*<<< orphan*/ const,
                               int /*<<< orphan*/ const, unsigned int);
double fabs(int /*<<< orphan*/);
int /*<<< orphan*/ fp_pi_half(int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ mpf_add(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_div(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_get_d(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/ const, double);
int /*<<< orphan*/ mpf_mul(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_mul_ui(int /*<<< orphan*/ const,
                              int /*<<< orphan*/ const, int);
int /*<<< orphan*/ mpf_sqrt(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
void atan2_reduce(mpf_t atn, const mpf_t y, const mpf_t x, unsigned int prec) {
  mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
  double fy = fabs(mpf_get_d(y));
  double fx = fabs(mpf_get_d(x));
  if (fy > fx) {
    mpf_t pih;
    mpf_init2(pih, bits);
    fp_pi_half(pih, prec);
    atan2_reduce(atn, x, y, prec);
    mpf_sub(atn, pih, atn);
    mpf_clear(pih);
  }
  if (fy > 0.3 * fx) {
    mpf_t newx, ysq;
    mpf_init2(newx, bits);
    mpf_init2(ysq, bits);
    mpf_mul(ysq, y, y);
    mpf_mul(newx, x, x);
    mpf_add(newx, newx, ysq);
    mpf_sqrt(newx, newx);
    mpf_add(newx, newx, x);
    atan2_reduce(atn, y, newx, prec);
    mpf_mul_ui(atn, atn, 2);
    mpf_clear(ysq);
    mpf_clear(newx);
  } else {
    mpf_t zee;
    mpf_init2(zee, bits);
    mpf_div(zee, y, x);
    atan_series(atn, zee, prec);
    mpf_clear(zee);
  }
}


x86 assembly (clang, -O0):
<atan2_reduce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe0c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe08(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   10d0 <mpf_get_d@plt>
mov    %eax,%edi
call   1070 <fabs@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   10d0 <mpf_get_d@plt>
mov    %eax,%edi
call   1070 <fabs@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1280 <atan2_reduce+0xb0>
mov    -0x2c(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10f0 <mpf_init2@plt>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <fp_pi_half@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <atan2_reduce@plt>
mov    -0x4(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x4(%rbp),%edx
call   10b0 <mpf_sub@plt>
mov    -0x2c(%rbp),%edi
call   1080 <mpf_clear@plt>
movsd  -0x20(%rbp),%xmm0
movsd  0xd83(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    132f <atan2_reduce+0x15f>
mov    -0x30(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10f0 <mpf_init2@plt>
mov    -0x34(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10f0 <mpf_init2@plt>
mov    -0x34(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   10c0 <mpf_mul@plt>
mov    -0x30(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10c0 <mpf_mul@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1060 <mpf_add@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1050 <mpf_sqrt@plt>
mov    -0x30(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <mpf_add@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <atan2_reduce@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x2,%edx
call   10a0 <mpf_mul_ui@plt>
mov    -0x34(%rbp),%edi
call   1080 <mpf_clear@plt>
mov    -0x30(%rbp),%edi
call   1080 <mpf_clear@plt>
jmp    1360 <atan2_reduce+0x190>
mov    -0x38(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   10f0 <mpf_init2@plt>
mov    -0x38(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10e0 <mpf_div@plt>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1090 <atan_series@plt>
mov    -0x38(%rbp),%edi
call   1080 <mpf_clear@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atan2_reduce>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r15d
mov    %ecx,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xe0d(%rip),%xmm0
addsd  0xe0d(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %esi,%edi
call   10d0 <mpf_get_d@plt>
mov    %eax,%edi
call   1070 <fabs@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
call   10d0 <mpf_get_d@plt>
mov    %eax,%edi
call   1070 <fabs@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1265 <atan2_reduce+0x95>
movsd  (%rsp),%xmm0
call   10f0 <mpf_init2@plt>
mov    %r14d,%esi
call   1040 <fp_pi_half@plt>
mov    %r15d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1030 <atan2_reduce@plt>
mov    %r15d,%edi
mov    %r15d,%edx
call   10b0 <mpf_sub@plt>
call   1080 <mpf_clear@plt>
movsd  0x8(%rsp),%xmm0
mulsd  0xd9d(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   10f0 <mpf_init2@plt>
movsd  0x10(%rsp),%xmm0
ucomisd 0x8(%rsp),%xmm0
jbe    12e2 <atan2_reduce+0x112>
movsd  (%rsp),%xmm0
call   10f0 <mpf_init2@plt>
mov    %ebp,%esi
mov    %ebp,%edx
call   10c0 <mpf_mul@plt>
mov    %ebx,%esi
mov    %ebx,%edx
call   10c0 <mpf_mul@plt>
call   1060 <mpf_add@plt>
call   1050 <mpf_sqrt@plt>
mov    %ebx,%edx
call   1060 <mpf_add@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %r14d,%ecx
call   1030 <atan2_reduce@plt>
mov    %r15d,%edi
mov    %r15d,%esi
mov    $0x2,%edx
call   10a0 <mpf_mul_ui@plt>
call   1080 <mpf_clear@plt>
jmp    12f6 <atan2_reduce+0x126>
mov    %ebp,%esi
mov    %ebx,%edx
call   10e0 <mpf_div@plt>
mov    %r15d,%edi
mov    %r14d,%edx
call   1090 <atan_series@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <mpf_clear@plt>

LLVM IR (-O0):
define void @atan2_reduce(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%16 = load i32, i32* %8
%17 = uitofp i32 %16 to double
%18 = call double @llvm.fmuladd.f64(double %17, double 3.322000e+00, double 5.000000e+01)
store double %18, double* %9
%19 = load i32, i32* %6
%20 = call i32 @mpf_get_d(i32 %19)
%21 = call double @fabs(i32 %20)
store double %21, double* %10
%22 = load i32, i32* %7
%23 = call i32 @mpf_get_d(i32 %22)
%24 = call double @fabs(i32 %23)
store double %24, double* %11
%25 = load double, double* %10
%26 = load double, double* %11
%27 = fcmp ogt double %25, %26
br i1 %27, label %28, label %45
28: ; preds = %4
%29 = load i32, i32* %12
%30 = load double, double* %9
%31 = call i32 @mpf_init2(i32 %29, double %30)
%32 = load i32, i32* %12
%33 = load i32, i32* %8
%34 = call i32 @fp_pi_half(i32 %32, i32 %33)
%35 = load i32, i32* %5
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = load i32, i32* %8
%39 = load i32, i32* %5
%40 = load i32, i32* %12
%41 = load i32, i32* %5
%42 = call i32 @mpf_sub(i32 %39, i32 %40, i32 %41)
%43 = load i32, i32* %12
%44 = call i32 @mpf_clear(i32 %43)
br label %45
45: ; preds = %28, %4
%46 = load double, double* %10
%47 = load double, double* %11
%48 = fmul double 3.000000e-01, %47
%49 = fcmp ogt double %46, %48
br i1 %49, label %50, label %87
50: ; preds = %45
%51 = load i32, i32* %13
%52 = load double, double* %9
%53 = call i32 @mpf_init2(i32 %51, double %52)
%54 = load i32, i32* %14
%55 = load double, double* %9
%56 = call i32 @mpf_init2(i32 %54, double %55)
%57 = load i32, i32* %14
%58 = load i32, i32* %6
%59 = load i32, i32* %6
%60 = call i32 @mpf_mul(i32 %57, i32 %58, i32 %59)
%61 = load i32, i32* %13
%62 = load i32, i32* %7
%63 = load i32, i32* %7
%64 = call i32 @mpf_mul(i32 %61, i32 %62, i32 %63)
%65 = load i32, i32* %13
%66 = load i32, i32* %13
%67 = load i32, i32* %14
%68 = call i32 @mpf_add(i32 %65, i32 %66, i32 %67)
%69 = load i32, i32* %13
%70 = load i32, i32* %13
%71 = call i32 @mpf_sqrt(i32 %69, i32 %70)
%72 = load i32, i32* %13
%73 = load i32, i32* %13
%74 = load i32, i32* %7
%75 = call i32 @mpf_add(i32 %72, i32 %73, i32 %74)
%76 = load i32, i32* %5
%77 = load i32, i32* %6
%78 = load i32, i32* %13
%79 = load i32, i32* %8
%80 = load i32, i32* %5
%81 = load i32, i32* %5
%82 = call i32 @mpf_mul_ui(i32 %80, i32 %81, i32 2)
%83 = load i32, i32* %14
%84 = call i32 @mpf_clear(i32 %83)
%85 = load i32, i32* %13
%86 = call i32 @mpf_clear(i32 %85)
br label %101
87: ; preds = %45
%88 = load i32, i32* %15
%89 = load double, double* %9
%90 = call i32 @mpf_init2(i32 %88, double %89)
%91 = load i32, i32* %15
%92 = load i32, i32* %6
%93 = load i32, i32* %7
%94 = call i32 @mpf_div(i32 %91, i32 %92, i32 %93)
%95 = load i32, i32* %5
%96 = load i32, i32* %15
%97 = load i32, i32* %8
%98 = call i32 @atan_series(i32 %95, i32 %96, i32 %97)
%99 = load i32, i32* %15
%100 = call i32 @mpf_clear(i32 %99)
br label %101
101: ; preds = %87, %50
ret void
}

LLVM IR (-O2):
define void @atan2_reduce(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = uitofp i32 %3 to double
%6 = tail call double @llvm.fmuladd.f64(double %5, double 3.322000e+00, double 5.000000e+01)
%7 = tail call i32 @mpf_get_d(i32 %1)
%8 = tail call double @fabs(i32 %7)
%9 = tail call i32 @mpf_get_d(i32 %2)
%10 = tail call double @fabs(i32 %9)
%11 = fcmp ogt double %8, %10
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = tail call i32 @mpf_init2(i32 undef, double %6)
%14 = tail call i32 @fp_pi_half(i32 undef, i32 %3)
tail call void @atan2_reduce(i32 %0, i32 %2, i32 %1, i32 %3)
%15 = tail call i32 @mpf_sub(i32 %0, i32 undef, i32 %0)
%16 = tail call i32 @mpf_clear(i32 undef)
br label %17
17: ; preds = %12, %4
%18 = fmul double %10, 3.000000e-01
%19 = fcmp ogt double %8, %18
%20 = tail call i32 @mpf_init2(i32 undef, double %6)
br i1 %19, label %23, label %32
21: ; preds = %32, %23
%22 = tail call i32 @mpf_clear(i32 undef)
ret void
23: ; preds = %17
%24 = tail call i32 @mpf_init2(i32 undef, double %6)
%25 = tail call i32 @mpf_mul(i32 undef, i32 %1, i32 %1)
%26 = tail call i32 @mpf_mul(i32 undef, i32 %2, i32 %2)
%27 = tail call i32 @mpf_add(i32 undef, i32 undef, i32 undef)
%28 = tail call i32 @mpf_sqrt(i32 undef, i32 undef)
%29 = tail call i32 @mpf_add(i32 undef, i32 undef, i32 %2)
tail call void @atan2_reduce(i32 %0, i32 %1, i32 undef, i32 %3)
%30 = tail call i32 @mpf_mul_ui(i32 %0, i32 %0, i32 2)
%31 = tail call i32 @mpf_clear(i32 undef)
br label %21
32: ; preds = %17
%33 = tail call i32 @mpf_div(i32 undef, i32 %1, i32 %2)
%34 = tail call i32 @atan_series(i32 %0, i32 undef, i32 %3)
br label %21
}