// File: /workspace/github_c_makefile_star2_O1/stetre[P]moonglmath/src/quat.c
// Function: Quat
static int Quat(lua_State *L)
/* creates a quaternion from another quaternion, a scalar and a vec3, a matrix,
 * or a list of scalars.
 * the size is adapted by discarding exceeding values or adding zeros in lieu 
 * of missing values.
 * quat(q)
 * quat([w [, x [, y [, z]]])
 * quat(s, v)
 * quat(mat)
 * quat(axis, theta)
 */
    {
    quat_t q;
    vec_t v;
    double halftheta, s;
    size_t vsize, i, arg;

    if(testquat(L, 1, q))
        return pushquat(L, q);

    if(testvec(L, 2, v, &vsize, NULL))
        {
#if 0
        if(vsize != 3)
            return luaL_argerror(L, 2, "size 3 vector expected");
#endif
        q[0] = luaL_checknumber(L, 1);
        q[1] = v[0];
        q[2] = v[1];
        q[3] = v[2];
        return pushquat(L, q);
        }

    if(testvec(L, 1, v, &vsize, NULL)) // rotation quaternion
        {
        halftheta = luaL_checknumber(L, 2)/2;
        s = sin(halftheta);
        q[0] = cos(halftheta);
        q[1] = v[0] * s;
        q[2] = v[1] * s;
        q[3] = v[2] * s;
        quat_normalize(q);
        return pushquat(L, q);
        }

    if(testmat(L, 1, NULL, NULL, NULL))
        return quat_FromMat(L);

    arg = 1;
    for(i = 0; i < 4; i++)
        q[i] = luaL_optnumber(L, arg++, 0);
    return pushquat(L, q);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl $0x1, %ebp
movq %rsp, %rdx
movl $0x1, %esi
callq 0x8160
testl %eax, %eax
je 0x12762
movq %rsp, %rsi
jmp 0x127ad
leaq 0x30(%rsp), %rdx
leaq 0x28(%rsp), %rcx
movq %rbx, %rdi
movl $0x2, %esi
xorl %r8d, %r8d
callq 0x8a50
testl %eax, %eax
je 0x127c2
movl $0x1, %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0x8320
movq %rsp, %rsi
movsd %xmm0, (%rsi)
movaps 0x30(%rsp), %xmm0
movups %xmm0, 0x8(%rsi)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x18(%rsi)
movq %rbx, %rdi
callq 0x82d0
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rsp), %rdx
leaq 0x28(%rsp), %rcx
movq %rbx, %rdi
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x8a50
movq %rbx, %rdi
testl %eax, %eax
je 0x1286c
movl $0x2, %esi
callq 0x8320
mulsd 0x4f9f(%rip), %xmm0     # 0x17798
movsd %xmm0, 0x20(%rsp)
callq 0x8b80
movapd %xmm0, 0x50(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x85d0
movsd %xmm0, (%rsp)
movapd 0x50(%rsp), %xmm1
movapd %xmm1, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd 0x30(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm1
movupd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x18(%rsp)
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd (%rsp,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq $0x4, %rax
jne 0x12846
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x12890
sqrtsd %xmm0, %xmm0
jmp 0x12895
movl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x8990
testl %eax, %eax
je 0x128c8
movq %rbx, %rdi
callq 0x8b60
movl %eax, %ebp
jmp 0x127b5
callq 0x8cd0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
xorl %eax, %eax
movapd (%rsp,%rax,8), %xmm1
divpd %xmm0, %xmm1
movapd %xmm1, (%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x4, %rax
jne 0x1289b
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x82d0
movl $0x1, %ebp
jmp 0x127b5
xorl %r15d, %r15d
leaq 0x1(%r15), %r14
xorpd %xmm0, %xmm0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x8340
movsd %xmm0, (%rsp,%r15,8)
movq %r14, %r15
cmpq $0x4, %r14
jne 0x128cb
jmp 0x128b3