// File: 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:
subq $0x6a8, %rsp            # imm = 0x6A8
movb %dl, %al
movq %rdi, 0x698(%rsp)
movq %rsi, 0x690(%rsp)
andb $0x1, %al
movb %al, 0x68f(%rsp)
movsd %xmm0, 0x680(%rsp)
movq 0x698(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x7c(%rsp)
movl $0x0, 0x78(%rsp)
movl $0x0, 0x74(%rsp)
movl $0x0, 0x64(%rsp)
movq 0x18(%rsp), %rcx
movl 0x64(%rsp), %eax
cmpl 0x8(%rcx), %eax
jae 0x10d59
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rcx
movslq 0x64(%rsp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movsd (%rcx), %xmm1
movq 0x690(%rsp), %rcx
movss (%rcx), %xmm0
cvtss2sd %xmm0, %xmm2
movq 0x10(%rax), %rcx
movslq 0x64(%rsp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movsd 0x8(%rcx), %xmm0
movq 0x690(%rsp), %rcx
movss 0x4(%rcx), %xmm3
cvtss2sd %xmm3, %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x10(%rax), %rax
movslq 0x64(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movq 0x690(%rsp), %rax
movss 0x8(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0x690(%rsp), %rax
movss 0xc(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x68(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
movslq 0x64(%rsp), %rax
movsd %xmm0, 0x280(%rsp,%rax,8)
movsd 0x68(%rsp), %xmm0
ucomisd 0x680(%rsp), %xmm0
jbe 0x10ce1
movslq 0x64(%rsp), %rax
movl $0x0, 0x80(%rsp,%rax,4)
jmp 0x10d31
movsd 0x68(%rsp), %xmm1
movsd 0x680(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x10d1f
movslq 0x64(%rsp), %rax
movl $0x1, 0x80(%rsp,%rax,4)
jmp 0x10d2f
movslq 0x64(%rsp), %rax
movl $0x2, 0x80(%rsp,%rax,4)
jmp 0x10d31
movslq 0x64(%rsp), %rax
movslq 0x80(%rsp,%rax,4), %rax
movl 0x74(%rsp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, 0x74(%rsp,%rax,4)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x10be8
movl 0x80(%rsp), %ecx
movslq 0x64(%rsp), %rax
movl %ecx, 0x80(%rsp,%rax,4)
movsd 0x280(%rsp), %xmm0
movslq 0x64(%rsp), %rax
movsd %xmm0, 0x280(%rsp,%rax,8)
testb $0x1, 0x68f(%rsp)
je 0x10da8
cmpl $0x0, 0x74(%rsp)
jne 0x10da8
cmpl $0x0, 0x78(%rsp)
jne 0x10da8
movb $0x1, 0x6a7(%rsp)
jmp 0x11230
cmpl $0x0, 0x74(%rsp)
jne 0x10dee
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x10dcd
movq 0x10(%rsp), %rdi
callq 0x44f0
movq 0x18(%rsp), %rax
movq $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movb $0x0, 0x6a7(%rsp)
jmp 0x11230
cmpl $0x0, 0x78(%rsp)
jne 0x10e02
movb $0x1, 0x6a7(%rsp)
jmp 0x11230
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x4, %eax
movl %eax, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x5c(%rsp), %eax
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
movl 0x5c(%rsp), %eax
imulq $0x18, %rax, %rdx
xorl %esi, %esi
callq 0x4210
movl $0x0, 0x64(%rsp)
movq 0x18(%rsp), %rcx
movl 0x64(%rsp), %eax
cmpl 0x8(%rcx), %eax
jae 0x1118a
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x64(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
movslq 0x64(%rsp), %rax
cmpl $0x2, 0x80(%rsp,%rax,4)
jne 0x10f05
movq 0x48(%rsp), %rax
movsd (%rax), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq 0x48(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq 0x48(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x1117a
movslq 0x64(%rsp), %rax
cmpl $0x0, 0x80(%rsp,%rax,4)
jne 0x10f7a
movq 0x48(%rsp), %rax
movsd (%rax), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movq 0x48(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq 0x48(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x10f7c
movl 0x64(%rsp), %eax
addl $0x1, %eax
cltq
cmpl $0x2, 0x80(%rsp,%rax,4)
je 0x10fad
movl 0x64(%rsp), %eax
addl $0x1, %eax
cltq
movl 0x80(%rsp,%rax,4), %eax
movslq 0x64(%rsp), %rcx
cmpl 0x80(%rsp,%rcx,4), %eax
jne 0x10fb2
jmp 0x1117a
movq 0x18(%rsp), %rcx
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x8(%rcx), %eax
jb 0x10fd3
movl $0x0, 0x2c(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl 0x2c(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movslq 0x64(%rsp), %rax
movsd 0x280(%rsp,%rax,8), %xmm0
movslq 0x64(%rsp), %rax
movsd 0x280(%rsp,%rax,8), %xmm1
movl 0x64(%rsp), %eax
addl $0x1, %eax
cltq
subsd 0x280(%rsp,%rax,8), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rsp)
movl $0x0, 0x60(%rsp)
cmpl $0x3, 0x60(%rsp)
jge 0x1111f
movq 0x690(%rsp), %rax
movslq 0x60(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x18ffb(%rip), %xmm1    # 0x2a04c
ucomiss %xmm1, %xmm0
jne 0x11079
jp 0x11079
movq 0x690(%rsp), %rax
movss 0xc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x60(%rsp), %rax
movsd %xmm0, 0x30(%rsp,%rax,8)
jmp 0x1110d
movq 0x690(%rsp), %rax
movslq 0x60(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x1c42d(%rip), %xmm1    # 0x2d4c0
ucomiss %xmm1, %xmm0
jne 0x110c5
jp 0x110c5
movq 0x690(%rsp), %rax
movss 0xc(%rax), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movslq 0x60(%rsp), %rax
movsd %xmm0, 0x30(%rsp,%rax,8)
jmp 0x1110b
movq 0x48(%rsp), %rax
movslq 0x60(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x68(%rsp), %xmm0
movq 0x20(%rsp), %rax
movslq 0x60(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq 0x48(%rsp), %rax
movslq 0x60(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movslq 0x60(%rsp), %rax
movsd %xmm0, 0x30(%rsp,%rax,8)
jmp 0x1110d
jmp 0x1110f
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x1102c
movsd 0x30(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movsd 0x38(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movsd 0x40(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x10e5f
movl 0x58(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jbe 0x111a2
leaq 0x1c41f(%rip), %rdi     # 0x2d5ba
movb $0x0, %al
callq 0xba80
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x111c0
movq 0x8(%rsp), %rdi
callq 0x44f0
movq 0x18(%rsp), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rdi)
movl 0x58(%rsp), %eax
movl %eax, 0x8(%rdi)
movsd 0x680(%rsp), %xmm0
callq 0xf930
movq 0x18(%rsp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x11228
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x1120a
movq (%rsp), %rdi
callq 0x44f0
movq 0x18(%rsp), %rax
movq $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movb $0x0, 0x6a7(%rsp)
jmp 0x11230
movb $0x1, 0x6a7(%rsp)
movb 0x6a7(%rsp), %al
andb $0x1, %al
addq $0x6a8, %rsp            # imm = 0x6A8
retq
nopw %cs:(%rax,%rax)