// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movaps %xmm0, 0x10(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
pushq $-0x1
popq %rax
movsd 0x1144a(%rip), %xmm1    # 0x1c200
xorl %ecx, %ecx
movapd 0x11490(%rip), %xmm0    # 0x1c250
cmpq $0x3, %rcx
je 0xade4
movsd (%r14,%rcx,8), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
cmoval %ecx, %eax
maxsd %xmm1, %xmm2
incq %rcx
movapd %xmm2, %xmm1
jmp 0xadc0
cmpl $-0x1, %eax
je 0xae08
leaq 0xff80(%rip), %rcx      # 0x1ad70
movsd (%rcx), %xmm2
movsd 0x8(%rcx), %xmm0
cmpl $0x2, %eax
jae 0xae2d
movsd 0x11252(%rip), %xmm1    # 0x1c058
jmp 0xae3c
leaq 0x1153f(%rip), %rdi     # 0x1c34e
xorl %eax, %eax
callq 0x8d7b
leaq 0xff53(%rip), %rax      # 0x1ad70
movsd (%rax), %xmm2
movsd 0x8(%rax), %xmm0
movsd 0x10(%rax), %xmm1
jmp 0xae3c
movsd 0x10(%rcx), %xmm1
jne 0xae3c
movsd 0x1121c(%rip), %xmm2    # 0x1c058
movsd (%r14), %xmm3
movsd 0x8(%r14), %xmm4
movapd %xmm0, %xmm5
mulsd %xmm4, %xmm5
movapd %xmm2, %xmm6
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movsd 0x10(%r14), %xmm5
movapd %xmm1, %xmm7
mulsd %xmm5, %xmm7
addsd %xmm6, %xmm7
mulsd %xmm7, %xmm3
subsd %xmm3, %xmm2
leaq 0x90(%rsp), %r15
movsd %xmm2, (%r15)
mulsd %xmm7, %xmm4
subsd %xmm4, %xmm0
movsd %xmm0, 0x8(%r15)
mulsd %xmm5, %xmm7
subsd %xmm7, %xmm1
movsd %xmm1, 0x10(%r15)
movq %r15, %rdi
callq 0xc2e9
movsd 0x10(%r14), %xmm0
movapd %xmm0, 0x40(%rsp)
mulsd 0x10(%rsp), %xmm0
movapd %xmm0, 0x80(%rsp)
movsd (%r15), %xmm0
movaps %xmm0, 0x30(%rsp)
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%r15), %xmm0
movapd %xmm0, 0x20(%rsp)
mulsd 0x1130d(%rip), %xmm0    # 0x1c1f8
movapd %xmm0, 0x70(%rsp)
movups 0x8(%r15), %xmm1
movaps %xmm1, 0x50(%rsp)
movsd %xmm0, 0x10(%r15)
movapd (%r15), %xmm0
mulpd 0x11352(%rip), %xmm0    # 0x1c260
movapd %xmm0, 0x60(%rsp)
pushq $0x60
popq %rdi
callq 0x4040
movupd (%r14), %xmm0
movapd 0x10(%rsp), %xmm7
unpcklpd %xmm7, %xmm7            # xmm7 = xmm7[0,0]
mulpd %xmm0, %xmm7
movapd 0x30(%rsp), %xmm3
movapd 0x20(%rsp), %xmm5
unpcklpd %xmm3, %xmm5            # xmm5 = xmm5[0],xmm3[0]
movapd %xmm0, %xmm1
movapd 0x40(%rsp), %xmm4
shufpd $0x1, %xmm4, %xmm1      # xmm1 = xmm1[1],xmm4[0]
unpcklpd %xmm0, %xmm4            # xmm4 = xmm4[0],xmm0[0]
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
mulpd %xmm5, %xmm1
mulpd 0x50(%rsp), %xmm4
subpd %xmm1, %xmm4
mulsd %xmm3, %xmm0
subsd %xmm2, %xmm0
movapd 0x60(%rsp), %xmm6
movhpd %xmm6, 0x8(%r15)
mulpd 0x112d6(%rip), %xmm4    # 0x1c260
mulsd 0x11266(%rip), %xmm0    # 0x1c1f8
movl $0x4, 0x8(%rbx)
movq %rax, 0x10(%rbx)
movapd %xmm7, %xmm1
subpd %xmm4, %xmm1
movapd 0x80(%rsp), %xmm8
movapd %xmm8, %xmm2
subsd %xmm0, %xmm2
movapd %xmm6, %xmm3
addpd %xmm1, %xmm3
movupd %xmm3, (%rax)
movapd 0x70(%rsp), %xmm5
movapd %xmm5, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x10(%rax)
addsd %xmm8, %xmm0
addpd %xmm7, %xmm4
movapd %xmm6, %xmm3
addpd %xmm4, %xmm3
movupd %xmm3, 0x18(%rax)
movapd %xmm5, %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, 0x28(%rax)
subpd %xmm6, %xmm4
movupd %xmm4, 0x30(%rax)
subsd %xmm5, %xmm0
movsd %xmm0, 0x40(%rax)
subpd %xmm6, %xmm1
movupd %xmm1, 0x48(%rax)
subsd %xmm5, %xmm2
movsd %xmm2, 0x58(%rax)
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop