// File: /workspace/github_cpp_makefile_star2_O2/YiweiMao[P]tessDX/src/tessellator.cpp
// Function: CHWTessellator::StitchRegular(bool, CHWTessellator::DIAGONALS, int, int, int, int)
void CHWTessellator::StitchRegular(bool bTrapezoid,DIAGONALS diagonals,
                                 int baseIndexOffset, int numInsideEdgePoints,
                                 int insideEdgePointBaseOffset, int outsideEdgePointBaseOffset)
{
    int insidePoint = insideEdgePointBaseOffset;
    int outsidePoint = outsideEdgePointBaseOffset;
    if( bTrapezoid )
    {
        DefineClockwiseTriangle(outsidePoint,outsidePoint+1,insidePoint,baseIndexOffset);
        baseIndexOffset += 3; outsidePoint++;
    }
    int p;
    switch( diagonals )
    {
    case DIAGONALS_INSIDE_TO_OUTSIDE:
        // Diagonals pointing from inside edge forward towards outside edge
        for( p = 0; p < numInsideEdgePoints-1; p++ )
        {
            DefineClockwiseTriangle(insidePoint,outsidePoint,outsidePoint+1,baseIndexOffset);
            baseIndexOffset += 3; 

            DefineClockwiseTriangle(insidePoint,outsidePoint+1,insidePoint+1,baseIndexOffset);
            baseIndexOffset += 3; 
            insidePoint++; outsidePoint++;
        }    
        break;
    case DIAGONALS_INSIDE_TO_OUTSIDE_EXCEPT_MIDDLE: // Assumes ODD tessellation
        // Diagonals pointing from outside edge forward towards inside edge

        // First half
        for( p = 0; p < numInsideEdgePoints/2-1; p++ )
        {
            DefineClockwiseTriangle(outsidePoint,outsidePoint+1,insidePoint,baseIndexOffset);
            baseIndexOffset += 3; 
            DefineClockwiseTriangle(insidePoint,outsidePoint+1,insidePoint+1,baseIndexOffset);
            baseIndexOffset += 3; 
            insidePoint++; outsidePoint++;
        }

        // Middle
        DefineClockwiseTriangle(outsidePoint,insidePoint+1,insidePoint,baseIndexOffset);
        baseIndexOffset += 3; 
        DefineClockwiseTriangle(outsidePoint,outsidePoint+1,insidePoint+1,baseIndexOffset);
        baseIndexOffset += 3;
        insidePoint++; outsidePoint++; p+=2;

        // Second half
        for( ; p < numInsideEdgePoints; p++ )
        {
            DefineClockwiseTriangle(outsidePoint,outsidePoint+1,insidePoint,baseIndexOffset);
            baseIndexOffset += 3; 
            DefineClockwiseTriangle(insidePoint,outsidePoint+1,insidePoint+1,baseIndexOffset);
            baseIndexOffset += 3; 
            insidePoint++; outsidePoint++;
        }
        break;
    case DIAGONALS_MIRRORED:
        // First half, diagonals pointing from outside of outside edge to inside of inside edge
        for( p = 0; p < numInsideEdgePoints/2; p++ ) 
        {
            DefineClockwiseTriangle(outsidePoint,insidePoint+1,insidePoint,baseIndexOffset);
            baseIndexOffset += 3; 
            DefineClockwiseTriangle(outsidePoint,outsidePoint+1,insidePoint+1,baseIndexOffset);
            baseIndexOffset += 3; 
            insidePoint++; outsidePoint++;
        }
        // Second half, diagonals pointing from inside of inside edge to outside of outside edge
        for( ; p < numInsideEdgePoints-1; p++ )
        {
            DefineClockwiseTriangle(insidePoint,outsidePoint,outsidePoint+1,baseIndexOffset);
            baseIndexOffset += 3; 
            DefineClockwiseTriangle(insidePoint,outsidePoint+1,insidePoint+1,baseIndexOffset);
            baseIndexOffset += 3; 
            insidePoint++; outsidePoint++;
        }
        break;
    }
    if( bTrapezoid )
    {
        DefineClockwiseTriangle(outsidePoint,outsidePoint+1,insidePoint,baseIndexOffset);
        baseIndexOffset += 3;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x8(%rsp)
movl %r8d, 0x14(%rsp)
movl %ecx, %r8d
movl %edx, %ebx
movq %rdi, %r15
movl 0x70(%rsp), %eax
movq %rax, (%rsp)
movl %esi, 0x24(%rsp)
testl %esi, %esi
je 0x403284
movq (%rsp), %rsi
leal 0x1(%rsi), %ebp
movq %r15, %rdi
movl %ebp, %edx
movq 0x8(%rsp), %rcx
movq %r8, %r14
callq 0x402592
movq %r14, %r8
addl $0x3, %r8d
movl %ebp, %eax
movq %rax, (%rsp)
testl %ebx, %ebx
movq %r15, 0x18(%rsp)
je 0x4034b6
cmpl $0x1, %ebx
je 0x40331c
cmpl $0x2, %ebx
jne 0x40347d
pushq $0x2
popq %rcx
movl 0x14(%rsp), %eax
cltd
idivl %ecx
movl %eax, %r13d
xorl %r12d, %r12d
testl %eax, %eax
cmovlel %r12d, %r13d
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %rax
leal (%rax,%r12), %ebp
movq (%rsp), %rax
leal (%rax,%r12), %r15d
cmpl %r12d, %r13d
je 0x40351d
movq 0x8(%rsp), %rax
leal (%r12,%rax), %ebx
incl %ebx
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
movl %ebp, %ecx
movq %r8, %rbp
callq 0x402592
leal 0x3(%rbp), %r8d
movq (%rsp), %rax
leal (%r12,%rax), %edx
incl %edx
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %ecx
callq 0x402592
movq %rbp, %r8
addl $0x6, %r8d
incl %r12d
jmp 0x4032be
pushq $0x2
popq %rcx
movl 0x14(%rsp), %eax
cltd
idivl %ecx
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovgel %eax, %ecx
movq %rcx, 0x28(%rsp)
leal -0x1(%rcx), %eax
movl %eax, 0x34(%rsp)
xorl %r12d, %r12d
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rax
leal (%rax,%r12), %ecx
movq (%rsp), %rax
leal (%rax,%r12), %ebp
leal 0x3(%r8), %ebx
cmpl %r12d, 0x34(%rsp)
je 0x4033a4
movq (%rsp), %rax
leal (%r12,%rax), %r13d
incl %r13d
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
movq %rcx, %rbp
movq %r8, %r14
callq 0x402592
movq 0x8(%rsp), %rax
leal (%r12,%rax), %ecx
incl %ecx
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
movl %ebx, %r8d
callq 0x402592
movq %r14, %r8
addl $0x6, %r8d
incl %r12d
jmp 0x403343
movq 0x8(%rsp), %rax
leal (%rax,%r12), %r13d
incl %r13d
movq 0x18(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
movl %r13d, %edx
movq %rcx, 0x8(%rsp)
movq %r8, %r14
callq 0x402592
movq (%rsp), %rax
leal (%rax,%r12), %edx
incl %edx
movq %r15, %rdi
movq %rbp, (%rsp)
movl %ebp, %esi
movl %r13d, %ecx
movl %ebx, %r8d
callq 0x402592
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
addl $0x9, %r14d
xorl %r15d, %r15d
movl %r14d, %r12d
movq 0x8(%rsp), %rbp
movq 0x18(%rsp), %r14
movq 0x28(%rsp), %rax
addl %r15d, %eax
leal -0x3(%r12), %r8d
cmpl 0x14(%rsp), %eax
jge 0x40345c
leal (%r15,%rbp), %ebx
incl %ebx
movq (%rsp), %rax
leal 0x1(%rax,%r15), %esi
leal 0x2(%rax,%r15), %r13d
movq %r14, %rdi
movl %r13d, %edx
movl %ebx, %ecx
callq 0x402592
leal (%r15,%rbp), %ecx
addl $0x2, %ecx
movq %r14, %rdi
movl %ebx, %esi
movl %r13d, %edx
movl %r12d, %r8d
callq 0x402592
addl $0x6, %r12d
incl %r15d
jmp 0x403408
movq 0x8(%rsp), %rax
addl %r15d, %eax
incl %eax
movq %rax, 0x8(%rsp)
movq (%rsp), %rax
addl %r15d, %eax
incl %eax
movq %rax, (%rsp)
movq 0x18(%rsp), %r15
movl 0x24(%rsp), %eax
testb %al, %al
je 0x4034a7
movq (%rsp), %rsi
leal 0x1(%rsi), %edx
movq %r15, %rdi
movq 0x8(%rsp), %rcx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x402592
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x14(%rsp), %eax
cmpl $0x2, %eax
pushq $0x1
popq %r15
cmovgel %eax, %r15d
decl %r15d
movq 0x18(%rsp), %r14
subl $0x1, %r15d
jb 0x403478
movq (%rsp), %rdx
leal 0x1(%rdx), %ebx
movq %r14, %rdi
movq 0x8(%rsp), %r13
movl %r13d, %esi
movl %ebx, %ecx
movq %r8, %r12
callq 0x402592
leal 0x3(%r12), %r8d
leal 0x1(%r13), %ebp
movq %r14, %rdi
movl %r13d, %esi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x402592
movq %r12, %r8
addl $0x6, %r8d
movl %ebp, %eax
movq %rax, 0x8(%rsp)
movl %ebx, %eax
movq %rax, (%rsp)
jmp 0x4034cd
decl 0x14(%rsp)
xorl %r12d, %r12d
movq %r13, 0x28(%rsp)
leal (%r12,%rbp), %eax
movq %rax, 0x8(%rsp)
leal (%r15,%r12), %eax
movq %rax, (%rsp)
leal (%r12,%r13), %eax
cmpl 0x14(%rsp), %eax
jge 0x403478
leal (%r12,%r15), %ebx
incl %ebx
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
movl %ebx, %ecx
movq %r8, %r14
callq 0x402592
leal 0x3(%r14), %r8d
leal (%r12,%rbp), %ecx
incl %ecx
movq %r13, %rdi
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %rsi
movl %ebx, %edx
callq 0x402592
movq %r14, %r8
addl $0x6, %r8d
incl %r12d
jmp 0x403529
nop