// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, %rbx
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movl %eax, 0x4(%rsp)
movl %eax, 0x8(%rsp)
movl 0x8(%rdi), %r13d
testq %r13, %r13
je 0xd4b0
movq %rsi, %r14
cvtss2sd (%rsi), %xmm7
cvtss2sd 0x4(%rsi), %xmm1
cvtss2sd 0x8(%rsi), %xmm2
cvtss2sd 0xc(%rsi), %xmm3
movq 0x10(%rbx), %rax
movapd 0x120fb(%rip), %xmm4    # 0x1f2e0
xorpd %xmm0, %xmm4
addq $0x10, %rax
xorl %ecx, %ecx
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdi
leaq 0xc(%rsp), %r8
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 0xd240
movl $0x0, 0x50(%rsp,%rcx,4)
movq %rsi, %r9
jmp 0xd25e
ucomisd %xmm5, %xmm4
jbe 0xd253
movl $0x1, 0x50(%rsp,%rcx,4)
movq %rdi, %r9
jmp 0xd25e
movl $0x2, 0x50(%rsp,%rcx,4)
movq %r8, %r9
incl (%r9)
incq %rcx
addq $0x18, %rax
cmpq %rcx, %r13
jne 0xd1fe
movl 0x50(%rsp), %esi
movsd 0x250(%rsp), %xmm1
movl 0x8(%rsp), %ecx
movl 0x4(%rsp), %r9d
testl %ecx, %ecx
setne %dil
testl %r9d, %r9d
setne %r8b
movl %esi, 0x50(%rsp,%r13,4)
movsd %xmm1, 0x250(%rsp,%r13,8)
xorb $0x1, %dl
orb %dil, %dl
orb %r8b, %dl
movb $0x1, %al
je 0xd4d5
testl %ecx, %ecx
je 0xd4b6
testl %r9d, %r9d
je 0xd4d5
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 0xd483
movq 0x10(%rbx), %rax
movss 0xc(%r14), %xmm1
movaps 0xed6a(%rip), %xmm2     # 0x1c080
xorps %xmm1, %xmm2
cvtss2sd %xmm2, %xmm7
cvtss2sd %xmm1, %xmm1
xorl %ecx, %ecx
movss 0xed79(%rip), %xmm2     # 0x1c0a4
movss 0x11fdd(%rip), %xmm3    # 0x1f310
xorl %edi, %edi
xorl %ebp, %ebp
leaq (%rdi,%rdi,2), %rdx
leaq (%rax,%rdx,8), %rdx
movl 0x50(%rsp,%rdi,4), %r8d
testl %r8d, %r8d
je 0xd384
cmpl $0x2, %r8d
jne 0xd3ae
movsd (%rdx), %xmm4
movl %ebp, %esi
leaq (%rsi,%rsi,2), %rsi
movsd %xmm4, (%r15,%rsi,8)
movsd 0x8(%rdx), %xmm4
movsd %xmm4, 0x8(%r15,%rsi,8)
movsd 0x10(%rdx), %xmm4
movsd %xmm4, 0x10(%r15,%rsi,8)
incl %ebp
incq %rdi
movq %rdi, %rsi
jmp 0xd45d
movsd (%rdx), %xmm4
movl %ebp, %esi
leaq (%rsi,%rsi,2), %rsi
movsd %xmm4, (%r15,%rsi,8)
movsd 0x8(%rdx), %xmm4
movsd %xmm4, 0x8(%r15,%rsi,8)
movsd 0x10(%rdx), %xmm4
movsd %xmm4, 0x10(%r15,%rsi,8)
incl %ebp
leaq 0x1(%rdi), %rsi
movl 0x54(%rsp,%rdi,4), %r9d
cmpl $0x2, %r9d
sete %r10b
cmpl %r8d, %r9d
sete %r8b
orb %r10b, %r8b
jne 0xd45d
cmpq %r13, %rsi
movl %esi, %r8d
cmovaeq %rcx, %r8
leaq (%r8,%r8,2), %r8
leaq (%rax,%r8,8), %r8
movsd 0x250(%rsp,%rdi,8), %xmm4
movapd %xmm4, %xmm5
subsd 0x258(%rsp,%rdi,8), %xmm5
divsd %xmm5, %xmm4
xorl %edi, %edi
movss (%r14,%rdi), %xmm6
ucomiss %xmm2, %xmm6
movaps %xmm1, %xmm5
jne 0xd40d
jnp 0xd42e
ucomiss %xmm3, %xmm6
movaps %xmm7, %xmm5
jne 0xd417
jnp 0xd42e
movsd (%rdx,%rdi,2), %xmm6
movsd (%r8,%rdi,2), %xmm5
subsd %xmm6, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm6, %xmm5
movsd %xmm5, 0x30(%rsp,%rdi,2)
addq $0x4, %rdi
cmpq $0xc, %rdi
jne 0xd3fd
movl %ebp, %edx
leaq (%rdx,%rdx,2), %rdx
movaps 0x30(%rsp), %xmm4
movups %xmm4, (%r15,%rdx,8)
movsd 0x40(%rsp), %xmm4
movsd %xmm4, 0x10(%r15,%rdx,8)
incl %ebp
movq %rsi, %rdi
cmpq %r13, %rsi
jne 0xd337
cmpl 0x28(%rsp), %ebp
jbe 0xd483
leaq 0x11f94(%rip), %rdi     # 0x1f40a
xorl %eax, %eax
callq 0xa164
movapd 0x10(%rsp), %xmm0
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0xd497
callq 0x4410
movapd 0x10(%rsp), %xmm0
movq %r15, 0x10(%rbx)
movl %ebp, 0x8(%rbx)
movq %rbx, %rdi
callq 0xc87a
cmpl $0x0, 0x8(%rbx)
movb $0x1, %al
jne 0xd4d5
jmp 0xd4b6
movb $0x1, %al
testb %dl, %dl
jne 0xd4d5
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0xd4c4
callq 0x4410
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