// File: /workspace/github_cpp_makefile_star2_O1/FreeSlave[P]vhlt/common/winding.cpp
// Function: Winding::Clip(dplane_t const&, bool, double)
bool Winding::Clip(const dplane_t& split, bool keepon
#ifdef ZHLT_WINDING_EPSILON
				   , vec_t epsilon
#endif
				   )
{
    vec_t           dists[MAX_POINTS_ON_WINDING];
    int             sides[MAX_POINTS_ON_WINDING];
    int             counts[3];
    vec_t           dot;
    int             i, j;

    counts[0] = counts[1] = counts[2] = 0;

    // determine sides for each point
    // do this exactly, with no epsilon so tiny portals still work
    for (i = 0; i < m_NumPoints; i++)
    {
        dot = DotProduct(m_Points[i], split.normal);
        dot -= split.dist;
        dists[i] = dot;
        if (dot > ON_EPSILON)
        {
            sides[i] = SIDE_FRONT;
        }
#ifdef ZHLT_WINDING_FIX
        else if (dot < -ON_EPSILON)
#else
        else if (dot < ON_EPSILON)
#endif
        {
            sides[i] = SIDE_BACK;
        }
        else
        {
            sides[i] = SIDE_ON;
        }
        counts[sides[i]]++;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x658, %rsp            # imm = 0x658
movq %rsi, %r14
movq %rdi, %rbx
movl $0x0, 0xc(%rsp)
movq $0x0, 0x4(%rsp)
movl 0x8(%rdi), %r13d
testq %r13, %r13
je 0xd47a
movq 0x10(%rbx), %rax
cvtss2sd (%r14), %xmm7
cvtss2sd 0x4(%r14), %xmm1
cvtss2sd 0x8(%r14), %xmm2
cvtss2sd 0xc(%r14), %xmm3
movapd 0x11efe(%rip), %xmm4    # 0x1f300
xorpd %xmm0, %xmm4
addq $0x10, %rax
xorl %ecx, %ecx
movsd -0x8(%rax), %xmm5
mulsd %xmm1, %xmm5
movsd -0x10(%rax), %xmm6
mulsd %xmm7, %xmm6
addsd %xmm5, %xmm6
movsd (%rax), %xmm5
mulsd %xmm2, %xmm5
addsd %xmm6, %xmm5
subsd %xmm3, %xmm5
movsd %xmm5, 0x250(%rsp,%rcx,8)
ucomisd %xmm0, %xmm5
jbe 0xd44b
movl $0x0, 0x50(%rsp,%rcx,4)
jmp 0xd463
ucomisd %xmm5, %xmm4
jbe 0xd45b
movl $0x1, 0x50(%rsp,%rcx,4)
jmp 0xd463
movl $0x2, 0x50(%rsp,%rcx,4)
movslq 0x50(%rsp,%rcx,4), %rsi
incl 0x4(%rsp,%rsi,4)
incq %rcx
addq $0x18, %rax
cmpq %rcx, %r13
jne 0xd40c
jmp 0xd47c
xorl %ecx, %ecx
movl 0x50(%rsp), %eax
movl %eax, 0x50(%rsp,%rcx,4)
movsd 0x250(%rsp), %xmm1
movsd %xmm1, 0x250(%rsp,%rcx,8)
xorb $0x1, %dl
movl 0x4(%rsp), %esi
movl 0x8(%rsp), %ecx
testl %esi, %esi
setne %al
orb %dl, %al
testl %ecx, %ecx
setne %dl
orb %al, %dl
movb $0x1, %al
cmpb $0x1, %dl
jne 0xd6d5
testl %esi, %esi
je 0xd6b6
testl %ecx, %ecx
je 0xd6d5
leal 0x4(%r13), %eax
movq %rax, 0x28(%rsp)
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
movapd %xmm0, 0x10(%rsp)
callq 0x4040
movq %rax, %r15
xorl %ebp, %ebp
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x41c0
movapd 0x10(%rsp), %xmm0
testq %r13, %r13
je 0xd670
movq 0x10(%rbx), %rax
movss 0xc(%r14), %xmm1
movaps 0xeb71(%rip), %xmm2     # 0x1c090
xorps %xmm1, %xmm2
cvtss2sd %xmm2, %xmm7
cvtss2sd %xmm1, %xmm1
xorl %ecx, %ecx
movss 0xec04(%rip), %xmm2     # 0x1c138
movss 0x11df4(%rip), %xmm3    # 0x1f330
movq %rax, %rdx
xorl %esi, %esi
xorl %ebp, %ebp
leaq (%rsi,%rsi,2), %rdi
leaq (%rax,%rdi,8), %r8
movl 0x50(%rsp,%rsi,4), %edi
testl %edi, %edi
je 0xd581
cmpl $0x2, %edi
jne 0xd5af
movsd (%r8), %xmm4
movl %ebp, %edi
leaq (%rdi,%rdi,2), %rdi
movsd %xmm4, (%r15,%rdi,8)
movsd 0x8(%r8), %xmm4
movsd %xmm4, 0x8(%r15,%rdi,8)
movsd 0x10(%r8), %xmm4
jmp 0xd657
movsd (%r8), %xmm4
movl %ebp, %r9d
leaq (%r9,%r9,2), %r9
movsd %xmm4, (%r15,%r9,8)
movsd 0x8(%r8), %xmm4
movsd %xmm4, 0x8(%r15,%r9,8)
movsd 0x10(%r8), %xmm4
movsd %xmm4, 0x10(%r15,%r9,8)
incl %ebp
movl 0x54(%rsp,%rsi,4), %r8d
cmpl $0x2, %r8d
sete %r9b
cmpl %edi, %r8d
sete %dil
orb %r9b, %dil
jne 0xd660
leaq 0x1(%rsi), %rdi
cmpq %r13, %rdi
movl %edi, %edi
cmovaeq %rcx, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rax,%rdi,8), %rdi
movsd 0x250(%rsp,%rsi,8), %xmm4
movapd %xmm4, %xmm5
subsd 0x258(%rsp,%rsi,8), %xmm5
divsd %xmm5, %xmm4
xorl %r8d, %r8d
movss (%r14,%r8), %xmm6
ucomiss %xmm2, %xmm6
movaps %xmm1, %xmm5
jne 0xd60e
jnp 0xd630
ucomiss %xmm3, %xmm6
movaps %xmm7, %xmm5
jne 0xd618
jnp 0xd630
movsd (%rdx,%r8,2), %xmm6
movsd (%rdi,%r8,2), %xmm5
subsd %xmm6, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm6, %xmm5
movsd %xmm5, 0x30(%rsp,%r8,2)
addq $0x4, %r8
cmpq $0xc, %r8
jne 0xd5fe
movl %ebp, %edi
leaq (%rdi,%rdi,2), %rdi
movaps 0x30(%rsp), %xmm4
movups %xmm4, (%r15,%rdi,8)
movsd 0x40(%rsp), %xmm4
movsd %xmm4, 0x10(%r15,%rdi,8)
incl %ebp
incq %rsi
addq $0x18, %rdx
cmpq %r13, %rsi
jne 0xd543
cmpl 0x28(%rsp), %ebp
jbe 0xd68a
leaq 0x11dad(%rip), %rdi     # 0x1f42a
xorl %eax, %eax
callq 0xa2a0
movapd 0x10(%rsp), %xmm0
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0xd69e
callq 0x4420
movapd 0x10(%rsp), %xmm0
movq %r15, 0x10(%rbx)
movl %ebp, 0x8(%rbx)
movq %rbx, %rdi
callq 0xca9c
cmpl $0x0, 0x8(%rbx)
setne %al
jne 0xd6d5
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0xd6c4
callq 0x4420
movq $0x0, 0x10(%rbx)
movl $0x0, 0x8(%rbx)
xorl %eax, %eax
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop