// File: /workspace/github_c_makefile_star2_O0/stetre[P]moonglmath/src/quat.c
// Function: moonglmath_quat_slerp
void quat_slerp(quat_t dst, quat_t q, quat_t p, double t)
/* Rfr: "3D Math Primer for Graphics and Game Development", by F. Dunn, I. Parberry,
 *      AK Peters/CRC Press, section 8.5.11.
 */
    {
    double c, s, theta, t0, t1;
    c = q[0]*p[0] + q[1]*p[1] + q[2]*p[2] + q[3]*p[3];
    if(c < 0.0f)
        {
        c = -c;
        p[0] = - p[0];
        p[1] = - p[1];
        p[2] = - p[2];
        p[3] = - p[3];
        }
    if(c > .9999f) // q and p are very close: use linear interpolation
        quat_mix(dst, q, p, t);
    else
        {
        s = sqrt(1.0f - c*c);
        theta = atan2(s, c);
        t0 = sin((1.0f - t)*theta)/s;
        t1 = sin(t*theta)/s;
        dst[0] = t0*q[0] + t1*p[0];
        dst[1] = t0*q[1] + t1*p[1];
        dst[2] = t0*q[2] + t1*p[2];
        dst[3] = t0*q[3] + t1*p[3];
        }
    }

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
movq 0x38(%rsp), %rax
movsd (%rax), %xmm0
movq 0x30(%rsp), %rax
movsd (%rax), %xmm2
movq 0x38(%rsp), %rax
movsd 0x8(%rax), %xmm1
movq 0x30(%rsp), %rax
mulsd 0x8(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x38(%rsp), %rax
movsd 0x10(%rax), %xmm1
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x38(%rsp), %rax
movsd 0x18(%rax), %xmm0
movq 0x30(%rsp), %rax
movsd 0x18(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x20(%rsp), %xmm0
jbe 0x19cd1
movsd 0x20(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, 0x10(%rax)
movq 0x30(%rsp), %rax
movsd 0x18(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x30(%rsp), %rax
movsd %xmm0, 0x18(%rax)
movsd 0x20(%rsp), %xmm0
movsd 0x9a11(%rip), %xmm1     # 0x236f0
ucomisd %xmm1, %xmm0
jbe 0x19d04
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
movsd 0x28(%rsp), %xmm0
callq 0x87b0
jmp 0x19e5b
movsd 0x20(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm1, %xmm0
movsd 0x938d(%rip), %xmm1     # 0x230c0
addsd %xmm1, %xmm0
callq 0x8db0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x89b0
movsd %xmm0, 0x10(%rsp)
movsd 0x935f(%rip), %xmm0     # 0x230c0
subsd 0x28(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
callq 0x8c60
divsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x28(%rsp), %xmm0
mulsd 0x10(%rsp), %xmm0
callq 0x8c60
divsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movsd (%rax), %xmm2
movsd (%rsp), %xmm1
movq 0x30(%rsp), %rax
mulsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x40(%rsp), %rax
movsd %xmm0, (%rax)
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movsd 0x8(%rax), %xmm2
movsd (%rsp), %xmm1
movq 0x30(%rsp), %rax
mulsd 0x8(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x40(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movsd 0x10(%rax), %xmm2
movsd (%rsp), %xmm1
movq 0x30(%rsp), %rax
mulsd 0x10(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x40(%rsp), %rax
movsd %xmm0, 0x10(%rax)
movsd 0x8(%rsp), %xmm0
movq 0x38(%rsp), %rax
movsd 0x18(%rax), %xmm2
movsd (%rsp), %xmm1
movq 0x30(%rsp), %rax
mulsd 0x18(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x40(%rsp), %rax
movsd %xmm0, 0x18(%rax)
addq $0x48, %rsp
retq