#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*/ atan2_reduce(int /*<<< orphan*/ const,
                                int /*<<< orphan*/ const,
                                int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ fp_pi(int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ fp_pi_half(int /*<<< orphan*/ const, unsigned int);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_init2(int /*<<< orphan*/ const, double);
int /*<<< orphan*/ mpf_neg(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int mpf_sgn(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                           int /*<<< orphan*/ const);
void fp_arctan2(mpf_t atn, const mpf_t y, const mpf_t x, unsigned int prec) {
  int sgn_x = mpf_sgn(x);
  int sgn_y = mpf_sgn(y);
  if (0 < sgn_y) {
    if (0 < sgn_x) {
      atan2_reduce(atn, y, x, prec);
    } else if (0 > sgn_x) {
      mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
      mpf_t pi, negx;
      mpf_init2(pi, bits);
      mpf_init2(negx, bits);
      fp_pi(pi, prec);
      mpf_neg(negx, x);
      atan2_reduce(atn, y, negx, prec);
      mpf_sub(atn, pi, atn);
      mpf_clear(pi);
      mpf_clear(negx);
    } else {
      fp_pi_half(atn, prec);
    }
  } else {
    if (0 < sgn_x) {
      atan2_reduce(atn, y, x, prec);
    } else if (0 > sgn_x) {
      mp_bitcnt_t bits = ((double)prec) * 3.322 + 50;
      mpf_t negpi, negx;
      mpf_init2(negpi, bits);
      mpf_init2(negx, bits);
      fp_pi(negpi, prec);
      mpf_neg(negpi, negpi);
      mpf_neg(negx, x);
      atan2_reduce(atn, y, negx, prec);
      mpf_sub(atn, negpi, atn);
      mpf_clear(negpi);
      mpf_clear(negx);
    } else {
      fp_pi_half(atn, prec);
      mpf_neg(atn, atn);
    }
  }
}


x86 assembly (clang, -O0):
<fp_arctan2>:
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    -0xc(%rbp),%edi
call   1080 <mpf_sgn@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <mpf_sgn@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jge    127f <fp_arctan2+0xff>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jge    11d6 <fp_arctan2+0x56>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <atan2_reduce@plt>
jmp    127a <fp_arctan2+0xfa>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jle    126a <fp_arctan2+0xea>
mov    -0x10(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe0f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe0b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%edi
movsd  -0x20(%rbp),%xmm0
call   10a0 <mpf_init2@plt>
mov    -0x28(%rbp),%edi
movsd  -0x20(%rbp),%xmm0
call   10a0 <mpf_init2@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <fp_pi@plt>
mov    -0x28(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <mpf_neg@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <atan2_reduce@plt>
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <mpf_sub@plt>
mov    -0x24(%rbp),%edi
call   1060 <mpf_clear@plt>
mov    -0x28(%rbp),%edi
call   1060 <mpf_clear@plt>
jmp    1275 <fp_arctan2+0xf5>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <fp_pi_half@plt>
jmp    127a <fp_arctan2+0xfa>
jmp    135f <fp_arctan2+0x1df>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jge    12a0 <fp_arctan2+0x120>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <atan2_reduce@plt>
jmp    135a <fp_arctan2+0x1da>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jle    133f <fp_arctan2+0x1bf>
mov    -0x10(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xd45(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd41(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%edi
movsd  -0x30(%rbp),%xmm0
call   10a0 <mpf_init2@plt>
mov    -0x38(%rbp),%edi
movsd  -0x30(%rbp),%xmm0
call   10a0 <mpf_init2@plt>
mov    -0x34(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1090 <fp_pi@plt>
mov    -0x34(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1050 <mpf_neg@plt>
mov    -0x38(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <mpf_neg@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <atan2_reduce@plt>
mov    -0x4(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1070 <mpf_sub@plt>
mov    -0x34(%rbp),%edi
call   1060 <mpf_clear@plt>
mov    -0x38(%rbp),%edi
call   1060 <mpf_clear@plt>
jmp    1355 <fp_arctan2+0x1d5>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <fp_pi_half@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <mpf_neg@plt>
jmp    135a <fp_arctan2+0x1da>
jmp    135f <fp_arctan2+0x1df>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_arctan2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%r15d
mov    %edx,%edi
call   1080 <mpf_sgn@plt>
mov    %eax,%ebp
mov    %r12d,%edi
call   1080 <mpf_sgn@plt>
test   %eax,%eax
jle    11c9 <fp_arctan2+0x49>
test   %ebp,%ebp
jg     11cd <fp_arctan2+0x4d>
js     120d <fp_arctan2+0x8d>
mov    %r15d,%edi
mov    %r14d,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fp_pi_half@plt>
test   %ebp,%ebp
jle    11e9 <fp_arctan2+0x69>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <atan2_reduce@plt>
js     1245 <fp_arctan2+0xc5>
mov    %r15d,%edi
mov    %r14d,%esi
call   1040 <fp_pi_half@plt>
mov    %r15d,%edi
mov    %r15d,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mpf_neg@plt>
mov    %r14d,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xde3(%rip),%xmm0
addsd  0xde3(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   10a0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10a0 <mpf_init2@plt>
mov    %r14d,%esi
call   1090 <fp_pi@plt>
jmp    1280 <fp_arctan2+0x100>
mov    %r14d,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xdab(%rip),%xmm0
addsd  0xdab(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   10a0 <mpf_init2@plt>
movsd  0x8(%rsp),%xmm0
call   10a0 <mpf_init2@plt>
mov    %r14d,%esi
call   1090 <fp_pi@plt>
call   1050 <mpf_neg@plt>
mov    %ebx,%esi
call   1050 <mpf_neg@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r14d,%ecx
call   1030 <atan2_reduce@plt>
mov    %r15d,%edi
mov    %r15d,%edx
call   1070 <mpf_sub@plt>
call   1060 <mpf_clear@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <mpf_clear@plt>

LLVM IR (-O0):
define void @fp_arctan2(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%17 = load i32, i32* %7
%18 = call i32 @mpf_sgn(i32 %17)
store i32 %18, i32* %9
%19 = load i32, i32* %6
%20 = call i32 @mpf_sgn(i32 %19)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = icmp slt i32 0, %21
br i1 %22, label %23, label %70
23: ; preds = %4
%24 = load i32, i32* %9
%25 = icmp slt i32 0, %24
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = call i32 @atan2_reduce(i32 %27, i32 %28, i32 %29, i32 %30)
br label %69
32: ; preds = %23
%33 = load i32, i32* %9
%34 = icmp sgt i32 0, %33
br i1 %34, label %35, label %64
35: ; preds = %32
%36 = load i32, i32* %8
%37 = uitofp i32 %36 to double
%38 = call double @llvm.fmuladd.f64(double %37, double 3.322000e+00, double 5.000000e+01)
store double %38, double* %11
%39 = load i32, i32* %12
%40 = load double, double* %11
%41 = call i32 @mpf_init2(i32 %39, double %40)
%42 = load i32, i32* %13
%43 = load double, double* %11
%44 = call i32 @mpf_init2(i32 %42, double %43)
%45 = load i32, i32* %12
%46 = load i32, i32* %8
%47 = call i32 @fp_pi(i32 %45, i32 %46)
%48 = load i32, i32* %13
%49 = load i32, i32* %7
%50 = call i32 @mpf_neg(i32 %48, i32 %49)
%51 = load i32, i32* %5
%52 = load i32, i32* %6
%53 = load i32, i32* %13
%54 = load i32, i32* %8
%55 = call i32 @atan2_reduce(i32 %51, i32 %52, i32 %53, i32 %54)
%56 = load i32, i32* %5
%57 = load i32, i32* %12
%58 = load i32, i32* %5
%59 = call i32 @mpf_sub(i32 %56, i32 %57, i32 %58)
%60 = load i32, i32* %12
%61 = call i32 @mpf_clear(i32 %60)
%62 = load i32, i32* %13
%63 = call i32 @mpf_clear(i32 %62)
br label %68
64: ; preds = %32
%65 = load i32, i32* %5
%66 = load i32, i32* %8
%67 = call i32 @fp_pi_half(i32 %65, i32 %66)
br label %68
68: ; preds = %64, %35
br label %69
69: ; preds = %68, %26
br label %123
70: ; preds = %4
%71 = load i32, i32* %9
%72 = icmp slt i32 0, %71
br i1 %72, label %73, label %79
73: ; preds = %70
%74 = load i32, i32* %5
%75 = load i32, i32* %6
%76 = load i32, i32* %7
%77 = load i32, i32* %8
%78 = call i32 @atan2_reduce(i32 %74, i32 %75, i32 %76, i32 %77)
br label %122
79: ; preds = %70
%80 = load i32, i32* %9
%81 = icmp sgt i32 0, %80
br i1 %81, label %82, label %114
82: ; preds = %79
%83 = load i32, i32* %8
%84 = uitofp i32 %83 to double
%85 = call double @llvm.fmuladd.f64(double %84, double 3.322000e+00, double 5.000000e+01)
store double %85, double* %14
%86 = load i32, i32* %15
%87 = load double, double* %14
%88 = call i32 @mpf_init2(i32 %86, double %87)
%89 = load i32, i32* %16
%90 = load double, double* %14
%91 = call i32 @mpf_init2(i32 %89, double %90)
%92 = load i32, i32* %15
%93 = load i32, i32* %8
%94 = call i32 @fp_pi(i32 %92, i32 %93)
%95 = load i32, i32* %15
%96 = load i32, i32* %15
%97 = call i32 @mpf_neg(i32 %95, i32 %96)
%98 = load i32, i32* %16
%99 = load i32, i32* %7
%100 = call i32 @mpf_neg(i32 %98, i32 %99)
%101 = load i32, i32* %5
%102 = load i32, i32* %6
%103 = load i32, i32* %16
%104 = load i32, i32* %8
%105 = call i32 @atan2_reduce(i32 %101, i32 %102, i32 %103, i32 %104)
%106 = load i32, i32* %5
%107 = load i32, i32* %15
%108 = load i32, i32* %5
%109 = call i32 @mpf_sub(i32 %106, i32 %107, i32 %108)
%110 = load i32, i32* %15
%111 = call i32 @mpf_clear(i32 %110)
%112 = load i32, i32* %16
%113 = call i32 @mpf_clear(i32 %112)
br label %121
114: ; preds = %79
%115 = load i32, i32* %5
%116 = load i32, i32* %8
%117 = call i32 @fp_pi_half(i32 %115, i32 %116)
%118 = load i32, i32* %5
%119 = load i32, i32* %5
%120 = call i32 @mpf_neg(i32 %118, i32 %119)
br label %121
121: ; preds = %114, %82
br label %122
122: ; preds = %121, %73
br label %123
123: ; preds = %122, %69
ret void
}

LLVM IR (-O2):
define void @fp_arctan2(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @mpf_sgn(i32 %2)
%6 = tail call i32 @mpf_sgn(i32 %1)
%7 = icmp sgt i32 %6, 0
%8 = icmp sgt i32 %5, 0
br i1 %7, label %9, label %27
9: ; preds = %4
br i1 %8, label %10, label %12
10: ; preds = %9
%11 = tail call i32 @atan2_reduce(i32 %0, i32 %1, i32 %2, i32 %3)
br label %47
12: ; preds = %9
%13 = icmp slt i32 %5, 0
br i1 %13, label %14, label %25
14: ; preds = %12
%15 = uitofp i32 %3 to double
%16 = tail call double @llvm.fmuladd.f64(double %15, double 3.322000e+00, double 5.000000e+01)
%17 = tail call i32 @mpf_init2(i32 undef, double %16)
%18 = tail call i32 @mpf_init2(i32 undef, double %16)
%19 = tail call i32 @fp_pi(i32 undef, i32 %3)
%20 = tail call i32 @mpf_neg(i32 undef, i32 %2)
%21 = tail call i32 @atan2_reduce(i32 %0, i32 %1, i32 undef, i32 %3)
%22 = tail call i32 @mpf_sub(i32 %0, i32 undef, i32 %0)
%23 = tail call i32 @mpf_clear(i32 undef)
%24 = tail call i32 @mpf_clear(i32 undef)
br label %47
25: ; preds = %12
%26 = tail call i32 @fp_pi_half(i32 %0, i32 %3)
br label %47
27: ; preds = %4
br i1 %8, label %28, label %30
28: ; preds = %27
%29 = tail call i32 @atan2_reduce(i32 %0, i32 %1, i32 %2, i32 %3)
br label %47
30: ; preds = %27
%31 = icmp slt i32 %5, 0
br i1 %31, label %32, label %44
32: ; preds = %30
%33 = uitofp i32 %3 to double
%34 = tail call double @llvm.fmuladd.f64(double %33, double 3.322000e+00, double 5.000000e+01)
%35 = tail call i32 @mpf_init2(i32 undef, double %34)
%36 = tail call i32 @mpf_init2(i32 undef, double %34)
%37 = tail call i32 @fp_pi(i32 undef, i32 %3)
%38 = tail call i32 @mpf_neg(i32 undef, i32 undef)
%39 = tail call i32 @mpf_neg(i32 undef, i32 %2)
%40 = tail call i32 @atan2_reduce(i32 %0, i32 %1, i32 undef, i32 %3)
%41 = tail call i32 @mpf_sub(i32 %0, i32 undef, i32 %0)
%42 = tail call i32 @mpf_clear(i32 undef)
%43 = tail call i32 @mpf_clear(i32 undef)
br label %47
44: ; preds = %30
%45 = tail call i32 @fp_pi_half(i32 %0, i32 %3)
%46 = tail call i32 @mpf_neg(i32 %0, i32 %0)
br label %47
47: ; preds = %28, %44, %32, %10, %25, %14
ret void
}