// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/hlvis/flow.cpp
// Function: ClipToSeperators(winding_t const*, winding_t const*, winding_t*, bool, pstack_s*)
inline static winding_t* ClipToSeperators(
    const winding_t* const source,
    const winding_t* const pass, 
    winding_t* const a_target,
    const bool flipclip, 
    pstack_t* const stack)
{
    int             i, j, k, l;
    plane_t         plane;
    vec3_t          v1, v2;
    float           d;
    int             counts[3];
    bool            fliptest;
    winding_t*      target = a_target;

    const unsigned int numpoints = source->numpoints;

    // check all combinations       
    for (i=0, l=1; i < numpoints; i++, l++)
    {
        if (l == numpoints)
        {
            l = 0;
        }

        VectorSubtract(source->points[l], source->points[i], v1);

        // fing a vertex of pass that makes a plane that puts all of the
        // vertexes of pass on the front side and all of the vertexes of
        // source on the back side
        for (j = 0; j < pass->numpoints; j++)
        {
            VectorSubtract(pass->points[j], source->points[i], v2);
            CrossProduct(v1, v2, plane.normal);
            if (VectorNormalize(plane.normal) < ON_EPSILON)
            {
                continue;
            }
            plane.dist = DotProduct(pass->points[j], plane.normal);

            // find out which side of the generated seperating plane has the
            // source portal
            fliptest = false;
            for (k = 0; k < numpoints; k++)
            {
                if ((k == i) | (k == l)) // | instead of || for branch optimization
                {
                    continue;
                }
                d = DotProduct(source->points[k], plane.normal) - plane.dist;
                if (d < -ON_EPSILON)
                {                                          // source is on the negative side, so we want all
                    // pass and target on the positive side
                    fliptest = false;
                    break;
                }
                else if (d > ON_EPSILON)
                {                                          // source is on the positive side, so we want all
                    // pass and target on the negative side
                    fliptest = true;
                    break;
                }
            }
            if (k == numpoints)
            {
                continue;                                  // planar with source portal
            }

            // flip the normal if the source portal is backwards
            if (fliptest)
            {
                VectorSubtract(vec3_origin, plane.normal, plane.normal);
                plane.dist = -plane.dist;
            }

            // if all of the pass portal points are now on the positive side,
            // this is the seperating plane
            counts[0] = counts[1] = counts[2] = 0;
            for (k = 0; k < pass->numpoints; k++)
            {
                if (k == j)
                {
                    continue;
                }
                d = DotProduct(pass->points[k], plane.normal) - plane.dist;
                if (d < -ON_EPSILON)
                {
                    break;
                }
                else if (d > ON_EPSILON)
                {
                    counts[0]++;
                }
                else
                {
                    counts[2]++;
                }
            }
            if (k != pass->numpoints)
            {
                continue;                                  // points on negative side, not a seperating plane
            }

            if (!counts[0])
            {
                continue;                                  // planar with seperating plane
            }

            // flip the normal if we want the back side
            if (flipclip)
            {
                VectorSubtract(vec3_origin, plane.normal, plane.normal);
                plane.dist = -plane.dist;
            }

	    if (target != NULL)
	    {
            // clip target by the seperating plane
            target = ChopWinding(target, stack, &plane);
            if (!target)
            {
                return NULL;                               // target is not visible
            }
	    }
	    else
	    {
        	AddPlane(stack, &plane);
	    }

#ifdef RVIS_LEVEL_1
            break; /* Antony was here */
#endif
        }
    }

    return target;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, 0x28(%rsp)
movl %ecx, 0x34(%rsp)
movq %rdx, 0x18(%rsp)
movl 0x4(%rdi), %r12d
testq %r12, %r12
je 0xefc5
leaq 0x8(%rdi), %rax
movq %rax, 0x48(%rsp)
leaq 0x8(%rsi), %r9
leaq 0x534c(%rip), %rax      # 0x13e00
movsd (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movss 0x8(%rax), %xmm0
movss %xmm0, 0x24(%rsp)
addq $0x10, %rdi
movq %rdi, 0x58(%rsp)
leaq 0x10(%rsi), %rax
movq %rax, 0x50(%rsp)
movl $0x1, %eax
movsd 0x69a1(%rip), %xmm6     # 0x15488
movsd 0x69a1(%rip), %xmm7     # 0x15490
xorl %ebp, %ebp
movq %rsi, 0x40(%rsp)
movq %r9, 0x38(%rsp)
cmpl %r12d, %eax
movl $0x0, %ecx
cmovel %ecx, %eax
cmpl $0x0, 0x4(%rsi)
jle 0xee32
movl %eax, 0x14(%rsp)
cltq
leaq (%rax,%rax,2), %rcx
movq 0x48(%rsp), %rdi
movss (%rdi,%rcx,4), %xmm8
leaq (%rbp,%rbp,2), %rdx
leaq (%rdi,%rdx,4), %r15
subss (%r15), %xmm8
movsd 0x4(%rdi,%rcx,4), %xmm9
movsd 0x4(%r15), %xmm0
subps %xmm0, %xmm9
movaps %xmm8, %xmm10
shufps $0xd4, %xmm9, %xmm10    # xmm10 = xmm10[0,1],xmm9[1,3]
shufps $0x52, %xmm9, %xmm10    # xmm10 = xmm10[2,0],xmm9[1,1]
movaps 0x3537(%rip), %xmm0     # 0x12090
xorps %xmm0, %xmm10
movaps %xmm9, %xmm11
xorps %xmm0, %xmm11
movl %eax, %r13d
xorl %r14d, %r14d
movaps %xmm8, 0xa0(%rsp)
movaps %xmm9, 0x90(%rsp)
movaps %xmm10, 0x80(%rsp)
movaps %xmm11, 0x70(%rsp)
leaq (%r14,%r14,2), %rbx
movss 0x4(%r9,%rbx,4), %xmm0
subss 0x4(%r15), %xmm0
movss (%r9,%rbx,4), %xmm1
movss 0x8(%r9,%rbx,4), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
movss (%r15), %xmm1
movss 0x8(%r15), %xmm3
unpcklps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subps %xmm3, %xmm2
movaps %xmm2, %xmm1
shufps $0x0, %xmm2, %xmm1      # xmm1 = xmm1[0,0],xmm2[0,0]
movss %xmm0, %xmm1            # xmm1 = xmm0[0],xmm1[1,2,3]
mulps %xmm10, %xmm1
movaps %xmm9, %xmm3
mulps %xmm2, %xmm3
addps %xmm1, %xmm3
movlps %xmm3, (%rsp)
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
mulss %xmm11, %xmm2
mulss %xmm8, %xmm0
addss %xmm2, %xmm0
movss %xmm0, 0x8(%rsp)
movaps %xmm3, %xmm1
mulps %xmm3, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
mulss %xmm3, %xmm3
addss %xmm1, %xmm3
mulss %xmm0, %xmm0
addss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x6677(%rip), %xmm0     # 0x15290
jb 0xec21
sqrtsd %xmm0, %xmm0
jmp 0xec61
callq 0x31a0
movaps 0x70(%rsp), %xmm11
movaps 0x80(%rsp), %xmm10
movaps 0x90(%rsp), %xmm9
movaps 0xa0(%rsp), %xmm8
movsd 0x6841(%rip), %xmm7     # 0x15490
movsd 0x6831(%rip), %xmm6     # 0x15488
movq 0x38(%rsp), %r9
movq 0x40(%rsp), %rsi
movsd 0x34a7(%rip), %xmm1     # 0x12110
ucomisd %xmm0, %xmm1
jbe 0xec84
movl $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
jmp 0xee1e
cvtps2pd (%rsp), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
divpd %xmm2, %xmm1
cvtpd2ps %xmm1, %xmm1
movlpd %xmm1, (%rsp)
xorps %xmm1, %xmm1
cvtss2sd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm0
movss %xmm1, 0x8(%rsp)
cvtss2sd %xmm0, %xmm0
ucomisd %xmm0, %xmm6
ja 0xee1e
leaq (%r9,%rbx,4), %rax
movsd (%rsp), %xmm0
movaps %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm3     # xmm3 = xmm3[1,1],xmm0[1,1]
movaps %xmm3, %xmm1
mulss 0x4(%rax), %xmm1
movss (%rax), %xmm4
mulss %xmm0, %xmm4
addss %xmm1, %xmm4
movss 0x8(%rsp), %xmm2
movss 0x8(%rax), %xmm1
mulss %xmm2, %xmm1
addss %xmm4, %xmm1
movss %xmm1, 0xc(%rsp)
movq 0x58(%rsp), %rcx
xorl %eax, %eax
cmpq %rax, %rbp
je 0xed4a
cmpq %rax, %r13
je 0xed4a
movss -0x4(%rcx), %xmm4
mulss %xmm3, %xmm4
movss -0x8(%rcx), %xmm5
mulss %xmm0, %xmm5
addss %xmm4, %xmm5
movss (%rcx), %xmm4
mulss %xmm2, %xmm4
addss %xmm5, %xmm4
subss %xmm1, %xmm4
cvtss2sd %xmm4, %xmm4
ucomisd %xmm4, %xmm7
ja 0xed5d
ucomisd %xmm6, %xmm4
ja 0xed61
incq %rax
addq $0xc, %rcx
cmpq %rax, %r12
jne 0xed0a
xorl %ecx, %ecx
movl %r12d, %eax
jmp 0xed63
xorl %ecx, %ecx
jmp 0xed63
movb $0x1, %cl
cmpl %r12d, %eax
je 0xee1e
testb %cl, %cl
je 0xed99
movaps 0x60(%rsp), %xmm3
subps %xmm0, %xmm3
movlps %xmm3, (%rsp)
movss 0x24(%rsp), %xmm0
subss %xmm2, %xmm0
movss %xmm0, 0x8(%rsp)
xorps 0x32fd(%rip), %xmm1     # 0x12090
movss %xmm1, 0xc(%rsp)
movl 0x4(%rsi), %eax
testl %eax, %eax
jle 0xee12
movss (%rsp), %xmm0
movss 0x4(%rsp), %xmm1
movss 0x8(%rsp), %xmm2
movss 0xc(%rsp), %xmm3
xorl %ecx, %ecx
movq 0x50(%rsp), %rdi
xorl %edx, %edx
cmpq %rcx, %r14
je 0xedfd
movss -0x4(%rdi), %xmm4
mulss %xmm1, %xmm4
movss -0x8(%rdi), %xmm5
mulss %xmm0, %xmm5
addss %xmm4, %xmm5
movss (%rdi), %xmm4
mulss %xmm2, %xmm4
addss %xmm5, %xmm4
subss %xmm3, %xmm4
cvtss2sd %xmm4, %xmm4
ucomisd %xmm4, %xmm7
ja 0xee0b
ucomisd %xmm6, %xmm4
jbe 0xedfd
incl %edx
incq %rcx
addq $0xc, %rdi
cmpq %rcx, %rax
jne 0xedc0
movl %eax, %ecx
testl %edx, %edx
setne %dl
jmp 0xee16
xorl %ecx, %ecx
xorl %edx, %edx
cmpl %eax, %ecx
jne 0xee1e
testb %dl, %dl
jne 0xee45
incq %r14
movslq 0x4(%rsi), %rax
cmpq %rax, %r14
jl 0xeb8c
movl 0x14(%rsp), %eax
incq %rbp
incl %eax
cmpq %r12, %rbp
jne 0xeafb
jmp 0xefc5
cmpb $0x0, 0x34(%rsp)
je 0xee82
movsd (%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
subps %xmm0, %xmm1
movlps %xmm1, (%rsp)
movss 0x24(%rsp), %xmm0
subss 0x8(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movss 0xc(%rsp), %xmm0
xorps 0x3214(%rip), %xmm0     # 0x12090
movss %xmm0, 0xc(%rsp)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xeeca
movq 0x28(%rsp), %rsi
movq %rsp, %rdx
callq 0xefdc
movsd 0x65ef(%rip), %xmm7     # 0x15490
movsd 0x65df(%rip), %xmm6     # 0x15488
movq 0x38(%rsp), %r9
movq 0x40(%rsp), %rsi
movq %rax, 0x18(%rsp)
testq %rax, %rax
movl 0x14(%rsp), %eax
jne 0xee32
jmp 0xefbc
movq 0x28(%rsp), %rax
movslq 0x14d0(%rax), %rax
testq %rax, %rax
jle 0xef90
movq 0x28(%rsp), %rcx
movq 0x14d8(%rcx), %rcx
movss (%rsp), %xmm0
movss 0xc(%rsp), %xmm1
leaq 0x4(%rcx), %rdx
xorl %r8d, %r8d
movq %r8, %rdi
shlq $0x4, %rdi
movss 0xc(%rcx,%rdi), %xmm2
subss %xmm1, %xmm2
andps 0x63bb(%rip), %xmm2     # 0x152d0
cvtss2sd %xmm2, %xmm2
movsd 0x655f(%rip), %xmm3     # 0x15480
ucomisd %xmm2, %xmm3
jb 0xef80
movss (%rcx,%rdi), %xmm2
subss %xmm0, %xmm2
andps 0x6399(%rip), %xmm2     # 0x152d0
cvtss2sd %xmm2, %xmm2
ucomisd 0x653d(%rip), %xmm2     # 0x15480
ja 0xef80
xorl %edi, %edi
cmpq $0x2, %rdi
je 0xef75
movss (%rdx,%rdi,4), %xmm2
subss 0x4(%rsp,%rdi,4), %xmm2
andps 0x6371(%rip), %xmm2     # 0x152d0
cvtss2sd %xmm2, %xmm2
incq %rdi
ucomisd 0x6512(%rip), %xmm2     # 0x15480
jbe 0xef47
decq %rdi
jmp 0xef7a
movl $0x2, %edi
cmpq $0x1, %rdi
ja 0xefae
incq %r8
addq $0x10, %rdx
cmpq %rax, %r8
jne 0xeefd
movq 0x28(%rsp), %rdx
movq 0x14d8(%rdx), %rcx
shlq $0x4, %rax
movups (%rsp), %xmm0
movups %xmm0, (%rcx,%rax)
incl 0x14d0(%rdx)
movq $0x0, 0x18(%rsp)
jmp 0xee2e
movq $0x0, 0x18(%rsp)
movq 0x18(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq