// File: /workspace/github_c_makefile_star2_O0/esheldon[P]xshear/src/healpix.c
// Function: hpix_eq2pix
int64 hpix_eq2pix(const HealPix* hpix, double ra, double dec) {
    int64 nside=hpix->nside;
    int64 ipix=0;
    double theta=0, phi=0;

    hpix_radec_degrees_to_thetaphi_radians(ra, dec, &theta, &phi);

    double z = cos(theta);
    double za = fabs(z);

    // in [0,4)
    double tt = fmod(phi, M_TWO_PI)/M_PI_2;

    if (za <= M_TWOTHIRD) {
        double temp1 = nside*(.5 + tt);
        double temp2 = nside*.75*z;

        int64 jp = (int64)(temp1-temp2); // index of  ascending edge line
        int64 jm = (int64)(temp1+temp2); // index of descending edge line
        int64 ir = nside + 1 + jp - jm;  // in {1,2n+1} (ring number counted from z=2/3)
        int64 kshift = 1 - (ir % 2);      // kshift=1 if ir even, 0 otherwise
        
        int64 nl4 = 4*nside;
        int64 ip = (int64)( ( jp+jm - nside + kshift + 1 ) / 2); // in {0,4n-1}

        ip = ip % nl4;

        ipix = hpix->ncap + nl4*(ir-1) + ip;

    } else { 
        // North & South polar caps
        double tp = tt - (int64)(tt);   // MODULO(tt,1.0_dp)

        double tmp = nside * sqrt( 3.0*(1.0 - za) );
        int64 jp = (int64)(tp*tmp);              // increasing edge line index
        int64 jm = (int64)((1.0 - tp) * tmp); // decreasing edge line index

        int64 ir = jp + jm + 1;        // ring number counted from the closest pole
        int64 ip = (int64)( tt * ir);     // in {0,4*ir-1}

        if (ip >= 4*ir) {
            ip = ip - 4*ir;
        }
        if (z>0.) {
            ipix = 2*ir*(ir-1) + ip;
        } else {
            ipix = hpix->npix - 2*ir*(ir+1) + ip;
        }

    }

    return ipix;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3760
movsd -0x30(%rbp), %xmm0
callq 0x2120
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movaps 0xac12(%rip), %xmm1     # 0xe0b0
pand %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
movsd 0xabcc(%rip), %xmm1     # 0xe080
callq 0x2110
movsd 0xab6f(%rip), %xmm1     # 0xe030
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0xab7e(%rip), %xmm0     # 0xe050
ucomisd -0x48(%rbp), %xmm0
jb 0x35e2
cvtsi2sdq -0x20(%rbp), %xmm0
movsd 0xab7d(%rip), %xmm1     # 0xe068
addsd -0x50(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
cvtsi2sdq -0x20(%rbp), %xmm0
movsd 0xab81(%rip), %xmm1     # 0xe088
mulsd %xmm1, %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x58(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x68(%rbp)
movsd -0x58(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
addq -0x68(%rbp), %rax
subq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movl $0x1, %eax
subq %rdx, %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
shlq $0x2, %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
subq -0x20(%rbp), %rax
addq -0x80(%rbp), %rax
addq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cqto
idivq -0x88(%rbp)
movq %rdx, -0x90(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x88(%rbp), %rcx
movq -0x78(%rbp), %rdx
subq $0x1, %rdx
imulq %rdx, %rcx
addq %rcx, %rax
addq -0x90(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x3750
movsd -0x50(%rbp), %xmm0
cvttsd2si -0x50(%rbp), %rax
cvtsi2sd %rax, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
cvtsi2sdq -0x20(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0xaa14(%rip), %xmm1     # 0xe028
subsd -0x48(%rbp), %xmm1
movsd 0xa9ff(%rip), %xmm0     # 0xe020
mulsd %xmm1, %xmm0
callq 0x2270
movaps %xmm0, %xmm1
movsd -0xc8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x98(%rbp), %xmm0
mulsd -0xa0(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xa8(%rbp)
movsd 0xa9c3(%rip), %xmm0     # 0xe028
subsd -0x98(%rbp), %xmm0
mulsd -0xa0(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
addq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
movsd -0x50(%rbp), %xmm0
cvtsi2sdq -0xb8(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq -0xb8(%rbp), %rcx
shlq $0x2, %rcx
cmpq %rcx, %rax
jl 0x36eb
movq -0xc0(%rbp), %rax
movq -0xb8(%rbp), %rcx
shlq $0x2, %rcx
subq %rcx, %rax
movq %rax, -0xc0(%rbp)
movsd -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x371f
movq -0xb8(%rbp), %rax
shlq %rax
movq -0xb8(%rbp), %rcx
subq $0x1, %rcx
imulq %rcx, %rax
addq -0xc0(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x374e
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0xb8(%rbp), %rcx
shlq %rcx
movq -0xb8(%rbp), %rdx
addq $0x1, %rdx
imulq %rdx, %rcx
subq %rcx, %rax
addq -0xc0(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x3750
movq -0x28(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)