// File: /workspace/github_cpp_makefile_star2_O3/FreeSlave[P]vhlt/common/winding.cpp
// Function: Winding::initFromPlane(double const*, double)
void Winding::initFromPlane(const vec3_t normal, const vec_t dist)
{
    int             i;
    vec_t           max, v;
    vec3_t          org, vright, vup;

    // find the major axis               

    max = -BOGUS_RANGE;
    int x = -1;
    for (i = 0; i < 3; i++)          
    {
        v = fabs(normal[i]);        
        if (v > max)
        {
            max = v;
            x = i;
        }
    }                
    if (x == -1)
    {
        Error("Winding::initFromPlane no major axis found\n");
    }

    VectorCopy(vec3_origin, vup);
    switch (x) 
    {
    case 0:
    case 1:          
        vup[2] = 1;
        break;
    case 2:
        vup[0] = 1;      
        break;
    }

    v = DotProduct(vup, normal);
    VectorMA(vup, -v, normal, vup);
    VectorNormalize(vup);

    VectorScale(normal, dist, org);

    CrossProduct(vup, normal, vright);

    VectorScale(vup, BOGUS_RANGE, vup);
    VectorScale(vright, BOGUS_RANGE, vright);

    // project a really big     axis aligned box onto the plane
    m_NumPoints = 4;
    m_Points = new vec3_t[m_NumPoints];

    VectorSubtract(org, vright, m_Points[0]);
    VectorAdd(m_Points[0], vup, m_Points[0]);

    VectorAdd(org, vright, m_Points[1]);
    VectorAdd(m_Points[1], vup, m_Points[1]);

    VectorAdd(org, vright, m_Points[2]);
    VectorSubtract(m_Points[2], vup, m_Points[2]);

    VectorSubtract(org, vright, m_Points[3]);
    VectorSubtract(m_Points[3], vup, m_Points[3]);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movsd 0x12d9d(%rip), %xmm1    # 0x1f2a0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movapd 0x12dde(%rip), %xmm3    # 0x1f2f0
movsd (%r14,%rcx,8), %xmm2
andpd %xmm3, %xmm2
ucomisd %xmm1, %xmm2
cmoval %ecx, %eax
maxsd %xmm1, %xmm2
incq %rcx
movapd %xmm2, %xmm1
cmpq $0x3, %rcx
jne 0xc512
cmpl $-0x1, %eax
movapd %xmm0, 0x20(%rsp)
je 0xc55e
leaq 0x118ba(%rip), %rcx     # 0x1de00
movaps (%rcx), %xmm1
cmpl $0x2, %eax
jae 0xc58e
movsd 0x12b92(%rip), %xmm2    # 0x1f0e8
movsd %xmm2, 0x8(%rsp)
jmp 0xc5a2
leaq 0x12e79(%rip), %rdi     # 0x1f3de
xorl %eax, %eax
callq 0xa164
movapd 0x20(%rsp), %xmm0
leaq 0x11887(%rip), %rax     # 0x1de00
movaps (%rax), %xmm1
movaps %xmm1, 0x10(%rsp)
movsd 0x10(%rax), %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0xc5a7
movsd 0x10(%rcx), %xmm2
movsd %xmm2, 0x8(%rsp)
jne 0xc5a2
movlps 0x12b46(%rip), %xmm1    # xmm1 = mem[0,1],xmm1[2,3]
movaps %xmm1, 0x10(%rsp)
movsd 0x10(%r14), %xmm1
movapd %xmm1, 0x30(%rsp)
mulsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movl $0x60, %edi
callq 0x4040
movapd 0x30(%rsp), %xmm7
movupd (%r14), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
movapd 0x10(%rsp), %xmm4
movapd %xmm4, %xmm2
mulpd %xmm1, %xmm2
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm4, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd 0x8(%rsp), %xmm5
movapd %xmm5, %xmm2
mulsd %xmm7, %xmm2
addsd %xmm3, %xmm2
movapd %xmm2, %xmm3
unpcklpd %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
mulpd %xmm1, %xmm3
subpd %xmm3, %xmm4
mulsd %xmm7, %xmm2
subsd %xmm2, %xmm5
movapd %xmm4, %xmm2
mulpd %xmm4, %xmm2
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm4, %xmm3
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
movapd %xmm5, %xmm2
mulsd %xmm5, %xmm2
addsd %xmm3, %xmm2
xorps %xmm3, %xmm3
sqrtsd %xmm2, %xmm3
movsd 0xfac3(%rip), %xmm2     # 0x1c118
xorl %ecx, %ecx
ucomisd %xmm3, %xmm2
seta %dl
movapd %xmm3, %xmm2
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
divpd %xmm2, %xmm4
xorpd %xmm2, %xmm2
ja 0xc678
divsd %xmm3, %xmm5
movapd %xmm5, %xmm2
movb %dl, %cl
movd %ecx, %xmm3
pshufd $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
pslld $0x1f, %xmm3
psrad $0x1f, %xmm3
pandn %xmm4, %xmm3
movapd 0x20(%rsp), %xmm6
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
mulpd %xmm1, %xmm6
movapd %xmm2, %xmm4
unpcklpd %xmm3, %xmm4            # xmm4 = xmm4[0],xmm3[0]
movapd %xmm1, %xmm5
shufpd $0x1, %xmm7, %xmm5      # xmm5 = xmm5[1],xmm7[0]
mulpd %xmm4, %xmm5
movapd %xmm3, %xmm4
shufpd $0x1, %xmm2, %xmm4      # xmm4 = xmm4[1],xmm2[0]
unpcklpd %xmm1, %xmm7            # xmm7 = xmm7[0],xmm1[0]
mulpd %xmm4, %xmm7
subpd %xmm5, %xmm7
pshufd $0xee, %xmm3, %xmm4     # xmm4 = xmm3[2,3,2,3]
mulsd %xmm1, %xmm4
mulsd %xmm3, %xmm0
subsd %xmm4, %xmm0
movapd 0x12c1e(%rip), %xmm1    # 0x1f300
mulpd %xmm1, %xmm3
movsd 0x12baa(%rip), %xmm4    # 0x1f298
mulsd %xmm4, %xmm2
mulpd %xmm1, %xmm7
mulsd %xmm4, %xmm0
movl $0x4, 0x8(%rbx)
movq %rax, 0x10(%rbx)
movapd %xmm6, %xmm1
subpd %xmm7, %xmm1
movapd 0x40(%rsp), %xmm8
movapd %xmm8, %xmm4
subsd %xmm0, %xmm4
movapd %xmm3, %xmm5
addpd %xmm1, %xmm5
movupd %xmm5, (%rax)
movapd %xmm2, %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, 0x10(%rax)
addsd %xmm8, %xmm0
addpd %xmm6, %xmm7
movapd %xmm3, %xmm5
addpd %xmm7, %xmm5
movupd %xmm5, 0x18(%rax)
movapd %xmm2, %xmm5
addsd %xmm0, %xmm5
movsd %xmm5, 0x28(%rax)
subpd %xmm3, %xmm7
movupd %xmm7, 0x30(%rax)
subsd %xmm2, %xmm0
movsd %xmm0, 0x40(%rax)
subpd %xmm3, %xmm1
movupd %xmm1, 0x48(%rax)
subsd %xmm2, %xmm4
movsd %xmm4, 0x58(%rax)
addq $0x58, %rsp
popq %rbx
popq %r14
retq
nop