// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
movaps %xmm0, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movsd 0x12bb5(%rip), %xmm1    # 0x1f2b8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %eax, %eax
movapd 0x12bfe(%rip), %xmm0    # 0x1f310
movsd (%r14,%rax,8), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
cmoval %eax, %ebp
maxsd %xmm1, %xmm2
incq %rax
movapd %xmm2, %xmm1
cmpq $0x3, %rax
jne 0xc712
cmpl $-0x1, %ebp
jne 0xc747
leaq 0x12cbe(%rip), %rdi     # 0x1f3fe
xorl %eax, %eax
callq 0xa2a0
leaq 0x116c2(%rip), %rax     # 0x1de10
movsd (%rax), %xmm6
movsd 0x8(%rax), %xmm5
cmpl $0x2, %ebp
jae 0xc766
movsd 0x12994(%rip), %xmm0    # 0x1f0f8
jmp 0xc775
movsd 0x10(%rax), %xmm0
jne 0xc775
movsd 0x12983(%rip), %xmm6    # 0x1f0f8
movsd (%r14), %xmm1
movupd 0x8(%r14), %xmm2
movapd %xmm5, %xmm3
mulsd %xmm2, %xmm3
movapd %xmm6, %xmm4
mulsd %xmm1, %xmm4
addsd %xmm3, %xmm4
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
mulsd %xmm0, %xmm3
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm1
subsd %xmm1, %xmm6
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
unpcklpd %xmm0, %xmm5            # xmm5 = xmm5[0],xmm0[0]
mulpd %xmm2, %xmm3
subpd %xmm3, %xmm5
movapd %xmm5, %xmm0
mulsd %xmm5, %xmm0
movapd %xmm6, %xmm1
mulsd %xmm6, %xmm1
addsd %xmm0, %xmm1
movapd %xmm5, %xmm0
unpckhpd %xmm5, %xmm0            # xmm0 = xmm0[1],xmm5[1]
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
jb 0xc7f0
sqrtsd %xmm0, %xmm0
jmp 0xc80f
movapd %xmm5, 0x10(%rsp)
movsd %xmm6, (%rsp)
callq 0x4260
movsd (%rsp), %xmm6
movapd 0x10(%rsp), %xmm5
xorpd %xmm3, %xmm3
movsd 0xf8f9(%rip), %xmm1     # 0x1c110
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %cl
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
divpd %xmm1, %xmm5
ja 0xc836
divsd %xmm0, %xmm6
movapd %xmm6, %xmm3
movb %cl, %al
movd %eax, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
pslld $0x1f, %xmm0
psrad $0x1f, %xmm0
pandn %xmm5, %xmm0
movapd 0x20(%rsp), %xmm6
movapd %xmm6, %xmm2
unpcklpd %xmm6, %xmm2            # xmm2 = xmm2[0],xmm6[0]
movupd (%r14), %xmm4
movupd 0x8(%r14), %xmm1
mulpd %xmm4, %xmm2
movapd %xmm2, 0x10(%rsp)
movsd 0x10(%r14), %xmm5
mulsd %xmm5, %xmm6
movapd %xmm6, 0x20(%rsp)
pshufd $0xee, %xmm0, %xmm6     # xmm6 = xmm0[2,3,2,3]
movdqa %xmm0, %xmm2
shufpd $0x1, %xmm3, %xmm2      # xmm2 = xmm2[1],xmm3[0]
mulpd %xmm1, %xmm2
unpcklpd %xmm4, %xmm5            # xmm5 = xmm5[0],xmm4[0]
mulpd %xmm0, %xmm5
subpd %xmm2, %xmm5
movapd %xmm4, %xmm2
movapd %xmm4, %xmm1
mulsd %xmm0, %xmm1
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
mulsd %xmm3, %xmm2
subsd %xmm1, %xmm2
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
movapd 0x12a5c(%rip), %xmm0    # 0x1f320
mulpd %xmm0, %xmm3
movapd %xmm3, 0x30(%rsp)
movsd 0x129d2(%rip), %xmm1    # 0x1f2a8
mulsd %xmm1, %xmm6
movapd %xmm6, (%rsp)
mulpd %xmm0, %xmm5
movapd %xmm5, 0x50(%rsp)
mulsd %xmm1, %xmm2
movapd %xmm2, 0x40(%rsp)
movl $0x4, 0x8(%rbx)
movl $0x60, %edi
callq 0x4040
movq %rax, 0x10(%rbx)
movapd 0x10(%rsp), %xmm4
movapd %xmm4, %xmm0
movapd 0x50(%rsp), %xmm5
subpd %xmm5, %xmm0
movapd 0x20(%rsp), %xmm6
movapd %xmm6, %xmm1
movapd 0x40(%rsp), %xmm7
subsd %xmm7, %xmm1
movapd 0x30(%rsp), %xmm8
movapd %xmm8, %xmm2
addpd %xmm0, %xmm2
movupd %xmm2, (%rax)
movapd (%rsp), %xmm3
movapd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rax)
addsd %xmm6, %xmm7
movapd %xmm3, %xmm2
addsd %xmm7, %xmm2
movsd %xmm2, 0x28(%rax)
addpd %xmm4, %xmm5
movapd %xmm8, %xmm2
addpd %xmm5, %xmm2
movupd %xmm2, 0x18(%rax)
subpd %xmm8, %xmm5
movupd %xmm5, 0x30(%rax)
subsd %xmm3, %xmm7
movsd %xmm7, 0x40(%rax)
subpd %xmm8, %xmm0
movupd %xmm0, 0x48(%rax)
subsd %xmm3, %xmm1
movsd %xmm1, 0x58(%rax)
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq