// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movl $0x1, %esi
callq 0x8170
cmpl $0x0, %eax
je 0x1b2b0
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8300
movl %eax, 0x84(%rsp)
jmp 0x1b489
movq 0x78(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movl $0x2, %esi
leaq 0x18(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x8b00
cmpl $0x0, %eax
je 0x1b327
movq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x8350
movsd %xmm0, 0x50(%rsp)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8300
movl %eax, 0x84(%rsp)
jmp 0x1b489
movq 0x78(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movl $0x1, %esi
leaq 0x18(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x8b00
cmpl $0x0, %eax
je 0x1b3ec
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x8350
movsd 0x839b(%rip), %xmm1     # 0x23700
divsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
callq 0x8c60
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
callq 0x8610
movsd %xmm0, 0x50(%rsp)
movsd 0x30(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x38(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x40(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x8640
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8300
movl %eax, 0x84(%rsp)
jmp 0x1b489
movq 0x78(%rsp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rdx
movq %r8, %rcx
callq 0x8a30
cmpl $0x0, %eax
je 0x1b41e
movq 0x78(%rsp), %rdi
callq 0x8c40
movl %eax, 0x84(%rsp)
jmp 0x1b489
movq $0x1, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
cmpq $0x4, 0x10(%rsp)
jae 0x1b473
movq 0x78(%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rsp)
movl %eax, %esi
xorps %xmm0, %xmm0
callq 0x8370
movq 0x10(%rsp), %rax
movsd %xmm0, 0x50(%rsp,%rax,8)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x1b430
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x8300
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopl (%rax,%rax)