// File: /workspace/github_cpp_makefile_star2_O2/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 $0x678, %rsp            # imm = 0x678
leaq 0x3c(%rsp), %rax
andl $0x0, (%rax)
leaq 0x8(%rsp), %rcx
andl $0x0, (%rcx)
leaq 0xc(%rsp), %r8
andl $0x0, (%r8)
movq %rsi, %r15
movq %rdi, %rbx
movl 0x8(%rdi), %ebp
movq 0x10(%rdi), %r14
cvtss2sd (%rsi), %xmm6
cvtss2sd 0x4(%rsi), %xmm1
cvtss2sd 0x8(%rsi), %xmm2
movss 0xc(%rsi), %xmm8
cvtss2sd %xmm8, %xmm7
movapd 0x10920(%rip), %xmm3    # 0x1c240
xorpd %xmm0, %xmm3
leaq 0x10(%r14), %rsi
xorl %edi, %edi
cmpq %rdi, %rbp
je 0xb998
movsd -0x8(%rsi), %xmm4
mulsd %xmm1, %xmm4
movsd -0x10(%rsi), %xmm5
mulsd %xmm6, %xmm5
addsd %xmm4, %xmm5
movsd (%rsi), %xmm4
mulsd %xmm2, %xmm4
addsd %xmm5, %xmm4
subsd %xmm7, %xmm4
movsd %xmm4, 0x270(%rsp,%rdi,8)
ucomisd %xmm0, %xmm4
jbe 0xb96e
andl $0x0, 0x70(%rsp,%rdi,4)
movq %r8, %r9
jmp 0xb98c
ucomisd %xmm4, %xmm3
jbe 0xb981
movl $0x1, 0x70(%rsp,%rdi,4)
movq %rcx, %r9
jmp 0xb98c
movl $0x2, 0x70(%rsp,%rdi,4)
movq %rax, %r9
incl (%r9)
incq %rdi
addq $0x18, %rsi
jmp 0xb92a
movl 0x70(%rsp), %eax
movl %eax, 0x70(%rsp,%rbp,4)
movsd 0x270(%rsp), %xmm1
movsd %xmm1, 0x270(%rsp,%rbp,8)
xorb $0x1, %dl
movl 0xc(%rsp), %edi
testl %edi, %edi
setne %sil
orb %dl, %sil
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
setne %dl
orb %sil, %dl
movb $0x1, %al
cmpb $0x1, %dl
jne 0xbbe8
testl %edi, %edi
je 0xbbd0
testl %ecx, %ecx
je 0xbbe8
leal 0x4(%rbp), %eax
movq %rax, 0x28(%rsp)
imulq $0x18, %rax, %r13
movq %r13, %rdi
movapd %xmm0, 0x10(%rsp)
movsd %xmm7, 0x30(%rsp)
movaps %xmm8, 0x40(%rsp)
callq 0x4040
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x41e0
xorl %r9d, %r9d
movsd 0x30(%rsp), %xmm7
movapd 0x10(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
xorps 0x10836(%rip), %xmm1    # 0x1c270
cvtss2sd %xmm1, %xmm6
movss 0xd61e(%rip), %xmm1     # 0x19064
movss 0x10832(%rip), %xmm2    # 0x1c280
xorl %ecx, %ecx
xorl %r13d, %r13d
cmpq %rbp, %rcx
je 0xbb82
movq %rcx, %rdx
imulq $0x18, %rcx, %rax
addq %r14, %rax
movl 0x70(%rsp,%rcx,4), %esi
movl %r13d, %ecx
testl %esi, %esi
je 0xbaa7
cmpl $0x2, %esi
jne 0xbad0
movsd (%rax), %xmm3
imulq $0x18, %rcx, %rcx
movsd %xmm3, (%r12,%rcx)
movsd 0x8(%rax), %xmm3
movsd %xmm3, 0x8(%r12,%rcx)
movsd 0x10(%rax), %xmm3
movsd %xmm3, 0x10(%r12,%rcx)
incl %r13d
incq %rdx
movq %rdx, %rcx
jmp 0xba53
movsd (%rax), %xmm3
imulq $0x18, %rcx, %rcx
movsd %xmm3, (%r12,%rcx)
movsd 0x8(%rax), %xmm3
movsd %xmm3, 0x8(%r12,%rcx)
movsd 0x10(%rax), %xmm3
movsd %xmm3, 0x10(%r12,%rcx)
incl %r13d
leaq 0x1(%rdx), %rcx
movl 0x74(%rsp,%rdx,4), %edi
cmpl $0x2, %edi
sete %r8b
cmpl %esi, %edi
sete %sil
orb %r8b, %sil
jne 0xba53
cmpq %rbp, %rcx
movl %ecx, %esi
cmovaeq %r9, %rsi
imulq $0x18, %rsi, %rsi
addq %r14, %rsi
movsd 0x270(%rsp,%rdx,8), %xmm3
movapd %xmm3, %xmm4
subsd 0x278(%rsp,%rdx,8), %xmm4
divsd %xmm4, %xmm3
xorl %edx, %edx
cmpq $0xc, %rdx
je 0xbb5c
movss (%r15,%rdx), %xmm5
ucomiss %xmm1, %xmm5
movaps %xmm7, %xmm4
jne 0xbb30
jnp 0xbb50
ucomiss %xmm2, %xmm5
movaps %xmm6, %xmm4
jne 0xbb3a
jnp 0xbb50
movsd (%rax,%rdx,2), %xmm5
movsd (%rsi,%rdx,2), %xmm4
subsd %xmm5, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm5, %xmm4
movsd %xmm4, 0x50(%rsp,%rdx,2)
addq $0x4, %rdx
jmp 0xbb1a
movl %r13d, %eax
imulq $0x18, %rax, %rax
movaps 0x50(%rsp), %xmm3
movups %xmm3, (%r12,%rax)
movsd 0x60(%rsp), %xmm3
movsd %xmm3, 0x10(%r12,%rax)
incl %r13d
jmp 0xba53
cmpl 0x28(%rsp), %r13d
jbe 0xbba1
leaq 0x107ea(%rip), %rdi     # 0x1c37a
xorl %eax, %eax
callq 0x8d7b
movapd 0x10(%rsp), %xmm0
movq 0x10(%rbx), %r14
testq %r14, %r14
je 0xbbb4
movq %r14, %rdi
callq 0x4430
movapd 0x10(%rsp), %xmm0
movq %r12, 0x10(%rbx)
movl %r13d, 0x8(%rbx)
movq %rbx, %rdi
callq 0xb10a
cmpl $0x0, 0x8(%rbx)
movb $0x1, %al
jne 0xbbe8
movq 0x10(%rbx), %r14
testq %r14, %r14
je 0xbbdd
movq %r14, %rdi
callq 0x4430
andq $0x0, 0x10(%rbx)
andl $0x0, 0x8(%rbx)
xorl %eax, %eax
addq $0x678, %rsp            # imm = 0x678
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq