// File: 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:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movsd %xmm0, 0x90(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movsd 0x1e34b(%rip), %xmm0    # 0x2d4a0
movsd %xmm0, 0x80(%rsp)
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x8c(%rsp)
cmpl $0x3, 0x8c(%rsp)
jge 0xf1e1
movq 0x98(%rsp), %rax
movslq 0x8c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x1e319(%rip), %xmm1    # 0x2d4b0
pand %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x78(%rsp), %xmm0
ucomisd 0x80(%rsp), %xmm0
jbe 0xf1cc
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movl 0x8c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0xf1ce
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0xf171
cmpl $-0x1, 0x1c(%rsp)
jne 0xf1f6
leaq 0x1e39f(%rip), %rdi     # 0x2d58e
movb $0x0, %al
callq 0xba80
leaq 0x1cc93(%rip), %rax     # 0x2be90
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
subl $0x2, %eax
jb 0xf237
jmp 0xf22c
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0xf247
jmp 0xf255
movsd 0x1df39(%rip), %xmm0    # 0x2d178
movsd %xmm0, 0x30(%rsp)
jmp 0xf255
movsd 0x1df29(%rip), %xmm0    # 0x2d178
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm1
movq 0x98(%rsp), %rax
movsd (%rax), %xmm2
movsd 0x28(%rsp), %xmm0
movq 0x98(%rsp), %rax
mulsd 0x8(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
movq 0x98(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x20(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x98(%rsp), %rax
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x98(%rsp), %rax
movsd 0x8(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm1
movsd 0x78(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq 0x98(%rsp), %rax
movsd 0x10(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x121b0
movq 0x10(%rsp), %rax
movq 0x98(%rsp), %rcx
movsd (%rcx), %xmm0
mulsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x98(%rsp), %rcx
movsd 0x8(%rcx), %xmm0
mulsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0x98(%rsp), %rcx
movsd 0x10(%rcx), %xmm0
mulsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x28(%rsp), %xmm0
movq 0x98(%rsp), %rcx
movsd 0x10(%rcx), %xmm2
movsd 0x30(%rsp), %xmm1
movq 0x98(%rsp), %rcx
mulsd 0x8(%rcx), %xmm1
movq %xmm1, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x30(%rsp), %xmm0
movq 0x98(%rsp), %rcx
movsd (%rcx), %xmm2
movsd 0x20(%rsp), %xmm1
movq 0x98(%rsp), %rcx
mulsd 0x10(%rcx), %xmm1
movq %xmm1, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x20(%rsp), %xmm0
movq 0x98(%rsp), %rcx
movsd 0x8(%rcx), %xmm2
movsd 0x28(%rsp), %xmm1
movq 0x98(%rsp), %rcx
mulsd (%rcx), %xmm1
movq %xmm1, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x1dff3(%rip), %xmm0    # 0x2d498
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x1dfdf(%rip), %xmm0    # 0x2d498
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x1dfcb(%rip), %xmm0    # 0x2d498
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x1dfb7(%rip), %xmm0    # 0x2d498
mulsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x1dfa3(%rip), %xmm0    # 0x2d498
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x1df8f(%rip), %xmm0    # 0x2d498
mulsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movl $0x4, 0x8(%rax)
movl 0x8(%rax), %eax
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movsd 0x60(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, (%rcx)
movsd 0x68(%rsp), %xmm0
subsd 0x48(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x8(%rcx)
movsd 0x70(%rsp), %xmm0
subsd 0x50(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x10(%rcx)
movq 0x10(%rax), %rcx
movsd (%rcx), %xmm0
addsd 0x20(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, (%rcx)
movq 0x10(%rax), %rcx
movsd 0x8(%rcx), %xmm0
addsd 0x28(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x8(%rcx)
movq 0x10(%rax), %rcx
movsd 0x10(%rcx), %xmm0
addsd 0x30(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x10(%rcx)
movsd 0x60(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x18(%rcx)
movsd 0x68(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x20(%rcx)
movsd 0x70(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x28(%rcx)
movq 0x10(%rax), %rcx
movsd 0x18(%rcx), %xmm0
addsd 0x20(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x18(%rcx)
movq 0x10(%rax), %rcx
movsd 0x20(%rcx), %xmm0
addsd 0x28(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x20(%rcx)
movq 0x10(%rax), %rcx
movsd 0x28(%rcx), %xmm0
addsd 0x30(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x28(%rcx)
movsd 0x60(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x30(%rcx)
movsd 0x68(%rsp), %xmm0
addsd 0x48(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x38(%rcx)
movsd 0x70(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x40(%rcx)
movq 0x10(%rax), %rcx
movsd 0x30(%rcx), %xmm0
subsd 0x20(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x30(%rcx)
movq 0x10(%rax), %rcx
movsd 0x38(%rcx), %xmm0
subsd 0x28(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x38(%rcx)
movq 0x10(%rax), %rcx
movsd 0x40(%rcx), %xmm0
subsd 0x30(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x40(%rcx)
movsd 0x60(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x48(%rcx)
movsd 0x68(%rsp), %xmm0
subsd 0x48(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x50(%rcx)
movsd 0x70(%rsp), %xmm0
subsd 0x50(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x58(%rcx)
movq 0x10(%rax), %rcx
movsd 0x48(%rcx), %xmm0
subsd 0x20(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x48(%rcx)
movq 0x10(%rax), %rcx
movsd 0x50(%rcx), %xmm0
subsd 0x28(%rsp), %xmm0
movq 0x10(%rax), %rcx
movsd %xmm0, 0x50(%rcx)
movq 0x10(%rax), %rcx
movsd 0x58(%rcx), %xmm0
subsd 0x30(%rsp), %xmm0
movq 0x10(%rax), %rax
movsd %xmm0, 0x58(%rax)
addq $0xa8, %rsp
retq
nopl (%rax)